function popup(which) {
   mywindow = window.open (which, "mywindow");
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function getElementByID_Master(e) {
//    alert('ge-' + e.toString());

    var ret = null;

    ret = MM_findObj(e);
    if (ret)
        return ret;

    //alert('ctl00_ContentPlaceHolder1_' + e.toString());
    ret = MM_findObj("ctl00_ContentPlaceHolder1_" + e);
    if (ret)
        return ret;

    //alert('ctl00$ContentPlaceHolder1$' + e.toString());
    ret = MM_findObj("ctl00$ContentPlaceHolder1$" + e);
    if (ret)
        return ret;
    
    

/*
    //alert('ctl00_ContentPlaceHolder1_' + e.toString());
    ret = document.getElementsByName('ctl00_ContentPlaceHolder1_' + e.toString());
    if (ret != null)
        return ret;

    //alert('ctl00$ContentPlaceHolder1$' + e.toString());
    ret = document.getElementsByName('ctl00$ContentPlaceHolder1$' + e.toString());
    if (ret != null)
        return ret;
*/

    //if (ret)
        //alert(e.toString());
        
    return ret;        
}

function popup_extra(theURL,winName,features) { //v2.0
	var pw;
	pw = window.open(theURL,winName,features);
	pw.focus();
}

function zeropad(i) {
    if (i == 0)
        return 0;

    if (i < 9)
        return "0" + i;
   
   return i;
}

function popup_win_params(w, p) {
    var pw;
    pw = window.open(w, 'Popup', p);
    pw.focus();
}

function popup_win(w) {
	var pw;
	pw = window.open(w,'Popup','height=275,width=475,toolbar=no,resizable=no,scrollbars=no');
	pw.focus();
}

function popup_fitguide(w,height,width) {
	var pw;
	var paramstring = "height=" + height + ",width=" + width + ",toolbar=no,resizable=no,scrollbars=no";
	pw = window.open(w,'FitGuide',paramstring);
	pw.focus();
}
function popup_sizechart(w) {
	var pw;
	pw = window.open(w,'SizeChart','height=450,width=620,toolbar=no,resizable=no,scrollbars=yes');
	pw.focus();
}

function popup_sizechart2(w,height,width) {
	var pw;
	var paramstring = "height=" + height + ",width=" + width + ",toolbar=no,resizable=no,scrollbars=yes";
	pw = window.open(w,'SizeChart',paramstring);
	pw.focus();
}

function popup_referafriend(w) {
	var pw;
	pw = window.open(w,'ReferAFriend','height=425,width=450,toolbar=no,resizable=no,scrollbars=no');
	pw.focus();
}

function popup_shareproduct(w,height,width) {
	var pw;
	var paramstring = "height=" + height + ",width=" + width + ",toolbar=no,resizable=no,scrollbars=yes";
	pw = window.open(w,'ShareBookmarkProduct',paramstring);
	pw.focus();
}

function FacebookShare(productid) {
    FacebookShareURL(location.hostname + "/pd/cl/" + color_ids[g_color] + "/p/" + productid + ".html");

}

function FacebookShareURL(url) {
    window.open("http://www.facebook.com/sharer.php?u=" + url);
}

function getElementsByClassName(className, tag, elm){
	var Class = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(Class.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

function addCls(elm, className){
    var currentClass = elm.className;
    if(!new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i").test(currentClass)){ 
        elm.className = currentClass + ((currentClass.length > 0)? " " : "") + className;
    }
    return elm.className;
}

function remCls(elm, className){
    var classToRemove = new RegExp(("(^|\\s)" + className + "(\\s|$)"), "i");
    elm.className = elm.className.replace(classToRemove, "").replace(/^\s+|\s+$/g, "");
    return elm.className;
}

function toggleElem(id,show) {
    if (show=="1"){
        if (document.layers) {
            document.layers[id].visibility = "show";
        } else if (document.all) {
            document.all[id].style.visibility = "visible";
        } else if (document.getElementById) {
            getElementByID_Master(id).style.visibility = "visible";
        }
    } else if (show=="0") {
        if (document.layers) {
            document.layers[id].visibility = "hide";
        } else if (document.all) {
            document.all[id].style.visibility = "hidden";
        } else if (document.getElementById) {
            getElementByID_Master(id).style.visibility = "hidden";
        }
    }
}

function setElem(id,val) {
    if (getElementByID_Master(id))
        getElementByID_Master(id).innerHTML = val;
        try { getElementByID_Master(id).className = "" }
	    catch(err){}
}

function reload_sizes() {
	if (size_count == 0)
		return;

    var ps = getElementByID_Master("ProductSizes");
	if (ps == null)
		return;
				
	var curr_value = ps.options[ps.selectedIndex].value;
	var curr_index = 0;

	ps.length = 0;
	ps.options[0] = new Option("Select " + g_sizealias, "-1");
	curr_index++;

	for (var i = 1; i <= size_count; i++) {
		if (g_color == 0 || aSCSA[g_color][i] == true || g_showwhenoos == 1) {
			ps.options[curr_index] = new Option(size_names[i], size_ids[i]);
			if (curr_value == size_ids[i])
				ps.selectedIndex = curr_index;

			curr_index++;
		}
	}
	if (ps.length == 2 && (getElementByID_Master("DisableOneSizeSelection") == null || (getElementByID_Master("DisableOneSizeSelection") != null && getElementByID_Master("DisableOneSizeSelection").value != 1))) {
	    ps.selectedIndex = 1; 
  } 	
}

function reload_colors() {
	if (color_count == 0)
		return;

    var ps = getElementByID_Master("ProductColors");
	if (ps == null)
		return; 
				
	var curr_value = ps.options[ps.selectedIndex].value;
	var curr_index = 0;

	ps.length = 0;
	ps.options[0] = new Option("Select Color", "-1");
	curr_index++;
	
	for (var i = 1; i <= color_count; i++) {
		if (g_size == 0 || aSCSA[i][g_size] == true || g_showwhenoos == 1) { 
			ps.options[curr_index] = new Option(color_names[i], color_ids[i]);
			if (curr_value == color_ids[i])
				ps.selectedIndex = curr_index;

			curr_index++;
		}
	}
	if (ps.length == 2){
  ps.selectedIndex = 1; 
  } 	
}

function change_upc() {
    var upc = getElementByID_Master("upc_text");
	if (upc == null)
		return;
		
	if (aUPC[g_color] == null) {
		upc.innerHTML = '';
		return;
	}
		
	var val = aUPC[g_color][g_size];
	if (val == null || val == '') {
		upc.innerHTML = '';
		return;
	}
	
	upc.innerHTML = 'UPC: ' + val;
}

function HideElem(id) {
    var e = getElementByID_Master(id);
    if (e != null) {
        e.style.display = "none";
    }
}

function ShowElem(id) {
    var e = getElementByID_Master(id);
    if (e != null) {
        e.style.display = "inline";
    }
}

function reset_unitcost(uc, flag)
{
    if (g_unitcost == '$0.00' || g_mincost != g_maxcost) {
        if (g_mincost == g_maxcost || flag == 1) {
            if (g_previouscost == '$0.00')
                uc.innerHTML = g_maxcost;
            else
                uc.innerHTML = g_unitcost;
        }
        else
	        uc.innerHTML = g_mincost + ' - ' + g_maxcost;
    }
    else {
	    uc.innerHTML = g_unitcost;
    }
}

function change_costspans()
{
    var lpl = getElementByID_Master("legacy_price_layout");
	if (lpl == null)
	    return;

	var csr = getElementByID_Master("costspan_regular");
	if (csr == null)
	    return;

	var css = getElementByID_Master("costspan_sale");
	if (css == null)
	    return;

	var uc = getElementByID_Master("UnitCostSpan");
	if (uc == null)
		return;

    var pc = getElementByID_Master("PreviousCostSpan");
	if (pc == null)
		return;

    var csr_uc = getElementByID_Master("costspan_regular_uc");
	if (csr_uc == null)
		return;

    var css_uc = getElementByID_Master("costspan_sale_uc");
	if (css_uc == null)
		return;

    var css_pc = getElementByID_Master("costspan_sale_pc");
	if (css_pc == null)
		return;

    if (pc.innerHTML == '') {
        csr.style.display = "block";
        css.style.display = "none";
        csr_uc.innerHTML = uc.innerHTML;
    } else {
        csr.style.display = "none";
        css.style.display = "block";
        css_uc.innerHTML = uc.innerHTML;
        css_pc.innerHTML = pc.innerHTML;
    }
    
    lpl.style.display = "none";
    HideElem("PreviousCost");
    HideElem("PreviousCostCustom");
    HideElem("PreviousCostCustom2");
}

function change_unitcost() {
    var uc = getElementByID_Master("UnitCostSpan");
    var ucv2 = getElementByID_Master("RegularPrice2LB");
    HideElem("RegularPrice2LB");
    
	if (uc == null)
		return;
		
	if (aSKUUnitCost[g_color] == null) {
		reset_unitcost(uc, 0);
		return;
	}
		
	var val = aSKUUnitCost[g_color][g_size];
	if (val == null || val == '') {
		reset_unitcost(uc, 1);
		return;
}
        
    if (ucv2 != null) {
        if (val == g_unitcost)
            HideElem("RegularPrice2LB");
        else
            ShowElem("RegularPrice2LB");
    }
    
	uc.innerHTML = val;
}

function reset_unitcost_col(productid, uc)
{
    if (eval("g_unitcost_" + productid) == '$0.00') {
        if (eval("g_mincost_" + productid) == eval("g_maxcost_" + productid))
            uc.innerHTML = eval("g_maxcost_" + productid);
        else
	        uc.innerHTML = eval("g_mincost_" + productid) + ' - ' + eval("g_maxcost_" + productid);
    }
    else {
	    uc.innerHTML = eval("g_unitcost_" + productid);
    }
}

function change_unitcost_col(productid,i) {
    //alert(productid + " " + i);
    var uc = getElementByID_Master("UnitCostSpan_" + productid);
	//alert(uc);
	if (uc == null)
		return;
		
    //alert(eval("aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]"));
	if (eval("aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]") == null) {
	    //alert('reset1');
		reset_unitcost_col(productid, uc);
		return;
	}
		
	var val = eval("aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]" + "[" + "g_size_" + productid + "]");
	if (val == null || val == '') {
	    //alert(val + ' :reset2' + " aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]" + "[" + "g_size_" + productid + "]" + ' g_color: ' + eval("g_color_" + productid) + ' g_size: ' + eval("g_size_" + productid));
		reset_unitcost_col(productid, uc);
		return;
	}
	
	uc.innerHTML = val;
}

function reset_previouscost_col(productid,pc) {
    if (eval("g_previouscost_" + productid) == '$0.00') {
    	    
	    pc.innerHTML = '';
    }
    else {
	    pc.innerHTML = eval("g_previouscost_" + productid);
    }
}

function reset_previouscost(pc) {
    if (g_previouscost == '$0.00') {
        HideElem("PreviousCost");
        HideElem("PreviousCostCustom");
        HideElem("PreviousCostCustom2");
    	    
	    pc.innerHTML = '';
    }
    else {
	    pc.innerHTML = g_previouscost;

	    if (g_previouscost == g_unitcost) {
	        HideElem("PreviousCostCustom");
	        HideElem("PreviousCostCustom2");
	    }
	    else {
	        ShowElem("PreviousCost");
	        ShowElem("PreviousCostCustom"); 
	        ShowElem("PreviousCostCustom2");
	    }
    }
}

function change_previouscost() {
    var pc = getElementByID_Master("PreviousCostSpan");
	if (pc == null)
		return;
		
	if (aSKUPreviousCost[g_color] == null) {
		reset_previouscost(pc);
		return;
	}
		
	var val = aSKUPreviousCost[g_color][g_size];
	if (val == null || val == '') {
		reset_previouscost(pc);
		return;
	}
	
    ShowElem("PreviousCost");
    ShowElem("PreviousCostCustom");
    ShowElem("PreviousCostCustom2");

	pc.innerHTML = val;
}

function change_previouscost_col(productid,i) {
    //alert(productid + " " + i);
    var pc = getElementByID_Master("PreviousCostSpan_" + productid);
	//alert(uc);
	if (pc == null)
		return;
		
    //alert(eval("aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]"));
	if (eval("aSKUPreviousCost_" + productid + "[" + "g_color_" + productid + "]") == null) {
	    //alert('reset1');
		reset_previouscost_col(productid, pc);
		return;
	}
		
	var val = eval("aSKUPreviousCost_" + productid + "[" + "g_color_" + productid + "]" + "[" + "g_size_" + productid + "]");
	if (val == null || val == '') {
	    //alert(val + ' :reset2' + " aSKUUnitCost_" + productid + "[" + "g_color_" + productid + "]" + "[" + "g_size_" + productid + "]" + ' g_color: ' + eval("g_color_" + productid) + ' g_size: ' + eval("g_size_" + productid));
		reset_previouscost_col(productid, pc);
		return;
	}
	
	pc.innerHTML = val;
}


function zoom_show(width,height) {
//    alert('zoom_show');
    var rzg = getElementByID_Master("RealZoomGraphic");
    if (rzg != null)
        rzg.style.visibility = "visible";

    //alert(width + " " + height);
	zoom_zoomimagewid = width;
	zoom_zoomimagehei = height;
    
    Zoom_ReInitialize();
}

function zoom_hide() {
//    alert('zoom_hide');
    var rzt = getElementByID_Master("realZOOMBG");
    if (rzt != null)
        rzt.style.visibility = "hidden";

    var rzg = getElementByID_Master("RealZoomGraphic");
    if (rzg != null)
        rzg.style.visibility = "hidden";

	zoom_zoomimagewid = 0;
	zoom_zoomimagehei = 0;
    
    Zoom_DeInitialize();
}

function zoom_show_if_loaded(width,height) {
    if (width > 0)
        zoom_show(width,height);
}

function get_product_image() {
    var x = document.images['ProductImage'];
    if (x == null)
        x = document.images['ProductImage2'];
    if (x == null)
        x = document.images['ctl00_ContentPlaceHolder1_ProductImage'];
    if (x == null)
        x = document.images['ctl00_ContentPlaceHolder1_ProductImage2'];
        
    return x;
}

function change_zoom_realzoom(img, regpath, detailpath) {
    // Get the OnClick text from ProductImageHL
    var pih = getElementByID_Master("ProductImageHL");
    if (pih != null) {
        var f = pih.getAttribute('OnClick').toString();
        if (f.indexOf('anonymous') != -1) {
            f = f.substr(23, f.length - 24);
        }
        zoom_zoomclickfuncs += f;
    }

    zoom_mainimageurl = regpath + img;
    zoom_zoomimageurl = detailpath + img.replace(".jpg", "_z.jpg");

    //    alert(zoom_mainimageurl + " " + zoom_zoomimageurl);
    //    alert(loadzoom);

    //    var zmi = new Image();
    //    zmi.onerror = zoom_image_missing;
    //    zmi.src = zoom_mainimageurl;

    // Temporarily removed "Safari" Agent checker for testing - Richard 05-22-08

    /*
    if (navigator.userAgent.indexOf("Safari") != -1)
    {
    zoom_hide();
    var zzi = new Image();
    zzi.src = zoom_zoomimageurl;
    window.setTimeout("zoom_show_if_loaded(" + zzi.width + ", " + zzi.height + ")", 2000);
    }
    else
    {
    */
    var zzi = new Image();
    zzi.onerror = zoom_hide;
    zzi.onload = function() { zoom_show(zzi.width, zzi.height); };
    zzi.src = zoom_zoomimageurl;
    //   }
}

function change_zoom_magiczoom(img, regpath, detailpath) {
    // Get the OnClick text from ProductImageHL
    var pih = getElementByID_Master("ProductImageHL");
    if (pih == null)
        return;

	MagicZoom_stopZooms();
	pih.href = detailpath + img.replace(".jpg", "_z.jpg");
	setTimeout('MagicZoom_findZooms()', 100);
}

function change_zoom(img, regpath, detailpath) {
    //zoom_hide();
    var mir = getElementByID_Master("RealZoomH");
    if (mir != null) {
        change_zoom_realzoom(img, regpath, detailpath);
        return;
    }

    var mz = getElementByID_Master("MagicZoomHidden");
    if (mz != null) {
        change_zoom_magiczoom(img, regpath, detailpath);
        return;
    }
}

function set_color(i) { 
	g_color = i;
	try
	{
        get_product_image().src = "/store/productimages/regular/" + aColor[i];
	}
    catch (err)
	{
    }
	setElem("Message", "");
	if (g_size_priority == 0)
	    reload_sizes();
	change_upc();
	change_unitcost();
	change_previouscost();
	change_costspans();
	change_extragroup();
}

function change_color(i) {
    set_color(i);
	change_zoom(aColor[i], "/store/productimages/regular/", "/store/productimages/details/");

	try {
	    setElem("AddToCartMessage", "");
	    
	    if (g_isvproductid == 1)
	        change_vpid_elements(i - 1);
	}
	catch (err) { }
}

function change_vpid_elements(i) {
    var modelname = getElementByID_Master("ModelNameLB");
    var description = getElementByID_Master("ctl00_ContentPlaceHolder1_TD1_DescriptionLB");
    var mfgsku = getElementByID_Master("ctl00_ContentPlaceHolder1_MFGSKUL");
    var breadcrumb = getElementByID_Master("modelname");
   
    if (modelname != null)
        modelname.innerHTML = aModelName[i];

    if (description != null)
        description.innerHTML = aDescription[i];

    if (mfgsku != null)
        mfgsku.innerHTML = aMfgSku[i];

    if (breadcrumb != null)
        breadcrumb.innerHTML = aModelName[i];
}

function change_extrabutton(hyperlinkname, imgname, elementindex) {
//    alert(g_color + " " + hyperlinkname + " " + imgname + " " + elementindex);
    if (g_useextragroup_colors == 0)
        return;

    var e_img = getElementByID_Master(imgname);
	if (e_img == null)
	    return;

	var e_hl = getElementByID_Master(hyperlinkname);
	if (e_hl == null)
	    return;
	    
    try
    {
        if (aExtraGroupColors[g_color] == null || aExtraGroupColors[g_color][elementindex] == null) {
            e_hl.style.visibility = "hidden";
            e_img.src = '';
            return;
	    }
    	    
        e_hl.style.visibility = "visible";
        e_img.src = aExtraGroupColors[g_color][elementindex];
    }
    catch (err)
    {
    }
}

function change_extragroup() {
    change_extrabutton("ExtraMediaButton1", "ExtraMediaButton1_img", 1);
    change_extrabutton("ExtraMediaButton2", "ExtraMediaButton2_img", 2);
    change_extrabutton("ExtraMediaButton3", "ExtraMediaButton3_img", 3);
    change_extrabutton("ExtraMediaButton4", "ExtraMediaButton4_img", 4);
}

function change_size(i) {
	g_size = i;
	setElem("Message", "");
	if (g_size_priority == 1)
    	reload_colors();
	change_upc();
	change_unitcost();
	change_previouscost();
	change_costspans();

	try {
	    setElem("AddToCartMessage", "");
	}
	catch(err){}
}

function change_extra(i) {
	document.images['theimage'].src = aExtra[i];
}

function change_extra2(i) {
//    alert('change_extra2(' + i + ')');
    if (color_count > 1) {
        set_color(getElementByID_Master("ProductColors").selectedIndex);
    }
    try
    {
        get_product_image().src = aExtra[i];
    }
    catch (err)
    {
    }
	change_zoom(aExtra[i], "", "");
}

function change_extra3(i) {
    if (g_useextragroup_colors == 0)
        return;

    if (aExtraGroupColors[g_color] == null || aExtraGroupColors[g_color][i + 1] == null)
        return;

    var img = aExtraGroupColors[g_color][i + 1];
    img = img.replace("_t.jpg", ".jpg");
    try
    {
        get_product_image().src = img;
    }
    catch (err)
    {
    }
	change_zoom(img, "", "");
}

function Contains(s) {
    if (s.indexOf(s) >= 0) {
        return 1;
    }

    return 0;
}

function change_and_select_color(i, cid, qtycid) {
    if (Contains("ProductColors"))
    {
        var pc = getElementByID_Master("ProductColors");
        if (pc != null) {
            pc.selectedIndex = i;
        }
        change_color(i);
        window.status = '';
    }
    else
    { 
        try
        {
            getElementByID_Master(cid).selectedIndex = i;
            // 	if(getElementByID_Master(qtycid)!= null && getElementByID_Master(qtycid).value=='')
            //	    getElementByID_Master(qtycid).value = '1'; 
        }
        catch(err){}
    }
}

function set_selection(id, val) {
    getElementByID_Master(id).selectedIndex = val;
}

function show_color(i) {
    try
    {
	    get_product_image().src = "/store/productimages/regular/" + aColor[i];
	}
    catch (err)
	{
	}
}

function swatch_mouse_out(i) {
	window.status='';
	if (g_color != i)
		MM_swapImgRestore();
	show_color(g_color);
	window.status='';
}

function swatch_mouse_over(i,color_name,over_img_name) {
	window.status='';
	MM_swapImage(color_name,'',over_img_name,1);
	show_color(i);
	window.status=color_name;
} 

function swatch_click(i,color_name,img_name) {
	window.status='';
	MM_swapImage(g_swatch_name,'',g_swatch_img,1);
	change_and_select_color(i);
	g_swatch_name = color_name;
	g_swatch_img = img_name;
	window.status=color_name;
}

function size_swatch_click(i,size_name) {
	window.status='';
	set_selection("ProductSizes", i);
	set_size_swatch(i);
	change_size(i);
	window.status=size_name;
}

function set_size_swatch(i) {
	for (var i = 0; i < size_count; i++)
	{
	    var j = i + 1;
	    var sw = getElementByID_Master("SizeSwatch_" + j);
		if (sw == null)
			continue;

		if (g_size == j)
		    sw.className = "sizebox active";
		else
    		sw.className = "sizebox a";
	}
}

function NoChangeAll(nochangename, updatename)
{
	var ml = document.forms[0];
	var len = ml.elements.length;

	for (var i = 0; i < len; i++) {
		var e = ml.elements[i];
		if (e.value == nochangename) {
			e.checked = true;
		}
		if (e.value == updatename) {
			e.checked = false;
		}
	}
}

function UpdateAll(nochangename, updatename)
{
	var ml = document.forms[0];
	var len = ml.elements.length;

	for (var i = 0; i < len; i++) {
		var e = ml.elements[i];
		if (e.value == nochangename) {
			e.checked = false;
		}
		if (e.value == updatename) {
			e.checked = true;
		}
	}
}

function DefaultButton(btnID, event){
    btn = getElementByID_Master(btnID);
	if (document.all) {
		if (event.keyCode == 13) {
			event.returnValue = false;
			event.cancelBubble = true;
			btn.click();
		}
	}
	else if (document.getElementById) {
		if (event.which == 13) {
			event.returnValue = false;
			event.cancelBubble = true;
			btn.click();
			btn.focus();
		}
	}
	else if(document.layers) {
		if (event.which == 13) {
			event.returnValue = false;
			event.cancelBubble = true;
			btn.focus();
			btn.click();
		}
	}
}

function findObj(n, d) {
	var p,i,x;
	
	if(!d)
		d=document;
	
	if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}   
	
	if(!(x=d[n])&&d.all)
		x=d.all[n];
		
	for (i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
		
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=findObj(n,d.layers[i].document);
		
	if(!x && d.getElementById)
		x=d.getElementById(n);
	
	return x;
}

function change_img(imgid, img) {
    var i = getElementByID_Master(imgid);
    if (i == null)
        return;

	i.src = eval(img + ".src");
}

function change_master_img(img) {
	change_img("master_img", img);
}

function change_master_text(txt) {
    var i = getElementByID_Master("master_text");
    if (i == null)
        return;

	i.innerHTML = txt;
}

function change_master_text2(txt, txtid) {
    var i = getElementByID_Master(txtid);
    if (i == null)
        return;

    i.innerHTML = txt;
}

function change_master_link(link) {
    var i = getElementByID_Master("master_link");
    if (i == null)
        return;

    i.href = link;
}

function change_master_link2(link, linkid) {
    var i = getElementByID_Master(linkid);
    if (i == null)
        return;

    i.href = link;
}

function change_master_price(txt) {
    var i = getElementByID_Master("master_price");
    if (i == null)
        return;
	
	i.innerHTML = txt;
}

function change_master_price2(txt, txtid) {
    var i = getElementByID_Master(txtid);
    if (i == null)
        return;

    i.innerHTML = txt;
}

function change_master_mfgsku(txt) {
    var i = getElementByID_Master("master_mfgsku");
    if (i == null)
        return;
	
	i.innerHTML = txt;
}

function change_master_morecolors(txt) {
    var i = getElementByID_Master("master_colors");
    if (i == null)
        return; 
        
    i.innerHTML = txt;
}

function change_master_new(txt) {
   var i = getElementByID_Master("master_newtxt");    
    if (i == null)
        return;              
      
     i.innerHTML = txt;    
 }

function lightup(imageobject, opacity) {
    var obj = getElementByID_Master(imageobject);

    if (navigator.userAgent.indexOf("Safari")!=-1)
		obj.style.opacity = opacity/100;
    else if ((navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)>=5))
		obj.style.MozOpacity = opacity/100;
    else if ((navigator.appName.indexOf("Microsoft")!=-1 && parseInt(navigator.appVersion)>=4))
		obj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ");";
}

function set_master_img(img) {
    var i = getElementByID_Master("master_img");
    if (i == null)
        return;

	i.src = img;
}

function outfit_left() {
	g_outfitindex--;
	if (g_outfitindex <= 0)
		g_outfitindex = g_numoutfits - 1;

	reload_outfits(g_outfitindex);
}

function outfit_right() {
	g_outfitindex++;
	if (g_outfitindex == g_numoutfits)
		g_outfitindex = 1;

	reload_outfits(g_outfitindex);
}

function reload_outfits(current_outfit) {
	var outfit_changer = current_outfit;

	for (var i = 1; i <= g_maxdisplaythumbscollection; i++) {
	    var img = getElementByID_Master("OutfitThumbRPT_ctl" + zeropad(i) + "_OutfitNavImage");
	    var imghl = getElementByID_Master("OutfitThumbRPT_ctl" + zeropad(i) + "_OutfitNavImageHL");
		if (img != null)
    		img.src = "/store/productimages/thumbs/" + aOutfitThumb[outfit_changer];
    		
        if (imghl != null)
		    imghl.href = aOutfitThumbHL[outfit_changer];

		outfit_changer++;
		if (outfit_changer == g_numoutfits)
			outfit_changer = 0;
	}
}

function change_color_col_img(imgctlname,productid,i) {
    var img = getElementByID_Master(imgctlname);
	if (img == null)
	    return;

	var imgpath = "/store/productimages/regular/" + eval("aColors_" + productid + "[i]");
	img.src = imgpath;
}

function change_color_col(imgctlname,productid,i) {
    this["g_color_" + productid] = i;
    
    change_color_col_img(imgctlname,productid,i);
	change_unitcost_col(productid,i);
	change_previouscost_col(productid,i);
}

function change_size_col(productid,i, qtycid, sizecid) {
//    alert(eval("g_color_" + productid));

    this["g_size_" + productid] = i;
 
	change_unitcost_col(productid,i);
	change_previouscost_col(productid,i);

	if (getElementByID_Master(qtycid) != null && getElementByID_Master(qtycid).value == '')
	    getElementByID_Master(qtycid).value = '1';

	var ps = getElementByID_Master(sizecid);
	
	if (ps == null)
		return;
				
	var curr_value = ps.options[ps.selectedIndex].value;  
	 
	if(curr_value == '-1')
	    getElementByID_Master(qtycid).value = '';  	 
} 

function GetQueryStringVar( name )
{
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var tmpURL = window.location.href;
	var results = regex.exec( tmpURL );
	if( results == null )
		return "";
	else
		return results[1];
}

function toggle_RPTFullDivItem(i) {
    var div = getElementByID_Master("ProductRPTFull_ctl" + zeropad(i) + "_RPTFullDiv");
	if (div.style.visibility == "hidden")
		div.style.visibility = "visible";
	else
		div.style.visibility = "hidden";
}

function unset_checkbox(i,j) {
    var rb_ip = getElementByID_Master("ProductRPTFull_ctl" + zeropad(i) + "_PM1_PetiteRB");
    var rb_jp = getElementByID_Master("ProductRPTFull_ctl" + zeropad(j) + "_PM1_PetiteRB");
	
	if (rb_ip.checked == true)
	{
		rb_jp.checked = true;
	}
	else
	{
		rb_jp.checked = false;
	}

	var rb_im = getElementByID_Master("ProductRPTFull_ctl" + zeropad(i) + "_PM1_MissyRB");
	var rb_jm = getElementByID_Master("ProductRPTFull_ctl" + zeropad(j) + "_PM1_MissyRB");

	if (rb_im.checked == true)
	{
		rb_jm.checked = true;
	}
	else
	{
		rb_jm.checked = false;
	}
}

function toggle_RPTFullDiv(rb,i,j) {
	unset_checkbox(i,j);
	
	toggle_RPTFullDivItem(i);
	toggle_RPTFullDivItem(j);
		
	return false;
}

function get_DIVVisibilityStates() {
	var s = "";

	for (var i = 0; i < 10; i++)
	{
	    var div = getElementByID_Master("ProductRPTFull_ctl" + zeropad(i) + "_RPTFullDiv");
		if (div == null)
			continue;
			
		if (div.style.visibility == "hidden")
			s += "h";
		else
			s += "v";
	}
	
	return s;
}


function AttributePoster() {
	var a = "";

	var ProductSizesV = getElementByID_Master("ProductSizesV");
    if(ProductSizesV!= null)
        ValidatorEnable(ProductSizesV, false);
    var ProductColorsV = getElementByID_Master("ProductColorsV");
    if(ProductColorsV!= null)
        ValidatorEnable(ProductColorsV, false);  

	// Get the selected values from the nav and send to the productslist page
	for (var i=0; i < aAttributes.length; i++)
	{
	    var c = getElementByID_Master(aAttributes[i]);
		if (c == null)
			continue;
			
		a += c.value;

		if (i + 1 < aAttributes.length)
			a += ",";
	}

	var vals = "";

	if (a.length > 0)
		vals += "&a=" + a;

	// See if there's a size option
    var s = getElementByID_Master(AttributeSizeNameDDL.id);
	if (s != null && s.length > 0)
		vals += "&sn=" + s.value;
	
	location.href = "/store/productslist.aspx?categoryid=" + AttributeSearchCategoryID + vals;
}

// function change image
function chgimg(imgfield,newimg) {
	if (document.images) {
		document[imgfield].src = eval(newimg + ".src")
	}
}

function openWin(url, name, height, width) {
	remote = window.open(url,name,'height=' + height + ',width=' + width + ',titlebar=0,channelmode=0,screenX=10,left=10,screenY=10,top=10,hotkeys=0,dependent=1,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0');
	remote.focus();
	if (remote.opener == null) remote.opener = window;
	// remote.opener.name = 'opener';
}

function openbranchby_branchnamevar()
{
	if (typeof(branchname) != 'undefined') {
		openBranchByName(branchname);
	}
}

function doSort(val) 
{   
    filterorsort("sort",val);
}

function doSizeFilter(val) 
{    
    filterorsort("sizef",val);
}

function doColorFilter(val) 
{    
    filterorsort("colorf",val);
}

function doFitFilter(val) 
{    
    filterorsort("fitf",val);
}

function doRiseFilter(val) 
{    
    filterorsort("risef",val);
}

function doWashFilter(val) 
{
    filterorsort("washf",val);     
}

function doSupportFilter(val) {
    filterorsort("supportf", val);
}

function doSportFilter(val) {
    filterorsort("sportf", val);
}

function doPriceFilter(min,max)
{
    filterorsort2("minf",min,"maxf",max);
}


function addsingleparam(param, value, searchstring, categoryid, parentcolorid)
{
    var newsearchstring = "";

    if (searchstring == "" && parentcolorid == "")
        newsearchstring = "?categoryid=" + categoryid + "&" + param + "=" + (gup(param)==""? value :gup(param));
    else if (searchstring == "" && parentcolorid != "")
        newsearchstring = "?categoryid=" + categoryid + "&" + param + "=" + (gup(param) == "" ? value : gup(param)) + "&parentcolorid=" + parentcolorid;    
    else
        newsearchstring = searchstring.replace("&" + param + "=" + gup(param),"") + "&" + param + "=" + (gup(param)==""? value : gup(param).replace(gup(param), value));

    if (value == "")
        newsearchstring = newsearchstring.replace("&" + param + "=", "")
        
    return newsearchstring;
}

function addparam(param, value, base, searchstring, categoryid, parentcolorid)
{
    var baseurl = "";
    var newsearchstring = addsingleparam(param, value, searchstring, categoryid, parentcolorid);
   
    baseurl = base + newsearchstring;
        
    return baseurl;
}

function filterorsort(ctrlname, ctrlvalue)
{
    var categoryid = getElementByID_Master("categoryidhidden").value;
    var parentcolorid = 0;
    try
    {
       parentcolorid = getElementByID_Master("parentcoloridhidden").value;
    }
    catch (err) { } 
    
    var page = window.location.href;
    var base = "";
    
    if (page.indexOf("productslist2") > 0) {
        base = "/store/productslist2.aspx";
    } else if (page.indexOf("productslist3") > 0) {
        base = "/store/productslist2.aspx";
    } else if (page.indexOf("productslist4") > 0) {
        base = "/store/productslist4.aspx";
    } else {
        base = "/store/productslist.aspx";
    }           
    var searchstring = window.location.search;
    var baseurl = addparam(ctrlname, ctrlvalue, base, searchstring, categoryid, parentcolorid);
        
    window.location.href = baseurl;
}

function filterorsort2(ctrlname, ctrlvalue, ctrlname2, ctrlvalue2)
{
    var categoryid = getElementByID_Master("categoryidhidden").value;
    var base = "/store/productslist.aspx";       
    var searchstring = window.location.search;
    var newsearchstring = addsingleparam(ctrlname, ctrlvalue, searchstring, categoryid);
    var baseurl = addparam(ctrlname2, ctrlvalue2, base, newsearchstring, categoryid);
        
    window.location.href = baseurl;
}

function gup(name)
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
    var regexS = "[\\?&]"+name+"=([^&#]*)";  
    var regex = new RegExp( regexS );  
    var results = regex.exec( window.location.href );  
    if( results == null )
        return "";  
    else    
        return results[1];
}

function popup_productemailsignup(w) {
	var pw;
	pw = window.open(w,'ProductEmailSignup','height=508,width=541,toolbar=no,resizable=yes,scrollbars=yes');
	pw.focus();
}

function autoclose_popup(timebeforeclosing)
{
    closeMe(timebeforeclosing)
}

function closeMe(timebeforeclosing)
{
    t = null;
    t = setTimeout("self.close()",timebeforeclosing);
}

function OutfitListPageLoad()
{
    var firstthumb = findObj("OutfitImagesDL_ctl00_OutfitNavImage");
    if (firstthumb == null)
        return;

    var oc = firstthumb.getAttribute("onmouseover");
    if (oc == null)
        return;

//    alert(oc);
        
    var ocs = oc.toString();
        
    if (ocs.indexOf('anonymous') != -1) {
        ocs = ocs.substr(23, ocs.length-24);
    }
        
//    alert(ocs);

    eval(ocs);	    
}


function ProductsListPageLoad()
{
    var firstthumb = getElementByID_Master("MyList_ctl00_ThumbnailImage");
    if (firstthumb == null)
        return;

    var oc = firstthumb.getAttribute("onmouseover");
    if (oc == null)
        return;

//    alert(oc);
        
    var ocs = oc.toString();
        
    if (ocs.indexOf('anonymous') != -1) {
        ocs = ocs.substr(23, ocs.length-24);
    }
        
//    alert(ocs);

    eval(ocs);	    
}

//Start PopOver Swatches
function os_moveemnt(id, x, y){
  if (document.getElementById){
      getElementByID_Master(id).style.left = x + 'px';
      getElementByID_Master(id).style.top = y + 'px';
  }
}
function os_showemnt(id){
    if (document.getElementById){
        if (getElementByID_Master(id)) {
            getElementByID_Master(id).style.visibility = 'visible';
        }
    }
}
function os_hideemnt(id){
    if (document.getElementById){
        if (getElementByID_Master(id)) {
            getElementByID_Master(id).style.visibility = 'hidden';
        }
    }
}
function swhtml(id, html){
    if (document.getElementById){
        if (getElementByID_Master(id)) {
            getElementByID_Master(id).innerHTML = html;
        }
    }
}
function os_swmvswh(index, swatchDiv, colorDesc, img){
    os_strcont = getElementByID_Master("os_swcntr" + index);
    os_strbcont = getElementByID_Master("container");
	os_strconttop = os_strcont.offsetTop + os_strbcont.offsetTop;
	os_strcontleft = os_strcont.offsetLeft + os_strbcont.offsetLeft;
	os_strscontwidth = os_strcont.offsetWidth;
	os_strcontright = os_strcontleft+os_strscontwidth;

	os_strbox = getElementByID_Master("os_swbox");
	os_strboxtop = os_strbox.offsetTop;
	os_strboxleft  = os_strbox.offsetLeft;
	os_strboxwidth = os_strbox.offsetWidth;
	os_strsboxheight = os_strbox.offsetHeight;
	
	os_strboxnewleft = os_strcontleft + (swatchDiv.offsetLeft + (swatchDiv.offsetWidth / 2) ) - (os_strboxwidth/2)
	os_strboxnewright = os_strboxnewleft + (os_strboxwidth)

	if ((os_strboxnewleft) < (os_strcontleft)) {
		sbPosLeft=os_strcontleft;
	} else if ((os_strboxnewright) > (os_strcontright )){
		sbPosLeft=os_strcontright - os_strboxwidth -4;
	} else {
		sbPosLeft=os_strboxnewleft;
	}
	imgTag='<img src="' + img + '">';
	imgURL='' + img;
	os_showsw(index);
	var IfrRef = getElementByID_Master('dvsh');
	IfrRef.style.width = os_strbox.offsetWidth;
    IfrRef.style.height = os_strbox.offsetHeight;
    IfrRef.style.top = os_strbox.style.top;
    IfrRef.style.left = os_strbox.style.left;
    IfrRef.style.zIndex = 999;

	os_moveemnt('dvsh', sbPosLeft, os_strconttop-os_strsboxheight-1);
	os_moveemnt('os_swbox', sbPosLeft, os_strconttop-os_strsboxheight-1);
	swhtml('os_swboxclrdsc', colorDesc);
	 
	swhtml('os_swboximg', imgTag);
}

dispSwatch=false;
function os_swhdswh(index){
	dispSwatch=false;
	setTimeout('os_dohideswatch()',100);
}
function os_dohideswatch(index){
	if(!dispSwatch){
	    var IfrRef = getElementByID_Master('dvsh');
		IfrRef.style.display = "none";
		os_hideemnt('os_swbox');
	}
}
function os_showsw(index){
	dispSwatch=true;
	var IfrRef = getElementByID_Master('dvsh');
	IfrRef.style.display = "block";
	os_showemnt('os_swbox');
}
 
{
	document.write("<div class=\"os_swbox\" id=\"os_swbox\">");
	document.write(	"<div class=\"os_swboximg\" id=\"os_swboximg\"></div>");
	document.write(	"<div class=\"os_swboxtxt\">");
	document.write(		"<div class=\"os_swboxclrdsc\" id=\"os_swboxclrdsc\"></div>");
	document.write(		"<div class=\"os_swboxacn\" id=\"os_swboxacn\"></div>");
	document.write(	"</div>");
	document.write("</div>");
	document.write("<div class=\"dvsh\" id=\"dvsh\" src=\"javascript:false;\" scrolling=\"no\" style=\"position:absolute; top:0px; left:0px; display:none;\"></div>");	 
}
//End PopOver Swatches

//PopupHover - Collections Page

function getObj(objectId) {
    if (document.getElementById && getElementByID_Master(objectId)) {
        return getElementByID_Master(objectId).style;
    } else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {	 
	return document.layers[objectId];
    } else {
	return false;
    }
} 

function objvisibilityStatus(objectId, newVisibility) {
    // make sure the object exists
    var styleObject = getObj(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// if we cant find the object change visibility
	return false;
    }
}  

function verifyPosition(objectId, x, y) {
    // check if object exists
    var styleObject = getObj(objectId);
    if(styleObject) {
	styleObject.left = x;
	styleObject.top = y;
	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
}  

// Variables used to determine where the popup opens
var xOffset = 40;
var yOffset = -5;

function openPopup (newObjID, eventObj) {
    if(eventObj) {
	hidePopup();
	eventObj.cancelBubble = true;
	var x = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
	var y = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
	verifyPosition(newObjID, x, y);
	// and make it visible
	if( objvisibilityStatus(newObjID, 'visible') ) {
	    // globally-accessible object
	    window.currentlyVisiblePopup = newObjID;
	    return true;
	    } else {
	        // popup couldnt be found
	        return false;
	    }
            } else {
	    // no event found
	    return false;
    }
} 

function hidePopup() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.currentlyVisiblePopup) {
	objvisibilityStatus(window.currentlyVisiblePopup, 'hidden');
	window.currentlyVisiblePopup = false;
    }
}  
 
