function ltrim ( s )
	{
		return s.replace( /^\s*/, "" )
	}
	
	function rtrim ( s )
	{
		return s.replace( /\s*$/, "" );
	}
	
	function trim ( s )
	{
		return rtrim(ltrim(s));
	}
	function ucase(obj)
	{
		if(obj.value !="")
		{
				obj.value = (obj.value).toUpperCase();
			obj.value=trim(obj.value);
		}
	}

function encrypt(theText){
	var output = "";
	var TextSize = theText.length;
	for (var i = 0; i < TextSize; i++) {
		output = output +String.fromCharCode(((theText.charCodeAt(i) ) + 120));
	}
		
	return output;
}
function decrypt(theText){
	var output = "";
	var TextSize = theText.length;
	for (var i = 0; i < TextSize; i++) {
		output = output +String.fromCharCode(((theText.charCodeAt(i) ) - 120));
	}
		
	return output;
}
function loginCheck(){
	var route = "Login";
	var usrType;
	/*for (var i=0; i < document.forms[0].usrType.length; i++)
	{
		if (document.forms[0].usrType[i].checked)
		{
			usrType=  document.forms[0].usrType[i].value;
		}
	}*/
	usrType=  document.forms[0].usrType.value;
	document.getElementById("msgLayer").style.display = 'none';
	var usr_type  = trim(usrType);
	var mobile = trim(document.forms[0].txtMobile.value);
	
	var password = trim(document.forms[0].txtIPin.value);
	
	if(mobile == ""){
		document.getElementById("msgLayer").style.display = 'inline';
		document.getElementById("msgLayer").innerHTML = "Please Enter Login ID";
		document.forms[0].txtMobile.focus();
		return;
	}
	
	if(trim(document.getElementById("txtIPin").value) == ""){
		document.getElementById("msgLayer").style.display = 'inline';
		document.getElementById("msgLayer").innerHTML = "Please Enter Password";
		document.forms[0].txtIPin.focus();
		return;
	}
	
	/*usr_type	= encrypt(usr_type);
	mobile		= encrypt(mobile);
	password	= encrypt(password);*/
	
	var ajaxRequest = new AjaxRequest("http://www.xpayindia.com/XPAY/web/xpayRouter.jsp"); 
	var QueryString ="user_type="+usr_type+"&mobile="+mobile+"&password="+password+"&hidRouteFlag=Login&route="+route;  
	ajaxRequest.setPostRequest(updateCorpPage); 
	ajaxRequest.setPreRequest(function (){setLoadingImage("","http://www.xpayindia.com/images/ajax-loader_red.gif");});
	ajaxRequest.setQueryString(QueryString);
	ajaxRequest.setErrorHandler(ajaxErrorhandler);
	ajaxRequest.setUseGET();
	ajaxRequest.setAsync(false); 
	ajaxRequest.sendRequest();
	
}

function updateCorpPage(response)
{
	closeErrorMessage();
 	var ResponseObject = response.getXMLHttpRequestObject();
	
	var resptext  		= "";

	if (ResponseObject.readyState == 4)
    	{
        resptext = trim(ResponseObject.responseText);
    	}
	
	var usr_type ;
	/*for (var i=0; i < document.forms[0].usrType.length; i++)
	{
		if (document.forms[0].usrType[i].checked)
		{
			usr_type=  document.forms[0].usrType[i].value;
		}
	}	*/
	usr_type=  document.forms[0].usrType.value;
	usr_type= trim(usr_type);
	
		if(usr_type == 'C'){
				
				window.location.replace("http://www.xpayindia.com/html/XPAYFrame.html");
				
			}else{
				
				window.location.replace("http://www.xpayindia.com/html/XPAYFrame.htm");
				
			}
		if(resptext == 'N'){
			if(usr_type == 'C' || resptext == 'Y'){
				
				window.location.replace("http://www.xpayindia.com/html/XPAYFrame.html");
				
			}else{
				
				window.location.replace("http://www.xpayindia.com/html/XPAYFrame.htm");
				
			}
			
			
		}/*else if(resptext == 'Y'){		// password change
			if(usr_type == 'C'){
				document.forms[0].action = "XPAY/web/client/xpayCUChangePwd.jsp";
			}else{
				document.forms[0].action = "XPAY/web/merch/xpayMRHome.jsp";
				
			}
			document.forms[0].method = 'post';
			document.forms[0].submit();
			
		}*/else {		
			document.getElementById("msgLayer").style.display = 'inline';
			document.getElementById("msgLayer").innerHTML = resptext;
		}
		
	document.getElementById("txtMobile").value 	="";
	document.getElementById("txtIPin").value	="";
	
				
}

function shopLoginCheck(){
	
	
	document.getElementById("msgLayer").style.display = 'none';
	var mobile = trim(document.forms[0].shpMobile.value);
	var password = trim(document.forms[0].shpIPin.value);
	var route = trim(document.forms[0].route.value);
	
	if(mobile == ""){
		alert("Please enter your mobile number");
		document.forms[0].shpMobile.focus();
		return;
	}
	
	if(trim(document.getElementById("shpIPin").value) == ""){
		alert("Please enter your xpay password");
		document.forms[0].shpIPin.focus();
		return;
	}
	
	/*usr_type	= encrypt(usr_type);
	mobile		= encrypt(mobile);
	password	= encrypt(password);*/
	
	var ajaxRequest = new AjaxRequest("http://www.xpayindia.com/XPAY/web/xpayRouter.jsp"); 
	var QueryString ="user_type=C&mobile="+mobile+"&password="+password+"&hidRouteFlag=Shop&route="+route; 
	ajaxRequest.setPostRequest(updateShopCorpPage); 
	ajaxRequest.setPreRequest(function (){setLoadingImage("","http://www.xpayindia.com/images/ajax-loader_red.gif");});
	ajaxRequest.setQueryString(QueryString);
	ajaxRequest.setErrorHandler(ajaxErrorhandler);
	ajaxRequest.setUseGET();
	ajaxRequest.setAsync(false); 
	ajaxRequest.sendRequest();
	
}

function updateShopCorpPage(response)
{
	closeErrorMessage();
 	var ResponseObject = response.getXMLHttpRequestObject();
	var resptext = trim(ResponseObject.responseText);
	window.location.replace("http://www.xpayindia.com/html/XPAYFrame.html");
		
	
				
}

function chkSpChar(Control)
{
   var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>? ";
   for (var i = 0; i < Control.value.length; i++) {
  	if (iChars.indexOf(Control.value.charAt(i)) != -1) {
  	alert ("Your login id has special characters or space.\n Please remove them and try again.");
  	Control.focus();
	
  	return false;
  	}
  }
}
	
	
	
function goURL(url)
{
	//window.location.replace(url);
	window.location.href =url;
}	
