function populatejobsectors()
{
  temp1="";
  for (i=0; i<document.info.jobsectorid.length; i++)
  {
   if (document.info.jobsectorid[i].selected==true)
    temp1=temp1+document.info.jobsectorid[i].value+",";
  }
  document.info.jobsectors.value=temp1.substring(0,temp1.length-1);
}


function checkJobsector()
{
  with (document.info)
  {
   if (jobsector.value=='')
   {
    alert("Please enter a job sector");
    return(false);
   }
  }
}

function checkRate()
{
  with (document.info)
  {
   if (rate.value=='')
   {
    alert("Please enter a rate");
    return(false);
   }
   else 
   {
	var valid = "0123456789.";
	ok = 1;
	var temp;
	for (var i=0; i<rate.value.length; i++)
	{
		temp = "" + rate.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0 && rate.value.length>0 && rate.value!='-')
	{
		alert("Please only enter numbers in the rate field");
		return(false);
	}
   }
  }
}

function checkLocation()
{
  with (document.info)
  {
   if (location.value=='')
   {
    alert("Please enter a location");
    return(false);
   }
  }
}

function checkEmployer()
{
  with (document.info)
  {
   if (companyname.value=='')
   {
    alert("Please enter a company name name");
    return(false);
   }
   else if (address.value.length>200)
   {
    alert("Please enter a shorter address");
    return(false);
   } 
   else if (country.value=='-')
   {
    alert("Please select a country");
    return(false);
   } 
   else if (email.value=='')
   {
    alert("Please enter an email address");
    return(false);
   } 
   else if (telephone.value=='')
   {
    alert("Please enter a telephone");
    return(false);
   } 
   else if (password.value=='')
   {
    alert("Please enter a password");
    return(false);
   } 
 }
}

