/************************ browser check / BEGIN ************************/
var checkBrowserType = navigator.appVersion.toLowerCase();
var checkBrowserAgent = navigator.userAgent.toLowerCase();
if(checkBrowserType.indexOf("msie") != -1 && checkBrowserType.indexOf("6.0") != -1){
	browserType = "ie6";
}
else if(checkBrowserType.indexOf("msie") != -1 && checkBrowserType.indexOf("7.0") != -1){
	browserType = "ie7";
}
else if(checkBrowserType.indexOf("msie") != -1 && checkBrowserType.indexOf("8.0") != -1){
	browserType = "ie8";
}
else if(checkBrowserType.indexOf("safari") != -1 && checkBrowserType.indexOf("3") != -1){
	browserType = "safari3";
}
else if(checkBrowserAgent.indexOf("firefox") != -1 && checkBrowserAgent.indexOf("2.") != -1){
	browserType = "firefox2";
}
else if(checkBrowserAgent.indexOf("firefox") != -1 && checkBrowserAgent.indexOf("3.") != -1){
	browserType = "firefox3";
}
else if(checkBrowserAgent.indexOf("k-meleon") != -1){
	browserType = "kmeleon";
}
else {
	browserType = "";
}
/************************ browser check / END ************************/



/************ globalJCarousel - BEGIN ************/
function globalJCarousel(gjc){

	gjc = jQuery.extend({
		element	: null
	}, gjc || {});

	if(gjc.element){
		var targetContainer = jQuery(gjc.element);
		if(targetContainer.size() != 0){

			var prevBtn = "#prevBtn";
			var nextBtn = "#nextBtn";

			function mycarousel_initCallback(carousel){

				jQuery(prevBtn).bind("click", function(){
					carousel.prev();
					return false;
				});
				jQuery(nextBtn).bind("click", function(){
					carousel.next();
					return false;
				});
			};

			function mycarousel_itemVisibleInCallbackAfterAnimation(carousel, item, idx, state){

				var currentCount = 0;
				jQuery("ul li", targetContainer).each(function(){
					currentCount = currentCount + 1;
				});


				var currentPositionOfList = jQuery("ul", targetContainer).css("left");
				if(state == "init" || currentPositionOfList == "0pt" || currentPositionOfList == "0px"){
					jQuery(prevBtn).addClass("disabled");
					if(currentCount > 3) {
						jQuery(nextBtn).removeClass("disabled");
					}
					else {
						jQuery(nextBtn).addClass("disabled");
					}

				} else if(currentCount == idx){
					jQuery(nextBtn).addClass("disabled");
					jQuery(prevBtn).removeClass("disabled");
				} else {
					jQuery("#nextBtn, #prevBtn").removeClass("disabled");
				}
			};

			var createCarouselButtons = "<div id=\"prevBtn\"></div><div id=\"nextBtn\"></div>";
			targetContainer.append(createCarouselButtons).jcarousel({
				//scroll: 1,
				initCallback: mycarousel_initCallback,
				itemVisibleInCallback: {
					onAfterAnimation:  mycarousel_itemVisibleInCallbackAfterAnimation
				},
				// This tells jCarousel NOT to autobuild prev/next buttons
				buttonNextHTML: null,
				buttonPrevHTML: null
			});
		}
	}
}
/************ globalJCarousel - END ************/



/************************ initializeStoreItemFunctionalities / BEGIN ************************/
function initializeStoreItemFunctionalities(){


	if(jQuery("#sku-tabs").size() != 0){
		jQuery("#sku-tabs").tabs();
	}


	globalJCarousel({
		element: "#merch-slider-content"
	});


	if(jQuery(".color-tooltip").size() != 0){
		jQuery(".color-tooltip").cluetip({
			cluetipClass: 'color-tooltip',
			positionBy: 'auto',
			width: 172,
			height: 'auto',
			local: true,
			hideLocal: false,
			dropShadow: false,
			topOffset: -225,
			leftOffset: -98,
			arrows: false,
			showTitle: false,
			cluezIndex: 500,
			attribute: 'id'
		});
	}
}
/************************ initializeStoreItemFunctionalities / END ************************/



