//Begin Global Functions
var browser, sampTop1, sampTop2;

var pageURL = window.location.href;
if(window.location.protocol == "http:" && window.location.href.indexOf(".com/cart") > 0) {
	pageURL = pageURL.substring(4);
	pageURL = "https" + pageURL;
	window.location.href = pageURL;
}

function getElement(psID) {
	if (document.all) {
		return document.all[psID];
	} else if (document.getElementById) {
		return document.getElementById(psID);
	} else {
		for (iLayer = 1; iLayer < document.layers.length; iLayer++) {
			if (document.layers[iLayer].id == psID)
			return document.layers[iLayer];
		}
	}
	return null;
}

function toggleDisplay(whichLayer) {
	if (getElement(whichLayer).style.display == "" || getElement(whichLayer).style.display == "block") {
		getElement(whichLayer).style.display = "none";
	} else {
		getElement(whichLayer).style.display = "";
	}
}
function toggleClass(whichLayer) {
	if (getElement(whichLayer).className == "csubHdr divlink") {
		getElement(whichLayer).className = "csubHdrOn divlink";
	} else {
		getElement(whichLayer).className = "csubHdr divlink";
	}
}

function urlParams(name) {
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if ( results == null ) { return ""; }
	else { return results[1]; }
}

function setCookie(name,value,expY,expM,expD,path,domain) {
	var cookie_string = name + "=" + escape(value);
	if(expY) {
		var expires = new Date(expY,expM,expD);
		cookie_string += ";expires=" + expires.toGMTString();
	}
	if(path) {
		cookie_string += ";path=" + escape(path);
	}
	if(domain) {
		cookie_string += ";domain=" + escape(domain);
	}
	document.cookie = cookie_string;
}
function getCookie(name) {
	if (document.cookie.length>0) {
		cStart=document.cookie.indexOf(name + "=");
		if (cStart!=-1) {
			cStart=cStart + name.length+1;
			cEnd=document.cookie.indexOf(";",cStart);
			if(cEnd==-1) { cEnd=document.cookie.length; }
			return unescape(document.cookie.substring(cStart,cEnd));
		}
	}
	return "";
}
function delCookie(name,value) {
	var cookieDate = new Date("2008","01","01");
	document.cookie = name + "=" + value + "; expires=" + cookieDate.toGMTString() + "; path=" + escape ("/") + "; domain=" + escape ("arccorp.com");
}

function getScroll() {
	if (navigator.appName.indexOf('Microsoft') != -1) {
		browser = 'IE'
		//alert("IE");
	} else if (navigator.appName.indexOf('Netscape') != -1) {
		browser = 'Netscape'
		//alert("Netscape");
	} else {
		browser = 'IE';
		//alert("other therefore IE");
	}

	if(browser == 'IE') {
		sampTop1 = document.documentElement.clientWidth - 920;
		sampTop2 = sampTop1 / 2;
	} else {
		if(window.innerHeight <= document.height) {
		//if(window.scrollbars.visible) {
			sampTop1 = window.innerWidth - 938;
			sampTop2 = sampTop1 / 2;
			//alert("scrollbars visible");
		} else {
			sampTop1 = window.innerWidth - 920;
			sampTop2 = sampTop1 / 2;
			//alert("scrollbars not visible");
		}
	}
}

