// JavaScript Document
function validate_login(){
		var fn=document.login_form;
		document.getElementById('login_div').innerHTML='';
		if(fn.uname.value.length==0){
		document.getElementById('login_div').innerHTML='Enter Username';
		fn.uname.focus();
		fn.uname.style.borderColor='red';
		return false;
		}else{
		fn.uname.style.borderColor='';
		}
		if(fn.password.value.length==0){
		document.getElementById('login_div').innerHTML='Enter Password';
		fn.password.focus();
		fn.password.style.borderColor='red';
		return false;
		}else{
		fn.password.style.borderColor='';
		}
		return true;
}

// return cookie value
function Get_Cookie(check_name,cookie_value) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			chk_tem_value = a_temp_cookie[1].split( '%26' );
			if(chk_tem_value[0].replace("%40","@") == cookie_value)
			{
			document.getElementById('password').value = chk_tem_value[1];
			break;
			}
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
}
$(document).ready(function(){
	$("#login_form").submit(function(){
		var str = $(this).serialize();
		$("#login_div").ajaxStart(function(event, request, settings){
			$(this).html("Please Wait..");
		});
		$.ajax({
			type: "POST",
			url: "util/login_ajax.php",
			data: str,
			success: function(msg){
			$("#login_div").ajaxComplete(function(event, request, settings){
					
					if(msg == "ERROR")
					{
						//document.getElementById('login_div').innerHTML='Login Attempt Failed!';
						$(this).html('Login Attempt Failed!');
					}
					else if(msg == "OK")
					{
						$(this).html('<font color="green">Wait while redirecting....</font>');
						window.location='index.php?page=myaccount';
					}
					//$(this).html(msg);
					//window.location='index.php';
					<!--if(msg == 'Wait while redirecting....')
					//{
					//window.localtion='localhost/rea/Register-Here';	
					//alert("hell");
					//}-->
					$('#uname').val("");
					$('#password').val("");
			  });        
			}    
		});
		return false;		
	});							   
});
