﻿function validform1(bnf) {
  if (bnf.shipzip.value == "") {
    alert("Please enter a zip code.");
    bnf.shipzip.focus();
    return false;
    }
  if (bnf.contactemail.value =="") {
    alert("You must enter an email address.");
    bnf.contactemail.focus();
    return false;
    }
  if (!bnf.shiptobilladdr.checked && bnf.billstreet1.value == "") {
    alert("Please enter a billing address or check the box above the shipping form.");
    bnf.shiptobilladdr.focus();
    return false;
    }
  else {
    return true;
    }
}

function validform2(bnf) {
  if (bnf.cardnumber.value =="") {
    alert("You must enter a credit card number.");
    bnf.cardnumber.focus();
    return false;
    }
  if (bnf.cardtype.value == "Visa" && bnf.cardnumber.value.length !=16 && bnf.cardnumber.value.length!=13) {
    alert("The credit card number does not have the required number of digits. Please re-enter. And please omit dashes and spaces if applicable.");
    bnf.cardnumber.focus();
    return false;
    }
  if (bnf.cardtype.value == "MasterCard" && bnf.cardnumber.value.length !=16) {
    alert("The credit card number does not have the required number of digits. Please re-enter. And please omit dashes and spaces if applicable.");
    bnf.cardnumber.focus();
    return false;
    }
  if (bnf.cardtype.value == "Discover" && bnf.cardnumber.value.length!=16) {
    alert("The credit card number does not have the required number of digits. Please re-enter. And please omit dashes and spaces if applicable.");
    bnf.cardnumber.focus();
    return false;
    }
  if (bnf.cardtype.value == "AMEX" && bnf.cardnumber.value.length !=15) {
    alert("The credit card number does not have the required number of digits. Please re-enter. And please omit dashes and spaces if applicable.");
    bnf.cardnumber.focus();
    return false;
    }
  else {
    return true;
    }
}

function validform3(bnf) {
  if (bnf.contactemail.value =="") {
    alert("You must enter an email address.");
    bnf.contactemail.focus();
    return false;
    }
  if (bnf.cardnumber.value =="") {
    alert("You must enter a credit card number.");
    bnf.cardnumber.focus();
    return false;
    }
else {
  return true;
   }
}

function validform4(bnf) {
  if (bnf.friend2.value =="") {
    alert("To send coupons you must enter at least two different email addresses.");
    bnf.friend2.focus();
    return false;
    }
  if (bnf.friend1.value == bnf.friend2.value) {
    alert("To send coupons you must enter at least two different email addresses.");
    bnf.friend2.focus();
    return false;
    }
  else {
    return true;
    }
}

function validLogin(passForm) {
  if ((passForm.username.value == "") && (passForm.password.value == "")) {
    alert("You must enter a Username and Password.")
    passForm.username.focus()
    return false
  }
  if (passForm.username.value == "") {
    alert("You must enter a Username.")
    passForm.username.focus()
    return false
  }
  if (passForm.password.value == "") {
    alert("You must enter a Password.")
    passForm.password.focus()
    return false
  }
  return true
}

function validRegForm(regForm) {
 if (regForm.username.value == ""){
   alert("You must enter a Username.")
   regForm.username.focus()
   return false
 }
 if (regForm.password.value == ""){
   alert("You must enter a Password.")
   regForm.password.focus()
   return false
 }
 if (regForm.password.value != regForm.password2.value){
   alert("Passwords don't match! Please try again.")
   regForm.password.value = ""
   regForm.password2.value = ""
   regForm.password.focus()
   return false
 }
return true
}

function popUp(path,name,wide,high) {
   if (window.popupwindow && !window.popupwindow.closed){
     window.popupwindow.close()
   }
   wide=wide+40
   high=high+70
   popupwindow = window.open(path, name, "location=no, scrollbars=yes, menubars=no, toolbars=no, resizable=yes, width="+wide+", height="+high)
   popupwindow.focus()
   }

function filepolicy() {
  filepolicywindow = window.open("filepolicy.html", "File_Policy", "width=400,height=450,scrollbars=yes")
  filepolicywindow.focus()
  }

function textpolicy() {
  textpolicywindow = window.open("textpolicy.html", "File_Policy", "width=400,height=350,scrollbars=yes")
  textpolicywindow.focus()
  }

function validPostform(postForm) {

  if (postForm.title.value == "") {
    alert("You must enter a title.")
    postForm.title.focus()
    return false
  }
  if (postForm.price.value == "") {
    alert("You must enter a price.")
    postForm.price.focus()
    return false
  }
  return true
}

function AreYouSure() {
  if (confirm("Are you sure you want to Delete this listing?")){
    return true
  }
  else {
    return false
  }
}

function SortPage(newLoc){
  newPage = newLoc.options[newLoc.selectedIndex].value
  if (newPage !=""){
    window.location = newPage
  }
}