/*

browserType				return browser type: ie, ff, safari. (For anything else, returns FF!)
MM_preloadImages		Preload images, for situations like mouseover version of image
showFlash				Display flash object. Specify width, height, URL.
						NOTE: extra benefit: using this code solves IE problem of having to click on a flash object to activate it.
doBookmark				For bookmarking a page. [Note that this fails when running on local machine, so don't worry!]
						NOTE: works on IE and FF, but not on Safari.
getValue				return value of object, by ID
setValue				set value of object, by ID
found					true/false: does string contain substring?
empty					true/false: is object's value efectively empty?
isObject				true/false: does object with this ID exists?
isnull					true/false: is argument null? [function looks useful, but I haven't used it yet.]
removeWhiteSpace		remove extra spaces: 1. at beginning, 2. at end, 3. more than 1 consecutive
simpleCheck				check whether field, by id, contains pattern, return appropriate error messages
duplicate_stateChanged	Helper function for checkDup
checkDup				Use AJAX to check availability of selected email/username.
validate_email			email validation
validate_email			email validation -- also ensures email unique in system
validate_emailList		email validation for list of emails
checkAvailability		Call to checkDup to pre-check whether selection is a duplicate
validate_emailConfirm	ensure emails match
validate_user_password	called by the following two
validate_password		password validation: 1. At least 6 characters. 2. Numbers and letters only.
validate_username		username validation: 1. At least 6 characters. 2. Numbers and letters only.
validate_passwordConfirmensure passwords match
validate_genericPhone	phone validation. Simply ensures contains at least 9 digits.
						Problematic to get more specific, because each country has different format.
validate_zipcode		zipcode validation: checks for US and Canada only. Use global variable to indicate whether or not required.
						ASSUMES: presence of object with id "country"
mod10					helper function for validate_ccNumber
validate_ccNumber		credit card number validation
						ASSUMES: presence of object with id "ccType"
badCCcode				helper function for validate_ccCode
validate_ccCode			validate 3-digit credit card code (4-digits for amex). Use global variable to indicate whether or not required.
						ASSUMES: presence of object with id "ccType"
						NOTE: not clear that this field is really all that critical
checkFields				loop and check all fields in a form. Assumes submit button has id of formSubmitButton.
numbersOnly				ensure user types in digits only for number field
FFcheckKey				helper function: No-paste: Prevent control-v on FF
SafaricheckKey			helper function: No-paste: Prevent control-v on Safari (doesn't work on keydown, so I had to kludge it on keyup!)
MScheckKey				helper function: No-paste: Prevent control-v on MS
FFnoPaste				helper function: No-paste: Prevent right-click on FF
MSnoPaste				helper function: No-paste: Prevent right-click on FF
noPaste					No-paste: Put all of the above together, for confirm fields
loadAttacher			Attach "onload", for ie, ff, safari
touchDown				If someone puts cursor in text field, remove default text
leaveField				If someone leaves text field without typing anything, restore default text
setInputs				Function that allows input sub-types to have classes, like input.text.
GetXmlHttpObject		Create object for AJAX. The code I borrowed has a separate clause for ie, but for me, the first clause works fine for ie!
						NOTE: Ezequiel may have found something better, something to do with portability.

NOTES:

1. FOR MOST VALIDATION FUNCTIONS, NO ERROR RETURNED IF FIELD IS EMPTY.
2. I HAD A URL VALIDATION FUNCTION, BUT DON'T KNOW IF IT WAS CORRECT. ANYWAY, ARE THERE ANY CHARACTERS, BESIDES SPACE, THAT ARE INVALID FOR URL?
3. I'D LIKE TO HAVE A GENERIC TEXT FIELD FUNCTION, BUT IT ALWAYS SEEMS TO GIVE ME PROBLEMS, IN THAT PEOPLE TELL ME THAT THEIR INPUT IS REJECTED.

*/

var PASSWORD =				"Password"
var USERNAME =				"Username"

