function getFormObject(objectName){return document.forms[objectName];};
function getHTMLObject(objectName){return document.getElementById(objectName);};
function hideItem(theItem){getHTMLObject(theItem).style.display	= "none";};
function showItem(theItem){getHTMLObject(theItem).style.display	= "block";};
function toggleShowItem(theItem){
	if(getHTMLObject(theItem).style.display	== "block"){
		getHTMLObject(theItem).style.display	= "none";
	}else{
		getHTMLObject(theItem).style.display	= "block";	
	}
};
function setBookmark(url,title){
	if(document.all){
		window.external.AddFavorite(url, title);
	}
	else if(window.sidebar){
		window.sidebar.addPanel(title, url, "");
	}
	else if(window.print && window.opera){
		var bmLink = document.createElement('a');
		bmLink.setAttribute('href',url);
		bmLink.setAttribute('title',title);
		bmLink.setAttribute('rel','sidebar');
		bmLink.click();
	} 
	else{
		if(editionLCID==1053){
			alert("Vi saknar tyvärr direktlänk för att lägga till bokmärket i den webbläsare du använder.");	
		}else{
			alert("Unfortunatly we were not able to add the bookmark directly to the browser you are using.");	
		}
	}
}
var captchaField 		= "";
var captchaForm			= "";
var captchaFormTrigger 	= "";
var captchaFormMessage	= "";
var captchaValidField	= "";

function validateCaptchaInput(formTrigger){
	
	var hiddenVal 	= captchaForm.find("#captchaRandom").val();
	var inputVal 	= captchaField.val();
	var indicator	= captchaForm.find(".capthcaCheck");

	indicator.css({"background-image" : "url(http://www.smode-resource.se/gfx/icons/ajax-loader.gif)"});

	if(captchaValidField.val()==1){
		return captchaOk();
	}else{
		if(inputVal.length==4){
			$.ajax({
			  type: "GET",
			  url: "/core/coreSrc/modules/captcha/ajax-validate.asp",
			  data: "inputVal="+inputVal+"&hiddenVal="+hiddenVal,
			  contentType: "text/html; charset=iso-8859-1",
			  error : function(data,string) {alert(string);},
			  success : function (data) {
				  var theResult = Math.floor(data);
				  if(theResult==-1){
					  indicator.css({"background-image" : "url(http://www.smode-resource.se/gfx/icons/check.gif)"});
					  return captchaOk();
					}else{
					  indicator.css({"background-image" : "url(http://www.smode-resource.se/gfx/icons/action_refresh.gif)"});
					 return captchaInvalid();
				  }
				}
			});
		}else{
			  indicator.css({"background-image" : "url(http://www.smode-resource.se/gfx/icons/action_refresh.gif)"});
			return captchaInvalid();
		}
	}
}
function captchaOk(){
	 captchaField.removeClass("swlValidationError");
	 captchaField.addClass("swlValidationOk");
	 captchaValidField.val("1");
	 captchaField.attr("disabled","disabled");
	 captchaShowSubmit();
	 return true;
}
function captchaInvalid(){
	 captchaField.removeClass("swlValidationOk");
	 captchaField.addClass("swlValidationError");
	 captchaValidField.val("0");
	 captchaHideSubmit();
	return false;
}
function captchaHideSubmit(){
	 captchaFormTrigger.after(captchaFormMessage);
	 captchaFormTrigger.hide();
}
function captchaShowSubmit(){
	 captchaFormMessage.remove();
	 captchaFormTrigger.show();
}
function validateComment(){
	
	var errMess 	= "";
	var fldName		= $("#userName");
	var fldEmail	= $("#userEmail");
	
	if(fldName.val().length<2){
		fldName.addClass("formAttention");
		if(editionLCID==1053){
		  errMess += "- Ditt namn\n";
			}else{
		  errMess += "- Your name\n";
		}
	}else{fldName.removeClass("formAttention");}
	
	if(fldEmail.val().length<2){
		fldEmail.addClass("formAttention");
		if(editionLCID==1053){
		  errMess += "- Din e-postadress\n";
			}else{
		  errMess += "- Your e-mail\n";
		}
	}else{fldEmail.removeClass("formAttention");}

	if(errMess.length>2){
		if(editionLCID==1053){
		  errMess = "Vänligen ange obligatoriska uppgifter:\n" + errMess;
			}else{
		  errMess = "Please enter:\n" + errMess;
		}
		alert(errMess);
		return false;
	}else{
		return true;	
	}
}
function removeGenericConfirm(theURL,theMessage){
	if(confirm(theMessage)){
		document.location=theURL;
	}
}
function ajaxRenewSession(){
	if($(".ajaxRenewLoginSession").is('*')){
		var theKey		= escape($(".ajaxRenewLoginSession > .key").text());
		var theRandom	= escape($(".ajaxRenewLoginSession > .rnd").text());
		var theSalt		= escape($(".ajaxRenewLoginSession > .salt").text());
		var theDate		= $(".ajaxRenewLoginSession > .dte").text();
		
		if(theKey.length>0 && theRandom.length>0 && theSalt.length>0 && theDate.length>0){
		   $(".ajaxRenewLoginSession").load("/core/coreSrc/ajax/renew-session.asp",{randomInt : theRandom, keyStr : theKey, saltInt : theSalt, timeDate: theDate}, function(){});
		   setTimeout('ajaxRenewSession()',60000);
		}
	}
}
function hideSystemMessage(){
	if($("div.systemMessageBox").is('*')){
	   $("div.systemMessageBox").fadeOut('slow');
	}
}
function clockSystemMessage2010(){
	var delayBox = $(".system-message-container").find(".delay");
	var newDelay = Math.floor(delayBox.html())-1;
	
	var doCount	 = !$(".pause-delay").is("*");
	if(newDelay > 0 && doCount){
		delayBox.html(newDelay);
		setTimeout('clockSystemMessage2010()',1000);
	}else{
		if(doCount){
			$(".system-message-container").fadeOut("slow");	
		}else{

		}
	}
}
function userAutoCompleteFill(tempName,tempId,destinationField,valueField){
	$("input#"+destinationField).val(tempId);
	$("input#"+valueField).val(tempName);
	$("div#autoComplete"+destinationField).slideUp("slow");
}