function checkJob()
{
  with (document.info)
  {
   if (jobtitle.value=='')
   {
    alert("Please enter a job title");
    return(false);
   }
   else if (description.value=='')
   {
    alert("Please enter a description");
    return(false);
   }
   else if (description.value.length>4000)
   {
    alert("Please shorten the job description to 4,000 or less characters");
    return(false);
   }
   else if (rateid.value=='0')
   {
    alert("Please select a rate range");
    return(false);
   }
   else if (locationid.value=='0')
   {
    alert("Please select a location");
    return(false);
   }
   else if (jobsectorid.value=='0' || jobsectorid.selectedIndex==-1)
   {
    alert("Please select a job sector");
    return(false);
   }
   else if (contactname.value.length<3)
   {
    alert("Please a contact name");
    return(false);
   }
   else if (email.value.length<7)
   {
    alert("Please enter an email address");
    return(false);
   }
   else if ((email.value.indexOf('@')==-1) || (email.value.indexOf('.')==-1)) 
   {
    alert("Please enter a valid email address");
    return(false);
   }
   else if (telephone.value.length<7)
   {
    alert("Please enter a telephone number");
    return(false);
   }
   else if (purchaseauthority.value.length<3)
   {
    alert("Please a purchase authority");
    return(false);
   }
   else if (purchaseauthorityemail.value.length<7)
   {
    alert("Please enter a purchase authority email address");
    return(false);
   }
   else if (purchaseauthoritytelephone.value.length<7)
   {
    alert("Please enter a purchase authority telephone number");
    return(false);
   }
   else if (timesheetsignature.value.length<3)
   {
    alert("Please a timesheet signature");
    return(false);
   }
   else if (timesheetsignatureemail.value.length<7)
   {
    alert("Please enter a timesheet signature email address");
    return(false);
   }
   else if ((timesheetsignatureemail.value.indexOf('@')==-1) || (timesheetsignatureemail.value.indexOf('.')==-1)) 
   {
    alert("Please enter a valid timesheet signature email address");
    return(false);
   }
   else if (timesheetsignaturetelephone.value.length<7)
   {
    alert("Please enter a timesheet signature telephone number");
    return(false);
   }
   else if (sdd.selectedIndex==0 && smm.selectedIndex==0 && syyyy.selectedIndex==0)
   {
    alert("Please select a start date");
    return(false);
   }
   else if (edd.selectedIndex==0 && emm.selectedIndex==0 && eyyyy.selectedIndex==0)
   {
    alert("Please select an end date");
    return(false);
   }
   else if (shhfrom1.selectedIndex==0 && smifrom1.selectedIndex==0 && shhto1.selectedIndex==0 && smito1.selectedIndex==0 &&shhfrom2.selectedIndex==0 && smifrom2.selectedIndex==0 && shhto2.selectedIndex==0 && smito2.selectedIndex==0 &&shhfrom3.selectedIndex==0 && smifrom3.selectedIndex==0 && shhto3.selectedIndex==0 && smito3.selectedIndex==0 &&shhfrom4.selectedIndex==0 && smifrom4.selectedIndex==0 && shhto4.selectedIndex==0 && smito4.selectedIndex==0 &&shhfrom5.selectedIndex==0 && smifrom5.selectedIndex==0 && shhto5.selectedIndex==0 && smito5.selectedIndex==0 &&shhfrom6.selectedIndex==0 && smifrom6.selectedIndex==0 && shhto6.selectedIndex==0 && smito6.selectedIndex==0 &&shhfrom7.selectedIndex==0 && smifrom7.selectedIndex==0 && shhto7.selectedIndex==0 && smito7.selectedIndex==0)
   {
    alert("Please select the daily working hours");
    return(false);
   }
   else 
   {
    shhfroma=shhfrom1.value;
    shhtoa=shhto1.value;

    shhtoa=shhtoa-shhfroma;
    if (shhtoa<0) shhtoa=0;
    smifroma=smifrom1.value;
    smitoa=smito1.value;
    smitoa=smitoa-smifroma;
 
    shhfromb=shhfrom2.value;
    shhtob=shhto2.value;
    shhtob=shhtob-shhfromb;
    if (shhtob<0) shhtob=0;
    smifromb=smifrom2.value;
    smitob=smito2.value;
    smitob=smitob-smifromb;

    shhfromc=shhfrom3.value;
    shhtoc=shhto3.value;
    shhtoc=shhtoc-shhfromc;
    if (shhtoc<0) shhtoc=0;
    smifromc=smifrom3.value;
    smitoc=smito3.value;
    smitoc=smitoc-smifromc;

    shhfromd=shhfrom4.value;
    shhtod=shhto4.value;
    shhtod=shhtod-shhfromd;
    if (shhtod<0) shhtod=0;
    smifromd=smifrom4.value;
    smitod=smito4.value;
    smitod=smitod-smifromd;

    shhfrome=shhfrom5.value;
    shhtoe=shhto5.value;
    shhtoe=shhtoe-shhfrome;
    if (shhtoe<0) shhtoe=0;
    smifrome=smifrom5.value;
    smitoe=smito5.value;
    smitoe=smitoe-smifrome;

    shhfromf=shhfrom6.value;
    shhtof=shhto6.value;
    shhtof=shhtof-shhfromf;
    if (shhtof<0) shhtof=0;
    smifromf=smifrom6.value;
    smitof=smito6.value;
    smitof=smitof-smifromf;

    shhfromg=shhfrom7.value;
    shhtog=shhto7.value;
    shhtog=shhtog-shhfromg;
    if (shhtog<0) shhtog=0;
    smifromg=smifrom7.value;
    smitog=smito7.value;
    smitog=smitog-smifromg;

    shhtog=shhtog+shhtof+shhtoe+shhtod+shhtoc+shhtob+shhtoa;
    smitog=smitog+smitof+smitoe+smitod+smitoc+smitob+smitoa;
    smitog=smitog/60;
    shhtog=shhtog+smitog;
    if (shhtog>=48) alert("You have entered more than 48 hours work in a calendar week, please ensure that the candidate you are seeking to employ has opted out of the working time directive agreement. Please contact the temporary worker you select directly to establish this.");
   }
  }
}