var BAD_EMAIL =				"Please enter a valid email address."
var BAD_EMAILMATCH =		"The two emails you have entered do not match."
var BAD_PASSWORDMATCH =		"The two passwords you have entered do not match."
var REQUIRED =				"Required Field"
var NOPASTE =				"You may not paste into this field. Please type in the information."
var ATLEASTONE	=			"Please select at least one:"
var BAD_USER_SMALL =		"Username must contain at least six characters."
var BAD_USER_CHARS =		"Username may contain numbers and letters only."
var BAD_PASSWORD_SMALL =	"Password must contain at least six characters."
var BAD_PASSWORD_CHARS =	"Password may contain numbers and letters only."

var NOFAVORITES =			"Your browser does not support automatic bookmarking. You must bookmark this page manually."

var BAD_PHONE =				"Please enter a valid phone number."
var BAD_ZIPCODE_US =		"Please enter a 5-digit zip code."
var BAD_ZIPCODE_CANADA =	"Please enter a postal code, in the form 'M8M 3N3'."
var BAD_CCNUMBER =			"Please enter a valid credit card number."
var BAD_CCCODE1 =			"Please enter a "
var BAD_CCCODE2 =			"-digit security code."
var HEBREWSTRING =			""
var ZIP_REQUIRED =			true
for (i = 1488; i <= 1514; i++)
	HEBREWSTRING += String.fromCharCode(i)

function browserType () {
	if (found(navigator.appName, "Microsoft"))
		return "IE"
	if (navigator.userAgent.search(/Chrome/i) != -1)
		return "Google"
	if (navigator.userAgent.search(/Safari/i) != -1)
		return "Safari"
	if (navigator.userAgent.search(/Firefox/i) != -1)
		return "FF"
	return "FF"
}

function MM_preloadImages () { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function showFlash (width, height, URL) {
	//DON'T KNOW IF ALIGN NECESSARY
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '" align="middle">')
	document.write('<param name="movie" value="' + URL + '" />')
	document.write('<param name="quality" value="high" />')
	//THIS NEXT ONE SO THAT DROPDOWN MENUS HANGING OVER FLASH DON'T DISAPPEAR
	document.write('<param name="wmode" value="opaque">')
	//DON'T KNOW WHAT THIS DOES
	document.write('<param name="allowScriptAccess" value="sameDomain" />')
	//DON'T KNOW IF NECESSARY, BUT IT CAUSED THE FLASH IN ALIYAH JOB CENTER TO DISAPPEAR, SO DISABLING IT -- ALSO REMOVED bgcolor="#ffffff" FROM FINAL EMBED
	//document.write('<param name="bgcolor" value="#ffffff" />')
	//THE EMBED STATEMENT HAS ONE PROPERTY MATCHING EVERYTHING ABOVE, PLUS TYPE AND PLUGINSPAGE
	document.write('<embed width="' + width + '" height="' + height + '" align="middle" src="' + URL + '" quality="high" wmode="opaque" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />')
	document.write('</object>')
}

function getSite (href) {
	return href.replace(/^(http:\/\/[^\/]+)\/.*$/, "$1")
}

function doBookmark (title, href) {
	if (browserType() == "IE")
		window.external.AddFavorite(href, title)
	else if (window.sidebar)
		window.sidebar.addPanel(title, href, "")
	else
		alert(NOFAVORITES)
}

function bookmark_this_page () {
	doBookmark(document.title, window.location.href)
}

function getValue (id) {
	return document.getElementById(id).value
}

function getValueInOpener (id) {
	return window.opener.document.getElementById(id).value
}

function getHTMLInOpener (id) {
	return window.opener.document.getElementById(id).innerHTML
}

function setValue (id, value) {
	document.getElementById(id).value = value
}

function found (haystack, needle) {
	return haystack.search(needle) != -1
}

function empty (value) {
	return found(value, /^\s*$/)
}

function isObject (myID) {
	return (document.getElementById(myID) + "").search(/^\[object.*\]$/) != -1
}

function isObjectInOpener (myID) {
	return (window.opener.document.getElementById(myID) + "").search(/^\[object.*\]$/) != -1
}

function isnull (arg) {
	arg = arg + '';
	return (arg == '' || arg == 'null' || arg == 'undefined')
}

function removeWhiteSpace (myObject) {
	setValue(myObject.id, myObject.value.replace(/(^ *| *$)/g, "").replace(/ +/g, " "))
}

function simpleCheck (id, pattern, message) {
	myValue = getValue(id)
	if (empty(myValue))
		return ""
	return found(myValue, pattern) ? "" : message
}

