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 invalid_message(theMessage) {
	alert(theMessage);
}
function up_it(x) {
	x.value = x.value.toUpperCase();
}
function validate_qnty(a) {
	if (parseInt(a.value) <= 0 ||
		a.value.substring(0,1) > '9' ||
		a.value.substring(0,1) < '0' ) {
		a.value='1';
		alert("A valid quantity must be entered.");
	} else {
		a.value = parseInt(a.value);
	} 
}
function isTime(atime) {
	var isvalid;
	if (atime.value.toUpperCase()=='NOW') {
	   isvalid=2;
	} else if (atime.value=='') {
		isvalid=2; //no action to perform
	} else if (atime.value.indexOf(':')>=0 && atime.value.length >= atime.value.indexOf(':')+3) {
		var vhour = atime.value.substring(0,atime.value.indexOf(':'));
		var vmin = atime.value.substring(atime.value.indexOf(':')+1,atime.value.indexOf(':')+3);
		var vrest = '';
		if (vhour < 0 || vhour > 23 || vmin < 0 || vmin > 59) {
			isvalid = 0;
		} else if (atime.value.length > atime.value.indexOf(':')+3) {
			vrest = atime.value.substring(atime.value.indexOf(':')+3,atime.value.length);
			while (vrest.substring(0,1) == ' ') {
				vrest = vrest.substring(1,vrest.length);
			}
			if (vhour > 12 || !(vrest.toUpperCase()=='AM' || 
				vrest.toUpperCase()=='PM')) {
				isvalid = 0;
			} else {
				isvalid = 1;
			}
		} else {
			isvalid = 1;
		}
	} else {
		isvalid = 0;
	}
	if (isvalid == 0) {
		alert ("Please enter the time as 'NOW' or using format hh:mm AM/PM or hh:mm (24hr)");
		//atime.value = 'hh:mm AM';
		//document.form1.scheddatedisplay.focus();
		atime.value = '';
		atime.focus();
	} else if (isvalid == 1) {
		if (vhour.length==1) vhour = '0' + vhour;
		if (vrest.length>0) vrest = ' ' + vrest;
		atime.value = vhour + ':' + vmin + vrest.toUpperCase();
	} 
}
function isDate(adate, outdate) {
	if (adate.value!='') {
	var vDay = parseInt(adate.value.substring(0,adate.value.indexOf('/')),10);
	var vMonth = parseInt(adate.value.substring(adate.value.indexOf('/')+1,
		adate.value.indexOf('/',3)),10);
	var vYear = parseInt(adate.value.substring(adate.value.indexOf('/',3)+1,
		adate.value.length),10);
	if (vYear <10) { vYear = '200' + vYear; }
	else if (vYear <70) { vYear = '20' + vYear; }
	else if (vYear >= 70 && vYear <= 99) { vYear = '19' + vYear; }
	var vLeapY = vYear % 4;
	var isValid = 1;
	if (isNaN(vDay) || isNaN(vMonth) || isNaN(vYear)) {
		isValid = 0;
	}
	if (!((vYear >= 0 && vYear <= 99) || 
		(vYear >= 1970 && vYear <2070))) {
		isValid = 0;
	}
	else if (vMonth <1 || vMonth > 12) {
		isValid = 0;
	}
	else if (vDay <1 || vDay > 31) {
		isValid = 0;
	}
	else if (vDay>30 && (vMonth==2 || vMonth==4 || vMonth==6 ||
		vMonth==9 || vMonth==11)) {
		isValid = 0;
	}
	else if (vDay>29 && vMonth==2) {
		isValid = 0;
	}
	if (isValid == 0) {
		alert("Dates must be entered in dd/mm/yyyy format.");
		adate.value = '';
		outdate.value = '';
	}
	else if (vDay==29 && vMonth==2 && vLeapY>0) {
		alert("February 29 does not exist in year " + vYear + "!!");
		adate.value = '';
		outdate.value = '';
	}
	else {
		if (vMonth <10) { vMonth = '0' + vMonth; }
		if (vDay <10) { vDay = '0' + vDay; }
		// hack to enable strings to concatenate rather than evaluate expression.
		outdate.value = " " + vYear + vMonth + vDay;
		outdate.value = outdate.value.substring(1,outdate.value.length);

		adate.value=vDay + '/' + vMonth + '/' + vYear;
		}
	}
}

function changeBg( aitem, acolor ) {
	aitem.style.background = acolor;
}

function showJob( key, jid ) {
	location.href="dmiis.dll?dmID=Drill&key="+key+"&jid="+jid;
}

function selectAddr( key, sid, sdd ) {
	location.href="dmiis.dll?dmID=Booking&key="+key+"&sid="+sid+"&sdd=" +sdd;
}

function showManRecords( key, mid ) {
	location.href="dmiis.dll?dmID=ViewEDIR&key="+key+"&mid="+mid;
}

function showManDetails( key, mid, rid ) {
	location.href="dmiis.dll?dmID=ViewEDID&key="+key+"&mid="+mid+"&rid="+rid;
}

function changeBg2( aitem, acolor ) {
	var theitem;
//	window.status = aitem.id;
	theitem = eval('x' + aitem.id.substring(1));
	theitem.style.background = acolor;
	theitem = eval('y' + aitem.id.substring(1));
	theitem.style.background = acolor;
//	eval('x' + aitem.id.substring(1) + '.style.background = ' + acolor);
//	eval('y' + aitem.id.substring(1) + '.style.background = ' + acolor);
}

function DisableMultiClick() {
 if (document.fupload.clicked.value == "Y") {
  alert(
   "You have either used the [BACK] button to return to this page; or\n" +
   "You have clicked the 'Upload' button more than once.\n\n" +
   "PLEASE do not click 'Upload' more than once.\n" +
   "You can start over by using the 'Reset' button.");
  return false; // already sent
 }
 document.fupload.clicked.value = "Y";
 uploadresult.innerHTML = "<br><strong>Please wait.... uploading file</strong>"; 
 return true;
}
function isInteger(a) {
	if (a.value != '') {
		if (a.value.substring(0,1) < '0' || a.value.substring(0,1) > '9') {
			a.value = '';
			alert("An integer must be entered.");
		} else {
			a.value = parseInt(a.value);
		}
	}
}
function disableEnterSubmit() {
	testElm = document.getElementById("pctt");
	if (!testElm.attachEvent) { if (!testElm.setAttribute) { return; } }
	
	for(i=0;i<document.forms[0].length;i++) {
		anEl = document.forms[0].elements[i];
		if (anEl.type && (anEl.type == "textarea")) {}
		else if (anEl.attachEvent) {
			anEl.attachEvent("onkeydown", function() {return !(event.keyCode==13);});
		}
		else if (anEl.setAttribute) {
			anEl.setAttribute("onkeydown", "return !(event.keyCode==13);");
		}
	}
}
function debugtableborders(el) {
	var els = el.getElementsByTagName("table");
	if (els) {
		for(var i=0;i<els.length;i++) {
			els[i].border = "1";
			els[i].borderColor = "#0000ff";
			els[i].cellPadding = "0";
			els[i].cellSpacing = "0";
		}
	}
}
