
/* 
function openFPWindow(URL,name,attrib) {
// example of the openFPWindow Function below:
// <a href="javascript:openFPWindow('URL here','title of window here','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=590,height=420')">
	popupWin = window.open(URL,name,attrib);
	popupWin.focus();
}
*/


function doSwap(location, image) {
        document[location].src=image;
}

function doubleSwap(location1, image1, location2, image2) {
        doSwap(location1, image1);
        doSwap(location2, image2);
}

function go(url, fromframe, dowhat) {
	if (fromframe == "frame") {
		if (dowhat == "focus") {
			if (opener.closed != true) {
				opener.location = url;
				opener.focus();
			}
			else {
				window.open(url, "mainwindow",  "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=470");
				window.mainwindow.focus();
			}
		}
		else if (dowhat == "close") {
			if (opener.closed != true) {
				opener.top.location = url;
				window.close();
			}
			else {
				window.open(url, "mainwindow", "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=470");
				window.mainwindow.focus();
				window.close();
			}
		}
		else if (dowhat == "top") {
			top.document.location = url;
		}
	}
	else {
		document.location = url;
	}
}

function checkSelected(fromframe, dowhat) {
	// alert("checkSelected() function is running")
	var length, i, j, blnChecked, strWPIDs, strURL;
	var arrWPID = new Array();
	blnChecked=false;
	length = document.forms.results.wpid.length;
	j=0;
	// alert(document.forms.results.wpid.checked)
	for (i=0;i<length;i++) {
		if ((document.forms.results.wpid[i].checked) || (document.forms.results.wpid.checked)) {
			blnChecked = true;
			currValue = document.forms.results.wpid[i].value;
			if(currValue.indexOf(',') != -1){
				stopped    = false;
				startPoint = 0;
				endPoint   = 0;
				currWpid   = "";
				while(stopped == false){
					endPoint = currValue.indexOf(',', startPoint);
					if(endPoint == -1){
						endPoint = currValue.length;
						stopped    = true;
					}
					currWpid    = currValue.substring(startPoint, endPoint);
					arrWPID[j]=currWpid;
					j++;
					startPoint = currValue.indexOf(',', startPoint)+1;
				}
			}
			else{
				arrWPID[j]=document.forms.results.wpid[i].value;
				j++;
			}
		}
	}
	// following statement to test single result
	if (document.forms.results.wpid.checked) {
		// alert(parent.frames.body.document.forms.results.wpid.checked)
		blnChecked = true;
		// alert(blnChecked)
		arrWPID[j]=document.forms.results.wpid.value;
	}
	if (blnChecked) {
		var length = arrWPID.length;
		// capture initial part of the string
		strWPIDs = "?wpid1=" + arrWPID[0]
		var p = 2;
		for (i=1;i<length;i++) {
			strWPIDs = strWPIDs + "&wpid" + p + "=" + arrWPID[i];
			p++;
		}
		// strWPIDs = arrWPID.join(",");
		strUrl = "/asp/mip.asp"+strWPIDs;
		// alert(strUrl);
		go(strUrl, fromframe, dowhat);
		// strUrl is the URL to the mip.asp page | fromframe is if it's from a frame value should be "frame" | dowhat is either "close" or "focus"
	} 
	else {
		alert("Please select a product before continuing.");
		// return false;
	}
}

function getvar(arg) {
	// alert(location.search)
	if (location.search.indexOf(arg) != -1) {
		var x = location.search.indexOf(arg);
		var y = location.search.indexOf("&", x);
		if (y == -1) {
			y = location.search.length;
		}
		var stringVariables = location.search.substring(x,y);
		var x = (stringVariables.indexOf("=") + 1);
		var y = stringVariables.length;
		var stringVariables = stringVariables.substring(x,y);
		// alert(stringVariables)
	}
	else {
		var stringVariables = "";
	}
	stringVariables = unescape(stringVariables);
	return stringVariables;
}

/*
function GetCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
*/
// used by navigation/topnav.html Author Andrew Southwick
function getStringVar(StringValue, arg) {
	// alert(location.search)
	if (StringValue.indexOf(arg) != -1) {
		var x = StringValue.indexOf(arg);
		var y = StringValue.indexOf("&", x);
		if (y == -1) {
			y = StringValue.length;
		}
		var stringVariables = StringValue.substring(x,y);
		var x = (stringVariables.indexOf("=") + 1);
		var y = stringVariables.length;
		var stringVariables = stringVariables.substring(x,y);
		// alert(stringVariables)
		stringVariables = unescape(stringVariables);
	}
	else {
		var stringVariables = "";
	}
	return stringVariables;
}