/************************ initializeBrowseCatalogFunctionalities / BEGIN ************************/
function initializeBrowseCatalogFunctionalities(){

	if(jQuery(".item-tooltip").size() != 0){
		jQuery(".item-tooltip").cluetip({
			cluetipClass: 'list-tooltip',
			positionBy: 'auto',
			width: 173,
			height: 'auto',
			local: true,
			hideLocal: false,
			dropShadow: false,
			topOffset: -280,
			leftOffset: -120,
			arrows: false,
			showTitle: false,
			cluezIndex: 500
		});
	}
}
/************************ initializeBrowseCatalogFunctionalities / END ************************/

/************************ initializeBrowseCatalogFunctionalities / BEGIN ************************/
function initializeLooksFunctionalities(){

	if(jQuery(".item-tooltip").size() != 0 && jQuery("#looks-heading").size() != 0){
		jQuery(".item-tooltip").cluetip({
			cluetipClass: 'list-tooltip',
			attribute: 'id',
			positionBy: 'auto',
			width: 173,
			height: 'auto',
			local: true,
			hideLocal: false,
			dropShadow: false,
			topOffset: -280,
			leftOffset: -120,
			arrows: false,
			showTitle: false,
			cluezIndex: 500
		});
	}
}
/************************ initializeBrowseCatalogFunctionalities / END ************************/


/************************ initializeThickBoxFunctionalities / BEGIN ************************/
function initializeThickBoxFunctionalities(){

	globalJCarousel({
		element: "#overlay-slider-content"
	});
}
/************************ initializeThickBoxFunctionalities / END ************************/

//Handle overlays
var dropdowntoopen = null;
var droplinktoclose = null;
var headeringOverlayTrigger = "";
var headerImageAlreadyApplied = false

