/////////////////////////////////////////////////////////////////////////////////////
//  Copyright.........: (c) Avani Cimcon
//  Product...........: Customer Care System
//  Program...........: CCS_LoginPage.js
//  Description.......: Specific Client side functions of CCS_LoginPage Form.
//  Created By........: Nishant Khandhadia
//  Created...........: 2005/04/07 17:10 [yyyymmddhhmm]
//
//  File Referenced By: Included in CCS_LoginPage.stm 
//
//  Files Referenced..: None
//
//////////////////////////////////////////////////////////////////////////////////////



//************************************************
//Function called when user clicks Login button. 
//It will check all validations.
//************************************************

function fnLogin_onclick() 
{
	
		
	if(fnValidation()==false)
	{
		return false;
	}

	SetValueOfHC('mode','login');
	//window.document.all.CCS_frmlogin.submit();
	return true;
}


//************************************************
//Function called when user clicks Register as customer button. 
//This is function add while solving bugs.(date: 09/06/2005)
//************************************************

function fnReg_onclick() 
{
	
	SetValueOfHC('mode','reg');
	document.getElementById("CCS_frmlogin").submit();
	return true;
}



//************************************************
//Function called when user clicks Register as Partner button. 
//This is function add while solving bugs.(date: 09/06/2005)
//************************************************

function fnPartner_onclick()
{
	
	SetValueOfHC('mode','Partner');
	document.getElementById("CCS_frmlogin").submit();
	return true;
}


//************************************************
//Function return true if user has filled all  
//the compulsory field otherwise return false.
//************************************************

function fnValidation()
{
	var strMsg = "";
	var bFlag=0;

	if(document.getElementById("txtPassword").value == "")
	{
		strMsg = "Password," + strMsg;
		document.getElementById("txtPassword").focus();
		bFlag = 1;
	}
	

	if(document.getElementById("txtLoginId").value=="")
	{
		strMsg = "E-Mail," + strMsg;
		document.getElementById("txtLoginId").focus(); 
		bFlag = 1;
	}
	
	if(bFlag==1)
	{
		strMsg = strMsg.substring(0,strMsg.length-1);
		strMsg = strMsg.replace(","," and ");
		strMsg += " cannot be blank.";
		document.getElementById("divError").innerHTML = strMsg;
		document.getElementById("errorMsg").innerHTML="";
		return false;
	}
	
	if(CCS_frmlogin.txtLoginId.value.length < 3)
	{
		document.getElementById("divError").innerHTML= "Username cannot be less than 3 characters.";
		document.getElementById("txtLoginId").focus();
		document.getElementById("errorMsg").innerHTML="";
		return false;
	}
	if(!fnCheckEmail())
	{
		document.getElementById("divError").innerHTML= "Enter email in username@domain.com format."
		document.getElementById("txtLoginId").focus();
		document.getElementById("errorMsg").innerHTML="";
		return false;
	}
	if(CCS_frmlogin.txtPassword.value.length < 6)
	{
		document.getElementById("divError").innerHTML= "Password cannot be less than 6 characters.";
		document.getElementById("txtPassword").focus();
		document.getElementById("errorMsg").innerHTML="";
		return false;
	}
	
	return true;
}


//************************************************
//Function allows only a-z,A-Z 0-9 and enter keys. 
//************************************************

