///////////////////////
//Submits the form with given name
///////////////////////
function submitForm(form)
{
	if (form)
	{
		if (typeof formAlreadySubmitted == 'undefined')
		{
			var formAlreadySubmitted = true;
			form.submit();
		}
	}
}

function showHideElement(element_id, visible)
{
	var element = document.getElementById(element_id);
	if (element)
	{
		if (visible)
		{
			element.style.display='block';
		}
		else
		{
			element.style.display='none';
		}
	}
}


/////////////////////////////////////////////////////////////////////////////////
// This function switches the images for different views on mouse over the images
/////////////////////////////////////////////////////////////////////////////////

function replaceFlash(flashMovie){
	var flashvars = false;
	var params = {
	  wmode: "transparent",
	  menu: "true" ,
	  allowScriptAccess: "always"
	};	
	swfobject.embedSWF(flashMovie, "flashcontent", "269", "269", "8","expressInstall.swf", flashvars, params);
}

function replaceImage(source){
	savedImage = document.getElementById('target').src;
	if(source == 'source1'){	
		document.getElementById('target').src = document.getElementById('source1').src.replace('_thmb?$48x48$', '_lg?$269x269$');return;}
	else if(source == 'source2'){
		document.getElementById('target').src = document.getElementById('source2').src.replace('_thmb?$48x48$', '_lg?$269x269$');return;}
	else if(source == 'source3'){
		document.getElementById('target').src = document.getElementById('source3').src.replace('_thmb?$48x48$', '_lg?$269x269$');return;}
	else if(source == 'source4'){
		document.getElementById('target').src = document.getElementById('source4').src.replace('_thmb?$48x48$', '_lg?$269x269$');return;}
	else if(source == 'source5'){
		document.getElementById('target').src = document.getElementById('source5').src.replace('_thmb?$48x48$', '_lg?$269x269$');return;}
}

//////////////////////////////////////////////////////////
// Checks whether a string contains a double byte character
// target = the string to be checked
//
// Return true if target contains a double byte char; false otherwise
//////////////////////////////////////////////////////////
function containsDoubleByte (target) {
     var str = new String(target);
     var oneByteMax = 0x007F;

     for (var i=0; i < str.length; i++){
        chr = str.charCodeAt(i);
        if (chr > oneByteMax) {return true;}
     }
     return false;
}

//////////////////////////////////////////////////////////
// A simple function to validate an email address
// It does not allow double byte characters
// strEmail = the email address string to be validated
//
// Return true if the email address is valid; false otherwise
//////////////////////////////////////////////////////////
function isValidEmail(strEmail){
	// check if email contains dbcs chars
	if (containsDoubleByte(strEmail)){
		return false;
	}
	
	if(strEmail.length == 0) {
		return true;
	} else if (strEmail.length < 5) {
			 showError("Invalid email format.");
             return false;
       	}else{
           	if (strEmail.indexOf(" ") > 0){
           				showError("Invalid email format.");
                      	return false;
               	}else{
                  	if (strEmail.indexOf("@") < 1) {
                  				showError("Invalid email format.");
                            	return false;
                     	}else{
                           	if (strEmail.lastIndexOf(".") < (strEmail.indexOf("@") + 2)){
                           				showError("Invalid email format.");
                                     	return false;
                                }else{
                                        if (strEmail.lastIndexOf(".") >= strEmail.length-2){
                                        	showError("Invalid email format.");
                                        	return false;
                                        }
                              	}
                       	}
              	}
       	}

}