function checkDup (field, table) {
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null) {
		return "Your browser does not support AJAX!"
	}
	myValue = getValue(field)
	var url = "/library/duplicateCheck.php?table=" + table + "&field=" + field + "&value=" + myValue + "&id=" + id
	xmlHttp.open("GET" , url , false)
	try {
		xmlHttp.send()
	}
	catch (e) {
		xmlHttp.send(null)
	}
	return xmlHttp.responseText == 0 ? "" : "The " + field + " '" + myValue + "' already exists in our system. Please choose another."
}

function validate_email (id) {
	return simpleCheck(id, /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/, BAD_EMAIL)
}

function validate_email_noDups_company (id) {
	if (simpleCheck(id, /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/, BAD_EMAIL) != "")
		return BAD_EMAIL
	return checkDup("email", "company")
}

function validate_email_noDups_jobSeeker (id) {
	if (simpleCheck(id, /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/, BAD_EMAIL) != "")
		return BAD_EMAIL
	result = checkDup("email", "jobSeeker")
	return result == "" ? "" : (result + "\n\nIf you are an existing member attempting to renew your account,\n" +
		"then instead of using this form, please login and select the 'Renew my account' option.")
}

function validate_emailList (id) {
	document.getElementById(id).value = document.getElementById(id).value.
		replace(/\s*$/, "").
		replace(/;/g, ",").
		replace(/[, ]+/g, ",").
		replace(/(^[ ,]*|[ ,]*$)/g, "")
	if (empty(getValue(id)))
		return ""
	emailList = document.getElementById(id).value.split(",")
	if (emailList.length > 10)
		return "You have entered more than 10 email addresses.\nPlease check this entry and try again."
	for (i = 0; i < emailList.length; i++)
		if (emailList[i].search(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/) == -1)
			return "The e-mail address '" + emailList[i] + "' is not a valid e-mail address.\nPlease check your entry and try again."
	return ""
}

function checkAvailability (field, validation) {
	if ((result = eval("validate_" + validation + "('" + field + "')")) == "") {
		alert("The " + field + " '" + document.getElementById(field).value + "' is available.")
	}
	else {
		alert(result)
		document.getElementById(field).focus()
	}
}

function validate_emailConfirm (id) {
	return getValue(id) == getValue("email") ? "" : BAD_EMAILMATCH
}

function validate_user_password (id, errorField) {
	myValue = getValue(id)
	if (empty(myValue))
		return ""
	if (myValue.length < 6)
		return errorField == USERNAME ? BAD_USER_SMALL : BAD_PASSWORD_SMALL
	return simpleCheck(id, /^[a-zA-Z0-9]*$/, errorField == USERNAME ? BAD_USER_CHARS : BAD_PASSWORD_CHARS)
}

function validate_password (id) {
	return validate_user_password(id, PASSWORD)
}

function validate_username (id) {
	if ((result = validate_user_password(id, USERNAME)) != "")
		return result
	return checkDup("username")
}

function validate_passwordConfirm (id) {
	return getValue(id) == getValue("password") ? "" : BAD_PASSWORDMATCH
}

function validate_genericPhone (id) {
	return simpleCheck(id, /(\d.*){9}/, BAD_PHONE)
}

