
var xmlHttp;
var color;
var zoom;
var modelSession;
var sizeSession;
var page;
var inputSession;
var inputChoiceSession;
var inputCategorySession;
var colorSession;
var amount;

zoom = "small";

function createXMLHttpRequest()
{
	if (window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
	}
}

function checkWinning()
{
	var winContent=document.getElementById("winContent");
	
	winContent.innerHTML = '<img src="img/ajax-loader.gif" alt="" style="margin-left:auto; margin-right:auto;" />';
	
	var code = document.getElementById('winCode').value;
	var email = document.getElementById('winEmail').value;
	
	createXMLHttpRequest();
	xmlHttp.onreadystatechange=processWinning;
	xmlHttp.open("GET","check_winning.php?winCode="+escape(code)+"&winEmail="+escape(email),true);
	xmlHttp.send(null);
	
}

function processWinning(){
	if(xmlHttp.readyState==4 && xmlHttp.status==200)
	{
		var winContent=document.getElementById("winContent");
		winContent.innerHTML = xmlHttp.responseText;
	}
}

function changeImg(form, colorShirt)
{
	color = document.getElementById("color").options[document.getElementById("color").selectedIndex].text;
	if(colorShirt){
		color = colorShirt;
		form.color.value = colorShirt;
	}
	var url="model.php";
	
	if (form.inputtext.value)
	{
		var value = form.inputtext.value;
	}
	else if (form.inputselect.value != "")
	{
		var value = form.inputselect.options[form.inputselect.selectedIndex].text;
	}
	else
	{
		var value = "";
	}
	
	url=url+"?text="+escape(value)+"&color="+color+"&zoom="+zoom+"&model="+form.model.value+"&show_zoom="+form.show_zoom.value;

	document.getElementById("gdimg").src=url;
}

function changeZoom()
{
	if (zoom == "large"){zoom = "small"}
	else if(zoom == "small") {zoom = "large"}
}

function changeSelectBoxDesign(id) {
  	createXMLHttpRequest();
	xmlHttp.onreadystatechange=processDesign;
	xmlHttp.open("GET","xml_output.php?action=design&id="+escape(id),true);
	xmlHttp.send(null);
}

function processDesign()
{
	if(xmlHttp.readyState==4 && xmlHttp.status==200)
	{
		var xmlDoc=xmlHttp.responseXML;
		var designList=xmlDoc.getElementsByTagName("design");
		var selectObject=document.getElementById("inputselect");
		
		selectObject.options.length=0;
		
		selectObject.disabled=false;
		selectObject.options[0]=new Option("", "");
		
		var designIndexSession = "";
		for (var i=0; i<designList.length; i++)
		{
			selectObject.options[i+1]=new Option(designList[i].childNodes[1].firstChild.nodeValue, designList[i].childNodes[1].firstChild.nodeValue);
			if(designList[i].childNodes[1].firstChild.nodeValue==inputSession){
				designIndexSession=i+1;
			}		
		}	
		if(designIndexSession!=""){
			selectObject.selectedIndex=designIndexSession;
		}
	}
}

function changeSelectBoxSize(id) {
	dressgoat.model.value = id;
  	createXMLHttpRequest();
	xmlHttp.onreadystatechange=processSize;
	xmlHttp.open("GET","xml_output.php?action=size&id="+escape(id),true);
	xmlHttp.send(null);
}

function processSize()
{
	if(xmlHttp.readyState==4 && xmlHttp.status==200)
	{
		var xmlDoc=xmlHttp.responseXML;
		var list=xmlDoc.getElementsByTagName("size");
		var selectObject=document.getElementById("size");
		
		selectObject.options.length=0;
		
		selectObject.disabled=false;
		selectObject.options[0]=new Option("", "");
		
		var sizeIndexSession = "";
		for (var i=0; i<list.length; i++)
		{
			selectObject.options[i+1]=new Option(list[i].childNodes[1].firstChild.nodeValue, list[i].childNodes[0].firstChild.nodeValue);
			if(list[i].childNodes[0].firstChild.nodeValue==sizeSession){
				sizeIndexSession=i+1;
			}
		}	
		if(sizeIndexSession!=""){
			selectObject.selectedIndex=sizeIndexSession;
		}
		
		if(modelSession!="false" && sizeSession!="false" && modelSession!="" && sizeSession!="")
		{
			changeDimensionsShirt(modelSession, sizeSession);
		}
		else
		{
			changeProductInformation();
		}
	}
}

