// Javascript to check the contact form
// 11/11/03 - R. Costantini
//

function checkForm() {
    var why = ""
	why += checkName()
	why += checkEmail()
	why += checkLead()
	why += checkTimeFrame()
    why += checkVia()
    if (why != "") {
       alert(why)
       return false
    }
return true
}

function checkRMA() {
    var why = ""
	why += checkName()
	why += checkEmail()
    if (why != "") {
       alert(why)
       return false
    }
return true
}

function driverForm() {
    var why = ""
	why += checkName()
	why += checkEmail()
	why += checkSerial()
	why += checkPurchase()
    if (why != "") {
       alert(why)
       return false
    }
return true
}

function checkEmail () {
var error=""
var strng= document.form1.submit_by.value
if (strng == "") {
	document.form1.submit_by.style.backgroundColor = "#FFFFCC"
   error = "You didn't enter an email address.\n"
} else {
	document.form1.submit_by.style.backgroundColor = "#FFFFFF"
}

    var emailFilter=/^.+@.+\..{2,3}$/
    if (!(emailFilter.test(strng))) {
		document.form1.submit_by.style.backgroundColor = "#FFFFCC" 
       error = "Please enter a valid email address.\n"
    } else { 	//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          document.form1.submit_by.style.backgroundColor = "#FFFFCC"
		  error = "The email address contains illegal characters.\n"
       } else {
	   		document.form1.submit_by.style.backgroundColor = "#FFFFFF"
	   }
    }
return error    
}

// phone number - strip out delimiters and check for 10 digits
function checkPhone () {
var error = ""
var strng= document.form1.BillingPhoneNumber.value
if (strng == "") {
	document.form1.BillingPhoneNumber.style.backgroundColor = "#FFFFCC"
   error = "You didn't enter a phone number.\n"
}else {
	document.form1.BillingPhoneNumber.style.backgroundColor = "#FFFFFF"
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, '') //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       document.form1.BillingPhoneNumber.style.backgroundColor = "#FFFFCC"
	   error = "The phone number contains illegal characters."
  	} else {
		document.form1.BillingPhoneNumber.style.backgroundColor = "#FFFFFF"
	}
    if (!(stripped.length >= 10)) {
	document.form1.BillingPhoneNumber.style.backgroundColor = "#FFFFCC"
	error = "Please enter a phone number, be sure to include an area code.\n"
    } else {
	document.form1.BillingPhoneNumber.style.backgroundColor = "#FFFFFF"
	}
return error
}

// Check for the Buyer Name 
function checkName() {
var error = ""
var name = document.form1.Name.value
  if (name.length == 0) {
  	document.form1.Name.style.backgroundColor = "#FFFFCC"
     error += "Please enter your name.\n"
  } else {
  	document.form1.Name.style.backgroundColor = "#FFFFFF"
  }
return error	  
}

// Check for the Buyer Name 
function checkLead() {
var error = ""
var counter = 0
var Lead = document.form1.LeadSource.length
for (var i = 0; i < Lead; i++) {
  if ( document.form1.LeadSource[i].checked) {
     counter++
  } 
  }
  if (counter == 0 ) {
  	error += "Please enter a choice for question # 1.\n"
  }
return error	  
}

// Check for the Time Frame field 
function checkTimeFrame() {
var error = ""
var counter = 0
var Time = document.form1.timeFrame.length
for (var i = 0; i < Time; i++) {
  if ( document.form1.timeFrame[i].checked) {
     counter++
  } 
  }
  if (counter == 0 ) {
  	error += "Please enter a choice for question # 7.\n"
  }
return error	  
}

// Check for Contact via 
function checkVia() {
var error = ""
var counter = 0
var contact = document.form1.Via.length
  for (var i = 0; i < contact; i++) {
  if ( document.form1.Via[i].checked) {
     counter++
  } 
  }
  if (counter == 0 ) {
  	error += "Please enter a choice for question # 9.\n"
  }
return error	  
}


// Check for the Serial Number 
function checkSerial() {
var error = ""
var serial = document.form1.serialnumber.value
  if (serial.length == 0) {
  	document.form1.serialnumber.style.backgroundColor = "#FFFFCC"
     error += "Please enter the serial number for the product.\n"
  } else {
  	document.form1.serialnumber.style.backgroundColor = "#FFFFFF"
  }
return error	  
}

// Check for the Purchased Name 
function checkPurchase() {
var error = ""
var purchase = document.form1.purchased.value
var date = document.form1.datePurchased.value
  if (purchase.length == 0) {
  	document.form1.purchased.style.backgroundColor = "#FFFFCC"
     error += "Please enter the name of the company where you purchased the product.\n"
  } else {
  	document.form1.purchased.style.backgroundColor = "#FFFFFF"
  }
  if (date.length == 0) {
  	document.form1.datePurchased.style.backgroundColor = "#FFFFCC"
     error += "Please enter the date when you purchased the product.\n"
  } else {
  	document.form1.datePurchased.style.backgroundColor = "#FFFFFF"
  }
return error	  
}


