	var expDays = 30;
	var exp     = new Date(); 
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
	 
	function valid(str) {
        for(var i = 0; i < str.length; i++) {
            var charcode = str.charCodeAt(i);

            /* A-Z */
            if(charcode >= 0x41 && charcode <= 0x5A) {
                continue;
            }               
            /* a-z */
            if(charcode >= 0x61 && charcode <= 0x7A) {
                continue;
            }   
            /* 0-9 */
            if(charcode >= 0x30 && charcode <= 0x39) {
                continue;
            }               
            /* . - _ 32*/
            if(charcode == 0x2D || charcode == 0x2E || charcode == 0x5F  ) {
                continue;
            }
               
            return false;
        }//end for(var i = 0; i < str.length; i++)

        return true;

    }//end function valid
	
	function testemail(obj) {
        var atpos = obj.value.indexOf("@");
            if(atpos == -1) {
                return false;
            }

            if(atpos == 0) {
                return false;
            }

            var dotpos = obj.value.indexOf('.', atpos+2);

            if( dotpos == -1) {
                return false;
            }
               
            if(dotpos == (obj.value.length - 1) ) {
               return false;
            }
               
            if(obj.value.indexOf(".") == 0){
                return false;
            }
               
            if( obj.value.indexOf("@")  == (obj.value.indexOf('.', obj.value.indexOf("@")+1)) - 1 ){
                return false;
            }
                              
            if( obj.value.indexOf(".")  == (obj.value.indexOf('.', obj.value.indexOf(".")+1)) - 1 ){
	        return false;
            }
               
                             
           var fpart = obj.value.substring(0,atpos);
           var host = obj.value.substring(atpos + 1, dotpos);
           var domain = obj.value.substr(dotpos +1);

           if(!( valid(fpart) && valid(host) && valid(domain))) {
               return false;
           }
     
           var afterat = obj.value.substr(atpos + 1);
     
           if(afterat.lastIndexOf('.') == (afterat.length - 1)) {
               return false;
           }
     
           for(var i = 1; i < afterat.length; i++) {
        
     	       if(afterat.charAt(i) == '.' && afterat.charAt(i-1) == '.') {
                   return false;
               }

           }//end for(var i = 1; i < afterat.length; i++)

           return true;
                  
    }//end function testemail	

	function loginValidateData(){
		
		if (document.Loginform.name.value == "") {
	    	document.getElementById('pform').innerHTML='<font color="#FF0000">من فضلك, تأكد من إدخال الإسم</font>';
	 		document.Loginform.name.focus();
			return false;
		}else if (document.Loginform.pass.value == "") {
	    	document.getElementById('pform').innerHTML='<font color="#FF0000">من فضلك, تأكد من إدخال كلمة السر</font>';
	 		document.Loginform.pass.focus();
			return false;
		}else{
			if(document.Loginform.remember_me.checked==true){ 
	  	    	SetCookie('meuser_login',document.Loginform.name.value, exp);
				SetCookie('remember_remember','1', exp);
			}else{ 	
				DeleteCookie('meuser_login');
			   	SetCookie('remember_remember','0', exp);				   
			}
			return true
		}
	}//end function
	
	
	function load_data(){
	
	    if (GetCookie('remember_remember') == 0 || GetCookie('remember_remember') == null) {
	        document.Loginform.remember_me.checked=false;
		    document.Loginform.name.focus();
	    }else{
			document.Loginform.remember_me.checked=true;
			if (GetCookie('meuser_login') != null)
	            document.Loginform.name.value=GetCookie('meuser_login');
	
			if(document.Loginform.name.value != '')
			    document.Loginform.pass.focus();
			else
			 	document.Loginform.name.focus();
	    }//end if

}//end load_data()

	
	var retrunToPage="";
	function login(){
	if(loginValidateData())
	{
		document.Loginform.submit();
	}

}

function loginHandler(sText){
	
	if(sText)
	{
		top.location = sText;
	}
	else
	{
		document.Loginform.submit();
	}
}


function viewlogin(sText){
	if(sText != 0){
		document.getElementById('loginDiv').innerHTML = sText;
		document.Loginform.login_text.value = '';
		
	}
}
function logout(location){
	if (confirm('هل انت متاكد بانك تريد الخروج ؟')) {
		
		AJAXGet("logout.php?location="+location,loginHandler,false,false);
	}

}
function close_InvalidOne(sText)
{
	top.location = sText;
}
function loginKey(event)
{
	
	if(event == 13) {
		login();
	}
}
function check_login(val)
{
	if(val==1)
	{
		top.location = retrunToPage;
	}
	else
	{
		show_LoginDiv();
		document.getElementById('pform').innerHTML='<font color="#FF0000">نعتذر هناك خطأ في إسم المستخدم أو كلمة السر</font>';
	 	document.Loginform.name.focus();
	}
}


	function SetCookie (name, value) {  
		var argv = SetCookie.arguments;  
		var argc = SetCookie.arguments.length;  
		var expires = (argc > 2) ? argv[2] : null;  
		var path = (argc > 3) ? argv[3] : "/"; 
		//var domain = (argc > 4) ? argv[4] : null;  
		var secure = (argc > 5) ? argv[5] : false;  
		document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((secure == true) ? "; secure" : "")+"; domain=.maktoob.com";
	}

	function DeleteCookie (name) {  
		var exp = new Date();  
		exp.setTime (exp.getTime() - 1);  
		var cval = GetCookie (name);  
		document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
	}
	
	
	function getCookieVal (offset) {  
		var endstr = document.cookie.indexOf (";", offset);  
		if (endstr == -1)    
		endstr = document.cookie.length;  
		return unescape(document.cookie.substring(offset, endstr));
	}
	
	function GetCookie (name) {  
		var arg = name + "=";  
		var alen = arg.length;  
		var clen = document.cookie.length;  
		var i = 0;  
		
		while (i < clen) {    
			var j = i + alen;    
			if (document.cookie.substring(i, j) == arg)      
				return getCookieVal (j);    
			i = document.cookie.indexOf(" ", i) + 1;    
			if (i == 0) 
				break;   
		}  
		return null;
	}