function changeDimensionsShirt(product_id, size_id) {
	if(size_id!=''){
		createXMLHttpRequest();
		xmlHttp.onreadystatechange=processDimensions;
		var url = "xml_output.php?action=dimension&id="+escape(product_id)+"&size_id="+escape(size_id);
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}else{
		document.getElementById('span_shirt_width').innerHTML= "-- cm";
		document.getElementById('span_shirt_height').innerHTML= "-- cm";
		
		changeProductInformation();
	}
}

function processDimensions()
{
	if(xmlHttp.readyState==4 || xmlHttp.status==200)
	{
		var xmlDoc=xmlHttp.responseXML;
		var list=xmlDoc.getElementsByTagName("dimension");
				
		document.getElementById('span_shirt_width').innerHTML= list[0].childNodes[0].firstChild.nodeValue+" cm";
		document.getElementById('span_shirt_height').innerHTML= list[0].childNodes[1].firstChild.nodeValue+" cm";
		
		changeProductInformation();
	}
}

function emptyDimensions()
{
	document.getElementById('span_shirt_width').innerHTML="-- cm";
	document.getElementById('span_shirt_height').innerHTML="-- cm";
	sizeSession = "";
}

function changeProductInformation()
{
	createXMLHttpRequest();
	xmlHttp.onreadystatechange=fillProductInformation;
	
	xmlHttp.open("GET","price.php?action=product&id="+escape(document.getElementById("model").value)+"&amount="+escape(parseInt(document.getElementById("amount").value))+"&extra_cost_id="+document.getElementById("method").value, true);
	xmlHttp.send(null);
}

function fillProductInformation()
{			
	if(xmlHttp.readyState==4 && xmlHttp.status==200)
	{
		var value;

		if (dressgoat.inputtext.value)
		{
			value = htmlspecialchars(dressgoat.inputtext.value);
		}
		else if (dressgoat.inputselect.value)
		{
			value = htmlspecialchars(dressgoat.inputselect.options[dressgoat.inputselect.selectedIndex].text);
		}
		else value = "?????";
	
		//value = value.charAt(0).toUpperCase() + value.substr( 1, value.length);
		
		document.getElementById('span_label_text').innerHTML = value;
		document.getElementById('span_label_color').innerHTML = document.getElementById("color").options[document.getElementById("color").selectedIndex].text;
		
		if (document.getElementById("size").options[document.getElementById("size").selectedIndex].text != "" && document.getElementById("method").options[document.getElementById("method").selectedIndex].text != "")
		{
			document.getElementById('span_label_shirt_size').innerHTML= document.getElementById("method").options[document.getElementById("method").selectedIndex].text+" - "+document.getElementById("size").options[document.getElementById("size").selectedIndex].text;
		}
		else if(document.getElementById("method").options[document.getElementById("method").selectedIndex].text != "" && document.getElementById("size").options[document.getElementById("size").selectedIndex].text == "")
		{
			document.getElementById('span_label_shirt_size').innerHTML= document.getElementById("method").options[document.getElementById("method").selectedIndex].text;
		}
		else if(document.getElementById("method").options[document.getElementById("method").selectedIndex].text == "" && document.getElementById("size").options[document.getElementById("size").selectedIndex].text != "")
		{
			document.getElementById('span_label_shirt_size').innerHTML= document.getElementById("size").options[document.getElementById("size").selectedIndex].text;
		}
		
		if(parseInt(document.getElementById("amount").value))
		{
			document.getElementById('span_label_amount').innerHTML= parseInt(document.getElementById("amount").value);
		}
		else
		{
			document.getElementById('span_label_amount').innerHTML = "";
		}
		
		if (value != "" && color != "" && document.getElementById("method").options[document.getElementById("method").selectedIndex].text != "" && document.getElementById("size").options[document.getElementById("size").selectedIndex].text != "" && document.getElementById("amount").value != "" && parseInt(document.getElementById("amount").value) > 0)
		{
			price = xmlHttp.responseText;
			if(price == Math.round(price))
			{
				document.getElementById('span_label_cost').innerHTML= "&euro; "+price+",- (inclusief verzendkosten)";
			}
			else
			{
				price = price * 100;
				price=price.toString();
				price = price.substring(0, price.length-2)+','+price.substring(price.length-2, price.length);
				document.getElementById('span_label_cost').innerHTML= "&euro; "+price+" (inclusief verzendkosten)";
			}
			
			document.getElementById('btnAddToCart').disabled = false;
			document.getElementById('btnCheckOut').disabled = false;
		}
		else
		{
			document.getElementById('span_label_cost').innerHTML= "";
			
			document.getElementById('btnAddToCart').disabled = true;
			document.getElementById('btnCheckOut').disabled = true;
		}
	}
}