function validate_zipcode (id) {
	myValue = getValue(id)
	if (!ZIP_REQUIRED && empty(myValue))
		return
	country = getValue("country")
	if (country == "United States")
		return found(myValue, /^\d{5}$/) ? "" : BAD_ZIPCODE_US
	if (country == "Canada")
		return found(myValue, /^[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d$/) ? "" : BAD_ZIPCODE_CANADA
	return ""
}

function mod10 (ccNumber) {
	var ary = new Array(ccNumber.length)
	var i = 0, sum = 0
	for (i = 0; i < ccNumber.length; i++)
		ary[i] = parseInt(ccNumber.charAt(i))
	for (i = ary.length - 2; i >= 0; i -= 2) {
		ary[i] *= 2
		if (ary[i] > 9)
			ary[i] -= 9
	}
	for (i = 0; i < ary.length; i++)
		sum += ary[i]
	return sum % 10 == 0
}

function validate_ccNumber (id) {
	//http://www.sitepoint.com/article/card-validation-class-php
	/*	VALID CC #'s:
		VISA:		4444333322221111
		DISCOVER:	6011111111111117
		MC:			5123456789012346
		AMEX:		343434343434343
		DINERS:		30569309025904
	*/

	myValue = getValue(id)
	if (empty(myValue))
		return ""
	testValue = myValue.replace(/[ \-]/g, "")
	switch (getValue("ccType")) {
	case "Visa":
		pattern = /^4\d{12}(\d{3})?$/
		break
	case "Discover":
		pattern = /^6011\d{12}?$/
		break
	case "Mastercard":
		pattern = /^5[1-5]\d{14}$/
		break
	case "American Express":
		pattern = /^3[47]\d{13}?$/
		break
	case "Diners Club":
		pattern = /^3(0[0-5]|[68]\d)\d{11}$/
		break
	case "Isracard":	//CHECKED HERE TO AVOID MOD10
		pattern = /^\d{8}$/
		if (found(testValue, pattern)) {
			setValue(id, testValue)
			return ""
		}
		return BAD_CCNUMBER
		break
	}
	if (found(testValue, pattern) && mod10(testValue)) {
		setValue(id, testValue)
		return ""
	}
	return BAD_CCNUMBER
}

function badCCcode (param) {
	return BAD_CCCODE1 + param +  BAD_CCCODE2
}

function validate_ccCode (id) {
	if (getValue("ccType") == "American Express") {
		param = "3- or 4"
		pattern = /^\d{3,4}$/
	}
	else {
		param = 3
		pattern = /^\d{3}$/
	}
	return simpleCheck(id, pattern, badCCcode(param))
}

var debug = false

function checkFields () {
	var invalidField = ""
	var message = ""
	if (debug)
		alert("In checkfields")
	
	for (var i in fieldIDs) {
		if (debug)
			alert(i + ": " + fieldIDs[i])
		if (document.getElementById(fieldIDs[i])) {
			currentObject = document.getElementById(fieldIDs[i])
			if (currentObject.type == "text" || currentObject.type == "textArea")
				removeWhiteSpace(currentObject)
			if (!currentObject.disabled) {
				if (debug)
					alert("Req: " + fieldRequireds[i] + ". Valid: " + fieldValidations[i] + ". Value: " + currentObject.value)
				if ((fieldRequireds[i] && empty(currentObject.value)) ||
					(fieldValidations[i] &&
					(message = eval("validate_" + fieldValidations[i] + "('" + fieldIDs[i] + "')")) != "")) {
						invalidField = fieldIDs[i]
						break
				}
			}
		}
	}
	if (debug)
		alert("Out of loop")
	if (checkFields.arguments.length == 1)
		return invalidField == ""
	if (invalidField != "") {
		alert(message == "" ? REQUIREDFIELD + ": " + fieldLabels[i] : message)
		document.getElementById(invalidField).focus()
		return false
	}
	if (isObject("formSubmitButton"))
		document.getElementById("formSubmitButton").disabled = true
	else if (isObject("submitTD"))
		setTimeout("disableButton()", 10)
	return true
}

function disableButton () {
	if (isObject("submitTD")) {
		if (isObject("waitTD")) {
			document.getElementById("submitTD").style.display = "none"
			document.getElementById("waitTD").style.display = ""
			//wait_loadingDots()
		}
		else
			document.getElementById("submitTD").innerHTML = PLEASEWAIT
	}
}

var nWaitDots = 1
function wait_loadingDots () {
	nWaitDots++
	if (nWaitDots > 4)
		nWaitDots = 1
	var myString = ""
	var i
	for (i = 0; i < nWaitDots; i++)
		myString += ". "
	document.getElementById("waitDots").innerHTML = myString
	setTimeout("wait_loadingDots()", 300)
}

function numbersOnly (myField, e, decimal) {
	 var key, keyChar
	 if (window.event)
		 key = window.event.keyCode
	 else if (e)
		 key = e.which
	 else
		 return true
	 keyChar = String.fromCharCode(key)
	 // control keys
	 if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27))
		 return true
	 // numbers
	 else if (("0123456789").indexOf(keyChar) > -1)
		 return true
	// decimal point jump -- jump to the next field. code not working at this point.
	 else if (decimal && (keyChar == ".")) {
		myField.form.elements[decimal].focus()
		return false
	 }
	 else
		return false
}

