function formControls() {
	if (document.getElementById("StartOption")) {
		startOption = document.getElementById("StartOption");
		startOption.onchange = new Function("showDateSelect('Start')");
		showDateSelect('Start');
	}
	if (document.getElementById("EndOption")) {
		endOption = document.getElementById("EndOption");
		endOption.onchange = new Function("showDateSelect('End')");
		showDateSelect('End');
	}
	if (document.getElementById("quickRegistration")) {
		qrFirstName = document.getElementById("quickRegistration").FirstName;
		qrFirstName.onfocus = new Function("focusValues(qrFirstName, 'First Name*')");
		qrFirstName.onblur = new Function("blurValues(qrFirstName, 'First Name*')");
		qrLastName = document.getElementById("quickRegistration").LastName;
		qrLastName.onfocus = new Function("focusValues(qrLastName, 'Last Name*')");
		qrLastName.onblur = new Function("blurValues(qrLastName, 'Last Name*')");
		grEmailAddress = document.getElementById("quickRegistration").EmailAddress;
		grEmailAddress.onfocus = new Function("focusValues(grEmailAddress, 'E-mail Address*')");
		grEmailAddress.onblur = new Function("blurValues(grEmailAddress, 'E-mail Address*')");
		qrContactNumber = document.getElementById("quickRegistration").ContactNumber;
		qrContactNumber.onfocus = new Function("focusValues(qrContactNumber, contactNumberValue + '*')");
		qrContactNumber.onblur = new Function("blurValues(qrContactNumber, contactNumberValue + '*')");
	}
	if (document.getElementById("contactForm")) {
		cYourName = document.getElementById("contactForm").YourName;
		cYourName.onfocus = new Function("focusValues(cYourName, 'Your Name')");
		cYourName.onblur = new Function("blurValues(cYourName, 'Your Name')");
		cEmailAddress = document.getElementById("contactForm").EmailAddress;
		cEmailAddress.onfocus = new Function("focusValues(cEmailAddress, 'E-mail Address')");
		cEmailAddress.onblur = new Function("blurValues(cEmailAddress, 'E-mail Address')");
		cCompany = document.getElementById("contactForm").Company;
		cCompany.onfocus = new Function("focusValues(cCompany, 'Company')");
		cCompany.onblur = new Function("blurValues(cCompany, 'Company')");
		cMessage = document.getElementById("contactForm").Message;
		cMessage.onfocus = new Function("focusValues(cMessage, 'Your Message')");
		cMessage.onblur = new Function("blurValues(cMessage, 'Your Message')");
	}
	if (document.getElementById("referForm")) {
		rYourEmail = document.getElementById("referForm").YourEmail;
		rYourName = document.getElementById("referForm").YourName;
		rYourProfession = document.getElementById("referForm").YourProfession;
		rYourContactNumber = document.getElementById("referForm").YourContactNumber;
		rFriendEmail = document.getElementById("referForm").FriendEmail;
		rFriendName = document.getElementById("referForm").FriendName;
		rFriendProfession = document.getElementById("referForm").FriendProfession;
		rFriendContactNumber = document.getElementById("referForm").FriendContactNumber;
		rMessage = document.getElementById("referForm").Message;
		rYourName.onfocus = new Function("focusValues(rYourName, 'Your Name')");
		rYourName.onblur = new Function("blurValues(rYourName, 'Your Name')");
		rYourEmail.onfocus = new Function("focusValues(rYourEmail, 'Your Email')");
		rYourEmail.onblur = new Function("blurValues(rYourEmail, 'Your Email')");
		rYourProfession.onfocus = new Function("focusValues(rYourProfession, 'Your Profession')");
		rYourProfession.onblur = new Function("blurValues(rYourProfession, 'Your Profession')");
		rYourContactNumber.onfocus = new Function("focusValues(rYourContactNumber, 'Your ' + contactNumberValue)");
		rYourContactNumber.onblur = new Function("blurValues(rYourContactNumber, 'Your ' + contactNumberValue)");
		rFriendName.onfocus = new Function("focusValues(rFriendName, 'Friend Name')");
		rFriendName.onblur = new Function("blurValues(rFriendName, 'Friend Name')");
		rFriendEmail.onfocus = new Function("focusValues(rFriendEmail, 'Friend Email')");
		rFriendEmail.onblur = new Function("blurValues(rFriendEmail, 'Friend Email')");
		rFriendProfession.onfocus = new Function("focusValues(rFriendProfession, 'Friend Profession')");
		rFriendProfession.onblur = new Function("blurValues(rFriendProfession, 'Friend Profession')");
		rFriendContactNumber.onfocus = new Function("focusValues(rFriendContactNumber, 'Friend ' + contactNumberValue)");
		rFriendContactNumber.onblur = new Function("blurValues(rFriendContactNumber, 'Friend ' + contactNumberValue)");
		rMessage.onfocus = new Function("focusValues(rMessage, 'Your Message')");
		rMessage.onblur = new Function("blurValues(rMessage, 'Your Message')");
	}
	if (document.getElementById("loginForm")) {
		lUserName = document.getElementById("loginForm").UserName;
		lPassword = document.getElementById("loginForm").Password;
		lUserName.onfocus = new Function("focusValues(lUserName, 'Email')");
		lUserName.onblur = new Function("blurValues(lUserName, 'Email')");
		lPassword.onfocus = new Function("focusValues(lPassword, 'Password')");
		lPassword.onblur = new Function("blurValues(lPassword, 'Password')");
	}
	if (document.getElementById("registerForm")) {
		email = document.getElementById("registerForm").EmailAddress;
		password = document.getElementById("registerForm").Password;
		confirmPassword = document.getElementById("registerForm").ConfirmPassword;
		email.onkeyup = new Function("checkEmailAddress()");
		password.onkeyup = new Function("checkPassword()");
		confirmPassword.onkeyup = new Function("checkConfirmPassword()");
	}
	if (document.getElementById("jobSearch")) {
		professionBox = document.getElementById("jobSearch").professionID;
		countryBox = document.getElementById("jobSearch").countryID;
		locationAreaBox = document.getElementById("jobSearch").locationAreaID;
		locationBox = document.getElementById("jobSearch").locationID;
		professionBox.onchange = new Function("populateSearchSelect('profession',professionBox,countryBox,locationAreaBox,locationBox)");
		locationAreaBox.onchange = new Function("populateSearchSelect('locationArea',professionBox,countryBox,locationAreaBox,locationBox)");
	} else {
		if ((document.getElementById("CountryID")) && (document.getElementById("CountryID"))) {
			countryBox = document.getElementById("CountryID");
			countryBox.onchange = new Function("populateSelect2()");
		}
		if ((document.getElementById("LocationAreaID")) && (document.getElementById("LocationID"))) {
			locationAreaBox = document.getElementById("LocationAreaID");
			locationAreaBox.onchange = new Function("populateSelect()");
		}
	}
	if (document.getElementById("callBackForm")) {
		cYourName = document.getElementById("callBackForm").YourName;
		cYourName.onfocus = new Function("focusValues(cYourName, 'Your Name')");
		cYourName.onblur = new Function("blurValues(cYourName, 'Your Name')");
		cContactNumber = document.getElementById("callBackForm").ContactNumber;
		cContactNumber.onfocus = new Function("focusValues(cContactNumber, contactNumberValue)");
		cContactNumber.onblur = new Function("blurValues(cContactNumber, contactNumberValue)");
	}
	if (document.getElementById("AdminType")) {
		cAdminType = document.getElementById("AdminType");
		cAdminType.onchange = new Function("showBehalfOf()");
		showBehalfOf();
	}
}