/************************ document ready / BEGIN ************************/
//apply when document is loaded, has to be positioned at the end of this document!
jQuery(document).ready(function(){

	var storeLocation = $("#storeLocation").html();

	var dynamicImgLocation = window.location.protocol + "//" + window.location.hostname + "/ctlimg/Wolford/images/from_client/" + storeLocation + "/categoryHeading/";

	// handle top margin, when page-heading image is available
	if( $(".page-heading").length){

		var currentCategory = $(".current-category").text();
		if(currentCategory == "")
			currentCategory = "default";

		var imagePath = dynamicImgLocation + "" + currentCategory + ".jpg";

		if(navigator.appVersion.toLowerCase().indexOf("msie") != -1){
			if(!headerImageAlreadyApplied){
				$("body").find("#content-noright").css( "background",
						"url(" + dynamicImgLocation + "" + currentCategory +
						".jpg) no-repeat");
			}
		}
		else{
			$.ajax({
				type: "GET",
				url: imagePath,
				success: function(msg){
					//Set the image
					$("body").find("#content-noright").css( "background",
						"url(" + dynamicImgLocation + "" + currentCategory +
						".jpg) no-repeat");
				},
				error: function(msg){
					//Set the standard image as we run into a 404
					currentCategory = "default";
					$("body").find("#content-noright").css(
						"background", "url(" + dynamicImgLocation + "" +
						currentCategory + ".jpg) no-repeat");

				}
			});
		}

		$("body").find("#content-noright").css("padding-top","0");
	}

	// handle top margin, when checkout-trail is available
	if( $("#checkout-trail").length ){
		$("body").find("#content-noleft-noright").css("margin-top","0");
	};

	// show/hide expandables
	$(".header-expandable h2").click(function(){
		var expandabletoopen = $(this).attr("id");
		$(this).toggleClass("show");
		$("body").find("#" + expandabletoopen + "-content").toggleClass("show");
	});

	// show/hide FAQ items
	$(".faq-item h2").click(function(){
		$(this).toggleClass("active");
		$(this).next("div").toggleClass("show");
	});

	// toogle cart help
	$(".accordion h3 a").click(function(){
		$(this).toggleClass("active");
		$(this).parent("h3").next("div").toggleClass("hide");
	});

	// toggle checkbox explain/additional content
	// checkbox
	$("input.checkbox-combo-check").each(function() {
		var contenttocheck = $(this).attr("id");
		$("#" + contenttocheck + "-content").hide();
		if(this.checked) {
			$("#" + contenttocheck + "-content").show();
		}
	}).click(function() {
		var inputtohandle = $(this).attr("id");
		if(this.checked) {
			$("#" + inputtohandle + "-content").show();
		}
		else {
			$("#" + inputtohandle + "-content").hide();
		}
	});

	// radio
	$("input.checkbox-combo-radio").each(function() {
		var contenttocheck = $(this).attr("id");
		$("#" + contenttocheck + "-content").hide();
		if(this.checked) {
			$("#" + contenttocheck + "-content").show();
		}
	}).click(function() {
		var inputtohandle = $(this).attr("id");
		var radiotoclose = $(this).attr("name");
		$("body").find("." + radiotoclose + "-content").hide();
		if(this.checked) {
			$("#" + inputtohandle + "-content").show();
		}
		else {
			$("#" + inputtohandle + "-content").hide();
		}
	});

	// Set position and with for my wolford
	if( $("#header-minicart").length ){
		var widthtohandle = $("#header-minicart").width() + 44;
		var widthtohandle2 = widthtohandle + 1;
		$("#header-myaccount").css("right" , widthtohandle2 + "px");
		$("#header-myaccount-content").css("right" , widthtohandle + "px");
	}

	// Set position and with for listing-collections
	if( $("#listing-colors").length ){
		var widthtohandle = $("#listing-colors").width() + 242;
		$("#listing-collections-content").css("left" , widthtohandle + "px");
	}

	// Set position and with for listing-sorts
	if( $("#listing-colors").length && $("#listing-collections").length ){
		var widthtohandle = $("#listing-colors").width() + 242;
		var widthtohandle2 = $("#listing-collections").width() + 24;
		finalWidthtohandle = widthtohandle + widthtohandle2;
		$("#listing-sorts-content").css("left" , finalWidthtohandle + "px");
	}
	else {
		if($("#listing-colors").length ) {
			var widthtohandle = $("#listing-colors").width() + 242;
			$("#listing-sorts-content").css("left" , widthtohandle + "px");
		}
		else{
			if($("#listing-collections").length ) {
				var widthtohandle = $("#listing-collections").width() + 242;
				$("#listing-sorts-content").css("left" , widthtohandle + "px");
			}
		}
	}

	// Set min-width for listing sorts
	if( $("#listing-sorts").length ){
		var minwidthtohandle = $("#listing-sorts").width() + 10;
		$("#listing-sorts-content").css("width" , minwidthtohandle + "px");
	}

	// set ui-tabs bg
	if( $(".tabs").length ){
		var heighttohandle = $(".tabs ul").height() - 29;
		$(".tabs").css("background-position" , "0px " + heighttohandle + "px");
	}

	// set image for non-available variants
	if( $(".not-available").length ){
		$(".not-available").each( function() {
			var varianttohandle = $(this).attr("id");
			var variantwidthtohandle = $(this).width() + 8;
			var variantheighttohandle = $(this).height() + 8;
			$("#" + varianttohandle).append('<image src=' + window.location.protocol + '//' + window.location.hostname + '/ctlimg/Wolford/images/backgrounds/not_available.gif class="image-not-available" id="image-not-available-' + varianttohandle + '">');
			$("#image-not-available-" + varianttohandle).css("width" , variantwidthtohandle + "px");
			$("#image-not-available-" + varianttohandle).css("height" , variantheighttohandle + "px");
			$("#image-not-available-" + varianttohandle).css("display" , "block");
		});
	}

	// read-on sku detail
	if( $(".rest-slide-text").length ) {
		$(".read-on").show();

		$(".read-on").click( function() {
			var texttoadd = $(".rest-slide-text").text();
			$(".initial-slide-text").append(texttoadd);
			$(".read-on").hide();
			$(".read-less").css("display" , "block");
		});
	}

	// language selection positioning
	if($("#footer-language-content").length) {
		var topPosition = $("#footer-language-content").height();
		topPosition = 10 + topPosition;
		topPosition = "" + "-" + topPosition;
		topPosition = parseInt(topPosition);
		$("#footer-language-content").css("top",topPosition);
	}

	$(".dropdown-link").mouseover( function(){
		droplinktoopen = $(this).attr("id");
		headeringOverlayTrigger = $(this).attr("id");
		dropdowntoopen = droplinktoopen + "-content";

		$(this).addClass("active");
		$(this).addClass(droplinktoopen + "-active");

		$("body").find("#" + dropdowntoopen).show();
		$("body").find("#" + dropdowntoopen).addClass("shizzle");
	});

	$(".dropdown-link").mouseout( function(){

		droplinktoclose = $(this).attr("id")
		dropdowntoclose = droplinktoclose + "-content";

		$("body").find("#" + dropdowntoclose + "").hide();
		$("body").find("#" + dropdowntoclose).removeClass("shizzle");
		$("body").find("#" + droplinktoclose + "").removeClass("active");
		$("body").find("#" + droplinktoclose + "").removeClass(droplinktoclose + "-active");

	});

	$(".dropdown-content").mouseover( function(){
		$("#" + headeringOverlayTrigger + "").addClass("active");
		$("#" + headeringOverlayTrigger + "").addClass("" + headeringOverlayTrigger + "-active");
		$(this).show();
	});

	$(".dropdown-content").mouseout( function(){
		$("#" + headeringOverlayTrigger + "").removeClass("active");
		$("#" + headeringOverlayTrigger + "").removeClass("" + headeringOverlayTrigger + "-active");
		$(this).hide();
	});

	var siteMapInnerHtml = $("#siteMapStaticLinks").html();
	$(".right_col_content ul").each(function(){
		siteMapInnerHtml = siteMapInnerHtml + "<ul class='firstLevel'>" + $(this).html() + "</ul>";
	});
	siteMapInnerHtml = siteMapInnerHtml + "<span class='cleaner2'>&nbsp;</span>";
	$("#siteMapStaticLinks").html(siteMapInnerHtml);
	$("#siteMapStaticLinks").show();

	var colorLiCounter = 0;

	$("#listing-colors-content ul li").each(function(){
		colorLiCounter++;
	});

	if(colorLiCounter == 1){
		$("#listing-colors-content").css("width","104px");
	}
	else{
		if(colorLiCounter == 2){
			$("#listing-colors-content").css("width","208px");
		}
	}

	// store item
	initializeStoreItemFunctionalities();

	// browseCatalog
	initializeBrowseCatalogFunctionalities();

	// looks
	initializeLooksFunctionalities();

	// thickBox
	initializeThickBoxFunctionalities();

	// tooltip
	$(".jTip").tooltip({showURL: false,track:true,delay:0,top:0,left:25});

});