/********************** Begin Cookie Functions ***************************************/

function getCookie(name) {
	// alert(document.cookie)
  	var arg = name + "=";
  	var alen = arg.length;
  	var clen = document.cookie.length;
  	var i = 0;
  	while (i < clen) {
    	var j = i + alen;
    	if (document.cookie.substring(i, j) == arg) {
			return getCookieVal (j);
		} 
		i = document.cookie.indexOf(" ", i) + 1;
    	if (i == 0) {
			break;
		}
  	}
  	// 0 is returned if cookie is not found.
 	 return 0;
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
  	if (endstr == -1) {
    	endstr = document.cookie.length;
	}
	// alert("return code from getCookieVal" + unescape(document.cookie.substring(offset, endstr)));
  	return unescape(document.cookie.substring(offset, endstr));
}

// Author Andrew Southwick
function getCookieVar(strCookieName, arg) {
	// alert(location.search)
	var cookievalue = getCookie(strCookieName);
	// alert("cookieString = " + cookieString)
	if (cookievalue == 0) {
		cookieString = "";
	}
	else {
		cookieString = cookievalue;
	}
	if (cookieString.indexOf(arg) != -1) {
		var x = cookieString.indexOf(arg);
		var y = cookieString.indexOf("&", x);
		if (y == -1) {
			y = cookieString.length;
		}
		var stringVariables = cookieString.substring(x,y);
		var x = (stringVariables.indexOf("=") + 1);
		var y = stringVariables.length;
		var stringVariables = stringVariables.substring(x,y);
		// alert(stringVariables)
		stringVariables = unescape(stringVariables);
	}
	else {
		var stringVariables = "";
	}
	return stringVariables;
}

function cookie_object(strCookieName, strCookieValue, strCookieDate, strCookiePath, strCookieDomain, IsCookieSecure) {
	this.strCookieName = strCookieName;
	this.strCookieValue = strCookieValue;
	this.strCookieDate = strCookieDate;
	this.strCookiePath = strCookiePath;
	this.strCookieDomain = strCookieDomain;
	this.IsCookieSecure = IsCookieSecure;
}

