// JavaScript Document
//-----------------------------------------------  login  ------------------------------------------------------

function validate_login(from)
{
	
	
	var status;
	var suffix;
	
	if(from == 'captcha')
	{
		suffix = '_captcha';
	}
	else 
	{
		suffix = "";
	}

	status=validate("username"+suffix,"defaultStr=email_address","enter your email address", "login_status"+suffix ) ;  if(!status) return false;

	status=validate("username"+suffix,"req","enter your email address" , "login_status"+suffix ) ;  if(!status) return false;
	
	status=validate("username"+suffix,"email","enter valid email address", "login_status"+suffix ) ;  if(!status) return false ;
	
	status=validate("password"+suffix,"defaultStr=password","enter password", "login_status"+suffix ) ; if(!status) return false;
	
	status=validate("password"+suffix,"req","enter password", "login_status"+suffix  ) ; if(!status) return false;
	status=validate("password"+suffix,"minlen=6","enter valid password", "login_status"+suffix  ); if(!status) return false ;
	
	
	if(document.getElementById("captcha_txt_value")) 
	{		
		status=validate("captcha_txt_value","req","Please Enter Security Access Code", "login_status") ; 
		if(!status) return false;
	}

	return true;
}





function checkLogin(from)
{

	var suffix;
	var refVal;
	
	if(from == 'captcha') 
	{
		suffix = '_captcha';
	}

	else 
	{
		suffix = ""; from="";
	}


	var status = validate_login(from);
	
	if(status == true)
	{
		ajaxPop 					= new piAjax;
		ajaxPop.phpPage 			= "process/process_customer.php";
		ajaxPop.processIndicator 	= "processing";
		ajaxPop.container 			= "login_status"+suffix;

		ajaxPop.formName			= "loginForm";

		ajaxPop.redirectDelay 		= 1000;
		ajaxPop.postAction 			= "welcomeMessage()";
		ajaxPop.ajaxStart();
	}
	
}


function welcomeMessage()
{
	
	var param = document.getElementById('param').value;

	document.getElementById('loginDiv').innerHTML = '<div class="txt11 white" style="position:relative" id="loggedDiv">Logged in as <span class="white"><strong>'+param+'</strong></span> | <a href="?Account&amp;see=overview">Your Account</a> | <a href="javascript:void(0)" onclick="javascript:logout()">Logout</a> |  <a href="?" style="position:relative">Home</a></div>';
}

//------------------------------------------------------ login ends  -------------------------------------------------------------------

//---------------------------------------------------- forgot password ---------------------------------------------------------------


function forgotPassword()
{
	/*dimObj = new dim;
	dimObj.fileToInclude = "view_forgot_password.php"
	dimObj.doDim();*/
	document.getElementById("notloogedDiv").className		= "abs_hide";
	document.getElementById("loginDiv").className			= "abs_hide";
	document.getElementById("forgotPasswordDiv").className 	= "abs_show";
	
}

function cancelForgotPassword()
{
	document.getElementById("notloogedDiv").className ="abs_show";
	document.getElementById("loginDiv").className ="abs_hide";
	document.getElementById("forgotPasswordDiv").className ="abs_hide";
}


function validate_forgotPassword()
{
	var status;
	status=validate("customers_email","defaultStr=email_address","enter your email address", "fp_status" ) ;  if(!status) return false
	status=validate("customers_email","req","enter your email address" , "fp_status" ) ;  if(!status) return false
	status=validate("customers_email","email","enter valid email address", "fp_status" ) ;  if(!status) return false 
	return true;
}

function processForgotPassword(email)
{
	
	var status = validate_forgotPassword();
	if(status == true)
	{
		ajax 					= new piAjax;
		ajax.phpPage 			="process/process_customer.php";
		ajax.processIndicator 	= indicator_small+" Processing";
		ajax.container 			= "fp_status";
		ajax.redirectDelay 		= 1000;
		ajax.post				= { 
									action						: "forgotpassword", 
									customers_email 			: email
								  }
		ajax.ajaxStart();
	}
}


//---------------------------------------------------- forgot password ends ---------------------------------------------------------------


function logout()
{
	ajax = new piAjax;
	ajax.phpPage ="process/process_customer.php";
	ajax.processIndicator = indicator_small+" Logging out...";
	ajax.container = "loggedDiv";
	ajax.redirectDelay = 1000;
	ajax.post			= { action:"logout" }
	//ajax.postAction = "switchToNotLoggedIn()";
	ajax.ajaxStart();
}


/*function checkfields(id)
{
	
	if(document.getElementById(id).value == "email address" || document.getElementById(id).value == "password") 
	document.getElementById(id).value = "";	
		
}*/


function changeMsg()
{
	
	document.getElementById("messagePop").innerHTML = '<span class="txt14 white bold"><br>'+bar_indicator+'<br>Sucessfully Logged Out..<br>Re-directing..</span>';
}


function tryagain()
{
	document.getElementById("login_table").style.display = "";
	document.getElementById("login_msg").style.display = "none";
}



function showLoginTemplate()
{
	showDim('dim', 70, 20, '#000000', 'loginPop');	
}

function login_to_fp()
{
	document.getElementById('loginPop').className = "abs_hide";	
	showPopUp('forgotPasswordPop');
//document.getElementById('loginPop').className = "abs_show";	
}

function fp_to_login()
{
	document.getElementById('forgotPasswordPop').className = "abs_hide";	
	showPopUp('loginPop');
//document.getElementById('loginPop').className = "abs_show";	
}

function showLoginForm()
{
	//alert("in here");
	document.getElementById("notloogedDiv").className = "abs_hide";
	document.getElementById("loginDiv").className = "abs_show";
}