function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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 MM_reloadPage(init) {  //Updated by PVII. Reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(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_swapImage() { //v3.0
	//define variables; variable passed by link are dumped into array called a:
	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 navRollOver(obj, state) {
	document.getElementById(obj).className = (state == 'on') ? 'nav-highlight' : 'nav';
}

function toggle(id){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	if(element.style.display == 'none'){
		element.style.display = '';
	} else {element.style.display = 'none';}
}

function appear(id){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	element.style.display = '';
}

function hide(id){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	element.style.display = 'none';
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {begin += 2;}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {end = dc.length;}
	return unescape(dc.substring(begin + prefix.length, end));
}

// checks to see if contract cookie exists; redirects page otherwise:
function cookieChecker() {
	var where = new String(window.location);
	var reg = /contract_listing/;
	if(!reg.test(where)) {
		var cookieCheck0 = getCookie('contract');
		if (!cookieCheck0) {window.location='contract_listing.asp?no_contract';}
	}
}

// get a variable and its value from a query string:
function proc(term){
	var where = new String(window.location);
	var a = where.split('?');
	var where = new String(a[1]);
	var b = where.split('&');
	for(i=0; i < b.length; i++){
		var search = new String(b[i]);
		if (search.indexOf(term) >= 0){
			return '<A HREF="pay_invoice.asp?'+search+'">';
		}
	}
}


// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 
// Coded by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
// If want to use this code, feel free to do so, but please leave this message intact.
// If you do remove this, I will hunt you down :)
//
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// --- Version Date 8-6-02 ---------------------------------------------------------------

var agent = navigator.userAgent.toLowerCase(); 
var mac = agent.indexOf('mac') != -1;
var w3c = document.getElementById ? true : false;
var iex = document.all ? true : false;
var ns4 = document.layers ? true : false;

function fixNetscape(){
	if(origWidth != window.innerWidth || origHeight != window.innerHeight){
		window.location.reload();
	}
}
if(ns4){
	origWidth = window.innerWidth;
	origHeight = window.innerHeight;
	window.onresize = fixNetscape;
}
function getStyle(name, nest){
	nest = nest ? 'document.'+nest+'.' : '';
	return w3c ? document.getElementById(name).style : iex ? document.all[name].style : ns4 ? eval(nest+'document.'+name) : false;
}

// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
// Menu Constructor

CenterMenu = function(name,left,top){
	this.name = name;
	this.left = left;
	this.top = top;
	this.timer = null;
	this.obj = name+'Object';
	eval(this.obj+'=this');
}
CenterMenu.prototype.show = function(){
	clearTimeout(this.timer);
	var windowWidth = iex ? document.body.clientWidth : window.innerWidth;
	var offset = Math.floor((windowWidth-pageWidth)/2);
	if(offset < 0){
		offset = 0;
	}
	if(ns4 && offset > 0){ // Ugly NS4 Bug Fix
		if(mac){
			if(document.height < window.innerHeight){
				offset -= 8;
			}
		}else{
			offset -= 8;
		}
	}
	getStyle(this.name).left = offset+this.left;
	getStyle(this.name).visibility = 'visible';
	curMenu = this.name;

	var rNum = this.name;
	var rNum = rNum.slice(7, rNum.length); //extract number
	MM_swapImage('b'+rNum,'','images/button'+rNum+'a.gif',1);
}
CenterMenu.prototype.hide = function(){
	this.timer = setTimeout(this.obj+'.hideIt()',500);
}
CenterMenu.prototype.hideIt = function(){
	getStyle(this.name).visibility = 'hidden';

	var rNum = this.name;
	var rNum = rNum.slice(7, rNum.length); //extract number
	MM_swapImage('b'+rNum,'','images/button'+rNum+'.gif',1);
}
CenterMenu.prototype.startMenu = function(){
	var html;
	if(ns4){
		html = '<layer name="'+this.name+'" left="'+this.left+'" top="'+this.top+'" z-index="1000" visibility="hidden" ';
	}else{
		html = '<div id="'+this.name+'" style="position:absolute; left:'+this.left+'px; top:'+this.top+'px; z-index:1000; visibility:hidden" ';
	}
	html += 'onMouseOver="Menus.'+this.name+'.show()" onMouseOut="Menus.'+this.name+'.hide()">';
	return html;
}

// Global Menu Functions
hideCur = function(){
	if(curMenu != null){
		Menus[curMenu].hideIt();
		curMenu = null;
	}
}
endMenu = function(){
	 return ns4 ? '<\/layer>' : '<\/div>';
}
createCenterMenu = function(name,left,top){
	Menus[name] = new CenterMenu(name,left,top);
}

Menus = new Object();
var curMenu = null;
var pageWidth = 700;

// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
// Build Menu Structure

createCenterMenu('submenu1', 1,  85);
createCenterMenu('submenu2', 117, 85);
createCenterMenu('submenu3', 233, 85);
createCenterMenu('submenu4', 349, 85);
createCenterMenu('submenu5', 465, 85);
createCenterMenu('submenu6', 581, 85);

// ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 
// Coded by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
// If want to use this code, feel free to do so, but please leave this message intact.
// If you do remove this, I will hunt you down :)
//
// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

var w3c = (document.getElementById) ?true:false;
var iex = (document.all)            ?true:false;
var ns4 = (document.layers)         ?true:false;
var supported = (w3c || iex || ns4) ?true:false;

var active = false;
var curObj,curNest;

var userHide = false;

function mousemoved (evt){
	if(iex){
		mousex = window.event.clientX+document.body.scrollLeft;
		mousey = window.event.clientY+document.body.scrollTop;
	}
	else if(ns4){
		mousex = evt.pageX+window.pageXOffset;
		mousey = evt.pageY+window.pageYOffset;
	}
	else{
		mousex = evt.pageX;
		mousey = evt.pageY;
	}
	if(active){
		shiftTo(curObj, mousex-50, mousey-25, curNest);
	}
	return true;
}

// =-=-=-=-=-=-=

function getStyle (objstr, nest){
	nest = (nest) ? "document."+nest+"." : "";
	return (w3c) ? document.getElementById(objstr).style : (iex) ? document.all[objstr].style : (ns4) ? eval(nest+"document."+objstr) : false;
}
function shiftTo (objstr, x, y, nest){
	var obj = getStyle(objstr,nest);
	if(iex){
		obj.pixelLeft = x;
		obj.pixelTop = y;
	}
	else if(ns4){
		obj.moveTo(x,y);
	}
	else if(w3c){
		obj.left = x;
		obj.top = y;
	}
}
function showtips (objstr,nest){
	if(userHide == true){return false;}
	curObj = objstr;
	curNest = (nest) ? nest : null;
	getStyle(objstr,nest).visibility = "visible";
	active = true;
	//hides the tool tip after set amount of time:
	tiptimer = setTimeout('hidetips()',1200);
}
function hidetips (){
	getStyle(curObj,curNest).visibility = "hidden";
	active = false;
	clearTimeout(tiptimer);
}

// =-=-=-=-=-=-=

if(supported){
	if(ns4){
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = mousemoved;
}

function toggleToolTips(id){
	var tipobj=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	if(userHide == false){
		tipobj.innerHTML='<A HREF="javascript:toggleToolTips(\'tipToggle\')">turn tool tips on</A>';
		userHide = true;
	} else {
		tipobj.innerHTML='<A HREF="javascript:toggleToolTips(\'tipToggle\')">turn tool tips off</A>';
		userHide = false;
	}
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

//format number into dollars and cents:
function FormatClean(num){
	var x = 0;
	if(num < 0){
		num = num * -1;
		x = 1;
	}
	//convert numbers to strings:
	var num = new String(num);
	var arr = num.split('');
	arr = arr.reverse();
	if(arr.length > 3){arr[3] = arr[3]+',';}
	if(arr.length > 6){arr[6] = arr[6]+',';}
	if(arr.length > 9){arr[9] = arr[9]+',';}
	arr = arr.reverse();
	arr = arr.join('');
	arr = '$'+arr+'.00';
	if(x > 0){arr = '('+arr+')';}
	return arr;
}

// get a variable and its value from a query string:
function query(param){
	//split the URL to get the query string:
	var where = new String(window.location);
	var a = where.split('?');
	var where = new String(a[1]);
	//split the query string into name/value pairs:
	var b = where.split('&');
	//go through each name/value pair; split and look for a match with param:
	for(i=0; i < b.length; i++){
		var search = new String(b[i]);
		var output = search.split('=');
		var name = new String(output[0]);
		if (name == param){
			//replace gibberish with @:
			output = output[1].replace(/%40/, '@');
			output = output.replace(/\+/g, ' ');
			return output;
		}
	}
}

function hiLite(id, color){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	element.style.color = color;
}

function sendIt(formName, formAction){
	var launch = "true";
	var theForm = eval('document.'+formName);
	/* get values from the form "req_list"; YOU NEED THIS! */
	var array = document.req_list.required.value.split("::");
	for(i=0; i<array.length; i++){
		var fieldVal = eval('theForm.'+array[i]+'.value');
		var fieldID = array[i]+'ID';
		if(!fieldVal){
			hiLite(fieldID, '#f00')
			launch = "false";
		}else{hiLite(fieldID, '#000')}
	}
	if(launch == "true"){
		theForm.action = formAction; theForm.submit();
	}else{
		alert('Please provide all the required information.');
		return false;
	}
}
