/**
 * Common client-side functions
 * @ctype file
 * @id /diy_main/common_lib.js
 * @name common_lib.js
 * @author
 * @version $Revision:   4.24  $
 * @file $RCSfile$
 * @revdate $Date:   04 Nov 2005 09:32:14  $
 */

function getClientSideArgsForExternalSites(serverSideArgs){
		if (serverSideArgs){
			
			if(top && top.Session_userLoggedIn){ 
				 serverSideArgs += "&userLoggedIn="+ top.Session_userLoggedIn;
			}	
			if(getCookie("userName") != null){
				 serverSideArgs += "&userName=" + getCookie("userName");
			}
			if(getCookie("hdStore") != null && getCookie("targetedBizID") != null){
				var targetStoreId = getCookie("targetedBizID");
				serverSideArgs += "&targetedBizID="+targetStoreId;
				var storeInfo = getCookie("hdStore");
				var storeInfoArray = storeInfo.split("|");
				serverSideArgs += "&hdStoreName=" + escape(storeInfoArray[0]);
				serverSideArgs += "&hdStoreNumber=" + escape(storeInfoArray[3]);
			}	
			return serverSideArgs;
		}
	else {
		return null;
	}	
}

function openEmailFeature(URL,title,winWidth,winHeight){

    var winY,winX = 0;
        if (screen.width>winWidth && screen.height>winHeight){
            winX=(screen.width-winWidth)/2;
            winY=(screen.height-winHeight)/2;
        }
        var winOptions  = 'resizable=yes,scrollbars=yes,location=no,toolbar=yes,status=yes,top='+winY+',left='+winX;
        winOptions += ',screenX=10,screenY=10,width='+winWidth+',height='+winHeight;
        var popupWin2 = window.open(URL, title, winOptions);
        window.top.name='opener';
        if (popupWin2) {
            popupWin2.focus();
        }
    document.promoForm.enterPromoEmail.value = "";
}	
function getCSAnchorString(cntType, cntKey, destPath, destProto, args, anchor){ 
	var retStr = "" ;
	if (destProto == null)destProto = "http" ;
	var newLink = getCSLinkObject(cntType, cntKey, destPath, destProto) ;
	if (newLink != null)
	{
		if (newLink.href != null && newLink.href != "")
		{	if (args != null && args!= "")
				newLink.href += "&"+args;
			if (anchor != null && anchor != "")
				newLink.href += "#" + anchor;			
		}
		else
		{	newLink.href = "#";
			newLink.target = "_self";
		}
		retStr = "<a class=Jlink href=\"" + newLink.href + "\" target=\"" + newLink.target + "\">" ;
	}
	return retStr ;
}	
function getCSCorporateAnchorString(destPath, args, anchor){ 
	var retStr = "" ;
	var destProto = "http" ;
	var newLink = getCSCorporateLinkObject(destPath, args, anchor) ;
	if (newLink != null)
	{
		if (newLink.href != null && newLink.href != "")
		{	if (args != null && args!= "")
				newLink.href += "&"+args;
			if (anchor != null && anchor != "")
				newLink.href += "#" + anchor;			
		}
		else
		{	newLink.href = "#";
			newLink.target = "_self";
		}
		retStr = "<a class=Jlink href=\"" + newLink.href + "\" target=\"" + newLink.target + "\">" ;
	}
	return retStr ;
}
function getCSCorporateLinkObject(destPath, args, anchor){
	var omitSiteName = true;
	var newLink = {href: "", target: "corporate"};
	newLink.href = getHostString("http",omitSiteName) ;
	newLink.href += "/" + gv_siteContext + "/" + gv_langCode + destPath;
	if (args != null && args != "")	newLink.href += "&"+args;	
	if (anchor != null && anchor != "")	newLink.href += "#" + anchor;	
	return newLink ;
}	
function getCSLinkObject(cntType, cntKey, destPath, destProto, args, anchor){
	var newLink = {href: "", target: "_self"};
	if (destProto == null)destProto = "http" ;
	
	if (top.location.protocol != destProto+":")	{
		destPath = "/diy_main/pg_diy.jsp";
		newLink.target = "_top";
	}
	if (newLink.target=="_self" && top.location.href != parent.location.href)	newLink.target = "_parent";
	newLink.href = getHostString(destProto) ;
	newLink.href += "/" + gv_siteContext + "/" + gv_langCode + destPath;
	newLink.href += "?"+Session.Location.linkString();
	newLink.href += "&CNTTYPE=" + escape(cntType) + "&CNTKEY="  + escape(cntKey) ;
	if (args != null && args != "")	newLink.href += "&"+args;	
	if (MID != null && MID != "") newLink.href += "&MID="+MID;
	if (anchor != null && anchor != "")	newLink.href += "#" + anchor;
	return newLink ;
}	

