	function trim(str) {      
        var from_start = 0;
        var from_end = str.length - 1;
        var return_value;

        while(str.charAt(from_start) == ' ') {
            from_start ++;
        }

        while(str.charAt(from_end) == ' ') {
           from_end --;
        }
   
        if(from_end < from_start){
           return '' ;
        }

        return_value = str.substring(from_start,from_end+1);
        return return_value;

   	}//end function trim 
    
	function checkForm(){
		document.getElementById("username").className = "ts";
		document.getElementById("code").className     = "ts";
		document.theForm.username.value = trim(document.theForm.username.value);
		document.theForm.code.value     = trim(document.theForm.code.value);
		if(document.getElementById("error1")){
			document.getElementById("error1").style.visibility = "hidden";
			document.getElementById("error1").style.display = "none";
		}
		if (document.theForm.username.value == "") {
			document.getElementById("error").style.visibility = "";
			document.getElementById("username").className = "tsr";
		    document.getElementById("error").innerHTML='حقل اسم الدخول فارغ، نرجو تعبئته لتتمكن من المتابعة';
		 	document.theForm.username.focus();
			return false;
		/*}else if(document.theForm.username.value.length > 32 || document.theForm.username.value.length < 1 ) {
		    document.getElementById("error").style.visibility = "";
			document.getElementById("username").className = "tsr";
		    document.getElementById("error").innerHTML='اسم الدخول يجب ان يكون 32 حرف على الأكثر';
		    document.theForm.username.focus();
		    return false;	*/
		}else if (document.theForm.code.value == "") {
			document.getElementById("error").style.visibility = "";
			document.getElementById("code").className = "tsr";
		    document.getElementById("error").innerHTML='الرجاء طباعة الرقم الذي يظهر في المربع';
		 	document.theForm.code.focus();
			return false;
		}else if (isNaN(document.theForm.code.value)) {
			document.getElementById("error").style.visibility = "";
			document.getElementById("code").className = "tsr";
		    document.getElementById("error").innerHTML='يمكنك ادخال الأرقام 0-9 فقط';
		 	document.theForm.code.focus();
			return false;
		}
		
		return true;
	}//end function
	
	function checkHint(){
		document.theForm.hint.value = trim(document.theForm.hint.value);
		if(document.getElementById("error1")){
			document.getElementById("error1").style.visibility = "hidden";
			document.getElementById("error1").style.display = "none";
		}
		if (document.theForm.hint.value == "") {
			document.getElementById("error").style.visibility = "";
			document.getElementById("hint").className = "tsr";
		    document.getElementById("error").innerHTML='حقل تذكير كلمة السر فارغ، نرجو تعبئته لتتمكن من المتابعة.';
		 	document.theForm.hint.focus();
			return false;
		}
		return true;
	}//end function
	
	function checkQuestion(){
		if(document.getElementById("error1")){
			document.getElementById("error1").style.visibility = "hidden";
			document.getElementById("error1").style.display = "none";
		}
		document.theForm.answer.value = trim(document.theForm.answer.value);
		if (document.theForm.answer.value == "") {
			document.getElementById("error").style.visibility = "";
			document.getElementById("answer").className = "tsr";
		    document.getElementById("error").innerHTML='حقل إجابة السؤال السري فارغ، نرجو تعبئته لتتمكن من المتابعة.';
		 	document.theForm.answer.focus();
			return false;
		}
		return true;
	}//end function
	
	function checkPassword(){  
		if(document.getElementById("error1")){
			document.getElementById("error1").style.visibility = "hidden";
			document.getElementById("error1").style.display = "none";
		}
		
		if (document.theForm.password.value == "") {
			document.getElementById("error").style.visibility = "";
			document.getElementById("password").className = "tsr";
		    document.getElementById("error").innerHTML='حقل كلمة السر الجديدة فارغ، نرجو تعبئته لتتمكن من المتابعة.';
		 	document.theForm.password.focus();
			return false;
		}else if(document.theForm.password.value.length > 32 || document.theForm.password.value.length < 6) {
		    document.getElementById("error").style.visibility = "";
			document.getElementById("password").className = "tsr";
		    document.getElementById("error").innerHTML='كلمة السر يجب أن تتكون من 6 أحرف على الأقل و 20 حرفاً على الأكثر';
		    document.theForm.password.focus();
		    return false;
		}else if(hasPasswordInvalidChars(document.theForm.password.value)) {  
			document.getElementById("error").style.visibility = "";
			document.getElementById("password").className = "tsr";
		    document.getElementById("error").innerHTML='كلمة السر يمكن أن تحتوي على الأحرف (A-Z) (a-z) (أ-ي) والأرقام (0-9)فقط';
		    document.theForm.password.focus();
		    return false; 
		}else if(document.theForm.password.value != document.theForm.confPassword.value){
		    document.getElementById("error").style.visibility = "";
			document.getElementById("password").className = "tsr";
			document.getElementById("confPassword").className = "tsr";
		    document.getElementById("error").innerHTML='كلمات السر لا تتطابق ';
		    document.theForm.password.focus();
		    return false;
		}else if(document.theForm.password.value == document.theForm.username.value){
		    document.getElementById("error").style.visibility = "";
			document.getElementById("password").className = "tsr";
		    document.getElementById("error").innerHTML='كلمة السر واسم الدخول يجب أن لا يتطابقا';
		    document.theForm.password.focus();
		    return false;          
		}
		return true;
	}
	
	function hasPasswordInvalidChars(text) {
	    var invalidChars = ['`','~','!','@','#','$','%','^','&','*','(',')','\'','"','`','<','>',';',',','|','\\','/','?','+','=','{','}','[',']',':' , '،' , 'ٌ' , 'ٌ' , 'ُ' , 'ً' , 'َ' , 'ٍ' , ' ' ] ;
	
	    for (var i=0;i<text.length;i++) {
	        textChar = text.charAt(i);
	        for (var j=0; j<invalidChars.length; j++) {
	            if(invalidChars[j] == textChar) {
	                return true;
	            }
	        }
	    }
	    return false;
	}
	
	
	function relaodImage(){
		var img  = document.getElementById('img');
		img.src  = 'http://login.maktoob.com/forgotpw/CAPTCHA.php?rb=' +  Math.random() ;
	}

	
	function showDiv( divName ){
		try {
			divElm = document.getElementById( divName );
			divElm.style.display = ""; 
		}catch( e ) { }
	}

	function hideDiv( divName ){
		try {
			divElm = document.getElementById( divName );
			divElm.style.display = "none"; 
		}catch( e ) { }
	}