//////////////////////////////////////////////////////////
// A simple function to validate an email address
// It does not allow double byte characters
// strEmail = the email address string to be validated
//
// Return true if the email address is valid and then submit form for email signup; 
// false otherwise & change label to red
//////////////////////////////////////////////////////////
function isValidEmail(form, strEmail, label, errorDiv){
	// check if email contains dbcs chars
	if (containsDoubleByte(strEmail)){
		return false;
	}
	var errorMsg = 'Invalid email address. Please try again.';
	document.getElementById(errorDiv).style.color = 'red';
	if(strEmail.length == 0) {
		return true;
	} else if (strEmail.length < 5) {
			document.getElementById(label).style.color = 'red';
			// (Example formatting is?.)
			 document.getElementById(errorDiv).innerHTML =errorMsg;
             return false;
       	}else{
           	if (strEmail.indexOf(" ") > 0){
           				document.getElementById(label).style.color = 'red';
           				document.getElementById(errorDiv).innerHTML =errorMsg;
                      	return false;
               	}else{
                  	if (strEmail.indexOf("@") < 1) {
                  				document.getElementById(label).style.color = 'red';
                  				document.getElementById(errorDiv).innerHTML =errorMsg;
                            	return false;
                     	}else{
                           	if (strEmail.lastIndexOf(".") < (strEmail.indexOf("@") + 2)){
                           				document.getElementById(label).style.color = 'red';
                           				document.getElementById(errorDiv).innerHTML =errorMsg;
                                     	return false;
                                }else{
                                        if (strEmail.lastIndexOf(".") >= strEmail.length-2){
                                        	document.getElementById(label).style.color = 'red';
                                        	document.getElementById(errorDiv).innerHTML =errorMsg;
                                        	return false;
                                        }
                              	}
                       	}
              	}
       	}
      	
		if (form.email1 != null)
		{
			form.email1.value = form.emailSignup.value;
			var str = location.pathname;
			var temp = str.slice(str.lastIndexOf("/") + 1, str.length);
			form.URL.value = temp;
		}
      	form.submit();
}



//////////////////////////////////////////////////////////
// This function will count the number of bytes
// represented in a UTF-8 string
//
// arg1 = the UTF-16 string
// arg2 = the maximum number of bytes allowed in your input field
// Return false is this input string is larger then arg2
// Otherwise return true...
//////////////////////////////////////////////////////////
function isValidUTF8length(UTF16String, maxlength) {
    if (utf8StringByteLength(UTF16String) > maxlength) return false;
    else return true;
}

//////////////////////////////////////////////////////////
// This function will count the number of bytes
// represented in a UTF-8 string
//
// arg1 = the UTF-16 string you want a byte count of...
// Return the integer number of bytes represented in a UTF-8 string
//////////////////////////////////////////////////////////
function utf8StringByteLength(UTF16String) {
  if (UTF16String === null) return 0;
  var str = String(UTF16String);
  var oneByteMax = 0x007F;
  var twoByteMax = 0x07FF;
  var byteSize = str.length;

  for (i = 0; i < str.length; i++) {
    chr = str.charCodeAt(i);
    if (chr > oneByteMax) byteSize = byteSize + 1;
    if (chr > twoByteMax) byteSize = byteSize + 1;
  }  
  return byteSize;
}

////////////////////////////////////////////////////////
//This function will filter out all key strokes 
//that are not numbers or '-'
///////////////////////////////////////////////////////
function isNumberKey2(evt)
{
     var charCode = (evt.which) ? evt.which : evt.keyCode
     if ((charCode > 31) && (charCode < 48 || charCode > 57)){
     	if (charCode == 45) { return true;}
		return false;
	  }
     return true;
}



////////////////////////////////////////////////////////
//This function will filter out all key strokes 
//that are not numbers 
///////////////////////////////////////////////////////
function isNumberKey(evt)
{
     var charCode = (evt.which) ? evt.which : evt.keyCode
     if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

     return true;
}

function quantityCheck(evt,qty)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
	 if (charCode == 48 && qty > 0)
	 	return true;
     if (charCode > 31 && (charCode < 49 || charCode > 57))
        return false;

     return true;
}

////////////////////////////////////////////////////////
//This function displays the errorText at the corresponding span id=errorTextId
//if errorTextId is not passed then 
//errorText will be displayed at span id='error_display_text'
///////////////////////////////////////////////////////
function showError(errorText, errorTextId)
{
	var element = getErrorElement(errorTextId);
	if (element)
	{
		element.innerHTML = errorText;
		element.style.color ='red'
	}
	showHideErrorText("visible", errorTextId);
	var omniture_errors= errorText.replace(new RegExp(/\n/g)," ");
	var s_prop6 = omniture_errors;
	s_code=s_dc(s_account);
}
function clearError(errorText, errorTextId)
{
	showHideErrorText("hidden", errorTextId);
}
function showHideErrorText(visibility, errorTextId)
{

	var element = getErrorElement(errorTextId);
	if (element) {
		element.style.visibility = visibility; //'visible';

	}
}
function getErrorElement(errorTextId)
{
	var element;
	var elementId;
	if(typeof(errorTextId)=='undefined') {
		elementId = 'error_display_text';
	} else {
		elementId = errorTextId;
	}
	if (document.getElementById) {
	// IE 5.5+, NS6+, Opera 6+
		element = document.getElementById(elementId);
	} else if (document.layers) {
	// NS4
		element = document.layers[elementId];
	} else if (document.all) {
	// IE < 5.5, Opera 5(?)
		element = document.all(elementId);
	}
	return element;
}


