// JavaScript Document
function HipRefresh(obj){
	obj.src='/files/code.do?'+new Date;
	var objtext=document.getElementById("characters");
	if(objtext!=null){
		objtext.focus();
		objtext.select();
	}
}
function Ajaxc(){if(window.ActiveXObject){var msxmls=new Array('Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');for(var i=0;i<msxmls.length;i++){try{return new ActiveXObject(msxmls[i]);}catch(e){}}}else if(window.XMLHttpRequest){return new XMLHttpRequest();}return null;}

function RPcontinue(){
	var eml=document.getElementById("emails");
	var code=document.getElementById("characters");
	var checkbt=document.getElementById("check");
	checkbt.value='Wait...';
	checkbt.disabled='disabled';
	if(code.value.length!=6){
		alert("Characters is wrong.");
		code.focus(); 
		checkbt.disabled='';
		checkbt.value='Continue';
		return false;
	}
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9])+\.([a-zA-Z0-9])+/;
	var flag=pattern.test(eml.value);
	if(!flag)
	{
		  alert("Email is wrong.");
		  eml.focus(); 
		  checkbt.disabled='';
		  checkbt.value='Continue';
		  return false;
	}
	var xmlhttp=Ajaxc();
	xmlhttp.open("post","/RP.do",false);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlhttp.send("c_code="+code.value);
	if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
	{
		var rtxt=xmlhttp.responseText;
		rtxt=rtxt.toLowerCase();
		if(rtxt=="ok"){
			xmlhttp=null;
			xmlhttp=Ajaxc();
			xmlhttp.open("post","/RP.do",true);
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			xmlhttp.send("c_email="+eml.value+"&s="+escape(new Date().toString()));
			xmlhttp.onreadystatechange = function(){
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
				{
					rtxt=xmlhttp.responseText;
					rtxt=rtxt.toLowerCase();
					if(rtxt=="ok"){
						var objcom=document.getElementById("divcontinue");
						var objocom=document.getElementById("oldivcontinue");
						objocom.style.display='none';
						objcom.style.display='block';
						var objeml=document.getElementById("emialstr");
						objeml.innerHTML=eml.value;
						xmlhttp=null;
						checkbt.disabled='';
						checkbt.value='Continue';
						
						return true;
					}
					else{
						alert(rtxt);
						checkbt.disabled='';
						checkbt.value='Continue';
						xmlhttp=null;
					}
				}
			};
			
		}
		else{
			alert("Characters is wrong.");
			checkbt.disabled='';
			checkbt.value='Continue';
		}
	}
}

function submitcheck(obj){
	if(obj.pass.value!=obj.rpass.value)
	{
		alert('This password doesn\'t match the confirmation password.');
		return false;
	}
	var pattern=/[\'\"\=\&]/;
	var pttest=pattern.test(obj.rpass.value);
	if(pttest){
		alert('Password is not legitimate.');
		return false;
	}
	if(obj.pass.value.length<6)
	{
		alert('Your password must be longer than 6 characters.');
		return false;
	}
	
	return true;
}