function validateAccount(theForm) {
var reason = "";

  reason += validateEmail(theForm.email);
  reason += validatePassword(theForm.password);
  reason += validatePhone(theForm.contact_phone1);
  reason += validateCCType(theForm.bill_type);
  reason += validateCC(theForm.bill_account_number);
  reason += validateCVV(theForm.bill_account_additional);
  reason += validateBillName(theForm.bill_name);
  reason += validateBillPhone(theForm.bill_phone);
  reason += validateBillAddress(theForm.bill_address1);
  reason += validateBillCity(theForm.bill_city);
  reason += validateBillState(theForm.bill_state);
  reason += validateBillZipcode(theForm.bill_zipcode);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  alert("All fields are filled correctly");
  return false;
}

//NO ENTER KEY SUBMIT
function stopRKey(evt)
{
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))
  {
    return false;
  }
}

function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#fffdd9'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a username.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = 'Yellow'; 
        error = "The username is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateCCType(fld)
{
    var error = "";
 
    if (fld.value == "")
    {
      fld.style.background = '#fffdd9'; 
      error = "You didn't pick a credit card type.\n";
    }
    else
    {
      fld.style.background = 'White';
    }
    return error;
}

function validateCC(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = '#fffdd9'; 
        error = "You didn't enter a credit card number.\n";
    } else if ((fld.value.length < 13) || (fld.value.length > 16)) {
        fld.style.background = '#fffdd9'; 
        error = "The credit card number is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#fffdd9'; 
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateCVV(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = '#fffdd9'; 
        error = "You didn't enter a CVV code.\n";
    } else if (fld.value.length < 3) {
        fld.style.background = '#fffdd9'; 
        error = "The CVV code is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = '#fffdd9'; 
        error = "The CVV code contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = '#fffdd9';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 16) || (fld.value.length > 4)) {
        //error = "The password is the wrong length. \n";
        //fld.style.background = '#fffdd9';
    } else {
        fld.style.background = 'White';
    }
   return error;
}  
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#fffdd9';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#fffdd9';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#fffdd9';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = '#fffdd9';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = '#fffdd9';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = '#fffdd9';
    }
    return error;
}

function validateBillName(fld)
{
    var error = "";
 
    if (fld.value == "")
    {
      fld.style.background = '#fffdd9'; 
      error = "You didn't enter a billing name.\n";
    }
    else
    {
      fld.style.background = 'White';
    }
    return error;
}

function validateBillPhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a billing phone number.\n";
        fld.style.background = '#fffdd9';
    } else if (isNaN(parseInt(stripped))) {
        error = "The billing phone number contains illegal characters.\n";
        fld.style.background = '#fffdd9';
    } else if (!(stripped.length == 10)) {
        error = "The billing phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = '#fffdd9';
    }
    return error;
}

function validateBillAddress(fld)
{
    var error = "";
 
    if (fld.value == "")
    {
      fld.style.background = '#fffdd9'; 
      error = "You didn't enter a billing address.\n";
    }
    else
    {
      fld.style.background = 'White';
    }
    return error;
}

function validateBillCity(fld)
{
    var error = "";
 
    if (fld.value == "")
    {
      fld.style.background = '#fffdd9'; 
      error = "You didn't enter a billing city.\n";
    }
    else
    {
      fld.style.background = 'White';
    }
    return error;
}

function validateBillState(fld)
{
    var error = "";
 
    if (fld.value == "")
    {
      fld.style.background = '#fffdd9'; 
      error = "You didn't enter a billing state.\n";
    }
    else
    {
      fld.style.background = 'White';
    }
    return error;
}

function validateBillZipcode(fld)
{
    var error = "";
 
    if (fld.value == "")
    {
      fld.style.background = '#fffdd9'; 
      error = "You didn't enter a billing zipcode.\n";
    }
    else
    {
      fld.style.background = 'White';
    }
    return error;
}

function showcontent(obj)
{
	var cardinfo = document.getElementById("cardinfo");

  if(obj.selectedIndex == "5")
  {
    cardinfo.style.display = "none";
  }
  else
  {
    cardinfo.style.display = "block";
  }
}