// initialize workarounds whenever the page loads
window.onload = initFixes;

// Hide popup if doc is clicked
document.onclick = hidePopup;

function initFixes() { 
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getObj('blankDiv')) {}      
} 
 

// End PopupHover - Collections Page


//Start Swatches with Selection Enabled


function DisplayDefault(id, DefaultSwatchText, tableName, strlblSwatch)
{
    var swatchlabel = getElementByID_Master(strlblSwatch);
	swatchlabel.innerHTML= DefaultSwatchText;
}

function DisplayText(id, SwatchText, currTDValue, tableName, strlblSwatch)
{   
    var strSwatchText = SwatchText;
    var swatchlabel = getElementByID_Master(strlblSwatch);
    swatchlabel.innerHTML= SwatchText;
    toggleImgColor(id, currTDValue, tableName)
}

function toggleImgColor(id, currentTD, tableName)
{		
	var tdTag;
	tdTag = getElementByID_Master(tableName).getElementsByTagName('td');
	 
	for (var counter = 0; counter < tdTag.length; counter++) 
	{  
		var imgTag= tdTag[counter].getElementsByTagName('img');
		
		if (imgTag != null)
		{			
			var imgClass = imgTag.item(0).className;
			 
			if (imgClass == 'SelectedImage')
			{
				imgTag.item(0).className = '';
			}
		}
	} 
	if(currentTD == null)
	    imgTag.item(0).className = '';	
	else
	    currentTD.className = 'SelectedImage';
}
   