/************************ document ready / END ************************/

function updateOrdInstructionCounter(id,target) {
	var limit = 250;
	if(document.getElementById(id)) {
		var textAreaLength = document.getElementById(id).value.length;
		var limitAct = limit - textAreaLength;
		if(limitAct == 0 || limitAct < 0) {
			document.getElementById(id).value = document.getElementById(id).value.substring(0,249);
		}
		if(document.getElementById(target)) {
			document.getElementById(target).innerHTML = "" + limitAct + "";
		}
	}
}


/*
 * @params: itemTrigger  -> boolean true: Add item to users cart
 * 						 -> boolean false: Remove item from users cart
 * 			siIdToHandle -> String: Holds siId wich has to be added / removed
 * 			stp_Id		 -> Store purchase Id in case of logged on user
 * 			item_count	 -> The number of items in the basket
 * 			cltnbr		 -> String: The catalog we are using at the moment
 */

function handleGiftWrapItem(itemTrigger,siIdToHandle,cltnbr,vecid) {

	// initialise the servlets we want to use
	var sslPgNameAddStoreOrderItem = "/edealinv/servlet/AddStoreOrderItem";
	var sslPgNameDeleteStoreOrderItem = "/edealinv/servlet/DeleteStoreOrderItem";
	// get the actual item number of the shopping cart
	if(document.getElementById("correctedItemCountTarget")){
		var actualItemCount = document.getElementById("correctedItemCountTarget").innerHTML;
	}
	// switch to secure conntection if needed
	if(window.location.href.indexOf("https:") != -1){
		sslPgNameAddStoreOrderItem = "" + window.location.protocol + "//" + window.location.hostname + "/edealinv/servlet/AddStoreOrderItem";
		sslPgNameDeleteStoreOrderItem = "" + window.location.protocol + "//" + window.location.hostname + "/edealinv/servlet/DeleteStoreOrderItem";
		sslParameter = "&sslpg-control/BuildNewBasketOverview.vm=Y";
	}
	else{
		sslParameter = "&sslpg-control/BuildNewBasketOverview.vm=N";
	}

	/*
	 * Switch off all inputs t the page
	 */
	$("input").each(function(){
		$(this).attr("disabled",true);
	});

	/*
	 * Add the item to the basket
	 */
	if(itemTrigger) {
		// show loading event animation
		$("#expandable-1-content").addClass("loadingHint");

		// fire the asynchron request with needed data
		var timeStamp = new Date().getTime();
		var urlParameterList = "?ctl_nbr=" + cltnbr + "&vec_id=" + vecid + "&siId=" + siIdToHandle + "&giftWrapSiId=" + siIdToHandle + "&nurl=control/BuildNewBasketOverview.vm" + "&eurl=control/BuildNewBasketOverview.vm" + "&rurl=control/BuildNewBasketOverview.vm" + "&siQty=1" + "&timeStamp=" + timeStamp + sslParameter;

			var AddGiftWrapItem = new XHR
				(
					// HTTP method
					"GET",
					// URL
					sslPgNameAddStoreOrderItem + urlParameterList,
					// callbacks
					{
						success: function(request)
						{
					$("#expandable-1-content").html(request.responseText);

					// update the cart item number
					if(document.getElementById("correctedItemCountTarget")) {
						document.getElementById("correctedItemCountTarget").innerHTML = parseInt(actualItemCount) + 1;
					}

					// remove loading event animation
					$("#expandable-1-content").removeClass("loadingHint");
					// update the item count inside the minicart
					if (document.getElementById("minicartiframe")) {
						document.getElementById("minicartiframe").contentWindow.location.reload();
					}

					// Switch buttons on again
					$("input").each(function(){
						$(this).removeAttr("disabled");
					});
					//alert("success: " + request.responseText);

						},
						error: function(request)
						{
							alert("error: " + request.responseText);
						}
					}
				);
		AddGiftWrapItem.send();
	}

	/*
	 * Remove the item from the basket
	 */
	else {
		// get the item number of the item we want to delete (logged off user)
		if(document.getElementById("giftWrapItemOriId"))
			var oriId = document.getElementById("giftWrapItemOriId").value;
		// get the store purchase id of the item we want to delete (logged on user)
		if(document.getElementById("giftWrapStpId"))
			var stp_Id = document.getElementById("giftWrapStpId").value;
		// show loading event animation
		$("#expandable-1-content").addClass("loadingHint");
		// fire the asynchron request with needed data

		// fire the asynchron request with needed data
		var timeStamp = new Date().getTime();
		var urlParameterList = "?ctl_nbr=" + cltnbr + "&vec_id=" + vecid + "&siId=" + siIdToHandle + "&ori_id=" + oriId + "&stpId=" + stp_Id + "&giftWrapSiId=" + siIdToHandle + "&nurl=control/BuildNewBasketOverview.vm" + "&eurl=control/BuildNewBasketOverview.vm" + "&rurl=control/BuildNewBasketOverview.vm" + "&siQty=1" + "&timeStamp=" + timeStamp + sslParameter;

			var RemoveGiftWrapItem = new XHR
				(
					// HTTP method
					"GET",
					// URL
					sslPgNameDeleteStoreOrderItem + urlParameterList,
					// callbacks
					{
						success: function(request)
						{
					$("#expandable-1-content").html(request.responseText);

					// update the cart item number
					if(document.getElementById("correctedItemCountTarget")) {
						document.getElementById("correctedItemCountTarget").innerHTML = parseInt(actualItemCount) - 1;
					}

					// remove loading event animation
					$("#expandable-1-content").removeClass("loadingHint");
					// update the item count inside the minicart
					if (document.getElementById("minicartiframe")) {
						document.getElementById("minicartiframe").contentWindow.location.reload();
					}

					// Switch buttons on again
					$("input").each(function(){
						$(this).removeAttr("disabled");
					});
					//alert("success: " + request.responseText);

						},
						error: function(request)
						{
							alert("error: " + request.responseText);
						}
					}
				);
		RemoveGiftWrapItem.send();

	}
}

