
/**
 * Global Variables
 * 
 */
var defaultCQSProductCodes = '20022, 35646, 28949'; // msg.form.defaultCQSProductCodes


/**
 * trim removes unwanted spaces from a string
 * @param {String} stringToTrim - The string to trim
 * 
 */
function trim(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g,""); }


/**
 * ltrim removes unwanted spaces from the left side of a string
 * @param {String} stringToTrim - The string to trim
 * 
 */
function ltrim(stringToTrim) { return stringToTrim.replace(/^\s+/,""); }


/**
 * rtrim removes unwanted spaces from the right side of a string
 * @param {String} stringToTrim - The string to trim
 * 
 */
function rtrim(stringToTrim) { return stringToTrim.replace(/\s+$/,""); }


/**
 * ToggleJewelryCloth adds or removes the needed hidden fields to add a Jewelry Polishing Cloth item to the MarketLive basket object
 * NOTE: Pk for the Jewelry Polishing Cloth item is currently hard-coded as a Global Variable at the top of this document.
 * 
 * @param {String} sJewelryClothPk - The product pk of the jewelry cloth product
 * @param {String} iProductPk - The product pk of the item table row product
 * @param {boolean} bIsChecked - Whether or not the checkbox to Add a Jewelry Polishing Cloth was checked
 * 
 */
function ToggleJewelryCloth(sJewelryClothPk, iProductPk, bIsChecked){
    var form = document.forms['addToBasketForm'];
    
    if(bIsChecked){
        
        // productPk
        var el = document.createElement("input");
        el.id = "jewelryCloth1_"+iProductPk;
        el.type = "hidden";
        el.name = "productPk";
        el.value = sJewelryClothPk;
        form.appendChild(el); 
        
        // optionTypes
        var e2 = document.createElement("input");
        e2.id = "jewelryCloth2_"+iProductPk;
        e2.type = "hidden";
        e2.name = "optionTypes";
        e2.value = "0";
        form.appendChild(e2); 
        
        // option
        var e3 = document.createElement("input");
        e3.id = "jewelryCloth3_"+iProductPk;
        e3.type = "hidden";
        e3.name = "option";
        e3.value = "none";
        form.appendChild(e3); 
        
        // qty
        var e4 = document.createElement("input");
        e4.id = "jewelryCloth4_"+iProductPk;
        e4.type = "hidden";
        e4.name = "qty";
        e4.value = "1";
        form.appendChild(e4); 
        
        // selectedKitItems
        var e5 = document.createElement("input");
        e5.id = "selectedKitItems_"+iProductPk;
        e5.type = "hidden";
        e5.name = "selectedKitItems";
        e5.value = "";
        form.appendChild(e5);
    
    } else {
        
        // productPk
        var e1 = document.getElementById("jewelryCloth1_"+iProductPk);
        form.removeChild(e1);
        
        // optionTypes
        var e2 = document.getElementById("jewelryCloth2_"+iProductPk);
        form.removeChild(e2);
        
        // option
        var e3 = document.getElementById("jewelryCloth3_"+iProductPk);
        form.removeChild(e3);
        
        // qty
        var e4 = document.getElementById("jewelryCloth4_"+iProductPk);
        form.removeChild(e4);
        
        // selectedKitItems
        var e5 = document.getElementById("selectedKitItems_"+iProductPk);
        form.removeChild(e5);
    }
}


/**
 * ClearCQSItemNums removes the sample item numbers from the Catalog Quick Shop starting page
 * 
 */
function ClearCQSItemNums(){
    var searchObj=document.catalogQuickShopForm.productCodes;
    if ( trim(searchObj.value) == defaultCQSProductCodes ){
        searchObj.value = "";
    }
}


/**
 * FillCQSItemNums adds the sample item numbers from the Catalog Quick Shop starting page
 * 
 */
function FillCQSItemNums(){
    var searchObj=document.catalogQuickShopForm.productCodes;
    if ( trim(searchObj.value) == ""){
        searchObj.value = defaultCQSProductCodes;
    }
}

/**
 * HideBrokenSwatch replaces the missing image with a missing image swatch
 * 
 */
function HideBrokenSwatch(img){
	img.src = "/images/set_a/en_us/local/localgraphics/swatch_unavailable.gif";  
}


/**
 * GetCookie gets a cookie based on name
 * @param NameOfCookie (string) the name of the cookie to get
 * 
 */	
function GetCookie(NameOfCookie){
	if (document.cookie.length > 0) {              
		begin = document.cookie.indexOf(NameOfCookie+"=");       
		if (begin != -1) {           
			begin += NameOfCookie.length+1;       
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(begin, end));
		} 
	}
	return null;
}

/**
 *
 *
 **/
function ShowRecentlyViewed(){
	var rvState=GetCookie('rvState');
	if (rvState != null && rvState == 'Hide') {
		return false;
	} else {
		return true;
	}
}