function sendMail(form) 
{
	recipients = form.recipients.value;
	sendername = form.sendername.value;
	senderemail = form.senderemail.value;
	subject = form.subject.value;
	message = form.message.value;
	//url = form.url.value;
	//alert(url);
	var queryString = "recipients="+recipients+"&sendername="+sendername+"&senderemail="+senderemail+"&subject="+subject+"&message="+message;
	
  	createXMLHttpRequest();
	xmlHttp.open("POST","sendmail.php?action=tellafriend",true);
	xmlHttp.onreadystatechange=processMail;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(queryString);
}

function processMail()
{
	document.getElementById('emailconfirm').style.visibility = 'visible';
	document.getElementById('emailconfirm').innerHTML = "<img src=\"img/progress.gif\" alt=\"progress\">";
	if(xmlHttp.readyState==4 && xmlHttp.status==200)
	{		
		mailstatus = xmlHttp.responseText;
		if (mailstatus == "mailsend")
		{
			//document.getElementById('emailconfirm').class = 'green';
			window.location.href = 'tellafriend.php?mail=send';
		}
		else if (mailstatus == "emailnotvalid")
		{
			document.getElementById('emailconfirm').style.color = '#FF0000';
			document.getElementById('emailconfirm').innerHTML = "Controleer geadresseerde(n)";
		}
		else if (mailstatus == "sendernotvalid")
		{
			document.getElementById('emailconfirm').style.color = '#FF0000';
			document.getElementById('emailconfirm').innerHTML = "Controleer uw naam en e-mail";
		}
		else if (mailstatus == "emptyfields")
		{
			document.getElementById('emailconfirm').style.color = '#FF0000';
			document.getElementById('emailconfirm').innerHTML = "Vul alle velden in";
		}
		else
		{
			document.getElementById('emailconfirm').style.color = '#FF0000';
			document.getElementById('emailconfirm').innerHTML = "Bericht niet verzonden";
		}
		
	}
}

function showdiv(divId) 
{ 
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6 
		document.getElementById(divId).style.visibility = 'visible'; 
	} 
}

function hideDiv(divId) 
{ 
	if (document.getElementById) 
	{ // DOM3 = IE5, NS6 
		document.getElementById(divId).style.visibility = 'hidden'; 
	} 
}

var firstClick = true;
function emptyOnFirstClick(input)
{
	if (firstClick == true)
	{
		document.getElementById(input).value = '';
		firstClick = false;
	}
}

function checkVariables(){
	if(page=="index"){
		changeImg(dressgoat);

		if(inputSession != "false" && inputSession != "")
		{
			document.getElementById('divColor').style.visibility = 'visible';
			
			if(colorSession != "false" && colorSession != "")
			{
				document.getElementById('divSize').style.visibility = 'visible';
				
				if(sizeSession != "false" && sizeSession != "")
				{
					document.getElementById('divAmount').style.visibility = 'visible';
					changeDimensionsShirt(document.getElementById('model').value, document.getElementById('size').value);	
				}
				else
				{
					changeProductInformation();
				}
			}
			else
			{
					changeProductInformation();
			}
		}
		else
		{
			changeProductInformation();
		}
	}	
}

