<!--
/* AJAX CONNECTION START*/
var xmlHttp;

function showCustomer(str) { 
	var url="../includes/ajax_joblistings.php?sid=" + Math.random() + "&q=" + str;
	xmlHttp=GetXmlHttpObject(stateChanged);
	xmlHttp.open("GET", url , true);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.send(null);
} 

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("jobList").innerHTML=xmlHttp.responseText ;
	} 
} 

function GetXmlHttpObject() //retrieve xmlHttp object, testing for all browsers
{ 
	var objXmlHttp=null;
	if (navigator.userAgent.indexOf("MSIE")>=0) {
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
			strName="Microsoft.XMLHTTP"
		} 
		try {
			objXmlHttp=new ActiveXObject(strName);
			return objXmlHttp;
		} catch(e) { 
			alert("Error! Scripting for ActiveX might be disabled in your browser.");
			return;
		} 
	} 
	try { // primarily for MOZILLA
		objXmlHttp=new XMLHttpRequest();
		return objXmlHttp;
	} catch (failure) { // all attempts have failed
		alert("Sorry, your browser does not work with the interactive features on this page");
		return;
	}
}
/* AJAX CONNECTION END*/
/* VALIDATION FUNCTIONS*/

function confirming(thisform) { //function to validate form client side upon submission
	with (thisform) {
		// validate the 'job details' section
		if (emptyvalid(name)==false) {name.focus(); return false;}
		if (emptyvalid(jobtitle)==false) {jobtitle.focus(); return false;}
		if (emailvalid(email)==false) {email.focus(); return false;}
		
		//test if new production date needs validating too	
		if (prodid.value == "NULL" || prodid.value == "0" ) {
		//create array of compulsory fields then check if any are empty
			var emptArray = new Array("author","title","director","producer");
			for (var x =0; x < emptArray.length; x++) {
				var z = document.getElementsByName(emptArray[x])
				if (emptyvalid(z[0])==false) {z[0].focus(); return false;}
			}
			// check they have set week to vac or multi week if its in a vac
			if (term.value % 2 == 0) { // all vac term no.s are even
				if (week.value != "0" && week.value != "NULL") {
					alert("You must set Week to 'Vac' or 'Multi-weeks' for productions in the vacation.");
					week.focus(); return false;
				}
			}
		}
	}
	//if got this far then form is OK
	return true;
}

//INDIVIDUAL VALIDATION FUNCTIONS
function emailvalid(entered) {
	with (entered) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		lastpos=value.length-1;
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
			alert("Please enter a valid email address.");
		 	return false;
		}
		else return true;
	}
}
function emptyvalid(entered) {
	with (entered) {
		if (value==null || value==""){
			{alert("The " + entered.name+" field cannot be empty");} return false;}
		else return true;
	}
}
//displays running tally of how many chars left in the textarea fields
function countChar(thisElem) {
	document.getElementById("count"+thisElem.name).innerHTML = "chars left: "+(240-thisElem.value.length);
}

function lengthbox(thisElem, name) { // NB the \ allows spreading code over multiple lines
	if (thisElem.value.length > 240) {
		alert("Field Length exceeded\n You cannot enter more than 240 characters in the "+name+" field.\n \
		   Please remove "+(thisElem.value.length-240)+" characters or the content will be \
		   truncated on the website.\n	 \
		   After deleting some characters you will get another warning like this if the content	\
		   is still too long.");
		}
	return true;
}
//function to disable some fields on form depending on other elements
function disable(srcElem, destElem, criteria, setting)
{
	var bgCol1 = "#CCCCCC";	var bgCol2 = "#FFFFFF";// the enabled/disabled bg colors
		if (!setting) { bgCol1 = "#FFFFFF"; bgCol2="#CCCCCC";} // if nec, reverse them
	if (srcElem.value == criteria) {
		destElem.disabled = setting;	
		if (destElem.type == "text") destElem.style.backgroundColor = bgCol1;
	}
	else {
		destElem.disabled = !setting;	
		if (destElem.type == "text") destElem.style.backgroundColor = bgCol2;
	}
}
//function for testing - inserts values for all form elements
function fillForm()
{
	var e = document.job.elements;
	for (var i=0;i<e.length;i++) {
		if (e[i].type == 'text')
			e[i].value = 'test'+i;
	}
}

function loadScript() { //in JS enabled browser, load some original page settings.
	document.job.submit.disabled = true;
	document.job.venue2.disabled = true;
	document.job.datenotes.disabled = true;
	document.job.venue2.style.backgroundColor = "#CCCCCC";
	document.job.datenotes.style.backgroundColor = "#CCCCCC";
}

-->