// JavaScript Document
var xmlHttp;

function mailjax(uname, email)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="mailto.asp";
url=url+"?uname="+uname;
url=url+"&email="+email;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("Get",url,true);
xmlHttp.send(null);
}

function stateChanged() { 
	if (xmlHttp.readyState==1){
		document.getElementById("float_holder").innerHTML="<div class='float_sm' style='height:20px;'><!--blank--></div><div class='float_bg' style='height:20px;'><h3 style='font-size:9px;margin-top:5px;'>Receive our guide to the latest dental cosmetic material</h3></div><br style='clear:both'/><br><span>Building Email...</span>";
	}
	if (xmlHttp.readyState==2){
		document.getElementById("float_holder").innerHTML="<div class='float_sm' style='height:20px;'><!--blank--></div><div class='float_bg' style='height:20px;'><h3 style='font-size:9px;margin-top:5px;'>Receive our guide to the latest dental cosmetic material</h3></div><br style='clear:both'/><br><span>Processing Values...</span>";
	}
	if (xmlHttp.readyState==3){ 
		document.getElementById("float_holder").innerHTML="<div class='float_sm' style='height:20px;'><!--blank--></div><div class='float_bg' style='height:20px;'><h3 style='font-size:9px;margin-top:5px;'>Receive our guide to the latest dental cosmetic material</h3></div><br style='clear:both'/><br><span>Sending Email...</span>";
	}	
	if (xmlHttp.readyState==4){ 
		if (xmlHttp.responseText == 'ok'){
			document.getElementById("float_holder").innerHTML="<div class='float_sm' style='height:20px;'><!--blank--></div><div class='float_bg' style='height:20px;'><h3 style='font-size:9px;margin-top:5px;'>Receive our guide to the latest dental cosmetic material</h3></div><br style='clear:both'/><br><span>We sent the free dental cosmetic material to your email!</span>";
		}else{
			document.getElementById("float_holder").innerHTML="<div class='float_sm' style='height:20px;'><!--blank--></div><div class='float_bg' style='height:20px;'><h3 style='font-size:9px;margin-top:5px;'>Receive our guide to the latest dental cosmetic material</h3></div><br style='clear:both'/><br><span>There was an error sending your email.</span>";
		}	
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}
function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}		
	if (str.indexOf(" ")!=-1){
		return false
	}
 	return true					
}
function mailit(){
	if (document.getElementById("uname").value==""){
		alert("You must enter your name to receive this free offer.");
	}
	else{
		if (document.getElementById("email").value==""){
			alert("You must enter your email address to receive this free offer.");
		}
		else if(echeck(document.getElementById("email").value)==false){
			alert("You must enter a valid email address to receive this free offer.");
		}
		else{
			mailjax(document.getElementById("uname").value, document.getElementById("email").value);
		}
	}		
}