

function chkIdentify(sIdentify,sTrName,sTextName)//('Identify','CompanyName_tr')
{
	//alert(sTrName);
	if( sIdentify == 'BusinessUser')
	{
		displayObj(sTrName,"block");
		displayObj(sTextName,"block");
	}	
	else if( sIdentify == 'EndUser')
	{
		displayObj(sTrName,"none");
		displayObj(sTextName,"none");
	}	
	
}
function checkInput(sFormName)
{
	var sForm;
	
	sForm = document.getElementById(sFormName);
	
	if( checkFormAllTextLength(sFormName) )
		if( checkFormAllTextCurrent(sFormName) )
			sForm.submit();
	
	sForm = null;
			
}

function submit_Login(e,sFormName)
{
	var charCode;
	
	charCode = getKeyCode(e);
		
	if( charCode == 13)
			 checkInput(sFormName);
}

function submit_Register(e,sRCName,sRPName,sRCPName,sRUName,sOptionName,sClickName,sFormName,sCaptchaName)
{
	var charCode;
	
	charCode = getKeyCode(e);
		
	if( charCode == 13)
			 checkRegisterAllData(sRCName,sRPName,sRCPName,sRUName,sOptionName,sClickName,sFormName,sCaptchaName);
}

function checkRegisterAllData(sRCName,sRPName,sRCPName,sRUName,sOptionName,sClickName,sFormName,sCaptchaName)//Company,Password,Confirm Password,UserName
{
	var sRCValue,sRPValue,sRCPValue,sRUValue;
	var xmlHttp;
	var webUrl;
	var sDataUrl;
	var sOption;
	var sCaptcha;
	
	//sOption = getElObjCheck(sRadioName);
	//setElObjDisable(sClickName,"true");
	sOption = getElValue(sFormName,sOptionName);
	
	if( sOption == "BusinessUser" )
	{		
		if( !checkFormAllTextLength(sFormName) || !checkFormAllTextCurrent(sFormName) )
			return;
		
		sRCValue = getElObjValue(sRCName);
		sRPValue = getElObjValue(sRPName);
		sRCPValue = getElObjValue(sRCPName);
		sRUValue = getElObjValue(sRUName);
		sCaptcha = getElObjValue(sCaptchaName);
		
		//alert(sCaptcha);		
		webUrl = "../functions/checkRegisterData.jsp";	
		sDataUrl = "checkRegisterData=BusinessUser&Company=" + sRCValue + "&Password=" + sRPValue +
					"&ConfirmPassword=" + sRCPValue + "&UserName=" + sRUValue + "&Captcha=" + sCaptcha;
	}				
	else if( sOption == "EndUser" )
	{		
		if( !checkFormAllTextLength(sFormName) || !checkFormAllTextCurrent(sFormName) )
			return;
			
		sRPValue = getElObjValue(sRPName);
		sRCPValue = getElObjValue(sRCPName);
		sRUValue = getElObjValue(sRUName);
		sCaptcha = getElObjValue(sCaptchaName);		
		
		webUrl = "../functions/checkRegisterData.jsp";	
		sDataUrl = "checkRegisterData=EndUser&Password=" + sRPValue +
					"&ConfirmPassword=" + sRCPValue + "&UserName=" + sRUValue + "&Captcha=" + sCaptcha;
	}			
	
	setElObjDisable(sClickName,"true");	
	xmlHttp = createXmlHttpRequest(xmlHttp);
	xmlHttp.onreadystatechange = function()
					{ 
						if(xmlHttp.readyState == 4) 
						{
							if(xmlHttp.status == 200) 
							{					
								registerResult(xmlHttp.responseText.trim(),10);
								this.onreadystatechange = null;
							}
							xmlHttp.abort();
							xmlHttp = null;
						}
					
					};
					//alert(sDataUrl);
	xmlHttp.open("POST", webUrl, true);
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttp.send(sDataUrl);	


}

function registerResult(sResultText,sExistTime)
{
	var sText;
	
	//alert(sResultText);
	if( sResultText.indexOf("Congratulation!") == -1 )
	{
		sText = "<font color='#ff0000'>" + sResultText	+ "</font>";
		setElObjInnerHTML("R_Msg",sText);	
		setElObjDisable("R_Click_IMG","");
		getNewCaptcha();
	}	
	else
	{

		sExistTime -= 1;
		sText = "<tr align='left' valign='top'><td><font class='red'>"
		sText += sResultText;//
		sText += "</font><br><br>";
		sText += "<font class='copy'>";
		sText += "You've successfully signed up for Gopass GIS System!";
		sText += "<br>";
		sText += "You'll be redirected to the login page in </font><font size='+1' color='#ff0000'>" + sExistTime + "</font><font class='copy'> seconds.</font>";
		sText += "</td></tr>";
		//setElObjInnerHTML('R_Msg',sText);
		//alert(sText);
		setElObjInnerHTML("Register_Main",sText);
		
		if( sExistTime == 0)
			resetRObj();
		else
			setTimeout("registerResult('" + sResultText + "'," + sExistTime + ");",1000);
	}	
	
	
}

function getNewCaptcha()
{
	setElObj_src("Captcha_img","../Index/image.jsp?random=" + Math.random());
}

function resetRObj()
{
	location.href="index.jsp?login";
	/*
	setElObjValue('R_CompanyName','');
	setElObjValue('R_UserName','');
	setElObjValue('R_Password','');
	setElObjValue('R_Confirm_Password','');
	displayObj('R_Data','none');
	visLayer('langSelect','visible');
	visLayer('Identify','visible');
	setElObjInnerHTML('R_Msg','');
	setElObjValue('Captcha','');
	setElObjDisable('R_Click_IMG',"");
	*/	
}