// JavaScript Document
function ck() {
var why = "";
why += checkName(document.ctiForm.name.value);
why += checkCompany(document.ctiForm.company.value);
why += checkAddress(document.ctiForm.address.value);
why += checkCity(document.ctiForm.city.value);
why += checkState(document.ctiForm.state.selectedIndex);
why += checkCountry(document.ctiForm.country.selectedIndex);
why += checkZipcode(document.ctiForm.zipcode.value);
why += checkPhone(document.ctiForm.phone.value);
why += checkEmail(document.ctiForm.email.value);
why += checkOther();
if (why != "") {
alert(why);
return false;
}
else {
document.ctiForm.submit();
}
return true;
}

function checkName(strng){
var error = "";
if (strng == "") {
   error = "You didn't enter your name.\n";
}
return error;
}

function checkCompany(strng){
var error="";
if (strng==""){
error="You didn't enter your company.\n";
}
return error;
}

function checkAddress (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter an address.\n";
}
return error;
}

function checkCity (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a city.\n";
}
return error;
}

function checkState(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't select a state.\n";
    }    
return error;
}

function checkCountry(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't select a country.\n";
    }    
return error;
}

function checkZipcode (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a zip code.\n";
}
else {
    if (isNaN(strng)) {
       error = "The zipcode is not valid.\n";
    }
	else{
    if (!(strng.length == 5)) {
	error = "The zipcode is not valid.\n";
    }
	}
	}
return error;
}

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}
else {
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number is not valid.\n";
      }
	
	else {
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. (Make sure you included an area code.)\n";
    } 
	}
	}
return error;
}

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}
else{
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address is not valid.\n";
       }
    }
	}
return error;    
}

function checkOther(){
var err="";
if ((document.ctiForm.other.checked==true)&&(document.ctiForm.comments.value=="")){
err ="You have selected 'other'. Please describe your interests.\n";
}
return err;
}