function matchHeight()
{
	var divs,contDivs,maxHeight,divHeight,d;
	// get all <div> elements in the document
	divs=document.getElementsByTagName('div');
	contDivs=[];
	// initialize maximum height value
	maxHeight=0;
	// iterate over all <div> elements in the document
	for(var i=0;i<divs.length;i++)
	{
		// make collection with <div> elements with class attribute 'column'
		if(/\bcolumn\b/.test(divs[i].className))
		{
			d=divs[i];
			contDivs[contDivs.length]=d;
			// determine height for <div> element
			if(d.offsetHeight)
			{
				divHeight=d.offsetHeight;
			}
			else
			{
				if(d.style.pixelHeight)
				{
					divHeight=d.style.pixelHeight;
				}
			}
			// calculate maximum height
			maxHeight=Math.max(maxHeight,divHeight);
		}
	}
	// assign maximum height value to all of container <div> elements
	for(var i=0;i<contDivs.length;i++)
	{
		contDivs[i].style.height=maxHeight+'px';
	}
}

function logincheckoutenter(e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if(keycode==13)
	{
		CheckPasswordAccount(document.getElementById('email2').value,document.getElementById('password_checkout').value,'true');
		return false;
	}
	else
	{
		return true;
	}
}

function loginenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
	{
		mylogin();
		return false;
	}
	else
	{
		return true;
	}
}

function setSort(sort, sortorder)
{
	var keeper = new sack();
	keeper.requestFile="/setsort.php?sort="+sort+"&sortorder="+sortorder;
	keeper.onCompletion=function()
	{
		document.location.reload();
	}
	keeper.runAJAX();
}

function html_entity_decode(str)
{
	var ta = document.createElement("textarea");
	ta.innerHTML = str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
	return ta.value;
}

function fctCheckout(lang,country,action,stars)
{
	switch (action)
	{
		case "recalculate":
		document.getElementById('subaction').value="recalculate";
		document.basket.action="/cart.php?subaction=recalculate&lang="+lang+"&transcountry="+country;
		document.basket.submit()
		break;

		case "checkout":
		document.getElementById('subaction').value="checkout";
		document.basket.action="/checkout.php?lang="+lang+"&transcountry="+country;
		//document.basket.submit();
		document.location="/checkout.php?lang="+lang+"&transcountry="+country;
		break;
	}
}

function CheckOutController(id,lang)
{
	$('checkoutproclogin').hide();
	$('checkoutprocinvoice').hide();
	$('checkoutprocdelivery').hide();
	$('checkoutprocpayment').hide();
	$('checkoutprocoverview').hide();
	$('checkoutprocconfirmation').hide();
	switch(id)
	{
		case 1:
		CheckPasswordAccount($('email').value, $('password').value,'true');
		break;
		case 2:
		CheckFacData();
		break;
		case 3:
		CheckDelData()
		break;
		case 4:
		SetPaymentSub(lang);
		GetProcOverview(lang);
		break;
	}
	//buttonsIE();
}