$(function(){
/* ADMIN-PANEL */
$("#adminToolBoxToggler").toggle(function () {
	$("#adminToolBox").slideDown("slow");
},function () {
	$("#adminToolBox").slideUp("slow");
}); 

$("#article_teaser").add("#activity_teaser").change(function(){
	var teaserField = $(this);
	teaserField.parents("form").find("#sharing_message").val(teaserField.val());
});
$("img.resizeAjax").each(function(){
	var theImage	= $(this);
	var originalSrc = theImage.attr("src");
	theImage.attr({"src" : "http://www.smode-resource.se/gfx/icons/ajax-loader.gif"});
	var newWidth 	= theImage.attr("width");
	var theHeight 	= theImage.height();
	$.ajax({
	  type: "GET",
	  url: "/core/coreSrc/ajax/resize-image.asp",
	  data: "width="+newWidth+"&path="+originalSrc+"&height="+theHeight,
	  contentType: "text/html; charset=iso-8859-1",
	  success : function (data) {
			theImage.attr({"src" : data});
		  }
	})
});
$(".colBoxContainer > .top").click(function () {
	var theContentBox 	= $(this).parent().find(".content");
	var theIcon 		= $(this).find(".icon");
	
	if(theContentBox.is(":visible")){
		theContentBox.slideUp("fast");
		if(theIcon.is(".visible")){
			theIcon.removeClass("visible");
		}else{
			theIcon.addClass("visible");
		}
	}else{
		theContentBox.slideDown("fast");
		if(theIcon.is(".visible")){
			theIcon.removeClass("visible");
		}else{
			theIcon.addClass("visible");
		}
	}
});
$(".moduleBoxContainer > .top").toggle(function () {
	$(this).parent().find(".content").slideUp("slow");
},function () {
	$(this).parent().find(".content").slideDown("slow");
}); 
$(".horizontal-colboxes").each(function(){
	var maxColBoxHeight	= 0;
	var currColBoxRow 	= $(this);
	var currBoxes		= currColBoxRow.find(".colBoxContainer,.unformated-messageBox-container");
	var boxCount		= currBoxes.length;
	var i				= 0;
	currBoxes.find(".content,.art-blockcontent,.art-Blockcontent,.unformated-messageBox").each(function(){
		var currBox 	= $(this);
		var currHeight 	= currBox.height();
		if(currHeight>maxColBoxHeight){maxColBoxHeight=currHeight}
	});														   
	currBoxes.find(".content,.art-blockcontent,.art-Blockcontent,.unformated-messageBox").each(function(){
		var currBox		= $(this);
		var currParent	= currBox.parents(".colBoxContainer");
		currBox.height(maxColBoxHeight);

		i++; if(i==boxCount){
			if(currParent.is("*")){
				currParent.addClass("last-colbox")						
				}else{
				currBox.addClass("last-colbox")		
			}
			
		};
	});														   
});


$(".stlth-field").hide();

	captchaField 		= $("#captchaValue");

if(captchaField.is("*")){
	captchaForm			= captchaField.parents("form");
	captchaFormTrigger 	= captchaForm.find(".formSubmitTrigger");
	captchaValidField 	= captchaForm.find("#captcha-is-validated");
	captchaValidField.val(0);
	
	if(editionLCID==1053){
	  captchaFormMessage	= $("<div id='captchaMessage'>Vänligen ange korrekt skräppostkod ovan innan du fortsätter.<br>Klicka på de gröna pilarna för att verifiera koden.</b>");
		}else{
	  captchaFormMessage	= $("<div id='captchaMessage'>Please enter the captcha-code above to continue.<br>To verify your code, press the green arrows.</b>");
	}
	
	captchaForm.submit(function(){return false;});
	captchaField.change(function(){validateCaptchaInput();});
	captchaHideSubmit();
}
$("input#userNewPassword").add("input#new_psw").val("")
$(".autoEmpty").find("input").focus(function () {$(this).val("");});
$(".password-change-field > input").change(function(){
	var message = "";
	editionLCID==1053 ? message="Detta kommer att skriva över ditt befintliga lösenord, vill du fortsätta?" : message="This will replace your current password, would you like to continue?";
	if(confirm(message)){}else{$(this).val("");}
});
$(".colBoxContainer,.unformated-messageBox").find("img").each(function(){

	var currImgLink = $(this);
	currImgLink.hover(function(){
			currImgLink.addClass("colbox-image-hover");
			currImgLink.css({"opacity" : "0.7"});
		},function(){
			currImgLink.removeClass("colbox-image-hover");
			currImgLink.css({"opacity" : "1"});
	});
	
});
var editorTable = $("table#idAreaoEdit1");
if(editorTable.is("*")){
	var editorContainer 	= editorTable.parent();
	var editorContHeader	= editorContainer.parent().find("#"+editorContainer.attr("id")+"_header");
	var pageWidth 			= editorTable.parent().parent().width();
	var editorWidth			= pageWidth.toString()+"px";
	var headerWidth			= pageWidth-24;
		headerWidth			= headerWidth.toString()+"px";
	editorContainer.css({"width": editorWidth, "padding" : "0px", "border" : "0"});
	editorContHeader.css({"width": headerWidth});
}

$(".ajaxFormLoader").removeClass("ajaxFormLoader");
$(".date1 > input").change(function(){
	var date1 	= $(this);
	var date2 	= date1.parents(".formGroup").find(".date2 > input");
		
	$.ajax({
	  type: "GET",
	  url: "/core/coreSrc/ajax/next-day-date.asp",
	  data: "sDate="+date1.val()+"&x="+Math.random(99999),
	  contentType: "text/html; charset=iso-8859-1",
	  error : function(data,string) {date2.val(date1.val());},
	  success : function (data) {
			date2.val(data);
		  }
	});	
});
if($("div.imageSwitcher").is("*")){
var switchImages = $("div.imageSwitcher img");   
switchImages.each(function(index){
	var currentImage = $(switchImages[index]);
	currentImage.hide();
	currentImage.click(function(){
		switchImages.hide();
		if(index==(switchImages.size()-1)){
			$(switchImages[0]).show();
		}else{
			$(switchImages[index+1]).show();					
		}
	});
});
$(switchImages[0]).show();
}
if($(".lightboxGallery").is("*")){
	var thumbs 			= $(".lightboxGallery > img");
	var overlay 		= $("<div class='lightboxOverlay'></div>");
	var container 		= $("<div class='lightboxContainer'></div>");
	var viewPort		= $("<div class='lightboxViewport'></div>");
	var captionBox		= $("<div class='lightboxCaption'></div>");
	var navRow			= $("<div class='lightboxNavigation'></div>");
	var closeBtn		= $("<span class='closeBtn btn'>×</span>");
	var prevBtn			= $("<span class='prevBtn btn'>«</span>");
	var nextBtn			= $("<span class='nextBtn btn'>»</span>");
	var winH			= $(window).height();
	var winW			= $(window).width();
	var currentImage	= 0;
	
	$("body").append(overlay).append(container);
	container.append(navRow).append(viewPort).append(closeBtn).append(captionBox);
	navRow.append(prevBtn).append(nextBtn);
	container.show().css({"top": Math.round((winH-container.outerHeight())/2) + "px","left": Math.round((winW-container.outerWidth())/2) + "px"}).hide();

	thumbs.each(function(index){
	 $(this).click(function(){overlay.css({"opacity" : 0.8, "height" : $(document).height()+"px"}); overlay.add(container).fadeIn("slow"); loadImage(index);});
	 $(this).attr({"image-index": index});
	});

	function loadImage(imageIndex) {
	  container.addClass("loadingImage");
	  
		var newImage = thumbs.eq(imageIndex);	
		var img = new Image();
			img.onload = function() {
			img.style.display = "none";
		
			var maxWidth = winW-20-100;
			var maxHeight = winH-20-200; 
			if(img.width > maxWidth || img.height > maxHeight){
				var ratio = img.width / img.height;
				if(img.height >= maxHeight) {
					img.height = maxHeight;
					img.width = maxHeight*ratio;
				}else{
					img.width = maxWidth;
					img.height = maxWidth*ratio;
				}
			}
			navRow.css({"width" : img.width+"px", "top" : img.height/3 +"px","opacity" : 0.7});
			container.animate({"width": img.width,"height": img.height,"top": Math.round((winH - img.height - 20)/2) + "px","left": Math.round((winW - img.width - 20)/2) + "px"},
								"normal", function(){
									viewPort.append(img);
									$(img).fadeIn("normal",function(){
										captionBox.html((currentImage+1)+" / "+thumbs.size()+"<br/>"+newImage.attr("alt"));
										container.removeClass("loadingImage");
										container.animate({"height": container.height() + captionBox.height() + 30},"fast", function(){
											captionBox.fadeIn("fast",function(){closeBtn.fadeIn("fast",function(){navRow.fadeIn("fast");});});
										});
									});
			});
			
			
		} 
		img.src = newImage.attr("src");
		thumbs.filter(".selected").removeClass("selected");
		newImage.addClass("selected");
		currentImage = parseInt(thumbs.filter(".selected").attr("image-index"));
		$.scrollTo("0px",800);
	}

	closeBtn.add(overlay).click(function(){
		viewPort.children().fadeOut("normal",function(){viewPort.children().remove();});
		overlay.add(container).add(closeBtn).add(captionBox).fadeOut("normal");
	});

	nextBtn.add(prevBtn).click(function(){
		navRow.hide();
		closeBtn.fadeOut("fast",function(){captionBox.fadeOut("fast");});
		viewPort.children().fadeOut("normal",function(){viewPort.children().remove();});
		if($(this).is(".prevBtn")){
			loadImage(currentImage == 0 ? thumbs.size()-1 : currentImage-1);
		}else{
			loadImage(currentImage == (thumbs.size()-1) ? 0 : currentImage+1);
		}
	});
}
$("form#loginForm").keydown(function (event) {
	if(event.keyCode == 13){
		$(this).parent().find("form")[0].submit();
		$(this).parent().html("Loading...").css({height : "60px", padding : "30px"}).addClass("AJAXloading").css("background-color","#fff");
	}
});
	   
$("#swlLoginA").click(function () {
		$(this).parent().parent().parent().find("form")[0].submit();
		$(this).parent().parent().parent().html("Loading...").css({height : "60px", padding : "30px"}).addClass("AJAXloading").css("background-color","#fff");
});

$("input#remind").click(function(){
	var pswBox = $(this).parent().parent().find("div.loginPassword");
	
	if(editionLCID==1053){
		var remindBtnTxt 	= "Begär lösenord";
		var loginBtnTxt		= "Logga in";
	}else{
		var remindBtnTxt 	= "Request password";
		var loginBtnTxt		= "Login";
	}
	
	if($(this).is(":checked")){
		pswBox.slideUp("fast")
		$("#swlLoginA").html(remindBtnTxt);
	}else{
		pswBox.slideDown("fast")
		$("#swlLoginA").html(loginBtnTxt);
	}
});
ajaxRenewSession();
if($("#mainHoverMenu").is('*')){
	$(".menu.level1").superfish({
		hoverClass:    "hover-menu",
		delay:         500,
		animation:     {height:"show"},
		speed:         "fast",
		autoArrows:    true,
		dropShadows:   true,
		disableHI:     false
	});
}
var showHideBox = $(".show-hide-container");
if(showHideBox.is("*")){
	showHideBox.find(".trigger-link").css({"cursor" : "pointer"});
	showHideBox.find(".trigger-link").toggle(function(){
		$(this).parents(".show-hide-container").find(".hidden-content").slideDown("normal");
	  },function(){
		$(this).parents(".show-hide-container").find(".hidden-content").slideUp("slow");
	});
}
var slideShow				= $(".slideShowGallery");
if(slideShow.is("*")){
	
	slideShow.each(function(index){
		var slideShowCurrentImage	= 0;
		var slideShowSpeed			= 1000;	
		var tempSlideShow 			= $(this);
		var slideShowThumbs			= tempSlideShow.find("img");
		var slideShowSpeedConfig 	= tempSlideShow.find(".slide-show-config-speed > .config-val");

		slideShowThumbs.each(function(index){$(this).attr({"image-index": index});});
		if(slideShowSpeedConfig.is("*")){slideShowSpeed	= slideShowSpeedConfig.text();}
		slideShowSpeed = (slideShowSpeed < 700 ? 700 : slideShowSpeed)
		
		slideShowLoadImage(0,slideShowThumbs,slideShowSpeed);
		
		if(slideShowThumbs.size()>1){
		  setInterval(function(){
			var selectedImage 		= slideShowThumbs.filter(".selected");
			slideShowCurrentImage 	= parseInt(selectedImage.attr("image-index"));
			tempSlideShow.css({"height" : selectedImage.height()+"px"});
			selectedImage.removeClass("selected");
			slideShowCurrentImage = (slideShowCurrentImage == (slideShowThumbs.size()-1) ? 0 : slideShowCurrentImage+1);
			selectedImage.fadeOut(slideShowSpeed/2.3,function(){slideShowLoadImage(slideShowCurrentImage,slideShowThumbs,slideShowSpeed);});
		  },slideShowSpeed*4)
		}
	});
	
}
function slideShowLoadImage(index,theThumbs,theSpeed){
	$(theThumbs[index]).addClass("selected").fadeIn(theSpeed*1.2);
}

var systemMessage = $(".system-message-container");
if(systemMessage.is('*')){
	var	messageDelay = Math.floor(systemMessage.find(".delay").text())*1000;
    systemMessage.fadeIn("slow");
	setTimeout('clockSystemMessage2010()',1000);
}
$(".system-message-box > .close").click(function(){systemMessage.fadeOut("slow");});
$(".system-message-box > .pause").click(function(){systemMessage.append("<span class='pause-delay'></span>");});
if($("div.systemMessageBox").is('*')){
   $("div.systemMessageBox").fadeIn("slow");
   $("div.systemMessageBox").animate({opacity: 0.7}, 2500);
}
setTimeout('hideSystemMessage()', 3000);
if($("table#mainDataTable").is('*')){
  if($("table#mainDataTable").tablesorter!=undefined){	
	$("table#mainDataTable").tablesorter({
		 widgets: ['zebra']	
	});
   }
}
$("a.toolActivator").toggle(function () {
	$("div.toolTip",this).show("slow");
},function () {
	$("div.toolTip",this).hide("slow");
}); 
$(".helpIcon").toggle(function(){
		$(this).parent().find(".helpBox").slideDown("fast");
	},function(){
		$(this).parent().find(".helpBox").slideUp("slow");			
});
$(".swlUserPicker > input.inputUserAutoComplete").focus(function () {
	if ($(this).val()=="Sök användare här"){
		$(this).val("");
		$(this).parent().find("input.destinationField").val("0");
	}
});
$(".swlUserPicker > input.inputUserAutoComplete").keyup(function () {
  userInputStr 	= this.value;
  userField 	= $(this);
  destField		= userField.parent().find("input.destinationField").attr("id");
  valueField	= userField.attr("id");	  
  
	if(userInputStr.length>2){
		$.ajax({
		url : "/core/coreSrc/ajax/user-picker.asp",
		data : "userSearch="+userInputStr+"&desinationField="+destField+"&valueField="+valueField,
		error : function(data,string) {alert(string);},
		success : function (data) {
			userField.parent().find("div.autoCompleteContainer").slideDown("fast").animate({opacity: "0.8"}, "fast").html(data);
			}		
		});
	}
});
$(".swlUserPicker > input.inputUserAutoComplete").change(function () {
	if ($(this).val().length==0){
		$(this).val("Ingen användare vald");
		$(this).parent().find("input.destinationField").val("0");
	}
	$("div#autoComplete"+$(this).parent().find("input.destinationField").attr("id")).slideUp("slow");		
});
// CASHIER
/* --------------------------------------------------------------------- */
	$(".termsAcceptance").toggle(function(){
			$(".confirmOrder").slideDown("slow");
			$(".termsAcceptance").addClass("accepted");
			$(".confirmTerms").slideUp("fast");
		},function(){
			$(".confirmOrder").slideUp("fast");
			$(".confirmTerms").slideDown("slow");
			$(".termsAcceptance").removeClass("accepted");
	});
	$(".confirmOrder").hover(function(){
			$(this).addClass("hovered");
		},function(){
			$(this).removeClass("hovered");
	});

	$(".confirmOrder").click(function(){
		var theForm			= $("#cashierForm");
		var thePass			= $("#thePass").val();
		var orderID			= $("#orderid").val();
		var orderAmount		= $(".total-cart-sum:first").text();
			orderAmount		= Math.floor(orderAmount.replace(/\D/g,""));
			$("#amount").val(orderAmount);
		var custID			= $("#cust_id").val();
		var custCompany		= $("#cust_company").val();
		var custName		= $("#cust_name").val();
		var custStreet1		= $("#cust_address1").val();
		var custStreet2		= $("#cust_address2").val();
		var custZipCode		= $("#cust_zip").val();
		var custCity		= $("#cust_city").val();
		var custPhone		= $("#cust_phone").val();
		var custEmail		= $("#cust_email").val();
		var payMeth			= $("input[@name='pay_method']:checked").val();
		var actionURL		= "";
		
		if(orderAmount<1){window.location = "/";}

		if(custName.length<2 || custStreet1.length<2 || custZipCode.length<2 || custCity.length<2 || custEmail.length<2){
			alert("Vänligen ange alla obligatoriska kunduppgifter.");
		}else{

			var dataString 	 = "x="+Math.random(9999);
				dataString 	+= "&orderID=" 				+ orderID;
				dataString 	+= "&orderAmount=" 			+ orderAmount;
				dataString 	+= "&customerID=" 			+ custID;
				dataString 	+= "&customerCompany=" 		+ custCompany;
				dataString 	+= "&customerName=" 		+ custName;
				dataString 	+= "&customerStreet1=" 		+ custStreet1;
				dataString 	+= "&customerStreet2=" 		+ custStreet2;
				dataString 	+= "&customerZipCode=" 		+ custZipCode;
				dataString 	+= "&customerCity=" 		+ custCity;
				dataString 	+= "&customerPhone=" 		+ custPhone;
				dataString 	+= "&customerEmail=" 		+ custEmail;
				dataString 	+= "&paymentMethod=" 		+ payMeth;
				dataString 	+= "&theKey="				+ thePass;

			if(payMeth=="Kortbetalning via Certitrade"){
				actionURL = $("#ct_auth_url").val();
				$("#result_code").val("");
			}else{
				actionURL = $("#retururl").val();
				$("#result_code").val("00");
			}

			$.ajax({
			  type: "GET",
			  url: "/_project/_public/modules/webshop/public/ajax/saveOrder.asp",
			  data: dataString,
			  contentType: "text/html; charset=iso-8859-1",
			  error : function(data,string) {alert(string);},
			  success : function (data) {
					$("#md5code").val(data);			  
					theForm.attr({"action" : actionURL});
					theForm.submit();
				  }
			});
			
		}

	});
$(".product-link").click(function(){
	var theLink	= $(this).attr("href");
	document.location = theLink;
});
// CART
/* --------------------------------------------------------------------- */
	bindCartEvents()
	function bindCartEvents(){
		$(".removeProduct").bind("click", function(){minusProductInCart($(this));});
		$(".emptyCart").bind("click", function(){emptyCart($(this));});
	}
	/* ---------------------- */

	function minusProductInCart(productPost){
		var dataString 	= "x="+Math.random(9999)+"&";
			dataString 	= dataString + "cartPostID="+productPost.find(".cartPostID").text();
			dataString 	= dataString + "&productID="+productPost.find(".productID").text();
		var orderId 	= $(".currentOrderID").text();
		productPost.hide("fast");
		$.ajax({
		  type: "GET",
		  url: "/_project/_public/modules/webshop/public/ajax/removeProduct.asp",
		  data: dataString,
		  contentType: "text/html; charset=iso-8859-1",
		  error : function(data,string) {alert(string);},
		  success : function (data) {
				reloadCart(orderId);
			  }
		});
	}

	function emptyCart(productPost){
		var orderId 	= $(".currentOrderID").text();
		var dataString 	= "x="+Math.random(9999)+"&orderId="+orderId;
		productPost.hide("fast");
		$.ajax({
		  type: "GET",
		  url: "/_project/_public/modules/webshop/public/ajax/emptyCart.asp",
		  data: dataString,
		  contentType: "text/html; charset=iso-8859-1",
		  error : function(data,string) {alert(string);},
		  success : function (data) {
				reloadCart(orderId);
			  }
		});
	}

	function reloadCart(order_id){
		var cartSnippet = $(".webshopCart");
		var dataString 	 = "x="+Math.random(9999)+"&orderID="+order_id;
		cartSnippet.fadeOut("fast");
		$.ajax({
		  type: "GET",
		  url: "/_project/_public/modules/webshop/public/ajax/loadCart.asp",
		  data: dataString,
		  contentType: "text/html; charset=iso-8859-1",
		  error : function(data,string) {alert(string);},
		  success : function (data) {
				cartSnippet.html(data).fadeIn("slow");
				bindCartEvents();
			  }
		});
	}

// SELECT MODEL/COLOR/SIZE
/* --------------------------------------------------------------------- */
	bindProductEvents($(this))
	function bindProductEvents(domSpace){
		domSpace.find(".addToCartBtn > .label").bind("click", function(){
			addProductToCart($(this));
		 });		
		domSpace.find(".prodSelector.color > select").bind("change",function(){
			var theMenu = $(this);
			theMenu.parent().parent().find("#prodColor").text(theMenu.val());
		});
		domSpace.find(".prodSelector.size > select").bind("change",function(){
			var theMenu = $(this);
			theMenu.parent().parent().find("#prodSize").text(theMenu.val());
		});

	}


// BUY BUTTON
/* --------------------------------------------------------------------- */
	function addProductToCart(label){
		var button			= label.parent();
		var ajaxScript		= button.find(".ajaxScriptAdd").text();
		var checksum		= button.find(".checksum").text();
		var dataString 	 	= "x="+Math.random(9999);
		var inputColor		= button.find(".prodSelector.color").is("*");
		var inputSize		= button.find(".prodSelector.size").is("*");
		var alertError		= "";
		var orderId 		= $(".currentOrderID").text();
		
		if(inputColor==true){
			if(button.find("#prodColor").text().length<1){alertError += "* Välj en färg!\n";}
		}
		if(inputSize==true){
			if(button.find("#prodSize").text().length<1){alertError += "* Välj en storlek!\n";}
		}

		if(alertError.length>0){alert(alertError);}else{
		  button.slideUp("fast");
			$(".prodVal",button).each(function(){
				var tempVal = $(this);
				dataString 	+= "&"+tempVal.attr("id")+"="+ tempVal.text();
			});
				dataString 	+= "&checksum="+checksum;
			
			$.ajax({
			  type: "GET",
			  url: ajaxScript,
			  data: dataString,
			  contentType: "text/html; charset=iso-8859-1",
			  error : function(data,string) {window.location="/?";},
			  success : function (data) {
					reloadCart(orderId);
					button.parent().find(".appendMessage").show();
					button.slideDown("slow");
				  }
			});
		}
	}

});

