// JavaScript Document
// Email Validation. Written by PerlScriptsJavaScripts.com
// Form Field names modified by Ben Montanelli www.riverinternet.com
// Cloned extra fields. Had to remove second email check.
// Added password confirm mar-9-06

function check_email(e) {
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt(i))<0){ 
return (false);
}	
} 

if (document.images) {
re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!e.match(re) && e.match(re_two)) {
return (-1);		
} 

}

}
//// end function check_email ////

//// begin function confirm password ////
function pconfirm(form) {
var e = form.elements, m = '';
if(!e['password'].value) {m += '- Password is required.\n';}
if(e['password'].value != e['confirm'].value) {
m += '- Your password and confirmation password do not match.\n';
}
if(m) {
alert('The following error(s) occurred:\n\n' + m);
return false;
}
return true;
}
//// end function confirm password ////

////////////////////// start routines /////////////////////

function check_subscribeform(f) { // f is the form (passed using the this keyword)

// check the first email address ( the exclamation means "not" )
if(!check_email(f.username.value)){
alert("Invalid email address detected.");
f.username.focus(); 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.username.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}

//// password check  ////
if(f.password.value.length < 1){
alert("You entered less than one character in Password.");
f.password.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.password.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}

if(f.confirm.value.length < 1){
alert("You entered less than one character in Confirm Password.");
f.confirm.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.confirm.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}

var m = '';
if(f.password.value != f.confirm.value) {
m += '- Your password and confirmation password do not match.\n';
}
if(m) {
alert('The following error(s) occurred:\n\n' + m);
return false;
}
//// end password check ////


// check name
if(f.fullname.value.length < 1){
alert("You entered less than one character in the Name field.");
f.fullname.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.fullname.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}

// Check for ornganization name
if(f.company.value.length < 1){
alert("You entered less than one character in Organization.");
f.company.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.company.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}


// Check for address one
if(f.addr1.value.length < 1){
alert("You entered less than one character in the Address field.");
f.addr1.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.addr1.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}

// Check for city
if(f.city.value.length < 1){
alert("You entered less than one character in the city field.");
f.city.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.city.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}

// Check for state
if(f.state.value.length < 1){
alert("You entered less than one character in the state field.");
f.state.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.state.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}

// Check for zip
if(f.zip.value.length < 1){
alert("You entered less than one character in the zip field.");
f.zip.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.zip.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}

// Check for country
if(f.country.value.length < 1){
alert("You entered less than one character in the country field.");
f.country.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.country.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}

// Check for telephone
if(f.telephone.value.length < 1){
alert("You entered less than one character in the telephone field.");
f.telephone.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.telephone.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}

// Check for fax
if(f.fax.value.length < 1){
alert("You entered less than one character in the fax field.");
f.fax.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.fax.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}

// Check for industry
if(f.industry.value.length < 1){
alert("You entered less than one character in the industry field.");
f.industry.focus(); // put the prompt in the name field 
// if the browser is Netscape 6 or IE
if(document.all || document.getElementByID){
// change the color of text field
f.industry.style.background = "yellow";
}
// make sure the form is not submitted
return false;
}


//// end function check_form ////
}


