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+"");
				}
			}
		}
}

// setdatequick is to create a SQL server date from a single text box - to allow 01/04/04 entry
function setdatequick(frm,datefld,initial) {
	//if(typeof(initial=="undefined")) alert("undefined")
	//alert(typeof(initial=="undefined"))
	var thisobj = ("document." + frm);
	var datestr = "" + eval(thisobj + "." + datefld + "1.value");
	if(datestr=="") {eval(thisobj+"."+datefld+".value=''"); return;}
	if((datestr.length>5)&&(datestr.indexOf("/")==-1)&&(!isNaN(datestr))) {
		datestr = datestr.substr(0,2)+"/"+datestr.substr(2,2)+"/"+datestr.substr(4); }
	datestr = datestr.replace("-","/");
	datestr = datestr.replace("-","/");
	eval(thisobj + "." + datefld + "1.value='"+datestr+"'");
	if((datestr.indexOf("/")==-1)||(datestr.indexOf("/",5)==-1)||(datestr.indexOf("/")==datestr.indexOf("/",5))) {alert("Please enter dates in dd/mm/yyyy or ddmmyyyy format"); return;}
	var x = datestr.split("/"); var thisday = x[0]; var thismon = x[1]; var thisyea = x[2];
	// irrespective of the rest of the date values, update the year to a 4 figure year
	//alert(parseFloat("09"))//alert(thisyea)
	if(isNaN(parseFloat(thisday)) || isNaN(parseFloat(thismon)) || isNaN(parseFloat(thisyea))) {alert("Please enter dates in dd/mm/yyyy or ddmmyyyy format"); return;}
  	if ((thisyea<=100)&&(isNaN(parseFloat(thisyea))==false)) { if(thisyea>=31) thisyea=(1900 + parseFloat(thisyea)); else thisyea=(2000 + parseFloat(thisyea)); }
	if (isNaN(parseInt(thisday))||thismon==0||isNaN(parseFloat(thisyea))) eval(thisobj+"."+datefld+".value='';" + thisobj+"."+datefld+"1.value='';")
	else{ if (thisday.length==1) thisday=("0" + thisday);
		  if ((isDate(""+thisyea+thismon+thisday+"")==false)||thisyea<1900||thismon>12) {
			alert(" "+thisday+"/"+thismon+"/"+thisyea+" is not a valid date"); eval(thisobj+"."+datefld+".value='';" + thisobj+"."+datefld+"1.value='';"); 
				eval(thisobj+"."+datefld+".value="+thisobj+"."+datefld+"last.value;")
				eval(thisobj+"."+datefld+"1.value="+thisobj+"."+datefld+"last1.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+"");
					eval(thisobj + "." + datefld + "1.value='"+thisday+"/"+thismon+"/"+thisyea+"'");
					eval(thisobj+"."+datefld+"last.value="+thisobj+"."+datefld+".value;")
					eval(thisobj+"."+datefld+"last1.value="+thisobj+"."+datefld+"1.value;"); 
				}
			}
		}
}

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 = ''; del = '';
	if(a[3]=='F') {desc = 'Sorry, but this product is currently unavailable'; price='N/A';}
	else { 
		if(parseFloat(a[6])>0) del = currsign + setzero(parseFloat(a[6])); else del = 'Free';
		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; document.productform.delivery.value=del;
	//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 addtickets(cnt,available,add,current) {
	newtotal = parseInt(current) + parseInt(add)
	if(newtotal<0 || newtotal > available) return
	eval("document.productform.Quantity" + cnt + ".value=" + newtotal)
	setprice(cnt, eval("document.productform.ticketprice" + cnt +".value"), newtotal)
}
function checkquantity(cnt,available,current) {
	newtotal = parseInt(setzero(current))
	if(newtotal<0) newtotal = 0
	if(newtotal>available) newtotal = available
	eval("document.productform.Quantity" + cnt + ".value="+newtotal)
	setprice(cnt, eval("document.productform.ticketprice" + cnt +".value"), newtotal)
}
function setprice(cnt,price,qty) {
	if(qty>0) eval("document.productform.totalprice"+cnt+".value='£"+setzero(parseFloat(price)*parseInt(qty))+"'")
	else eval("document.productform.totalprice"+cnt+".value=''")
}

function bc_logout(nextpage) { if(confirm("This will log you out of the Black Culm Control Panel. Is this OK?")) document.location.href=nextpage; }
function send1mail(root,murn) { window.open(root+'send1mail.asp?numflag1='+murn,'','width=630,height=620') }

function openawindow(url, t, w, h){
	// Fudge factors for window decoration space.
	w += 32;
	h += 96;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	var win = window.open(url,
		name,
		'width=' + w + ', height=' + h + ', ' +
		'left=' + wleft + ', top=' + wtop + ', ' +
		'location=no, menubar=no, ' +
		'status=no, toolbar=no, scrollbars=no, resizable=no');
	// Just in case width and height are ignored
	win.resizeTo(w, h);
	// Just in case left and top are ignored
	win.moveTo(wleft, wtop);
	win.focus();
}

function showhide(id) {
	obj = document.getElementById(id); 
	if (obj.style.display == "none") obj.style.display = ""; else obj.style.display = "none";
} 
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
}

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; }}

function handlecheck(thisval) { if(thisval!="") window.open('handlecheck.asp?h='+thisval,'','width=250,height=150,toolbar=no,location=no,menubar=no,scrollbars=no,resizable=no'); else alert("Sorry, but you have not entered a forum name to check")}

function usernamecheck(thisval,thisurn) { if(thisval!="") window.open('usernamecheck.asp?h='+thisval+'&u='+thisurn,'','width=250,height=150,toolbar=no,location=no,menubar=no,scrollbars=no,resizable=no'); else alert("Sorry, but you have not entered a username name to check")}

function usernamecheck2(thisval,thisurn,thispath) { if(thisval!="") window.open(thispath+'usernamecheck.asp?h='+thisval+'&u='+thisurn,'','width=250,height=150,toolbar=no,location=no,menubar=no,scrollbars=no,resizable=no'); else alert("Sorry, but you have not entered a username name to check")}

function testlink(thisval) { if(thisval!=""&&thisval!="http://") window.open(thisval,'linktest','toolbar=yes,location=yes,menubar=yes,scrollbars=yes,resizable=yes'); else alert("Sorry, but you have not entered an address to test")}

function tickall(chkval, chkname) {
	var items = parseInt(document.getElementById("cnt").value)
	for(i=1; i<=items; i++) document.getElementById(chkname+i).checked=chkval;
}