function CheckFacData()
{
	var empty = "no";

	if(!CheckForEmpty($('inv_lastname').value, $('error-invoice'), 'inv_lastname'))
	{
		empty = "yes";
	}
	if(!CheckForEmpty($('inv_firstname').value, $('error-invoice'), 'inv_firstname'))
	{
		empty = "yes";
	}
	if(!CheckForEmpty($('inv_address').value, $('error-invoice'), 'inv_address'))
	{
		empty = "yes";
	}
	if(!CheckForEmpty($('inv_zipcode').value, $('error-invoice'), 'inv_zipcode'))
	{
		empty = "yes";
	}
	if(!CheckForEmpty($('inv_city').value, $('error-invoice'), 'inv_city'))
	{
		empty = "yes";
	}

	if($('inv_vattype').value=='B')
	{
		if(!CheckForEmpty($('inv_companyname').value, $('error-invoice'), 'inv_companyname'))
		{
			empty = "yes";
		}
		if(!CheckForEmpty($('inv_vatpr').value, $('error-invoice'), 'inv_vatpr'))
		{
			empty = "yes";
		}
		if(!CheckForEmpty($('inv_vatnr').value, $('error-invoice'), 'inv_vatnr'))
		{
			empty = "yes";
		}
		else
		{
			if(CheckBTWnr($('inv_vatpr').value, $('inv_vatnr').value)>1)
			{
				empty = "yes";
				$('error-invoice').style.display = 'block';
				$('inv_vatpr').className = 'inputformerror';
				$('inv_vatnr').className = 'inputformerror';
			}
			else
			{
				$('inv_vatpr').className = 'inputform';
				$('inv_vatnr').className = 'inputform';
			}
		}

	}
	if(empty == "no")
	{
		$('error-invoice').style.display = 'none';
		$('checkoutprocdelivery').show();
		document.getElementById("chkdeliveryon").focus();

		var pageTracker = _gat._getTracker("UA-12224174-1");
		pageTracker._trackPageview("/checkout/deliveryinfo");
		/*$('subtabinvoice').style.display = 'block';
		$('subtabinvoice').innerHTML = $('inv_firstname').value+' '+$('inv_lastname').value+'<br>'+$('inv_address').value+'<br>'+$('inv_zipcode').value+' '+$('inv_city').value;*/

		if($('inv_vattype').value=='B')
		{
			//$('subtabinvoice').innerHTML =  $('inv_companyname').value+'<br>'+ $('subtabinvoice').innerHTML;
		}

		$('tabinvoice').className = 'checkoutproctab';
		$('tabdelivery').className = 'checkoutproctabsel';
	}
	else
	{
		$('checkoutprocinvoice').show();
	}
}

function CheckDelData()
{
	if(document.getElementById('chkdeliveryon').checked)
	{
		// facturatiegegevens zijn zelfde als transportgegevens
		$('delivcountrycode').value = $('inv_countrycode').value
		$('delivcompanyname').value = $('inv_companyname').value
		$('delivfirstname').value = $('inv_firstname').value
		$('delivlastname').value = $('inv_lastname').value
		$('delivaddress').value = $('inv_address').value
//		$('delivaddress2').value = $('inv_address2').value
		$('delivcity').value = $('inv_city').value
		$('delivzipcode').value = $('inv_zipcode').value
		//		$('delivtitleno').value = $('inv_titleno').value
		$('delivphone').value = $('inv_phone').value
		$('delivmobile').value = $('inv_mobile').value
		$('checkoutprocpayment').show();
		document.getElementById("pay1").focus();
		var pageTracker = _gat._getTracker("UA-12224174-1");
		pageTracker._trackPageview("/checkout/paymentinfo");
		/*$('subtabdelivery').style.display = 'block';
		$('subtabdelivery').innerHTML = $('delivfirstname').value+' '+$('delivlastname').value+'<br>'+$('delivaddress').value+'<br>'+$('delivzipcode').value+' '+$('delivcity').value;

		if ($('delivcompanyname').value != '')
		{
		$('subtabdelivery').innerHTML = $('delivcompanyname').value + '<br>'+$('subtabdelivery').innerHTML;
		}*/

		$('tabdelivery').className = 'checkoutproctab';
		$('tabpayment').className = 'checkoutproctabsel';
	}
	else
	{
		var empty = "no";

		if(!CheckForEmpty($('delivlastname').value, $('error-delivery'), 'delivlastname'))
		{
			empty = "yes";
		}
		if(!CheckForEmpty($('delivfirstname').value, $('error-delivery'), 'delivfirstname'))
		{
			empty = "yes";
		}
		if(!CheckForEmpty($('delivaddress').value, $('error-delivery'), 'delivaddress'))
		{
			empty = "yes";
		}
		if(!CheckForEmpty($('delivzipcode').value, $('error-delivery'), 'delivzipcode'))
		{
			empty = "yes";
		}
		if(!CheckForEmpty($('delivcity').value, $('error-delivery'), 'delivcity'))
		{
			empty = "yes";
		}
		if(!CheckForEmpty($('delivemail').value, $('error-delivery'), 'delivemail'))
		{
			empty = "yes";
		}
		if(empty == "no")
		{
			$('checkoutprocpayment').show();
			var pageTracker = _gat._getTracker("UA-12224174-1");
			pageTracker._trackPageview("/checkout/paymentinfo");
			/*$('subtabdelivery').style.display = 'block';
			$('subtabdelivery').innerHTML = $('delivfirstname').value+' '+$('delivlastname').value+'<br>'+$('delivaddress').value+'<br>'+$('delivzipcode').value+' '+$('delivcity').value;

			if ($('delivcompanyname').value != '')
			{
			$('subtabdelivery').innerHTML = $('delivcompanyname').value + '<br>'+$('subtabdelivery').innerHTML;
			}*/

			$('tabdelivery').className = 'checkoutproctab';
			$('tabpayment').className = 'checkoutproctabsel';
		}
		else
		{
			$('checkoutprocdelivery').show();
		}
	}
}