function getHostString(destProto, omitSiteName){
	var port=0;
	var portStr="";
	var host = getWebServerHost();
	if (destProto != "https"){
		port = getHTTPPort();
		if (port == 80) port = 0;
	}
	else {
		port = getHTTPSPort();
		host = getWebServerHostSecure();
		if (port ==443) port = 0;
	}	
	if (port != null && port !=0) portStr = ":" + port;
	var hostString = destProto + "://" + host + portStr;	
	if (omitSiteName){
		return hostString;
	}
	else{
  	return hostString + Request.SCRIPT_NAME;
	}
}
gc_ContextAttributeYes = "yes";
function LO_ObjectConstructor( obj, pgObj, relativeSourcePath )	{
	obj.NOCACHE_OUTPUT_FLG = false;
	obj.mv_pg = pgObj;
	obj.mv_relativeSourcePath = relativeSourcePath;
}
var gc_HOST_TYPE_SERVER = 1;
var gc_HOST_TYPE_CLIENT = 2;
function LO_PageConstructor( siteContext, hostType, thisPageRelativePath, pgObj ) {
	pgObj.mv_siteContext = siteContext;	
	pgObj.mv_relativePagePath = thisPageRelativePath;
	pgObj.mv_hostType = hostType;
	pgObj.mv_className = "PleaseAssignClassName";	
	pgObj.mv_allowCSJS = true;
	pgObj.mv_langCode = gv_langCode;
  pgObj.mv_pageTitle = "";
	pgObj.write = LO_PageConstructor_Write;
	pgObj.AddPageSectionRenderer = LO_PageConstructor_AddPageSectionRenderer;
	pgObj.a = LO_PageConstructor_AddPageSectionRenderer;
	pgObj.RegisterJSObject = LO_PageConstructor_Null;
	pgObj.RegisterContentObject = LO_PageConstructor_Null;
	pgObj.SetNoCacheOutput = LO_PageConstructor_Null;
	pgObj.SetPageTitle = LO_PageConstructor_SetPageTitle;
	pgObj.Finish = LO_PageConstructor_Null;
	pgObj.SetSectionDirty = LO_PageConstructor_Null;
	pgObj.GetSectionDirty = LO_PageConstructor_Null;
	pgObj.ProcessSection = LO_PageConstructor_ProcessSection;
  pgObj.GetNavFormString = LO_PageConstructor_GetNavFormString;
	pgObj.RT_ContentURL = RT_ContentURL;
	pgObj.mv_sectionRendererLists = new Array();
	pgObj.mv_dirtySections = new Array();
	}
function LO_PageConstructor_SetPageTitle(t)    {  this.mv_pageTitle = t;  }	
function LO_PageConstructor_Null()	{}
function LO_PageConstructor_Write(str)	{document.write(str)}

function LO_PageConstructor_AddPageSectionRenderer( sectionName, sectionRenderer ) 	{
	var sectionPool;
	var sectionList;
	sectionPool = this.mv_sectionRendererLists;
	sectionList = sectionPool[sectionName];
	if( !sectionList )
		{
		sectionList = new Array();
		sectionPool[sectionName] = sectionList;
		}
	sectionList[sectionList.length]= sectionRenderer ;
}
function LO_PageConstructor_ProcessSection(sectionName, markSectionDirty, reverseOrder) {
	var renderer;
	var rendererList;
	var rendererListIdx;
	var rendererListCount;
	var rendererListIncrement;
	if ( markSectionDirty )	this.mv_dirtySections[sectionName] = true;
	rendererList = this.mv_sectionRendererLists[sectionName];
	if ( rendererList ){
		rendererListCount = rendererList.length;
		if ( reverseOrder ){
			rendererListIncrement = -1;
			rendererListIdx = rendererListCount - 1;
			}
		else{
			rendererListIncrement = 1;
			rendererListIdx = 0;
			}
		while( rendererListCount-- > 0 )
			{
			renderer = rendererList[rendererListIdx];
			renderer.WriteSection(sectionName, this);
			rendererListIdx += rendererListIncrement;
			}			
		}
	}

 function  LO_PageConstructor_GetNavFormString(cntType, cntKey) {
   var s;
   if (!cntType) cntType = Request.value ("CNTTYPE");
   if (!cntKey) cntKey = Request.value ("CNTKEY");
   s =  "<input type=HIDDEN name=\"CNTTYPE\" value=\"" + cntType + "\">\n";
	 s += "<input type=HIDDEN name=\"CNTKEY\"  value=\"" + cntKey+ "\">\n";
   return s
  }		
	
var gc_SITE_CONTEXT_HDUS = "HDUS";
var gc_SITE_CONTEXT_DEFAULT = gc_SITE_CONTEXT_HDUS;
	
function RT_DRPATH(siteContext, langCode, drPath )	{
	return "/" + siteContext + "/" + langCode + drPath;
	}

function RT_SRPATH(siteContext, langCode, srPath ){
	if(srPath.indexOf("/cstudio/") == 0)	return srPath;
	return "/" + siteContext + "/" + langCode + srPath;
	}
function RT_UPLOADPATH(siteContext, langCode, uploadPath)
{	return "cmc_upload" + "/" + siteContext + "/" + langCode + uploadPath;	}
	
function RT_CATPATH(siteContext, langCode, catPath )
	{	return "/" + siteContext + "/" + langCode + catPath;	}

function RT_ImageURL(siteContext, langCode, relativePath, args, protocol, host, port)
	{	return RT_DocRoot(siteContext, langCode, relativePath, args, protocol, host, port);	}

