String.prototype.trimEnd = function(c) {
    if (c)        
        return this.replace(new RegExp(c.escapeRegExp() + "*$"), '');
    return this.replace(/\s+$/, '');
}
String.prototype.trimStart = function(c) {
    if (c)
        return this.replace(new RegExp("^" + c.escapeRegExp() + "*"), '');
    return this.replace(/^\s+/, '');
}

String.prototype.escapeRegExp = function() {
    return this.replace(/[.*+?^${}()|[\]\/\\]/g, "\\$0");
};


function getQuerystring(key, default_) {
  if (default_==null) default_=""; 
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

getUrlEncodedKey = function(key, query) {
    if (!query)
        query = window.location.search;    
    var re = new RegExp("[?|&]" + key + "=(.*?)&");
    var matches = re.exec(query + "&");
    if (!matches || matches.length < 2)
        return "";
    return decodeURIComponent(matches[1].replace("+", " "));
}

setUrlEncodedKey = function(key, value, query) {
    query = query || window.location.search;
    var q = query + "&";
    var re = new RegExp("[?|&]" + key + "=.*?&");
    if (!re.test(q))
        q += key + "=" + encodeURI(value);
    else
        q = q.replace(re, "&" + key + "=" + encodeURIComponent(value) + "&");
    q = q.trimStart("&").trimEnd("&");
    return q[0]=="?" ? q : q = "?" + q;
}



$(document).ready(function(){
	$(".Activ_Productmenu").parent(".RootCategory_Productmenu").css("background", "#FFCC00");
	if($(".SubMenu_Productmenu_Table").length > 0){
		$(".SubMenu_Productmenu_Table").parent(".RootCategory_Productmenu").css("background", "none #FFCC00");
		
		$(".SubMenu_Productmenu_Table").parent(".RootCategory_Productmenu").parent("tr").prev().children("td").css("background", "url('/images/design/Da/ProdMenu/MenuArrowAktiv.jpg') no-repeat 13px 12px #FFCC00");
		$(".SubMenu_Productmenu_Table").parent(".RootCategory_Productmenu").parent("tr").prev().children("td").css("border-bottom", "none")
	$(".SubMenu_Productmenu_Table").parent(".RootCategory_Productmenu").parent("tr").prev().children("td").children("a").click(function(){
		if($(".SubMenu_Productmenu_Table").parent(".RootCategory_Productmenu").parent("tr").css("display") == "none"){
			$(".SubMenu_Productmenu_Table").parent(".RootCategory_Productmenu").parent("tr").prev().children("td").css("background", "url('/images/design/Da/ProdMenu/MenuArrowAktiv.jpg') no-repeat 13px 12px #FFCC00");
		} else {
			$(".SubMenu_Productmenu_Table").parent(".RootCategory_Productmenu").parent("tr").prev().children("td").css("background", "url('/images/design/Da/ProdMenu/MenuArrow.jpg') no-repeat 15px 12px #FFCC00");
		}
	})
		
	}
	
	$(".VariantGroupPosition").parent("td").remove();
	$(".VariantGroup").attr("cellpadding", "0")
	$(".VariantGroup").attr("cellspacing", "0")
	if($(".Related_Custom_TBL").length > 0){
		$("#ShopMainLayOutTable .Related_Custom_TBL").find("td[width*='25%']").attr("align", "left");
		if ($(".Related_Custom_TBL").length == 2){
			$("#ShopMainLayOutTable .Related_Custom_TBL").find("td[width*='25%']:first").attr("width", "170px");
			$("#ShopMainLayOutTable .Related_Custom_TBL").find("td[width*='25%']:last").removeAttr("width");
		} else {
			$("#ShopMainLayOutTable .Related_Custom_TBL").find("td[width*='26%']:first").attr("align", "left");
			$("#ShopMainLayOutTable .Related_Custom_TBL").find("td[width*='26%']:first").attr("width", "24%");
			$("#ShopMainLayOutTable .Related_Custom_TBL").find("td[width*='26%']:last").attr("width", "24%");
			$("#ShopMainLayOutTable .Related_Custom_TBL").find("td[width*='24%']:last").attr("align", "right")
		}
	}
	
	if($(".CustomersAlsoBought_Custom_TBL").length > 0){
		$("#ShopMainLayOutTable .CustomersAlsoBought_Custom_TBL").find("td[width*='25%']").attr("align", "left");
		if ($(".CustomersAlsoBought_Custom_TBL").length == 2){
			$("#ShopMainLayOutTable .CustomersAlsoBought_Custom_TBL").find("td[width*='25%']:first").attr("width", "170px");
			$("#ShopMainLayOutTable .CustomersAlsoBought_Custom_TBL").find("td[width*='25%']:last").removeAttr("width");
		} else {
			$("#ShopMainLayOutTable .CustomersAlsoBought_Custom_TBL").find("td[width*='26%']:first").attr("align", "left");
			$("#ShopMainLayOutTable .CustomersAlsoBought_Custom_TBL").find("td[width*='26%']:first").attr("width", "24%");
			$("#ShopMainLayOutTable .CustomersAlsoBought_Custom_TBL").find("td[width*='26%']:last").attr("width", "24%");
			$("#ShopMainLayOutTable .CustomersAlsoBought_Custom_TBL").find("td[width*='24%']:last").attr("align", "right")
		}
	}
	
	/*Product List Custom Size */
	var defaultSize = 16;
	var currentSize = getQuerystring("customPageSize",defaultSize);
	//if (currentSize != defaultSize || $("#ShopMainLayOutTable .InactivePageNumber_ProductList").length > 0) {
		//$("#pageQuantity select").val(currentSize);
		$("#pageQuantity select").change(function(){
			if ($(this).val() != "") {
				var newPageSize = $(this).val();
				window.location.href = location.pathname + setUrlEncodedKey("customPageSize",newPageSize);
			}
		});
	/*} else {
		$("#pageQuantity").hide();
	}*/
	
	
	if($(".PriceStriked_Productlist").length > 0){
		$(".PriceStriked_Productlist").after("<br>");
	}
	
});