function showBehalfOf() {
	behalfOf = document.getElementById("BehalfOf");
	if (!isEmpty(document.getElementById("AdminType").value)) {
		adminType = document.getElementById("AdminType").value;
		if (adminType == 4) {
			behalfOf.disabled = false;
			document.getElementById("BehalfOfSelect").style.display = "block";
		} else {
			behalfOf.disabled = true;
			document.getElementById("BehalfOfSelect").style.display = "none";
		}
	}
}

function showDateSelect(optionString) {
	dropDown = optionString + "Option";
	holderElement = optionString.toLowerCase() + "DateSelect"
	dateOption = document.getElementById(dropDown).value;
	if (dateOption == 2) {
			document.getElementById(holderElement).style.display = "block";
	} else {
			document.getElementById(holderElement).style.display = "none";
	}
}

function checkEmailAddress() {
	var outcome = false;
	var emailAddress = document.getElementById("registerForm").EmailAddress.value;
	emailAddressLength = emailAddress.length;
	if (emailAddressLength >= 1) {
		whiteSpace = stringContains(emailAddress, " ");
		atSign = stringContains(emailAddress, "@");
		bullet = stringContains(emailAddress, ".");
		if ((emailAddressLength >= 3) && (!whiteSpace) && (atSign) && (bullet)) {
			outcome = true;	
			requestURL = "/ajax/checkUserAvailable.php";
			requestVar = "emailAddress=" + emailAddress;
			myRequest = new ajaxObject(requestURL);
			myRequest.callback = function(responseText) { showFormResponse("Email",responseText);}
			myRequest.update(requestVar,"POST");
		}
		showFormResponse("Email", outcome);
	} else {
		showFormResponse("Email", "");
	}
}