function copyhours(fieldnumber)
{
  with(document.info)
  {
    if (fieldnumber==1)
    {
	shhfrom2.selectedIndex=shhfrom1.selectedIndex;
	shhto2.selectedIndex=shhto1.selectedIndex;
	smifrom2.selectedIndex=smifrom1.selectedIndex;
	smito2.selectedIndex=smito1.selectedIndex;
    }
    else if (fieldnumber==2)
    {
	shhfrom3.selectedIndex=shhfrom2.selectedIndex;
	shhto3.selectedIndex=shhto2.selectedIndex;
	smifrom3.selectedIndex=smifrom2.selectedIndex;
	smito3.selectedIndex=smito2.selectedIndex;
    }
    else if (fieldnumber==3)
    {
	shhfrom4.selectedIndex=shhfrom3.selectedIndex;
	shhto4.selectedIndex=shhto3.selectedIndex;
	smifrom4.selectedIndex=smifrom3.selectedIndex;
	smito4.selectedIndex=smito3.selectedIndex;
    }
    else if (fieldnumber==4)
    {
	shhfrom5.selectedIndex=shhfrom4.selectedIndex;
	shhto5.selectedIndex=shhto4.selectedIndex;
	smifrom5.selectedIndex=smifrom4.selectedIndex;
	smito5.selectedIndex=smito4.selectedIndex;
    }
    else if (fieldnumber==5)
    {
	shhfrom6.selectedIndex=shhfrom5.selectedIndex;
	shhto6.selectedIndex=shhto5.selectedIndex;
	smifrom6.selectedIndex=smifrom5.selectedIndex;
	smito6.selectedIndex=smito5.selectedIndex;
    }
    else if (fieldnumber==6)
    {
	shhfrom7.selectedIndex=shhfrom6.selectedIndex;
	shhto7.selectedIndex=shhto6.selectedIndex;
	smifrom7.selectedIndex=smifrom6.selectedIndex;
	smito7.selectedIndex=smito6.selectedIndex;
    }
  }
}

function copycontactdetails(fieldnumber)
{
  with(document.info)
  {
    if (fieldnumber==1)
    {
	purchaseauthority.value=contactname.value;
	purchaseauthorityemail.value=email.value;
	purchaseauthoritytelephone.value=telephone.value;
    }
    else if (fieldnumber==2)
    {
	timesheetsignature.value=purchaseauthority.value;
	timesheetsignatureemail.value=purchaseauthorityemail.value;
	timesheetsignaturetelephone.value=purchaseauthoritytelephone.value;
    }
  }
}

