var cartSuccess = function(o) {
  var json = o.responseText.substring(o.responseText.indexOf('{'), o.responseText.lastIndexOf('}') + 1); 
  try {
  	var resp = eval('(' + json + ')');
  	 if(resp['html']) {
  	 	if (resp['popup']) {
  	 		info_html(resp['subject'], resp['html']);
  	 	}
  	 	fetchcart();
  	 	/*
  	 	here we return the cart data and print it...
  	 	*/
  	 }
  } catch (e) {
  	// errors, just accept them and continue our work
  }
}

var cartFailure = function(o) {

}

var cart_callback = { 
	success:cartSuccess,
	failure:cartFailure
}

var cartFetchSuccess = function(o) {
  var json = o.responseText.substring(o.responseText.indexOf('{'), o.responseText.lastIndexOf('}') + 1); 
  try {
  	var resp = eval('(' + json + ')');
  	 if(resp['html']) {
  	 	document.getElementById('small_cart').innerHTML = resp['html'];
  	 	document.getElementById('small_cart_box').style.display = "block";
  	 	/*
  	 	here we return the cart data and print it...
  	 	*/
  	 } else {
  	 	document.getElementById('small_cart').innerHTML = "";
  	 	document.getElementById('small_cart_box').style.display = "none";
  	 }
  } catch (e) {
  	// errors, just accept them and continue our work
  }
}

var cart_fetch_callback = { 
	success:cartFetchSuccess,
	failure:cartFailure
}


function addtocart(domain, status) {
  
  // we need a timestamp to fool cached pages
  var currentTime = new Date();
  
  YAHOO.util.Connect.asyncRequest('GET','/xml/cart.php?domain='+domain+'&status='+status+'&act=add&time='+urlencode(currentTime), cart_callback, null);
  
}

function deletefromcart(domain) {
  
  // we need a timestamp to fool cached pages
  var currentTime = new Date();
  
  YAHOO.util.Connect.asyncRequest('GET','/xml/cart.php?domain='+domain+'&act=delete&time='+urlencode(currentTime), cart_fetch_callback, null);
  
}

function fetchcart() {
	  // we need a timestamp to fool cached pages
  var currentTime = new Date();
  
  YAHOO.util.Connect.asyncRequest('GET','/xml/cart.php?time='+urlencode(currentTime), cart_fetch_callback, null);
	
}

function popupchange() {
	  // we need a timestamp to fool cached pages
  var currentTime = new Date();
  var popupvalue = document.getElementById("stop_popup").checked;
  
  YAHOO.util.Connect.asyncRequest('GET','/xml/cart.php?act=popup&value='+popupvalue+'&time='+urlencode(currentTime), null, null);
	
}

function select_product(domain, price, adsl, diskspace, database, email) {
	var product_id = document.getElementById('product_'+domain).value;
	var total_price = price+(domain_products[product_id]*12)
	//document.getElementById('price_'+domain).innerHTML = '&euro; '+total_price.toFixed(2).replace(/\./, ",");
	document.getElementById('specs_'+domain).innerHTML = domain_products_specs[product_id].replace(/domainkey/g, domain).replace(/domainprice/g, price);
	if (adsl!=null) {
		document.getElementById('adsl_'+domain).value=adsl;
	}
	if (diskspace!=null) {
		document.getElementById('diskspace_'+domain).value=diskspace;
	}
	if (database!=null) {
		document.getElementById('database_'+domain).value=database;
	}
	if (email!=null) {
		document.getElementById('email_'+domain).value=email;
	}
	recalc_product(domain, price);
}

function recalc_product(domain, price) {
	var product_id = document.getElementById('product_'+domain).value;
	var total_price = (domain_products[product_id]*12)

	//adsl
	try{
	var option_id = document.getElementById('adsl_'+domain).value;
	total_price = total_price+(domain_products_options[option_id]*12);
	}catch(e){
	}
	
	//diskspace
	try{
	var option_id = document.getElementById('diskspace_'+domain).value;
	total_price = total_price+(domain_products_options[option_id]*12);
	}catch(e){
	}
	
	//database
	try{
	var option_id = document.getElementById('database_'+domain).value;
	total_price = total_price+(domain_products_options[option_id]*12);
	}catch(e){
	}
	
	//email
	try{
	var option_id = document.getElementById('email_'+domain).value;
	total_price = total_price+(domain_products_options[option_id]*12);
	}catch(e){
	}
	total_price=total_price+price;
	if (total_price>200) {
		total_price=total_price/12;
		document.getElementById('invoice_'+domain).innerHTML = per_month;	
	} else {
		document.getElementById('invoice_'+domain).innerHTML = per_year;
	}
	
	document.getElementById('price_'+domain).innerHTML = '&euro; '+total_price.toFixed(2).replace(/\./, ",");
	
}

function confirm_order() {
	var answer = confirm(complete_text)
	if (answer)
		return true;
	else
		return false;
}