function RT_NEW(siteContext, langCode, objName, arg1, arg2, arg3, arg4, arg5, arg6, arg7)	{
	var obj;
	var fullObjName = langCode + "_" + objName;
	eval("obj = new " + fullObjName + "(arg1, arg2, arg3, arg4, arg5, arg6, arg7);");
	obj.mv_className = fullObjName;
	obj.mv_nonTranslatedClassName = objName;
	return obj;
	}

function getARL(drPath) 
{
	return drPath;
}

function RT_BinaryURL(siteContext, langCode, relativePath, args, protocol, host, port)
	{	return RT_DocRoot(siteContext, langCode, relativePath, args, protocol, host, port);	}
 
function RT_DocRootURL(siteContext, langCode, relativePath, args, protocol, host, port)	{
	var url = "";
	if(host)	{
	  if (!protocol)protocol = "http" ;
	  url += protocol + "://" + host;  }
	if( port )url += ":" + port;
	url += relativePath;
	if ( !isEmptyString(args) )	url += "?" + args;
	return url;
	}


function RT_ContentURL(siteContext, langCode, cntType, cntKey, relativePath, args, protocol, host, port)	{
	var url = "";
	if(host){
		if (!protocol) protocol = "http" ;
		url += protocol + "://" + host;
	}
	if( port )	url += ":" + port;
	url += Request.SCRIPT_NAME + relativePath + "?" + "CNTTYPE=" + Request.url_encode(cntType) + "&" + "CNTKEY=" + Request.url_encode(cntKey) + "&";
	if ( !isEmptyString(args) )	url +=  args + "&" + Session.Location.linkString();
	else url += Session.Location.linkString();
	if (MID != null && MID != "") url += "&MID="+MID;
	return url;
	}
 
function RT_ScriptURL(siteContext, langCode, relativePath, args, protocol, host, port)	{
		var url = "";
		if(protocol)url += protocol + "://" + host;
		if( port )	url += ":" + port;
		url += Request.SCRIPT_NAME + relativePath + "?";
		if ( !isEmptyString(args) )	url += args + "&" + Session.Location.linkString();
		else	url += Session.Location.linkString();
		if (MID != null && MID != "") url += "&MID="+MID;
		return url;
	}

 function stopError()   {  return true;  } 
 window.onerror = stopError;

function  CSJS_DoRollover(pg){
  var llen = CSJS_DoRollover.arguments.length;
  if (document.images)   {
	for (var i = 1; i < llen ; i += 2)
	   { 
			 document[ CSJS_DoRollover.arguments[i + 1]].src = pg.mv_topNavImages[ CSJS_DoRollover.arguments[i]].src; 
	   } 
  } 
} 

var gc_ATTR_ID = "ATTR_ID";
var gc_ATTR_GROUP = "ATTR_GROUP";
var gc_ATTR_NAME = "ATTR_NAME";
var gc_ATTR_VALUE = "ATTR_VALUE";

function NAV_GetValue(nav, id, group, name){
var rowNo=-1;
var row;

if (nav)  {
	nav.cursor =0;
  if (id)	rowNo = nav.locate (gc_ATTR_ID, id)
  else if (group && name)	{
	 while ((rowNo = nav.locate (gc_ATTR_NAME, name)) != -1) {
	     row = nav.get (rowNo);
		   if (row.get(gc_ATTR_GROUP).stringValue == group) leave;
	     }
	  }
 }	
if (rowNo != -1) {
	 row = nav.get (rowNo);
	 myvalue = DB_GetValueByType(row.get (gc_ATTR_VALUE));
	 if (myvalue) myvalue = myvalue.toLowerCase() ;
	 return myvalue;
	 }
 return null;
}			

function NAV_LocateCSJSNavObjRow (attribName, attribValue){
   for (var isub = this.cursor; isub< this.row.length; isub++) {
		  if (eval("this.row[" + isub + "]." + attribName + " == '" + attribValue + "'")) return isub;
	    }
	 return -1;
}

function LO_CSJS_Environment(master) {
	this.mv_master = master;
	this.ApostropheFix= L0_CSJS_Environment_ApostropheFix;
  this.ClientIsSet= L0_CSJS_Environment_ClientIsSet;
	this.CheckIfAnyClientIsSet = L0_CSJS_Environment_CheckIfAnyClientIsSet;
	this.ClientRequestPersonal= L0_CSJS_Environment_ClientRequestPersonal;
	this.ClientLoadDummyValues = L0_CSJS_Environment_ClientLoadDummyValues;
	}
		
function L0_CSJS_Environment_ClientIsSet(code)  {
  var isSet = eval(this.mv_master + "personalData"+code+"Loaded");
  if ( (isSet == null) || !isSet)	 return false;
	else  return true;
   }

//returns true if either personalData1Loaded or personalData2Loaded is true.
function L0_CSJS_Environment_CheckIfAnyClientIsSet(){
	var isSet = eval(this.mv_master + "personalData2Loaded");
	if ( (isSet == null) || !isSet)	 {
		
		//Next attempt: eval "top.personalData1Loaded"
		isSet = eval(this.mv_master + "personalData1Loaded");
		if ( (isSet == null) || !isSet)	 {
			return false;
		}
		else{
			return true;
		}
		return false;
	}
	else  {
		return true;
	}
}
	