function showErrorNav(errorText)
{
	var element = getErrorElementNav();
	if (element)
	{
		element.innerHTML = errorText;
	}
	showHideErrorTextNav("visible");
}
function clearErrorNav(errorText)
{
	showHideErrorTextNav("hidden");
}
function showHideErrorTextNav(visibility)
{
	
	var element = getErrorElementNav();
	if (element) {
		element.style.visibility = visibility; //'visible';
	} 	
}
function getErrorElementNav()
{
	var element;
	if (document.getElementById) {
	// IE 5.5+, NS6+, Opera 6+
		element = document.getElementById('error_display_textNav');
	} else if (document.layers) {
	// NS4
		element = document.layers['error_display_textNav'];
	} else if (document.all) {
	// IE < 5.5, Opera 5(?)
		element = document.all('error_display_textNav');
	}
	return element;
}
////////////////////////////////////////////////////////
// Determines whether or not an address is PO BOX.
///////////////////////////////////////////////////////
function isPOBox(address)
{
	var isPOBoxRE = /(P[\s.]*O[\s.]|POB(OX)?[\s]|Postal[\s]+Box[\s]+|Box[\s]|Post[\s]+Office[\s])/i;

	return (address.match(isPOBoxRE) != null);
}

////////////////////////////////////////////////////////
// Determines whether or not an radio button is checked.
///////////////////////////////////////////////////////

function getRadioValue(radioForm, radioN)
{
	for(i=0;i<radioForm[radioN].length;i++)
	{
		if (radioForm[radioN][i].checked == true)
		{
			return radioForm[radioN][i].value;
		}
	}
	
	return null;
}

////////////////////////////////////////////////////////
// Goes through the phone fields once last is complete
///////////////////////////////////////////////////////

function jumpThroughPhoneFields(currentBox, nextBoxId, currentBoxLimit, evt)
{
	if (!isNumberKey(evt))
	{
	    return false;
	}
	else
	{
	    if (!evt)
	    {
	    	var evt = window.event;
	    }
	    
	    var charCode = (evt.which) ? evt.which : evt.keyCode;
	    
		if (charCode >= 48 && charCode <= 57)
		{
		    // do the actions
		    var currentValue = currentBox.value;
		    var currentLength = 0;
		    if (currentValue)
		    {
		        currentLength = currentValue.length;
		    }
		    
		    if (currentLength == currentBoxLimit-1)
		    {
			    var charTyped = String.fromCharCode(charCode);
			    
			    var nextBox = document.getElementById(nextBoxId);
			    
			    currentBox.value += charTyped;
			    nextBox.focus();
			    return false;
		    }
		    else
		    {
		    	return true;
		    }
		}
		else
		{
		    return true;
		}
	}
	
}


////////////////////////////////////////////////////////
// This code will show/hide a div
///////////////////////////////////////////////////////


function show(layer_ref) {
	var layer = document.getElementById(layer_ref);
	if (layer != null)
		layer.style.display = 'block';
	
}

function hide(layer_ref) {
	var layer = document.getElementById(layer_ref);
	if (layer != null)
		layer.style.display = 'none';
	
}

function testClear(id)
{
	var text = document.getElementById(id).value;
	if (text == "Enter keyword or item #")
		inputClear(id);
	if (text == "Email Address")
		inputClear(id);
		
}

function inputClear(id) {

	document.getElementById(id).value = "";
	
}

////////////////////////////////////////////////////////
// This code will validate search field 
///////////////////////////////////////////////////////

