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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}	

function ShowAutoLoginHelp() {
	MM_openBrWindow('../pops/autologinhelp.php','help','status=yes,width=450,height=350,resizable=yes,scrollbars=yes');
	return false;
}

function ShowCompileHelp() {
	MM_openBrWindow('../pops/compileoptionhelp.php','help','status=yes,width=450,height=350');
	return false;
}		

function GoToMC() {
	window.location.replace("../clients/newcasting.php");
}

function ClearCart() {
	var split_url=document.URL.split('?');
	window.location.replace(split_url[0]+"?clearcart=1");
}	

function appendTEXT(ltag,index,text){
                str = text;
                Myelem = document.getElementById(ltag);
                Myelem.innerHTML = str;
}

function LoginAlert() {
	alert("Please login to view more details!");
	document.theform.username.focus();
}	

function checkFields() {
infoheader = "To complete a successful search certain fields have to be completed correctly. Here is a list of the requirements:<br><br>";
missinginfostr = "";
focusitem = "";
if (document.theform.scatagory.value == "") {
missinginfostr += "    -  Select a catagory<br>";
if (focusitem=="")
	focusitem="scatagory";
}
if (document.theform.sage1.value == "") {
missinginfostr += "    -  Define an age group<br>";
if (focusitem=="")
	focusitem="sage1";
}

if (missinginfostr != "") {
missinginfostr = infoheader + missinginfostr;
MM_openBrWindow('../pops/missing_info.php?mi=' + missinginfostr + "&fi=" + focusitem,'missing_info','status=yes,width=450,height=150');
return false;
} else {
document.theform.action = "search.php?DoIT=1";
return true;
}
}

function checkCasting() {
infoheader = "Some essential information is missing. Please see the details below.<br><br>";
missinginfostr = "";
focusitem = "";
if (document.theform.client.value == "") {
missinginfostr += " -  Client name<br>";
if (focusitem=="")
	focusitem="client";
}
if (document.theform.job_number.value == "") {
missinginfostr += " -  Job number<br>";
if (focusitem=="")
	focusitem="job_number";
}
if (document.theform.media.value == "") {
missinginfostr += " -  The type of media<br>";
if (focusitem=="")
	focusitem="media";
}
if (document.theform.cdates.value == "") {
missinginfostr += " -  Casting date/s<br>";
if (focusitem=="")
	focusitem="cdates";
}
if (document.theform.sdates.value == "") {
missinginfostr += " -  Shoot date/s<br>";
if (focusitem=="")
	focusitem="sdates";
}
if ((document.theform.attach.value == "") && ((document.theform.rates.value == "") || (document.theform.cdates.value == "") || (document.theform.sdates.value == ""))) {
missinginfostr += " -  Attach a file or complete the remaining fields<br>";
if (focusitem=="")
	focusitem="attach";
}

if (missinginfostr != "") {
missinginfostr = infoheader + missinginfostr;
MM_openBrWindow('../pops/missing_info.php?mi=' + missinginfostr + "&fi=" + focusitem,'missing_info','status=yes,width=450,height=150');
return false;
} else {
document.theform.action = "doaddcasting.php";
return true;
}
}

function PassReminder() {
	missinginfo = "";
	if (document.theform.username.value == "") {
		missinginfo = "Please enter your e-mail address:\n" +
		missinginfo + "\n_____________________________" +
		"\nAnd submit again!";
		alert(missinginfo);
		document.theform.username.focus();
	}
	else {
	document.theform.action = "../actions/mail_pass.php";
	document.theform.submit();
	}
}

function DoCompile(tbox,dreturn) {
  if (tbox.value == "ezcard") {
  	MM_openBrWindow('../actions/send_ezcard.php?return='+dreturn,'ezcard','status=yes,width=550,height=250');
  } else {	
	window.location.replace("../clients/newcasting.php?co=" + tbox.value);
  }	
}	