function checkPassword() {
	var outcome = false;
	var emailAddress = document.getElementById("registerForm").Password.value;
	emailAddressLength = emailAddress.length;
	if (emailAddressLength >= 1) {
		whiteSpace = stringContains(emailAddress, " ");
		if ((emailAddressLength >= 6) && (!whiteSpace)) {
			outcome = true;	
		}
		showFormResponse("Password", outcome);
	} else {
		showFormResponse("Password", "");
	}
}

function checkConfirmPassword() {
	var outcome = false;
	var firstString = document.getElementById("registerForm").Password.value;
	var secondString = document.getElementById("registerForm").ConfirmPassword.value;
	emailAddressLength = secondString.length;
	if (emailAddressLength >= 1) {
		if (secondString == firstString) {
			outcome = true;	
		}
		showFormResponse("ConfirmPassword", outcome);
	} else {
		showFormResponse("ConfirmPassword", "");
	}
}


function showFormResponse(errorElement,response) {
	responseBox = errorElement + "Result";
	responseText = "";
	validBox = "valid" + errorElement;
	document.getElementById(validBox).value = makeBool(response);
	if ((response === false) || (response === true)) {
		responseText = "<img src=\"/images/icons/" + response + ".gif\" width=\"15\" height=\"15\" alt=\"" + response + "\" title=\"" + response + "\" />"
	}
	document.getElementById(responseBox).innerHTML = responseText;
}

function focusValues(formElement, val) {
	if (formElement.value == val) {
		formElement.value = "";
	}
}

function blurValues(formElement, val) {
	if (formElement.value == "") {
		formElement.value = val;
	}
}