function number_format(number, decimals, dec_point, thousands_sep) {
    // Formats a number with grouped thousands  
    // 
    // version: 1006.1915
    // discuss at: http://phpjs.org/functions/number_format
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'
    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    var n = !isFinite(+number) ? 0 : +number, 
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
}

function FFcheckKey (event) {
	if (event.which == 118 && event.ctrlKey == true) {
		alert(NOPASTE)
		event.preventDefault()
	}
}

function SafaricheckKey (event) {
	if (event.which == 86 && event.ctrlKey == true) {
		event.srcElement.value = ""
		alert(NOPASTE)
		event.preventDefault()
	}
}

function MScheckKey () {
	if (event.keyCode == 86 && event.ctrlKey) {
		alert(NOPASTE)
		return false
	}
	return true
}

function FFnoPaste (event) {
	alert(NOPASTE)
	event.preventDefault()
}

function MSnoPaste () {
	alert(NOPASTE)
	return false
}

function noPaste (myID) {
	myObject = document.getElementById(myID)
	if (browserType() == "IE") {
		myObject.onkeydown = MScheckKey
		myObject.oncontextmenu = MSnoPaste
	}
	else {
		if (browserType() == "Safari")
			myObject.addEventListener("keyup", SafaricheckKey, false)
		else
			myObject.addEventListener("keypress", FFcheckKey, true)
		myObject.addEventListener("contextmenu", FFnoPaste, true)
	}
}

function loadAttacher (loadFunc) {
	if (window.addEventListener) {
		window.addEventListener("load", loadFunc, false)
	}
	else if (document.addEventListener) {
		document.addEventListener("load", loadFunc, false)
	}
	else if (window.attachEvent) {
		window.attachEvent("onload", loadFunc)
	}
}

function touchdown (myInput, defaultText) {
	if (myInput.value == defaultText) {
		myInput.style.textAlign = "left"
		myInput.value = ""
	}
}

function leaveField (myInput, defaultText) {
	if (myInput.value == "") {
		myInput.value = defaultText
	}
}

