function preloader() 
{
heavyImage = new Image(); 
heavyImage.src = "images/checkbox-marked.png";
heavyImage = new Image(); 
heavyImage.src = "images/greenBtn_clicked.png";
}
function changeCheck()
{
	checkVal=document.getElementById("allpolicy");
	checkImg=document.getElementById("checkboxImg");
	
	if(checkVal.value=="on")
	{
		checkVal.value="";
		checkImg.className="checkBoxOff";		
	}
	else
	{
		checkVal.value="on";
		checkImg.className="checkBoxOn";		
		
	}
	
}

function clearField(f, val)
{	
	if(f.value==val)
	{
		f.value='';
		f.style.color='black';
	}

}


// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkChar(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);
  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode<48 || (cCode>57 &&cCode < 65) || (cCode > 90 && cCode<97) || cCode>122 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}


function passwordChanged() {
		var weakDiv = document.getElementById('weak');
		var normalDiv = document.getElementById('normal');
		var strongDiv = document.getElementById('strong');
		
		var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
		var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
		var enoughRegex = new RegExp("(?=.{5,}).*", "g");
		var pwd = document.getElementById("password");
		if (pwd.value.length==0) {
			weakDiv.style.background="white";
			normalDiv.style.background="white";
			strongDiv.style.background="white";
		} else if (false == enoughRegex.test(pwd.value)) {
			weakDiv.style.background="white";
			normalDiv.style.background="white";
			strongDiv.style.background="white";
		} else if (strongRegex.test(pwd.value)) {
			weakDiv.style.background="url(images/red.gif)";
			normalDiv.style.background="url(images/yellow.gif)";
			strongDiv.style.background="url(images/green.gif)";
		} else if (mediumRegex.test(pwd.value)) {
			weakDiv.style.background="url(images/red.gif)";
			normalDiv.style.background="url(images/yellow.gif)";
			strongDiv.style.background="white";
		} else {
			weakDiv.style.background="url(images/red.gif)";
			normalDiv.style.background="white";
			strongDiv.style.background="white";
		}
	}
function checkEmail(email) {

	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		return false;
	} else {
		return true;
	}
}


function ajaxCheckEmail(email)
{
	url="ajax/checkEmail.php?email="+email;
	ret=LoadHTML(url);
	return ret;
}

function checkHowToForm(myForm) {

	send = true;
	errormessage = "הבעיות הבאות נתגלו בטופס:\r\n";		
	if (document.getElementById("firstname").value=="" || document.getElementById("firstname").value=="First") {		
		send = false;
		errormessage += "שם פרטי\r\n";
	}
	if (document.getElementById("lastname").value=="" || document.getElementById("lastname").value=="Last") {		
		send = false;
		errormessage += "שם משפחה\r\n";
	}
	
	if (document.getElementById("username").value=="") {		
		send = false;
		errormessage += "שם משתמש\r\n";
	}
	else {
		
		url="ajax/checkusername.php?u="+document.getElementById("username").value;
			ret=LoadHTML(url);
			if(ret=="1")
			{
				send = false;
				errormessage += "שם משתמש תפוס\r\n";
			} 
		
	}
	
	if (document.getElementById("password").value=="") {		
		send = false;
		errormessage += "סיסמה\r\n";
	}
	
	
	
	
	if (document.getElementById("email").value=="" || !checkEmail(document.getElementById("email").value)) {	
		send = false;
		errormessage += "דואר אלקטרוני שגוי\r\n";
	} 
	else
	{
		
	if(ajaxCheckEmail(document.getElementById("email").value)=="1")
	{
		send = false;
		errormessage += 'כתובת הדוא"ל כבר רשומה באתר\r\n';
	
	}
		
		
	}
	
	
	
	
		if (document.getElementById("allpolicy").value != "on") {
			send = false;
			errormessage += "אישור הסכמי מדיניות \r\n";
		}
	
	
	if (send) {
		myForm.submit();
	} else {
		alert(errormessage);
		return false;
	}
}


function getHTTPObject()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
 }

function LoadHTML(url)
{

	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;

	}
	xmlHttp.send(null);
	return xmlHttp.responseText;
}
function LoadXML(url)
{
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, true);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;
	};
	xmlHttp.send(null);
	return xmlHttp.responseXML.documentElement;
}



