function focus() {
for (a=0;a<document.links.length;)
document.links[a].onfocus=document.links[a++].blur;
}

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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}



function validateemail(field) {
if(field.indexOf("@")==-1 || field.indexOf(".")==-1) return false;
return true;
}

function validate_contact()
{

  f = document.forms['frmcontact'];

  if (f.contactname.value == "") {
    window.alert("Please enter contact name!");
    return false;
  }

  if (f.companyname.value == "") {
    window.alert("Please enter company name!");
    return false;
  }

  if (f.address.value == "") {
    window.alert("Please enter address!");
    return false;
  }

  if (f.telephone.value == "") {
    window.alert("Please enter telephone number!");
    return false;
  }

  if (!validateemail(f.email.value)) {
    window.alert("Please enter valid email!");
    return false;
  }

  return true;
}


function validate_become1(){
  i=0;
  var message="";
  f = document.forms['frmbecome1'];
  if (f.name.value == "") message+=(++i)+". name\n";
  if (f.addressline1.value == "")  message+=(++i)+". address\n";
  if (f.postcode.value == "")  message+=(++i)+". postcode\n";
  if (f.mobile.value == "")  message+=(++i)+". mobile\n";
  if (f.tel.value == "")  message+=(++i)+". tel\n";
  if (!validateemail(f.email.value))  message+=(++i)+". valid email\n";
  if (f.dayofbirth.options[f.dayofbirth.selectedIndex].value == '')  message+=(++i)+". day of birth\n";
  if (f.monthofbirth.options[f.monthofbirth.selectedIndex].value == '')  message+=(++i)+". month of birth\n";
  if (f.yearofbirth.options[f.yearofbirth.selectedIndex].value == '')  message+=(++i)+". year of birth\n";
  if ((!f.cardnumber[0].checked) && (!f.cardnumber[1].checked)) message+=(++i)+". have a valid Equity Card or Spotlight Number\n";
  if ((!f.Model.checked) && (!f.Actor.checked) && (!f.Dancer.checked)) message+=(++i)+". working categories\n";
  if(message.length==0)
  	return true;
  else{
	window.alert("Please enter:\n\n"+message);
	return false;
  }
}

function validate_become2(){
  f = document.forms['frmbecome2'];
  child=IsChild(adultFrom,f.dayofbirth.value,f.monthofbirth.value,f.yearofbirth.value);
  i=0;
  var message="";
  if (f.gender.options[f.gender.selectedIndex].value == '')  message+=(++i)+". gender\n";
  if (f.height.options[f.height.selectedIndex].value == '')  message+=(++i)+". height\n";
  if ((f.waist.options[f.waist.selectedIndex].value == ''))  message+=(++i)+". waist\n";
  if (f.haircolour.options[f.haircolour.selectedIndex].value == '')  message+=(++i)+". hair colour\n";
  if (f.eyecolour.options[f.eyecolour.selectedIndex].value == '')  message+=(++i)+". eye colour\n";
  if (f.complexion.options[f.complexion.selectedIndex].value == '')  message+=(++i)+". complexion\n";
  if (f.shoecategory.options[f.shoecategory.selectedIndex].value == '')  message+=(++i)+". shoe category\n";
  if (f.shoesize.options[f.shoesize.selectedIndex].value == '')  message+=(++i)+". shoe size\n";
  if (f.bustchest.options[f.bustchest.selectedIndex].value == '')  message+=(++i)+". chest\n";
  if (f.hips.options[f.hips.selectedIndex].value == '')  message+=(++i)+". hips\n";
  if (f.dresssuit.options[f.dresssuit.selectedIndex].value == '')  message+=(++i)+". dress size\n";
  if ((f.clothessize.options[f.clothessize.selectedIndex].value == '') && child)  message+=(++i)+". clothes size\n";
  if (f.collar.options[f.collar.selectedIndex].value == '')  message+=(++i)+". collar\n";
  if (f.insideleg.options[f.insideleg.selectedIndex].value == '')  message+=(++i)+". inside leg\n";
  if ((!f.Photographic.checked) && (!f.PromoEvents.checked) && (!f.Catwalk.checked) && (!f.Castings.checked)) message+=(++i)+". work interested\n";
  if (f.experience.value == "") message+=(++i)+". previous experience\n";
  if(message.length==0)
  	return true;
  else{
	window.alert("Please enter:\n\n"+message);
	return false;
  }
}

