// JavaScript Document
//Animated Collapsible DIV- Author: Dynamic Drive (http://www.dynamicdrive.com)
//Last updated Aug 1st, 07'. Fixed bug with "block" parameter not working when persist is enabled
//Updated June 27th, 07'. Added ability for a DIV to be initially expanded.

var uniquepageid=window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, "") //get current page path and name, used to uniquely identify this page for persistence feature

function animatedcollapse(divId, animatetime, persistexpand, initstate){
	this.divId=divId
	this.divObj=document.getElementById(divId)
	this.divObj.style.overflow="hidden"
	this.timelength=animatetime
	this.initstate=(typeof initstate!="undefined" && initstate=="block")? "block" : "contract"
	this.isExpanded=animatedcollapse.getCookie(uniquepageid+"-"+divId) //"yes" or "no", based on cookie value
	this.contentheight=parseInt(this.divObj.style.height)
	var thisobj=this
	if (isNaN(this.contentheight)){ //if no CSS "height" attribute explicitly defined, get DIV's height on window.load
		animatedcollapse.dotask(window, function(){thisobj._getheight(persistexpand)}, "load")
		if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
			this.divObj.style.visibility="hidden" //hide content (versus collapse) until we can get its height
	}
	else if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes" && this.isExpanded!="") //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
		this.divObj.style.height=0 //just collapse content if CSS "height" attribute available
	if (persistexpand)
		animatedcollapse.dotask(window, function(){animatedcollapse.setCookie(uniquepageid+"-"+thisobj.divId, thisobj.isExpanded)}, "unload")
}

animatedcollapse.prototype._getheight=function(persistexpand){
	this.contentheight=this.divObj.offsetHeight
	if (!persistexpand && this.initstate=="contract" || persistexpand && this.isExpanded!="yes"){ //Hide DIV (unless div should be expanded by default, OR persistence is enabled and this DIV should be expanded)
		this.divObj.style.height=0 //collapse content
		this.divObj.style.visibility="visible"
	}
	else //else if persistence is enabled AND this content should be expanded, define its CSS height value so slideup() has something to work with
		this.divObj.style.height=this.contentheight+"px"
}


animatedcollapse.prototype._slideengine=function(direction){
	var elapsed=new Date().getTime()-this.startTime //get time animation has run
	var thisobj=this
	if (elapsed<this.timelength){ //if time run is less than specified length
		var distancepercent=(direction=="down")? animatedcollapse.curveincrement(elapsed/this.timelength) : 1-animatedcollapse.curveincrement(elapsed/this.timelength)
	this.divObj.style.height=distancepercent * this.contentheight +"px"
	this.runtimer=setTimeout(function(){thisobj._slideengine(direction)}, 10)
	}
	else{ //if animation finished
		this.divObj.style.height=(direction=="down")? this.contentheight+"px" : 0
		this.isExpanded=(direction=="down")? "yes" : "no" //remember whether content is expanded or not
		this.runtimer=null
	}
}


animatedcollapse.prototype.slidedown=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
			alert("Please wait until document has fully loaded then click again")
		else if (parseInt(this.divObj.style.height)==0){ //if content is collapsed
			this.startTime=new Date().getTime() //Set animation start time
			this._slideengine("down")
		}
	}
}

animatedcollapse.prototype.slideup=function(){
	if (typeof this.runtimer=="undefined" || this.runtimer==null){ //if animation isn't already running or has stopped running
		if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
			alert("Please wait until document has fully loaded then click again")
		else if (parseInt(this.divObj.style.height)==this.contentheight){ //if content is expanded
			this.startTime=new Date().getTime()
			this._slideengine("up")
		}
	}
}

animatedcollapse.prototype.slideit=function(){
	if (isNaN(this.contentheight)) //if content height not available yet (until window.onload)
		alert("Please wait until document has fully loaded then click again")
	else if (parseInt(this.divObj.style.height)==0)
		this.slidedown()
	else if (parseInt(this.divObj.style.height)==this.contentheight)
		this.slideup()
}

// -------------------------------------------------------------------
// A few utility functions below:
// -------------------------------------------------------------------

