function checkSerials()
{
 var form = document.forms[0];
 var formElements = form.elements;
 var serialsArea = formElements['oldserials'].value;
 formElements['os0'].value = serialsArea;
 var serialsInput = formElements['os0'].value;
 if (serialsInput=="") {alert("Please provide us with your old serials in order to update them"); return false;}
 return true;
} 

function changeservice(service)
{
 var span = document.getElementById('checkoutbtn');
 var serialsDivObj = document.getElementById('serialsDiv');
 var serialsInputObj = document.getElementById('oldserials');
 var plimusNoteSpan = document.getElementById('plimusnote');
 var form = document.forms[0];
 var elements = form.elements;
 var par = document.forms[0];
 var parelmts = par.elements;
 var prodid = parelmts["ProdID"].value;
 var quantity = parelmts["inputquantity"].value;
 var url = elements["plimusurl"].value;

 if (service=="paypal") {
  if (prodid=="OBU" || prodid=="OBUOH" || prodid=="OBUOP" || prodid=="OBUVOH" || prodid=="OBUVOP") { 
   serialsInputObj.style.backgroundColor="#FFFFFF"; serialsInputObj.disabled=false; plimusNoteSpan.style.display="none"; 
  } 
  span.innerHTML = "<input type=\"image\" src=\"/images/checkout.png\" border=\"0\" name=\"submit\" value=\"Buy Now!\">"; 
 }

 if (service=="plimus") {
  if (prodid=="OBU" || prodid=="OBUOH" || prodid=="OBUOP" || prodid=="OBUVOH" || prodid=="OBUVOP") { 
   serialsInputObj.style.backgroundColor="#DDDDDD"; serialsInputObj.disabled = true; plimusNoteSpan.style.display=""; 
  } 
  span.innerHTML = "<a id=\"plimusurl\" href=\""+url+"\"><img src=\"/images/checkout.png\" border=\"0\"></a>"; 
 }
}

function numbersonly(myfield, e, dec)
{
 var key;
 var keychar;

 if (window.event)
  key = window.event.keyCode;
 else if (e)
  key = e.which;
 else
  return true;
 keychar = String.fromCharCode(key);
 if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
  return true;
 else 
  if ((("0123456789").indexOf(keychar) > -1))
   return true;
  else if (dec && (keychar == "."))
   {
    myfield.form.elements[dec].focus();
    return false;
   }
  else
   return false;
}


function changePage(newprice)
{
  var par = document.forms[0];
  var parelmts = par.elements;
  var prodid = parelmts["ProdID"].value;
  var quantity = parelmts["inputquantity"].value;

  var quantityInputObj = document.getElementById('qinput');
  var ammountWithoutDiscountInputObj = document.getElementById('withoutdiscount');
  var discountInputObj = document.getElementById('discount');
  var ammountWithDiscountInputObj = document.getElementById('withdiscount');
  var form = document.forms[0];
  var quantityInput = form.elements["quantity"];
  var amountInput = form.elements["amount"];
  var returnUrlInput = form.elements["return"];
  var plimusUrlInputObj = form.elements['plimusurl'];

  quantityInputObj.innerHTML = quantity;
  ammountWithoutDiscountInputObj.innerHTML = "$"+newprice[0];
  discountInputObj.innerHTML = "$"+newprice[2];
  ammountWithDiscountInputObj.innerHTML = "$"+newprice[1];
  quantityInput.value = quantity;
  amountInput.value = "$"+newprice[3];
  //changing plimus url
  var url = plimusUrlInputObj.value;
  var qpos = url.indexOf("&quantity");
  if (qpos!=-1){
  url = url.substr(0, qpos);
  }
  plimusUrlInputObj.value = url+"&quantity="+quantity;
  var ff;
  if(ff = document.getElementById('plimusurl')) {ff.href=plimusUrlInputObj.value}

  //changing return url for paypal
  url = returnUrlInput.value;
  qpos = url.indexOf("&price");
  if (qpos!=-1){
  url = url.substr(0, qpos);
  }
  returnUrlInput.value = url+"&price="+newprice[1];
}

function loadprices()
{

  var animator = document.getElementById('animator');
  animator.style.backgroundImage="url('ajax-animation.gif')";
  var par = document.forms[0];
  var parelmts = par.elements;
  var prodid = parelmts["ProdID"].value;
  var quantity = parelmts["inputquantity"].value;
  var myGet = "prices.php?version="+prodid+"&quantity="+quantity;
  xmlhttp.open("GET", myGet, true);
  xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {

  	if ( xmlhttp.responseText == "" ) {
  	
  	} else {
  	
  		ajaxResponse = xmlhttp.responseText;
  		
                var arr = ajaxResponse.split("|");
                var newprice = new Array(0,0,0,0);
		newprice[0] = arr[0];
		newprice[1] = arr[1];
		newprice[2] = arr[2];
		newprice[3] = arr[3];
		changePage(newprice);
		animator.style.backgroundImage="none";

  	}					   
      
  }
  }

  xmlhttp.send(null);


//  calculateprice(prodid, quantity);
}
