﻿/*
This function will call the webservice to ADD,REMOVE and UPDATE the current Basket.Then it will rewrite the inner html of the ID "" 
*/

function calctot(tot,freight,prdcount,qntycnt)
{
	//alert(document.getElementById("totalpriceforTeaser").value);
	if(tot >= 350 && tot < 500 && freight > 0)
	{
	var targetprice = 500;   
        var diffprice = targetprice - tot ;
        var message="Om du handlar för  " + diffprice + " kr till så bjuder vi på frakten!";
        document.getElementById('text_area').innerHTML=message;

        var popmessage= '<h3>'+"Fri frakt!?"+'</h3>' +"Om du handlar för " +'<b>'+ diffprice +" kr till "+'</b>'+ "så bjuder vi på frakten!";
        var popclose= "Stäng";
        var body = document.body;
        var hoverPopup = document.createElement("div");
        hoverPopup.className = "freeshippop";
        hoverPopup.setAttribute("id", "hover_img_shipping");
        var hoverContainer = '';
        hoverContainer += '<div class="freeshippop_cvr" onclick="CloseShipPopup()">';
        hoverContainer += '<div class="ship_pop_cvr1">';
        hoverContainer += '     <div class="ship_pop_cvr2">';
        hoverContainer += '          <div class="ship_pop">';
        hoverContainer += '               <img src="/designtorget/upload/images/templates/webbshop/teaser_img_big.png"/>';
        hoverContainer += '               <div id="pop_text_area">' + popmessage + '</div>';
        hoverContainer += '               <a class="spopclosebut"></a>';
        hoverContainer += '          </div>';
        hoverContainer += '          <a class="spopclose">' + popclose + '</a>';
        hoverContainer += '     </div>';
        hoverContainer += '</div>';
        hoverContainer += '</div>';
        hoverPopup.innerHTML = hoverContainer;
        body.insertBefore(hoverPopup, body.firstChild);

	 }
	 if(prdcount == 2 && qntycnt <= 1)
	 {
	  // var abroadmessage='<span class="semsg">'+"Just nu levererar vi endast inom Sverige!"+'</span>'+'<span class="enmsg">'+"Currently we only deliver within Sweden!"+'<span>';
	     document.getElementById('text_area').innerHTML=abroadordmsg; 
	    //var popmessage1= '<h2 style="font-size:9px;">'+abroadordmsg+'</h2>';
        var popclose1= "Stäng";
        var body = document.body;
        var hoverPopup1 = document.createElement("div");
        hoverPopup1.className = "freeshippop";
        hoverPopup1.setAttribute("id", "hover_img_shipping");
        var hoverContainer1 = '';
        hoverContainer1 += '<div class="freeshippop_cvr" onclick="CloseShipPopup()">';
        hoverContainer1 += '<div class="ship_pop_cvr1">';
        hoverContainer1 += '     <div class="ship_pop_cvr2">';
        hoverContainer1 += '          <div class="ship_pop">';
        hoverContainer1 += '               <img src="/designtorget/upload/images/templates/webbshop/teaser_img_big.png"/>';
        hoverContainer1 += '               <div id="pop_text_area" class="newpopup">' + abroadordmsg + '</div>';
        hoverContainer1 += '               <a class="spopclosebut"></a>';
        hoverContainer1 += '          </div>';
        hoverContainer1 += '          <a class="spopclose">' + popclose1 + '</a>';
        hoverContainer1 += '     </div>';
        hoverContainer1 += '</div>';
        hoverContainer1 += '</div>';
        hoverPopup1.innerHTML = hoverContainer1;
        body.insertBefore(hoverPopup1, body.firstChild);
      }
	else
	{  
	document.getElementById('text_area').innerHTML=document.getElementById('dummy_text').value;  
	}
}

function CloseShipPopup()
{
    var popup_id = document.getElementById('hover_img_shipping');
    var body = document.body;
    body.removeChild(popup_id);
}

var _pageid;
var _positionid;
var _leastshippingid = '';