/*
 * Update CCFs after order creation or address book changes
 */

function doUpdateCCFs(clt_nbr,vec_id,field_0,field_1,field_2,field_3,field_4,field_5,field_6,field_7,field_8,field_9,field_10,field_11,field_12,field_13,field_14,field_15,field_16,field_17,field_18,field_19) {
	$(document).ready(function() {
		// do the update asynchron

		// initialise the servlets we want to use
		var sslPgNameAddUpdVECCustFieldValues = "/edealinv/servlet/AddUpdVECCustFieldValues";

		// switch to secure conntection if needed
		if(window.location.href.indexOf("https:")){
			sslPgNameAddUpdVECCustFieldValues = "" + window.location.protocol + "//" + window.location.hostname + "/edealinv/servlet/AddStoreOrderItem";
		}

		// fire the post
		$.post(sslPgNameAddUpdVECCustFieldValues,{ ctl_nbr: clt_nbr, vec_id: vec_id, nurl: "control/Blank.vm",field_0: field_0,field_1: field_1,field_2: field_2,field_3: field_3,field_4: field_4,field_5: field_5,field_6: field_6,field_7: field_7,field_8: field_8,field_9: field_9,field_10: field_10,field_11: field_11,field_12: field_12,field_13: field_13,field_14: field_14,field_15: field_15,field_16: field_16,field_17: field_17,field_18: field_18,field_19: field_19 });

	});
}