function searchCheck(searchForm, searchField)
{
	var text = searchField.value;
	
	if ((text == "Keyword or Item #") || (text == "")) {
        showError("Required field missing.");
        return false;
	} else {
		searchForm.submit();
	}
}

////////////////////////////////////////////////////////
// This code will validate search field and changes label to red if error
///////////////////////////////////////////////////////

function searchCheck(searchForm, searchField, label, errorDiv)
{
	var text = searchField.value;
	
	if ((text == "Keyword or Item #") || (text == "")) {
				document.getElementById(label).style.color = 'red';
        showError("Required field missing.");
        return false;
	} else {
		searchForm.submit();
	}
}

////////////////////////////////////////////////////////
// This code will validate zip code 
///////////////////////////////////////////////////////

function zipCheck(StoreSearchForm, searchField)
{
	var text = searchField.value;
	
	 var re = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	if (!(re.test(text)) ) {
		showError("Invalid Zip Code entered.");
		return false;
	} 
	else {
		StoreSearchForm.submit();
	}
}

////////////////////////////////////////////////////////
// This code will validate zip code and changes label to red if error
///////////////////////////////////////////////////////

function zipCheck(StoreSearchForm, searchField, label, errorDiv)
{
	var text = searchField.value;
	var errorMsg = 'Please enter a valid ZIP code';
	document.getElementById(errorDiv).style.color = 'red';	
	 var re = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	if (!(re.test(text)) ) {
		document.getElementById(label).style.color = 'red';
		document.getElementById(errorDiv).innerHTML =errorMsg;		
		return false;
	} 
	else {
		StoreSearchForm.submit();
	}
}



////////////////////////////////////////////////////////
// This code will validate checkbox is checked
///////////////////////////////////////////////////////

function validateCheckBox(form)
{
		if(!(form.accept.checked))
	{
	    showError("Please check box to verify you have reviewed your order.");
		return false;

	} else {
		form.submit()
	}
}

////////////////////////////////////////////////////////
// This code will validate checkbox is checked, if not then change label to red
///////////////////////////////////////////////////////

function validateCheckBox(form, label)
{
		if(!(form.accept.checked))
	{
		document.getElementById(label).style.color = 'red';
	    showError("Please check box to verify you have reviewed your order.");
		return false;

	} else {
		form.submit()
	}
}

//*******************LAYER logic starts here********************
var ie5=document.all && !window.opera
var ns6=document.getElementById

if (ie5||ns6)
document.write('<div id="popupbox" onMouseover="clearhidemenu();" ></div>')

function iecompattest(){
return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}

function showmenu(e, which, optWidth){
var delayhide=setTimeout('', 3000)
if (!document.all&&!document.getElementById)
return
clearhidemenu()
menuobj=document.all?  document.all['popupbox'] : document.getElementById("popupbox")
contentobj=document.all?  eval('document.all.'+which) : eval('document.getElementById("'+which+'")')
menuobj.innerHTML=contentobj.innerHTML
menuobj.style.width=(typeof optWidth!="undefined")? optWidth : defaultMenuWidth
menuobj.contentwidth=menuobj.offsetWidth
menuobj.contentheight=menuobj.offsetHeight+100
eventX=ie5? event.clientX : e.clientX
eventY=ie5? event.clientY : e.clientY
//Find out how close the mouse is to the corner of the window
var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY
//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX-menuobj.contentwidth+"px" : window.pageXOffset+eventX-menuobj.contentwidth+"px"
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX+"px" : window.pageXOffset+eventX+"px"
//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.style.top=ie5? iecompattest().scrollTop+eventY-menuobj.contentheight+"px" : window.pageYOffset+eventY-menuobj.contentheight+"px"
else
menuobj.style.top=ie5? iecompattest().scrollTop+event.clientY+"px" : window.pageYOffset+eventY+"px"
menuobj.style.visibility="visible"

return false
}

function contains_ns6(a, b) {
//Determines if 1 element in contained in another
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
if (window.menuobj)
menuobj.style.visibility="hidden"
}

function dynamichide(e){
if (ie5&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("hidemenu()",500)
}

function delayshowmenu(e, which, optWidth){
delayhide=setTimeout("showmenu(e, which, optWidth)",500)
}


function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}

