//-------------- USER LOG IN -----------------//
function checkUserLogIn()
{
	//showLoader(1);
	//alert('hello');
	$('msg_div').innerHTML = '';
	
	if($F('userName') == '') {
    var arr='<table width="90%" style="background-color:#c1d6eb;border:thin;border-style:solid; border-color:#347cb6;">';
		arr=arr+'<tr><td height="15" valign="middle" style="text-align:center"><strong>Username</strong> is blank!.</td></tr>';
		arr=arr+'</table>';
        $('alert_div').style.display = '';
		$('msg_div').innerHTML = arr;
		//displayAlert();
		//showLoader(0);
		return false;
	}
	
	if($F('password')== '') {
		var arr='<table width="90%" style="background-color:#c1d6eb;border:thin;border-style:solid; border-color:#347cb6;">';
		arr=arr+'<tr><td height="15" valign="middle" style="text-align:center"><strong>Password</strong> is blank!.</td></tr>';
		arr=arr+'</table>';
		$('alert_div').style.display = '';
		$('msg_div').innerHTML = arr;
		//displayAlert();
		//showLoader(0);
		return false;
	}
	var url =  'login_action.php';
	//	document.login_form.submit();
  
	var pars = 'userName=' + $F('userName') + '&password=' + $F('password') + "&mode=login";
	
	//	displayAlert(msg);alert(pars);
	var myAjax = new Ajax.Request(
	url,
	{
		method: 'POST',
		parameters: pars,
		onComplete:showUserLogin_Response
	});
}
function showUserLogin_Response(originalRequest)
{
	/*if($('rememberMe').checked==true)
	{
		var userName=$('userName').value;
		var retailerPassword=$('retailerPassword').value;
		createCookie('remeberMe',userName,365);
		createCookie('remeberPassword',retailerPassword,365);
	}*/
	response  = alltrim(originalRequest.responseText);
	//	alert(response);
	if(response.indexOf('yes') != -1) {
		//showLoader(0);
		//var backToPage=$('backToPage').value;
		//if(backToPage=="")
		 window.location = "resources.php";
	//	else
	//	{
	//	 window.location.href = backToPage;
	//	}
	}
	else {
		$('alert_div').style.display = '';
		$('msg_div').innerHTML = response;
		//displayAlert();
		//showLoader(0);
		return false;
	}
}
//---------------EDIT USER PROFILE---------------//

//---------------FORGOT PASSWORD SECTION----------------//
function ViewForgot() {
     $('msg_div').innerHTML = '';
	 //$('showAlert_Div').style.display = 'none';
	//if($('alert_div')) $('alert_div').className = "alert_hide";
	if($('login_div')) $('login_div').style.display = 'none';
	if($('forgot_div')) $('forgot_div').style.display = '';
}

function ViewLogin() {
	$('msg_div').innerHTML = '';
	//$('showAlert_Div').style.display = 'none';
	//if($('alert_div')) $('alert_div').className = "alert_hide";
	if($('login_div')) $('login_div').style.display = '';
	if($('forgot_div')) $('forgot_div').style.display = 'none';
}

function getPassword()
{
	//showLoader(1);
  $('msg_div').innerHTML = '';
	var url =  'login_action.php';
	if(alltrim($('userEmail').value) == '') {
	var arr='<div style="background-color:#b3eaff;border:thin;border-style:solid;color:#ff0000; border-color:#347cb6;width=100; height:17; font-size:12px;text-align:center">';
		arr=arr+'<strong>Username</strong> is blank !';
		arr=arr+'</div>';
		$('alert_div').style.display='';
		$('msg_div').innerHTML = arr;
		return false;
	}
	else {
      if (!checkEmail(alltrim($('userEmail').value)))
      {
		  
	  var arr='<div style="background-color:#b3eaff;color:#ff0000;border:thin;border-style:solid; border-color:#347cb6;width=100; height:17; font-size:12px;text-align:center">';
		arr=arr+'Invalid <strong>Username/Email</strong> !';
		arr=arr+'</div>';
		$('msg_div').innerHTML = arr;
		document.getElementById('alert_div').style.display='';
		return false;
     }
	
	//	document.login_form.submit();
	var pars = 'userName=' + $F('userEmail') + "&mode=password";
	//alert(pars)
	var myAjax = new Ajax.Request(
	url,
	{
		method: 'POST',
		parameters: pars,
		onComplete:showLogin_password
	});
	}
}
function showLogin_password(originalRequest)
{
	response  = alltrim(originalRequest.responseText);
		//alert(response);
	if(response.indexOf('yes') != -1) {
		$('alert_div').style.display='';
		var arr='<div style="background-color:#b3eaff;color:brown;border:thin;border-style:solid; border-color:#347cb6;width=100; height:17; font-size:12px;text-align:center">';
		arr=arr+'Your password has been sent via mail. Please check your mail.';
		arr=arr+'</div>'; 
		 $('msg_div').innerHTML = arr;
	}
	else {
	  $('alert_div').style.display='';
	  $('msg_div').innerHTML = response;
		return false;
	}
}

