function valid(field) {
var receipt = parseInt(field);
if (receipt == 51600000) {
  alert("Your online support and returns facilities have been disabled due to consistent  misuse.\n\nPlease email admin@metatech.co.uk with an explanation to get your account reinstated .");
  return false;
} else if (receipt > 51600000 & receipt < 51601000) {
  alert("Technical support is only available for 12 months from the date of delivery.");
  return false;
} else if (receipt > 51600500  & receipt < 51650000) {
      return true;
  } else {
        alert("This is not a valid METATECH.co.uk sales receipt number.\n\nYou must supply a valid sales receipt number to receive support. \n\nYour sales receipt number can be found on your paper sales receipt which is enclosed with your goods."); 
      return false;
        }
 }


function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-')  + num + '.' + cents);
}

function valid2(form) {
  q1 = eval(form.MC_qty1.value)
  q2 = eval(form.MC_qty2.value)
  if (q2 < q1 ){
    alert("Exchange quantity must be greater than or equal to the ordered quantity.");
    return false;
  } else {
    return true;
  }
}


function calc(form) {
  q1 = eval(form.MC_qty1.value)
  q2 = eval(form.MC_qty2.value)

  var e1 = 1, e2 = 1, e3 = 1, e4 = 1, e5 = 1, e6 = 1;
  p1 = eval(form.MC_price1.value)
  p2 = eval(form.MC_price2.value)

  var dif1 = (p2*q2) - (p1*q1);

  dif1 = dif1.toString().replace(/\$|\,/g,'');
  if(isNaN(dif1))
  dif1 = "0";
  sign = (dif1 == (dif1 = Math.abs(dif1)));
  dif1 = Math.floor(dif1*100+0.50000000001);
  cents = dif1%100;
  dif1 = Math.floor(dif1/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((dif1.length-(1+i))/3); i++)
  dif1 = dif1.substring(0,dif1.length-(4*i+3))+','+
  dif1.substring(dif1.length-(4*i+3));
  var dif2 = ((sign)?'':'-')  + dif1 + '.' + cents;

  form.MC_price_dif.value = dif2;

  x1 = eval(form.MC_admin.value)
  d1 = eval(form.MC_delivery.value)
  dif3 = eval(form.MC_price_dif.value)

  var sub1 = dif3 + x1 + d1;
  var v1 = sub1 * 0.175;


  v1 = v1.toString().replace(/\$|\,/g,'');
  if(isNaN(v1))
  v1 = "0";
  sign = (v1 == (v1 = Math.abs(v1)));
  v1 = Math.floor(v1*100+0.50000000001);
  cents = v1%100;
  v1 = Math.floor(v1/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((v1.length-(1+i))/3); i++)
  v1 = v1.substring(0,v1.length-(4*i+3))+','+
  v1.substring(v1.length-(4*i+3));
  var v2 = ((sign)?'':'-')  + v1 + '.' + cents;

  form.MC_vat.value = v2;
  v3 = eval(form.MC_vat.value)
  var tot1 = v3 + sub1;

  tot1 = tot1.toString().replace(/\$|\,/g,'');
  if(isNaN(tot1))
  tot1 = "0";
  sign = (tot1 == (tot1 = Math.abs(tot1)));
  tot1 = Math.floor(tot1*100+0.50000000001);
  cents = tot1%100;
  tot1 = Math.floor(tot1/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((tot1.length-(1+i))/3); i++)
  tot1 = tot1.substring(0,tot1.length-(4*i+3))+','+
  tot1.substring(tot1.length-(4*i+3));
  var tot2 = ((sign)?'':'-')  + tot1 + '.' + cents;
 
  form.amount.value = tot2;
}


function ChangeCase(form) 
{
 var strVariable = form._EmailAddress.value; 
 strVariable = strVariable.toLowerCase( ); 
 form._EmailAddress.value = strVariable;
}