function CallSoapReqForUpdatingBasket(pageId,positionId,pageType,productId,quantity,comments,action)
{
     //var pageId = pageId;
     //var positionId = positionId;
     var pageId = _pageid;
     var positionId = _positionid;

     var pageType = pageType;
     var productId = productId;
     var quantity = quantity;
     var comments = comments;
     var action = action;
     var stage = "confirm";
     var createorder = "false";
     var shippingmethod; 
     var paymentmethod;		

      	var firstname;
     	var lastname;
	var middlename;
     	var phone;	
      	var vatnumber;
	var deliverydate;
	var pobox;
	var email;
	var city;
	var postalcode;
	var address;
	var organisation;
	var apartment;
	var region;
	var addressdescription;
	var credit_card_type;
	var credit_card_expire_month;
	var credit_card_expire_year;
	var bank_name;
	var name_on_card;
	var credit_card_number;
	var credit_card_expire;
	var cvc;
	var cardtype;
	
	 
	//alert(pageId+","+positionId+","+pageType+","+productId+","+quantity+","+comments+","+action);
	if(document.getElementById('ec_webshop_page_10_shippingmethod'))
		shippingmethod = document.getElementById('ec_webshop_page_10_shippingmethod').value;
	
	if(document.getElementById('ec_webshop_page_10_paymentmethod'))
		paymentmethod = document.getElementById('ec_webshop_page_10_paymentmethod').value;

	if(document.getElementById('ec_webshop_page_10_firstname'))
		firstname = document.getElementById('ec_webshop_page_10_firstname').value;
	
	if(document.getElementById('ec_webshop_page_10_lastname'))
		lastname = document.getElementById('ec_webshop_page_10_lastname').value;

	if(document.getElementById('ec_webshop_page_10_middlename'))
		middlename = document.getElementById('ec_webshop_page_10_middlename').value;

	if(document.getElementById('ec_webshop_page_10_phone'))
		phone = document.getElementById('ec_webshop_page_10_phone').value;
	
	if(document.getElementById('ec_webshop_page_10_vatnumber'))
		vatnumber = document.getElementById('ec_webshop_page_10_vatnumber').value;

	if(document.getElementById('ec_webshop_page_10_deliverydate'))
		deliverydate = document.getElementById('ec_webshop_page_10_deliverydate').value;
	
	if(document.getElementById('ec_webshop_page_10_newsletter'))
		pobox = document.getElementById('ec_webshop_page_10_newsletter').value;

	if(document.getElementById('ec_webshop_page_10_email'))
		email = document.getElementById('ec_webshop_page_10_email').value;
	
	if(document.getElementById('ec_webshop_page_10_city'))
		city = document.getElementById('ec_webshop_page_10_city').value;

	if(document.getElementById('ec_webshop_page_10_postalcode'))
		postalcode = document.getElementById('ec_webshop_page_10_postalcode').value;
	
	if(document.getElementById('ec_webshop_page_10_address'))
		address = document.getElementById('ec_webshop_page_10_address').value;

	if(document.getElementById('ec_webshop_page_10_organisation'))
		organisation = document.getElementById('ec_webshop_page_10_organisation').value;
	
	if(document.getElementById('ec_webshop_page_10_apartment'))
		apartment = document.getElementById('ec_webshop_page_10_apartment').value;
	
	if(document.getElementById('ec_webshop_page_10_region'))
		region = document.getElementById('ec_webshop_page_10_region').value;
	
	if(document.getElementById('ec_webshop_page_10_addressdescription'))
		addressdescription = document.getElementById('ec_webshop_page_10_addressdescription').value;
	
	if(document.getElementById('ec_webshop_page_10_credit_card_type'))
		credit_card_type = document.getElementById('ec_webshop_page_10_credit_card_type').value;
	
	if(document.getElementById('ec_webshop_page_10_credit_card_expire_month'))
		credit_card_expire_month = document.getElementById('ec_webshop_page_10_credit_card_expire_month').value;

	if(document.getElementById('ec_webshop_page_10_credit_card_expire_year'))
		credit_card_expire_year = document.getElementById('ec_webshop_page_10_credit_card_expire_year').value;
	
	if(document.getElementById('ec_webshop_page_10_bank_name'))
		bank_name = document.getElementById('ec_webshop_page_10_bank_name').value;

	if(document.getElementById('ec_webshop_page_10_name_on_card'))
		name_on_card = document.getElementById('ec_webshop_page_10_name_on_card').value;

	/*if(document.getElementById('ec_webshop_page_10_credit_card_number'))
		credit_card_number = document.getElementById('ec_webshop_page_10_credit_card_number').value;*/

	if(document.getElementById('ec_webshop_page_10_credit_card_number')){
		var cc_number = document.getElementById('ec_webshop_page_10_credit_card_number').value;
		credit_card_number = cc_number;
		/*if(cc_number.length > 0)
			credit_card_number = document.getElementById('ec_webshop_page_10_credit_card_number').value;
		else
			credit_card_number = '0000000000000001';*/
	}

	if(document.getElementById('ec_webshop_page_10_credit_card_expire'))
		credit_card_expire = document.getElementById('ec_webshop_page_10_credit_card_expire').value;

	if(document.getElementById('ec_webshop_page_10_cvc'))
		cvc = document.getElementById('ec_webshop_page_10_cvc').value;

	if(document.getElementById('ec_webshop_page_10_cardtype'))
		cardtype = document.getElementById('ec_webshop_page_10_cardtype').value;




   var queryparam = "<orderinfo><shippingmethod>"+shippingmethod+"</shippingmethod><paymentmethod>"+paymentmethod+"</paymentmethod><attributes><attribute><name>firstname</name><value>"+firstname+"</value></attribute><attribute><name>lastname</name><value>"+lastname+"</value></attribute><attribute><name>middlename</name><value>"+middlename+"</value></attribute><attribute><name>phone</name><value>"+phone+"</value></attribute><attribute><name>vatnumber</name><value>"+vatnumber+"</value></attribute><attribute><name>deliverydate</name><value>"+deliverydate+"</value></attribute><attribute><name>pobox</name><value>"+pobox+"</value></attribute><attribute><name>email</name><value>"+email+"</value></attribute><attribute><name>city</name><value>"+city+"</value></attribute><attribute><name>postalcode</name><value>"+postalcode+"</value></attribute><attribute><name>address</name><value>"+address+"</value></attribute><attribute><name>organisation</name><value>"+organisation+"</value></attribute><attribute><name>apartment</name><value>"+apartment+"</value></attribute><attribute><name>region</name><value>"+region+"</value></attribute><attribute><name>addressdescription</name><value>"+addressdescription+"</value></attribute><attribute><name>credit_card_type</name><value>"+credit_card_type+"</value></attribute><attribute><name>credit_card_expire_month</name><value>"+credit_card_expire_month+"</value></attribute><attribute><name>credit_card_expire_year</name><value>"+credit_card_expire_year+"</value></attribute><attribute><name>bank_name</name><value>"+bank_name+"</value></attribute><attribute><name>name_on_card</name><value>"+name_on_card+"</value></attribute><attribute><name>credit_card_number</name><value>"+credit_card_number+"</value></attribute><attribute><name>credit_card_expire</name><value>"+credit_card_expire+"</value></attribute><attribute><name>cvc</name><value>"+cvc+"</value></attribute><attribute><name>cardtype</name><value>"+cardtype+"</value></attribute></attributes><queryparams><querystring><name>confirm</name><value>true</value></querystring></queryparams></orderinfo>";

 

     //var queryparam = "<orderinfo><queryparams><querystring><name>confirm</name><value>true</value></querystring></queryparams></orderinfo>";
     queryparam = queryparam.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;')
     var soapBody = new SOAPObject("processBasket");
     soapBody.ns = "http://tempuri.org/";
     soapBody.appendChild(new SOAPObject("pageId")).val(pageId);
     soapBody.appendChild(new SOAPObject("positionId")).val(positionId);
     soapBody.appendChild(new SOAPObject("pageType")).val(pageType);
     soapBody.appendChild(new SOAPObject("productId")).val(productId);
     soapBody.appendChild(new SOAPObject("quantity")).val(quantity);
     soapBody.appendChild(new SOAPObject("comments")).val(comments);
     soapBody.appendChild(new SOAPObject("action")).val(action);
     soapBody.appendChild(new SOAPObject("option")).val(""); 
     //Create a new SOAP Request
     var sr = new SOAPRequest("http://tempuri.org/processBasket", soapBody); //Request is now ready to be sent to a web-service
     sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     //Lets send it
     SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
     SOAPClient.SendRequest(sr,processResponse); //Send request to server and assign callback function
		function processResponse(respObj) 
			{
				try 
                   			{
						if(document.getElementById("oldproductquantity_"+productId)){
							var oldquantity = document.getElementById("oldproductquantity_"+productId).value;
							create_cookie('oldcustomvalue_'+productId,oldquantity,1);
							//alert("Cookie::"+read_cookie('oldcustomvalue_'+productId));
						}
                   				var responseMessage = respObj.Body[0].processBasketResponse[0].processBasketResult[0].root[0];
                   				var htmlData = responseMessage.htmldata[0].Text;
			       			largeCartStart = htmlData.indexOf('<LARGECART>');
			       			largeCartEnd = htmlData.indexOf('</LARGECART>');
		           			smallCartStart = htmlData.indexOf('<SMALLCART>');
			       			smallCartEnd = htmlData.indexOf('</SMALLCART>'); 
			        		start = htmlData.indexOf('<tsd>');
						start = start + 5 ;
						end = htmlData.indexOf('</tsd>');
						totvalue = htmlData.substring(start,end);
						startfright=htmlData.indexOf('<tfd>');
						startfright=startfright+5;
						endfright=htmlData.indexOf('</tfd>');
						freightamt=htmlData.substring(startfright,endfright)
						startprod=htmlData.indexOf('<tcd>');
						startprod=startprod+5;
						endprod=htmlData.indexOf('</tcd>');
						prodqnty=htmlData.substring(startprod,endprod)
						startprodqnty=htmlData.indexOf('<tqd>');
						startprodqnty=startprodqnty+5;
						endprodqnty=htmlData.indexOf('</tqd>');
						prodqntycnt=htmlData.substring(startprodqnty,endprodqnty)
						calctot(totvalue,freightamt,prodqnty,prodqntycnt);

				   		document.getElementById("large_cart").innerHTML = htmlData.substring(largeCartStart,largeCartEnd); 
			       			document.getElementById("small_cart_container").innerHTML = htmlData.substring(smallCartStart,smallCartEnd);
				       		if(parseInt(quantity) != 1)	
		             				setCount(productId);
		           			if(document.getElementById('order_button')) 
				   				document.getElementById('order_button').href = document.getElementById('checkout_button').href;
				  	        if(document.getElementById('customvalue_'+productId))	
			     					document.getElementById('customvalue_'+productId).value = read_cookie('ProductCustomCount'+productId);	
			     			var shippingProduct = read_cookie('shippingProduct');
			     			var shippingcomments = '&lt;options&gt;&lt;category&gt;Frakt&lt;/category&gt;&lt;/options&gt;';
			     			if (shippingProduct == "" && action != 'clear' && read_cookie('shippingproductexist') != 'yes')
				         			CallSoapReqForGettingLeastShippingProduct(pageId,positionId,shippingcomments);

			     			if(action=="clear")	{
							create_cookie('shippingProduct','',-1);
							create_cookie('paymentProduct','',-1);
							create_cookie('greeting','',-1);
							create_cookie('wrapper','',-1);	
							create_cookie('voucherProductAdded','',-1);
							create_cookie('oldcustomvalue_'+productId,'',-1);
							_leastshippingid = '';
						}
						if (shippingProduct != "")
							closeUpdatingWindow();
				    
						/** This function will rewrite the html of orderprocess step 3 basket**/

						var url = document.location.href;
			     			if(url.indexOf('/steg3/')>-1){
							var positionId1 = "10";
	 			 			var pageType1 = "1";
				 			var soapBodyOrderprocess = new SOAPObject("orderProcess");
  			         			soapBodyOrderprocess.ns = "http://tempuri.org/";
     							soapBodyOrderprocess.appendChild(new SOAPObject("pageId")).val(pageId);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("positionId")).val(positionId1);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("pageType")).val(pageType1);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("stage")).val(stage);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("createorder")).val(createorder);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("orderInfoXml")).val(queryparam);
 				 			var OrderSR = new SOAPRequest("http://tempuri.org/orderProcess", soapBodyOrderprocess); //Request is now ready to be sent to a web-service
     				 			OrderSR.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     				 			OrderSR.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
				 			//Lets send it
     							SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     							SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
							SOAPClient.SendRequest(OrderSR,orderProcessResponse); //Send request to server and assign callback function
				 		}
				
			     			/** to assign the free freight price in postpaket shipping method **/

			     			if(url.indexOf('/steg2/')>-1){
							if(document.getElementById("postpaket").checked)
								document.getElementById("postpaket_price").innerHTML=trim(document.getElementById("frieghtPrice").innerHTML).replace('kr','');
							if(totvalue >= 500)
								document.getElementById("postpaket_price").innerHTML=0;
 							else
								document.getElementById("postpaket_price").innerHTML=Math.round(postpaket_currentPrice);
					 		
						}
						CallSoapReqForLoginCustomProperty(productId,quantity,action,comments);

                        		} 
                        	catch(e) { 
                        		        alert(e); 
                              
                        		}
		   	}


			function orderProcessResponse(orderRespObj) {
				try {
						
					var orderResponseMessage = orderRespObj.Body[0].orderProcessResponse[0].orderProcessResult[0].root[0];
			     		var basketHtmlData = orderResponseMessage.htmldata[0].Text;
			     		basketStart = basketHtmlData.indexOf('<ORDERPROCESSBASKET>');
			     		basketEnd = basketHtmlData.indexOf('</ORDERPROCESSBASKET>');
                             		document.getElementById("orderProcessBasket").innerHTML = basketHtmlData.substring(basketStart,basketEnd); 

				    }
				catch(e) { 
                                    alert(e); 
                              
                       		 }
			}	
		
}
/*
This function will call a CUSTOM webservice,that inturn will call the Private Method of ECWEB to get all the product's from the category "Frakt/Visa på webben", 
then sort all the products by Ascending order and then it will return the Lowest price shipping product.This lowest shipping cost product will be added in to the basket by default. 	
*/
function CallSoapReqForGettingLeastShippingProduct(pageId,positionId,comments)
{
     var soapBody = new SOAPObject("GetAllShippingProduct");
     soapBody.ns = "http://tempuri.org/";
     //soapBody.appendChild(new SOAPObject("option")).val(""); 
     //Create a new SOAP Request
     var sr = new SOAPRequest("http://tempuri.org/GetAllShippingProduct", soapBody); //Request is now ready to be sent to a web-service
     sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     //Lets send it
     SOAPClient.Proxy = "/designtorget/upload/files/WS/dtservice.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     SOAPClient.SOAPServer = "/designtorget/upload/files/WS/dtservice.asmx";
     //alert(sr);
     SOAPClient.SendRequest(sr,processResponse); //Send request to server and assign callback function
   function processResponse(respObj) 
                     {
      try 
                        {
                             var responseMessage = respObj.Body[0].GetAllShippingProductResponse[0].GetAllShippingProductResult[0].root[0];
                             //alert(responseMessage.htmldata[0].Text);
                             var shipping = responseMessage.items[0].item.length;
                             responseMessage.items[0].item.SortByNode("price");
                             var leastShippingProductGuid = responseMessage.items[0].item[0].id[0].Text;
			     create_cookie('shippingProduct',leastShippingProductGuid,1);
			     _leastshippingid = leastShippingProductGuid;		
                             CallSoapReqForUpdatingBasket(pageId,positionId,2,leastShippingProductGuid,1,comments,'add');
			     		            
                        } 
                        catch(e) 
                        { 
                              alert(e); 
                        }
     }
}

