var httpreq;
var code;

function init()
{
	var d = document;
	var btnSubmit = d.getElementById("btnSubmit");
	var loginid = d.getElementById("tbLogin");
	var email = d.getElementById("tbEmail");
	btnSubmit.onclick = function(){ verifyEmail(loginid,email) };
	loginid.focus();
}

function verifyEmail(loginid,email)
{
	var verifyStatus = document.getElementById("verifyStatus");
	verifyStatus.innerHTML = "<img src='images/flash-timing.gif'>";
	
	httpreq = new httpRequest();
	httpreq.sendRequest("POST","verifyemail.aspx",verifyCallback,"loginid="+loginid.value+"&email="+email.value);
}

function verifyCallback()
{
	var http = httpreq.http;
	
	if(http.readyState == 4)
	{
		if(http.status == 200)
		{
			var verifyStatus = document.getElementById("verifyStatus");
			verifyStatus.innerHTML = "";
			var xmlobj = http.responseXML;
			if(xmlobj.documentElement)
			{
				var verifi = xmlobj.documentElement.selectSingleNode("verification");
				verifyStatus.innerText = verifi.getAttribute("message");
				
				if(verifi.getAttribute("result") == "True")
				{
					var divVerified = document.getElementById("divVerified");
					
					getImageCode();
					divVerified.style.display = "block";
				}
			}
		}
	}
}

function getImageCode()
{
	code = "";
	var rand;
	
	for(var i=0; i<6; i++)
	{
		do
		{
			rand = String.fromCharCode(Math.random()*255);
		}while(!rand.match(/^[A-Za-z0-9]/));
	//alert(Math.random());
		
		code += rand;
	}
	
	var img = document.createElement("IMG");
	var divimagecode = document.getElementById("divimagecode");
	
	img.src = "generateimagecode.aspx?code="+code;
	divimagecode.innerHTML = "";
	divimagecode.appendChild(img);
}

function validateCode()
{
	var d = document;
	var imagecode = d.getElementById("tbImageCode");
	
//	if(code != imagecode.value)
//	{
//		alert("Invalid verification code.");
//		return false;
//	}
	if(imagecode.value.length == 0)
	{
		alert("Please enter code.");
		return false;
	}
}