function L0_CSJS_Environment_ClientRequestPersonal(code)  {
		// Re-Request this page, but with DRC flag set to 'code'.
   var pos = location.href.indexOf("?");
   if (pos == -1)		location.href += "?DRC="+code;
   else location.href += "&DRC="+code;
  }
		
function L0_CSJS_Environment_ClientLoadDummyValues(type){
	var m = this.mv_master;
switch (type)
  {
	  case ("1"): // DIY data
	  eval (m + "Session_HD_myProjectsLink = '';");
	  eval (m + "Session_userLoggedIn = false;");
	  eval (m + "THDgetMyProjects = 'You can add How-To projects to your Personal Project File';");
	  eval (m + "isCsrUser = false;");
	  eval (m + "isCsrAdminUser = false;");
	  eval (m + "suggestedPicture_HEADER_IMAGE = '';");
	  eval (m + "firstMatch_SUMMARYTITLE = '';");
	  eval (m + "firstMatch_BASE_KEY = '';");
	  eval (m + "THDMP_SUGPROJ_NUM = 0;");
	  eval (m + "THDgetUsersEmail = '';");
	  eval (m + "THDMPgetMyProjListText = '';");
	  eval (m + "ACTUAL_SUGPROJ = 0;");
			eval (m + "personalData1Loaded = false;")
			break;
	  case ("2","3"): // CAT data
		  eval (m + "cart_GetCartItemCount = '0';");
		  eval (m + "cart_GetCartTotalQty = '0';");
	    eval (m + "cart_GetCartSubTotalFormatted = '$0.00';");
		  eval (m + "Session_HD_storeName = '';");
		  eval (m + "Session_HD_storePhoneFormatted = '';");
		  eval (m + "Session_HD_storeAddress1 = '';");
		  eval (m + "Session_HD_storeAddress2 = '';");
		  eval (m + "Session_HD_storeCity = '';");
			eval (m + "Session_HD_stateName = '';");
			eval (m + "Session_HD_shipToZip = '';");
			eval (m + "personalData2Loaded = false;")
			eval (m + "personalData3Loaded = false;")
			break;
		default:
			eval (m + "personalData" + type + "Loaded = false;")
		  break;
  }
	// generic descriptions
	  eval (m + "Request_SCRIPT_NAME = '';");
		eval (m + "getWebServerHost = '';");
		eval (m + "getHTTPPort = 80;");
		eval (m + "getHTTPSPort = 443;");
		eval (m + "getMIDValue = 0;");
	  eval (m + "Request_REMOTE_ADDR = '';");
	  eval (m + "Session_Location_linkString = '';");
	  eval (m + "Session_Location_formString= '';");
	  eval (m + "Session_HD_myHomeDepotLink = '';");
	  eval (m + "Session_HD_storeLocatorLink = '';");
	  eval (m + "currentVisitor_isRegistered = 0;");
	  eval (m + "currentVisitor_isActive = 0;");
	  eval (m + "currentVisitor_MAX_PERS_LEVEL = 0;");
	  eval (m + "currentVisitor_NUMBER_LOGIN = 0;");
	  eval (m + "currentVisitor_FIRSTNAME = '';");
	  eval (m + "THDcurrentVisitor_GetOnlineStoreLinkFrame = '';");
	eval (m + "THDcurrentVisitor_GetOnlineStoreLinkNoFrame = '';");
	  eval (m + "domain = 'homedepot.com';");
	  eval (m + "THDcurrentVisitor_IsPro = false;");
	  eval (m + "THDgetNearestRetailStore = '';");
	  eval (m + "THDcurrentVisitor_IsInStore = false;\n");
}
function L0_CSJS_Environment_ApostropheFix(s,addPlaceHolder) {
	if (s)  {
	  if (addPlaceHolder)  s = s.replace(/\x27/g, "ZZAPOSHOLDZZ");
		else   s = s.replace( /ZZAPOSHOLDZZ/g, "'");
		}
  return s;
   }
				 
function EncodeFix(val) {
		var s = "";
		if (val)
		{		
			s = new String(val);
			s = s.replace(/é/g, '%e9');
			//The Mac has funky encoding:
			s = s.replace(/%uFFE9/g, '%e9');
			s = s.replace(/%8E/g, '%e9');
			s = s.replace('+&+', '+%26+'); //this makes sure that only ampersands with spaces around them get encoded. 
		}
	  return s;
  }
	
// fgp01 - replace apostrophe placeholder with html quote (&#39;)
function convertPlaceHolderToHTML(val){
		var s =  "";
		if (val){
			s = new String(val);
		var ph = "ZZAPOSHOLDZZ";	
		while (s.indexOf(ph) != -1)
		{
	  	s = s.replace(ph, "&#39;");
   		}
		}
  return s;
}

function Certify(URL) {
  popupWin = window.open(URL, 'Participant', 'location,scrollbars,width=450,height=420')
  window.top.name = 'opener';
}