function SetImgColor(cid, id, currentTD, tableName, DefaultSwatchText, strlblSwatch)
{
    var swatchlabel = getElementByID_Master(strlblSwatch);
	swatchlabel.innerHTML= 'Selected Color: ' + DefaultSwatchText;
    
    var tdTag;
    tdTag = getElementByID_Master(tableName).getElementsByTagName('td');
	
	for (var counter = 0; counter < tdTag.length; counter++) 
	{  
		var imgTag= tdTag[counter].getElementsByTagName('img');
		
		if (imgTag != null)
		{			
			var imgClass = imgTag.item(0).className;
			 
			if (imgClass == 'SelectedImage')
			{
				imgTag.item(0).className = '';
			}
		}
	} 
	currentTD.className = 'SelectedImage';	
    
    try
    {
        getElementByID_Master(cid).selectedIndex = id + 1; 
 	}
 	catch(err){} 
} 

// End Swatches with Selection Enabled

function SwapS7Image(VignetteName, ProductID, Scene7RenderServer, ImageID, ProductColor, ImageIndex, CurrTD, tableName, FabricName , strlblSwatch, Scene7VignetteWidth, Scene7VignetteSharpness, Scene7VignetteResolution, SKUPrice)
{
try{
    var swatchlabel = getElementByID_Master(strlblSwatch);
 swatchlabel.innerHTML= 'Now Showing: ' + FabricName + " | Price: " + SKUPrice;
}
catch(err){}	
try{
    getElementByID_Master("MainProductImage").src = Scene7RenderServer + ProductID + '?wid=' + Scene7VignetteWidth + '&obj=body&src=' + VignetteName + '&res=' + Scene7VignetteResolution + '&sharpen=' + Scene7VignetteSharpness + '&cache=off';
}
catch(err){}
try{
    for (var s = 0; s <= getElementByID_Master("ProductSizes").length; s = s + 1)
    {
        var ddl1value = getElementByID_Master("ProductSizes").options[s].value;   

        if(ddl1value==ImageID)
        {
            getElementByID_Master("ProductSizes").selectedIndex = s;
            break;
        }
    }

    for (var i = 0; i <= getElementByID_Master("ProductColors").length; i = i + 1)
    {
        var ddlvalue = getElementByID_Master("ProductColors").options[i].value;   

        if(ddlvalue==ProductColor)
        {
            getElementByID_Master("ProductColors").selectedIndex = i;
            break;
        }
    } 
}
catch(err){}
}