function CallSoapReqForUpdatingBasket_Vocher(pageId,positionId,pageType,productId,quantity,comments,action)
{
	 var pageId = pageId;
	 var positionId = positionId;
	 var pageType = pageType;
	 var productId = productId;
	 var quantity = quantity;
	 var comments = comments;
	 var action = action;
	 var soapBody = new SOAPObject("processBasket");
     soapBody.ns = "http://tempuri.org/";
     soapBody.appendChild(new SOAPObject("pageId")).val(pageId);
     soapBody.appendChild(new SOAPObject("positionId")).val(positionId);
     soapBody.appendChild(new SOAPObject("pageType")).val(pageType);
     soapBody.appendChild(new SOAPObject("productId")).val(productId);
     soapBody.appendChild(new SOAPObject("quantity")).val(quantity);
     soapBody.appendChild(new SOAPObject("comments")).val(comments);
     soapBody.appendChild(new SOAPObject("action")).val(action);
     soapBody.appendChild(new SOAPObject("option")).val(""); 
     //alert(soapBody);
     //Create a new SOAP Request
     var sr = new SOAPRequest("http://tempuri.org/processBasket", soapBody); //Request is now ready to be sent to a web-service
     sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     //Lets send it
     SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
     //alert(sr);
     SOAPClient.SendRequest(sr,processResponse); //Send request to server and assign callback function
			function processResponse(respObj) 
                     {
						try 
                        {
                              
                             var responseMessage = respObj.Body[0].processBasketResponse[0].processBasketResult[0].root[0];
                             //alert(responseMessage.htmldata[0].Text);
                             //document.getElementById("basket_holder").innerHTML = responseMessage.htmldata[0].Text;
			     var htmlData = responseMessage.htmldata[0].Text;
			     largeCartStart = htmlData.indexOf('<LARGECART>');
			     largeCartEnd = htmlData.indexOf('</LARGECART>');
		             smallCartStart = htmlData.indexOf('<SMALLCART>');
			     smallCartEnd = htmlData.indexOf('</SMALLCART>'); 
					
                             document.getElementById("large_cart").innerHTML = htmlData.substring(largeCartStart,largeCartEnd); 
			     document.getElementById("small_cart_container").innerHTML = htmlData.substring(smallCartStart,smallCartEnd);
				//alert(document.getElementById("price_list_main").innerHTML);
			     document.userinformationform.submit();
	
                        } 
                        catch(e) 
                        { 
                              
                              alert(e); 
                              
                        }
		}
		
}
/*This function will call a CUSTOM webservice to check whether voucher product exists*/
function CallSoapReqForAddingVoucherProduct(productId){
	var productId = productId;
	var soapBody = new SOAPObject("GetVoucherProduct");
     	soapBody.ns = "http://tempuri.org/";
   	soapBody.appendChild(new SOAPObject("productid")).val(productId);
	 //Create a new SOAP Request
    	 var sr = new SOAPRequest("http://tempuri.org/GetVoucherProduct", soapBody); //Request is now ready to be sent to a web-service
     	sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     	sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     	//Lets send it
     	SOAPClient.Proxy = "/designtorget/upload/files/WS/Dtservice.asmx"; //Specify web-service address (if local to your domain) or a proxy file
    	 SOAPClient.SOAPServer = "/designtorget/upload/files/WS/Dtservice.asmx";
     	//alert(sr);
     	SOAPClient.SendRequest(sr,processResponse); //Send request to server and assign callback function
		function processResponse(respObj) 
                     {
			try 
                        {
                             if(respObj.Body[0].GetVoucherProductResponse[0].GetVoucherProductResult[0].root[0].Text != null) {
                            	 var responseMessage = respObj.Body[0].GetVoucherProductResponse[0].GetVoucherProductResult[0].root[0];
			    	 var voucher = responseMessage.row[0].attributes[0].id[0].Text;	
                             	  var vouchercomments = '&lt;options&gt;&lt;category&gt;Rabatt&lt;/category&gt;&lt;/options&gt;';
				document.getElementById('error_voucher').innerHTML="";
				 CallSoapReqForUpdatingBasket_Vocher(read_cookie('pageid'),read_cookie('positionid'),2,voucher,1,vouchercomments,'add');
				 create_cookie('voucherProductAdded','yes',1);
    				 //document.userinformationform.submit();	
				}
                            else{
				document.getElementById('error_voucher').innerHTML = "Din rabattkod är inte giltig";
				}	
                        } 
                        catch(e) 
                        { 
                              
                              alert(e); 
                              
                        }
		}
}


