function showShipToStoreLayer(path, isStoreSet) {
    $('html').animate({
        scrollTop: 0
    }, 800);

    var locatorParent = $('#storeLocatorLayer');
    locatorParent.fadeIn("fast");
    $.ajax({
        url:path,
        type:"GET",
        dataType:"HTML",
        success:function(data) {
            $('.storeLocatorFrameBackground', locatorParent).removeClass("showLoader");
            //these lines are needed to fix the background in IE6
            if ($.browser.msie && $.browser.version.substring(0, 1) == '6') {
                DD_belatedPNG.fix('#storeLocatorLayer');
                DD_belatedPNG.fix('#header #storeLocatorLayer');
            }
            $('.locatorFrame', locatorParent).html(data);
        }
    });
}

function initPageHeight() {
	var lch = $(".leftnav").height(); //lch - left column height
	var pbh = $(".page-body").height() - 50; //pbh = page body height
	var rch = $(".rightnav").height(); //rch = right column height

	if (lch > rch && lch > pbh){
		$(".page-body").css("height", lch + "px");
		$(".rightnav").css("height", lch + "px");
	} else if (rch > lch && rch > pbh){
		$(".page-body").css("height", rch + "px");
		$(".leftnav").css("height", rch + "px");
	} else if (pbh > rch && pbh > lch){
		$(".leftnav").css("height", pbh + "px");
		$(".rightnav").css("height", pbh + "px");
	}

	$(".fill-height").each(function() {
		var regex = new RegExp("\\D", "g");

   		$(this).height($(this).parent().height() -
   				( $(this).offset().top - $(this).parent().offset().top ) +
   				$(this).parent().css("border-top-width").replace(regex,"") * 1  +
   				( $(this).parent().css("padding-top").replace(regex,"")  * 1 +
   				  $(this).parent().css("padding-bottom").replace(regex,"")  * 1 ) -
   				( $(this).css("padding-top").replace(regex,"")  * 1   +
   				  $(this).css("padding-bottom").replace(regex,"")  * 1  ) -
   				( $(this).css("border-top-width").replace(regex,"")  * 1  +
   				  $(this).css("border-bottom-width").replace(regex,"")  * 1)
   		);
	  });

}

$(function(){
	$(".button").assignMouseEvents();
	initPageHeight();
});

function doSearchValidation (theForm) {
	var searchVal = theForm.keyword.value ;
	if (searchVal == "" || searchVal == searchInstructions) {
		alert(searchErrorText) ;
		return false ;
	}
	return true ;
}

function submitSearchForm(theForm) {
	   if(doSearchValidation (theForm)) theForm.submit();	
}
	
function doSearchFocus(component) {
    var searchVal = component.value;
    component.value = "";
}

function strTrim(s) {
    // Remove leading spaces and carriage returns
    while (s.substring(0,1) == ' ') {
        s = s.substring(1, s.length);
    }
    // Remove trailing spaces and carriage returns
    while (s.substring(s.length-1, s.length) == ' ') {
        s = s.substring(0, s.length-1);
    }
    return s;
}

function doSearchBlur(component) {
    var searchVal = component.value;
    if (strTrim(searchVal) == '') {
        component.value = searchInstructions;
    }
}

function doControlFocus(component,defaultMessage) {
    var controlVal = component.value;
    if (controlVal == defaultMessage) {
        component.value = "";
    }
}

function doControlBlur(component,defaultMessage) {
    var controlVal = component.value;
    if (strTrim(controlVal) == '') {
        component.value = defaultMessage;
    }
}

/*
 * This function launches a new web browser window to a specified width, height and features.
 * Features string is a comma separated window's feature needed for this new window. For Instance
 * If a new window needs a toolbar the feature string must be "toolbar" like needs scroll bar and
 * and toolbar then it must be "toolbar,scrollbar". Note that the order of the feature is not required.
 * Also it's case insensitive. Therefore, "scrollbar,toolbar" is identical to "Toolbar,ScrollBar".
 *
 * If the features string is ommitted then all the features are turned off. To turn all the features on
 * use the word "all" for features instead of specifying each feature.
 */