function swatch_swap_mouse_over(ImagePath, ImageID, SwatchCount, SwatchID, ThumbImageID, NavUrl) {
    getElementByID_Master(ImageID).src = ImagePath;
    UnSelectAllSwatches_Iterator(SwatchID);
    getElementByID_Master(SwatchID + "_" + SwatchCount).className = "main-prod-swatch-selected";

    getElementByID_Master(ThumbImageID).href = NavUrl;

    if (ImagePath != null)
        swap_previewimage(ImagePath);
}

function swatch_swap_mouse_out(ImagePath, ImageID, SwatchCount, SwatchID, ThumbImageID, NavUrl) {

    UnSelectAllSwatches_Iterator(SwatchID);
    getElementByID_Master(ImageID).src = ImagePath;
    getElementByID_Master(SwatchID + "_" + SwatchCount).className = "main-prod-swatch-selected";

    getElementByID_Master(ThumbImageID).href = NavUrl;

    if (ImagePath != null)
        swap_previewimage(ImagePath);
}

function isNumeric(value) {
    if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
    return true;
}

function swatch_swap_click(ImagePath, ImageID, SwatchCount, SwatchID, ThumbImageID, NavUrl) {

    if (isNumeric(ImageID)) {
        getElementByID_Master(ImageID.toString()).src = ImagePath;
    }
    else
        getElementByID_Master(ImageID).src = ImagePath;
        
    UnSelectAllSwatches_Iterator(SwatchID);
    getElementByID_Master(SwatchID + "_" + SwatchCount).className = "main-prod-swatch-selected";

    getElementByID_Master(ThumbImageID).href = NavUrl;

    if (ImagePath!= null)
        swap_previewimage(ImagePath);
}

