function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
function showdiv(id) {
	//safe function to show an element with a specified id
	if (document.getElementById) {document.getElementById(id).style.display = 'block';}
	else {
		if (document.layers) {document.id.display = 'block';}
		else {
		if (document.all.id.style.display) {document.all.id.style.display = 'block';}
		else {return false;}
		}
	}
}
function addlistelem(node,desc)
{
	var li=document.createElement("li");
	li.appendChild(document.createTextNode(desc));
	node.appendChild(li);
}
function addemelem(node,desc)
{
	var li=document.createElement("em");
	li.appendChild(document.createTextNode(desc));
	node.appendChild(li);
}
function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	{num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));}
	return (((sign)?'':'-') + num + '.' + cents);
}
function insertAfter(newElem,targetElem)
{
	var parent=targetElem.parentNode;
	if (parent.lastChild==targetElem) {parent.appendChild(newElem);}
	else {parent.insertBefore(newElem,targetElem.nextSibling);}
}
function jumpMenu(targ,selObj)
{
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
}
function appOptLast(curId,ordId)
{
	var catId=document.getElementById(curId);
	var catOrd = document.getElementById(ordId);
	if (catId && catOrd)
	{
		var catCur=catId.childNodes;
		for (var i=0; i<catCur.length; i++)
		{
			if (catCur[i].selected==true) {insOpt(catOrd, catCur[i].text,catCur[i].value);}
		}
	}
}
function delOpt(curId)
{
	var catOrd=document.getElementById(curId);
	if (catOrd)
	{
		var catCh=catOrd.childNodes;
		var j=0;
		while (catCh[j])
		{
			if (catCh[j].selected==true) {catOrd.removeChild(catCh[j]);} else {j++;}
		}
	}
}
function insOpt(optId,optText,optVal)
{
	var elOptNew = document.createElement('option');
	elOptNew.text=optText;
	elOptNew.value=optVal;
	optId.appendChild(elOptNew);
}
function setAll(curId)
{
	var catCh=document.getElementById(curId).childNodes;
	for (var i=0; i<catCh.length; i++) {catCh[i].selected=true;}
}

function stopRKey(evt)
{
	var evt = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
function showGP (spr,shpr)
{
	var gp='n/a';
	var mucm='n/a';
	var muca='n/a';
	var mucl='n/a';
	if (document.getElementById('av_cp') && document.getElementById('l_cp') && document.getElementById('CP') && document.getElementById('vtval'))
	{
		var bprm=parseFloat(document.getElementById('CP').value);
		if (!bprm) {bprm=0;}
		var bpra=parseFloat(document.getElementById('av_cp').value);
		if (!bpra) {bpra=0;}
		var bprl=parseFloat(document.getElementById('l_cp').value);
		if (!bprl) {bprl=0;}
		var vat=document.getElementById('vtval').value;
		vat=vat.split('%')[0]/100;
		shpr=parseFloat(shpr);
		if (!shpr) {shpr=0;}
		spr=parseFloat(spr/(vat+1));
		if ((shpr+bprm)>0) {mucm=Math.round(1000*(spr-shpr-bprm)/(shpr+bprm))/10+'%';}
		if ((shpr+bpra)>0) {muca=Math.round(1000*(spr-shpr-bprm)/(shpr+bpra))/10+'%';}
		if ((shpr+bprl)>0) {mucl=Math.round(1000*(spr-shpr-bprm)/(shpr+bprl))/10+'%';}
		if (spr>0)
		{
			gp='Manual('+Math.round(spr-shpr-bprm)+'): '+Math.round(1000*(spr-shpr-bprm)/spr)/10+'%, Average('+Math.round(spr-shpr-bpra)+'): '+Math.round(1000*(spr-shpr-bpra)/spr)/10+'%, Last('+Math.round(spr-shpr-bprl)+'): '+Math.round(1000*(spr-shpr-bprl)/spr)/10+'%';
		}
		muc='Manual: '+mucm+', Average: '+muca+', Last: '+mucl;
		var gpt = document.createTextNode(gp);
		var muct = document.createTextNode(muc);
		if (document.getElementById('GRP'))
		{
			var grp=document.getElementById('GRP');
			if (grp.hasChildNodes())
			{
				grp.removeChild(grp.firstChild);
			}
			grp.appendChild(gpt);
		}
		if (document.getElementById('MUC'))
		{
			var mucd=document.getElementById('MUC');
			if (mucd.hasChildNodes())
			{
				mucd.removeChild(mucd.firstChild);
			}
			mucd.appendChild(muct);
		}
	}
}
function hsu_insTx(y,t,a)
{
	while (y.hasChildNodes()) {y.removeChild(y.lastChild);}
	if (t.split('~')[1])
	{
		var link = document.createElement('a');
		link.setAttribute('href', t.split('~')[1]);
		link.appendChild(document.createTextNode(t.split('~')[0]));
		y.appendChild(link);
	}
	else {y.appendChild(document.createTextNode(t.split('~')[0]));}
}
function hsdoSetElems (hsdoID)
{
	if (document.getElementById && document.getElementsByTagName)
	{
		var hsdoForm = document.getElementById(hsdoID);
		for (var i = 0; i < hsdoForm.length; i++)
		{
			hsdoFocus(hsdoForm[i].getElementsByTagName("input"));
			hsdoFocus(hsdoForm[i].getElementsByTagName("textarea"));
		}
	}
}
function hsdoFocus (hsdoElem)
{
	for (var i = 0; i < hsdoElem.length; i++)
	{
		if(hsdoElem[i].className.search(/^but/)<1)
		{
			hsdoElem[i].onfocus=function ()
			{
				this.select();
			}
			hsdoElem[i].onclick=function ()
			{
				this.select();
			}
			hsdoElem[i].onblur=function ()
			{
				this.selectionStart=this.selectionEnd;
			}
		}
	}
}
function hs_getElementsByClass(theClass, classType)
{
	var hs_allHTMLTags=document.getElementsByTagName((classType?classType:'*'));
	var hs_returnerArray = new Array();
	for (var i=0; i<hs_allHTMLTags.length; i++)
	{
		if (hs_allHTMLTags[i].className.search(theClass)>0)
		{
			hs_returnerArray.push(hs_allHTMLTags[i]);
		}
	}
	return hs_returnerArray;
}

