﻿function go()
{
location=document.forms[0].gowhere.value

}

/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Check if a string is in valid email format. 
Returns true if valid, false otherwise.
*/
function validEmail(str)
{
	var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	return regex.test(str);
}

function validUrl(str)
{
	var regex = /^[-_.a-z0-9]+.(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	return regex.test(str);
}
	


	function isNumOnly(passedVal) {					// Is this a number?
			if (passedVal == "") {
				return false
			}
			for (i=0; i<passedVal.length; i++) {
				if (passedVal.charAt(i) < "0") {
					return false
				}
				if (passedVal.charAt(i) > "9") {
					return false
				}
			
			}
			return true
		}
		
	function isNum(passedVal) {					// Is this a number?
			if (passedVal == "") {
				return false
			}
			for (i=0; i<passedVal.length; i++) {
				if (passedVal.charAt(i) < "0") {
					return false
				}
				if (passedVal.charAt(i) > "9") {
					return false
				}
				if (passedVal.charAt(i) > "-") {
					return true
				}
			}
			return true
		}
		

		
		function validZip(inZip) {					// Is this Empty?
			if (inZip == "") {
				return false
			}
						
			if (isNum(inZip)) {						// Check if Zip is numeric
				return true
			}
			return false
		}
		
			function validNumOrEmpty(inZip) {					// Is this Empty or Number?
			if (inZip == "") {
				return true
			}
						
			if (isNum(inZip)) {						// Check if Zip is numeric
				return true
			}
			return false
		}
		
			function validZipCode(inZip) {					// Is this a valid Zip code?
		
			if (inZip.length != 5) {
				return false
			}
			
			if (inZip == "") {
				return false
			}
			
			
			if (isNum(inZip)) {						// Check if Zip is numeric
				return true
			}
			return false
		}
		
			function validPhoneNumber(inZip) {					// Is this a valid Zip code?
		
			if (inZip.length < 6) {
				return false
			}
			
			if (inZip == "") {
				return false
			}
			
			
			if (isNum(inZip)) {						// Check if Zip is numeric
				return true
			}
			return false
		}
		
		
		

		function validPip(inPip) {					// Is this a valid Zip code?
			if (inPip == "") {
				return false
			
			}
			
			return true
				
}


	

	function checkPassword (inPip) {

			if (inPip == "") {
			
			return false
			
			}
					
    var illegalChars = /[\W_]/; // allow only letters and numbers
    if ((inPip.length < 6) || (inPip.length > 15)) {
      return false
    }
		
    if (illegalChars.test(inPip)) {
    return false
    }



	return true
						
}

function checkUserName (inPip) {

	var illegalChars = /[^a-zA-Z0-9_-]/; // allow only letters and numbers And underScore

			if (inPip == "") {
			
			return false
			
			}
					
    
    if ((inPip.length < 3) || (inPip.length > 12)) {
      return false
    }
		
    if (illegalChars.test(inPip)) {
    return false
    }

	return true
						
}

// AJAX //
var xmlHttp // xmlHttp variable

function GetXmlHttpObject(){ // This function we will use to call our xmlhttpobject.
var objXMLHttp=null // Sets objXMLHttp to null as default.
if (window.XMLHttpRequest){ // If we are using Netscape or any other browser than IE lets use xmlhttp.
objXMLHttp=new XMLHttpRequest() // Creates a xmlhttp request.
}else if (window.ActiveXObject){ // ElseIf we are using IE lets use Active X.
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") // Creates a new Active X Object.
} // End ElseIf.
return objXMLHttp // Returns the xhttp object.
} // Close Function

function CheckUsername(username){ // This function we will use to check to see if a username is taken or not.
xmlHttp=GetXmlHttpObject() // Creates a new Xmlhttp object.
if (xmlHttp==null){ // If it cannot create a new Xmlhttp object.
alert ("Browser does not support HTTP Request") // Alert Them!
return // Returns.
} // End If.

var url="config/ajax.php?username="+username // Url that we will use to check the username.
xmlHttp.open("GET",url,true) // Opens the URL using GET

xmlHttp.onreadystatechange = function () { // This is the most important piece of the puzzle, if onreadystatechange is equal to 4 than that means the request is done.
if (xmlHttp.readyState == 4) { // If the onreadystatechange is equal to 4 lets show the response text.
document.getElementById("Domainerror").innerHTML = xmlHttp.responseText; // Updates the div with the response text from check.php
} // End If.
}; // Close Function
xmlHttp.send(null); // Sends NULL instead of sending data.
} // Close Function.

// AJAX //

function  CheckNForm(form, InitialValue) {

		document.forms[0].SubmitIt.disabled=true;
		document.forms[0].SubmitIt.value='בודק נתונים';

		if (!CheckRegisterForm(form)) {
		document.forms[0].SubmitIt.disabled = false
		document.forms[0].SubmitIt.value = InitialValue
		return false
		}
		
		document.forms[0].SubmitIt.value = 'מבצע הרשמה'
		return true
}

		function CheckRegisterForm(form) {
		
	
		
		
	
		
		if (!validPip (trim(form.FirstName.value))) {
			//	alert("First Name Field Is Mandatory")		
				document.getElementById('error').innerHTML = "אנא הקלד את שימך הפרטי!";
				form.FirstName.focus()
				form.FirstName.select()
				form.FirstName.style.background = '#E6F4F5'; 
				
				return false
			}
			

					
			
			
			if (!validPhoneNumber(trim(form.Phone.value))) {
				document.getElementById('error').innerHTML = "אנא הקלד את מספר הטלפון או הנייד שלך!";
				form.Phone.focus()
				form.Phone.select()
				form.Phone.style.background = '#E6F4F5'; 
				return false
			}
			
			// check to see if the email's valid
			if (!validEmail(trim(form.ContactEmail.value))) {
				document.getElementById('error').innerHTML = "אנא הקלד כתובת דואר אלקטרוני פעילה!";
				form.ContactEmail.focus()
				form.ContactEmail.select()
			form.ContactEmail.style.background = '#E6F4F5'; 
				return false
			}
			
			
		

			return true

		}
	
	
		