//if (ie5||ns6)
//document.onclick=hidemenu

//*******************LAYER logic Ends here********************

////////////////////////////////////////////////////////
// This code will validate RequestCatalogForm
///////////////////////////////////////////////////////

function validateRequestCatalog(form)
{   
	//phone number regular expresion
	var re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/; 
	if (form.firstName.value == '')
    {
        showError("<fmt:message key='_ERR_CMD_INVALID_PARAM.5066' bundle='${storeErrorMessages}' />");
        window.scrollTo(0,0);return false;
    }
    else if (form.lastName.value == '')
    {
        showError("<fmt:message key='_ERR_CMD_INVALID_PARAM.5060' bundle='${storeErrorMessages' />");
        window.scrollTo(0,0);return false;
    }
    else if (form.address1.value == '')
    {
        showError("<fmt:message key='_ERR_CMD_INVALID_PARAM.5080' bundle='${storeErrorMessages}' />");
        window.scrollTo(0,0);return false;
    }
    else if (isPOBox(form.address1))
	{
		showError("<fmt:message key='_ERR_ADDRESS_IS_PO_BOX' bundle='${storeErrorMessages}' />");
	    window.scrollTo(0,0);return false;
	}
    else if (form.city.value == '')
    {
        showError("<fmt:message key='_ERR_CMD_INVALID_PARAM.5100' bundle='${storeErrorMessages}' />");
        window.scrollTo(0,0);return false;
    }
    else if (form.state.value == '')
    {
        showError("<fmt:message key='_ERR_STATE_NOT_SELECTED' bundle='${storeErrorMessages}' />");
        window.scrollTo(0,0);return false;
    }
    else if (form.zipCode.value == '')
    {
        showError("<fmt:message key='_ERR_ZIP_CODE_EMPTY' bundle='${storeErrorMessages}' />");
        window.scrollTo(0,0);return false;
    }
    else if (form.zipCode.value.length != 5)
    {
        showError("<fmt:message key='_ERR_ZIP_CODE_INVALID_LENGTH' bundle='${storeErrorMessages}' />");
        window.scrollTo(0,0);return false;
    }
    else if (form.phone1.value == '')
    {
        showError("<fmt:message key='_ERR_CMD_INVALID_PARAM.phone1' bundle='${storeErrorMessages}' />");
        window.scrollTo(0,0);return false;
    }
    else if (!(re.test(form.phone1)))
    {
    	
        showError("<fmt:message key='_ERR_CMD_INVALID_PARAM.phone1' bundle='${storeErrorMessages}' />");
        window.scrollTo(0,0);return false;
    }
    else if(form.email1.value != '')
    {
     	if(form.email1.value != form.emailconfirm.value)
     	{
     		showError("<fmt:message key='_ERR_MATCHING_EMAIL' bundle='${storeErrorMessages}' />");
        	window.scrollTo(0,0);return false;
     	}
     	else
     	{
     		// set up email updates 
     	    submitForm(form);
     	}
    }
    // validate if at least on check box is checked
    
    submitForm(form);
}

////////////////////////////////////////////////////////
// This code will validate Store locator zip or city, state
///////////////////////////////////////////////////////

function zipCityStateCheck(Form, searchField, zipLabel, cityLabel, stateLabel, errorDiv)
{

	var errorMsg = 'Please enter a valid ZIP code or City and state.';
	document.getElementById(errorDiv).style.color = 'red';		

	if (searchField.value.length == 0 && Form.citylocation.value.length == 0){
		document.getElementById(errorDiv).innerHTML = errorMsg;
		document.getElementById(zipLabel).style.color = 'red';	
		document.getElementById(cityLabel).style.color = 'red';	
		return false;
	}
	else if(searchField.value.length != 0)
	{
		zipCheck(Form, searchField, zipLabel, errorDiv);

	}
	else if(Form.citylocation.value.length != 0)
	{
		if(Form.state1.value == '')
		{
			document.getElementById(errorDiv).innerHTML = "Please select a state.";
		    document.getElementById(stateLabel).style.color = 'red';
		    document.getElementById(zipLabel).style.color = 'black';
		    document.getElementById(cityLabel).style.color = 'black';		    				
			return false;
		}
		else
		{
			Form.zipcode.value = searchField.value;
			Form.city.value = Form.citylocation.value;
			Form.state.value = Form.state1.value;
			
			Form.submit();
		}
	}
}

