var xmlHttp
function doMath()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="domath.php"

var ind = document.getElementById('Country').selectedIndex;
url=url+"?q="+document.getElementById('Country').options[ind].value
//url=url+"&num="+eval(document.forms[0].amount.value)
url=url+"&sid="+Math.random()
//alert (url);
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

// url=url+"?q="+document.getElementById('Country').options[selectedIndex].value

function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
//alert(xmlHttp.responseText);
//alert (xmlHttp.responseText);
var shipcost = parseFloat(xmlHttp.responseText);
//var shipcost = xmlHttp.responseText;
//alert(shipcost);
var price = 49.50;
var amount = eval(document.getElementById("amount").value);
var shipcosttotal = amount*shipcost;
var shipto = eval(getSelectedRadioValue(document.forms[0].shipto));


var caltotalprice = amount*price;

if (document.forms[0].priority.checked){
shipcosttotal = shipcosttotal + 10;
}
if (shipto != 0){
shipcosttotal = 0;
shipcost = 0;
}


//if (){
var prod = (shipcost + price) * amount;
//}else{
//var prod = (shipcost + price) * amount;
//}
//alert(prod);
 document.getElementById("price").value=("€ "+(amount*price));
 document.getElementById("shipcost").value=("€ "+(shipcosttotal));
 document.getElementById("totprice").value=("€ "+custRound(prod,2));
 }
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


function  doMath2() {
var shipto = eval(getSelectedRadioValue(document.forms[0].shipto));

var price = 49.50;
var amount = eval(document.forms[0].amount.value);
var shipcost = amount*shipto;
var prod = (shipto + price) * amount;
//alert(shipto + price);
alert(shipcost);


document.forms[0].price.value=("€ "+amount*price);
document.forms[0].shipcost.value=("€ "+amount*shipto);
document.forms[0].totprice.value=("€ "+custRound(prod,2));

//shipto
//price
//shipcost
//totprice

}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function custRound(x,places) {
return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;

var ind = document.getElementById('Country').selectedIndex;
//alert(ind);
if (ind==0) errors+='- County Select your country.\n';
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}