function openWindow(address, width, height,features)
{
	/* Find out what features need to be enable
	 *
   */
	if(features) {
		features = features.toLowerCase();
	}
	else {
		features = "";
	}
	var toolbar = (features == "all" ? 1 : 0);
	var menubar = (features == "all" ? 1 : 0);
	var location = (features == "all" ? 1 : 0);
	var directories = (features == "all" ? 1 : 0);
	var status = (features == "all" ? 1 : 0);
	var scrollbars = (features == "all" ? 1 : 0);
	var resizable = (features == "all" ? 1 : 0);


	if(features != "all")
	{
		//split features
		var feature = features.split(",");
		for(i = 0; i < feature.length; i++)
		{
		 	if(feature[i] == "toolbar")
			   toolbar = 1;
			else if(feature[i] == "menubar")
			   menubar = 1;
			else if(feature[i] == "location")
			   location = 1;
			else if(feature[i] == "directories")
			   directories = 1;
			else if(feature[i] == "status")
			   status = 1;
			else if(feature[i] == "scrollbars")
			   scrollbars = 1;
			else if(feature[i] == "resizable")
			   resizable = 1;
		}

	}
	features = "toolbar=" + toolbar + ",";
	features += "menubar=" + menubar + ",";
	features += "location=" + location + ",";
	features += "directories=" + directories + ",";
	features += "status=" + status + ",";
	features += "scrollbars=" + scrollbars + ",";
	features += "resizable=" + resizable;

	/* position center */
	var left = (screen.width/2)-(width/2);
	var top = (screen.height/2)-(height/2);

	var newWindow = window.open(address, 'Popup_Window', 'top=' + top + ',left='+ left + ',width=' + width + ',height=' + height + ',"' + features + '"');
	newWindow.moveTo(left, top);
	newWindow.focus();
}

function trim(s)
{
	// Remove leading spaces and carriage returns
	while (s.substring(0,1) == ' '){
		s = s.substring(1,s.length);
	}
	// Remove trailing spaces and carriage returns
	while (s.substring(s.length-1,s.length) == ' '){
		s = s.substring(0,s.length-1);
	}
	return s;
}

/**
 * Check if the zip code is a US zip code 
 */
function isUnitedStateZipCode(s) {
	
	var reUSZip = new RegExp(/(^\d{5}$)|(^\d{5}(\-|\ )\d{4}$)/);

    if (!reUSZip.test(s)) {
         return false;
    }

    return true;
}

/**
 * Check if the zip code is a Canadian zip code 
 */
function isCanadianZipCode(s) {
	
	var reCanZip = new RegExp(/(^[a-zA-Z]\d{1}[a-zA-Z](\-|\ )\d{1}[a-zA-Z]\d{1}$)/);
	
    if (!reCanZip.test(s)) {
         return false;
    }

    return true;
}

/**
 * Check if the zip code is a FPO or APO zip code 
 */
function isFPOorAPOZipCode(s) {
	
	var reFPOorAPOZip = new RegExp(/(^[a-zA-Z]{3}(\-|\ )?[a-zA-Z]{2}(\-|\ )?\d{5}$)/);
	
    if (!reFPOorAPOZip.test(s)) {
         return false;
    }

    return true;
}
/**
 * Check if the zip code is a US or APO/FPO or Canadian zip code
 */
function isZipCode(s) {
	return isUnitedStateZipCode(s) || isFPOorAPOZipCode(s) || isCanadianZipCode(s);
}

function makeCurrent(elem){
	$(elem).css("background-color", "#ffffbb");
}
function makeNormal(elem){
	$(elem).css("background-color", "white");
}

$(function(){
	$("input[@type=text]").focus(function(){
		makeCurrent(this);
	});
	$("input[@type=text]").blur(function(){
		makeNormal(this);
	});
	$("input[@type=password]").focus(function(){
		makeCurrent(this);
	});
	$("input[@type=password]").blur(function(){
		makeNormal(this);
	});
	$("textarea").focus(function(){
		makeCurrent(this);
	});
	$("textarea").blur(function(){
		makeNormal(this);
	});
});

/*************************
	Footer Javascript
*************************/

function callEmailSignup() {
	var formAction = $("#subscribeForm").attr("action");
	$("#emailSignUp").html("Saving...").load(formAction, {"userEmail":$("#subscribeForm input[@name=userEmail]").val()});
}

