function highlight(cell) { cell.bgColor = '#000000'; }
function revert(cell)    { cell.bgColor = '#31416B'; }

// Checkjob fires when the focus is taken off the job title field
// It checks to see if this is a new job title, so resets the urn to 0
function checkjob(thisval,pre) {
  var checkval = eval("document.addemp." + pre + "name.value")
  if (checkval!=thisval)
	{
  	eval("document.addemp." + pre + "urn.value = '0'");
  	eval("document.addemp." + pre + "name.value = '" + thisval + "'");
	}
}

// Setjob splits the value of the job select box and sets the other fields
function setjob(thisobj,pre) {
  var thisstr = thisobj.options[thisobj.selectedIndex].value;
  var x = thisstr.split("~");
  eval("document.addemp." + pre + "urn.value = x[0]");
  eval("document.addemp." + pre + "name.value = x[1]");
  eval("document.addemp." + pre + "named.value = x[1]");
}

// setdate is to create a SQL server date from a series of 2 text boxes and a select menu
// All fields use the same stem for naming to facilitate the generic nature of the function
function setdate(frm,datefld) {
	var thisobj = ("document." + frm);
	var thisday = eval(thisobj + "." + datefld + "1.value");
	var thismon = eval(thisobj+"."+datefld+"2.options["+thisobj+"."+datefld+"2.selectedIndex].value");
	var thisyea = eval(thisobj + "." + datefld + "3.value");
	// irrespective of the rest of the date values, update the year to a 4 figure year
  	if ((thisyea<=100)&&(isNaN(parseInt(thisyea))==false))
		{if(thisyea>=31)
			{thisyea=(1900 + parseInt(thisyea));}
		else
			{thisyea=(2000 + parseInt(thisyea));}
		 eval(thisobj + "." + datefld + "3.value="+thisyea);
		}

	if (isNaN(parseInt(thisday))||thismon==0||isNaN(parseInt(thisyea)))
		{ eval(thisobj+"."+datefld+".value=''");}
	else
		{ 
		  if (thisday.length==1) thisday=("0" + thisday);
		  if (isDate(""+thisyea+thismon+thisday+"")==false) {
			alert(" "+thisday+"/"+thismon+"/"+thisyea+" is not a valid date");
			eval(thisobj+"."+datefld+".value=''");
			}
		  else  {var thisDate = new Date();
			if((datefld=="empDob")&&((thisDate.getFullYear()-thisyea)<15))
				{alert("Sorry, but that would make the age less than 16 - please try again");}
			else {thisfld = eval(thisobj+"."+datefld);thisfld.value=(""+thisyea+thismon+thisday+"");}
			}
		}
}

function isDate(dateStr) {
    month = dateStr.substring(4,6);
    day = dateStr.substring(6,8);
    year = dateStr.substring(0,4);
    if (day < 1 || day > 31) { return false;}
    if ((month==4 || month==6 || month==9 || month==11) && day>=31) {return false;}
    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {return false;}
    }
    return true; // date is valid
}

function clearsearch(thisfield) {
	if(thisfield.value=='Enter keywords here') thisfield.value='';
	else {
		if(thisfield.value=='') thisfield.value='Enter keywords here';
		}
}

// Validate form
function searchform(thisform) {
	if ((thisform.searchtext.value=='')||(thisform.searchtext.value=='Enter keywords here')){
		alert("Sorry, but you haven't entered any search keywords!"); return false; } else return true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_displayStatusMsg(msgStr) { 
  status=msgStr;
  document.MM_returnValue = true;
}
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_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}
// setzero is to turn a text string (which is a number) into a number with two padded decimal places
function setzero(sz_num) {
	if(sz_num=='') return "0.00"
	sz_num = "" + sz_num;
	sz_num = sz_num.replace(",","");
	if(isNaN(sz_num)) sz_num = "0" 
	sz_num = parseFloat(sz_num);
	sz_num = Math.round(sz_num*100)/100;
	sz_num = "" + sz_num;
	var sz_dotpos = sz_num.indexOf('.');
	if (sz_dotpos < 0) sz_num+=".00";
	if (sz_dotpos==(sz_num.length-1)) sz_num+="00";
	if (sz_dotpos==(sz_num.length-2)) sz_num+="0";
	return sz_num ;
}

function prod_details(a) {
	desc = ''; price = a[2]; perm_urn = 0; rrp = ''; partno = '';
	if(a[3]=='F') {desc = 'Sorry, but this product is currently unavailable'; price='N/A';}
	else { 
		if(a[4]=='0') desc = 'Sorry, but this product is currently out of stock';
		else { // in stock and active
			if(a[5]=='T') desc+='Sale Price - with ' + a[8] + ' : was ' + currsign + a[7];
			if(parseFloat(a[9])>parseFloat(a[2])) rrp = 'Save ' + currsign + setzero(parseFloat(a[9])-parseFloat(a[2])) + ' on the RRP'
			if(!a[1]=='') partno='Part no: ' + a[1] 
			perm_urn = a[0]
		}
	}
	document.productform.status_price.value=price; 
	document.productform.status_info.value=desc; 
	document.productform.perm_urn.value=perm_urn; 
	document.productform.status_rrp.value=rrp; 
	document.productform.status_partno.value=partno; 
	//if (document.layers) { document.layers.product_info.document.write(desc); document.layers.product_info.document.close(); }
	//else { if (document.all) product_info.innerHTML = desc; }
}
function getSelectedRadio(buttonGroup) { // returns the array number of the selected radio button or -1 if no button is selected
	if (buttonGroup[0]) { for (var i=0; i<buttonGroup.length; i++) if (buttonGroup[i].checked) return i } 
	else {if (buttonGroup.checked) return 0;} return -1; }

function getSelectedRadioValue(buttonGroup) { // returns the value of the selected radio button or "" if no button is selected
	var i = getSelectedRadio(buttonGroup);
	if (i == -1) return ""; else {if (buttonGroup[i]) return buttonGroup[i].value; else return buttonGroup.value; }}

// Ajax functions
function GetXmlHttpObject() {
	var xmlHttp=null;
	try { xmlHttp=new XMLHttpRequest(); } // Firefox, Opera 8.0+, Safari
	catch (e) { // Internet Explorer
		try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	return xmlHttp;
}

function getajax(div, ajaxpage, ajtype, var1, var2, var3, var4) {
	xmlHttp=GetXmlHttpObject();
	//document.getElementById(div).innerHTML = "Loading ...";
	if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } 
	xmlHttp.onreadystatechange=function() { if (xmlHttp.readyState==4) { document.getElementById(div).innerHTML=xmlHttp.responseText } }
	xmlHttp.open("GET",ajaxpage + "?ajax="+div+"|"+ajtype+"|"+var1+"~"+var2+"~"+var3+"~"+var4+"|"+new Date().getTime(),true);
	xmlHttp.send(null);
} 

function getajaxas(div, ajaxpage, ajtype, var1, var2, var3, var4) {
	xmlHttp=GetXmlHttpObject();
	//document.getElementById(div).innerHTML = "Loading ...";
	if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } 
	xmlHttp.open("GET",ajaxpage + "?ajax="+div+"|"+ajtype+"|"+var1+"~"+var2+"~"+var3+"~"+var4+"|"+new Date().getTime(),false);
	xmlHttp.send(null);
	document.getElementById(div).innerHTML=xmlHttp.responseText;
} 

