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_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_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 confirmdelete()
{
  if(confirm('Are you sure you want to delete this ?'))
  {
    return true;
  }
  else
    return false;
}

function confirmthis(comment)
{
  var confwords = 'Are you sure you want to ' + comment;

  if(confirm(confwords))
  {
    return true;
  }
  else
    return false;
}

function validateDate(fld) {
  if (!checkDate(fld)) {
  // focus if validation fails
  fld.focus();
  }
}

function valcheck(form)
{
  if (!form.agreement.checked) 
  {
    alert("You must agree to the Terms of the site.");
    form.agreement.focus();
    return false;
  }
}


function checkDate(fld) {
   var mo, day, yr;
   var entry = fld.value;
   var reLong = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{4}\b/;
   var reShort = /\b\d{1,2}[\/-]\d{1,2}[\/-]\d{2}\b/;
   var valid = (reLong.test(entry)) || (reShort.test(entry));
   if (valid) {
     var delimChar = (entry.indexOf("/") != -1) ? "/" : "-";
     var delim1 = entry.indexOf(delimChar);
     var delim2 = entry.lastIndexOf(delimChar);
	 day = parseInt(entry.substring(0, delim1), 10);
	 mo = parseInt(entry.substring(delim1+1, delim2), 10);
	 yr = parseInt(entry.substring(delim2+1), 10);

	 // handle two-digit year

     if (yr < 100) {
       var today = new Date();
       // get current century floor (e.g., 2000)

       var currCent = parseInt(today.getFullYear() / 100) * 100;
       // two digits up to this year + 15 expands to current century

       var threshold = (today.getFullYear() + 15) - currCent;
       if (yr > threshold) {
         yr += currCent - 100;
       } else {
	   yr += currCent;
	 }
   }

   var testDate = new Date(yr, mo-1, day);

   if (testDate.getDate() == day) {
   if (testDate.getMonth() + 1 == mo) {
     if (testDate.getFullYear() == yr) {
	   // fill field with database-friendly format
	   fld.value = day + "/" + mo + "/" + yr;
	   return true;
	 } else {
	   alert("There is a problem with the year entry.");
     }
   } else {
     alert("There is a problem with the month entry.");
   }
  } else {
  alert("There is a problem with the date entry.");
}
} else {
alert("Incorrect date format. Enter as dd/mm/yyyy.");
}
return false;
}

function openCenteredWindow(url) {
  var width = 400;
  var height = 300;
  var left = parseInt((screen.availWidth/2) - (width/2));
  var top = parseInt((screen.availHeight/2) - (height/2));
  var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
  myWindow = window.open(url, "subWind", windowFeatures);
}

function clearDefault(el) { if (el.value=="DD/MM/YYYY") el.value = "" }
function clearDefault2(el,def) { if (el.value==def) el.value = "" }

function checkAll(wotForm,wotState,wotLike) {
  for (a=0; a<wotForm.elements.length; a++) {
  if (wotForm.elements[a].id.indexOf(wotLike) == 0) {
    wotForm.elements[a].checked = wotState ;
  }
  }
}

function emailForm(email, ref)
{
  email = email.replace(/@/g,".");
  email = email.replace(/:/g,"@");

  var subject = "UKJobs.net enquiry. Ref: " + ref;
  var mailto_link = 'mailto:'+email+'?subject='+subject;

  win = window.open(mailto_link,'emailWindow');
  if (win && win.open &&!win.closed) win.close();

  return false;
} 