function openFeature2(URL,title,winWidth,winHeight){
	var winY,winX = 0;
	if (screen.width>winWidth && screen.height>winHeight)
	{
		winX=(screen.width-winWidth)/2;
		winY=(screen.height-winHeight)/2;
	}
	var winOptions  = 'resizable=yes,scrollbars=yes,location=no,toolbar=yes,status=yes,top='+winY+',left='+winX;
	winOptions += ',screenX=10,screenY=10,width='+winWidth+',height='+winHeight;
	var popupWin2 = window.open(URL, title, winOptions);
	window.top.name='opener';
	if (popupWin2) {
		popupWin2.focus();
	}
}
	
function openFeatureFlex(URL,title,winWidth,winHeight,resizable,scrollbars,location,toolbar,status,menubar){
	var winY,winX = 0;
	if (screen.width>winWidth && screen.height>winHeight)
	{
		winX=(screen.width-winWidth)/2;
		winY=(screen.height-winHeight)/2;
	}
	var winOptions = "";
	if (resizable){
		winOptions += ",resizable";
	}
	if (scrollbars){
		winOptions += ",scrollbars";
	}
	if (location){
		winOptions += ",location";
	}
	if (toolbar){
		winOptions += ",toolbar";
	}
	if (status){
		winOptions += ",status";
	}
	if (menubar){
		winOptions += ",menubar";
	}
	if (winOptions.charAt(0) == ","){
		winOptions = winOptions.substr(1);
	}
	
	winOptions  += ',top='+winY+',left='+winX + ',screenX=10,screenY=10,width='+winWidth+',height='+winHeight;
	var popupWin2 = window.open(URL, title, winOptions);
	window.top.name='opener';
	if (popupWin2) {
		popupWin2.focus();
	}
}

function addToWishList(oid, qtyField){
	var qty=qtyField.value;
	var hrefObj = getCSLinkObject("PROD_META", 'Your Account/Wish List','/wish_list/pg_index.jsp',null,'oid='+oid+"&qty="+qty);

	//Redirect to wish_list/pg_index.jsp
	if (hrefObj.target.indexOf ("self")!=0 ) 
	{ 
		window.location.href=hrefObj.href;
	}
	else 
	{
		top.location = hrefObj.href;
	}

}
function popChangeStoreWindow(filename){  
		var popupPage = RT_SRPATH(gv_siteContext, gv_langCode, filename);
		var url = RT_ScriptURL(gv_siteContext, gv_langCode, popupPage);
		var winArgs='width=350,height=350,scrollbars=No,resizable=No,screenX=40,screenY=50';
		var win = window.open(url, 'resultsPage', winArgs);
		win.focus();
  }
	
function displayContentPopup(contentType, contentKey, destPath, passArgs, winWidth, winHeight, features){
	if (winWidth == null)	winWidth = 600;
	if (winHeight == null)	winHeight = 400;
	var args = "";
	if (contentType != null)args += "&CNTTYPE="+escape(contentType);
	if (contentKey != null)	args += "&CNTKEY="+(contentKey);
	if (passArgs != null)	args += "&"+passArgs;
	var url = RT_ScriptURL(gv_siteContext, gv_langCode, RT_SRPATH(gv_siteContext, gv_langCode,  destPath))
	var winFeatures = 'width=' + winWidth + ',height=' + winHeight + ',scrollbars=yes,resizable=yes';
	if (features) winFeatures += ','+features;
	var cntWin = window.open(url + args,'ContentPopUp',winFeatures);
	cntWin.focus();
}