/* change image name */
function changeImg(elem, oldname, newname) {
   // var src = $(elem).find('img').attr("src").match(/[^\.]+/) + "_on.jpg"; 
   var src = $(elem).find('img').attr("src").replace(oldname, newname);
   $(elem).find('img').attr("src", src);
}

$(function() {
	$("#subscribeForm input[@name=userEmail]").keydown(function(event) {
		if (event.keyCode == 13){
			callEmailSignup();
			return false;
		}
	});
	$("#subscribeForm input[@name=userEmailFooter]").keydown(function(event) {
		if (event.keyCode == 13){
			callCheetahPreferencesFromFooter();
			return false;
		}
	});
	

	$(".email-signup-contianer .signup-button").click(function(){
		callEmailSignup();
	});
	
	$(".email-signup-contianer .signup-button-cheetah").click(function(){
		callCheetahPreferencesFromFooter();
	});

      /* header: show/hide second level nav */
   $(".cat-level1").parent().hover(
     function(){
       changeImg(this, ".", "_on.");
       $(this).find('.cat-level2').css("display", "block"); // show level2
     },
     function(){
       changeImg(this, "_on.", ".");
       $(this).find('.cat-level2').css("display", "none");  // hide level2
     }
   );
    
    /* add rollover effect to him/her buttons */
   $(".him").hover(
     function(){
       changeImg(this, ".", "_on.");
     },
     function(){
       changeImg(this, "_on.", ".");
     }
   );

    $(".her").hover(
     function(){
       changeImg(this, ".", "_on.");
     },
     function(){
       changeImg(this, "_on.", ".");
     }
   );

   /* header: create columns of 10 categories in level2 */
$('.cat-level2').each(function(index) {
   var $bigList = $(this).find('ul'),
       group    = $bigList.find('li:lt(10)').remove();
   var bigListParent = $(this).find('ul').parent();

   var cl2width = $(this).width();
   var finalwidth = cl2width;

   while(group.length){
      $('<ul class="cl2-col" style="float:left;"></ul>').append(group).appendTo(bigListParent);
      group = $bigList.find('li:lt(10)').remove();

      lastulwidth = $(this).find('.cl2-col:last').width();
      finalwidth = finalwidth + lastulwidth;
   }

   if (finalwidth==cl2width){
   } else {
      finalwidth = finalwidth - cl2width;
      $(this).css("width",finalwidth);
   }

});

   /* header: for last cat-level2, make it wrap to left not right and have it align with right border of 1st nav */
   $('.cat-level2:last').each(function(index) {
           var parentwidth = $(this).parent().parent().outerWidth();
           var catlevel2width = $(this).outerWidth();
           var catlevel2margin = -(catlevel2width-parentwidth);
       if($.browser.msie && $.browser.version < 8){
	        if($.browser.version < 7) {
		        //ie 6
				  $(this).css("margin-left", catlevel2margin - 201);
	        } else {
		        //ie 7
		        $(this).css("margin-left", catlevel2margin - 2);
	        }
       }else{
           $(this).css("margin-left", catlevel2margin);
       }
   });
   
   /* header: store locator link: show / hide */
//   $('.store-loc-toggle').click(function() {
//      $('.common-header-store-locator-layer').toggleClass('show');
//   });

/**
 * This removes the dropdown completely if it has no li inside
 */
 if($.browser.msie && $.browser.version < 8){
    $('.cat-level2').each(function(index) {
         var mylisize = $(this).find('li').size();
         if(mylisize == 0){
            $(this).remove();
         }
         if(mylisize <= 10){
            $(this).css('width','220px');
         }
        if(mylisize > 10){
            $(this).css('width','400px');
         }

    });
}


});

/* ==========================================================================================================================*/
function replaceSubString(text, expression, value){  
    //replaceSubstring("hellothere","l","x") = "hexxothere"
   var expr = new RegExp(expression);
	return text.replace(expr,value);
}

function replaceEllipsis(elp) {
	return elp.replace("\u2026", "...");
}

