// JavaScript Document
var xmlHttp;

function berekenGame(){
	var game=document.getElementById("game").value;
	var slots=document.getElementById("slots").value;
	var type=document.getElementById("type").value;
	var contract=document.getElementById("contract").value;
			if(game=="0"|slots=="0"|type=="0"){return;}
	xmlHttp=MaakXmlHttpObject();
	if (xmlHttp==null) return;
	var url="/gamehosting/getPrice.php" + "?game=" + game + "&slots=" + slots + "&type=" + type + "&contract=" + contract;
	xmlHttp.onreadystatechange=StatusGewijzigd;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp.send(null);
} 

function berekenVoice(){
	var voice=document.getElementById("voice").value;
	var slots=document.getElementById("slots").value;
	var type=document.getElementById("type").value;
	var contract=document.getElementById("contract").value;
			if(voice=="0"|slots=="0"|type=="0"){return;}
	xmlHttp=MaakXmlHttpObject();
	if (xmlHttp==null) return;
	var url="/voicehosting/getPrice.php" + "?voice=" + voice + "&slots=" + slots + "&type=" + type + "&contract=" + contract;
	xmlHttp.onreadystatechange=StatusGewijzigd;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp.send(null);
} 

function berekenRedirect(){
	var game=document.getElementById("game").value;
	var contract=document.getElementById("contract").value;
	xmlHttp=MaakXmlHttpObject();
	if (xmlHttp==null) return;
	var url="/gamehosting/redirect/getPrice.php" + "?game=" + game + "&contract=" + contract;
	xmlHttp.onreadystatechange=StatusGewijzigd;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp.send(null);
} 

function berekenMinecraft(){
	var game=document.getElementById("game").value;
	var contract=document.getElementById("contract").value;
	xmlHttp=MaakXmlHttpObject();
	if (xmlHttp==null) return;
	var url="/gamehosting/minecraft/getPrice.php" + "?game=" + game + "&contract=" + contract;
	xmlHttp.onreadystatechange=StatusGewijzigd;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp.send(null);
} 

function StatusGewijzigd() { 
	if (xmlHttp.readyState==4 && xmlHttp.status==200) VerwerkAjax();
}

function MaakXmlHttpObject() {
	xmlHttp = null;
    if (window.ActiveXObject)       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    else if (window.XMLHttpRequest) xmlHttp = new XMLHttpRequest();
  	else alert ("Your browser does not support AJAX!");
	return xmlHttp;
}

function VerwerkAjax(){
document.getElementById("getPrice").innerHTML=xmlHttp.responseText;
}

function emptyCart(){
	var awnser = confirm("Are you sure you want to clear your shopping cart?");
	if(awnser){
		window.clearCart.location = "/shopping_cart/clearCart.php";
	}
	else{}
}

function deleteCartItem(id){
	var awnser = confirm("Are you sure you want to delete this item from your cart?");
	if(awnser){
		window.clearCart.location = "/shopping_cart/deleteCartItem.php?id="+id;
	}
	else{}
}

function addWebhosting(id){
	window.iSubmit.location = "/webhosting/addToCart.php?id="+id;
}

function getPayment()
{
for (var i=0; i < document.orderForm.payment_methode.length; i++)
   {
   if (document.orderForm.payment_methode[i].checked)
      {
      return document.orderForm.payment_methode[i].value;
      }
   }
}


function getNewTotal(){
	var payment=getPayment();
	var fee = document.getElementById("fee").value;
	var subtotaal=document.getElementById("subtotaal").value;
	xmlHttp=MaakXmlHttpObject();
	if (xmlHttp==null) return;
		if(payment == "paypal"){
			var url="/shopping_cart/order/getPrice.php" + "?fee=" + fee + "&subtotaal=" + subtotaal;
		}
		else{
			var url="/shopping_cart/order/getPrice.php" + "?fee=0.00&subtotaal=" + subtotaal;
		}
	xmlHttp.onreadystatechange=StatusGewijzigd;
	xmlHttp.open("GET",url,true);
	xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
	xmlHttp.send(null);
} 

function bereken(){
	var cpu=document.getElementById("cpu").value;
	var mem=document.getElementById("geheugen").value;
	var hd1=document.getElementById("hd1").value;
	var hd2=document.getElementById("hd2").value;
	var period=document.getElementById("period").value;
	
	if(cpu=="Celeron D430"){cpu=30;}
	else if(cpu=="PentiumD E5400"){cpu=50;}
	else if(cpu=="C2D E7500"){cpu=85;}
	else if(cpu=="C2D E8500"){cpu=141;}
	else if(cpu=="C2Q Q8300"){cpu=105;}
	else if(cpu=="C2Q Q9400"){cpu=142;}
	else if(cpu=="Xeon X3220"){cpu=145;}
	else if(cpu=="Xeon X3330"){cpu=150;}
	
	if(mem=="1GB DDR2"){mem=30;}
	else if(mem=="2GB DDR2"){mem=50;}
	else if(mem=="4GB DDR2"){mem=75;}
	else if(mem=="8GB DDR2"){mem=145;}
	
	if(hd1=="160GB SATAII"){hd1=31;}
	else if(hd1=="320GB SATAII"){hd1=35;}
	else if(hd1=="640GB SATAII"){hd1=43;}
	else if(hd1=="1000GB SATAII"){hd1=60;}
	else if(hd1=="1500GB SATAII"){hd1=78;}
	else if(hd1=="2000GB SATAII"){hd1=135;}
	else if(hd1=="40GB SSD"){hd1=85;}
	else if(hd1=="80GB SSD"){hd1=165;}
	else if(hd1=="160GB SSD"){hd1=305;}
	
	if(hd2=="160GB SATAII"){hd2=31;}
	else if(hd2=="320GB SATAII"){hd2=35;}
	else if(hd2=="640GB SATAII"){hd2=43;}
	else if(hd2=="1000GB SATAII"){hd2=60;}
	else if(hd2=="1500GB SATAII"){hd2=78;}
	else if(hd2=="2000GB SATAII"){hd2=135;}
	else if(hd2=="40GB SSD"){hd2=85;}
	else if(hd2=="80GB SSD"){hd2=165;}
	else if(hd2=="160GB SSD"){hd2=305;}
	
	if(cpu==""|mem==""|hd1==""){}
	else{
	totaalmaand=375+cpu+mem+hd1+hd2;
	totaalmaand/=11;
	totaalmaand+=30;
	totaalmaand=totaalmaand*1.19;
	totaalmaand=Math.round(totaalmaand*100)/100;
	document.getElementById("price").value= totaalmaand;
	totaal=(totaalmaand*period)*100;
	totaal=Math.round(totaal)/100;
	document.getElementById("totalprice").value= totaal;
	}
}