/*
 * product view switch tab one back on
 */

function showTabOneOnly(idFiredFrom) {

	// remove actual selected tab conditions
	$("#sku-tab-" + idFiredFrom + "").addClass("ui-tabs-hide");
	$("#sku-tab-heading-" + idFiredFrom + "").removeClass("ui-tabs-selected");

	// switch on tab one again and add needed classes
	$("#sku-tab-heading-1").addClass("ui-tabs-selected");
	$("#sku-tab-1").removeClass("ui-tabs-hide");
}
/*
function doThickBox(title, url){
	$(document).ready(function(){ tb_show(title, url, null); });
}
*/

function getUserStatus(){
	var allcookies = document.cookie;
	var flCustLogon = false;

	var cookieList = allcookies.split("; ");

	for(var i=0; i<cookieList.length; i++)
	{
		var mycookie = cookieList[i].split("=");
		var mycookieKey = mycookie[0];
		var mycookieVal = mycookie[1];

		if(mycookieKey == "EISESSION_ID")
		{

			if(!mycookieVal || mycookieVal == "")
			{
				flCustLogon = false;
			}
			else
			{
				flCustLogon = true;
			}
		}
	}

	return flCustLogon;

}

function handleWishlistView(){
	if(getUserStatus()){
		$("#wishListGuest").addClass("hide");
		$("#wishListUser").removeClass("hide");
	}
}