function swap_previewimage(ImagePath) {
    var s = ImagePath;
    var previewimage = getElementByID_Master('main');
    var path = s.replace("thumbs", "regular").replace("_thumb.jpg",".jpg");

    if (previewimage!= null)
        previewimage.src = path;
}

function UnSelectAllSwatches_Iterator(elementId) { 
    var i = 0;
    while (!isNull(getElementByID_Master(elementId+"_"+i))) {       
        var elem = getElementByID_Master(elementId+"_"+i)
       if (elem.className == "main-prod-swatch-selected") {
           elem.className = "main-prod-swatch-unselected";
       }
       i++;
   }
}

function isNull(elem) {
    if (elem == null) return true;
    return false;
}

function OnRequestStart(ajaxPanel, eventArgs)
{   
   if (navigator.userAgent.indexOf("Firefox")!=-1)
   {
        DisableControls();
   }
}

function OnResponseEnd(ajaxPanel, eventArgs) {
   if (navigator.userAgent.indexOf("Firefox")!=-1)
   {
        EnableControls();
   }
    try {
        var CartItems;
        var CartTotal;
        var CartItemsHidden;
        var CartTotalHidden;
        
        CartItems = getElementByID_Master("Top1_ShoppingBag1_CartItemsLB");
        CartTotal = getElementByID_Master("Top1_ShoppingBag1_CartTotalLB");
        CartItemsCount = getElementByID_Master("ctl00_ShoppingBag1_CartItemsCount");
        CartItemsHidden = getElementByID_Master("CartItemsHidden");
        CartTotalHidden = getElementByID_Master("CartTotalHidden");
        CartItemsTopNav = getElementByID_Master("ctl00_TopNav1_ShoppingBag1_CartItemsLB");
        CartTotalTopNav = getElementByID_Master("ctl00_TopNav1_ShoppingBag1_CartTotalLB");
        CartItemsCountTopNav = getElementByID_Master("ctl00_TopNav1_ShoppingBag1_CartItemsCount");

        //CartItems can remain null for clients like PAIG/SEVN/BTSY whose Top1 is null (line 1842)
        //consequently, bag value gets updated but bag item count does not
        //therefore, we would only want to re-init CartItems IF IT REMAINS NULL so I am changing line 1854 from != to ==
        if (CartItems == null) {
            if (CartItemsTopNav != null)
                CartItems = getElementByID_Master("ctl00_TopNav1_ShoppingBag1_CartItemsLB");
            else
                CartItems = getElementByID_Master("ctl00_ShoppingBag1_CartItemsLB");
        }

        if (CartTotalTopNav != null)
            CartTotal = getElementByID_Master("ctl00_TopNav1_ShoppingBag1_CartTotalLB");
        else
            CartTotal = getElementByID_Master("ctl00_ShoppingBag1_CartTotalLB");

        if (CartTotal != null)
            CartTotal.innerHTML = CartTotalHidden.value;

        if (CartItemsCount != null)
            CartItemsCount.innerHTML = CartItemsHidden.value;
        
        if (CartItemsCountTopNav != null)
            CartItemsCountTopNav.innerHTML = CartItemsHidden.value;

        if (CartItemsHidden.value == "1") {
            if (CartItems != null)
                CartItems.innerHTML = CartItemsHidden.value + " Item";
        }
        else {
            if (CartItems != null)
                CartItems.innerHTML = CartItemsHidden.value + " Items";
        }
    }
    catch(err){}
}
function UpdateContinueShoppingLink() {
    try {
        var continueShippingLink = getFirstElementByClassName("jsHlContinueshopping");
        if (continueShippingLink != null) {
            var hiddenField = getFirstElementByClassName("jsHdnContinueShoppingLink");
            if (hiddenField != null) {
                continueShippingLink.href = hiddenField.value;                
            }
        }
    }
    catch (err) { }
}
function DisableControls()
{ 
   for (var i=0; i<document.forms[0].elements.length; i++)
    {            
        var obj = document.forms[0].elements[i]; 
        
        if(document.forms[0].elements[i].name == "__VIEWSTATE")
            obj.disabled = true;
    }   
}