function GetProcOverview(lang)
{
	// facturatiegegevens tonen
	if($('inv_companyname').value>"")
	$('ovw_companyname').innerHTML = $('inv_companyname').value;
	else
	$('tr_companyname').style.display = "none";
	$('ovw_firstname').innerHTML = $('inv_firstname').value;
	$('ovw_lastname').innerHTML = $('inv_lastname').value;
	$('ovw_address').innerHTML = $('inv_address').value;
	/*
	if($('inv_address2').value>"")
	$('ovw_address2').innerHTML = $('inv_address2').value;
	else
	$('tr_address2').style.display = "none";
	*/
	$('ovw_city').innerHTML = $('inv_city').value;
	GetCountry($('inv_countrycode').value,$('ovw_country'),lang);
	$('ovw_zipcode').innerHTML = $('inv_zipcode').value;
	if($('inv_phone').value>"")
	$('ovw_phone').innerHTML = $('inv_phone').value;
	else
	$('tr_phone').style.display = "none";
	if($('inv_fax').value>"")
	$('ovw_fax').innerHTML = $('inv_fax').value;
	else
	$('tr_fax').style.display = "none";
	if($('inv_mobile').value>"")
	$('ovw_mobile').innerHTML = $('inv_mobile').value;
	else
	$('tr_mobile').style.display = "none";
	if($('inv_vatnr').value>"")
	$('ovw_vat').innerHTML = $('inv_vatpr').value+'-'+$('inv_vatnr').value;
	else
	$('tr_vat').style.display = "none";

	// leveringsgegevens tonen
	/*if(document.getElementById('chkdeliveryoff').checked)
	{*/
	if($('delivcompanyname').value>"")
	$('ovw_del_companyname').innerHTML = $('delivcompanyname').value;
	else
	$('tr_del_companyname').style.display = "none";

	$('ovw_del_firstname').innerHTML = $('delivfirstname').value;
	$('ovw_del_lastname').innerHTML = $('delivlastname').value;
	$('ovw_del_address').innerHTML = $('delivaddress').value;
	/*
	if($('delivaddress2').value>"")
	$('ovw_del_address2').innerHTML = $('delivaddress2').value;
	else
	$('tr_del_address2').style.display = "none";
	*/
	$('ovw_del_city').innerHTML = $('delivcity').value;
	$('ovw_del_zipcode').innerHTML = $('delivzipcode').value;
	GetCountry($('delivcountrycode').value,$('ovw_del_country'),lang);
	if($('delivphone').value>"")
	$('ovw_del_phone').innerHTML = $('delivphone').value;
	else
	$('tr_del_phone').style.display = "none";
	if($('delivmobile').value>"")
	$('ovw_del_mobile').innerHTML = $('delivmobile').value;
	else
	$('tr_del_mobile').style.display = "none";
	if($('delivemail').value>"")
	{
		//			alert('if');
		$('ovw_del_email').innerHTML = $('delivemail').value;
	}
	else
	{
		$('tr_del_email').style.display="none";
		//			alert('else');
	}
	/*}
	else
	{
	$('tbl_delivery').style.display = "none";
	}*/

	// remarks tonen
	if(document.getElementById('remarks').value>"")
	{
		$('ovw_remarks').innerHTML = document.getElementById('remarks').value.replace(/\n/g,'<br>');
	}
	else
	{
		$('tbl_remarks').style.display="none";
	}
	$('checkoutprocoverview').show();
	var pageTracker = _gat._getTracker("UA-12224174-1");
	pageTracker._trackPageview("/checkout/overview");
}

function CheckForEmpty(valuestr, element, obj)
{
	//alert(valuestr+"-"+element+"-"+obj);
	if(valuestr == "")
	{
		if(obj != "")
		{
			$(obj).className = 'inputformerror';
			$(element).style.display = 'block';
		}
		return false;
	}
	else
	{
		//alert('no');
		if(obj != "")
		{
			$(obj).className = 'inputform';
			//$(element).style.display = 'none';
		}
		return true;
	}
}