function taLineCount(zHeight, zWidth, taId, key)
{

var isIE = false;
var isIE8orLess = false;
if($.browser.msie){
	isIE = true;
	if (parseInt(jQuery.browser.version) <= 8) {
		isIE8orLess = true;
	}
}
var sel = null;
var theField = "";

// this function is used both in personalization and on delivery page
// with some different logic for each environment
// the textarea id is messageText in the personalization path
var isDeliveryPage = false;

if (taId != undefined) {
	theField = document.getElementById(taId);
	if (taId != 'messageText'){
		isDeliveryPage = true;
	}
} else {
	theField = document.getElementById("messageText");
}
var m_Selection = new Selection(theField); //// Added to keep caret in correct location
var zoneHeight= parseInt(zHeight);
var zoneWidth= parseInt(zWidth);
var maxChars = (zoneWidth * zoneHeight) + zoneHeight - 1;
var maxLines = parseInt(zoneHeight) - 1;
var maxPerLine = parseInt(zoneWidth) + 1;
var strTemp = "";
var strLineCounter = 0;
var strCharCounter = 0;
var strTemporary = theField.value;
var taEditMode = "Append";
var ignoreNextLineBreak = false;

var caret = m_Selection.getCaret(); //// Added to keep caret in correct location
var caretStart = m_Selection.getCaret().start;

if (caretStart < strTemporary.length) {
	taEditMode = "Edit";
}

var isDefaultMessage = false;
if ($('#defaultTextareaMessage').val() == 'Enter your message here.') {
	isDefaultMessage = true;
}

// ie linebreaks take 2 chars instead of one, caret pos needs adjusted.
var IELineBreaksBeforeCaret = 0;
var IEBreakPos = -1;
if (isIE) {
	IEBreakPos = strTemporary.indexOf("\r\n");
	while (IEBreakPos != -1 ) {
		if (caretStart > IEBreakPos) {
		IELineBreaksBeforeCaret++;
		}
		IEBreakPos = strTemporary.indexOf("\r\n",IEBreakPos+1);
	}
}

strTemporary = replaceSubString(strTemporary, /(\r\n|\r|\n)/g, "\n");
var tmpValue = strTemporary;

var tmpSub = "";
var tmpWord = "";
var idx =0;
var idx2 =0;
var keyupKeyCode = "";
var CaretFixed = false;

caretStart = caretStart - IELineBreaksBeforeCaret;
// keycode trap to allow special keys
// allow cursor keys to move around in textarea (IE)
if (!(key == undefined)) {
	keyupKeyCode = parseInt(key.keyCode);
	switch (key.keyCode) {
		case 35: return; //end
		case 36: return; //home
		case 37: return; //left
		case 38: return; //up
		case 39: return; //right
		case 40: return; //down
		//case 46: alert('delete');
	}
}
//*** end keycode trap

for (var i = 0; i < tmpValue.length; i++)
	{
		var strChar = tmpValue.substring(i, i + 1 );
		var strCharTest = tmpValue.substring(i + 1, i + 2);

	if (ignoreNextLineBreak) {
		if (strChar == '\n') {
			if (strCharTest == ' ') {
			strChar = " ";
			}
			else
			{
			strChar = " ";
			}
		}
	}

	if (strChar == '\n')
	{
		strTemp += strChar;
		strCharCounter = 0;
		strLineCounter += 1;
	}
	else if (strCharCounter == (maxPerLine-1))
	{
	if (strLineCounter == (zoneHeight - 1)) {
		// if entering additional char on the last line...
		// just ignore the one character.. not delete a whole word
		break;
	}
	    //if the last char on the line is space convert it to newline and move caret to nextline
	if (taEditMode == 'Edit') {
		// user is entering text in the middle of textarea content
		if (strChar == ' ') {
			if (strCharTest != "\n") {
//				console.log('a');
				strTemp += '\n';
				strCharCounter = 0;
				strLineCounter += 1;
			}
			else
			{
			// don't want two newlines after each other
				strCharCounter = 0;
				strLineCounter += 1;
			}
		}
		else if (strCharTest != "\n")
		{
//			console.log('d');
			idx = strTemp.lastIndexOf(" ");
			if((idx > 0)||(idx == 0))
			{
//				console.log('e');
				tmpWrd = strTemp.substring(idx+1,strTemp.length);
				tmpWrd = tmpWrd + strChar;
				tmpSub = strTemp.substring(0,idx+1);
				tmpSub = tmpSub+ '\n' + tmpWrd;
				//strLineCounter += 1;
				strTemp = tmpSub;
				strCharCounter = tmpWrd.length;
				tmpWrd = "";
				tmpSub = "";
				idx =0;

				ignoreNextLineBreak = true;
			}
			else
			{
//				console.log('f');
				strTemp += '\n' + strChar;
				strLineCounter += 1;
				strCharCounter = 0;
			}
		}
		else
		{
//			console.log('g');
			idx = strTemp.lastIndexOf(" ");
			var preLineBreakText = "";

			if((idx > 0)||(idx == 0))
			{
//				console.log('h');
				tmpWrd = strTemp.substring(idx+1,strTemp.length);
				idx2 = tmpWrd.lastIndexOf("\n");
				if((idx2 > 0)||(idx2 == 0)) {
//					console.log('i');
					// this happens when the whole line of text does not have any spaces
					preLineBreakText = tmpWrd.substring(0,idx2);
					tmpWrd = tmpWrd.substring(idx2+1,tmpWrd.length);
					tmpWrd = tmpWrd + "\n" + strChar;
					tmpSub = strTemp.substring(0,idx+1) + preLineBreakText;
					tmpSub = tmpSub+ '\n' + tmpWrd;
					strTemp = tmpSub;
					strCharCounter = 1;
					tmpWrd = "";
					tmpSub = "";
					idx =0;
					idx2 = 0;

					if (!CaretFixed) {
						caret.start += 1;
						caret.end += 1;
						if (isIE) {
							caret.start += 1;
							caret.end += 1;
						}
					}
					ignoreNextLineBreak = true;
				}
				else
				{
//					console.log('j');
				tmpWrd = tmpWrd + strChar;
				tmpSub = strTemp.substring(0,idx+1);
				tmpSub = tmpSub+ '\n' + tmpWrd;
				strLineCounter += 1;
				strTemp = tmpSub;
				strCharCounter = tmpWrd.length;
				var IENeedsBreakFix = false;
				if (strTemp.length - 1 <= caretStart) {
//					console.log('j1');
					IENeedsBreakFix = true;
				}

				tmpWrd = "";
				tmpSub = "";
				idx =0;
				if (isIE && IENeedsBreakFix && !CaretFixed) {
//					console.log('j2');
					caret.start += 1;
					caret.end += 1;
					CaretFixed = true;
				}
					ignoreNextLineBreak = true;
				}
			}
			else
			{
//				console.log('k');
				strTemp += '\n' + strChar;
				strLineCounter += 1;
				strCharCounter = 0;
			}
		}
		//strLineCounter += 1;
	}
	else
	{
//  BEGIN APPEND MODE
		// user is entering text at the end of the text area
		if (strChar == ' ')
		{
			 strTemp += '\n';
			 strCharCounter = 0;
		}
		else if (strCharTest != "\n")
		{
			idx = strTemp.lastIndexOf(" ");
			if((idx > 0)||(idx == 0))
			{
				tmpWrd = strTemp.substring(idx+1,strTemp.length);
				tmpWrd = tmpWrd + strChar;
				tmpSub = strTemp.substring(0,idx+1);
				tmpSub = tmpSub+ '\n' + tmpWrd;
				strTemp = tmpSub;
				strCharCounter = tmpWrd.length;
				tmpWrd = "";
				tmpSub = "";
				idx =0;
				//we're appending a new line, so advance the caret position by 1
				caret.start += 1;
				caret.end += 1;
				if (isIE) {
					caret.start += 1;
					caret.end += 1;
				}
			}
			else
			{
				strTemp += '\n' + strChar;
				strCharCounter = 0;
				//we're appending a new line, so advance the caret position by 1
				caret.start += 1;
				caret.end += 1;
				if (isIE) {
					caret.start += 1;
					caret.end += 1;
				}
			}
		}
		else
		{
			strTemp += strChar;
			strCharCounter = 0;
		}
		strLineCounter += 1;
	}
// ========================================================
	}
	else
	{
		strTemp += strChar;
		strCharCounter ++;
	}
	} // end for

	// BUG0370 need to account for user entering space in edit mode
	// cannot auto-remove space at end of line
	// adjust \s+  space in reg exp to prevent unwanted newline behavior
	if (keyupKeyCode == 32 || keyupKeyCode == 0) {
		strTemp = replaceSubString(strTemp, /(\r\n|\r|\n)/g,"\n");
	}
	else {
		//if (isDeliveryPage) {
			//for delivery page we allow users to hit enter and maintain blank lines
			//strTemp = replaceSubString(strTemp, /\s+(\r\n)/g,"\n");
		//} else {
			strTemp = replaceSubString(strTemp, /\s+(\r\n|\r|\n)/g,"\n");
		//}
	}

	if (!(maxChars >= strTemp.length))
	{
		strTemp = strTemp.substring(0, maxChars);
	}

	myArr = strTemp.split('\n');

	if ((myArr.length-1) > maxLines)
	{
		// if needed to display a warning that text is truncated here is where it
		// could be added
		//$('#truncateWarning').show();
		//setTimeout(function() {$('#truncateWarning').fadeOut('slow')}, 1000);

		strTemp = "";
		for (var i = 0; i < maxLines+1; i++)
		{
			if (i == maxLines)
			{
				strTemp += myArr[i];
			}
			else
			{
				strTemp += myArr[i] + '\r\n';
			}
		}
	}
	theField.value = strTemp;
	strTemp = replaceSubString(strTemp, /\n/g," ");

	var createYourOwnMsg = "";
	if (taId != undefined) {
		createYourOwnMsg = $("#" + taId).val();
	} else {
		createYourOwnMsg = $("#messageText").val();
	}
	var createYourOwnMsgArr = createYourOwnMsg.split("\n");

	var lineArr = new Array();
	for(var i=0; i < zoneHeight; i++)
	{
		lineArr[i] = zoneWidth;
	}

	if (!isDefaultMessage){
		// dont calculate char line counts if default message
		for(var i=0; i< createYourOwnMsgArr.length; i++)
		{
			//IE keeps the carriage returns after the split on the newline above, which is throwing off our count
			//remove the carriage returns from each line before updating the count.
			createYourOwnMsgArr[i] = replaceSubString(createYourOwnMsgArr[i], /\r/g, "");
			if(createYourOwnMsgArr[i].length > zoneWidth)
			{
				createYourOwnMsgArr[i] = createYourOwnMsgArr[i].substring(0, zoneWidth);
			}
			lineArr[i] = (zoneWidth - createYourOwnMsgArr[i].length);
		}
	}
	var DeliveryCharCount;
	if (taId != undefined) {
		if (taId != 'messageText'){
			//calculate char remaining for delivery pg and display
			var finalline = createYourOwnMsgArr.length;
			DeliveryCharCount = 300 - ((finalline -1)*50);
			DeliveryCharCount = DeliveryCharCount - (createYourOwnMsgArr[finalline-1].length);
			if (DeliveryCharCount <= 0) {
				$('#'+taId+'_char').html("0");
			} else {
				$('#'+taId+'_char').html(DeliveryCharCount);
			}
//			console.log("count: " + DeliveryCharCount);
//			console.log(createYourOwnMsgArr[finalline-1].length);
		}
	}


	var counterText = '';
	for(var i=0; i < zoneHeight; i++)
	{
		counterText = counterText + '<p class="textcount" align="left">' + lineArr[i] +' Characters left</p>'
	}
	// display line count text
	$("#taCounterDiv").html(counterText);

	if (!isDefaultMessage){
		m_Selection.setCaret( caret.start, caret.end ); //// Added to keep caret in correct location
	} else {
		// need to move focus out of text area for default message so clear will work
		$('#occasionCode_title').focus();
	}
	//theField.scrollLeft = 100;
}