animatedcollapse.curveincrement=function(percent){
	return (1-Math.cos(percent*Math.PI)) / 2 //return cos curve based value from a percentage input
}


animatedcollapse.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
	var tasktype=(window.addEventListener)? tasktype : "on"+tasktype
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false)
	else if (target.attachEvent)
		target.attachEvent(tasktype, functionref)
}

animatedcollapse.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

animatedcollapse.setCookie=function(name, value){
		document.cookie = name+"="+value
}
//////////////////////////////////////////////////////////

// Password strength meter v1.0
// Matthew R. Miller - 2007
// www.codeandcoffee.com
// Based off of code from  http://www.intelligent-web.co.uk

// Settings
// -- Toggle to true or false, if you want to change what is checked in the password
var bCheckNumbers = true;
var bCheckUpperCase = true;
var bCheckLowerCase = true;
var bCheckPunctuation = true;
var nPasswordLifetime = 365;

// Check password
function checkPassword(strPassword)
{
	// Reset combination count
	nCombinations = 0;
	
	// Check numbers
	if (bCheckNumbers)
	{
		strCheck = "0123456789";
		if (doesContain(strPassword, strCheck) > 0) 
		{ 
        		nCombinations += strCheck.length; 
    		}
	}
	
	// Check upper case
	if (bCheckUpperCase)
	{
		strCheck = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		if (doesContain(strPassword, strCheck) > 0) 
		{ 
        		nCombinations += strCheck.length; 
    		}
	}
	
	// Check lower case
	if (bCheckLowerCase)
	{
		strCheck = "abcdefghijklmnopqrstuvwxyz";
		if (doesContain(strPassword, strCheck) > 0) 
		{ 
        		nCombinations += strCheck.length; 
    		}
	}
	
	// Check punctuation
	if (bCheckPunctuation)
	{
		strCheck = ";:-_=+\|//?^&!.@$£#*()%~<>{}[]";
		if (doesContain(strPassword, strCheck) > 0) 
		{ 
        		nCombinations += strCheck.length; 
    		}
	}
	
	// Calculate
	// -- 500 tries per second => minutes 
    	var nDays = ((Math.pow(nCombinations, strPassword.length) / 500) / 2) / 86400;
 
	// Number of days out of password lifetime setting
	var nPerc = nDays / nPasswordLifetime;
	
	return nPerc;
}
 
// Runs password through check and then updates GUI 
function runPassword(strPassword, strFieldID ,Lang)
{
	if(Lang == 'arb') {
	VSecure = 'آمن جداً';
	Secure  = 'أمن';
	Mediocre= 'متوسط الأمن';
	Insecure= 'غير آمن';		
	} else {
	VSecure = 'Very Secureً';
	Secure  = 'Secure';
	Mediocre= 'Mediocre';
	Insecure= 'Insecure';		
	}
	// Check password
	nPerc = checkPassword(strPassword);
	
	 // Get controls
    	var ctlBar = document.getElementById(strFieldID + "_bar"); 
    	var ctlText = document.getElementById(strFieldID + "_text");
    	if (!ctlBar || !ctlText)
    		return;
    	
    	// Set new width
    	var nRound = Math.round(nPerc * 100);
	if (nRound < (strPassword.length * 5)) 
	{ 
		nRound += strPassword.length * 5; 
	}
	if (nRound > 100)
		nRound = 100;
    	ctlBar.style.width = nRound + "%";
 
 	// Color and text
 	if (nRound > 95)
 	{
 		strText = VSecure;
 		strColor = "#3bce08";
 	}
 	else if (nRound > 75)
 	{
 		strText = Secure;
 		strColor = "orange";
	}
 	else if (nRound > 50)
 	{
 		strText = Mediocre;
 		strColor = "#ffd801";
 	}
 	else
 	{
 		strColor = "red";
 		strText = Insecure;
 	}
	ctlBar.style.backgroundColor = strColor;
	ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + "</span>";
}
 
// Checks a string for a list of characters
function doesContain(strPassword, strCheck)
 {
    	nCount = 0; 
 
	for (i = 0; i < strPassword.length; i++) 
	{
		if (strCheck.indexOf(strPassword.charAt(i)) > -1) 
		{ 
	        	nCount++; 
		} 
	} 
 
	return nCount; 
} 
 
 
 
 
 