function setCookieVar(strCookieName,strCookieVariable,strCookieVariableValue,intCookieExpiration) {
	// alert(location.search)
	/*
	alert("strCookieName = " + strCookieName + 
	"\rstrCookieVariable = " + strCookieVariable + 
	"\rstrCookieVariableValue = " + strCookieVariableValue +
	"\rintCookieExpiration = " + intCookieExpiration);
	*/
	// initialize variables.
	var IsEndOfString = false;
	var IsPersistCookie = false;
	var IsSessionCookie = false;
	var arrCookieStringPart = new Array();
	arrCookieStringPart[0] = "";
	arrCookieStringPart[1] = "";
	strCookieVariableValue = escape(strCookieVariableValue);
	
	// Insert Persist Values here.
	// Determine the expiration date
	if (intCookieExpiration != null) {
		// Custom expiration date passed to the function
		var datExpiresDate = intCookieExpiration;
	}
	else {
		// Determine next five year date based on today's date.
		var datNextFiveYearDate = new Date();
		var datExpiresDate = new Date();
		datNextFiveYearDate.setFullYear(datNextFiveYearDate.getFullYear() + 5);
		var datExpiresDate = datNextFiveYearDate;
	}
	
	//BEGIN COOKIE DOMAIN VERIFICATION FOR AKAMAI CHANGE
	var cookieDomain
	var currentHost = window.location.host.toLowerCase(); 
	
	if (currentHost == "www.amerisafeindustries.com") {
		cookieDomain = "www.gap.com"
	}
else if (currentHost == "secure.ak-gapstagevip02.gid.gapinc.com") {
	cookieDomain = "ak-gapstagevip02.gid.gapinc.com";
}
else { cookieDomain = null }
	//END DOMAIN VERIFICATION
	
	var objPersistCookie = new cookie_object(null,null,datExpiresDate,"/",cookieDomain,false)
	
	// Insert Session values here.
	var objSessionCookie = new cookie_object(null,null,null,"/",cookieDomain,false)
	var strObjCookie = ""	
		
	// determine if this is a session cookie or persist cookie.
	if (strCookieName.indexOf("persist") != -1) {
		IsPersistCookie = true;
		strObjCookie = "objPersistCookie";
	}
	else if (strCookieName.indexOf("session") != -1) {
		IsSessionCookie = true;
		strObjCookie = "objSessionCookie";
	}
	else {
		// default to session based cookie values.
		IsSessionCookie = true;
		strObjCookie = "objSessionCookie";	
	}
	
	/* 
	Program Flow
	1) determine if cookie already exists.
	2) if cookie exists then append the cookie with new variable.
	3) if cookie does not exist then create cookie with variable.
	*/
	
	strCookieValue = getCookie(strCookieName);
	
	// alert("strCookieValue initial value = " + strCookieValue);		
	
	if (strCookieValue == 0) {
		// cookie currently does not exist.
		// create cookie with new value.
		// 1) create strCookieValue variable.
		
		strCookieValue = strCookieVariable + "=" + strCookieVariableValue;
		
		// alert("strCookieValue = " + strCookieValue);
		// alert(strObjCookie + ".strCookiePath test = " + (eval((strObjCookie) + ".strCookiePath")));
		setCookie(strCookieName,strCookieValue,(eval((strObjCookie) + ".strCookieDate")),(eval((strObjCookie) + ".strCookiePath")),(eval((strObjCookie) + ".strCookieDomain")),(eval((strObjCookie) + ".IsCookieSecure")));
	}
	else {
		// cookie already exists so append or update the variable value pair for the cookie.
		// check to see if the variable already exists
		// alert("cookie already exists so append or update the variable value pair for the cookie.")
		if (strCookieValue.indexOf(strCookieVariable) != -1) {
			// variable was found so update the current value.
			// alert("variable was found so update the current value.")
			var x = strCookieValue.indexOf(strCookieVariable);
			var y = strCookieValue.indexOf("&", x);
			if (y == -1) {
				y = strCookieValue.length;
				IsEndOfString = true;
			}
			else {
				// create second part of the arrCookieStringPart array (the end of the cookie).
				arrCookieStringPart[1] = strCookieValue.substring(y,strCookieValue.length);
			}
			
			// create first part of cookieString
			arrCookieStringPart[0] = strCookieValue.substring(0,x);
			
			// create substring of variable and current value
			var strCurrentVariableValuePair = strCookieValue.substring(x,y);
				
			// create substring of variable value only		
			var x = (strCurrentVariableValuePair.indexOf("=") + 1);
			var y = strCurrentVariableValuePair.length;
			var strCurrentVariableValue = strCurrentVariableValuePair.substring(x,y);
			
			// re-assemble cookie with updated value.
			strCompleteCookieValue = arrCookieStringPart[0] + strCookieVariable + "=" + strCookieVariableValue + arrCookieStringPart[1];
			
			// reset strCookieValue to new value.
			strCookieValue = strCompleteCookieValue;
			// alert("strCompleteCookieValue = " + strCompleteCookieValue + "\rstrCookieValue = " + strCookieValue)
			
			// strCompleteCookieValue = unescape(strCompleteCookieValue)
			// alert(strObjCookie + ".strCookiePath test = " + (eval((strObjCookie) + ".strCookiePath")));
			setCookie(strCookieName,strCookieValue,(eval((strObjCookie) + ".strCookieDate")),(eval((strObjCookie) + ".strCookiePath")),(eval((strObjCookie) + ".strCookieDomain")),(eval((strObjCookie) + ".IsCookieSecure")));
			
		}
		else {
			// variable was not found so add the name value pair to the value string.
			// alert("variable was not found so add the name value pair to the value string.")
			if (strCookieValue.indexOf("=") != -1) {
				// cookie has a name value pair so append new variable.
				strCookieValue = strCookieValue + "&" + strCookieVariable + "=" + strCookieVariableValue;
			}
			else {
				// cookie does not have name value pair so simply create strCookieValue based variable and value pair.
				strCookieValue = strCookieVariable + "=" + strCookieVariableValue;
			}
			
			// alert("strCookieValue = " + strCookieValue);
			// alert(strObjCookie + ".strCookiePath test = " + (eval((strObjCookie) + ".strCookiePath")));
			setCookie(strCookieName,strCookieValue,(eval((strObjCookie) + ".strCookieDate")),(eval((strObjCookie) + ".strCookiePath")),(eval((strObjCookie) + ".strCookieDomain")),(eval((strObjCookie) + ".IsCookieSecure")));
		}	
	}
	return true;
}

function setCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

/*
setCookieVar("test_session", "variable_test", "variable_test_value")
strVariableTestValue = getCookieVar("test_session","variable_test")
document.write(strVariableTestValue)
*/

// alert(cookiesigValueTest)
// document.write("cookiesigValueTest = " + cookiesigValueTest)

