/* -- validate part numbers in buy now page*/

function validatePart(tBox) { 

   var desc = document.getElementById("desc" + tBox.id.substring(4));
   var m = document.getElementById("msg"); 


   //re = /^[a-zA-Z]\w{3,20}$/  
   //if (re.test(tBox.value) == false) {   
   //  desc.value = "Invalid Part"; 
   //  m.style.display = "none"; 
  // }     

  // make sure they aren't submitting blanks
 // else {
    var oXmlHttp = zXmlHttp.createRequest();
    oXmlHttp.open("get", "http://www.epscientific.com/product/getPart.aspx?id=" + encodeURI(tBox.value), true);
    oXmlHttp.onreadystatechange = function () {
      if (oXmlHttp.readyState == 4) {
        if (oXmlHttp.status == 200) {  
  
          var price = document.getElementById("price" + tBox.id.substring(4));  
          var qty = document.getElementById("qty" + tBox.id.substring(4));  
          var arrayInfo = oXmlHttp.responseText.split("||");
          if (arrayInfo[0] == "false") {
            m.style.display = "block";         
            desc.value ="** Invalid part number";
            qty.value = "";
            price.value = "";
            tBox.focus();         
          }       
          else {          
            desc.value = arrayInfo[1];
            price.value = formatCurrency(arrayInfo[2]);
            qty.value = "1";
            m.style.display = "none";           
          }        
        }
      }          
    }  
    oXmlHttp.send(null);  
 // } 
}


// format currency
function formatCurrency(amount) {

  var i = parseFloat(amount);
  if(isNaN(i)) { i = 0.00; }
  var minus = '';
  if(i < 0) { minus = '-'; }
  i = Math.abs(i);
  i = parseInt((i + .005) * 100);
  i = i / 100;
  s = new String(i);
  if(s.indexOf('.') < 0) { s += '.00'; }
  if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
  s = '$' + s;
  return s;
}