/*This function will call a CUSTOM webservice to check whether voucher product exists*/
/* The Parmeter for this funtion is object parametre */
function CallSoapReqForVoucherTracking(paraMeters,productId){
 var productId = productId;
 var comments = '';
 var soapBody = new SOAPObject("ValidateVouchour");
      soapBody.ns = "http://tempuri.org/";
        /* <params>
                <param param="searchparam1" paramname="email">vidhya@ec.is</param>
                 <param param="searchparam2" paramname="rabattkod">12345</param>
            </params>
        */
    var Params = '';
    Params = Params + '<params>';
    for(Obj in  paraMeters)
    {
        Params = Params + '<param ';
        var paramObj = paraMeters[Obj];
        for(iObj in  paramObj)
        {
            Params = Params + iObj + '="' + paramObj[iObj] +'" ';
        }
        Params = Params + '></param>';
    }
    Params = Params + '</params>';
    soapBody.appendChild(new SOAPObject("xml")).val(Params.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;'));
  //Create a new SOAP Request
      var sr = new SOAPRequest("http://tempuri.org/ValidateVouchour", soapBody); //Request is now ready to be sent to a web-service
      sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
      sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
      //Lets send it
      SOAPClient.Proxy = "/designtorget/upload/files/WS/Dtservice.asmx"; //Specify web-service address (if local to your domain) or a proxy file
      SOAPClient.SOAPServer = "/designtorget/upload/files/WS/Dtservice.asmx";
      //alert(sr);
      SOAPClient.SendRequest(sr,processResponse); //Send request to server and assign callback function
  function processResponse(respObj) 
        {
           try 
           {
               if(respObj.Body[0].ValidateVouchourResponse[0].ValidateVouchourResult[0].Text=="true")
               {
		     document.getElementById("error_voucher").innerHTML = 'Erbjudandet är redan nyttjat och kan inte användas igen';
		}
 
               else
               {
		   document.getElementById("error_voucher").innerHTML = " ";
		   	
		   if(readCookie('voucherProductAdded')!="yes")	{
		       CallSoapReqForAddingVoucherProduct(productId);

		   }	
		    else
			document.getElementById("error_voucher").innerHTML = 'Du kan bara använda en rabattkod per köp';	
		   
		  		
               }
       
           }
           catch(e) 
           { 
              alert(e); 
            }
  }
}


function CallSoapReqForRemovingShippingProduct(pageId,positionId,pageType,productId,quantity,comments,action)
{
	 var pageId = pageId;
	 var positionId = positionId;
	 var pageType = pageType;
	 var productId = productId;
	 var quantity = quantity;
	 var comments = comments;
	 var action = action;
	 var soapBody = new SOAPObject("processBasket");
     soapBody.ns = "http://tempuri.org/";
     soapBody.appendChild(new SOAPObject("pageId")).val(pageId);
     soapBody.appendChild(new SOAPObject("positionId")).val(positionId);
     soapBody.appendChild(new SOAPObject("pageType")).val(pageType);
     soapBody.appendChild(new SOAPObject("productId")).val(productId);
     soapBody.appendChild(new SOAPObject("quantity")).val(quantity);
     soapBody.appendChild(new SOAPObject("comments")).val(comments);
     soapBody.appendChild(new SOAPObject("action")).val(action);
     soapBody.appendChild(new SOAPObject("option")).val(""); 
     //alert(soapBody);
     //Create a new SOAP Request
     var sr = new SOAPRequest("http://tempuri.org/processBasket", soapBody); //Request is now ready to be sent to a web-service
     sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     //Lets send it
     SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
     //alert(sr);
     SOAPClient.SendRequest(sr,processResponse); //Send request to server and assign callback function
	function processResponse(respObj) 
                     {
						try 
                        {
                              
                             var responseMessage = respObj.Body[0].processBasketResponse[0].processBasketResult[0].root[0];
                             //alert(responseMessage.htmldata[0].Text);
                             //document.getElementById("basket_holder").innerHTML = responseMessage.htmldata[0].Text;
			     var htmlData = responseMessage.htmldata[0].Text;
			     largeCartStart = htmlData.indexOf('<LARGECART>');
			     largeCartEnd = htmlData.indexOf('</LARGECART>');
		             smallCartStart = htmlData.indexOf('<SMALLCART>');
			     smallCartEnd = htmlData.indexOf('</SMALLCART>'); 	
                             //document.getElementById("large_cart").innerHTML = htmlData.substring(largeCartStart,largeCartEnd); 
			     //document.getElementById("small_cart_container").innerHTML = htmlData.substring(smallCartStart,smallCartEnd);

			     var shippingProduct = read_cookie('shippingProduct');
			     var shippingcomments = '&lt;options&gt;&lt;category&gt;Frakt&lt;/category&gt;&lt;/options&gt;';
			     if (shippingProduct == "" && action != 'clear'){
				         CallSoapReqForGettingLeastShippingProduct(pageId,positionId,shippingcomments);
					 
			      }	
			     document.getElementById("shippingLabel").innerHTML = read_cookie('shippingOption');
	
                        } 
                        catch(e) 
                        { 
                              
                              alert(e); 
                              
                        }
		}
		
}

/*This function will call a CUSTOM webservice to check whether product count*/
/* The Parmeter for this funtion is product id */

function CallSoapReqForProductCount(productId,currentQty)
{
     var productId = productId;
     var quantity = parseInt(currentQty, 10);
     var soapBody = new SOAPObject("Get_ProductCount");
     soapBody.ns = "http://tempuri.org/";

     soapBody.appendChild(new SOAPObject("productid")).val(productId);
     //alert(soapBody);
     //Create a new SOAP Request
     var sr = new SOAPRequest("http://tempuri.org/Get_ProductCount", soapBody); //Request is now ready to be sent to a web-service
     sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     //Lets send it
     SOAPClient.Proxy = "/designtorget/editor/soap//productsxt.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     SOAPClient.SOAPServer = "/designtorget/editor/soap//productsxt.asmx";
     //alert(sr);
     SOAPClient.SendRequest(sr,processResponse); //Send request to server and assign callback function
			function processResponse(respObj) 
                     {
						try 
                       		 {
				
           	
                             var responseMessage = respObj.Body[0].Get_ProductCountResponse[0].Get_ProductCountResult[0].Text;
				//alert(responseMessage);
		             if(quantity<=responseMessage){
					
					CallSoapReqForUpdatingBasket(read_cookie('pageid'),read_cookie('positionid'),2,productId,currentQty,'','update');
			    }	 	
				
			    else{
				
				var browser = navigator.appName;
        			var b_version = navigator.appVersion;
        			var version = parseFloat(b_version); 
				    
					if((browser == "Microsoft Internet Explorer") && (b_version.indexOf('MSIE 6.0') > -1 ))
                          		 {   
                                		var body = document.body;
                                		var hoverContainer = document.createElement("div");
                                		hoverContainer.className = "giftguide_hover_container";
                                		hoverContainer.setAttribute("id", "hover_img_1");
                                		body.insertBefore(hoverContainer, body.firstChild);
                                		document.getElementById('popup_area').style. display="block"; 
                                		document.getElementById('popup_area').className = "popup_area";
                                		document.getElementById('popup_area').innerHTML=document.getElementById('largecart_outofstock_area').innerHTML;
                                		var bodyheight= document.getElementById('body_frame').scrollHeight; 
                                		document.getElementById('hover_img_1').style.height = bodyheight;
						document.getElementById('largecart_quantity').value = quantity;
						document.getElementById('largecart_productid').value = productId;
                                		var focusobj= document.getElementById('popup_area');
                                		focusobj.focus();
                                		if(document.getElementById('Select1'))    
                                     			document.getElementById('Select1').className = 'hidden'; 
                                		if(document.getElementById('Select2'))          
                                     			document.getElementById('Select2').className = 'hidden'; 
                         		 }
                			else
                         		 { 
                                		var body = document.body;
                                		var hoverContainer = document.createElement("div");
                                		hoverContainer.className = "giftguide_hover_container";
                                		hoverContainer.setAttribute("id", "hover_img_1");
                                		var alertText = document.createElement('div');
                                		alertText.className = "stock_container";
                                		alertText.innerHTML = document.getElementById('largecart_outofstock_area').innerHTML;
						document.getElementById('largecart_quantity').value = quantity;
						document.getElementById('largecart_productid').value = productId;
                                		hoverContainer.appendChild(alertText);
                                		body.insertBefore(hoverContainer, body.firstChild);                                                
                          		}
				
			   }	
 			     
                        } 
                        catch(e) 
                        { 
                              
                              alert(e); 
                              
                        }
		}
		
}
function CallSoapReqForLogin(productId,currentQty){
	 var username = "designadmin";
	 var password = "@92)qZMslm";
	 var langid = "1";

	 var soapBody = new SOAPObject("Login");
     soapBody.ns = "http://tempuri.org/";
     soapBody.appendChild(new SOAPObject("username")).val(username);
     soapBody.appendChild(new SOAPObject("password")).val(password);
     soapBody.appendChild(new SOAPObject("langid")).val(langid);
     //alert(soapBody);
     //Create a new SOAP Request
     var sr = new SOAPRequest("http://tempuri.org/Login", soapBody); //Request is now ready to be sent to a web-service
     sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     //Lets send it
     SOAPClient.Proxy = "/designtorget/editor/soap/users.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     SOAPClient.SOAPServer = "/designtorget/editor/soap/users.asmx";
     //alert(sr);
     SOAPClient.SendRequest(sr,processResponse); //Send request to server and assign callback function
	function processResponse(respObj) 
                     {
			try 
                        {
 				CallSoapReqForProductCount(productId,currentQty);

                             					 

                        } 
                        catch(e) 
                        { 
                              
                              alert(e); 
                              
                        }
		}
}

function CallSoapReqForLoginCustomProperty(productId,quantity,action,comments){
	var username = "designadmin";
	 var password = "@92)qZMslm";
	 var langid = "1";

	 var soapBody = new SOAPObject("Login");
     soapBody.ns = "http://tempuri.org/";
     soapBody.appendChild(new SOAPObject("username")).val(username);
     soapBody.appendChild(new SOAPObject("password")).val(password);
     soapBody.appendChild(new SOAPObject("langid")).val(langid);
     //alert(soapBody);
     //Create a new SOAP Request
     var sr = new SOAPRequest("http://tempuri.org/Login", soapBody); //Request is now ready to be sent to a web-service
     sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     //Lets send it
     SOAPClient.Proxy = "/designtorget/editor/soap/users.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     SOAPClient.SOAPServer = "/designtorget/editor/soap/users.asmx";
     //alert(sr);
     SOAPClient.SendRequest(sr,processResponse); //Send request to server and assign callback function
	function processResponse(respObj) 
                     {
			try 
                        {
				CallSoapForUpdatingCustomProperty(productId,quantity,action,comments);
							 

                        } 
                        catch(e) 
                        { 
                              
                              alert(e); 
                              
                        }
		}
}
function CallSoapForUpdatingCustomProperty(productId,currentQty,action,comments){
    	var productid = productId;
    	var hitscount;
	if(read_cookie('oldcustomvalue_'+productId) == "")
		create_cookie('oldcustomvalue_'+productId,1,1);	
	//alert("Quantity::"+currentQty+"Action::"+action+"Oldcustomvalue::"+read_cookie('oldcustomvalue_'+productId));
	var product_rating;
    	if((action =='add' || action =='update') && comments != 'decrement'){
		if(action == 'add')
			product_rating = "1";
		else if(action == 'update')
    			//product_rating = parseInt(currentQty) - parseInt(read_cookie('oldcustomvalue_'+productId));
    			product_rating = Math.round(currentQty) - Math.round(read_cookie('oldcustomvalue_'+productId));    		    
	 	var soapBody = new SOAPObject("UpdateProductRating");
     	 	soapBody.ns = "http://tempuri.org/";
     	 	soapBody.appendChild(new SOAPObject("productid")).val(productid);
     	 	soapBody.appendChild(new SOAPObject("product_rating")).val(product_rating);
     	 	//Create a new SOAP Request
     	 	var sr = new SOAPRequest("http://tempuri.org/UpdateProductRating", soapBody); //Request is now ready to be sent to a web-service
     	 	sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     	 	sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     	 	//Lets send it
     	 	SOAPClient.Proxy = "/designtorget/editor/soap/productsxt.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     	 	SOAPClient.SOAPServer = "/designtorget/editor/soap/productsxt.asmx";
	 	SOAPClient.SendRequest(sr,processResponse); //Send request to server and assign callback function
    	} 
	 function processResponse(respObj) {
			try {
     				hitscount = respObj.Body[0].UpdateProductRatingResponse[0].UpdateProductRatingResult[0].rating[0].productrating[0].Text;
				//alert("Hitscount"+hitscount);
				var propertyxml = "<property><name>Varukorg</name><value>"+hitscount+"</value></property>";
	 			propertyxml = propertyxml.replace(/</g,'&lt;');
	 			propertyxml = propertyxml.replace(/>/g,'&gt;')
	 			var soapBody = new SOAPObject("UpdateProductCustomProperty");
     	 			soapBody.ns = "http://tempuri.org/";
     	 			soapBody.appendChild(new SOAPObject("productid")).val(productid);
     	 			soapBody.appendChild(new SOAPObject("propertyxml")).val(propertyxml);
     	 			//Create a new SOAP Request
     	 			var Customsr = new SOAPRequest("http://tempuri.org/UpdateProductCustomProperty", soapBody); //Request is now ready to be sent to a web-service
     	 			Customsr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     	 			Customsr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     	 			//Lets send it
     	 			SOAPClient.Proxy = "/designtorget/editor/soap/productsxt.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     	 			SOAPClient.SOAPServer = "/designtorget/editor/soap/productsxt.asmx";
	 			SOAPClient.SendRequest(Customsr,CustomprocessResponse); //Send request to server and assign callback function

	 		}
                        catch(e) 
                        { 
                               alert(e); 
                              
                        }
	 }
     
	 function CustomprocessResponse(respObj) {
                   try  {
						
		   } 
                   catch(e) {
   			alert(e); 
             	    }
	 }
}
var _allproductsguid;
var _guid;
var _quantity;
var _productId;

function UpdateWrapper(allproductsguid,guid,quantity,productId,action){
	
    var pageId = read_cookie('pageid');
	var positionId = read_cookie('positionid');
	var pageType = '1';
	var comments;
	var count;
	
	_allproductsguid = allproductsguid;
	_guid = guid;
	_quantity = quantity;
	_productId = productId;
	

	comments = '&lt;options&gt;'
	comments += '&lt;category&gt;'
	comments += 'Inslagning'
	comments += '&lt;/category&gt;'
	comments += '&lt;wrappers&gt;'
	var str = allproductsguid.split(',');
	var str1;
	var productQuantity;
	var wrappercount = 0;
	//alert(productId);
        if(quantity > 0) {
		for(i=0;i<str.length-1;i++)
			{
				str1 = str[i].split('|');
				wrappercount = wrappercount + parseInt(document.getElementById('wquantity_'+str1[0]).value);
			}
			//alert("wrappercount:"+wrappercount);
			if(quantity == 1 && wrappercount == 0){		
		
		 		var soapBody = new SOAPObject("processBasket");
     				soapBody.ns = "http://tempuri.org/";
     				soapBody.appendChild(new SOAPObject("pageId")).val(pageId);
     				soapBody.appendChild(new SOAPObject("positionId")).val(positionId);
     				soapBody.appendChild(new SOAPObject("pageType")).val(pageType);
     				soapBody.appendChild(new SOAPObject("productId")).val(guid);
     				soapBody.appendChild(new SOAPObject("quantity")).val(0);
     				soapBody.appendChild(new SOAPObject("comments")).val("");
     				soapBody.appendChild(new SOAPObject("action")).val("remove");
     				soapBody.appendChild(new SOAPObject("option")).val(""); 
     				//Create a new SOAP Request
     				var sr = new SOAPRequest("http://tempuri.org/processBasket", soapBody); //Request is now ready to be sent to a web-service
     				sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     				sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     				//Lets send it
     				SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     				SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
				SOAPClient.SendRequest(sr,addwrapperproduct); //Send request to server and assign callback function	
     			
			}
		else{

			for(i=0;i<str.length-1;i++)
			{
				comments += '&lt;wrapper&gt;'
				str1 = str[i].split('|');

				comments += '&lt;productguid&gt;'
				comments += str1[0];
				comments += '&lt;/productguid&gt;'
				comments += '&lt;productquantity&gt;'
				comments += str1[1];
				comments += '&lt;/productquantity&gt;'
				comments += '&lt;wrapperquantity&gt;'
					
				
				if(str1[0] == productId){
					if(action == 'increment')
					{		
						count = parseInt(document.getElementById('wquantity_'+str1[0]).value) + 1;
						
					}
					else if(action == 'decrement')
					{
						count = parseInt(document.getElementById('wquantity_'+str1[0]).value) - 1;
						document.getElementById('wquantity_'+str1[0]).value = count<=0?0:count;
					}
					productQuantity = str1[1];
					comments += count;
			
				}
				else if(document.getElementById('wquantity_'+str1[0]).value == '0'){
			
					comments += '0';
				}
				else
					comments += document.getElementById('wquantity_'+str1[0]).value;

				comments += '&lt;/wrapperquantity&gt;'		
				comments += '&lt;/wrapper&gt;'
		
			}
		}
		
		comments += '&lt;/wrappers&gt;'
		comments += '&lt;/options&gt;';

		if(count <= productQuantity && (document.getElementById('wquantity_'+productId).value >= 0)){ 
			if(action == 'increment'){
				showUpdatingWindow();
        			addBB(pageId,positionId,2,guid,1,comments,'add');
			}
			else if(action == 'decrement'){	
				
				var Quan1 = parseInt(quantity) - 1;
				var allGUID ='';
				var Quantity =0;
				for(i=0;i<str.length-1;i++)
				{
					str2 = str[i].split('|');
					if(str2[0] == productId){
						allGUID = allGUID + str2[0] +'|' + (parseInt(str2[1]) - 1) +','
						Quantity = Quantity + parseInt(document.getElementById('wquantity_'+str2[0]).value);
					}
					else
					{
						allGUID = allGUID + str[i] +','
						Quantity = Quantity + parseInt(document.getElementById('wquantity_'+str2[0]).value);
					}
				}
				showUpdatingWindow();
				RemoveWrapper(pageId,positionId,2,guid,Quantity,productId,'remove',allGUID);
			}
		}
			
	}
	
	else{
		alert('Gå tillbaka till steg 2 och välj inslagspapper');
	}
	//document.location.href = document.location.href;
 	
}
function addwrapperproduct(respObj){

	document.getElementById('wquantity_'+_productId).value = 1;
	showUpdatingWindow();
	//alert(_allproductsguid+";"+_guid+";"+_quantity+";"+_productId);
	addAndUpdateWrapper(_allproductsguid,_guid,_quantity,_productId,'increment');

}
			

function addAndUpdateWrapper(allproductsguid,guid,quantity,productId,action){
	

	var comments;
	var count;

	comments = '&lt;options&gt;'
	comments += '&lt;category&gt;'
	comments += 'Inslagning'
	comments += '&lt;/category&gt;'
	comments += '&lt;wrappers&gt;'
	var str = allproductsguid.split(',');
	var str1;
	var productQuantity;
	//alert(quantity);
        if(quantity > 0) {
		for(i=0;i<str.length-1;i++)
			{
				comments += '&lt;wrapper&gt;'
				str1 = str[i].split('|');

				comments += '&lt;productguid&gt;'
				comments += str1[0];
				comments += '&lt;/productguid&gt;'
				comments += '&lt;productquantity&gt;'
				comments += str1[1];
				comments += '&lt;/productquantity&gt;'
				comments += '&lt;wrapperquantity&gt;'
				comments += parseInt(document.getElementById('wquantity_'+str1[0]).value);
				comments += '&lt;/wrapperquantity&gt;'
				comments += '&lt;/wrapper&gt;'
					
				
		
			}


		comments += '&lt;/wrappers&gt;'
		comments += '&lt;/options&gt;';
		//alert('updatewrapper');	
		
        	addBB(pageId,positionId,2,guid,quantity,comments,'add');
 	}
	
}

function addBB(pageId,positionId,pageType,guid,quantity,comments,action)
{
     var soapBody = new SOAPObject("processBasket");
     soapBody.ns = "http://tempuri.org/";
     soapBody.appendChild(new SOAPObject("pageId")).val(pageId);
     soapBody.appendChild(new SOAPObject("positionId")).val(positionId);
     soapBody.appendChild(new SOAPObject("pageType")).val(pageType);
     soapBody.appendChild(new SOAPObject("productId")).val(guid);
     soapBody.appendChild(new SOAPObject("quantity")).val(quantity);
     soapBody.appendChild(new SOAPObject("comments")).val(comments);
     soapBody.appendChild(new SOAPObject("action")).val(action);
     soapBody.appendChild(new SOAPObject("option")).val(""); 
     //Create a new SOAP Request
     var sr = new SOAPRequest("http://tempuri.org/processBasket", soapBody); //Request is now ready to be sent to a web-service
     sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     //Lets send it
     SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
     SOAPClient.SendRequest(sr,refreshpage); //Send request to server and assign callback function	
     function refreshpage(respObj)
     {
		//document.location.href = document.location.href;
		//alert("frm submitting order");
		document.ordersubmit.submit();
		
	
      }

}

function RemoveWrapper(pageId,positionId,pageType,guid,quantity,productId,action,allproductsguid){

     var soapBody = new SOAPObject("processBasket");
     soapBody.ns = "http://tempuri.org/";
     soapBody.appendChild(new SOAPObject("pageId")).val(pageId);
     soapBody.appendChild(new SOAPObject("positionId")).val(positionId);
     soapBody.appendChild(new SOAPObject("pageType")).val(pageType);
     soapBody.appendChild(new SOAPObject("productId")).val(guid);
     soapBody.appendChild(new SOAPObject("quantity")).val(quantity);
     soapBody.appendChild(new SOAPObject("comments")).val(comments);
     soapBody.appendChild(new SOAPObject("action")).val(action);
     soapBody.appendChild(new SOAPObject("option")).val(""); 
     //Create a new SOAP Request
     var sr = new SOAPRequest("http://tempuri.org/processBasket", soapBody); //Request is now ready to be sent to a web-service
     sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     //Lets send it
     SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
SOAPClient.SendRequest(sr,addwrapper); //Send request to server and assign callback function	
	function addwrapper(){
		if(quantity == 0)
			document.location.href=document.location.href;
		else			
			addAndUpdateWrapper(allproductsguid,guid,quantity,productId,'increment')
	}
}

function CallsoapforaddingWrapper(wrappercount,allguid){
	var str = allguid.split(',');
	var str1;
	var wrappercount1 = 0;

	for(i=0;i<str.length-1;i++)
			{
				str1 = str[i].split('|');
				wrappercount1 = wrappercount1 + parseInt(document.getElementById('wquantity_'+str1[0]).value);
			}
	if(wrappercount1 == 0 && wrappercount == 1)
		alert("Du måste välja vilken sak du vill ha inslagen");
	else
		document.orderplacementform.submit();
	
}

/** gift card ***/
var BalanceAmount = 0;
var ChargedAmount=0;
//if (read_cookie("BalanceAmount") > '0') {
//    BalanceAmount = read_cookie("BalanceAmount");
//}
var BalanceResult = '';
var LastAmount = 0;
function validateGiftcard(code,secret,amount,reservationRef){ 
showUpdatingWindowForGiftCard();
	var soapBody = new SOAPObject("validateGiftcard");
	soapBody.ns = "http://tempuri.org/";
	soapBody.appendChild(new SOAPObject("number")).val(code);
	soapBody.appendChild(new SOAPObject("code")).val(secret);
	soapBody.appendChild(new SOAPObject("amount")).val(amount);
	soapBody.appendChild(new SOAPObject("reservedID")).val(reservationRef);
    
    //Create a new SOAP Request
	var sr = new SOAPRequest("http://tempuri.org/validateGiftcard", soapBody); //Request is now ready to be sent to a web-service
	sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
	sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
	
 	//Lets send it
 	SOAPClient.Proxy = "/designtorget/upload/files/service/giftcard.asmx"; //Specify web-service address (if local to your domain) or a proxy file
 	SOAPClient.SOAPServer = "/designtorget/upload/files/service/giftcard.asmx";
        //alert(sr);
    
 	SOAPClient.SendRequest(sr, giftcardprocessResponse); //Send request to server and assign callback function
 	
	function giftcardprocessResponse(respObj){
		try{	
		

		    var ResultOut = eval(respObj.Body[0].validateGiftcardResponse[0].validateGiftcardResult[0].root[0]);
            if(ResultOut.error){
                document.getElementById("error_giftcardmethod").style.color = '#df0000';
                document.getElementById("error_giftcardmethod").style.padding= '0px 0px 0px 0px';
                document.getElementById("error_giftcardmethod").innerHTML = ResultOut.Result_Desc[0].Text;
                create_cookie("lastAmount",amount,1);create_cookie("BalanceResult",ResultOut.Result_Desc[0].Text,1);
                document.getElementById("paymentArea").style.display = 'block'; 
                closeUpdatingWindow();

            }


		    else if(ResultOut.ReservationID){		    
		        var reservedID = ResultOut.ReservationID[0].Text;
		        ChargedAmount = ResultOut.ChargedAmount[0].Text;
		        BalanceAmount = ResultOut.BalanceAmount[0].Text; 
		        BalanceResult = ResultOut.Result_Desc[0].Text;
		        var GiftCardNumber = ResultOut.giftcardNumber[0].Text;
		        var GiftCardCode = ResultOut.giftcardCode[0].Text;
		        
                var createorder = "false";
                var queryparam = "<orderinfo><attributes><attribute><name>custom_reservedID</name><value>" + reservedID + "</value></attribute><attribute><name>custom_ChargedAmount</name><value>" + ChargedAmount + "</value></attribute><attribute><name>custom_BalanceAmount</name><value>" + BalanceAmount + "</value></attribute><attribute><name>custom_GiftCardNumber</name><value>" + GiftCardNumber + "</value></attribute><attribute><name>custom_GiftCardCode</name><value>" + GiftCardCode + "</value></attribute><attribute><name>fax</name><value>" + GiftCardNumber + "-" + ChargedAmount + "</value></attribute></attributes></orderinfo>";
                queryparam = queryparam.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
                create_cookie("reservedID",reservedID,1);
                
                var pageId = read_cookie('pageid');
                var positionId = read_cookie('positionid');
                var pageType = 2;
                var quantity = 1; 
                var stage = "info";   
                LastAmount = amount;      
               
                var soapBodyOrderprocess = new SOAPObject("orderProcess");
                soapBodyOrderprocess.ns = "http://tempuri.org/";
                soapBodyOrderprocess.appendChild(new SOAPObject("pageId")).val(pageId);
                soapBodyOrderprocess.appendChild(new SOAPObject("positionId")).val(positionId);
                soapBodyOrderprocess.appendChild(new SOAPObject("pageType")).val(pageType);
                soapBodyOrderprocess.appendChild(new SOAPObject("stage")).val(stage);
                soapBodyOrderprocess.appendChild(new SOAPObject("createorder")).val(createorder);
                soapBodyOrderprocess.appendChild(new SOAPObject("orderInfoXml")).val(queryparam);
                
                var OrderSR = new SOAPRequest("http://tempuri.org/orderProcess", soapBodyOrderprocess); //Request is now ready to be sent to a web-service
                OrderSR.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
                OrderSR.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
                SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
                SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
                SOAPClient.SendRequest(OrderSR,GCorderProcessResponse); //Send request to server and assign callback function 
               closeUpdatingWindow();
                
            }	else {closeUpdatingWindow();return false;}
            
		}
		catch(e){
		document.getElementById("error_giftcardmethod").style.color = '#df0000';
                document.getElementById("error_giftcardmethod").style.padding= '0px 0px 0px 0px';
                document.getElementById("error_giftcardmethod").innerHTML = "Vi har för närvarande problem med att nå vår presentkort databas. Vänligen försök igen senare eller välj ett alternativt betalsätt.";
                create_cookie("lastAmount",amount,1);create_cookie("BalanceResult","Vi har för närvarande problem med att nå vår presentkort databas. Vänligen försök igen senare eller välj ett alternativt betalsätt.",1);
                document.getElementById("paymentArea").style.display = 'block'; 
                closeUpdatingWindow();
		}
		
	}	
	
}
function GCorderProcessResponse(respObj){

    create_cookie("lastAmount",LastAmount,1); create_cookie("BalanceAmount",BalanceAmount,1);create_cookie("BalanceResult",BalanceResult,1);
    
    var currStep = read_cookie('currentstep');
    if(currStep=="step2"){
        if(BalanceAmount != '0'){
            document.getElementById("succ_giftcardmethod").style.color = '#df0000';
            document.getElementById("succ_giftcardmethod").style.padding= '0px 0px 0px 0px';
            document.getElementById("succ_giftcardmethod").innerHTML = BalanceResult;
            document.getElementById("dummyPayment").checked = false;
            document.getElementById("paymentArea").style.display = 'block';
            document.getElementById("giftcardcheck").style.display = 'none';
            document.getElementById("giftcard_details").style.display = 'none';
            document.getElementById("giftcard_value").style.display = 'none';
            create_cookie("Success", "0", 1);
            create_cookie("nocheck","1",1);
            
        }else{
            document.getElementById("succ_giftcardmethod").style.color = '#df0000';
            document.getElementById("succ_giftcardmethod").style.padding= '0px 0px 0px 0px';
            document.getElementById("succ_giftcardmethod").innerHTML = BalanceResult;  
            document.getElementById("dummyPayment").checked = true;
            createordercookie("paymentProduct","giftcardpay");
            document.getElementById("paymentArea").style.display = 'none';
            document.getElementById("giftcardcheck").style.display = 'none';
            document.getElementById("giftcard_details").style.display = 'none';
            document.getElementById("giftcard_value").style.display = 'none';
            create_cookie("Success", "1", 1);
            create_cookie("nocheck","1",1);
        }
    }
    else if(currStep=="step3")
    {
    var pageId = read_cookie('pageid');
    var positionId = read_cookie('positionid');
    var pageType = 2;
    var quantity = 1; 
    var action="remove";
    var comments = ""; 
                             if(read_cookie("BalanceAmount") == '0')
                              {
                          
                                  if(document.getElementById("ec_webshop_page_10_payment_method_name").value=="Postforskott")
                                       {
                                            var productId="E6A161C7-EB20-4258-BE9C-1F590E44BED4";
                                            CallSoapReqForUpdatingBasketForGiftCard(pageId,positionId,pageType,productId,quantity,comments,action);                                                
                                            create_cookie("Success","1",1);
                                            document.getElementById("ec_webshop_page_10_payment_method_name").value="Presenkort";
                                            validateGiftcard(read_cookie("code"),read_cookie("secret"),LastAmount-50,read_cookie("reservedID"));                                            
                                            //processThirdStep();
                                       
                                       }
                                       
                                       else if(document.getElementById("ec_webshop_page_10_payment_method_name").value=="Faktura")
                                       {
                                            var productId="93549982-a383-4e26-942b-f887f9a5e4d3";
                                            CallSoapReqForUpdatingBasketForGiftCard(pageId,positionId,pageType,productId,quantity,comments,action);                                            
                                            create_cookie("Success","1",1);
                                            document.getElementById("ec_webshop_page_10_payment_method_name").value="Presenkort";
                                            validateGiftcard(read_cookie("code"),read_cookie("secret"),LastAmount-29,read_cookie("reservedID"));
                                            //processThirdStep();
                                        
                                       }
                                      else{
                                       create_cookie("Success","1",1);                                   
                                       document.getElementById("ec_webshop_page_10_payment_method_name").value="Presenkort";                                   
                                       updatePaymentAttribute();
                                       //showUpdatingWindow();
                                       processThirdStep();
                                       //closeUpdatingWindow();
                                       }
                              }
                              
                              else
                              {
                                
                              
                                if(document.getElementById("ec_webshop_page_10_payment_method_name").value=="Presenkort"){
                                   
                                   document.getElementById("msg_giftcardmethod_step3").style.color = '#df0000';
                                   document.getElementById("msg_giftcardmethod_step3").style.padding= '0px 0px 0px 10px';
                                   document.getElementById("msg_giftcardmethod_step3").innerHTML = "meddelande vi fick från vår presentkort databas: Du har inte tillräckligt belopp i presentkort att gå vidare. Gå tillbaka och välj betalningssätt för balansen beloppet.";           
                                   //document.getElementById("dummyPayment").checked = false;
                                   create_cookie("Success","0",1);
                                    
                                   }
                                   
                                   else if(document.getElementById("ec_webshop_page_10_payment_method_name").value=="Postforskott")
                                   {
                                    if((LastAmount-50)<=ChargedAmount)
                                    {
                                        
                                        var productId="E6A161C7-EB20-4258-BE9C-1F590E44BED4";
                                        CallSoapReqForUpdatingBasketForGiftCard(pageId,positionId,pageType,productId,quantity,comments,action);
                                        validateGiftcard(read_cookie("code"),read_cookie("secret"),LastAmount-50,read_cookie("reservedID"));
                                    }
                                   
                                        create_cookie("Success","1",1);
                                        //processThirdStep();
                                   
                                   }
                                   
                                   else if(document.getElementById("ec_webshop_page_10_payment_method_name").value=="Faktura")
                                   {
                                    if((LastAmount-29)<=ChargedAmount)
                                    {
                                        
                                        var productId="93549982-a383-4e26-942b-f887f9a5e4d3";
                                        CallSoapReqForUpdatingBasketForGiftCard(pageId,positionId,pageType,productId,quantity,comments,action);
                                        validateGiftcard(read_cookie("code"),read_cookie("secret"),LastAmount-29,read_cookie("reservedID"));
                                    }
                                   
                                        create_cookie("Success","1",1);
                                        //processThirdStep();
                                    
                                   }
                                   
                                   else{
                                    create_cookie("Success","1",1);
                                    
                                   //document.getElementById("dummyPayment").checked = true;
                                   processThirdStep();
                                   }
                              }
    }
    closeUpdatingWindow();
}
function updatePaymentAttribute(){
     var pageId = _pageid;
     var positionId = _positionid;
     var pageType = pageType;
     var productId = productId;
     var quantity = quantity;
     var comments = comments;
     var action = action;
     var stage = "confirm";
     var createorder = "false";
     var shippingmethod; 
     var paymentmethod;
     var firstname;
     var lastname;
	 var middlename;
     var phone;	
     var vatnumber;
	var deliverydate;
	var pobox;
	var email;
	var city;
	var postalcode;
	var address;
	var organisation;
	var apartment;
	var region;
	var addressdescription;
	var credit_card_type;
	var credit_card_expire_month;
	var credit_card_expire_year;
	var bank_name;
	var name_on_card;
	var credit_card_number;
	var credit_card_expire;
	var cvc;
	var cardtype;
	
	 
	//alert(pageId+","+positionId+","+pageType+","+productId+","+quantity+","+comments+","+action);
	if(document.getElementById('ec_webshop_page_10_shippingmethod'))
		shippingmethod = document.getElementById('ec_webshop_page_10_shippingmethod').value;
	
	if(document.getElementById('ec_webshop_page_10_paymentmethod'))
		paymentmethod = document.getElementById('ec_webshop_page_10_paymentmethod').value;

	if(document.getElementById('ec_webshop_page_10_firstname'))
		firstname = document.getElementById('ec_webshop_page_10_firstname').value;
	
	if(document.getElementById('ec_webshop_page_10_lastname'))
		lastname = document.getElementById('ec_webshop_page_10_lastname').value;

	if(document.getElementById('ec_webshop_page_10_middlename'))
		middlename = document.getElementById('ec_webshop_page_10_middlename').value;

	if(document.getElementById('ec_webshop_page_10_phone'))
		phone = document.getElementById('ec_webshop_page_10_phone').value;
	
	if(document.getElementById('ec_webshop_page_10_vatnumber'))
		vatnumber = document.getElementById('ec_webshop_page_10_vatnumber').value;

	if(document.getElementById('ec_webshop_page_10_deliverydate'))
		deliverydate = document.getElementById('ec_webshop_page_10_deliverydate').value;
	
	if(document.getElementById('ec_webshop_page_10_newsletter'))
		pobox = document.getElementById('ec_webshop_page_10_newsletter').value;

	if(document.getElementById('ec_webshop_page_10_email'))
		email = document.getElementById('ec_webshop_page_10_email').value;
	
	if(document.getElementById('ec_webshop_page_10_city'))
		city = document.getElementById('ec_webshop_page_10_city').value;

	if(document.getElementById('ec_webshop_page_10_postalcode'))
		postalcode = document.getElementById('ec_webshop_page_10_postalcode').value;
	
	if(document.getElementById('ec_webshop_page_10_address'))
		address = document.getElementById('ec_webshop_page_10_address').value;

	if(document.getElementById('ec_webshop_page_10_organisation'))
		organisation = document.getElementById('ec_webshop_page_10_organisation').value;
	
	if(document.getElementById('ec_webshop_page_10_apartment'))
		apartment = document.getElementById('ec_webshop_page_10_apartment').value;
	
	if(document.getElementById('ec_webshop_page_10_region'))
		region = document.getElementById('ec_webshop_page_10_region').value;
	
	if(document.getElementById('ec_webshop_page_10_addressdescription'))
		addressdescription = document.getElementById('ec_webshop_page_10_addressdescription').value;
	
	if(document.getElementById('ec_webshop_page_10_credit_card_type'))
		credit_card_type = document.getElementById('ec_webshop_page_10_credit_card_type').value;
	
	if(document.getElementById('ec_webshop_page_10_credit_card_expire_month'))
		credit_card_expire_month = document.getElementById('ec_webshop_page_10_credit_card_expire_month').value;

	if(document.getElementById('ec_webshop_page_10_credit_card_expire_year'))
		credit_card_expire_year = document.getElementById('ec_webshop_page_10_credit_card_expire_year').value;
	
	if(document.getElementById('ec_webshop_page_10_bank_name'))
		bank_name = document.getElementById('ec_webshop_page_10_bank_name').value;

	if(document.getElementById('ec_webshop_page_10_name_on_card'))
		name_on_card = document.getElementById('ec_webshop_page_10_name_on_card').value;


	if(document.getElementById('ec_webshop_page_10_credit_card_number')){
		var cc_number = document.getElementById('ec_webshop_page_10_credit_card_number').value;
		credit_card_number = cc_number;

	}

	if(document.getElementById('ec_webshop_page_10_credit_card_expire'))
		credit_card_expire = document.getElementById('ec_webshop_page_10_credit_card_expire').value;

	if(document.getElementById('ec_webshop_page_10_cvc'))
		cvc = document.getElementById('ec_webshop_page_10_cvc').value;

	if(document.getElementById('ec_webshop_page_10_cardtype'))
		cardtype = document.getElementById('ec_webshop_page_10_cardtype').value;
	//Gift Card Payment	
    paymentmethod="75ae0613-d4b9-4064-8821-28381b5b6a24";
   var queryparam = "<orderinfo><shippingmethod>"+shippingmethod+"</shippingmethod><paymentmethod>"+paymentmethod+"</paymentmethod><attributes><attribute><name>firstname</name><value>"+firstname+"</value></attribute><attribute><name>lastname</name><value>"+lastname+"</value></attribute><attribute><name>middlename</name><value>"+middlename+"</value></attribute><attribute><name>phone</name><value>"+phone+"</value></attribute><attribute><name>vatnumber</name><value>"+vatnumber+"</value></attribute><attribute><name>deliverydate</name><value>"+deliverydate+"</value></attribute><attribute><name>pobox</name><value>"+pobox+"</value></attribute><attribute><name>email</name><value>"+email+"</value></attribute><attribute><name>city</name><value>"+city+"</value></attribute><attribute><name>postalcode</name><value>"+postalcode+"</value></attribute><attribute><name>address</name><value>"+address+"</value></attribute><attribute><name>organisation</name><value>"+organisation+"</value></attribute><attribute><name>apartment</name><value>"+apartment+"</value></attribute><attribute><name>region</name><value>"+region+"</value></attribute><attribute><name>addressdescription</name><value>"+addressdescription+"</value></attribute><attribute><name>credit_card_type</name><value>"+credit_card_type+"</value></attribute><attribute><name>credit_card_expire_month</name><value>"+credit_card_expire_month+"</value></attribute><attribute><name>credit_card_expire_year</name><value>"+credit_card_expire_year+"</value></attribute><attribute><name>bank_name</name><value>"+bank_name+"</value></attribute><attribute><name>name_on_card</name><value>"+name_on_card+"</value></attribute><attribute><name>credit_card_number</name><value>"+credit_card_number+"</value></attribute><attribute><name>credit_card_expire</name><value>"+credit_card_expire+"</value></attribute><attribute><name>cvc</name><value>"+cvc+"</value></attribute><attribute><name>cardtype</name><value>"+cardtype+"</value></attribute></attributes><queryparams><querystring><name>confirm</name><value>true</value></querystring></queryparams></orderinfo>";
   queryparam = queryparam.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;')
   var positionId1 = "10";
	 			 			var pageType1 = "1";
				 			var soapBodyOrderprocess = new SOAPObject("orderProcess");
  			         			soapBodyOrderprocess.ns = "http://tempuri.org/";
     							soapBodyOrderprocess.appendChild(new SOAPObject("pageId")).val(pageId);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("positionId")).val(positionId1);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("pageType")).val(pageType1);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("stage")).val(stage);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("createorder")).val(createorder);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("orderInfoXml")).val(queryparam);
 				 			var OrderSR = new SOAPRequest("http://tempuri.org/orderProcess", soapBodyOrderprocess); //Request is now ready to be sent to a web-service
     				 			OrderSR.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     				 			OrderSR.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
				 			//Lets send it
     							SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     							SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
							SOAPClient.SendRequest(OrderSR,orderProcessResponse1); //Send request to server and assign callback function
 }