function BrowseNew(tbox) {
	sval = Number();
	oval = Number();
	if (tbox.name == "sage1") {
		if (tbox.value != "") {
			sval = Number(tbox.value);
			document.theform.sage2.disabled = false;
			document.theform.sage2.options.length = 0;
			lnght = tbox.length;
			ncount = 0;
			for (var i=0; i < lnght; i++) {
				oval = Number(tbox.options[i].value);
				if (oval >= sval) {
					document.theform.sage2.options[ncount] = new Option(tbox.options[i].text,tbox.options[i].value);
					ncount++;
				}
							
			}	
		} else {
			document.theform.sage2.value = "";
			document.theform.sage2.disabled = true;
		}		
	}
	
	if (tbox.name == "sheight1") {
		if (tbox.value != "") {
			sval = Number(tbox.value);
			document.theform.sheight2.disabled = false;
			document.theform.sheight2.options.length = 0;
			lnght = tbox.length;
			ncount = 0;
			for (var i=0; i < lnght; i++) {
				oval = Number(tbox.options[i].value);
				if (oval >= sval) {
					document.theform.sheight2.options[ncount] = new Option(tbox.options[i].text,tbox.options[i].value);
					ncount++;
				}
							
			}	
		} else {
			document.theform.sheight2.value = "";
			document.theform.sheight2.disabled = true;
		}		
	}
	
	if (tbox.name == "scsize1") {
		if (tbox.value != "") {
			sval = Number(tbox.value);
			document.theform.scsize2.disabled = false;
			document.theform.scsize2.options.length = 0;
			lnght = tbox.length;
			ncount = 0;
			for (var i=0; i < lnght; i++) {
				oval = Number(tbox.options[i].value);
				if (oval >= sval) {
					document.theform.scsize2.options[ncount] = new Option(tbox.options[i].text,tbox.options[i].value);
					ncount++;
				}
							
			}	
		} else {
			document.theform.scsize2.value = "";
			document.theform.scsize2.disabled = true;
		}		
	}
	
	if (tbox.name == "sshoe1") {
		if (tbox.value != "") {
			sval = Number(tbox.value);
			document.theform.sshoe2.disabled = false;
			document.theform.sshoe2.options.length = 0;
			lnght = tbox.length;
			ncount = 0;
			for (var i=0; i < lnght; i++) {
				oval = Number(tbox.options[i].value);
				if (oval >= sval) {
					document.theform.sshoe2.options[ncount] = new Option(tbox.options[i].text,tbox.options[i].value);
					ncount++;
				}
							
			}	
		} else {
			document.theform.sshoe2.value = "";
			document.theform.sshoe2.disabled = true;
		}
	}
	
}

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return "";
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function TestCookie () {
if (document.theform.AutoLogin.checked == true) {
testValue=Math.floor(1000*Math.random());
SetCookie('AreCookiesEnabled',testValue);
if (testValue!=ReadCookie('AreCookiesEnabled')) {
     alert('In order to use this function you will need to accept cookies from our site. If you are unsure about what this means click on "Remember me" for help');
}	
}
}

var ns6=document.getElementById&&!document.all
var ie=document.all
function changeto(e,highlightcolor,fontcolour){
source=ie? event.srcElement : e.target
if (source.tagName=="TR"||source.tagName=="TABLE"||source.tagName=="font")
return
while(source.tagName!="TD"&&source.tagName!="HTML")
source=ns6? source.parentNode : source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore") {
source.style.backgroundColor=highlightcolor
source.style.color=fontcolour
}
}
function contains_ns6(master, slave) { //check if slave is contained by master
while (slave.parentNode)
if ((slave = slave.parentNode) == master)
return true;
return false;
}
function changeback(e,originalcolor,fontcolour){
if
(ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TR"||source.tagName=="TABLE")
return
else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
return
if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source) {
source.style.backgroundColor=originalcolor
source.style.color=fontcolour
}
}
