function getCookie(c_name){
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
	{
	c_start=c_start + c_name.length+1;
	c_end=document.cookie.indexOf(";",c_start);
	if (c_end==-1) c_end=document.cookie.length;
	return unescape(document.cookie.substring(c_start,c_end));
	}
  }
return "";
}

function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1 + x2;
}


function r2(n) { 
  ans = n * 1000 
  ans = Math.round(ans /10) + "" 
  while (ans.length < 3) {ans = "0" + ans} 
  len = ans.length 
  ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
  return ans 
}

	function SetCNShipping(ShippingID,ShowClass,HideClass,ShippingCost,TotPrice){

		$('#ShopMainLayOutTable .'+ ShowClass).show();
		$('#ShopMainLayOutTable .'+ HideClass).hide();
		
		$('#ShopMainLayOutTable .ShippingTotPrice').text(parseFloat(TotPrice.toFixed(2))+parseFloat(ShippingCost))

		$('#ShopMainLayOutTable .ShippingTotPrice').text(addCommas(r2($('#ShopMainLayOutTable .ShippingTotPrice').text())))
	
		setCookie('StandardShippingID',ShippingID,1)
	
		$('.DeleveryTable').css('border','1px solid #ffffff');
	
	}



function GoToStep1(w){
	/*
	if ($('#CheckBox1').is(':checked') || $('#CheckBox2').is(':checked') ){
		location.href = "/shop/order1.html"
	}else{
		$('.DeleveryTable').css('border','1px solid #b60e01');
		alert('Du mangler udfylde leveringsform');
		w.setAttribute('href', '#');
	}
	*/
}