function changeShoppingCartAmount(rowId, operator, node)
{

	var spanName;
	
	spanName = "amountRow"+rowId;
	
	amount = document.getElementById(spanName).innerHTML;
	
	if (operator == 'minus')
	{
		if (amount > 1)
		{
			amount--;
		}else{
			confirm_delete(rowId, node);
		}
	}
	
	if (operator == 'plus')
	{
		amount++;
	}
	
	document.getElementById(spanName).innerHTML = amount;
	updateShoppingCartProduct(rowId, amount);
	changeShoppingCartPriceRow(rowId);
}

function changeShoppingCartPriceRow(rowId)
{
	var productTotal;
	var spanName;
	var productPrice;
	var extraCost;
	var discount;
	
	deleted = "deleted"+rowId;
	if (document.getElementById(deleted).value == 'false')
	{
	spanAmount = "amountRow"+rowId;
	amount = document.getElementById(spanAmount).innerHTML;

	spanName = "priceRow"+rowId;
	productPrice = parseFloat(document.getElementById('productPrice'+rowId).value);
	extraCost = parseFloat(document.getElementById('extraCost'+rowId).value);
	
	//pricePerProduct = productPrice + extraCost;
	productTotal = productPrice * amount;
	productTotal = productTotal * 100;
	productTotal = productTotal.toString();
	productTotal = productTotal.substring(0, productTotal.length-2)+','+productTotal.substring(productTotal.length-2, productTotal.length);
	document.getElementById(spanName).innerHTML = productTotal;
	}

	//productTotal = totalAmount + giftCost;
	
	calculateShoppingCartDiscount(1);
	
}

function updateShoppingCartProduct(rowId, quantity) {
  	createXMLHttpRequest();
	//xmlHttp.onreadystatechange=processShoppingCart;
	idInput = "cartProductId"+rowId;
	shoppingCartId = document.getElementById(idInput).value;
	xmlHttp.open("GET","updateshoppingcart.php?action=update&id="+shoppingCartId+"&quantity="+quantity,true);
	xmlHttp.send(null);
}

function deleteShoppingCartProduct(rowId) {
  	createXMLHttpRequest();
	//xmlHttp.onreadystatechange=processShoppingCart;
	idInput = "cartProductId"+rowId;
	shoppingCartId = document.getElementById(idInput).value;
	
	xmlHttp.open("GET","updateshoppingcart.php?action=delete&id="+shoppingCartId,true);
	xmlHttp.onreadystatechange=function(){
		if (document.getElementById('deletedRows').value >= document.getElementById('amountProducts').value - 1)
		{
			window.location.href = 'shoppingcart.php';
		}		
	};
	xmlHttp.send(null);
}

function changeShoppingCartTotalPrice()
{
	var i;
	var total = 0;
	var idRow;

	
	for (i = 0; i < document.getElementById('amountProducts').value; i++)
	{
		deleted = "deleted"+i;
		if (document.getElementById(deleted).value == 'false')
		{
			idRow = 'priceRow'+i;
			total = parseFloat(total) + parseFloat(document.getElementById(idRow).innerHTML);
		}
	}
	return total;
}



function calculateShoppingCartDiscount(id) {
  	createXMLHttpRequest();
	xmlHttp.onreadystatechange=processShoppingCartDiscount;
	xmlHttp.open("GET","xml_output.php?action=discount&id="+escape(id),true);
	xmlHttp.send(null);
}