/********************** End Cookie Functions ***************************************/



function reloadpage() {
	// alert(navigator.appName)
	if (navigator.appName.indexOf("Netscape") != -1) {
		// alert(navigator.appVersion)
		if (navigator.appVersion.indexOf("4.0") == -1) {
			// alert("reloadpage function is running")
			document.location.reload();
		}
	}
}

var strquote = '"';


/*----auto select functions --autoPopulate(),selector(), and autoSelectHotLink()--*/

function autoPopulate(){	
		for(i=0; i<=autoSelectText.length-1; ++i){
			document.autoSelectForm.autoSelectBox.options[i] = new Option();
		}
		for(i=0; i<=autoSelectText.length-1; ++i){	
			document.autoSelectForm.autoSelectBox.options[i].text = autoSelectText[i];
			document.autoSelectForm.autoSelectBox.options[i].value = autoSelectValue[i];
		}
}

function selector(){
document.autoSelectForm.autoSelectBox.options[0].selected = true;
}

function autoSelectHotLink(fromframe, dowhat){
	x=document.autoSelectForm.autoSelectBox.selectedIndex;
	y=document.autoSelectForm.autoSelectBox.options[x].value;
	go(y, fromframe, dowhat);
}

hideIndicator = "no";
function loadFunction(num, loadStatus){
	if(loadStatus == "isOnLoad"){
		if(hideIndicator == "yes"){
		hide();
		}
	}
	if(loadStatus == "notOnLoad"){
		for(i=0; i<=wdid.length; ++i){
			if(num == wdid[i]){
				currfilename = wdidFileName[i];
				hideIndicator = "yes";
			}
		}
	}
}
/*--------------------------------------------------------------------------*/
platform = 0;
browser = 0;
browserVersion = 0;
ie4 = "no";
function browse(){
	plat = navigator.platform;
	str_name = navigator.appName;
	str_version = navigator.appVersion;
	
	if(str_name == "Netscape"){
		browser = 1;
		if(str_version.indexOf("MSIE") == -1){
			str_version = str_version.substring(0, str_version.indexOf("("));
			if(str_version.charAt(0) == "4"){
				browserVersion = "4x";
			}
			else{
				browserVersion = "6x";
			}
		}
	}
	if(str_name == "Microsoft Internet Explorer") {
		if (navigator.appVersion.indexOf("MSIE 4") == -1) {
			browser = 2;
		}
		else {
			browser = 2;
			ie4 = "yes";
		}
	}
	if(plat=="Win32"){
		platform = 3;
	}
	else{
		platform = 4;
	}	
}

broadcastX = 1;
broadcastY = 1;

function getXYCoords(img){
	browse();
	if (browser == 1){
		broadcastX = document[img].x;
		broadcastY = document[img].y;
	}
	if (document.all) {
		var x = 0;
		var y = 0;
		imgs = img;
		obj = document[imgs];
		while (obj.offsetParent != null) {
			x += obj.offsetLeft;
			y += obj.offsetTop;
			obj = obj.offsetParent;
		}
		x += obj.offsetLeft;
		y += obj.offsetLeft;
		broadcastX = x;
		broadcastY = y;
		
	}
}

function DisplayPrice(sPrice, normal_color, sale_color, isInLayer, layerName) {
	// alert("DisplayPrice function running")
	var nPos = sPrice.indexOf(':');
	if (nPos > 0) {
		var sRegularPrice = new String(sPrice.substring(0,nPos));
		var nLen = sPrice.length;
		var sSalePrice = new String(sPrice.substring(nPos+1,nLen));
		if(isInLayer == true && browser == 1){
			document[layerName].document.write("<strike><span class="+normal_color+">" + sRegularPrice + "</span></strike>" 
				+ "<span class="+sale_color+"> now " 
					+ sSalePrice + "</span>");
		}
		else{
			document.write("<strike><span class="+normal_color+">" + sRegularPrice + "</span></strike>" 
				+ "<span class="+sale_color+"> now " 
					+ sSalePrice + "</span>");
		}
	}
	else {
		if(isInLayer == true && browser == 1){
			document[layerName].document.write("<span class='"+normal_color+"'>" + sPrice + "</span>");
		}
		else{
			document.write("<span class='"+normal_color+"'>" + sPrice + "</span>");
		}
	} 
}

/* DisplayPrice("<onol otype=custom oname=stynbr=102119002>") */
//swaps css classes
function swapTextDecoration(strIdName, nameOfClass){
		document.getElementById(strIdName).className = nameOfClass;
}