                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
var popupWin;

// 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')">
function openFPWindow(URL,name,attrib) {
  if (popupWin) {
	if (!popupWin.closed) {
		popupWin.close();
	}
   }
	popupWin = window.open(URL,name,attrib);
	popupWin.focus();
}

function doSwap(location, image) {
        document[location].src=image;
}

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 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 doubleSwap(location1, image1, location2, image2) {
        doSwap(location1, image1)
        doSwap(location2, image2)
}

/*--------------------------------------------------------------------------*/
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;}	
}

/********************** 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));
}

// used by navigation/topnav.html 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;
	}
	// alert("datExpiresDate = " + datExpiresDate)
	var objPersistCookie = new cookie_object(null,null,datExpiresDate,"/",null,false)
	
	// Insert Session values here.
	var objSessionCookie = new cookie_object(null,null,null,"/",null,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" : "");
}

if (getvar("cg") == "luxe") {
	setCookieVar("ClientSidePersonpersist", "cg_luxe", "1");
	if (getvar("cgv_luxe_g") == "m") {
		setCookieVar("ClientSidePersonpersist", "cgv_luxe_gender", "m");
	}
}

/********************** End Cookie Functions ***************************************/



/********************************************************************************/

var cookieValue = new String("")
var cookieValue = new String(getCookie('ClientSide'))

// determine user's first name and authenticated status.
// create string 
var cookieValueFirstName = new String("")
var cookieValueIsCSR = new String("")

if (cookieValue != 0) {
	var cookieValueFirstName = new String(getCookieVar('ClientSide','FirstName'))
	var cookieValueIsCSR = new String(getCookieVar('ClientSide','IsCSR'))
	var cookieValueIsCSR = cookieValueIsCSR.toLowerCase()
	// alert("cookieValueIsCSR = " + cookieValueIsCSR)
	if (cookieValueFirstName.indexOf("+") != -1) {
		cookieValueFirstNameArray = cookieValueFirstName.split("+")
		cookieValueFirstName = cookieValueFirstNameArray.join(" ")
		// alert(cookieValueFirstName)
	}
	var cookieValueIsAuthenticated = new String("")
	var cookieValueIsAuthenticated = new String(getCookieVar(cookieValue,'IsAuthenticated'))
	var cookieValueIsAuthenticated = cookieValueIsAuthenticated.toLowerCase()
	// alert("IsAuthenticated = " + cookieValueIsAuthenticated)
}

function writeWelcomeBackMessage() {
	if ((cookieValue != 0) && (cookieValueFirstName != "")) {
		with (document) {
			write("Welcome to BananaRepublic.com, " + cookieValueFirstName + ". If you are not " + cookieValueFirstName + " <a href='" + sign_out_confirmation_href + "'>click here</a>.\r")
		}
	}
	if ((cookieValue != 0) && (cookieValueIsCSR == "true")) {
		with (document) {
			write("CSR User is signed in: <a href='" + sign_out_confirmation_href + "'>Sign Out</a>\r")
		}
	}
}

function writeSignOutMessage() {
	if ((cookieValue != 0) && (cookieValueFirstName != "")) {
		with (document) {
			write("(If you are not " + cookieValueFirstName + ", please " + " <a href='" + sign_out_confirmation_href + "'><span class='mktColor02'>click here</span></a>.)\r")
		}
	}
}

function writeSignedInMessage() {
	// check normal user
	if ((cookieValue != 0) && (cookieValueFirstName != "")) {
		with (document) {
			write("&nbsp;" + cookieValueFirstName + " is signed in: <a href='" + profile_index_href + "'>Access Your Info</a> | <a href='" + sign_out_confirmation_href + "'>Sign Out</a><img src='/assets/common/clear.gif' border='0' width='1' height='13'>\r")
			/* disabled for now - always must do full sign out
			if (cookieValueIsAuthenticated == "true") {
				write(" | <a href='/registration/sign_out_confirmation.asp?State=signout'>Sign Out</a>\r")
			}
			*/
		}
	}
	// check CSR
	else if ((cookieValue != 0) && (cookieValueIsCSR == "true")) {
		with (document) {
			write("&nbsp;CSR User is signed in: <a href='" + sign_out_confirmation_href + "'>Sign Out</a>\r")
		}
	}
	// default message
	else {
		with (document) {
			write("&nbsp;Welcome to our online store.");
		}
	}
}


function writeOrderStatusLink() {
	// alert("function running\rcookieValue = " + cookieValue + "cookieValueFirstName = " + cookieValueFirstName)
	// if (cookieValue == "") {
	if (cookieValueFirstName == "") {
		// alert("cookieValueFirstName.length = " + cookieValueFirstName.length)
		with (document) {
			write("<a href='" + order_status_lookup_href + "'>check order status</a> | \r")
		}
		// }
	}
}
// alert("cookieValue = " + cookieValue)
// alert("cookieValueFirstName = " + cookieValueFirstName)

// Returns a boolean value stating if a user is signed in or not.
function blnIsSignedIn() {
	if ((cookieValue != 0 && cookieValueFirstName != "") || (cookieValue != 0 && cookieValueIsCSR == "true")) {
		return true;
	}
	else { 
		return false;
	}
}


//Evaluates and returns the layer object style based on the div id.
function objLayerStyle(the_div) {
	var the_layer;
	if (document.documentElement) {
		the_layer = document.getElementById(the_div).style;
	} else if (document.all) {
		the_layer = eval("document.all." + the_div + ".style");
	} else if (document.layers) {
		the_layer = eval("document." + the_div);
	} else {
//		alert("sorry, this only works in 4.0 and higher browsers");
		return false;
	}
	return the_layer;
}

//Evaluates and returns the layer object based on the div id.
function objLayer(the_div) {
	var the_layer;
	if (document.documentElement) {
		the_layer = document.getElementById(the_div);
	} else if (document.all) {
		the_layer = eval("document.all." + the_div);
	} else if (document.layers) {
		the_layer = eval("document." + the_div);
	} else {
//		alert("sorry, this only works in 4.0 and higher browsers");
		return false;
	}
	return the_layer;
}


function getXYCoords(img){
	browse();
	if (browser == 1){
		broadcastX = document[img].x;
		broadcastY = document[img].y;
		//alert("broadcastX = " + broadcastX)
		//alert("broadcastY = " + broadcastY)
	}
	if (document.all) {
		var x = 0;
		var y = 0;
		imgs = img;
		obj = document[imgs];
		while (obj.offsetParent != null) {
			x += obj.offsetLeft;
			//alert("x += obj.offsetLeft results to: " + x)
			y += obj.offsetTop;
			//alert("y += obj.offsetLeft results to: " + y)
			obj = obj.offsetParent;
			//alert("x: " + x + "\r" + "y: " + y + "\r" + "obj: " + obj + "\r" );
		}
		x += obj.offsetLeft;
		y += obj.offsetLeft;
		broadcastX = x;
		broadcastY = y;
		//if(platform == 4){
		//	broadcastX = broadcastX -10;
		//	broadcastY = broadcastY -96;
		//}
		
	}
	//alert("These are the new X and Y coordinates:" + "\r" + "broadcastX = " + broadcastX + "\r" + "broadcastY = " + broadcastY)
}

	// BEGIN added by RMH 2002.11.06
	// moved from individual sign-in files
	// RMH 2002.11.11: added URL encoding
	function SubmitLoginForm(sURL, sEmailAddress, sState) {
		var strURL;
		strURL = sURL + "?State=" + escape(sState) + "&txt_email_address=" + escape(sEmailAddress);
		go(strURL);
	}
	// END added by RMH 2002.11.06