///////////////////////////////////////
var xmlHttp
function GetXmlHttpObject(){
var xmlHttp=null;
try  { 
// Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
	catch (e)
	 {
		 // Internet Explorer
		 try        { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  }
		 catch (e)  {  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  }
	 }
return xmlHttp;
}
////////////////////////////////////////////////////////////////////////////////
function CheckUsrId(userid,lang) {
	
	//Replace Slashes to blank
	userid.replace(/^\s+/, '').replace(/\s+$/, '');
if (userid.length!=0) 
  {
	  var userfliter=/^[a-zA-Z0-9]+$/
      var returnval=userfliter.test(userid)
	  if(returnval == true) {
	  xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  } else {
document.getElementById("loder").style.display = document.getElementById("unamed").style.display   
var url = "ajaxscript/ajaxserverside.php";
var params = "userid="+userid;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) { 
		document.getElementById("loder").style.display = "none";
		if(xmlHttp.responseText == 1) {
			if(lang == 'arb') {
	    	 document.getElementById("unamed").innerHTML= " إسم المستخدم<img src='images/notavilable.jpg' /> :<strong style='color:green'>" + userid + "</strong>  مستخدم من قبل الرجاء إختيار إسم أخر  ";
			} else if(lang == 'eng') {
	    	 document.getElementById("unamed").innerHTML= "<img src='images/notavilable.jpg' /> User ID " + userid +" is not avilable  please change it.";
			 }//enf lang if
document.getElementById("r_uname").value = '';
document.getElementById("r_uname").style.backgroundColor="#FFFFCC";
} else {
			if(lang == 'arb') {
	    	 document.getElementById("unamed").innerHTML= "أسم المستخدم هذا متاح<img src='images/avilable.jpg' />";
			} else if(lang == 'eng') {
	    	 document.getElementById("unamed").innerHTML= "<img src='images/avilable.jpg' /> This User ID is available ";
			 }//enf lang if
document.getElementById("r_uname").style.backgroundColor="#ffffff";
}//end response if
	  }//end State if
}// end small function 



 
  }
xmlHttp.send(params);		
	  } else {
			if(lang == 'arb') {
	    	 document.getElementById("unamed").innerHTML= "إستخدم حروف إنجليزية فقط!!";
	    	 document.getElementById("r_uname").value = '';
			} else if(lang == 'eng') {
	    	 document.getElementById("unamed").innerHTML= "Use English Letters ONLY!!";
	    	 document.getElementById("r_uname").value = '';
			 userid = '';
			 }//enf lang if
	  }
	  
	  
  }
}
function CheckUsrIdCo(userid,lang) {
	
	//Replace Slashes to blank
	userid.replace(/^\s+/, '').replace(/\s+$/, '');
if (userid.length!=0) 
  {
	  var userfliter=/^[a-zA-Z0-9]+$/
      var returnval=userfliter.test(userid)
	  if(returnval == true) {
	  xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  } else {
document.getElementById("loder").style.display = document.getElementById("unamed").style.display   
var url = "ajaxscript/coajaxserverside.php";
var params = "userid="+userid;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) { 
		document.getElementById("loder").style.display = "none";
		if(xmlHttp.responseText == 1) {
			if(lang == 'arb') {
	    	 document.getElementById("unamed").innerHTML= " إسم المستخدم<img src='images/notavilable.jpg' /> :<strong style='color:green'>" + userid + "</strong>  مستخدم من قبل الرجاء إختيار إسم أخر  ";
			} else if(lang == 'eng') {
	    	 document.getElementById("unamed").innerHTML= "<img src='images/notavilable.jpg' /> User ID " + userid +" is not avilable  please change it.";
			 }//enf lang if
document.getElementById("r_uname").value = '';
document.getElementById("r_uname").style.backgroundColor="#FFFFCC";
} else {
			if(lang == 'arb') {
	    	 document.getElementById("unamed").innerHTML= "أسم المستخدم هذا متاح<img src='images/avilable.jpg' />";
			} else if(lang == 'eng') {
	    	 document.getElementById("unamed").innerHTML= "<img src='images/avilable.jpg' /> This User ID is available ";
			 }//enf lang if
document.getElementById("r_uname").style.backgroundColor="#ffffff";
}//end response if
	  }//end State if
}// end small function 



 
  }
