
//To expand and close sections
function toggleblocks (postid) { 
	var whichpost = document.getElementById(postid); 
	if (whichpost.className=="expandblock") { 
		whichpost.className="collapseblock"; 
	} else { 
		whichpost.className="expandblock"; 
	} 
} 


//Javascripting for Rollover Buttons
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_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 changeBox(cbox) {
	box = eval(cbox);
	box.checked = !box.checked;
}

function OnButtonPenName()
{
    document.frmContacts.action = "staciPending.php"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonPenCourse()
{
    document.frmContacts.action = "staciPending.php?orderby=course"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonPartDate()
{
    document.frmContacts.action = "staciPart.php?orderby=date"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonPartName()
{
    document.frmContacts.action = "staciPart.php"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonPartCourse()
{
    document.frmContacts.action = "staciPart.php?orderby=course"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonPenDate()
{
    document.frmContacts.action = "staciPending.php?orderby=date"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButton1()
{
    document.frmContacts.action = "saveTicks.php"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonName()
{
    document.frmContacts.action = "staciem.php?orderby=name"    // First target
	var orderBy = document.getElementById("orderBy");
	if (orderBy != null){
		orderBy.value = "name";
	}
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonNameCan()
{
    document.frmContacts.action = "staciCancelled.php?orderby=name"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonNameOrder()
{
    document.frmContacts.action = "changeTrainer.php?orderby=name"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}
function OnButtonNameOrderE()
{
    document.frmContacts.action = "changeTrainer.php?orderby=name&page=enquiry"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonDateOrder()
{
    document.frmContacts.action = "changeTrainer.php?orderby=date"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonEmployerOrder()
{
    document.frmContacts.action = "changeTrainer.php?orderby=employer"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonReasonOrder()
{
    document.frmContacts.action = "changeTrainer.php?orderby=reason"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonStateOrder()
{
    document.frmContacts.action = "changeTrainer.php?orderby=state"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonDateCan()
{
    document.frmContacts.action = "staciCancelled.php?orderby=date"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonWorksiteCan()
{
    document.frmContacts.action = "staciCancelled.php?orderby=worksite"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonReasonCan()
{
    document.frmContacts.action = "staciCancelled.php?orderby=reason"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonDateOrderE()
{
    document.frmContacts.action = "changeTrainer.php?orderby=date&page=enquiry"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonEmployerOrderE()
{
    document.frmContacts.action = "changeTrainer.php?orderby=employer&page=enquiry"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonReasonOrderE()
{
    document.frmContacts.action = "changeTrainer.php?orderby=reason&page=enquiry"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonStateOrderE()
{
    document.frmContacts.action = "changeTrainer.php?orderby=state&page=enquiry"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButton2()
{
    document.frmContacts.action = "saveTicks.php?orderby=course"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonInfo(client)
{
    document.frmContacts.action = "staciinfo.php?get=" + client;    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonCourse()
{
    document.frmContacts.action = "staciem.php?orderby=course"    // First target
	var orderBy = document.getElementById("orderBy");
	if (orderBy != null){
		orderBy.value = "course";
	}
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonStatus()
{
    document.frmContacts.action = "staciem.php?orderby=status"    // First target
	var orderBy = document.getElementById("orderBy");
	if (orderBy != null){
		orderBy.value = "status";
	}
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonWorkplace()
{
    document.frmContacts.action = "stacitm.php?orderby=workplace"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonStateTrainers()
{
    document.frmContacts.action = "stacitm.php?orderby=state"    // First target
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonState()
{
    document.frmContacts.action = "staciem.php?orderby=state"    // First target
	var orderBy = document.getElementById("orderBy");
	if (orderBy != null){
		orderBy.value = "state";
	}
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButtonLocation()
{
    document.frmContacts.action = "staciem.php?orderby=location"    // First target
	var orderBy = document.getElementById("orderBy");
	if (orderBy != null){
		orderBy.value = "location";
	}
	document.frmContacts.target = "_self";    // Open in a iframe
    document.frmContacts.submit();        // Submit the page
    return true;
}

function OnButton3(number, size)
{
    document.frmUnit.action = "saveUnits.php?current=" + number + "&size=" + size + "&btn=contact";    // First target
	document.frmUnit.target = "_self";    // Open in a iframe
    document.frmUnit.submit();        // Submit the page
    return true;
}

function redirect(theURL){
	window.location = theURL;
}

//-----------------------------------------------------------------------------
// CheckEvent - checks if a user agress to a message, if yes then will redirect to a new URL
// msg - the message displayed to the user
// theURL - the URL that is redirected to
//-----------------------------------------------------------------------------
function checkEvent(msg, theURL){
	//Display a message to the user asking for confirmation
	r = confirm(msg);
	
	//Check if the user agreed to the message
    if (r == 1) {
		//User agreed, redirect the user to a new URL
    	redirect(theURL);
        return true;
    } 
}// End function checkEvent


//-----------------------------------------------------------------------------
// allowPress - allows only certain keys to be pressed by the user
// type - the type of keys allowed by the user
//-----------------------------------------------------------------------------
function allowPress(type){
	switch(type){
		case 'numeric':
			if ((event.keyCode > 31 && event.keyCode < 45) || (event.keyCode == 46) || (event.keyCode > 57 && event.keyCode < 128)) event.returnValue = false;
			break;
		case 'price':
			if ((event.keyCode > 31 && event.keyCode < 46) || (event.keyCode == 47) || (event.keyCode > 57 && event.keyCode < 128)) event.returnValue = false;
			break;
	}// End switch
}// End function 

function enable(obj){
	obj.disabled = false;
	obj.focus();
}

function criteriaEnable(obj, currentObj, value){
	
	if (currentObj.value != value){
		obj.value = "";
		obj.disabled = true;
	} else {
		obj.disabled = false;
	}
}

function disable(obj){
	obj.value = "";
	obj.disabled = true;
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}

//-----------------------------------------------------------------------------
// CheckEvent - checks if a user agress to a message, if yes then will redirect to a new URL
// msg - the message displayed to the user
// theURL - the URL that is redirected to
//-----------------------------------------------------------------------------
function checkEvent2(msg){
	//Display a message to the user asking for confirmation
	r = confirm(msg);
	
	//Check if the user agreed to the message
    if (r == 1) {
		//User agreed, redirect the user to a new URL
    	document.FrmAffiliateReport.submit();
        return true;
    }
	
	return false;
}// End function checkEvent

function checkEventConfirm(msg){
	//Display a message to the user asking for confirmation
	r = confirm(msg);
	
	//Check if the user agreed to the message
    if (r == 1) {
		//User agreed, redirect the user to a new URL
    	document.form1.submit();
        return true;
    }
	
	return false;
}// End function checkEvent

function CheckAll(){
	
	count = document.frmInvoices.elements.length;
    for (i=0; i < count; i++) {
    	document.frmInvoices.elements[i].checked = 1;
	}// End for 
	
}// End function CheckAll

function UncheckAll(){
	count = document.frmInvoices.elements.length;
    for (i=0; i < count; i++) {
    	document.frmInvoices.elements[i].checked = 0;
	}// End for 
}

function EnablePrice(){
	document.FrmAffiliateReport.Price.disabled = false;
}

function EnablePriceTwo(){
	document.FrmAffiliateReport2.Price.disabled = false;
}

function ChangePrice(){
	ItemID = document.FrmAffiliateReport.ExtraItemID.value;
	if(ItemID == 0){
		document.FrmAffiliateReport.Price.disabled = false;
		//document.FrmAffiliateReport.otherDesc.disabled = false;
		Price1 = '';
		document.FrmAffiliateReport.hiddenPrice.value = Price1;
		document.FrmAffiliateReport.Price.value = Price1;	
	}else{
		document.FrmAffiliateReport.Price.disabled = true;
		//document.FrmAffiliateReport.otherDesc.disabled = false;
		Type = document.frmInvoices.type.value;
		
		Price1 = document.getElementById('ItemID'+ItemID+'').value;
		
		if (Type == "Local"){
			Price1 = Price1;
		}else{
			Distance = Price1 * 0.1;
			Price1 = (Price1 * 1) + (Distance * 1);
		}
	
	document.FrmAffiliateReport.hiddenPrice.value = Price1;
	document.FrmAffiliateReport.Price.value = Price1;	
	
	}

}

function ChangePriceTwo(){
	ItemID = document.FrmAffiliateReport2.ExtraItemID.value;
	if(ItemID == 9){
		document.FrmAffiliateReport2.otherDesc.disabled = false;
		Price1 = '';
	}else if(ItemID == 5){
		document.FrmAffiliateReport2.otherDesc.disabled = false;
		Price1 = '';
	}else if(ItemID == 1){
		document.FrmAffiliateReport2.otherDesc.disabled = false;
		Price1 = document.getElementById('ItemID'+ItemID+'').value ;
		Price1 = Price1;
	}else if(ItemID == 10){
		Price1 = document.getElementById('ItemID'+ItemID+'').value ;
		Price1 = Price1;
	}else if(ItemID == 45){
		document.FrmAffiliateReport2.otherDesc.disabled = false;
		Price1 = document.getElementById('ItemID'+ItemID+'').value ;
		Price1 = Price1;
	}else if(ItemID == 100){
		document.FrmAffiliateReport2.otherDesc.disabled = false;
		Price1 = '';
	}else{
		document.FrmAffiliateReport2.otherDesc.disabled = true;
	Price1 = document.getElementById('ItemID'+ItemID+'').value ;
	Price1 = Price1;
	
	}

		document.FrmAffiliateReport2.hiddenPrice.value = Price1;
		document.FrmAffiliateReport2.Price.value = Price1;	

}


function OnUnitSubmit(value){
    document.frmConfirm.action = "confirmExecute.php?type=" + value;    // First target
	document.frmConfirm.target = "_self";    // Open in a iframe
    document.frmConfirm.submit();        // Submit the page
    return true;
}

function SubmitOrderForm(action){
    document.frmAddItem.action = action;  
	document.frmAddItem.target = "_self";    // Open in a iframe
    document.frmAddItem.submit();        // Submit the page
    return true;
}

/* Menu functions */
var menuids=new Array("verticalmenu") //Enter id(s) of UL menus, separated by commas
var submenuoffset=-2 //Offset of submenus from main menu. Default is -2 pixels.

function createcssmenu(){
	for (var i=0; i<menuids.length; i++){
		var menutags=document.getElementById(menuids[i])
		if (menutags != null){
			ultags = menutags.getElementsByTagName("ul")
			for (var t=0; t<ultags.length; t++){
				var spanref=document.createElement("span")
				spanref.className="arrowdiv"
				spanref.innerHTML="&nbsp;&nbsp;"
				ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
				ultags[t].parentNode.onmouseover=function(){
					this.getElementsByTagName("ul")[0].style.left=this.parentNode.offsetWidth+submenuoffset+"px"
					this.getElementsByTagName("ul")[0].style.display="block"
				}
				ultags[t].parentNode.onmouseout=function(){
					this.getElementsByTagName("ul")[0].style.display="none"
				}
		    }
  		}
	}
}

if (window.addEventListener)
window.addEventListener("load", createcssmenu, false)
else if (window.attachEvent)
window.attachEvent("onload", createcssmenu)
/* End menu functions */

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("\\b"+searchClass+"\\b");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function checkform(form){
	var checkInputs = getElementsByClass("required");
	
	for(i=0;i < checkInputs.length; i++){
		inputName = checkInputs[i].name;
		inputType = checkInputs[i].type;
		if(inputType == 'text'){
			if(checkInputs[i].value == null || checkInputs[i].value == "") {
				checkInputs[i].focus();
				alert('You are missing some required information');
				return false;
			}
		} else if (inputType == 'select-one'){
			if(checkInputs[i].options[checkInputs[i].selectedIndex].value == null || 
				checkInputs[i].options[checkInputs[i].selectedIndex].value == "" || 
				checkInputs[i].options[checkInputs[i].selectedIndex].value == 0) {
				checkInputs[i].focus();
				alert('You are missing some required information');
				return false;
			}
		}
	}
	return true;
}

function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}catch (e){
		// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function trainerInfo(staffID, staffState){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	}
			
	var url="trainer90Days.php";
	url+="?staffID="+staffID;
	
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4){
			document.getElementById("trainer").innerHTML=xmlHttp.responseText;	
			top5NatInfo(staffState);
		}
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	document.getElementById('trainer').innerHTML='<img id="submitImage" name="submitImage" src="../images/ajaxLoader.gif" alt="Please Wait for AJAX Results">';
}

function top5NatInfo(staffState){
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	}
			
	var url="top5Nat90Days.php";
	
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4){
		
			document.getElementById("top5Nat").innerHTML=xmlHttp.responseText;
			top5StateInfo(staffState);
		}
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	document.getElementById('top5Nat').innerHTML='<img id="submitImage" name="submitImage" src="../images/ajaxLoader.gif" alt="Please Wait for AJAX Results">';
}

function top5StateInfo(staffState){
	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	}
			
	var url="top5State90Days.php";
	url+="?staffState="+staffState;
	
	xmlHttp.onreadystatechange=function(){
		if (xmlHttp.readyState==4){
		
			document.getElementById("top5State").innerHTML=xmlHttp.responseText;
		}
	};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	document.getElementById('top5State').innerHTML='<img id="submitImage" name="submitImage" src="../images/ajaxLoader.gif" alt="Please Wait for AJAX Results">';
}