function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function popUpWin(url, w, h){
	width = w; height = h;

	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if(window.screen){
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;

		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
		str += ",location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no";
	}
	window.open(url, 'win1', str);
}

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 cookie
// value = value of the cookie
function setCookie(name, value, expires) {
	var curCookie = name + "=" + escape(value);
	//expires must be a date, i.e.:
	//var today = new Date();
	//var expires = new Date(today.getTime() + (560 * 864000000));
	if(expires){curCookie = curCookie + ";expires=" + expires.toGMTString();}
	else{curCookie = curCookie + ";expires=";}
	curCookie = curCookie + ";path=/";
	document.cookie = curCookie;
}

// 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.php?no_contract';}
	}
}

// name - name of the cookie
function deleteCookie(name) {
	if (getCookie(name)) {
		document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
} 
// 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.shtml?'+search+'">';
		}
	}
}

function setTxt(id, content){
	var tipobj=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	tipobj.innerHTML = content;
}
function setText(id, content){
	var tipobj=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	tipobj.innerHTML = content;
}

// |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 
// 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 where = new String(window.location);
	if(where.match(/\/vendors/)){
		pre = 'vendors_';
	}else if(where.match(/\/sales/)){
		pre = 'sales_';
	}else{pre = '';}

	var rNum = this.name;
	var rNum = rNum.slice(7, rNum.length); //extract number
	MM_swapImage('b'+rNum,'','/images/'+pre+'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 where = new String(window.location);
	if(where.match(/\/vendors/)){
		pre = 'vendors_';
	}else if(where.match(/\/sales/)){
		pre = 'sales_';
	}else{pre = '';}

	var rNum = this.name;
	var rNum = rNum.slice(7, rNum.length); //extract number
	MM_swapImage('b'+rNum,'','/images/'+pre+'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

/* var where = new String(window.location); */
/* if(where.match(/\/vendors/)){ */
/* 	createCenterMenu('submenu1', 1,  85); */
/* 	createCenterMenu('submenu2', 175, 85); */
/* 	createCenterMenu('submenu3', 349, 85); */
/* 	createCenterMenu('submenu4', 523, 85); */
/* }else{ */
	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-15, 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()',600);
}
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);

	//remove dollar sign/equivalent:
	num = num.replace(/\$/, '');
	num = num.replace(/%24/, '');
	//remove commas/equivalent::
	num = num.replace(/%2C/, '');
	num = num.replace(/,/, '');

	//capture the cents value, and format it:
	var cents = num.match(/\.\d+/);
	var cents = new String(cents);
	var cents = cents.replace(/\./, "");
	if(cents.length > 2){cents = cents.replace(/(\d\d)\d+/, "$1");}
	if((cents) && (cents.length < 2)){cents = cents+'0';}
	//remove cents:
	num = num.replace(/\.\d+/, '');

	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('');
	if((!cents)||(cents=="null")){cents = '00';}
	arr = '$'+arr+'.'+cents;
	//if the number is negative, return in parentheses:
	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, ' ');
			output = output.replace(/%2F/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 fieldType = eval('theForm.'+array[i]+'.type');
		var fieldID = array[i]+'ID';
		if((fieldType == "text") || (fieldType == "password")){
			var fieldVal = eval('theForm.'+array[i]+'.value');
			if(!fieldVal){
				hiLite(fieldID, '#f00')
				launch = "false";
			}else{hiLite(fieldID, '#000')}
		}else if(fieldType == "checkbox"){
			var fieldVal = eval('theForm.'+array[i]+'.checked');
			if(fieldVal == false){
				hiLite(fieldID, '#f00')
				launch = "false";
			}else{hiLite(fieldID, '#000')}
		}else if(fieldType == "select-one"){
			var fieldVal = eval('theForm.'+array[i]+'.options[theForm.'+array[i]+'.selectedIndex].value');
			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;
	}
}

function helpWin(topic) { //v2.0
	window.open('help_pop_up.php?topic='+topic,'help','height=300,width=400,scrollbars=yes,status=yes');
}

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 showCalendar(formName,fieldName, monthOnly) { //v2.0
	if(monthOnly == 'monthOnly'){monthOnly = 'true';}
	window.open('/calendar.php?formName='+formName+'&fieldName='+fieldName+'&first=true&monthOnly='+monthOnly, 'calendar', 'height=180,width=200,scrollbars=no,status=yes,resizable=no');
}



function taLimit(taObj) {
	if (taObj.value.length==2000) return false;
	return true;
}

function taCount(taObj,Cnt) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>2000) objVal=objVal.substring(0,2000);
	if (objCnt) objCnt.innerText=2000-objVal.length;
	return true;
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}



function noenter() {
	return !(window.event && window.event.keyCode == 13);
}

function ajaxFunction(script, target, vars){
	var xmlHttp;
	try{
		//Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}catch (e){
		//IE
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

	document.getElementById(target).innerHTML = 'Loading&nbsp;&hellip;';

	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState==4){
			document.getElementById(target).innerHTML = xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET", script+'?cache='+new Date().getSeconds()+'&'+vars, true);
	xmlHttp.send(null);
}
