var detectMacXFF;
var userAgent = navigator.userAgent.toLowerCase();
var dontCloseAlert = false;
var fProgress = "off";
if (userAgent.indexOf('firefox')!=-1) {
   detectMacXFF =  true; 
} else {
	detectMacXFF = false;
}

// checks existence of ID in markup
function checkID(idName) {
	if (document.getElementById(idName)) {
		return true;
	} else {
		return false;
	}
}

// goes to a loc
function goHere(url) {
		window.location.href=url;
}

// focuses on element
function focusMe(idName) {
	if (checkID(idName)){
		document.getElementById(idName).focus();
	}
}

// submit an element
function submitMe(idName) {
	if (checkID(idName)) {
		document.getElementById(idName).submit();
	}
}

// submit an element
function resetMe(idName) {
	if (checkID(idName)) {
		document.getElementById(idName).reset();
	}
}

// sets the href of a value
function hrefMe(idName,h) {
	if (checkID(idName)) {
		document.getElementById(idName).href=h;
	}
}

// sets the href of a value
function srcMe(idName,s) {
	if (checkID(idName)) {
		document.getElementById(idName).src=s;
	}
}

// clears an element
function clearMe(t,val) {
	if (t.value==val) {
		t.value = '';
	}
}

// gives INNERHTML to an element
function visibleMe(idName) {
	if (checkID(idName)) {
		document.getElementById(idName).style.visibility = "visible";
	}
}


// gives INNERHTML to an element
function htmlMe(idName,h) {
	if (checkID(idName)) {
		document.getElementById(idName).innerHTML = h;
	}
}

//gets the value
function getValue(idName) {
 if (checkID(idName)) {
 		return document.getElementById(idName).value;
	}
}

// gives value to an ID
function valueMe(idName,val) {
	if (checkID(idName)){
		document.getElementById(idName).value=val;
	}
}

// gets the class
function getClassName(idName) {
 if (checkID(idName)) {
 		return document.getElementById(idName).className;
	}
}

// shows a html block
function showMe(idName) {
	if (checkID(idName)) {
		document.getElementById(idName).style.display="block";
	}
}

// shows a html block
function showMe2(idName) {
	if (checkID(idName)) {
		document.getElementById(idName).style.display="inline";
	}
}

// shows a html block
function showMe3(idName,displayWay) {
	if (checkID(idName)) {
		document.getElementById(idName).style.display=displayWay;
	}
}

function showTableRow(idName)
{
	if (detectMacXFF) {
		displayWay = "table-row";
	} else {
		displayWay = "block";
	}
	showMe3(idName,displayWay);
}

function showTableCell(idName)
{
	if (detectMacXFF) {
		displayWay = "table-cell";
	} else {
		displayWay = "block";
	}
	showMe3(idName,displayWay);
}

// hides a html block
function hideMe(idName) {
	if (checkID(idName)) {
		document.getElementById(idName).style.display="none";
	}
}

// changes a stylesheet class to a specified ID
function changeClass(idName,toClass) {
	if (checkID(idName)) {
		document.getElementById(idName).className=toClass;
	}
}

function showSub(hubName,navName) {
	changeClass("top"+navName,'on');
	changeClass("link"+navName,'on');
	showMe(hubName+"sub"+navName);
}

function hideSubs(hubName,navName) {
	changeClass("top"+navName,'');
	changeClass("link"+navName,'');
	for (n = 0; n < navArray.length; n++) {
		hideMe(hubName+"sub"+navArray[n]);
	}
}

function iFrameHeight(idName) {
	if(document.getElementById(idName)) {
		if (idName=="commentsFrame") {
			if (document.getElementById(idName).contentDocument) {
				h = document.getElementById(idName).contentDocument.getElementById("mac50template").offsetHeight+FFextraHeight;
			} else {
				h = document.frames(idName).document.getElementById("mac50template").scrollHeight;
			}
		} else {

			if (document.getElementById(idName).contentDocument) {
				h = document.getElementById(idName).contentDocument.body.offsetHeight+FFextraHeight;
			} else {
				h = document.frames(idName).document.body.scrollHeight;
			}
		}
		document.getElementById(idName).style.height = h;
	}
}

function tabNext(t,l,f) {
	if (t.value.length == l) {
		focusMe(f);
	}
}

function removeError(str) {
	var space;
	if (str.indexOf("error") >=0) { // keep only until space
		space = str.indexOf(" ");
		return str.substr(0,space);
	} else {
		return (str);
	}
}


function checkForm(arrayStr) {
	var splitStr = arrayStr.split("|");
	var count = 0;
	for (s = 0; s < splitStr.length; s++) {
		if (getValue(splitStr[s])=="") {
			count++;
			alert("Please fill in all required fields.");
			focusMe(splitStr[s]);
			changeClass(splitStr[s],getClassName(splitStr[s])+" error");
			break;
		} else {
			//alert();
			changeClass(splitStr[s],removeError(getClassName(splitStr[s])));
		}
	}
	if (count == 0) {
		submitMe('quoteForm');
	}
}


function Popup(myUrl,popType) {
	var winName='a';
	var d = new Date();
	var winTime = d.getUTCHours()+'_'+d.getUTCMinutes()+'_'+d.getUTCSeconds();

	switch (popType) {
		case 1:   // upload
			var winTop=100;
			var winLeft=100;
	  	pop = window.open(myUrl,winName,'width=450,height=220,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=yes,resizable=yes,location=no,menubar=no,directories=no,status=yes,copyhistory=no');
		break
		case 2:   // preview
			var winTop=100;
			var winLeft=100;
	  	pop = window.open(myUrl,winName,'width=709,height=493,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=yes,resizable=yes,location=no,menubar=no,directories=no,status=yes,copyhistory=no');
		break
		case 3:   // preview
			var winTop=100;
			var winLeft=100;
	  	pop = window.open(myUrl,winName,'width=600,height=500,top=' + winTop + ',left=' + winLeft + ',toolbar=no,scrollbars=yes,resizable=yes,location=no,menubar=no,directories=no,status=yes,copyhistory=no');
		break
	}

	pop.focus();

}


function getOffH(idName) {
	if (checkID(idName)) {
		return document.getElementById(idName).offsetHeight;
	} else {
		return 0;
	}
}

function getOffW(idName) {
	if (checkID(idName)) {
		return document.getElementById(idName).offsetWidth;
	} else {
		return 0;
	}
}

function setHeight(idName,h) {
	if (checkID(idName)) {
			document.getElementById(idName).style.height = (h)+"px";
	}
}		

function adjustHeight() {	
	var lHeight, cHeight, rHeight;
	lHeight = getOffH("leftnav");
	cHeight = getOffH("mainContent");
	rHeight = getOffH("rightArea");
	if ((rHeight > cHeight) && (rHeight > lHeight)) {
		setHeight("mainContent",rHeight);
		setHeight("leftNav",rHeight);
	} else if ((cHeight > lHeight) && (cHeight > rHeight)) {
		setHeight("rightContent",cHeight);
		setHeight("leftNav",cHeight-2);
	} else if ((lHeight > cHeight) && (lHeight > rHeight)) {
		setHeight("rightContent",lHeight);
		setHeight("mainContent",lHeight-2);
	}
}