function IsNumeric(strString)
{
	   var strValidChars="0123456789,-";
	   var strChar;
	   var blnResult=true;

	   if (strString.length == 0) return false;

	   //  test strString consists of valid characters listed above
	   for (i=0; i < strString.length && blnResult == true; i++)
	   {
	      strChar=strString.charAt(i);
	      if(strValidChars.indexOf(strChar) == -1)
	      {
	      	blnResult=false;
	      }
	   }
	   return blnResult;
}

function CheckBTWnr(vatpr, vatnr)
{
	if(vatpr == 'BE')
	{
		if(IsNumeric(vatnr))
		{
			if (vatnr.length == 9)
			{
				vatnr=0+vatnr;
			}
			else if (vatnr.length == 10)
			{
				if (vatnr.charAt(0)!=0)
				{
					return false;
				}
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
		if(parseFloat(vatnr.substr(0, 8))<=0)
		{
			return false;
		}

		if (parseFloat(vatnr.substr(8, 2)) == (97 - (parseFloat(vatnr.substr(1,7))%97)))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	else
	{
		return true;
	}
}

function SetPaymentDesc(id,max)
{
	for(i=1;i<=max;i++)
	{
		if(i==id)
		{
			$('paymentdesc'+i).show();
		}
		else
		{
			//alert('paymentdesc'+i);
			$('paymentdesc'+i).hide();
		}
	}
	//buttonsIE();
}

function SetPaymentRadio(id,max)
{
	for(i=1;i<=max;i++)
	{
		if(i==id)
		{
			document.getElementById('payimg'+i).className = 'paymentimgsel';
			document.getElementById('pay'+i).checked = true;
		}
		else
		{
			document.getElementById('payimg'+i).className = 'paymentimg';
			document.getElementById('pay'+i).checked = false;
		}
	}
}

function SetPayment(id,max)
{
	for(i=1;i<=max;i++)
	{
		if(i==id)
		{
			document.getElementById('payimg'+i).className = 'paymentimgsel';
			$('paymentdesc'+i).show();
		}
		else
		{
			document.getElementById('payimg'+i).className = 'paymentimg';
			$('paymentdesc'+i).hide();
		}
	}
}

//AJAX FUNCTIONS

function getCart(lang, transcountry)
{
	$$('#cartbody .smallbutton').each(function(item){
		if(item.vml)
		{
			item.vml.style.display='none';
		}
	});

	$('transcountry').value=transcountry;

	var keeper = new sack();
	keeper.requestFile = "/ajax_getcart.php?lang="+lang+"&transcountry="+transcountry;
	keeper.onCompletion = function()
	{
		if(keeper.response!="")
		{
			$('cartbody').innerHTML=keeper.response;
		}
	};
	keeper.runAJAX();
	return true;
}

function CalculateTransport(invcountry,country,lang)
{
	var keeper = new sack();
	keeper.requestFile = "/ajax_calculatetransport.php?invcountry="+invcountry+"&country="+country+"&lang="+lang;
	keeper.onCompletion = function()
	{
		eval("var response = "+ keeper.response);
		// transport kosten aanpassen
		if(response.transportfree == 'N' && response.transport_unknown == 'N')
		{
			$('transport').innerHTML = '&euro; '+response.totalglobal;
			$('totalprice').innerHTML = '&euro; '+response.total;
		}
		else
		{
			$('transport').innerHTML = response.transportfreedesc;
			$('totalprice').innerHTML = '&euro; '+response.total;
		}

		if(response.transport_unknown == 'Y')
		{
			$$('div.payother').each(Element.hide);
			$$('div.paytransfer').each(Element.show);
			$$('input[name="paymentmethod"][value="3"]').first().click();
		}
		else
		{
			$$('div.payother').each(Element.show);
			$$('div.paytransfer').each(Element.hide);

			$$('input[name="paymentmethod"][value!="3"]').first().click();
		}
	};
	keeper.runAJAX();
	return true;
}

function GetShopcart(lang,country,clear)
{
	var keeper = new sack();
	keeper.requestFile = "/ajax_getshopcart.php?lang="+lang+"&country="+country+"&clear="+clear;
	keeper.onCompletion = function()
	{
		$('checkoutcart').innerHTML = html_entity_decode(keeper.response);
		if(CalculateTransport(country,country,lang))
		{
			if(CalculateDiscountChk(lang))
			{
				if(clear=='Y')
				{
					var keeper2 = new sack();
					keeper2.requestFile = "/ajax_clearshopcart.php";
					keeper2.onCompletion = function()
					{};
					keeper2.runAJAX();
				}
			}
		}
	};
	keeper.runAJAX();
}

function SetPaymentSub(lang)
{
	var keeper = new sack();
	keeper.requestFile = "/ajax_getpaymentmethod.php?lang="+lang;
	//alert(document.forms["frmcheckout"].paymentmethod.length);
	for (var i=1; i<=document.forms["frmcheckout"].paymentmethod.length;i++)
	{
		if($("pay"+i).checked)
		{
			var paymentno =	$("pay"+i).value;
		}
	}
	keeper.setVar("paymentno",paymentno);
	keeper.onCompletion = function()
	{
		eval("var response = "+ keeper.response);
		//alert(response.status);
		if(response.status)
		{
			//$('subtabpayment').style.display = 'block';
			//$('subtabpayment').innerHTML = response.methoddesc;
			$('ovw_paymentmethod').innerHTML = response.methoddesc;
			$('tabpayment').className = 'checkoutproctab';
			$('taboverview').className = 'checkoutproctabsel';
		}
	};
	keeper.runAJAX();
}

function GetCountry(country,field,lang)
{
	var keeper = new sack();
	keeper.requestFile = "/ajax_getcountry.php?country="+country+"&lang="+lang;
	keeper.onCompletion = function()
	{
		field.innerHTML = keeper.response;
	};
	keeper.runAJAX();
}

function CalculateDiscountChk(lang)
{
	$$('#checkoutcart .smallbutton').each(function(item){
		if(item.vml)
		{
			item.vml.style.display='none';
		}
	});
	var continuecode = "N";
	if(document.getElementById('discountcode'))
	{
		if(document.getElementById('discountcode').value!='')
		{
			continuecode = "YC"
		}
	}
	else
	{
		continuecode = "Y";
	}
	if(continuecode!="N")
	{
		var keeper = new sack();
		if(document.getElementById('chkdeliveryon').checked == true)
		{
			var country = document.getElementById('inv_countrycode').value;
		}
		else
		{
			var country = document.getElementById('delivcountrycode').value;
		}
		if(continuecode=='YC')
		{
			keeper.requestFile="/ajax_calculatediscount.php?lang="+lang+"&discountcode="+document.getElementById('discountcode').value;
		}
		else
		{
			keeper.requestFile="/ajax_calculatediscount.php?lang="+lang+"&country="+country;
		}

		keeper.onCompletion = function()
		{
			eval("var ajax_response = "+ keeper.response);
			if(ajax_response.discountamount!='0,00000' || ajax_response.discountartname!='')
			{
				if(document.getElementById('trdiscounterror'))
				{
					document.getElementById('trdiscounterror').style.display='none';
					document.getElementById('trdiscounterror').style.visibility='hidden';
				}
				if(document.getElementById('trdiscountcode'))
				{
					var discountamount=ajax_response.discountamount;
					var discountvat=ajax_response.discountvat;
					discountamount=parseFloat(discountamount.replace(",","."));
					discountvat=parseFloat(discountvat.replace(",","."));
					discounttot=parseFloat(discountamount+(discountamount*discountvat/100));
					discounttot=Math.round(discounttot*100)/100;
					discounttot=discounttot.toFixed(2);
					discounttot=discounttot+'';
					discounttot=discounttot.replace(".",",");
					//					alert(discounttot);

					while (document.getElementById('trdiscountcode').firstChild)
					{
						//The list is LIVE so it will re-index each call
						document.getElementById('trdiscountcode').removeChild(document.getElementById('trdiscountcode').firstChild);
					}

					var kolom0 = document.createElement('td');
					kolom0.align='right';
					document.getElementById('trdiscountcode').appendChild(kolom0);

					var kolom1 = document.createElement('td');
					kolom1.align = 'left';
					kolom1.innerHTML = ajax_response.discountdesc;
					document.getElementById('trdiscountcode').appendChild(kolom1);

					var kolom2 = document.createElement('td');
					kolom2.align = 'right';
					if(ajax_response.discountartname!='')
					{
						kolom2.innerHTML = '<span class=\'discount\'>'+ajax_response.discountartname+'<\/span>';
					}
					else
					{
						kolom2.innerHTML = '<span class=\'discount\'>-&nbsp;&euro;&nbsp;'+discounttot+'<\/span>';
					}
					document.getElementById('trdiscountcode').appendChild(kolom2);

				}
				if(document.getElementById('trdiscountremove'))
				{

					while (document.getElementById('trdiscountremove').firstChild)
					{
						//The list is LIVE so it will re-index each call
						document.getElementById('trdiscountremove').removeChild(document.getElementById('trdiscountremove').firstChild);
					}

					var kolom1 = document.createElement('td');
					kolom1.colSpan=3;
					kolom1.align = 'right';
					kolom1.innerHTML = 	ajax_response.discountremove;
					document.getElementById('trdiscountremove').appendChild(kolom1);

					document.getElementById('trdiscountremove').style.display='';
					document.getElementById('trdiscountremove').style.visibility='visible';
				}

				if(document.getElementById('chkdeliveryon').checked == true)
				{
					CalculateTransport(document.getElementById('inv_countrycode').value,document.getElementById('inv_countrycode').value,lang);
				}
				else
				{
					CalculateTransport(document.getElementById('inv_countrycode').value,document.getElementById('delivcountrycode').value,lang);
				}
			}
			else
			{
				if(document.getElementById('trdiscounterror'))
				{
					while (document.getElementById('trdiscounterror').firstChild)
					{
						//The list is LIVE so it will re-index each call
						document.getElementById('trdiscounterror').removeChild(document.getElementById('trdiscounterror').firstChild);
					}
					var kolom1 = document.createElement('td');
					kolom1.colSpan=3;
					kolom1.align = 'right';
					kolom1.className = 'checkout_error';
					kolom1.innerHTML = 	ajax_response.discounterror;


					document.getElementById('trdiscounterror').appendChild(kolom1);

					document.getElementById('trdiscounterror').style.display='';
					document.getElementById('trdiscounterror').style.visibility='visible';
				}

				if(document.getElementById('trdiscountremove'))
				{

					while (document.getElementById('trdiscountremove').firstChild)
					{
						//The list is LIVE so it will re-index each call
						document.getElementById('trdiscountremove').removeChild(document.getElementById('trdiscountremove').firstChild);
					}

					var kolom1 = document.createElement('td');
					kolom1.colSpan=3;
					kolom1.align = 'right';
					kolom1.innerHTML = 	ajax_response.discountremove;
					document.getElementById('trdiscountremove').appendChild(kolom1);

					document.getElementById('trdiscountremove').style.display='';
					document.getElementById('trdiscountremove').style.visibility='visible';
				}
			}
		};
		keeper.runAJAX();
	}
}

function ResetDiscount(lang)
{
	var keeper = new sack();
	//keeper.requestFile="/ajax_resetdiscount.php?transcountry="+document.getElementById('transcountry').value;
	keeper.requestFile="/ajax_resetdiscount.php";
	keeper.onCompletion = function()
	{
		if(document.getElementById('trdiscountcode'))
		{
			while (document.getElementById('trdiscountcode').firstChild)
			{
				//The list is LIVE so it will re-index each call
				document.getElementById('trdiscountcode').removeChild(document.getElementById('trdiscountcode').firstChild);
			}

			eval(keeper.response);

			if(document.getElementById('trdiscountremove'))
			{
				while (document.getElementById('trdiscountremove').firstChild)
				{
					//The list is LIVE so it will re-index each call
					document.getElementById('trdiscountremove').removeChild(document.getElementById('trdiscountremove').firstChild);
				}

				document.getElementById('trdiscountremove').style.display='none';
				document.getElementById('trdiscountremove').style.visibility='hidden';
			}

			if(document.getElementById('trdiscounterror'))
			{
				while (document.getElementById('trdiscounterror').firstChild)
				{
					document.getElementById('trdiscounterror').removeChild(document.getElementById('trdiscounterror').firstChild);
				}
				document.getElementById('trdiscounterror').style.display='none';
				document.getElementById('trdiscounterror').style.visibility='hidden';
			}

			if(document.getElementById('chkdeliveryon').checked == true)
			{
				CalculateTransport(document.getElementById('inv_countrycode').value,document.getElementById('inv_countrycode').value,lang);
			}
			else
			{
				CalculateTransport(document.getElementById('inv_countrycode').value,document.getElementById('delivcountrycode').value,lang);
			}
		}
		else
		{
			while (document.getElementById('cartdiscountcode').firstChild)
			{
				//The list is LIVE so it will re-index each call
				document.getElementById('cartdiscountcode').removeChild(document.getElementById('cartdiscountcode').firstChild);
			}

			eval(keeper.response);

			if(document.getElementById('cartdiscountremove'))
			{
				while (document.getElementById('cartdiscountremove').firstChild)
				{
					//The list is LIVE so it will re-index each call
					document.getElementById('cartdiscountremove').removeChild(document.getElementById('cartdiscountremove').firstChild);
				}

				document.getElementById('cartdiscountremove').style.display='none';
				document.getElementById('cartdiscountremove').style.visibility='hidden';
			}

			CalculateTransport(document.getElementById('countryselecttransport').value,document.getElementById('countryselecttransport').value,lang);
		}
	};
	keeper.runAJAX();
}

function mylogin()
{
	$$('#logindiv .largebutton').each(function(item){
		if(item.vml)
		{
			item.vml.style.display='none';
		}
	});

	var username='';
	var password='';
	if(document.getElementById("email2") && document.getElementById("password_checkout"))
	{
		username=document.getElementById("email2").value;
		password=document.getElementById("password_checkout").value;
	}
	else
	{
		username=document.getElementById("username_login").value;
		password=document.getElementById("password_login").value;
	}

	var keeper = new sack;
	keeper.requestFile = "/login.php?username="+username+"&password="+password;
	keeper.onCompletion = function()
	{
		document.getElementById("logindiv").innerHTML = keeper.response;
	};
	keeper.runAJAX();
}

function logout()
{
	$$('#logindiv .largebutton').each(function(item){
		if(item.vml)
		{
			item.vml.style.display='none';
		}
	});
	var keeper = new sack;
	keeper.requestFile = "/logout.php";
	keeper.onCompletion = function()
	{
		document.getElementById("logindiv").innerHTML = keeper.response;
		document.location='/';
	};
	keeper.runAJAX();
}

function writeEmbed(cls, cb, mt, p) {
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
	h += '>';

	for (n in p)
		h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
		h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}

function writeFlash(p) {
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'application/x-shockwave-flash',
		p
	);
}

function EmbedFlash(file)
{
	document.write('<OBJECT ID=\"MediaPlayer\" classid=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" valign=\"center\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\" standby=\"Loading Microsoft® Windows® Media Player components...\" type=\"application/x-oleobject\" width=\"375\" height=\"288\">' +
	'<PARAM name=\"FileName\" value=\"images/filelib/'+file+'\"><PARAM NAME=\"AutoStart\" VALUE=\"1\"><PARAM NAME=\"ShowControls\" VALUE=\"1\"><PARAM NAME=\"ShowStatusBar\" VALUE=\"0\"><PARAM NAME=\"SendErrorEvents\" VALUE=\"true\"><param NAME=\"TransparentAtStart\" VALUE=\"-1\"><PARAM name=\"InvokeURLs\" value=\"false\">' +
	'<EMBED TYPE=\"application/x-mplayer2\" NAME=\"MediaPlayer\" SRC=\"images/filelib/' + file +'\" WIDTH=\"375\" HEIGHT=\"288\" autostart=\"0\" showcontrols=\"1\"></EMBED></OBJECT>');
}

function SwapImg(img,title,desc)
{
	if(document.getElementById('img_large'))
	{
		document.getElementById('img_large').src='/images/photolib/'+img;
		document.getElementById('img_large').alt=title;
		document.getElementById('img_large').title=title;
	}
	if(document.getElementById('prod_desc'))
	{
		document.getElementById('prod_desc').innerHTML='<h3>'+title+'</h3>'+desc;
	}
}

function SaveCountry(countrycode) {
	/*
	$.post("/savecountry.php?countrycode=" + countrycode, function (response) {
		window.location.reload();
	});
	 */	
	var keeper = new sack();
	keeper.requestFile="/savecountry.php?countrycode=" + countrycode;
	keeper.onCompletion=function()
	{
		window.location.reload();
	}
	keeper.runAJAX();
	
}