function processShoppingCartDiscount()
{
	var discount_percentage = 0;
	var discount_total = 0;
	var totalAmount = 0;
	
	if(xmlHttp.readyState==4 && xmlHttp.status==200)
	{
		var xmlDoc=xmlHttp.responseXML;
		var discountList=xmlDoc.getElementsByTagName("discount");

		for (var j = 0; j < document.getElementById('amountProducts').value; j++)
		{		
		
		deleted = "deleted"+j;
		if (document.getElementById(deleted).value == 'false')
			{
				for (var i=0; i<discountList.length; i++)
				{
					amountInput = "amountRow"+j;
					productPriceInput = "productPrice"+j;
					amount = document.getElementById(amountInput).innerHTML;				
					productPrice = document.getElementById(productPriceInput).value;
					
					totalAmount = amount * productPrice;
					if(parseInt(document.getElementById(amountInput).innerHTML) >= parseInt(discountList[i].childNodes[0].firstChild.nodeValue))
					{	
						discount_percentage = discountList[i].childNodes[1].firstChild.nodeValue;
					}
				}
				discount = totalAmount * discount_percentage / 100;
				discount_total = discount + discount_total;
			}
			else
			{
				//discount_total = 0;
			}
		}
		if(discount_total != 0)
		{
			discount_total = Math.round(discount_total * 100);
			discount_total = discount_total.toString();
			discount_total = discount_total.substring(0, discount_total.length-2)+','+discount_total.substring(discount_total.length-2, discount_total.length);
		}
		else
		{
			discount_total = "0,00";
		}
		document.getElementById('discountPrice').innerHTML = discount_total;
		
		total_price = (changeShoppingCartTotalPrice() - parseFloat(discount_total.replace(',', '.'))) * 100;
		if(isNaN(total_price))
		{
			total_price = "0,00";
		}
		else
		{
		total_price = total_price.toString();
		total_price = total_price.substring(0, total_price.length-2)+','+total_price.substring(total_price.length-2, total_price.length);
		}
		document.getElementById('totalPrice').innerHTML = total_price;
	}
}

function changeDeliveryStatus()
{
	if(document.getElementById('delivery').checked == true)
	{
		document.getElementById('divDelivery').style.visibility = 'visible';
		document.getElementById('btnConfirm').style.visibility = 'hidden';
	}
	else
	{
		document.getElementById('divDelivery').style.visibility = 'hidden';
		document.getElementById('btnConfirm').style.visibility = 'visible';
	}
	getShippingCosts();
}

function delRow(rowId, node)
{
	document.getElementById('deletedRows').value = parseInt(document.getElementById('deletedRows').value) + 1;
	//alert(document.getElementById('deletedRows').value+" "+document.getElementById('amountProducts').value);
	deleted = "deleted"+rowId;
	document.getElementById(deleted).value = 'true';
	
	var tr = node.parentNode;
	while (tr.tagName.toLowerCase() != "tr")
	tr = tr.parentNode;
	
	// Remove the tr node and all children.
	tr.parentNode.removeChild(tr);
	if (document.getElementById('deletedRows').value >= document.getElementById('amountProducts').value)
	{
		document.getElementById('btnCheckOut').disabled = true;
	}
}

function confirm_delete(id, node)
{
	input_box=confirm("Weet je zeker dat je dit artikel uit de winkelwagen wilt verwijderen?");
	
	if (input_box==true)
	{ 
		deleteShoppingCartProduct(id);
		delRow(id, node);
		changeShoppingCartPriceRow(id);
	}
}

function changeInputChoice(choice)
{
	if(choice == "select")
	{	
		document.getElementById('text0').style.display = 'none';
		document.getElementById('text1').style.display = 'none';
		document.getElementById('text2').style.display = 'none';
		document.getElementById('select0').style.display = '';
		document.getElementById('select1').style.display = '';
		document.getElementById('select2').style.display = '';
		document.getElementById('select3').style.display = '';
	}
	else
	{
		document.getElementById('select0').style.display = 'none';
		document.getElementById('select1').style.display = 'none';
		document.getElementById('select2').style.display = 'none';
		document.getElementById('select3').style.display = 'none';
		document.getElementById('text0').style.display = '';
		document.getElementById('text1').style.display = '';
		document.getElementById('text2').style.display = '';
	}
}

function emailCheck (emailStr) {
	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
	     even fit the general mould of a valid e-mail address. */
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
	    // user is not valid
	    return false
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	    // this is an IP address
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
			return false
		    }
	    }
	    return true
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
	    return false
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */
	
	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   return false
	}
	
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   return false
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}