xmlHttp.send(params);
	  } else {
			if(lang == 'arb') {
	    	 document.getElementById("unamed").innerHTML= "إستخدم حروف إنجليزية فقط!!";
	    	 document.getElementById("r_uname").value = '';
			} else if(lang == 'eng') {
	    	 document.getElementById("unamed").innerHTML= "Use English Letters ONLY!!";
	    	 document.getElementById("r_uname").value = '';
			 userid = '';
			 }//enf lang if
	  }
	
  }
}

//////////////////////////////////////////////////////////////////////////////////////////
function CheckJob(member) {
	
	//Replace Slashes to blank
	  xmlHttp=GetXmlHttpObject()
     if (xmlHttp==null)
	  {
	  alert ("Browser does not support HTTP Request")
	  return
	  } else {

	  
document.getElementById("loder").style.display = '';   
var url = "ajaxscript/checkmembrjobs.php";
var params = "memberid="+member;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) { 
		document.getElementById("loder").style.display = "none";
	    	 document.getElementById("memjob").innerHTML= xmlHttp.responseText;
	  }//end State if
}// end small function 
  }// end null if 
xmlHttp.send(params);		
	
  }// end function
//////////////////////////////////////////////////////////
function CheckEmail(email,lang) {
	
	//Replace Slashes to blank
	email.replace(/^\s+/, '').replace(/\s+$/, '');
if (email.length!=0) 
  {
	  xmlHttp=GetXmlHttpObject()
     if (xmlHttp==null)
	  {
	  alert ("Browser does not support HTTP Request")
	  return
	  } else {
	  
	  var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
      var returnval=emailfilter.test(email)
      ///this if statment to test the return value from testing email address// 					   
      if (returnval==false){
if(lang == 'arb') {
	    	 document.getElementById("email").innerHTML= "صيغة البريد غير صحيحة";
			} else if(lang == 'eng') {
	    	 document.getElementById("email").innerHTML= "Email format is not correct";
			 }//enf lang if
			document.getElementById("r_email").style.backgroundColor="#FFFFCC";
			 return;
	  } 

	  
document.getElementById("loder").style.display = document.getElementById("email").style.display   
var url = "ajaxscript/ajaxserverside.php";
var params = "email="+email;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) { 
		document.getElementById("loder").style.display = "none";
		if(xmlHttp.responseText == 1) {
			if(lang == 'arb') {
	    	 document.getElementById("email").innerHTML= "<img src='images/notavilable.jpg' /><strong>" + email + "</strong> مسجل لديناالرجاء إختيار بريد أخر.";
			} else if(lang == 'eng') {
	    	 document.getElementById("email").innerHTML= "<img src='images/notavilable.jpg' /><strong>" + email +"</strong> is Registered  please change it.";
			 }//enf lang if
document.getElementById("r_email").value = '';
document.getElementById("r_email").style.backgroundColor="#FFFFCC";
} else {
			if(lang == 'arb') {
	    	 document.getElementById("email").innerHTML= "هذا البريد غير مسجل لدينا<img src='images/avilable.jpg' />";
			} else if(lang == 'eng') {
	    	 document.getElementById("email").innerHTML= "<img src='images/avilable.jpg' /> This Email is not Registered";
			 }//enf lang if
document.getElementById("r_email").style.backgroundColor="#ffffff";
}//end response if
	  }//end State if
}// end small function 



	  
  }
xmlHttp.send(params);		
	
  }
}

