  function getHTTPObject()
  {
    var x = null;
    if (window.XMLHttpRequest)
    {
      x = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
      x = new ActiveXObject("Microsoft.XMLHTTP");
      if (!x)
      {
      x = new ActiveXObject("Msxml2.XMLHTTP");
      }
    }
    return x;
  }
 
  var gobj = getHTTPObject();
 
  function update()
  {   
	var c = document.getElementById('quality').value;
	var w = String(document.getElementById('quantity').value);
	if (w.length < 1) { w = "0"; }
	if (w.lenght > 6) { w = w.substring(0, 6); }
	w = validaten(w);
	var u = "goldquote.asp?c=" + myencode(c, w);  
    gobj.open("GET", u, true);
    gobj.onreadystatechange = update_all;
    gobj.send(null);
  }
   function myencode(v1, v2)
   {
            var P = v1 + "A" + v2;
            return escape(P);
   }
   function validaten(w)
   {
	var res = "";
	var xw = String(w);
	var i = 0;
	var j = 0;
	for (i = 0; i < xw.length; i++) {
		if (xw.charAt(i) >= "0" && xw.charAt(i) <= "9") {
						res += xw.charAt(i);
						}
	    if (xw.charAt(i) == "." && j == 0 ){
						res += xw.charAt(i);
						j = 1;
						}	 
	}
	return res;
   }
  function update_all()
  {
    if (gobj.readyState == 4)
    {
      var AR = gobj.responseText.split("$");
	  var aobj = document.getElementById('pricemess');;
	  var dobj = new Array(3);
	  dobj[0] = document.getElementById('carat');
	  dobj[1] = document.getElementById('price');
	  dobj[2] = document.getElementById('inc');
	  for (var i = 0; i < 3; i++) {
               								if ( i == 2) {
	                    if (AR[i] != "0.00" && AR[i] != "0") {
						     dobj[i].innerHTML = "H&T will pay you &pound;" + AR[i];
							 aobj.innerHTML = "<br>* This is a guide only and does not constitute a formal offer";
							 }
						else {
						     dobj[i].innerHTML = "";
							 aobj.innerHTML = "";
							 }	 
	           }
	   }
    }
  }
  
 
 function submitform()
 {
 document.GOLDPACK.submit();
 }
 