// supports caret placement
Selection = function(input){
    this.isTA = (this.input = input).nodeName.toLowerCase() == "textarea";
};
with({o: Selection.prototype}){
    o.setCaret = function(start, end){
        var o = this.input;
        if(Selection.isStandard) {
          try {
            o.setSelectionRange(start, end);
          } catch (err) {
          }
        } else if(Selection.isSupported){
          try {
            var t = this.input.createTextRange();
            end -= start + o.value.slice(start + 1, end).split("\n").length - 1;
            start -= o.value.slice(0, start).split("\n").length - 1;
            t.move("character", start), t.moveEnd("character", end), t.select();
          } catch (err) {
          }
        }
    };
    o.getCaret = function(){
        var o = this.input, d = document;
        if(Selection.isStandard) {
          try {
            return {start: o.selectionStart, end: o.selectionEnd};
          } catch (err) {
            return {start: 0, end: 0 };
          }
        } else if(Selection.isSupported){
          try {
            var s = (this.input.focus(), d.selection.createRange()), r, start, end, value;
            if(s.parentElement() != o)
                return {start: 0, end: 0};
            if(this.isTA ? (r = s.duplicate()).moveToElementText(o) : r = o.createTextRange(), !this.isTA)
                return r.setEndPoint("EndToStart", s), {start: r.text.length, end: r.text.length + s.text.length};
            for(var $ = "[###]"; (value = o.value).indexOf($) + 1; $ += $);
            r.setEndPoint("StartToEnd", s), r.text = $ + r.text, end = o.value.indexOf($);
            s.text = $, start = o.value.indexOf($);
            if(d.execCommand && d.queryCommandSupported("Undo"))
                for(r = 3; --r; d.execCommand("Undo"));
            return o.value = value, this.setCaret(start, end), {start: start, end: end};
          } catch (err) {
            return {start: 0, end: 0};
          }
        }
        return {start: 0, end: 0};
    };
    o.getText = function(){
        var o = this.getCaret();
        return this.input.value.slice(o.start, o.end);
    };
    o.setText = function(text){
        var o = this.getCaret(), i = this.input, s = i.value;
        i.value = s.slice(0, o.start) + text + s.slice(o.end);
        this.setCaret(o.start += text.length, o.start);
    };
    new function(){
        var d = document, o = d.createElement("input"), s = Selection;
        s.isStandard = (document.selection == null);
        s.isSupported = true; //s.isStandard || (o = d.selection) && !!o.createRange();
    };
}