function calcPopPosition(whichDiv) {
	var browser, popTop1, popTop2, popLef1, popLef2;
	if (navigator.appName.indexOf('Microsoft') != -1) {
		browser = 'IE';
	} else if (navigator.appName.indexOf('Netscape') != -1) {
		browser = 'Netscape'
	} else { browser = 'IE'; }
	if(browser == 'IE') {
		popTop1 = document.documentElement.clientHeight - getElement(whichDiv).clientHeight;
		popTop2 = popTop1 / 2;
		popLef1 = document.documentElement.clientWidth - getElement(whichDiv).clientWidth;
		popLef2 = popLef1 / 2;
	} else {
		popTop1 = window.innerHeight - getElement(whichDiv).clientHeight;
		popTop2 = popTop1 / 2;
		popLef1 = window.innerWidth - getElement(whichDiv).clientWidth;
		popLef2 = popLef1 / 2;
	}
	if(popTop2 < 100) {
		getElement(whichDiv).style.top = "100px";
	} else {
		getElement(whichDiv).style.top = popTop2 + "px";
	}
	getElement(whichDiv).style.left = popLef2 + "px";
	//alert("width is " + getElement(whichDiv).clientWidth + "\n" + "height is " + getElement(whichDiv).clientHeight);
}

var popUpsBlocked;
var popupURL;
function popCheck(whichURL) {
	var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
	if(mine) {
		popUpsBlocked = false;
		mine.close()
	} else {
		popUpsBlocked = true;
	}

	popupURL = whichURL;
	if(popUpsBlocked) {
		getElement("altBox").style.display = "";
		getElement("popDiv").style.display = "";
		calcPopPosition("altBox");
		//getElement("popLnk1").innerHTML = whichURL;
	} else {
		window.open(popupURL,'popupWindow');
	}
	return false;
}
//End Global Functions

function toggleLayer(whichLayer) {
	if(whichLayer == "prdSelDiv") {
		var optArray = ["agtChc","carTck","datExp","docRet","intRep","memMan","my_Arc","tckRes","trvOff"];
		for(var counter = 0; counter < optArray.length; counter++) {
			if(getElement("prdSel").value == optArray[counter]) {
				getElement(optArray[counter]).style.display = "";
			} else {
				getElement(optArray[counter]).style.display = "none";
			}
		}
	}
}

function fix(tab) {
	getElement("tabLine").style.display = "";
	switch (tab) {
	case 1:
		getElement("tabLine").style.width = "87px";
		getElement("tabLine").style.left = "1px";
		break;
	case 2:
		getElement("tabLine").style.width = "168px";
		getElement("tabLine").style.left = "97px";
		break;
	case 3:
		getElement("tabLine").style.width = "98px";
		getElement("tabLine").style.left = "274px";
		break;
	case 4:
		getElement("tabLine").style.width = "118px";
		getElement("tabLine").style.left = "381px";
		break;
	case 5:
		getElement("tabLine").style.width = "128px";
		getElement("tabLine").style.left = "508px";
		break;
	}
}

function clearFix() {
	getElement("tabLine").style.display = "none";
}

function getParams() {
	var urlquery = "";
	var urlterms = "";
	var urlitems = "";
	var urlstrip = "";
	urlquery = location.href.split("?");
	if(urlquery[1] !== null && urlquery[1] !== undefined && urlquery[1] !== "") {
		urlterms = urlquery[1].split("&");
		for(i=0; i < urlterms.length; i++) {
			urlitems += urlterms[i] + "\n";
			urlstrip = urlterms[i];
			if(!/^[a-zA-Z0-9\-\,\.\=\@]*$/.test(urlstrip)) {
				window.location.href = "index.jsp";
			}
		}
		//alert(urlitems);
	}
}
function clnParams() {
	for(i=0; i < document.authEdit.elements.length; i++) {
		var paramStr = document.authEdit.elements[i].value;
		paramStr = paramStr.replace(/\</g,"");
		paramStr = paramStr.replace(/\>/g,"");
		paramStr = paramStr.replace(/\'/g,"");
		paramStr = paramStr.replace(/\%/g,"");
		paramStr = paramStr.replace(/\;/g,"");
		paramStr = paramStr.replace(/\"/g,"");
		paramStr = paramStr.replace(/\(/g,"");
		paramStr = paramStr.replace(/\)/g,"");
		paramStr = paramStr.replace(/\+/g,"");
		document.authEdit.elements[i].value = paramStr;
	}
}