function EnableControls()
{
    for (var i=0; i<document.forms[0].elements.length; i++)
    {        
        var obj = document.forms[0].elements[i];
        obj.disabled = false;
    }
} 

function addToFavorites(url,title) {
    var ua = navigator.userAgent.toLowerCase();
    var isSafari = ua.indexOf('webkit') != -1;
    var isMac = ua.indexOf('mac') != -1;
    var buttonStr = isMac ? 'Command/Cmd' : 'CTRL';

    if (window.sidebar) // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url,"")
    else if (window.external) // IE Favorite
        window.external.AddFavorite(url, title)
    else if (isSafari) // Safari
        alert('You need to press '+buttonStr+' + D to bookmark this page.');
    else // Others
        alert("Your browser doesn't support this function."); 
}

function ToggleCheck(me, group) { 
    var checked = me.checked;
    if (checked) for (var i = 1; i < arguments.length; i++) {
        var ck = document.getElementById(arguments[i]);
        if (ck) ck.checked = false;
    }
    me.checked = checked;
}

function TrimString(inputString) {    
    if (typeof inputString != "string") { return inputString; }
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    while (ch == " ") {
        retValue = retValue.substring(1, retValue.length);
        ch = retValue.substring(0, 1);
    }
    ch = retValue.substring(retValue.length - 1, retValue.length);
    while (ch == " ") {
        retValue = retValue.substring(0, retValue.length - 1);
        ch = retValue.substring(retValue.length - 1, retValue.length);
    }
    while (retValue.indexOf("  ") != -1) {
        retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
    }
    return retValue;  
}  
 