function checkFieldsCheckOut(form)
{
	var emptyFields = 0;
	
	if(form.customer_firstname.value){document.getElementById('check_customer_firstname').style.visibility = 'hidden'}else{document.getElementById('check_customer_firstname').style.visibility = 'visible'; emptyFields++;}
	if(form.customer_lastname.value){document.getElementById('check_customer_lastname').style.visibility = 'hidden'}else{document.getElementById('check_customer_lastname').style.visibility = 'visible'; emptyFields++;}
	if(form.customer_street.value){document.getElementById('check_customer_street').style.visibility = 'hidden'}else{document.getElementById('check_customer_street').style.visibility = 'visible'; emptyFields++;}
	if(form.customer_number.value){document.getElementById('check_customer_number').style.visibility = 'hidden'}else{document.getElementById('check_customer_number').style.visibility = 'visible'; emptyFields++;}
	if(form.customer_postal_code.value){document.getElementById('check_customer_postal_code').style.visibility = 'hidden'}else{document.getElementById('check_customer_postal_code').style.visibility = 'visible'; emptyFields++;}
	if(form.customer_place.value){document.getElementById('check_customer_place').style.visibility = 'hidden'}else{document.getElementById('check_customer_place').style.visibility = 'visible'; emptyFields++;}
	if(form.customer_country.value){document.getElementById('check_customer_country').style.visibility = 'hidden'}else{document.getElementById('check_customer_country').style.visibility = 'visible'; emptyFields++;}
	if(form.customer_telephone.value){document.getElementById('check_customer_telephone').style.visibility = 'hidden'}else{document.getElementById('check_customer_telephone').style.visibility = 'visible'; emptyFields++;}
	if(emailCheck(form.customer_email.value)){document.getElementById('check_customer_email').style.visibility = 'hidden'}else{document.getElementById('check_customer_email').style.visibility = 'visible'; emptyFields++;}
	//if(form.payment_method[2].checked && form.actionCode.value==''){document.getElementById('check_payment_method').style.visibility = 'visible'; emptyFields++;}else{document.getElementById('check_payment_method').style.visibility = 'hidden';}
	if(document.getElementById('delivery').checked == true)
	{
		if(form.delivery_name.value){document.getElementById('check_delivery_name').style.visibility = 'hidden'}else{document.getElementById('check_delivery_name').style.visibility = 'visible'; emptyFields++;}
		if(form.delivery_street.value){document.getElementById('check_delivery_street').style.visibility = 'hidden'}else{document.getElementById('check_delivery_street').style.visibility = 'visible'; emptyFields++;}
		if(form.delivery_number.value){document.getElementById('check_delivery_number').style.visibility = 'hidden'}else{document.getElementById('check_delivery_number').style.visibility = 'visible'; emptyFields++;}
		if(form.delivery_postal_code.value){document.getElementById('check_delivery_postal_code').style.visibility = 'hidden'}else{document.getElementById('check_delivery_postal_code').style.visibility = 'visible'; emptyFields++;}
		if(form.delivery_place.value){document.getElementById('check_delivery_place').style.visibility = 'hidden'}else{document.getElementById('check_delivery_place').style.visibility = 'visible'; emptyFields++;}
		if(form.delivery_country.value){document.getElementById('check_delivery_country').style.visibility = 'hidden'}else{document.getElementById('check_delivery_country').style.visibility = 'visible'; emptyFields++;}
	}
	
	if(emptyFields == 0)
	{
		form.submit();
	}
}

function getShippingCosts()
{
    if(document.getElementById('delivery').checked == true) {
        var countryId = document.getElementById('delivery_country').value;
    } else {
        var countryId = document.getElementById('customer_country').value;
    }
    
    createXMLHttpRequest();
	xmlHttp.onreadystatechange=processShippingCosts;
	xmlHttp.open("GET","calculateShippingCosts.php?country_id="+escape(countryId),true);
	xmlHttp.send(null);
}

function processShippingCosts()
{
    if(xmlHttp.readyState==4 && xmlHttp.status==200)
	{
        document.getElementById('price').innerHTML=(parseFloat(document.getElementById('totalprice').value)+parseFloat(xmlHttp.responseText)).toFixed(2).replace('.',',');
	}
}

function htmlspecialchars(string) 
{ 
	string = string.replace(/&/g, '&amp;');
    string = string.replace(/</g, '&lt;'); 
    string = string.replace(/>/g, '&gt;'); 
    string = string.replace(/"/g, '&quot;'); 
    string = string.replace(/'/g, '&apos;'); 
    return string; 
}