function checkCandidate()
{
  var exp1 = /^[A-CEGHJ-NOPR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}[0-9]{6}[A-D\s]{1}/i;
  var exp2 = /(^GB)|(^BG)|(^NK)|(^KN)|(^TN)|(^NT)|(^ZZ).+/i;
  with (document.info)
  {
   /*
   ni.value=ni.value.toUpperCase();
   */
   temp1="";
   for (i=0; i<document.info.jobsectorid.length; i++)
   {
    if (document.info.jobsectorid[i].selected==true)
     temp1=temp1+document.info.jobsectorid[i].value+",";
   }
   document.info.jobsectors.value=temp1.substring(0,temp1.length-1);
   temp1="";
   for (i=0; i<document.info.locationid.length; i++)
   {
    if (document.info.locationid[i].selected==true)
     temp1=temp1+document.info.locationid[i].value+",";
   }
   document.info.locations.value=temp1.substring(0,temp1.length-1);

   if (fullname.value=='')
   {
    alert("Please enter your full name");
    return(false);
   }
   else if (address.value=='')
   {
    alert("Please enter your address");
    return(false);
   }
   else if (address.value.length>200)
   {
    alert("Please shorten the address to 200 or less characters");
    return(false);
   }
   else if (postcode.value=='')
   {
    alert("Please enter your postcode");
    return(false);
   }
   else if (country.value=='-')
   {
    alert("Please select your country");
    return(false);
   }
   /*
   else if (nationality.value=='')
   {
    alert("Please enter your nationality");
    return(false);
   }
   else if (ni.value.length!=9)
   {
       alert("Please enter a valid national insurance number, no spaces");
       return(false);
   }
   else if (!ni.value.match(exp1) || ni.value.match(exp2)) 	
   {	  
       alert("Please enter a valid national insurance number, no spaces");
       return(false);
   }
   else if (rate_from.value=='0' || rate_to.value=='0')
   {
    alert("Please select a rate range");
    return(false);
   }
   */
   else if (email.value=='')
   {
    alert("Please enter your email address");
    return(false);
   }
   else if ((email.value.indexOf('@')==-1) || (email.value.indexOf('.')==-1)) 
   {
    alert("Please enter a valid email address");
    return(false);
   }
   /*
   else if (position_sought1.value.length<2)
   {
    alert("Please enter your position sought");
    return(false);
   }
   else if (skills.value.length<2)
   {
    alert("Please enter your skills separating them by commas");
    return(false);
   }
   else if (skills.value.length>1000)
   {
    alert("Please shorten your skills to 1,000 or less characters");
    return(false);
   }
   else if (education.value.length>1000)
   {
    alert("Please shorten your education to 1,000 or less characters");
    return(false);
   }
   else if (brief_summary1.value.length>500)
   {
    alert("Please shorten your brief summary 1 to 500 or less characters");
    return(false);
   }
   else if (brief_summary2.value.length>500)
   {
    alert("Please shorten your brief summary 2 to 500 or less characters");
    return(false);
   }
   else if (brief_summary3.value.length>500)
   {
    alert("Please shorten your brief summary 3 to 500 or less characters");
    return(false);
   }
   else if (profile_assessments.value.length>1000)
   {
    alert("Please shorten your profile of assessments to 1,000 or less characters");
    return(false);
   }
   else if (qualifications.value.length>1000)
   {
    alert("Please shorten your qualifications to 1,000 or less characters");
    return(false);
   }
*/
   else if (locationid.value=='0' || locationid.selectedIndex==-1)
   {
    alert("Please select one or more locations");
    return(false);
   }
   else if (jobsectorid.value=='0' || jobsectorid.selectedIndex==-1)
   {
    alert("Please select one or more job sectors");
    return(false);
   }
   else if (cv.value.length==0)
   {
    alert("Please upload your CV, as a Word document, PDF, text or html file");
    return(false);
   }
   else if (cv.value.length>0 && cv.value.toLowerCase().indexOf('.doc')==-1 && cv.value.toLowerCase().indexOf('.pdf')==-1 && cv.value.toLowerCase().indexOf('.txt')==-1 && cv.value.toLowerCase().indexOf('.htm')==-1 && cv.value.toLowerCase().indexOf('.rtf')==-1)
   {
    alert("Please save your CV as a Word document, PDF, text or html file");
    return(false);
   }
   else if (cv.value.toLowerCase().indexOf('.exe')>-1 || cv.value.toLowerCase().indexOf('.bat')>-1 || cv.value.toLowerCase().indexOf('.tif')>-1 || cv.value.toLowerCase().indexOf('.bmp')>-1 || cv.value.toLowerCase().indexOf('.shs')>-1)
   {
    alert("Please save your CV as a Word document, PDF, text or html file");
    return(false);
   }
/*
   else if (picture.value.length>0 && picture.value.toLowerCase().indexOf('.jpg')==-1 && picture.value.toLowerCase().indexOf('.gif')==-1)
   {
    alert("Please save your picture as a JPG or GIF file");
    return(false);
   }
*/
   else if (password.value=='')
   {
    alert("Please enter your password");
    return(false);
   }
  }
}