/*
 * global thickbox variables for delay
 */
var urlDelay = "";
var titleDelay = "";

function doThickBoxDelayed(){
	tb_show(titleDelay, urlDelay, null);
}

function doThickBox(title, url, siIdAdded, siQty, delay, variantQtyOnHold){

	/*
	 * If we have to submit an additional parameter we have to paste the value
	 * before the thick box parameters
	 */

	var posToCut = url.indexOf("?ct=");

	if(posToCut > 1 && siIdAdded != ""){
		var siIdAdded = String(siIdAdded);
		var siQty = parseInt(siQty);
		posToCut = posToCut + 1;
		url = url.substring(0,posToCut)+ "&siId=" + siIdAdded + "&siQty=" + siQty + "&variantQtyOnHold=" + variantQtyOnHold + "&" + url.substring(posToCut,url.length) ;
	}

	$(document).ready(function(){
		if(delay == "delay500"){
			urlDelay = url;
			titleDelay = title;
			window.setTimeout("doThickBoxDelayed()", 1000);
		}
		else
			tb_show(title, url, null);
	});
}

function sendEmailAFriendForm(theForm){

	if(theForm.sender_name && theForm.sender_fname && theForm.sender_lname){
		theForm.sender_name.value = theForm.sender_fname.value + " " + theForm.sender_lname.value;
	}

	theForm.submit();
}

function sendContactUsForm(theForm){

	if(theForm.cu_name && theForm.cu_fname && theForm.cu_lname){
		theForm.cu_name.value = theForm.cu_fname.value + " " + theForm.cu_lname.value;
	}

	theForm.submit();
}

function changeStorefrontLanguage(languageValue,ctl_nbr) {

	var oldShopURL = window.location.href;
	var newShopURL = null;

	// First we have to cut out any existing userLangISO parameter
	// may be the customer wants to switch languages on the same page again
	if(oldShopURL.indexOf("userLangISO") != -1) {
		var pos = oldShopURL.indexOf("userLangISO");
		pos = pos - 1;
		var nextPos = pos + 18;
		var oldShopURL = "" + oldShopURL.substring(0,pos) + oldShopURL.substring(nextPos,oldShopURL.length);
	}

	// Search for paramterlist in URL
	if(oldShopURL.indexOf("&") != -1) {
		// we have to add an amp;
		newShopURL = oldShopURL + "&userLangISO=" + languageValue;
	}
	else {
		// we have to add an ?
		newShopURL = oldShopURL + "?userLangISO=" + languageValue;
	}

	// now redirect to the former URL but with new user language
	window.location.href = newShopURL;
}