function setInputs () {
	var myElements = document.getElementsByTagName("input")
	var i
	for (i = 0; i < myElements.length; i++) {
		if (myElements[i].getAttribute("type")) {
			if (myElements[i].getAttribute("type") == "text")
				myElements[i].className += " text"
			else if (myElements[i].getAttribute("type") == "password")
				myElements[i].className += " password"
			else if (myElements[i].getAttribute("type") == "button")
				myElements[i].className += " button"
			else if (myElements[i].getAttribute("type") == "submit")
				myElements[i].className += " button"
			else if (myElements[i].getAttribute("type") == "file")
				myElements[i].className += " file"
			myElements[i].className = myElements[i].className.replace(/^ /, "")
		}
	}
}

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 validate_url (id) {
	return simpleCheck(id, /^http:\/\//, "URL must begin with 'http://'")
}

function validate_address (id) {
	return getValue(id).length > 200 ? ("Address must not exceed 200 characters in length. (Your address contains " + getValue(id).length + " characters.)") : ""
}

function validate_textarea_max (id, name, max_chars) {
	return getValue(id).length > max_chars ? (name + " field must not exceed " + max_chars + " characters in length. (You have entered " + getValue(id).length + " characters.)") : ""
}

/*	DON'T KNOW ABOUT THIS ONE	*/

function okay_text (fieldValue) {
	if(fieldValue == '')
		return true	
//	var RE = new RegExp("^[a-zA-Z0-9 ,\\.\\-\\/\\;\\:!@\\#\\%\\*\\?+=$\\&\\)\\(<>" + hebrewString + "]*$")
	var RE = new RegExp("[0-9A-Za-z\\d\\s\\t\\r\\n\\:\\;\\!\\@\\#\\%\\*\\+\\?\\-\\=\\$,&\\.\\'\"\\(\\)\\[\\]\\/ ²–ÌÀÌÀÀÆ®™•’“" + HEBREWSTRING + "]", "g")
		return (fieldValue.search(RE) != -1)
}

function handleNewline (myText) {
	return myText.replace(/###NEWLINE###/g, "\r\n")
}

function addField (myID, myLabel, myRequired, myValidate, myMax) {
	fieldIDs.push(myID)
	fieldLabels.push(myLabel)
	fieldRequireds.push(myRequired)
	fieldValidations.push(myValidate)
	if (isnull(document.getElementById(myID).getAttribute("name")))
		document.getElementById(myID).setAttribute("name", myID)
	if (myMax)
		document.getElementById(myID).setAttribute("maxLength", myMax)
}

function disableElements (parentTR, fieldType, myBoolean) {
	var myElements = document.getElementById(parentTR).getElementsByTagName(fieldType)
	for (var i = 0; i < myElements.length; i++) {
		myElements[i].style.display = myBoolean ? "none" : ""
		myElements[i].disabled = myBoolean
	}
}

function checkDependentTR (parentID, childTR, firstField) {
	yesDisplay = browserType() == "IE" ? "block" : "table-row"
	parentElement = document.getElementById(parentID)
	if (parentElement.type.search(/select/i) != -1)
		myDisplay = parentElement.selectedIndex == parentElement.options.length - 1 ? yesDisplay : "none"
	else
		myDisplay = parentElement.checked ? yesDisplay : "none"
	document.getElementById(childTR).style.display = myDisplay

	myBoolean = myDisplay == "none"
	disableElements(childTR, "input", myBoolean)
	disableElements(childTR, "textarea", myBoolean)
	disableElements(childTR, "select", myBoolean)

	if (myDisplay == yesDisplay)
		document.getElementById(firstField).focus()
}

function checkRadio (parentID, fieldLabel) {
	var myElements = document.getElementById(parentID).getElementsByTagName("input")
	for (i = 0; i < myElements.length; i++)
		if (myElements[i].checked)
			return ""
	return REQUIREDFIELD + ": " + fieldLabel
}

function checkCheckbox (parentID, fieldLabel) {
	var myElements = document.getElementById(parentID).getElementsByTagName("input")
	for (i = 0; i < myElements.length; i++)
		if (myElements[i].checked)
			return ""
	return ATLEASTONE + ": " + fieldLabel
}

function validate_agreement (id) {
	return checkCheckbox("agreement_parent", "xx") == "" ? "" : "Please indicate your agreement with the conditions."
}

function paymentClick () {
	myDisabled = !document.getElementById("Credit Card").checked
	ccFields = new Array("ccType", "ccNumber", "cvv", "ccExpMonth", "ccExpYear", "ccName")
	for (i = 0; i < ccFields.length; i++) {
		document.getElementById(ccFields[i]).disabled = myDisabled
		if (myDisabled)
			document.getElementById(ccFields[i]).value = ""
	}
}
	
function createCookie (name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		var expires = ";expires=" + date.toGMTString();
	}
	else
		var expires = "";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie (name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ')
			c = c.substring(1, c.length);
		if (c.indexOf(nameEQ) == 0)
			return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie (name) {
	createCookie(name, "", -1);
}

function fixBodyHeight () {
	if (browserType() == "IE")
		return
	var extraHeight = parseInt(window.innerHeight) - parseInt(document.getElementById("mainArea2").clientHeight)
	if (window.location.href.search(/jobApplicationForm/) != -1)
		extraHeight -= 38
	var myDiv = document.createElement("div")
	myDiv.style.height = extraHeight + "px"
	document.body.appendChild(myDiv)
}

function doEncrypt (myString) {
	var result = "";
	var i;
	for (i = 0; i < myString.length; i++)
		result += "&#" + myString.charCodeAt(i) + ";";
	return result;
}

function doMailto (to) {
	mailto = doEncrypt("mailto:");
	email = doEncrypt(to);
	anchorText = to
	extra = ""
	subject = ""
	if (doMailto.arguments.length >= 2 && doMailto.arguments[1] != "")
		subject = doEncrypt("?subject=" + doMailto.arguments[1]);
	else
		subject = ""
	if (doMailto.arguments.length >= 3 && doMailto.arguments[2] != "")
		anchorText = doMailto.arguments[2];
	else
		anchorText = to
	if (doMailto.arguments.length == 4 && doMailto.arguments[3] != "")
		extra = doMailto.arguments[3];
	else
		extra = ""
	return '<a extra href="' + mailto + email + subject + '">' + anchorText + "</a>"
}