function decimalOnly(field)
{
	var valid = "0123456789.";
	ok = 1;
	var temp;
	for (var i=0; i<field.value.length; i++)
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0 && field.value.length>0 && field.value!='-')
	{
		alert("Please only enter numbers in this field");
		field.focus();
		field.select();
	}
}

function checkCandidateSearch()
{
  with (document.info)
  {
   if ((position_sought1.value.length<2) && (rate.value==0) && (jobsectorid.value==0) && (locationid.value==0) && (skills.value==''))
   {
    alert("Please select at least one search criteria");
    return(false);
   }
   else if (sdd.selectedIndex==0 && smm.selectedIndex==0 && syyyy.selectedIndex==0)
   {
    alert("Please select a start date");
    return(false);
   }
   else if (edd.selectedIndex==0 && emm.selectedIndex==0 && eyyyy.selectedIndex==0)
   {
    alert("Please select an end date");
    return(false);
   }
  }
}

function confirmremovecontract(url)
{
  var x=window.confirm('Are you sure you want to cancel this job contract');
  if (x) document.location=url;
}

function checkJobAlert()
{
  with (document.info)
  {
   if (keywords.value.length>400)
   {
    alert("Please shorten the keywords to 400 or less characters");
    return(false);
   }
   else if (email.value=='')
   {
    alert("Please enter your email address");
    return(false);
   }
   else if ((email.value.indexOf('@')==-1) || (email.value.indexOf('.')==-1)) 
   {
    alert("Please enter a valid email address");
    return(false);
   }
   else if (locationid.value=='0')
   {
    alert("Please select a location");
    return(false);
   }
   else if (ratefrom.value=='0')
   {
    alert("Please select a minimum rate");
    return(false);
   }
   else if (rateto.value=='0')
   {
    alert("Please select a maximum rate");
    return(false);
   }
  }
}

function checktimesheet(formname)
{
  with (formname)
  {
   if (hours_day1.value=='' && hours_day2.value=='' && hours_day3.value=='' && hours_day4.value=='' && hours_day5.value=='' && hours_day6.value=='' && hours_day7.value=='')
   {
      alert("Please enter your hours worked");
      return(false);
   }
   if (hours_day1.value!='')
   {
	var valid = "0123456789.";
	ok = 1;
	var temp;
	for (var i=0; i<hours_day1.value.length; i++)
	{
		temp = "" + hours_day1.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0 && hours_day1.value.length>0 && hours_day1.value!='-')
	{
		alert("Please only enter numbers in the Hours worked on Monday field");
		return(false);
	}
   }
   if (hours_day2.value!='')
   {
	var valid = "0123456789.";
	ok = 1;
	var temp;
	for (var i=0; i<hours_day2.value.length; i++)
	{
		temp = "" + hours_day2.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0 && hours_day2.value.length>0 && hours_day2.value!='-')
	{
		alert("Please only enter numbers in the Hours worked on Tuesday field");
		return(false);
	}
   }
   if (hours_day3.value!='')
   {
	var valid = "0123456789.";
	ok = 1;
	var temp;
	for (var i=0; i<hours_day3.value.length; i++)
	{
		temp = "" + hours_day3.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0 && hours_day3.value.length>0 && hours_day3.value!='-')
	{
		alert("Please only enter numbers in the Hours worked on Wednesday field");
		return(false);
	}
   }
   if (hours_day4.value!='')
   {
	var valid = "0123456789.";
	ok = 1;
	var temp;
	for (var i=0; i<hours_day4.value.length; i++)
	{
		temp = "" + hours_day4.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0 && hours_day4.value.length>0 && hours_day4.value!='-')
	{
		alert("Please only enter numbers in the Hours worked on Thursday field");
		return(false);
	}
   }
   if (hours_day5.value!='')
   {
	var valid = "0123456789.";
	ok = 1;
	var temp;
	for (var i=0; i<hours_day5.value.length; i++)
	{
		temp = "" + hours_day5.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0 && hours_day5.value.length>0 && hours_day5.value!='-')
	{
		alert("Please only enter numbers in the Hours worked on Friday field");
		return(false);
	}
   }
   if (hours_day6.value!='')
   {
	var valid = "0123456789.";
	ok = 1;
	var temp;
	for (var i=0; i<hours_day6.value.length; i++)
	{
		temp = "" + hours_day6.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0 && hours_day6.value.length>0 && hours_day6.value!='-')
	{
		alert("Please only enter numbers in the Hours worked on Saturday field");
		return(false);
	}
   }
   if (hours_day7.value!='')
   {
	var valid = "0123456789.";
	ok = 1;
	var temp;
	for (var i=0; i<hours_day7.value.length; i++)
	{
		temp = "" + hours_day7.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0 && hours_day7.value.length>0 && hours_day7.value!='-')
	{
		alert("Please only enter numbers in the Hours worked on Sunday field");
		return(false);
	}
   }
   if (expensespaid.value!='')
   {
	var valid = "0123456789.";
	ok = 1;
	var temp;
	for (var i=0; i<expensespaid.value.length; i++)
	{
		temp = "" + expensespaid.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = 0;
	}
	if (ok==0 && expensespaid.value.length>0 && expensespaid.value!='-')
	{
		alert("Please only enter numbers in the expenses field");
		return(false);
	}
   }
  }
}