function CheckEmailCo(email,lang) {
	
	//Replace Slashes to blank
	email.replace(/^\s+/, '').replace(/\s+$/, '');
if (email.length!=0) 
  {
	  xmlHttp=GetXmlHttpObject()
     if (xmlHttp==null)
	  {
	  alert ("Browser does not support HTTP Request")
	  return
	  } else {
	  
	  var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
      var returnval=emailfilter.test(email)
      ///this if statment to test the return value from testing email address// 					   
      if (returnval==false){
if(lang == 'arb') {
	    	 document.getElementById("email").innerHTML= "صيغة البريد غير صحيحة";
			} else if(lang == 'eng') {
	    	 document.getElementById("email").innerHTML= "Email format is not correct";
			 }//enf lang if
			document.getElementById("r_email").style.backgroundColor="#FFFFCC";
			 return;
	  } 

	  
document.getElementById("loder").style.display = document.getElementById("email").style.display   
var url = "ajaxscript/coajaxserverside.php";
var params = "email="+email;
xmlHttp.open("POST", url, true);

//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200) { 
		document.getElementById("loder").style.display = "none";
		if(xmlHttp.responseText == 1) {
			if(lang == 'arb') {
	    	 document.getElementById("email").innerHTML= "<img src='images/notavilable.jpg' /><strong>" + email + "</strong> مسجل لديناالرجاء إختيار بريد أخر.";
			} else if(lang == 'eng') {
	    	 document.getElementById("email").innerHTML= "<img src='images/notavilable.jpg' /><strong>" + email +"</strong> is Registered  please change it.";
			 }//enf lang if
document.getElementById("r_email").value = '';
document.getElementById("r_email").style.backgroundColor="#FFFFCC";
} else {
			if(lang == 'arb') {
	    	 document.getElementById("email").innerHTML= "هذا البريد غير مسجل لدينا<img src='images/avilable.jpg' />";
			} else if(lang == 'eng') {
	    	 document.getElementById("email").innerHTML= "<img src='images/avilable.jpg' /> This Email is not Registered";
			 }//enf lang if
document.getElementById("r_email").style.backgroundColor="#ffffff";
}//end response if
	  }//end State if
}// end small function 



	  
  }
xmlHttp.send(params);		
	
  }
}

///////// This function to dynamcly inser TR to tabke that containe information added by clinte /////


		
		
		/*
	This is the JavaScript file for the How to Create CAPTCHA Protection using PHP and AJAX Tutorial

	You may use this code in your own projects as long as this 
	copyright is left in place.  All code is provided AS-IS.
	This code is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	
	For the rest of the code visit http://www.WebCheatSheet.com
	
	Copyright 2006 WebCheatSheet.com	

*/
//Gets the browser specific XmlHttpRequest Object 
function getXmlHttpRequestObject() {
 if (window.XMLHttpRequest) {
    return new XMLHttpRequest(); //Mozilla, Safari ...
 } else if (window.ActiveXObject) {
    return new ActiveXObject("Microsoft.XMLHTTP"); //IE
 } else {
    //Display our error message
    alert("Your browser doesn't support the XmlHttpRequest object.");
 }
}

//Our XmlHttpRequest object
var receiveReq = getXmlHttpRequestObject();

//Initiate the AJAX request
function makeRequest(url, param) {
//If our readystate is either not started or finished, initiate a new request
 if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
   //Set up the connection to captcha_test.html. True sets the request to asyncronous(default) 
   receiveReq.open("POST", url, true);
   //Set the function that will be called when the XmlHttpRequest objects state changes
   receiveReq.onreadystatechange = updatePage; 

   receiveReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   receiveReq.setRequestHeader("Content-length", param.length);
   receiveReq.setRequestHeader("Connection", "close");

   //Make the request
   receiveReq.send(param);
 }   
}

//Called every time our XmlHttpRequest objects state changes
function updatePage() {
 //Check if our response is ready
 if (receiveReq.readyState == 4) {
   //Set the content of the DIV element with the response text
   //document.getElementById('result').innerHTML = receiveReq.responseText;
   //Get a reference to CAPTCHA image
   img = document.getElementById('secureimg'); 
   //Change the image
   img.src = 'include/create_image.php?' + Math.random();
 }
}

//Called every time when form is perfomed
function getParam(theForm) {
 //Set the URL
 var url = 'captcha.php';
 //Set up the parameters of our AJAX call
 var postStr = theForm.txtCaptcha.name + "=" + encodeURIComponent( theForm.txtCaptcha.value );
 //Call the function that initiate the AJAX request
 makeRequest(url, postStr);
}