function SearchBarSetQuery(searchfield, storeUrl, btnId, searchfieldid) {
    if (false == ValidateSearch(searchfieldid)) {
        return false;
    }
    searchfield = trim(searchfield.toLowerCase());
   
    if (false == ValidateSearch(searchfieldid)) {
        return false;
    }    
    else { 
        document.MM_returnValue = false;
        window.location.href = storeUrl + CallEncode(searchfield);
    }
}

function CallEncode(text) {
    var encoded = encodeURIComponent(text);
    return encoded;
}

function ValidateSearch(textBoxId) {
    var textBox = document.getElementById(textBoxId);
    if (TrimString(textBox.value).length == 0) {
        alert('Please specify a search criteria');
        return false;
    }
    // Check for invalid characters, specifically, "<" and ">".
    if (TrimString(textBox.value).indexOf('<') > -1 || TrimString(textBox.value).indexOf('>') > -1) {
        alert('We\'re sorry, the search value entered is invalid. Please try again.');
        return false;
    }
    return true;
}
//*************Search Functions used on TRUE*************//

function SingleSelectCheckBox(regex, current) {
    re = new RegExp(regex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox') {

            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
}

function render_cart_header(items, total) {
    var xmlhttp = false;
    /*@cc_on@*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    @end@*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && window.createRequest) {
        try {
            xmlhttp = window.createRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }

    try {
        if (document.domain) {
            xmlhttp.open("GET", "http://" + document.domain + "/store/os/shoppingcartcost.aspx", false);
            xmlhttp.send("");
            var str = xmlhttp.responseText;
            var ary = str.split("|");
            if (ary.length > 1) {
                getElementByID_Master(total).innerHTML = ary[0];
                getElementByID_Master(items).innerHTML = ary[1];
            }
        }
    }
    catch (e) { }
}

function addEvent(obj, evType, fn, useCapture) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, useCapture);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    }
}

function addEventToElement(element, evenType, functionToRun) {
    if (element.addEventListener) {
        element.addEventListener(evenType, functionToRun, false);
        EventCache.add(element, evenType, functionToRun);
    }
    else if (element.attachEvent) {
        element["e" + evenType + functionToRun] = functionToRun;
        element[evenType + functionToRun] = function() { element["e" + evenType + functionToRun](window.event); }
        element.attachEvent("on" + evenType, element[evenType + functionToRun]);
        EventCache.add(element, evenType, functionToRun);
    }
    else {
        element["on" + evenType] = element["e" + evenType + functionToRun];
    }
}

var EventCache = function() {
    var listEvents = [];
    return {
        listEvents: listEvents,
        add: function(node, sEventName, fHandler) {
            listEvents.push(arguments);
        },
        flush: function() {
            var i, item;
            for (i = listEvents.length - 1; i >= 0; i = i - 1) {
                item = listEvents[i];
                if (item[0].removeEventListener) {
                    item[0].removeEventListener(item[1], item[2], item[3]);
                };
                if (item[1].substring(0, 2) != "on") {
                    item[1] = "on" + item[1];
                };
                if (item[0].detachEvent) {
                    item[0].detachEvent(item[1], item[2]);
                };
                item[0][item[1]] = null;
            };
        }
    };
} ();

function setNumericValuesOnlyOnElements(elementsClassName) {
    var elements = getElementsByClassName(elementsClassName);
    if (elements != null) {
        var numberOfElements = elements.length;
        if (numberOfElements > 0) {
            var element;
            for (var i = 0; i < numberOfElements; i++) {
                setNumericValuesOnlyOnElement(elements[i]);
            }
        }
    }
}

function setNumericValuesOnlyOnElement(element) {
    if (element != null) {
        addEventToElement(element, "keyup",
                    function() { removeNoNumericValuesOnElement(element); });
    }
}

function removeNoNumericValuesOnElement(element) {
    if (element != null) {
        element.value = element.value.replace(/[^0-9]/g, "");
    }
}

function getFirstElementByClassName(className) {
    var elements = getElementsByClassName(className);
    if (elements != null) {
        if (elements.length > 0) {
            return elements[0];
        }
    }
    return null;
}
/* CHECKBOX START */
function createOneStopCheckBoxes() {
    var checkBoxes = getElementsByClassName("OneStopCheckBox");
    if (checkBoxes != null) {
        var numberOfCheckBoxes = checkBoxes.length;
        if (numberOfCheckBoxes > 0) {
            for (var i = 0; i < numberOfCheckBoxes; i++) {
                setOneStopCheckBox(checkBoxes[i]);                
            }
        }
    }
}
function setOneStopCheckBox(checkbox) {
    if (checkbox.type == "checkbox") {
        var oneStopSpan = createOneStopElementSpan();
        if (checkbox.checked == true) {
            addCls(oneStopSpan, "OneStopCheckBoxChecked");
        }
        oneStopSpan.onclick = function() { changeCheckBoxStatus(checkbox, oneStopSpan); };
        checkbox.parentNode.appendChild(oneStopSpan);
    }
}
function createOneStopElementSpan() {
    var span = document.createElement("span");
    span.className = "OneStopElementSpan";
    return span;
}
function changeCheckBoxStatus(checkbox, span) {
    if (checkbox.checked == true) {
        remCls(span, "OneStopCheckBoxChecked");
        checkbox.checked = false;
    }
    else {
        addCls(span, "OneStopCheckBoxChecked");
        checkbox.checked = true;
    }
    fireCheckBoxChangeEvent(checkbox);
}
function fireCheckBoxChangeEvent(element) {
    if (element.onchange) {
        var fireOnThis = element;
        if (document.createEvent) {
            var evObj = document.createEvent('HTMLEvents');
            evObj.initEvent('change', true, false);
            fireOnThis.dispatchEvent(evObj);
        } else if (document.createEventObject) {
            var evObj = document.createEventObject();
            fireOnThis.fireEvent('change', evObj);
        }
    }
}
/* CHECKBOX END */