(function($){
if(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) == 6) {
  try {
    document.execCommand("BackgroundImageCache", false, true);
  } catch(err) {}
}
});

/* this is needed to make sure select elements appear behind our navigation drop down
 It only applies itself to IE 6.X */
(function($){

$.fn.bgiframe = ($.browser.msie && /msie 6\.0/i.test(navigator.userAgent) ? function(s) {
    s = $.extend({
        top     : 'auto', // auto == .currentStyle.borderTopWidth
        left    : 'auto', // auto == .currentStyle.borderLeftWidth
        width   : 'auto', // auto == offsetWidth
        height  : 'auto', // auto == offsetHeight
        opacity : true,
        src     : 'javascript:false;'
    }, s);
    var html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
                   'style="display:block;position:absolute;z-index:-1;'+
                       (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
                       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
                       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
                       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
                       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
                '"/>';
    return this.each(function() {
        if ( $(this).children('iframe.bgiframe').length === 0 )
            this.insertBefore( document.createElement(html), this.firstChild );
    });
} : function() { return this; });

// old alias
$.fn.bgIframe = $.fn.bgiframe;

function prop(n) {
    return n && n.constructor === Number ? n + 'px' : n;
}

})(jQuery);


$(function() {
       $('.cat-level2').bgiframe();
       $('#colorHelpLayer').bgiframe();
});
/* this sets the width of the sort by options. it was breaking in ie 6/7 */
 if($.browser.msie && $.browser.version < 8){
$(document).ready( function() {
    $('.sort-option-container-right').each(function() {
    var $textWidth = $(this).find('.option-text').width();
    var $optionWidth = $(this).find('.option').width();
    var $totalWidth = $textWidth + $optionWidth;
        $(this).css('width',$totalWidth);
    });
 });
 }

var showDynamicContent = (function ($) {
	var sDC = function (section, requestURL) {
		$.ajax({
			type: "POST",
			url: requestURL,
			data: "",
			dataType: "text",
			timeout: 15000,
			success: function(data)  {
                section.append(data);
				section.show();
            },
			error: function() {
				return false;
			}
		});
	};
	return sDC;
}(jQuery));