function fnIsAlphaEnter(eventObj)
{
	var sAgent=navigator.userAgent.toLowerCase();
	if(sAgent.indexOf("msie") != -1)
	{ 
		if((eventObj.keyCode>=65 && eventObj.keyCode<=90)||(eventObj.keyCode>=97 && eventObj.keyCode<=122)||(eventObj.keyCode>=48 && eventObj.keyCode<=57)||eventObj.keyCode==13)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	/*else if(navigator.product == "Gecko")
	{
		if((eventObj.which >=65 && eventObj.which<=90)||(eventObj.which>=97 && eventObj.which<=122)||(eventObj.which>=48 && eventObj.which<=57)||eventObj.which==13)
		{
			return true;
		}
		else
		{
			return false;
		}
	}*/
}

//************************************************
//Function allows only a-z,A-Z and 0-9 enter keys. 
//************************************************

function fnIsAlpha(eventObj)
{
	
	var sAgent=navigator.userAgent.toLowerCase();
	if(sAgent.indexOf("msie") != -1)
	{ 
		if((eventObj.keyCode>=65 && eventObj.keyCode<=90)||(eventObj.keyCode>=97 && eventObj.keyCode<=122)||(eventObj.keyCode>=48 && eventObj.keyCode<=57))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	/*else if(navigator.product == "Gecko")
	{
		if((eventObj.which>=65 && eventObj.which<=90)||(eventObj.which>=97 && eventObj.which<=122)||(eventObj.which>=48 && eventObj.which<=57))
		{
			return true;
		}
		else
		{
			return false;
		}
	}*/
	
}

//************************************************
//Function used to hide error division 
//on body load and on reset form it also loads the 
//date in head which is written in CCS_Common.js
//************************************************

function fnBody_onload()
{
	//Code commented for demo
	//divError.innerHTML=" ";
	fnDate();
	/*window.document.all.CCS_frmlogin.txtLoginId.focus();
	if(CCS_frmlogin.txtLoginId.value!="")
	{
		window.document.all.CCS_frmlogin.txtPassword.focus();
	}*/
	///Added By Darshan Dalwadi [22/04/2006]
	if ( String(document.getElementById("txtLoginId").value) != "" )
	{
		document.getElementById("txtLoginId").focus();
	}
	return true;
}

//************************************************
//Function returns true if user has filled E-mail  
//in correct format.
//************************************************

function fnCheckEmail()
{
	strEmail = new String(CCS_frmlogin.txtLoginId.value);
	
	//Check @ is exists or not and if exists then it is not at the biggining.  
	if(strEmail.indexOf('@')==0||strEmail.indexOf('@')==-1)
	{
		CCS_frmlogin.txtLoginId.focus();
		return false;		
	}
	
	//Check @ is not more than one.
	if(strEmail.indexOf('@')!=strEmail.lastIndexOf('@'))
	{
		CCS_frmlogin.txtLoginId.focus();
		return false;
	}
	
	var nLength = strEmail.length;
	
	if(strEmail.lastIndexOf('.')==nLength-1||strEmail.lastIndexOf('_')==nLength-1||strEmail.lastIndexOf('@')==nLength-1)
	{
		CCS_frmlogin.txtLoginId.focus();
		return false;
	}
	var nIndex = strEmail.indexOf('@');
	strSubPart = strEmail.substring(nIndex+1);
	
	//Check '.' is Exists or not and it is not exact besides @.
	if(strSubPart.indexOf('.')==0||strSubPart.indexOf('.')==-1)
	{
		CCS_frmlogin.txtLoginId.focus();
		return false;
	}
	
	//Check '_ ' is not exists after @. 
	if(strSubPart.indexOf('_')!=-1)
	{
		frmUserMang.txtEmail.focus();
		return false;
	}
	return true;
}


//Following functions are added for launch page
function fnValidateEmail(strEmail)
{
	//Check @ is exists or not and if exists then it is not at the biggining.  
	if(strEmail.indexOf('@')==0||strEmail.indexOf('@')==-1)
	{
		return false;		
	}
	
	//Check @ is not more than one.
	if(strEmail.indexOf('@')!=strEmail.lastIndexOf('@'))
	{
		
		return false;
	}
	
	var nLength = strEmail.length;
	
	if(strEmail.lastIndexOf('.')==nLength-1||strEmail.lastIndexOf('_')==nLength-1||strEmail.lastIndexOf('@')==nLength-1)
	{
		return false;
	}
	var nIndex = strEmail.indexOf('@');
	strSubPart = strEmail.substring(nIndex+1);
	
	//Check '.' is Exists or not and it is not exact besides @.
	if(strSubPart.indexOf('.')==0||strSubPart.indexOf('.')==-1)
	{
		return false;
	}
	
	//Check '_ ' is not exists after @. 
	if(strSubPart.indexOf('_')!=-1)
	{
		return false;
	}
	return true;
}
function fnShowHideDiv()
{
	if(document.getElementById('tdRegister').style.display == "none")
	{
		document.getElementById('tdRegister').style.display = "block";
		if(String(document.getElementById("txtEmail"))!='null')
		{
			document.getElementById("txtEmail").focus()
		}
	}
	else
	{
		document.getElementById('tdRegister').style.display = "none";
		document.getElementById("divError").innerHTML = "";
		
	}
}
function fnLogin() 
{
	if(fnValidateEmail(document.getElementById('txtEmail').value) == false)
	{
		document.getElementById("divError").innerHTML= "Enter email in username@domain.com format."
		document.getElementById("txtEmail").focus();
		return false;
	}
	SetValueOfHC('mode','login');
	return true;
}