///////////////////////////////////
//This checks for valid email address
//then creates a cookie set to true
//////////////////////////////////
function submitGuestEmail(form, strEmail, label, errorDiv){
var params = [];
	// check if email contains dbcs chars
	if (containsDoubleByte(strEmail)){
		return false;
	}
	var errorMsg = 'Invalid email address. Please try again.';
	document.getElementById(errorDiv).style.color = 'red';
	if(strEmail.length == 0) {
		return true;
	} else if (strEmail.length < 5) {
			document.getElementById(label).style.color = 'red';
			// (Example formatting is?.)
			 document.getElementById(errorDiv).innerHTML =errorMsg;
             return false;
       	}else{
           	if (strEmail.indexOf(" ") > 0){
           				document.getElementById(label).style.color = 'red';
           				document.getElementById(errorDiv).innerHTML =errorMsg;
                      	return false;
               	}else{
                  	if (strEmail.indexOf("@") < 1) {
                  				document.getElementById(label).style.color = 'red';
                  				document.getElementById(errorDiv).innerHTML =errorMsg;
                            	return false;
                     	}else{
                           	if (strEmail.lastIndexOf(".") < (strEmail.indexOf("@") + 2)){
                           				document.getElementById(label).style.color = 'red';
                           				document.getElementById(errorDiv).innerHTML =errorMsg;
                                     	return false;
                                }else{
                                        if (strEmail.lastIndexOf(".") >= strEmail.length-2){
                                        	document.getElementById(label).style.color = 'red';
                                        	document.getElementById(errorDiv).innerHTML =errorMsg;
                                        	return false;
                                        }
                              	}
                       	}
              	}
       	}
	
		form.email1.value = form.emailSignup.value;
		form.email.value = form.emailSignup.value;
		form.ConfirmEmail.value = form.emailSignup.value;		
		eraseCookie('ThingsRememberedEmailUpdates');
		setCookie('ThingsRememberedEmailUpdates', form.email1.value, 0);
		dojo.io.bind(
		{
			formNode: form,
			load: updateBottomRight,
			mimetype: "text/html",
			content: params
		});

  
  function updateBottomRight(){

 document.getElementById("emailHeader").innerHTML = emailWCM;
  }
 
  
  	function couponControlCallback(type, data, evt){
		document.getElementById("emailHeader").innerHTML=data;
		var testObj = new dojo.xml.Parse();
		var testObjects = testObj.parseElement(document.getElementById("emailHeader"));
		var testParse = dojo.widget.getParser();
		testParse.createComponents(testObjects);
	}
  
  
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	if(expiredays != 0){
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+"; path=/";
	}
	else{
		document.cookie=c_name+ "=" +escape(value)+"; path=/";
	}
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



/* used for store locator map popup */
	function popupMap(myform, url) 
	{ 
		if (! window.focus )return true; 
		//var d = new Date(); //use this if you want each map in a new window
		//windowname = d.getTime(); 
		windowname='map';
		
		//if (mapWin)  //use this if you want to close the opened map window before lauching a new window (comment out window.setTimeout below)
		//	mapWin.close();		
		mapWin = window.open('', windowname, 'top=100,left=100,height=480,width=480,location=no,resizable=no,scrollbars=no,status=no'); 
		myform.target=windowname;	
		myform.z.value = 8;
		myform.u.value = url;	
		myform.submit();
		window.setTimeout('mapWin.focus()',1000); //use if you want to reuse an opened map window with a new map
		return true; 
	} 

function ajaxInventoryCheck(catentryId, storeId, qty, productId,addProduct) {
	//returns a JSON object representing the results of the inventory call. Should
	// consist of an available boolean and a quantity
	if (productId == null) productId = catentryId;
	if(addProduct == null) addProduct = 'no';
	var params = "successView=AjaxSuccessView&langId=-1&storeId=" + storeId + "&productId=" + productId + "&catEntryId_1=" + catentryId + "&skuId=" + catentryId + "&quantity=" + qty+"&addProduct="+ addProduct;
	var invAjax = new Ajax.Request('TRInventoryControllerCmd', 
						{
							method: 'post', 
							parameters: params, 
							asynchronous: false
						});
	var r = eval("(" + invAjax.transport.responseText + ")");
	return r;
}

//////////////////////////////////////////////////////////
// This function will return the value of a cookie
//
// arg1 = cookie name
// Return the value of the cookie
//////////////////////////////////////////////////////////
function getCookie(name) {

	var cookies = document.cookie.split(';');
	var value   = null;

	for ( var i=0; i < cookies.length; i++ ) {
		var cookie = cookies[i];

		while ( cookie.charAt(0) == ' ' ) {
			cookie = cookie.substring(1, cookie.length );
		}

		if ( cookie.indexOf(name+"=") == 0 ) {
			value = cookie.substring(name.length+1, cookie.length);
			value =	unescape(value);
		}
	}

	return value;
}

function ajaxSaveConfigCmd(formParams,storeId,productId,catentryId,qty) {
	//returns a JSON object representing the result of the SaveConfigComd call. 
	var params = formParams+"&successView=AjaxSuccessView&langId=-1&storeId=" + storeId + "&setId=" + productId + "&catentryId=" + catentryId + "&quantity=" + qty; 
	var invAjax = new Ajax.Request('SaveConfiguration', 
						{
							method: 'post', 
							parameters: params, 
							asynchronous: false
						});
	var r = eval("(" + invAjax.transport.responseText + ")");
	return r;
}


function ajaxConfigProductsInvCheck(formParams,catentryId, storeId, qty, productId,addProduct) {
	//returns a JSON object representing the results of the inventory call. Should
	// consist of an available boolean and a quantity
	if (productId == null) productId = catentryId;
	if(addProduct == null) addProduct = 'no';
	var params = formParams + "&successView=AjaxSuccessView&langId=-1&storeId=" + storeId + "&productId=" + productId + "&catEntryId_1=" + catentryId + "&quantity=" + qty+"&addProduct="+ addProduct;
	var invAjax = new Ajax.Request('TRInventoryControllerCmd', 
						{
							method: 'post', 
							parameters: params, 
							asynchronous: false
						});
	var r = eval("(" + invAjax.transport.responseText + ")");
	return r;
}

function ajaxTRresolveSkuCmd(productId,attrName1, attribute1,attrName2, attribute2, fetchConfigData,storeId,catalogId,langId) {
	if(langId ==null || langId != ''){
		langId = '-1' ;
	}
	if(storeId ==null || storeId != ''){
		storeId = '10001' ;
	}
	if(catalogId ==null || catalogId != ''){
		catalogId = '9951' ;
	}
	var params = "successView=TRResolveSkuSuccess" + "&productId=" + productId +"&langId="+langId +"&catalogId="+catalogId +"&storeId=" + storeId ;
	if(attrName1 !=null && attrName1 != '' && attribute1 !=null && attribute1 != '' ){
		params += "&attrName1="+attrName1+"&attribute1="+attribute1 ;
	}
	if(attrName2 !=null && attrName2 != '' && attribute2 !=null && attribute2 != '' ){
		params += "&attrName2="+attrName2+"&attribute2="+attribute2 ;
	} 
	if(fetchConfigData != null && fetchConfigData == 'true'){ 
		params += "&fetchConfigData="+ fetchConfigData ; 	
	}
	
	var invAjax = new Ajax.Request('TRResolveSkuControllerCmd', 
						{
							method: 'post', 
							parameters: params, 
							asynchronous: false
						});
	var r = eval("(" + invAjax.transport.responseText + ")");
	return r;
}

// Ensure 2 decimal places
function CurrencyFormatted(amount){
      var i = parseFloat(amount);
      if(isNaN(i)) { i = 0.00; }
      var minus = '';
      if(i < 0) { minus = '-'; }
      i = Math.abs(i);
      i = parseInt((i + .005) * 100);
      i = i / 100;
      s = new String(i);
      if(s.indexOf('.') < 0) { s += '.00'; }
      if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
      s = minus + s;
      return s;
}