function getFullURL(context,lang,destProto,destPath){
  var linkObj = {href: "", target: "_self"};
	if (destProto == null)destProto = "http" ;
	if (top.location.protocol != destProto+":")
	{
		destPath = "/diy_main/pg_diy.jsp";
		linkObj.target = "_parent";
	}
	
  var hostString = getHostString(destProto);
	var relativePath = RT_SRPATH(context, lang, destPath);
	linkObj.href = hostString + relativePath;
  return linkObj;
}
function SystemOnResize(evnt){
}	
  function isEmptyString  (arg) {return !arg;}	
  function  DB_GetValueByType (arg) {return arg;}
  function  HTMLEncode (arg) {return arg;}
  function  THDcurrentVisitor() {return tempTHD_VisitorObj;}
	function  THDgetUsersEmail () { return eval (master + "THDgetUsersEmail");}
  function THDcurrentVisitor () { return tempTHD_VisitorObj;}
	function THDgetNearestRetailStore () { return clientEnv.ApostropheFix(eval ( master + "THDgetNearestRetailStore")) ;}
  function currentVisitor() { return tempVisitorObj;}
  function getRequest() {
	  return  { SCRIPT_NAME: eval (master + "Request_SCRIPT_NAME"),REMOTE_ADDR: eval (master + "Request_REMOTE_ADDR"),url_encode:	new Function("arg", "return escape(arg)"),value: 		new Function("arg", "return null") };
		}
	function getTempVisitor(){
	return {isRegistered: new Function("return eval (master+ 'currentVisitor_isRegistered')"),isActive: new Function (" return eval (master+ 'currentVisitor_isActive')"),MAX_PERS_LEVEL: top.currentVisitor_MAX_PERS_LEVEL,NUMBER_LOGIN: top.currentVisitor_NUMBER_LOGIN,FIRSTNAME: top.currentVisitor_FIRSTNAME };
		}
	function getTempTHD_VisitorObj_GetStoreLink()
	  {
		if (top.location.protocol == "http:") return  eval (master+ 'THDcurrentVisitor_GetOnlineStoreLinkNoFrame');
		else return  eval (master+ 'THDcurrentVisitor_GetOnlineStoreLinkFrame');
		}
	function getTempTHD_VisitorObj (){
	  return  {IsPro: new Function (" return eval (master+ 'THDcurrentVisitor_IsPro') "),IsInStore: new Function (" return eval (master+ 'THDcurrentVisitor_IsInStore') "),GetOnlineStoreLink: getTempTHD_VisitorObj_GetStoreLink, GetOnlineStoreLinkNoFrame: new Function ("return  eval (master+ 'THDcurrentVisitor_GetOnlineStoreLinkNoFrame')")};
		}
  function getSession (){
	  return { Location: { linkString: new Function("return eval (master+ 'Session_Location_linkString') ") ,   formString: new Function("return eval (master+ 'Session_Location_formString') ")}, HD: { myHomeDepotLink: clientEnv.ApostropheFix(eval (master+ "Session_HD_myHomeDepotLink")),storeName: clientEnv.ApostropheFix(eval (master+ "Session_HD_storeName")),storePhoneFormatted:eval (master+ "Session_HD_storePhoneFormatted"),storeAddress: clientEnv.ApostropheFix(eval (master+ "Session_HD_storeAddress")),storeLocatorLink:eval (master+ "Session_HD_storeLocatorLink") } };
  }
  function getWebServerHost() {return eval (master+ 'getWebServerHost'); }
  function getWebServerHostSecure() {return eval (master+ 'getWebServerHostSecure'); }
  
	function getHTTPPort(){return eval (master+ 'getHTTPPort');}
	function getHTTPSPort() {return eval (master+ 'getHTTPSPort');}
	function getMID() {return eval (master + 'getMIDValue');}
	function THDcurrentMarket() {
	   return {IsUPSOnly: new Function ("return eval (master+ 'THDcurrentMarket_IsUPSOnly')")}
		 }
	
var commonLibLoaded = true;
//endeca related functions	

function Compare() {
	var searchResultsURL = getCSLinkObject("PROD_META", "misc/searchResults.jsp","/jsearch/searchResults.jsp");
	var compList = "";
	var counter = 0;
	for (var i=0; i<document.comparisonform.elements.length; i++) {
		var name = document.comparisonform.elements[i].name;
		var ischeckbox = name.indexOf("product");
			if (ischeckbox != -1) {
				if (document.comparisonform.elements[i].checked) {
					var value = document.comparisonform.elements[i].value;
					if (compList== "") {
						compList = value;
					}
					else {
						compList = compList+"+"+value;
					}
					counter++;
				}
			}
		}
	  var newList = "";
		var existingList = null;
	  var totalList = null;
	  if(document.comparisonform.total_products.value) {
			totalList = document.comparisonform.total_products.value;
		}	
		if(document.comparisonform.compare_products.value) {
			existingList = document.comparisonform.compare_products.value;
		}
		var excludeList = "";
		var totalListArray = totalList.split(",");
	  if(compList != null && compList.length >0) {
		  var compListArray = compList.split("+");
			for (var k=0; k < totalListArray.length; k++) 	{
				var prodExists = false;
				for(var j=0; j < compListArray.length; j++) 	{
					if(totalListArray[k] == compListArray[j]) {
						prodExists = true;
						break;
					}	
				}
				if(!prodExists) {
					excludeList += totalListArray[k] + ",";
				}	
			}
			excludeList = excludeList.substr(0, excludeList.lastIndexOf(","));
		}
		else {
			excludeList = totalList;
		}
		var newExistingList = "";
	  var modExistingList = ""; 
		if(existingList != null && existingList.length > 0) {
			var existingListArray = existingList.split(",");
			var excludeListArray = excludeList.split(",");
			for (var k=0; k < existingListArray.length; k++) 	{
				var prodExists = false;
				for(var j=0; j < excludeListArray.length; j++) 	{
					if(existingListArray[k] == excludeListArray[j]) {
							prodExists = true;
						  break;
					}	
				}
				if(!prodExists) {
						newExistingList += existingListArray[k] + ",";
				}	
			}
			newExistingList = newExistingList.substr(0, newExistingList.lastIndexOf(","));
			var newExistingListArray = newExistingList.split(",");
			var compListArray = compList.split("+");
			for (var k=0; k < newExistingListArray.length; k++) 	{
				var prodExists = false;
				for(var j=0; j < compListArray.length; j++) 	{
					if(newExistingListArray[k] == compListArray[j]) {
							prodExists = true;
						  break;
					}	
				}
				if(!prodExists) {
						modExistingList += newExistingListArray[k] + "+";
						counter++;
				}	
			}
			modExistingList = modExistingList.substr(0, modExistingList.lastIndexOf("+"));
		}
		newList = compList;
		if(modExistingList.length >0) {
			if(newList.length > 0) {
				newList += "+" + modExistingList;
			}
			else {
				newList += modExistingList;
			}	
		}
	if (counter == 0) {
			alert("Please Select One or More Products to Compare");
			return;
	}
	if (counter > 4) {
			alert("Only four products may be compared at a time. Currently "+counter+" products have been selected.  Please remove addtional products.");
			return;
	}
	else {
			var addterms = ["R="+newList];
			var newurl = searchResultsURL.href+"&"+addterms;
			window.location.href = newurl;
	}
}