function escapeHTML(value){

	//	Cast to string
	var valueToReplace = "" + value;

	valueToReplace = valueToReplace.replace(/"/g,"&quot;");
	valueToReplace = valueToReplace.replace(/'/g,"&quot;");

	return valueToReplace;

}

function showDefaultCategoryImage(debugMode) {

	if(debugMode == "Y"){
		alert("in");
	}

	if(document.getElementById("content-noright") && document.getElementById("storeLocation")){
		var storeLocationDefault = document.getElementById("storeLocation").innerHTML;
		document.getElementById("content-noright").style.background = "url('" + window.location.protocol + "//" + window.location.hostname + "/ctlimg/Wolford/images/from_client/" + storeLocationDefault + "/categoryHeading/default.jpg') no-repeat";
	}

	headerImageAlreadyApplied = true;
}



function recalculateCommulatedPrice(lengthOfItems) {

	var commulatedItemTotal = 0;
	var floatValue = 0.00;

	for(var i = 1; i <= lengthOfItems; i++) {
		if($("#item-price-inner-" + i).html()) {
			floatValue = $("#item-price-inner-" + i).html().replace(",",".");
			commulatedItemTotal = commulatedItemTotal + ($("[@name=look-item-qty-" + i +"]").val() *  parseFloat(floatValue) );
		}
	}
	commulatedItemTotal = String(commulatedItemTotal.toFixed(2)).replace(".",",");
	$("#commulated-item-price").html(commulatedItemTotal);
}

function addLookToBasket(lengthOfItems,ctlnbr,theForm,masterSkuName) {

	var siIdString = "";
	var siIdStringSep = ""
	var qtyString = "";
	var qtyStringSep ="";
	var addItemsToBasket = true;

	for(var i = 1; i <= lengthOfItems; i++) {

		if($("#select-look-item-id-" + i).is(":checked")) {
			siIdString = siIdString + siIdStringSep + $("[@name=variant-SiId-" + i +"]").val();
			siIdStringSep = ",";
			qtyString = qtyString + qtyStringSep + $("[@name=look-item-qty-" + i +"]").val();
			qtyStringSep = ",";
		}

		if(parseInt($("[@name=look-item-qty-" + i +"]").val()) > parseInt($("[@name=look-variant-qty-avail-" + i +"]").val())) {
			addItemsToBasket = false;
			doThickBox('',''+ window.location.protocol + '//' + window.location.hostname +'/edealinv/servlet/ExecMacro?nurl=control/Thickbox.vm&amp;ctl_nbr=' + ctlnbr + '&ct=addedToCart&amp;omni_scAdd=scAdd&amp;keepThis=true&amp;TB_iframe=true&amp;height=350&amp;width=310',$("[@name=variant-SiId-" + i +"]").val(),$("[@name=look-item-qty-" + i +"]").val(),'delay500',$("[@name=look-variant-qty-avail-" + i +"]").val());
		}
	}

	if(theForm) {
		theForm.action = "/edealinv/servlet/AddStoreOrderItem";
	}

	if(theForm) {
		theForm.target = "minicartiframe";
	}

	if(theForm.nurl){
		theForm.nurl.value = "control/MiniCart.vm";
	}

	if(theForm.eurl){
		theForm.eurl.value = "control/MiniCart.vm";
	}

	if(theForm.ourl){
		theForm.ourl.value = "control/MiniCart.vm";
	}

	if(theForm.siId){
		theForm.siId.value = siIdString;
	}

	if(theForm.siQty){
		theForm.siQty.value = qtyString;
	}

	if(siIdString != "" && qtyString != "" && addItemsToBasket) {
		theForm.submit();
		doThickBox('',''+ window.location.protocol + '//' + window.location.hostname +'/edealinv/servlet/ExecMacro?nurl=control/Thickbox.vm&amp;ctl_nbr=' + ctlnbr + '&ct=addedToCart&amp;omni_scAdd=scAdd&amp;keepThis=true&amp;TB_iframe=true&amp;height=350&amp;width=330',siIdString,1,'delay500',1);
	}

}

function handeLookCheckBoxEvent(numberOfCheckbox,lengthOfItems){
	if($("#select-look-item-id-" + numberOfCheckbox).is(":checked")) {
		$("[@name=look-item-qty-" + numberOfCheckbox +"]").val("1");
	}
	else {
		$("[@name=look-item-qty-" + numberOfCheckbox +"]").val("0");
	}
	recalculateCommulatedPrice(lengthOfItems);
}

function navigationViewSwitch(idToSwitch) {
	if(jQuery("#" + idToSwitch).hasClass("sidebar-down")){
		jQuery("#" + idToSwitch).removeClass("sidebar-down");
		jQuery("#" + idToSwitch).addClass("sidebar-up");
		jQuery("#" + idToSwitch + "-content").hide("slow");
	}
	else {
		jQuery("#" + idToSwitch).removeClass("sidebar-up");
		jQuery("#" + idToSwitch).addClass("sidebar-down");
		jQuery("#" + idToSwitch + "-content").show("slow");
	}
}


function convertLineBreaks(id){
	jQuery("[@name=" + id + "]").val(jQuery("[@name=" + id + "]").val().replace(/\n/g,'%0A'))
}