function validate_become3(){
  f = document.forms['frmbecome3'];
  i=0;
  if(!f.check_become.checked) 
	{
		window.alert("You must agree terms and conditions!");
		return false;
    }
  if(f.photo1.value != "") i++;
  if(f.photo2.value != "") i++;
  if(f.photo3.value != "") i++;
  if(f.photo4.value != "") i++;
  if(f.photo5.value != "") i++;
  if(i<3){
	window.alert("Please attach a minimum of 3 images!");
	return false;
  }
}


/*
function validate_become1old()
{

  f = document.forms['frmbecome'];



  if (f.Gender.options[f.Gender.selectedIndex].value == '') {
    window.alert("Please select your gender!");
    return false;
  }
  if (f.dayOfBirth.options[f.dayOfBirth.selectedIndex].value == '') {
    window.alert("Please select day of birth!");
    return false;
  }

  if (f.monthOfBirth.options[f.monthOfBirth.selectedIndex].value == '') {
    window.alert("Please select month of birth!");
    return false;
  }
  
  if (f.yearOfBirth.options[f.yearOfBirth.selectedIndex].value == '') {
    window.alert("Please select year of birth!");
    return false;
  }

  if (f.Height.value == "") {
    window.alert("Please enter your height!");
    return false;
  }

  if(!IsChild(adultFrom,f.dayOfBirth.value,f.monthOfBirth.value,f.yearOfBirth.value))
  	if (f.Waist.value == "") {
		window.alert("Please enter your waist!");
    	return false;
  	}

  if (f.HairColour.value == "") {
    window.alert("Please enter your hair colour!");
    return false;
  }

  if (f.EyeColour.value == "") {
    window.alert("Please enter your eye colour!");
    return false;
  }

  if (f.Complexion.value == "") {
    window.alert("Please enter your complexion!");
    return false;
  }

  if (f.ShoeCategory.value == "") {
    window.alert("Please enter your shoe category!");
    return false;
  }

  if (f.ShoeSize.value == "") {
    window.alert("Please enter your shoe size!");
    return false;
  }

  return true;
}



function validate_become2old()
{
  f = document.forms['frmbecome2'];
  child=IsChild(adultFrom,f.dayOfBirth.value,f.monthOfBirth.value,f.yearOfBirth.value);
  female=(f.Gender.value=='Female');

  if(!child)
  	if (f.BustChest.value == "") {
	    window.alert("Please enter your bust / chest!");
	    return false;
	}

  if(!child)
	  if (f.Hips.value == "") {
		window.alert("Please enter your hips!");
		return false;
	  }

  if(female)
	  if (f.DressSuit.value == "") {
		window.alert("Please enter dress size!");
		return false;
	  }


  if(!female && !child)
	  if (f.Collar.value == "") {
		window.alert("Please enter collar!");
		return false;
	  }


  if(!female && !child)
	  if (f.InsideLeg.value == "") {
		window.alert("Please enter Inside Leg!");
		return false;
	  }


  if ((!f.Photographic.checked) && (!f.PromoEvents.checked) && (!f.Catwalk.checked) && (!f.Castings.checked)) {
    window.alert("Please check what kind of work you are interested in!");
    return false;
  }

  if (f.Experience.value == "") {
	window.alert("Please enter previous experience!");
	return false;
  }

  if (f.Attachment1.value == "" || f.Attachment2.value == "" || f.Attachment3.value == "" || f.Attachment4.value == "" || f.Attachment5.value == "") {
	window.alert("Please attach all images!");
	return false;
  }

  return true;
}


function validate_shortlist(){

  f = document.forms['shortlist'];

  if (f.contactname.value == "") {
    window.alert("Please enter contact name!");
    return false;
  }

  if (f.company.value == "") {
    window.alert("Please enter company!");
    return false;
  }

  if (f.address.value == "") {
    window.alert("Please enter address!");
    return false;
  }


  if (f.telephone.value == "") {
    window.alert("Please enter telephone!");
    return false;
  }


  if (f.mobile.value == "") {
    window.alert("Please enter mobile!");
    return false;
  }


  if (!validateemail(f.email.value)) {
    window.alert("Please enter valid email!");
    return false;
  }

  if (f.fax.value == "") {
    window.alert("Please enter fax!");
    return false;
  }

  if (f.information.value == "") {
    window.alert("Please enter further information!");
    return false;
  }

  return true;	
}
*/