function saveForCompare(noArg) {
	var searchResultsURL = getCSLinkObject("PROD_META", "misc/searchResults.jsp","/jsearch/searchResults.jsp");
	var compList = "";
	// LOOP THROUGH ALL THE RECORD LIST CHECKBOXES
	for (var i=0; i<document.comparisonform.elements.length; i++) {
		var name = document.comparisonform.elements[i].name;
		var ischeckbox = name.indexOf("product");
			// LOOP OVER CHECKED BOXES
			if (ischeckbox != -1) {
				// IF THIS CHECKBOX IS CHECKED
				if (document.comparisonform.elements[i].checked) {
					// GET CHECKBOX VALUE
					var value = document.comparisonform.elements[i].value;
					if (compList== "") {
						compList = value;
					}
					else {
						compList = compList+","+value;
					}
				}
			}
		}
	  var newList = "";
		var existingList = null;
	  var totalList = null;
	  if(document.comparisonform.total_products.value) {
			totalList = document.comparisonform.total_products.value;
		}	
		if(document.comparisonform.compare_products.value) {
			existingList = document.comparisonform.compare_products.value;
		}
		var excludeList = "";
		var totalListArray = totalList.split(",");
	  if(compList != null && compList.length >0) {
		  var compListArray = compList.split(",");
			for (var k=0; k < totalListArray.length; k++) 	{
				var prodExists = false;
				for(var j=0; j < compListArray.length; j++) 	{
					if(totalListArray[k] == compListArray[j]) {
						prodExists = true;
						break;
					}	
				}
				if(!prodExists) {
					excludeList += totalListArray[k] + ",";
				}	
			}
			excludeList = excludeList.substr(0, excludeList.lastIndexOf(","));
		}
		else {
			excludeList = totalList;
		}
		var newExistingList = "";
	  var modExistingList = ""; 
		if(existingList != null && existingList.length > 0) {
			var existingListArray = existingList.split(",");
			var excludeListArray = excludeList.split(",");
			for (var k=0; k < existingListArray.length; k++) 	{
				var prodExists = false;
				for(var j=0; j < excludeListArray.length; j++) 	{
					if(existingListArray[k] == excludeListArray[j]) {
							prodExists = true;
						  break;
					}	
				}
				if(!prodExists) {
						newExistingList += existingListArray[k] + ",";
				}	
			}
			newExistingList = newExistingList.substr(0, newExistingList.lastIndexOf(","));
			var newExistingListArray = newExistingList.split(",");
			var compListArray = compList.split(",");
			for (var k=0; k < newExistingListArray.length; k++) 	{
				var prodExists = false;
				for(var j=0; j < compListArray.length; j++) 	{
					if(newExistingListArray[k] == compListArray[j]) {
							prodExists = true;
						  break;
					}	
				}
				if(!prodExists) {
						modExistingList += newExistingListArray[k] + ",";
				}	
			}
			modExistingList = modExistingList.substr(0, modExistingList.lastIndexOf(","));
		}
		newList = compList;
		if(modExistingList.length >0) {
			if(newList.length > 0) {
				newList += "," + modExistingList;
			}
			else {
				newList += modExistingList;
			}	
		}	
		if(newList != null && newList.length > 0) {
	  	document.comparisonform.compare_products.value = newList;
		}
	  var addterms = null;
		if(newList != null && newList.length > 0) {
			addterms = "compare_products="+newList;
		}	
	  var nArg = null;
		if(document.comparisonform.N.value) {
	  	nArg = "N="+escape(document.comparisonform.N.value);
		}
		var nKeyword = null;
		if(document.comparisonform.keyword.value) {
	  	nKeyword = "keyword="+escape(document.comparisonform.keyword.value);
		}
	  var sortArg = null;	  
	  if (document.comparisonform.sort.value) {
			sortArg = "Ns=" + escape(document.comparisonform.sort.value);
		}
		var paginationArg = "No="+noArg;
		var newurl = searchResultsURL.href+"&"+paginationArg;
		if(nArg != null && nArg.length > 0) {
			newurl += "&"+nArg;
		}	
	  if(nKeyword != null && nKeyword.length > 0) {
			newurl += "&"+nKeyword;
		}	
		if(addterms != null && addterms.length > 0 ) {
			newurl += "&"+addterms;
		}	  
	  if (sortArg != null && sortArg.length > 0) {
			newurl += "&" + sortArg;
		}
		window.location.href = newurl;
}




/*

	Overview:   PipView is a JS object that controls the images and viewing
			    of a PIP

	Usage: 		An instance of this object needs to be instantiated on each
				pip page. The markup should be structured so that the main
				image has an id of "pip-main-image" and the thumbnails should
				be inside the pip-thumbs div. Each thumbnail should have a
				class name of pip-thumb and be wrapped with a link that has
				a class of thumb-control. The link should point to the large
				image URL for accessibility and parsing.

				NOTE:
				* The thumbnail anchors must have a class name of thumb-control
				* The path to the large images should be the href of the links

	Arguments:	NONE

	Methods:	Object is self-initializing so the constructor is built in.

				toggleImage: 	Switches the src for the main image


	Sample Use: var myPipViewer = new PipView();
*/