function checkTellfriend()
{
  with (document.info)
  {
   if (friendemail.value=='-')
   {
    alert("Please enter a valid email address");
    return(false);
   } 
   else if ((friendemail.value.indexOf('@')==-1) || (friendemail.value.indexOf('.')==-1)) 
   {
    alert("Please enter a valid email address");
    return(false);
   }
   else if (email.value=='')
   {
    alert("Please enter an email address");
    return(false);
   } 
   else if ((email.value.indexOf('@')==-1) || (email.value.indexOf('.')==-1)) 
   {
    alert("Please enter a valid email address");
    return(false);
   }
  }
}

function today()
{
 Now = new Date();

 dateval = Now.getDate();
 monthval = Now.getMonth();
 yearval = Now.getFullYear();

 if (((monthval == 1)||(monthval == 3)||(monthval == 5)||(monthval == 8)||(monthval == 10))&&(dateval == 1))
 {
  dateval = 32;
  monthval = monthval - 1;
 }
 if (((monthval == 4)||(monthval == 6)||(monthval == 7)||(monthval == 9)||(monthval == 11))&&(dateval == 1))
 {
  dateval = 31;
  monthval = monthval - 1;
 }
 if ((monthval == 2)&&(dateval == 1))
 {
  if (yearval % 4 == 0)
  {
   dateval = 30;
   monthval = monthval - 1;
  }
  else
  {
   dateval = 29;
   monthval = monthval - 1;
  }
 }
 if ((monthval == 0)&&(dateval == 1))
 {
  dateval = 32;
  monthval = 11;
  yearval = yearval - 1;
 }
 
 with (document.info)
 {
	 sdd.selectedIndex = dateval-1;
	 smm.selectedIndex = monthval;
	 syyyy.selectedIndex = yearval-2008;
	 edd.selectedIndex = dateval-1;
	 emm.selectedIndex = monthval;
	 eyyyy.selectedIndex = yearval-2008;
 }
}

function checkReminder()
{
  with (document.info)
  {
   if (email.value.length<5 || email.value.indexOf('@')==-1 || email.value.indexOf('.')==-1)
   {
    alert("Please enter your correct email address");
    return(false);
   }
  }
}
