function checkUserData(mode)
{
  var uf=document.getElementById('cla_form');
  var retval=true;
  var alert_msg='';
  //PASSWORD CHECK
  if(uf.password.value!=uf.passwordConfirm.value)
  {  alert_msg+="Your Passwords do not match\n"; retval=false;}
  else if(!validatePass(uf.password,'',false)&&mode==0)
  {  alert_msg+="For security reasons, your password must be at least 6 characters long, and include at least 1 number and 1 alpha character.\n"; retval=false;}

  //REQUIRED FIELDS CHECK
  if(mode==0&&uf.username.value=='')
  {  alert_msg+="You must specify your username\n"; retval=false;}
  if(mode==0&&uf.password.value=='')
  {  alert_msg+="You must specify your password\n"; retval=false;}

  if(uf.first.value=='')
  {  alert_msg+="You must specify your first name\n"; retval=false;}
  if(uf.last.value=='')
  {  alert_msg+="You must specify your last name\n"; retval=false;}
  if(uf.company.value=='')
  {  alert_msg+="You must specify your company name\n"; retval=false;}

  //EMAIL CHECK
  if(uf.email.value=='')
  {  alert_msg+="You must specify your email address\n"; retval=false;}
  else if(!validateEmail(uf.email,'',false))
  {  alert_msg+="The email you specified is not valid\n"; retval=false;}

  if(uf.s_address1.value=='')
  {  alert_msg+="You must specify your shipping address\n"; retval=false;}
  if(uf.s_city.value=='')
  {  alert_msg+="You must specify your shipping city\n"; retval=false;}
  if(uf.s_state.value=='')
  {  alert_msg+="You must specify your shipping state\n"; retval=false;}
  if(uf.s_country.value=='')
  {  alert_msg+="You must specify your shipping country\n"; retval=false;}
  if(uf.s_zip.value=='')
  {  alert_msg+="You must specify your shipping zip\n"; retval=false;}

  if(!uf.s_equal_b_flag.checked)
  {
    if(uf.b_address1.value=='')
    {  alert_msg+="You must specify your billing address\n"; retval=false;}
    if(uf.b_city.value=='')
    {  alert_msg+="You must specify your billing city\n"; retval=false;}
    if(uf.b_state.value=='')
    {  alert_msg+="You must specify your billing state\n"; retval=false;}
    if(uf.b_country.value=='')
    {  alert_msg+="You must specify your billing country\n"; retval=false;}
    if(uf.b_zip.value=='')
    {  alert_msg+="You must specify your billing zip\n"; retval=false;}
  }

  if(!retval)
    alert(alert_msg);
  return retval;
}

function checkCheckoutData()
{
  var cf=document.getElementById('co_form');
  var retval=true;
  var alert_msg='';
  var cctype='';

  //REFERENCE NAME
  if(cf.customer_reference.value=='')
  {  alert_msg+="You must specify your customer reference number\n"; retval=false;}

  if(!cf.creditCard[0].checked)
  {
    if(cf.creditCard[1].checked)
      cctype=cf.creditCard[1].value;
    if(cf.creditCard[2].checked)
      cctype=cf.creditCard[2].value;
    if(cf.creditCard[3].checked)
      cctype=cf.creditCard[3].value;

    //CREDIT CARD DATA CHECK
    if(cf.cardName.value=='')
    {  alert_msg+="You must specify the name on your credit card\n"; retval=false;}
    if(cf.cardnumber.value=='')
    {  alert_msg+="You must specify your credit card number\n"; retval=false;}
    else
    { 
      if(!checkCreditCard(cf.cardnumber.value,cctype))
      {  alert_msg+=ccErrors[ccErrorNo]+"\n"; retval=false;}
    } 
    if(cf.securitycode.value=='')
    {  alert_msg+="You must specify your credit card's security code\n"; retval=false;}
  }
  else
  {
    if(cf.po_number.value=='')
    {  alert_msg+="You must specify a purchase order number\n"; retval=false;}
  }

  if(!retval)
    alert(alert_msg);
  return retval;
}


function validatePass(pass, msg, optional) 
{ 
  if (!pass.value && optional) 
    return true; 
  var re_pass1 = /^.*[0-9].*/; 
  var re_pass2 = /^.*[a-zA-Z].*/; 
  if (pass.value.length<6||!re_pass1.test(pass.value)||!re_pass2.test(pass.value))
  { 
    if(msg!='') { alert(msg); pass.focus(); pass.select(); } 
    return false; 
  } 
  return true; 
}

function validateEmail(email, msg, optional) 
{ 
  if (!email.value && optional) 
    return true; 
  if(msg!='')
    email.value=replaceAll(email.value," ",""); 
  var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/; 
  if (!re_mail.test(email.value))
  { 
    if(msg!='') { alert(msg); email.focus(); email.select(); } 
    return false; 
  }
  return true; 
}

function validateQ(qty)
{
  var re_num = /^[0-9]*$/; 
  qty=new String(qty);
  qty=qty.split(",");
  retval=true;
  for(i=0;i<qty.length;i++)
    if(qty[i]!=''&&qty[i]!='0'&&!re_num.test(qty[i]))
      retval=false;
  if(!retval)
    alert("You have not properly specified your quantity.");
  return retval;
}

function validateBR_psc(qty,siz,spec,name,asse,type)
{
  retval=true;
  if(validateQandS(qty,siz))
  {
    var re_num = /^[a-zA-Z0-9\s]*$/;
    type=new String(type);
    type=type.split(",");
    for(i=0;i<type.length;i++)
      if(type[i]==''||!re_num.test(type[i]))
        retval=false;
    if(!retval)
    {
      alert("You must select a type.");
      return retval;
    }
    var re_num = /^[a-zA-Z\s]*$/;
    spec=new String(spec);
    spec=spec.split(",");
    for(i=0;i<spec.length;i++)
      if(spec[i]==''||!re_num.test(spec[i]))
        retval=false;
    if(!retval)
    {
      alert("You have not properly specfied the species.");
      return retval;
    }
    var re_num = /^.*$/; 
    name=new String(name);
    name=name.split(",");
    for(i=0;i<name.length;i++)
      if(name[i]==''||!re_num.test(name[i]))
        retval=false;
    if(!retval)
    {
      alert("You have not properly specified the name of the gene.");
      return retval;
    }
    var re_num = /^[A-Za-z_0-9]*$/; 
    asse=new String(asse);
    asse=asse.split(",");
    for(i=0;i<asse.length;i++)
      if(asse[i]==''||!re_num.test(asse[i]))
        retval=false;
    if(!retval)
    {
      alert("You have not properly specfied the accession number.");
      return retval;
    }
  }
  else
    retval=false;
  return retval;
}


function validateQandS(qty,siz)
{
  var re_num = /^[0-9]*$/; 
  qty=new String(qty);
  siz=new String(siz);
  qty=qty.split(",");
  siz=siz.split(",");
  retval=true;
  var code=0;
  for(i=0;i<qty.length;i++)
  {
    if(qty[i]!=''&&qty[i]!='0'&&!re_num.test(qty[i]))
    {  retval=false; code=1;}
    if(qty[i]!=''&&qty[i]!='0'&&!siz[i])
    {  retval=false; code=2;}
    
  }
  if(!retval)
  {
    if(code==1)
      alert("You have not properly specified your quantity.");
    else if(code==2)
      alert("You must specify a size with your quantities.");
  }
  return retval;
}