function PipView(){

	// Properties
	// ==========================
	var t = this;
	t.image = '';
	t.thumb = '';

	// Self-Initialization
	// ==========================
	if((document.getElementById) && (document.getElementsByTagName)){

		// Thumbnail Controls
		t.controlsParent = document.getElementById('pip-thumbs');
		if(t.controlsParent){
			t.controls = t.controlsParent.getElementsByTagName('a');
			for(var i=0, control; control=t.controls[i]; i++){
				if(control.className == 'thumb-control'){
				control.onclick = function(){t.toggleImage(this); return false;}
				}
			}
		}else{return false}

		// Main Image
		t.image = document.getElementById('pip-main-image');
		if(!t.image){return false}


	}else{return false}

	// Methods
	// ==========================

	t.toggleImage = function(link){
		t.image.src = link.href;
	}


}





/*

	Overview:   TabNav is a JS object that controls one set of tabs
			    and their respective content blocks

	Usage: 		An instance of this object needs to be instantiated for each
				block of tabs on the page. The markup should be structured
				with the controller anchor and corresponding content div to
				be in the same relative position in it's respective parent.
				Ex) Second anchor tag controls the second content div tag.

				NOTE:
				* The content tabs must have a class name of tab-content
				* The control anchors must be the only anchors in the parent
				* The position of the anchor must be the same as the content
				* The H5 should have a classname called "alt-heading"

	Arguments:	Takes two string literal arguments. (controls, contents)
				controlsID: is the id of the parent block of the tab controls
				contentsID: is the id of the parent block of the content blocks

	Methods:	Object is self-initializing so the constructor is built in as init..

				init: 		Content Blocks and alternate headings are hidden.
							Displays the first content block in the source.

				hideAltHeadings: Hides alt headings(h5.alt-heading)

				toggleControls: Switches active link/tab
								Calls the toggleContent method

				toggleContent: Switches active content block.



	Sample Use: var myTabs = new TabNav("myControlsID", "myContentsID");

*/

function TabNav(controlsID, contentsID){

	// Properties
	// ==========================
	var t = this;
	t.controls = new Array();
	t.contents = new Array();
	t.active = 0;

	// Self-Initialization
	// ==========================
	if((document.getElementById) && (document.getElementsByTagName)){

		// Tab Controls
		t.controlsParent = document.getElementById(controlsID);
		if(t.controlsParent){
			t.controls = t.controlsParent.getElementsByTagName('a');
			for(var i=0, control; control=t.controls[i]; i++){
				control.pos = i;
				control.onclick = function(){t.activate(this.pos); this.blur(); return false;}
				if(control.className == 'active'){t.active = i;}
			}
		}else{return false}

		// Content Blocks
		t.contentsParent = document.getElementById(contentsID);
		if(t.contentsParent){
			t.divs = t.contentsParent.getElementsByTagName('div');
			for(var j=0, div; div=t.divs[j]; j++){
				if(div.className == 'tab-content'){
					t.contents[(t.contents.length)] = div;
				}
			}
		}else{return false}


	}else{return false}

	// Methods
	// ==========================

	t.toggleControls = function(){
		for(var i=0, control; control=t.controls[i]; i++){control.className = 'inactive';}
		t.controls[t.active].className = 'active';
	}

	t.toggleBlocks = function(){
		for(var c=0, content; content=t.contents[c]; c++){content.className = 'tab-content-hidden';}
		activeBlock = t.contents[t.active];
		activeBlock.className = 'tab-content';
	}

	t.showAllBlocks = function(){
		for(var c=0, content; content=t.contents[c]; c++){content.className = 'tab-content';}
	}

	t.hideAltHeadings = function(){
		altHeadings = t.contentsParent.getElementsByTagName('h5');

		if(altHeadings){
			for(var h=0, altHeading; altHeading=altHeadings[h]; h++){
				if(altHeading.className == 'tab-alt-heading'){altHeading.className = 'tab-alt-heading-hidden';}
			}
		}
	}

	t.activate = function(pos){
		t.active = pos;
		t.toggleControls();
		t.toggleBlocks();
	}

	t.init = function(){
		t.toggleBlocks();
		t.hideAltHeadings();
	}

	// Initialize
	var constructor = t.init();

}




// Get Elements By ClassName
function getElementsByClassName(className,oParent) {
  var doc = (oParent||document);
  var matches = [];
  var nodes = doc.all||doc.getElementsByTagName('*');
  for (var i=0; i<nodes.length; i++) {
    if (nodes[i].className == className || nodes[i].className.indexOf(className)+1 || nodes[i].className.indexOf(className+' ')+1 || nodes[i].className.indexOf(' '+className)+1) {
      matches[matches.length] = nodes[i];
    }
  }
  return matches; // kids, don't play with fire. ;)
}


// Generic Shorthand GetElement Function
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string') {
			if (document.getElementById){element = document.getElementById(element);}
			else if (document.all){element = document.all[element];}
		}
		if (arguments.length == 1) {return element;}
		elements.push(element);
	}
	return elements;
}