$(document).ready(function(){
/*						   
	if	(location.href.indexOf('/showbasket.html') != -1){







//		$('input[name=submitorder]').click(function(){return $('#acceptTermsBit').is(':checked')})




		DataFromTot = parseFloat($('#ShopMainLayOutTable .ShippingTotPrice').text().replace('.','').replace(',','.'))-parseFloat($('#ShopMainLayOutTable #BasketShippingFee').text().replace('.','').replace(',','.'));

		$('#ShopMainLayOutTable #shows').show();
		
		$('#ShopMainLayOutTable .InsertShippingContent').append("\
			<table border='0' cellspacing='0' cellpadding='0' width='100%' style='border:1px solid #ffffff;' class='DeleveryTable'> \
				<tr> \
					<td class='DeleveryCellType1' colspan='2'><h2 style='margin-top:0px;margin-bottom:5px;font-size:13px;padding-left:20px;'>Vælg leveringsform</h2></td> \
					<td class='DeleveryCellType2' valign='top'>&nbsp;</td> \
				</tr> \	<tr> \
					<td class='DeleveryCellType1' valign='top' align='right'><label for='CheckBox1'><img src='/images/template/DeleveryHome.png' align='top' hspace='20'></label><input id='CheckBox1' style='margin-top:10px;' onClick=\"SetCNShipping('1','Shipping1','Shipping2',"+ Shipping1.replace(',','.') +","+ DataFromTot +");\" type='radio' name='ShippingMethodID'></td> \
					<td class='DeleveryCellType2'><label for='CheckBox1'><span class='ChangeColor'><b>Privat levering</b></span>&nbsp;("+ Shipping1 +"&nbsp;DKK)<br>Pakken sendes til din egen privatadresse el. anden privatadresse<br><br></label></td> \
					<td class='DeleveryCellType2 Shipping1' valign='top'>"+ Shipping1 +" DKK</td> \
				</tr> \
				<tr> \
					<td class='DeleveryCellType1' width='135' valign='top' align='right'><label for='CheckBox2'><img src='/images/template/DeleveryWork.png' align='top' hspace='20'  vspace='12'></label><input id='CheckBox2' style='margin-top:22px;' onClick=\"SetCNShipping('57','Shipping2','Shipping1',"+ Shipping2.replace(',','.') +","+ DataFromTot +");\" type='radio' name='ShippingMethodID'></td> \
					<td class='DeleveryCellType3 ChangeColor' width='459'><label for='CheckBox2'><span class='ChangeColor'><b>Job eller erhvervs levering</b></span>&nbsp;("+ Shipping2 +"&nbsp;DKK)<br>Denne leveringsform kræver en erhvervsadresse <br>vi kan levere til. Firma, job eller institutioner.<br>Erhvervsadresse: Alle adresser med CVR nummer<br><br></label></td> \
					<td class='DeleveryCellType3 Shipping2' valign='top'>"+ Shipping2 +" DKK</td> \
				</tr> \
			</table>")
		
//		SetCNShipping('1','Shipping1','Shipping2',Shipping1.replace(',','.'),DataFromTot);
//		$('#ShopMainLayOutTable .Shipping2').hide();
		$('#ShopMainLayOutTable .Shipping1').hide();
		$('#ShopMainLayOutTable .Shipping2').hide();

		if (getCookie('StandardShippingID') == ''){$('#ShopMainLayOutTable #CheckBox1').attr("checked", "checked");SetCNShipping('1','Shipping1','Shipping2',Shipping1.replace(',','.'),DataFromTot);}
		if (getCookie('StandardShippingID') == 1){$('#ShopMainLayOutTable #CheckBox1').attr("checked", "checked");SetCNShipping('1','Shipping1','Shipping2',Shipping1.replace(',','.'),DataFromTot);}
		if (getCookie('StandardShippingID') == 57){$('#ShopMainLayOutTable #CheckBox2').attr("checked", "checked");SetCNShipping('57','Shipping2','Shipping1',Shipping2.replace(',','.'),DataFromTot);}

	}
	*/
/*	
	if	(location.href.indexOf('order1.html') != -1){
		
//		if (location.href.indexOf('marcus') != -1){
			
//			alert($('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL input').length)

			if ($('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL input').length != 0){
	
				$('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL').before('<table id="NewProfileTable" border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td width="50%" valign="top" class="LoadProfileTD1">'+ $('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL td').eq(0).html() +'</td><td width="50%" valign="top" class="LoadProfileTD2"><br><form method="POST" name="loadprofile" action="/shop/order1.html" style="margin:0px;"><input type="hidden" value="1" name="loadprofile">Indtast telefon nr.<br><input type="text" class="TextInputField_Orderstep1" size="25" name="profileid" id="profileid" value="" style="width:150px;"><input type="image" src="/images/template/hent.png" style="position:relative;top:4px;left:15px;"></form></td></tr><table>')
				
				$('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL').remove()
				$('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL').remove()
				$('#ShopMainLayOutTable .Heading_Orderstep1').next('table').remove()
			
			}else{
			
				$('#NewProfileTable').remove()
				$('#ShopMainLayOutTable .HR_OrderStep1').remove()
				$('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL').remove()
				$('#ShopMainLayOutTable .LoadProfile_Orderstep1_TBL').remove()
				$('#ShopMainLayOutTable .Heading_Orderstep1').next('table').remove()

			}		
		
//		}
		
		if (getCookie('StandardShippingID') == 1){
		
			$('#ShopMainLayOutTable .OptionSelect_Orderstep1').eq(0).val('0');
			ToggleFields();

			$('#ShopMainLayOutTable .CustomerData_Orderstep1_TBL').before('<div class="Step1Notification"><h2 style="margin-top:7px;margin-bottom:7px;">Privatlevering</h2>Du har valgt privatlevering. Husk du kan spare en tur på posthuset, ved at få sendt pakken til dit arbejde. Vælg <a href="/shop/showbasket.html" style="color:#000000;text-decoration:underline;">erhvervs levering ved at klikke her.</a></div>')

		}else{

			$('#ShopMainLayOutTable .OptionSelect_Orderstep1').eq(0).val('1');
			ToggleFields();

			$('#ShopMainLayOutTable .CustomerData_Orderstep1_TBL').before('<div class="Step1Notification"><h2 style="margin-top:15px;margin-bottom:15px;">Erhvervslevering</h2>Du har valgt erhvervslevering, som kræver der leveres til enten en virksomhed eller institution. Hvis dette ikke sker, bliver ordren annulleret.<br>Skal din bestilling sendes til privat leveringsadresse, så vælg <a href="/shop/showbasket.html" style="color:#000000;text-decoration:underline;">Privat levering ved at klikke her.</a></div>')

			$('#ShopMainLayOutTable .OptionSelect_Orderstep1').eq(0).parent().parent().after('<tr><td>Vælg leveringssted</td><td><select class="OptionSelect_Orderstep1"><option>Erhverv</option><option>Institution</option></select></td></tr>')

		}
		
		$('#ShopMainLayOutTable .OptionSelect_Orderstep1').eq(0).hide();
		$('#ShopMainLayOutTable .OptionSelect_Orderstep1').eq(0).parent().parent().hide();
	}

	if	(location.href.indexOf('order2.html') != -1){

		if (getCookie('StandardShippingID') == 1){
		
			$('#ShopMainLayOutTable #ShippingMethodID1').attr("checked", "checked");
			GetMethods('PayMethods','1',document.getElementById('PayMethodsContainer'),'')
		
		}else{

			$('#ShopMainLayOutTable #ShippingMethodID57').attr("checked", "checked");
			GetMethods('PayMethods','57',document.getElementById('PayMethodsContainer'),'')

		}

		$('#ShopMainLayOutTable #ShippingMethodsContainer').parent().parent().prev().hide();
		$('#ShopMainLayOutTable #ShippingMethodsContainer').hide();

	}
	
	if ($('#ShopMainLayOutTable #ShippingMethodsContainer input').length == 2){
	
		$('#ShopMainLayOutTable #ShippingMethodsContainer').parent().parent().prev().show();
		$('#ShopMainLayOutTable #ShippingMethodsContainer').show();

		$('#ShopMainLayOutTable #'+ $('#ShopMainLayOutTable #ShippingMethodsContainer input').eq(0).attr('id')).attr("checked", "checked");
		GetMethods('PayMethods',''+ $('#ShopMainLayOutTable #ShippingMethodsContainer input').eq(0).attr('id').replace('ShippingMethodID','') +'',document.getElementById('PayMethodsContainer'),'')

	}

*/






	if	(location.href.indexOf('/order1.html') != -1){

		$('#ShopMainLayOutTable .SubmitButton_Orderstep1_Position').click(function() {

			var SelectBrandToUbivoxTemp='';
			$('#SelectBrandToUbivox input:checked').each(function() {
				SelectBrandToUbivoxTemp = SelectBrandToUbivoxTemp + $(this).val() +' '
			})

			CNName = $('#ShopMainLayOutTable .CustomerData_Orderstep1_TBL #name').val();
			CNadress = $('#ShopMainLayOutTable .CustomerData_Orderstep1_TBL #email').val();
			
			if ($('#ShopMainLayOutTable .CustomerData_Orderstep1_TBL table:first input:checked').eq(0).val() == 'ON' && CNadress.length >= 1){
				setCookie('Ubivox-Name',CNName,365);
				setCookie('Ubivox-Brand',SelectBrandToUbivoxTemp,365);
				setCookie('Ubivox-Mail',CNadress,365);
			}else{
				setCookie('Ubivox-Name','',-1);
				setCookie('Ubivox-Brand','',-1);
				setCookie('Ubivox-Mail','',-1);
			}
	
		});

	}

	if	(location.href.indexOf('/order4.html') != -1){
		
		if (getCookie('Ubivox-Mail') != ''){
			$('body').append('<iframe width="10" height="10" src="/ubivox/communicate.asp?Ubivox-Mail='+ getCookie('Ubivox-Mail') +'&Ubivox-Name='+ getCookie('Ubivox-Name') +'&Ubivox-Brand='+ getCookie('Ubivox-Brand') +'"></iframe>')
		}

	}

});