function TrimString(str) {
	str = this != window? this : str;
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function isEmpty(TmpString) {
	if (!TmpString) {
		return true;
	}
	TmpString = TrimString(TmpString);
	if (TmpString.length <= 0) {
		return true;
	}
	return false;
}

function checkMetas() {
	metaTitle = document.getElementById("EditForm").MetaTitle.value;
	metaDescription = document.getElementById("EditForm").MetaDescription.value;
	metaKeywords = document.getElementById("EditForm").MetaKeywords.value;
	if ((isEmpty(metaTitle)) || (isEmpty(metaDescription)) || (isEmpty(metaKeywords))) {
		question = "Contine without adding SEO details?";
		if (confirm(question)) {
			return true;
		} else {
			return false;
		}
	}
	return true;
}

function addBenefit() {
	currentValueHolder = document.getElementById("numBenefits");
	currentValue = currentValueHolder.value;
	nextValue = parseInt(currentValue) + 1;
	benefitHolder = document.getElementById("Benefits");
	newCol = benefitHolder.appendChild(document.createElement("li"));
	newBenefitLabel = newCol.appendChild(document.createElement("label"));
	newBenefitLabel.htmlFor = "Benefits" + nextValue;
	newBenefitLabel.innerHTML = "Benefit " + nextValue;
	newBenefitInput = newCol.appendChild(document.createElement("input"));
	newBenefitInput.type = "text";
	newBenefitInput.name = "Benefits[]";
	newBenefitInput.id = "Benefits" + nextValue;
	currentValueHolder.value= nextValue;
}

function uploadResponse(fileID) {
	regDefaultFirstName = regFirstName = "First Name*";
	regDefaultLastName = regLastName = "Last Name*";
	regDefaultEmailAddress = regEmailAddress = "E-mail Address*";
	regDefaultContactNumber = regContactNumber = contactNumberValue + "*";
	regDefaultProfessionID = regProfessionID = 0;
	if (!fileID) {
		fileID = "0";
	} else {
		fileID = fileID.replace("response=", "");
	}
	if (document.getElementById("quickRegistration")) {
		document.getElementById("emailAddressError").innerHTML = "";
		emailError = false;
		errors = false;
		fileIDField = document.getElementById("quickRegistration").FileID;
		fileIDField.value = fileID;
		regFirstName = ((document.getElementById("quickRegistration").FirstName) && (!isEmpty(document.getElementById("quickRegistration").FirstName.value)) && (document.getElementById("quickRegistration").FirstName.value != regFirstName)) ? document.getElementById("quickRegistration").FirstName.value : "";
		regLastName = ((document.getElementById("quickRegistration").LastName) && (!isEmpty(document.getElementById("quickRegistration").LastName.value)) && (document.getElementById("quickRegistration").LastName.value != regLastName)) ? document.getElementById("quickRegistration").LastName.value : "";
		regEmailAddress = ((document.getElementById("quickRegistration").EmailAddress) && (!isEmpty(document.getElementById("quickRegistration").EmailAddress.value)) && (document.getElementById("quickRegistration").EmailAddress.value != regEmailAddress)) ? document.getElementById("quickRegistration").EmailAddress.value : "";
		tmpEmailAddress = regEmailAddress;
		regContactNumber = ((document.getElementById("quickRegistration").ContactNumber) && (!isEmpty(document.getElementById("quickRegistration").ContactNumber.value)) && (document.getElementById("quickRegistration").ContactNumber.value != regContactNumber)) ? document.getElementById("quickRegistration").ContactNumber.value : "";
		regProfessionID = ((document.getElementById("quickRegistration").ProfessionID) && (!isEmpty(document.getElementById("quickRegistration").ProfessionID.value))) ? document.getElementById("quickRegistration").ProfessionID.value : "";
		if ((isEmpty(fileID)) || (isEmpty(regFirstName)) || (isEmpty(regLastName)) || (isEmpty(regEmailAddress)) || (isEmpty(regContactNumber))) {
			errors = true;
			regFirstNameClass = (isEmpty(regFirstName)) ? "Error" : "";
			regLastNameClass = (isEmpty(regLastName)) ? "Error" : "";
			regEmailAddressClass = (isEmpty(regEmailAddress)) ? "Error" : "";
			regContactNumberClass = (isEmpty(regContactNumber)) ? "Error" : "";
			regFirstName = (!isEmpty(regFirstName)) ? regFirstName : regDefaultFirstName;
			regLastName = (!isEmpty(regLastName)) ? regLastName : regDefaultLastName;
			regEmailAddress = (!isEmpty(regEmailAddress)) ? regEmailAddress : regDefaultEmailAddress;
			regContactNumber = (!isEmpty(regContactNumber)) ? regContactNumber : regDefaultContactNumber;
			regProfessionID = (!isEmpty(regProfessionID)) ? regProfessionID : regDefaultProfessionID;
			document.getElementById("quickRegistration").FirstName.className = regFirstNameClass;
			document.getElementById("quickRegistration").LastName.className = regLastNameClass;
			document.getElementById("quickRegistration").EmailAddress.className = regEmailAddressClass;
			document.getElementById("quickRegistration").ContactNumber.className = regContactNumberClass;
		}
		if (!isEmpty(tmpEmailAddress)) {
			emailAddressLength = tmpEmailAddress.length;
			if (emailAddressLength >= 1) {
				whiteSpace = stringContains(tmpEmailAddress, " ");
				atSign = stringContains(tmpEmailAddress, "@");
				bullet = stringContains(tmpEmailAddress, ".");
				if ((emailAddressLength < 3) || (whiteSpace) || (!atSign) || (!bullet)) {
					emailError = true;
				}
			} else {
				emailError = true;
			}
			if (emailError) {
				document.getElementById("quickRegistration").EmailAddress.className = "Error";
			} else {
				checkEmailAvailable(tmpEmailAddress,errors);
			}
		}
	}
}

function checkPopOverReg() {
	popDefaultFirstName = popFirstName = "First Name*";
	popDefaultLastName = popLastName = "Last Name*";
	popDefaultEmailAddress = popEmailAddress = "E-mail Address*";
	popDefaultContactNumber = popContactNumber = contactNumberValue + "*";
	popDefaultProfessionID = popProfessionID = 0;
	if (document.getElementById("popOverReg")) {
		document.getElementById("popEmailAddressError").innerHTML = "";
		emailError = false;
		errors = false;
		popFirstName = ((document.getElementById("popOverReg").FirstName) && (!isEmpty(document.getElementById("popOverReg").FirstName.value)) && (document.getElementById("popOverReg").FirstName.value != popFirstName)) ? document.getElementById("popOverReg").FirstName.value : "";
		popLastName = ((document.getElementById("popOverReg").LastName) && (!isEmpty(document.getElementById("popOverReg").LastName.value)) && (document.getElementById("popOverReg").LastName.value != popLastName)) ? document.getElementById("popOverReg").LastName.value : "";
		popEmailAddress = ((document.getElementById("popOverReg").EmailAddress) && (!isEmpty(document.getElementById("popOverReg").EmailAddress.value)) && (document.getElementById("popOverReg").EmailAddress.value != popEmailAddress)) ? document.getElementById("popOverReg").EmailAddress.value : "";
		tmpEmailAddress = popEmailAddress;
		popContactNumber = ((document.getElementById("popOverReg").ContactNumber) && (!isEmpty(document.getElementById("popOverReg").ContactNumber.value)) && (document.getElementById("popOverReg").ContactNumber.value != popContactNumber)) ? document.getElementById("popOverReg").ContactNumber.value : "";
		popUploadCV = ((document.getElementById("popOverReg").UploadCV) && (!isEmpty(document.getElementById("popOverReg").UploadCV.value))) ? document.getElementById("popOverReg").UploadCV.value : "";
		popProfessionID = ((document.getElementById("popOverReg").ProfessionID) && (!isEmpty(document.getElementById("popOverReg").ProfessionID.value))) ? document.getElementById("popOverReg").ProfessionID.value : "";
		if ((isEmpty(popUploadCV)) || (isEmpty(popFirstName)) || (isEmpty(popLastName)) || (isEmpty(popEmailAddress)) || (isEmpty(popContactNumber))) {
			errors = true;
			popFirstNameClass = (isEmpty(popFirstName)) ? "Error" : "";
			popLastNameClass = (isEmpty(popLastName)) ? "Error" : "";
			popEmailAddressClass = (isEmpty(popEmailAddress)) ? "Error" : "";
			popContactNumberClass = (isEmpty(popContactNumber)) ? "Error" : "";
			popUploadCVClass = (isEmpty(popUploadCV)) ? "Error" : "";
			popFirstName = (!isEmpty(popFirstName)) ? popFirstName : popDefaultFirstName;
			popLastName = (!isEmpty(popLastName)) ? popLastName : popDefaultLastName;
			popEmailAddress = (!isEmpty(popEmailAddress)) ? popEmailAddress : popDefaultEmailAddress;
			popContactNumber = (!isEmpty(popContactNumber)) ? popContactNumber : popDefaultContactNumber;
			popProfessionID = (!isEmpty(popProfessionID)) ? popProfessionID : popDefaultProfessionID;
			document.getElementById("popOverReg").FirstName.className = popFirstNameClass;
			document.getElementById("popOverReg").LastName.className = popLastNameClass;
			document.getElementById("popOverReg").EmailAddress.className = popEmailAddressClass;
			document.getElementById("popOverReg").ContactNumber.className = popContactNumberClass;
			document.getElementById("popOverReg").UploadCV.className = popUploadCVClass;
		}
		if (!isEmpty(tmpEmailAddress)) {
			emailAddressLength = tmpEmailAddress.length;
			if (emailAddressLength >= 1) {
				whiteSpace = stringContains(tmpEmailAddress, " ");
				atSign = stringContains(tmpEmailAddress, "@");
				bullet = stringContains(tmpEmailAddress, ".");
				if ((emailAddressLength < 3) || (whiteSpace) || (!atSign) || (!bullet)) {
					emailError = true;
				}
			} else {
				emailError = true;
			}
			if (emailError) {
				document.getElementById("popOverReg").EmailAddress.className = "Error";
			} else {
				checkEmailAvailable(tmpEmailAddress,errors,"popOverReg","popEmailAddressError");
			}
		}
	}
}

function checkEmailAvailable(emailAddress,errors,formName,emailAddressError) {
	if (!formName) {
		formName = "";
	}
	if (!emailAddressError) {
		emailAddressError = "";
	}
	requestURL = "/ajax/checkUserAvailable.php";
	requestVar = "emailAddress=" + emailAddress;
	requestVar += "&errors=" + errors;
	if (formName) {
		requestVar += "&formName=" + formName;
	}
	if (emailAddressError) {
		requestVar += "&emailAddressError=" + emailAddressError;
	}
	myRequest = new ajaxObject(requestURL);
	myRequest.callback = function(responseText,responseStatus) { processResult(responseText,responseStatus);}
	myRequest.update(requestVar,"POST");
}