var xmlHttp;
var objHTML;
var user;
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 SendMail(url)
{
	var today = new Date(); 
	document.getElementById("send_mail").innerHTML = "Loading...";
	xmlHttp = GetXmlHttpObject();
	//var xmlHttp = main.xmlHttp;
	if (xmlHttp==null){objHTML="Your explore doesn't support this site, please use another to retry!";return;}

	url+="&sn="+today.getTime();
	xmlHttp.onreadystatechange=ChangeCont;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
     
function ChangeCont()
{
    if(xmlHttp.readyState==4)
    {
			if (xmlHttp.responseText == "0") {
        		document.getElementById("send_mail").innerHTML="<br><font color=#ff0000>Sorry! Your mail not send!refresh and try again!</font>";
			} else if (xmlHttp.responseText == "1") {
        		document.getElementById("send_mail").innerHTML="We have received your email - please allow upto 5 business days for a reply.";
			} else if (xmlHttp.responseText == "2") {
        		document.getElementById("send_mail").innerHTML="<br><font color=#ff0000>Sorry! This mail not send!<br>refresh and try again!</font>";
			}  else if (xmlHttp.responseText == "3") {
        		document.getElementById("send_mail").innerHTML="<br><font color=#ff0000>Sorry! This mail not send!<br>The Login Name or your Email is not valid!<br> refresh and try again!</font>";
			}  else if (xmlHttp.responseText == "4") {
        		document.getElementById("send_mail").innerHTML="Success! Your password has been emailed to you!";
			}else {
        		document.getElementById("send_mail").innerHTML=xmlHttp.responseText;
			}
    }
}


function OnContact()
{
	if (document.contact.name.value == "") {
		alert("Please make sure that ur name is not empty!");
		return;
	}
	var objReg = new RegExp("[a-z0-9-_]+@[a-z0-9-_]+[\.]{1}(com|net|bta|cn|org|edu|mil)","gi") 

	if (document.contact.email.value == "") {
		alert("Please make sure that ur email is not empty!");
		return;
	}
	if (!objReg.test(document.contact.email.value )){
		alert("Please make sure that ur email is right!");
		return;
	}
	if (document.contact.content.value == "") {
		alert("Please make sure that ur message is not empty!");
		return;
	}
	var url;
	url="sendmail.php";
	url+="?type="+1+"&name="+document.contact.name.value +"&email="+document.contact.email.value+"&content="+document.contact.content.value;
	SendMail(url);
}

function OnBugRep()
{
	if (document.contact.name.value == "") {
		alert("Please make sure that ur name is not empty!");
		return;
	}
	var objReg = new RegExp("[a-z0-9-_]+@[a-z0-9-_]+[\.]{1}(com|net|bta|cn|org|edu|mil)","gi") 

	if (document.contact.email.value == "") {
		alert("Please make sure that ur email is not empty!");
		return;
	}
	if (!objReg.test(document.contact.email.value )){
		alert("Please make sure that ur email is right!");
		return;
	}
	if (document.contact.content.value == "") {
		alert("Please make sure that ur message is not empty!");
		return;
	}
	var url;
	url="sendmail.php";
	url+="?type="+2+"&name="+document.contact.name.value +"&email="+document.contact.email.value+"&realm="+document.contact.realm.value+"&content="+document.contact.content.value;
	SendMail(url);
}

function CheckLog()
{
	//alert("1");
    document.getElementById("logcue").innerHTML = "";
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp==null) {
		objHTML="";
		return;
	}
	if (document.forgetpass.login.value == "") {
	 document.getElementById("logcue").innerHTML = "Empty";
	 return;
	}
}


var myemail = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
function CheckMail()
{
	document.getElementById("emailcue").innerHTML = "";
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp==null) {
		objHTML="";
		return;
	}
	if (document.forgetpass.email.value == "") {
	 document.getElementById("emailcue").innerHTML = "Empty";
	 return;
	}
	if(!myemail.test(document.forgetpass.email.value)) {
	 document.getElementById("emailcue").innerHTML = "You must have a valid e-mail address";
	 return;
	}
}
function GetPswdBack()
{
	xmlHttp = GetXmlHttpObject();
	if (document.forgetpass.login.value == "") {
	 document.getElementById("logcue").innerHTML = "Empty";
	 return;
	}
	if (document.forgetpass.email.value == "") {
	 document.getElementById("emailcue").innerHTML = "Empty";
	 return;
	}
	if(!myemail.test(document.forgetpass.email.value)) {
	 document.getElementById("emailcue").innerHTML = "You must have a valid e-mail address";
	 return;
	}
	var today = new Date(); 
	objHTML = document.getElementById("send_mail").innerHTML;
	objHTML = "Loading...";
	if (xmlHttp==null){objHTML="Your explore doesn't support this site, please use another to retry!";return;}
	var url;
	url="sendmail.php";
	url+="?type=forget"+"&name="+document.forgetpass.login.value +"&email="+document.forgetpass.email.value;
	SendMail(url);
}