function orderProcessResponse1(resObj){}

function clearAttributes(){
    var createorder = "false";
    var queryparam = "<orderinfo><attributes><attribute><name>custom_reservedID</name><value>0</value></attribute><attribute><name>custom_ChargedAmount</name><value>0</value></attribute><attribute><name>custom_BalanceAmount</name><value>0</value></attribute><attribute><name>custom_GiftCardNumber</name><value>0</value></attribute><attribute><name>custom_GiftCardCode</name><value>0</value></attribute><attribute><name>fax</name><value>0</value></attribute></attributes></orderinfo>";
    queryparam = queryparam.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');  
    var pageId = read_cookie('pageid');
    var positionId = read_cookie('positionid');
    var pageType = 2;
    var quantity = 1; 
    var stage = "info";       
    
     var soapBodyOrderprocess = new SOAPObject("orderProcess");
     soapBodyOrderprocess.ns = "http://tempuri.org/";
     soapBodyOrderprocess.appendChild(new SOAPObject("pageId")).val(pageId);
     soapBodyOrderprocess.appendChild(new SOAPObject("positionId")).val(positionId);
     soapBodyOrderprocess.appendChild(new SOAPObject("pageType")).val(pageType);
     soapBodyOrderprocess.appendChild(new SOAPObject("stage")).val(stage);
     soapBodyOrderprocess.appendChild(new SOAPObject("createorder")).val(createorder);
     soapBodyOrderprocess.appendChild(new SOAPObject("orderInfoXml")).val(queryparam);
     
     var OrderSR = new SOAPRequest("http://tempuri.org/orderProcess", soapBodyOrderprocess); //Request is now ready to be sent to a web-service
     OrderSR.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     OrderSR.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
     SOAPClient.SendRequest(OrderSR,ClearProcessResponse); //Send request to server and assign callback function 
     function ClearProcessResponse(resObj){}
 }
 function CallSoapReqForUpdatingBasketForGiftCard(pageId,positionId,pageType,productId,quantity,comments,action)
{
     //var pageId = pageId;
     //var positionId = positionId;
     var pageId = _pageid;
     var positionId = _positionid;

     var pageType = pageType;
     var productId = productId;
     var quantity = quantity;
     var comments = comments;
     var action = action;
     var stage = "confirm";
     var createorder = "false";
     var shippingmethod; 
     var paymentmethod;		

      	var firstname;
     	var lastname;
	var middlename;
     	var phone;	
      	var vatnumber;
	var deliverydate;
	var pobox;
	var email;
	var city;
	var postalcode;
	var address;
	var organisation;
	var apartment;
	var region;
	var addressdescription;
	var credit_card_type;
	var credit_card_expire_month;
	var credit_card_expire_year;
	var bank_name;
	var name_on_card;
	var credit_card_number;
	var credit_card_expire;
	var cvc;
	var cardtype;
	
	 
	//alert(pageId+","+positionId+","+pageType+","+productId+","+quantity+","+comments+","+action);
	if(document.getElementById('ec_webshop_page_10_shippingmethod'))
		shippingmethod = document.getElementById('ec_webshop_page_10_shippingmethod').value;
	
	if(document.getElementById('ec_webshop_page_10_paymentmethod'))
		 paymentmethod="55201ff1-5fa1-4ce3-b950-8495a332f10d";

	if(document.getElementById('ec_webshop_page_10_firstname'))
		firstname = document.getElementById('ec_webshop_page_10_firstname').value;
	
	if(document.getElementById('ec_webshop_page_10_lastname'))
		lastname = document.getElementById('ec_webshop_page_10_lastname').value;

	if(document.getElementById('ec_webshop_page_10_middlename'))
		middlename = document.getElementById('ec_webshop_page_10_middlename').value;

	if(document.getElementById('ec_webshop_page_10_phone'))
		phone = document.getElementById('ec_webshop_page_10_phone').value;
	
	if(document.getElementById('ec_webshop_page_10_vatnumber'))
		vatnumber = document.getElementById('ec_webshop_page_10_vatnumber').value;

	if(document.getElementById('ec_webshop_page_10_deliverydate'))
		deliverydate = document.getElementById('ec_webshop_page_10_deliverydate').value;
	
	if(document.getElementById('ec_webshop_page_10_newsletter'))
		pobox = document.getElementById('ec_webshop_page_10_newsletter').value;

	if(document.getElementById('ec_webshop_page_10_email'))
		email = document.getElementById('ec_webshop_page_10_email').value;
	
	if(document.getElementById('ec_webshop_page_10_city'))
		city = document.getElementById('ec_webshop_page_10_city').value;

	if(document.getElementById('ec_webshop_page_10_postalcode'))
		postalcode = document.getElementById('ec_webshop_page_10_postalcode').value;
	
	if(document.getElementById('ec_webshop_page_10_address'))
		address = document.getElementById('ec_webshop_page_10_address').value;

	if(document.getElementById('ec_webshop_page_10_organisation'))
		organisation = document.getElementById('ec_webshop_page_10_organisation').value;
	
	if(document.getElementById('ec_webshop_page_10_apartment'))
		apartment = document.getElementById('ec_webshop_page_10_apartment').value;
	
	if(document.getElementById('ec_webshop_page_10_region'))
		region = document.getElementById('ec_webshop_page_10_region').value;
	
	if(document.getElementById('ec_webshop_page_10_addressdescription'))
		addressdescription = document.getElementById('ec_webshop_page_10_addressdescription').value;
	
	if(document.getElementById('ec_webshop_page_10_credit_card_type'))
		credit_card_type = document.getElementById('ec_webshop_page_10_credit_card_type').value;
	
	if(document.getElementById('ec_webshop_page_10_credit_card_expire_month'))
		credit_card_expire_month = document.getElementById('ec_webshop_page_10_credit_card_expire_month').value;

	if(document.getElementById('ec_webshop_page_10_credit_card_expire_year'))
		credit_card_expire_year = document.getElementById('ec_webshop_page_10_credit_card_expire_year').value;
	
	if(document.getElementById('ec_webshop_page_10_bank_name'))
		bank_name = document.getElementById('ec_webshop_page_10_bank_name').value;

	if(document.getElementById('ec_webshop_page_10_name_on_card'))
		name_on_card = document.getElementById('ec_webshop_page_10_name_on_card').value;

	/*if(document.getElementById('ec_webshop_page_10_credit_card_number'))
		credit_card_number = document.getElementById('ec_webshop_page_10_credit_card_number').value;*/

	if(document.getElementById('ec_webshop_page_10_credit_card_number')){
		var cc_number = document.getElementById('ec_webshop_page_10_credit_card_number').value;
		credit_card_number = cc_number;
		/*if(cc_number.length > 0)
			credit_card_number = document.getElementById('ec_webshop_page_10_credit_card_number').value;
		else
			credit_card_number = '0000000000000001';*/
	}

	if(document.getElementById('ec_webshop_page_10_credit_card_expire'))
		credit_card_expire = document.getElementById('ec_webshop_page_10_credit_card_expire').value;

	if(document.getElementById('ec_webshop_page_10_cvc'))
		cvc = document.getElementById('ec_webshop_page_10_cvc').value;

	if(document.getElementById('ec_webshop_page_10_cardtype'))
		cardtype = document.getElementById('ec_webshop_page_10_cardtype').value;




   var queryparam = "<orderinfo><shippingmethod>"+shippingmethod+"</shippingmethod><paymentmethod>"+paymentmethod+"</paymentmethod><attributes><attribute><name>firstname</name><value>"+firstname+"</value></attribute><attribute><name>lastname</name><value>"+lastname+"</value></attribute><attribute><name>middlename</name><value>"+middlename+"</value></attribute><attribute><name>phone</name><value>"+phone+"</value></attribute><attribute><name>vatnumber</name><value>"+vatnumber+"</value></attribute><attribute><name>deliverydate</name><value>"+deliverydate+"</value></attribute><attribute><name>pobox</name><value>"+pobox+"</value></attribute><attribute><name>email</name><value>"+email+"</value></attribute><attribute><name>city</name><value>"+city+"</value></attribute><attribute><name>postalcode</name><value>"+postalcode+"</value></attribute><attribute><name>address</name><value>"+address+"</value></attribute><attribute><name>organisation</name><value>"+organisation+"</value></attribute><attribute><name>apartment</name><value>"+apartment+"</value></attribute><attribute><name>region</name><value>"+region+"</value></attribute><attribute><name>addressdescription</name><value>"+addressdescription+"</value></attribute><attribute><name>credit_card_type</name><value>"+credit_card_type+"</value></attribute><attribute><name>credit_card_expire_month</name><value>"+credit_card_expire_month+"</value></attribute><attribute><name>credit_card_expire_year</name><value>"+credit_card_expire_year+"</value></attribute><attribute><name>bank_name</name><value>"+bank_name+"</value></attribute><attribute><name>name_on_card</name><value>"+name_on_card+"</value></attribute><attribute><name>credit_card_number</name><value>"+credit_card_number+"</value></attribute><attribute><name>credit_card_expire</name><value>"+credit_card_expire+"</value></attribute><attribute><name>cvc</name><value>"+cvc+"</value></attribute><attribute><name>cardtype</name><value>"+cardtype+"</value></attribute></attributes><queryparams><querystring><name>confirm</name><value>true</value></querystring></queryparams></orderinfo>";

 

     //var queryparam = "<orderinfo><queryparams><querystring><name>confirm</name><value>true</value></querystring></queryparams></orderinfo>";
     queryparam = queryparam.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;')
     var soapBody = new SOAPObject("processBasket");
     soapBody.ns = "http://tempuri.org/";
     soapBody.appendChild(new SOAPObject("pageId")).val(pageId);
     soapBody.appendChild(new SOAPObject("positionId")).val(positionId);
     soapBody.appendChild(new SOAPObject("pageType")).val(pageType);
     soapBody.appendChild(new SOAPObject("productId")).val(productId);
     soapBody.appendChild(new SOAPObject("quantity")).val(quantity);
     soapBody.appendChild(new SOAPObject("comments")).val(comments);
     soapBody.appendChild(new SOAPObject("action")).val(action);
     soapBody.appendChild(new SOAPObject("option")).val(""); 
     //Create a new SOAP Request
     var sr = new SOAPRequest("http://tempuri.org/processBasket", soapBody); //Request is now ready to be sent to a web-service
     sr.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     sr.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
     //Lets send it
     SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
     SOAPClient.SendRequest(sr,processResponse); //Send request to server and assign callback function
		function processResponse(respObj) 
			{
				try 
                   			{
						if(document.getElementById("oldproductquantity_"+productId)){
							var oldquantity = document.getElementById("oldproductquantity_"+productId).value;
							create_cookie('oldcustomvalue_'+productId,oldquantity,1);
							//alert("Cookie::"+read_cookie('oldcustomvalue_'+productId));
						}
                   				var responseMessage = respObj.Body[0].processBasketResponse[0].processBasketResult[0].root[0];
                   				var htmlData = responseMessage.htmldata[0].Text;
			       			largeCartStart = htmlData.indexOf('<LARGECART>');
			       			largeCartEnd = htmlData.indexOf('</LARGECART>');
		           			smallCartStart = htmlData.indexOf('<SMALLCART>');
			       			smallCartEnd = htmlData.indexOf('</SMALLCART>'); 
			        		start = htmlData.indexOf('<tsd>');
						start = start + 5 ;
						end = htmlData.indexOf('</tsd>');
						totvalue = htmlData.substring(start,end);
						startfright=htmlData.indexOf('<tfd>');
						startfright=startfright+5;
						endfright=htmlData.indexOf('</tfd>');
						freightamt=htmlData.substring(startfright,endfright)
						startprod=htmlData.indexOf('<tcd>');
						startprod=startprod+5;
						endprod=htmlData.indexOf('</tcd>');
						prodqnty=htmlData.substring(startprod,endprod)
					    startprodqnty=htmlData.indexOf('<tqd>');
						startprodqnty=startprodqnty+5;
						endprodqnty=htmlData.indexOf('</tqd>');
						prodqntycnt=htmlData.substring(startprodqnty,endprodqnty)
						calctot(totvalue,freightamt,prodqnty,prodqntycnt);
                        //_totalAmount = totvalue;
                        
				   		document.getElementById("large_cart").innerHTML = htmlData.substring(largeCartStart,largeCartEnd); 
			       			document.getElementById("small_cart_container").innerHTML = htmlData.substring(smallCartStart,smallCartEnd);
				       		if(parseInt(quantity) != 1)	
		             				setCount(productId);
		           			if(document.getElementById('order_button')) 
				   				document.getElementById('order_button').href = document.getElementById('checkout_button').href;
				  	        if(document.getElementById('customvalue_'+productId))	
			     					document.getElementById('customvalue_'+productId).value = read_cookie('ProductCustomCount'+productId);	
			     			var shippingProduct = read_cookie('shippingProduct');
			     			var shippingcomments = '&lt;options&gt;&lt;category&gt;Frakt&lt;/category&gt;&lt;/options&gt;';
			     			//if (shippingProduct == "" && action != 'clear' && read_cookie('shippingproductexist') != 'yes')
				         			//CallSoapReqForGettingLeastShippingProduct(pageId,positionId,shippingcomments);

			     			if(action=="clear")	{
							create_cookie('shippingProduct','',-1);
							create_cookie('paymentProduct','',-1);
							create_cookie('greeting','',-1);
							create_cookie('wrapper','',-1);	
							create_cookie('voucherProductAdded','',-1);
							create_cookie('oldcustomvalue_'+productId,'',-1);
							_leastshippingid = '';
						}
						if (shippingProduct != "")
						{
							closeUpdatingWindow();
							}
				    
						/** This function will rewrite the html of orderprocess step 3 basket**/

						var url = document.location.href;
			     			if(url.indexOf('/steg3/')>-1){
							var positionId1 = "10";
	 			 			var pageType1 = "1";
				 			var soapBodyOrderprocess = new SOAPObject("orderProcess");
  			         			soapBodyOrderprocess.ns = "http://tempuri.org/";
     							soapBodyOrderprocess.appendChild(new SOAPObject("pageId")).val(pageId);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("positionId")).val(positionId1);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("pageType")).val(pageType1);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("stage")).val(stage);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("createorder")).val(createorder);
     				 			soapBodyOrderprocess.appendChild(new SOAPObject("orderInfoXml")).val(queryparam);
 				 			var OrderSR = new SOAPRequest("http://tempuri.org/orderProcess", soapBodyOrderprocess); //Request is now ready to be sent to a web-service
     				 			OrderSR.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
     				 			OrderSR.addNamespace("xsd","http://www.w3.org/2001/XMLSchema");
				 			//Lets send it
     							SOAPClient.Proxy = "/designtorget/editor/soap/ecbusiness.asmx"; //Specify web-service address (if local to your domain) or a proxy file
     							SOAPClient.SOAPServer = "/designtorget/editor/soap/ecbusiness.asmx";
							SOAPClient.SendRequest(OrderSR,orderProcessResponse); //Send request to server and assign callback function
				 		}
				
			     			/** to assign the free freight price in postpaket shipping method **/

			     			if(url.indexOf('/steg2/')>-1){
							if(document.getElementById("postpaket").checked)
								document.getElementById("postpaket_price").innerHTML=trim(document.getElementById("frieghtPrice").innerHTML).replace('kr','');
							if(totvalue >= 500)
								document.getElementById("postpaket_price").innerHTML=0;
 							else
								document.getElementById("postpaket_price").innerHTML=Math.round(postpaket_currentPrice);
					 		
						}
						//CallSoapReqForLoginCustomProperty(productId,quantity,action,comments);

                        		} 
                        	catch(e) { 
                        		        alert(e); 
                              
                        		}
		   	}


			function orderProcessResponse(orderRespObj) {
				try {
						
					var orderResponseMessage = orderRespObj.Body[0].orderProcessResponse[0].orderProcessResult[0].root[0];
			     		var basketHtmlData = orderResponseMessage.htmldata[0].Text;
			     		basketStart = basketHtmlData.indexOf('<ORDERPROCESSBASKET>');
			     		basketEnd = basketHtmlData.indexOf('</ORDERPROCESSBASKET>');
                             		document.getElementById("orderProcessBasket").innerHTML = basketHtmlData.substring(basketStart,basketEnd); 

				    }
				catch(e) { 
                                    alert(e); 
                              
                       		 }
			}	
		
}


 /** gift card end ***/