//alternative version
function validate_shortlist(){
  var message="";
  f = document.forms['shortlist'];
  if (f.contactname.value == "") message+="- contact name\n";
  if (f.company.value == "")  message+="- company\n";
  if (f.address.value == "")  message+="- address\n";
  if (f.telephone.value == "")  message+="- telephone\n";
  if (f.mobile.value == "")  message+="- mobile\n";
  if (!validateemail(f.email.value))  message+="- valid email\n";
  if (f.fax.value == "")  message+="- fax\n";
  if (f.information.value == "")  message+="- further information\n";
  if(message.length==0)
  	return true;
  else{
	window.alert("Please enter:\n\n"+message);
	return false;
  }
}


function NewWindow(link) {
window.open(link, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,fullscreen=no,channelmode=no,width=400,height=300,top=0,left=0');
}

//cookies
//universal functions
function SetCookie(name, value, expire){
	if((name.length+value.length+1)>4000) return false;
	var def_expir=";expires="+CreateExpiresTime(31);
	document.cookie=name+"="+value+((expire == null)?def_expir:(";expires="+expire));
	return true;
}
function CreateExpiresTime(days){
	var today = new Date();
	return new Date(today.getTime() + 1000*60*60*24*parseInt(days)).toGMTString();
}
function GetCookie(name){
	var sstr=name+"=";
	var rvalue="";
	var cook=document.cookie;
	if(cook.length>0){
		offset = cook.indexOf(sstr);
		if(offset != -1){
			offset+=sstr.length;
			end = cook.indexOf(";", offset);
			if(end == -1) end = cook.length;
			rvalue=cook.substring(offset, end);
		}
	}
	return rvalue;
}
function IsInCookie(subvalue, name){
		var cook=GetCookie(name);
		var tab_cook=cook.split(",");
		var sub_index=PosInArray(subvalue,tab_cook);
		if(sub_index==-1) return false; else return true;
}
function PosInArray(subvalue,tab_cook){
	var pos=-1;
	for(i=0;i<tab_cook.length;i++)
		if(tab_cook[i]==subvalue){
			pos=i;
			break;	
		}
	return pos;
}
function AddToCookie(subvalue, name){
		if((subvalue!=null) && !IsInCookie(subvalue, name)){
			var cook=GetCookie(name);
			if(cook.length>0) cook+=","+subvalue; else cook=subvalue;
			return SetCookie(name,cook);
		}
		return true;
}
function RemFromCookie(subvalue, name){
		var cook=GetCookie(name);
		var tab_cook=cook.split(",");
		var sub_index=PosInArray(subvalue,tab_cook);
		while(sub_index!=-1){
			tab_cook.splice(sub_index,1);
			sub_index=PosInArray(subvalue,tab_cook);
		}
		cook=tab_cook.join(",");
		SetCookie(name,cook);
}
//specific functions
timer=null;
function ChangeShortlist(id){
	if(timer) clearTimeout(timer);
	var img=document.getElementById("Image1");
	var posinfo=document.getElementById("posInfo");
	if(img.src.substr(img.src.lastIndexOf('/')+1)=="tool_ad2shortlist.gif"){
		img.src="images/search/tool_ad2shortlist_off.gif";
		RemFromCookie(id,"ids");
		posinfo.innerHTML='Model removed from shortlist.';
	}else{
		img.src="images/search/tool_ad2shortlist.gif";
		AddToCookie(id,"ids");
		posinfo.innerHTML='Model added to shortlist.';
	}
	posinfo.style.display="block";
	timer=setTimeout("document.getElementById('posInfo').style.display='none';",2000);
}

function RemFromShortlist(){
	var tab_check=document.getElementsByName("ids");
	for(z=0;z<tab_check.length;z++){
		if(tab_check[z].checked)
			RemFromCookie(tab_check[z].value,"ids");
	}
}

function IsChild(adultFrom,bd,bm,by){
	var today= new Date();
	if(today.getFullYear()>adultFrom+parseInt(by))
		return false;
	var bornDate= new Date(parseInt(by), (bm.indexOf('0')==0)?(parseInt(bm.substr(1))-1):(parseInt(bm)-1), (bd.indexOf('0')==0)?parseInt(bd.substr(1)):parseInt(bd), today.getHours(), today.getMinutes(), today.getSeconds(), today.getMilliseconds());
	bornDate.setFullYear(bornDate.getFullYear()+adultFrom);
	return (bornDate.getTime()>today.getTime());
}

function CheckDate(){
	var f=document.forms.frmbecome;
	with(f){
		if((dayOfBirth.value!='') && (monthOfBirth.value!='') && (yearOfBirth.value!=''))
			return IsChild(adultFrom,dayOfBirth.value,monthOfBirth.value,yearOfBirth.value);
	}
}