var ids = new Array('1', '2', '3', '4');

function switchid(id){	
	hideallids();
	showdiv(id);
}

function hideallids() {
    //loop through the array and hide each element by id
    for (var i = 0; i < ids.length; i++) {
        hidediv(ids[i]);
    }
}

var hpinsids = new Array('1', '2', '3', '4', '5', '6', '7', '8', '9');
function switchhpinsid(id) {
    hideallhpinsids();
    showdiv(id);
}

function hideallhpinsids() {
    //loop through the array and hide each element by id
    for (var i = 0; i < hpinsids.length; i++) {
        hidediv(hpinsids[i]);
    }
}

	function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = '';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = '';
		}
		else { // IE 4
			document.all.id.style.display = '';
		}
	}
}

function addClass() {
	//var element = document.getElementById(elementID);
	
	'1a'.setAttribute("class", 'active'); //For Most Browsers
	'1a'.setAttribute("className", 'active'); //For IE; harmless to other browsers.
}
function clearText(field){

    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;

}
function validateMailGuide(theForm) {
var reason = "";

  //reason += validateUsername(theForm.username);
  //reason += validatePassword(theForm.pwd);
  reason += validateEmpty(theForm.Zip);
  reason += validateEmpty(theForm.Name); 
  reason += validateEmpty(theForm.Address); 
  reason += validateEmpty(theForm.City);
  reason += validateEmpty(theForm.State);
  if (reason != "") {
    alert("Please correct highlighted fields.");
    return false;
  }

  return true;
}
function validateScholApp(theForm) {
var reason = "";

  //reason += validateUsername(theForm.username);
  //reason += validatePassword(theForm.pwd);
  reason += validateEmail(theForm.SEmail);
  reason += validatePhone(theForm.Phone);
  reason += validateEmpty(theForm.Zip);
  reason += validateEmpty(theForm.Contact); 
  reason += validateEmpty(theForm.Address); 
  reason += validateEmpty(theForm.City);
  reason += validateEmpty(theForm.SchoolName); 
  reason += validateEmpty(theForm.Address); 
  reason += validateEmpty(theForm.GradDate);
  reason += validateEmpty(theForm.Description); 
  reason += validateEmpty(theForm.ScholarshipUse); 
  reason += validateEmpty(theForm.Resume); 
  if (reason != "") {
    alert("Please correct highlighted fields.");
    return false;
  }

  return true;
}
function valIquoteClient(theForm) {
var reason = "";

  //reason += validateUsername(theForm.username);
  //reason += validatePassword(theForm.pwd);
  reason += validateEmail(theForm.email);
  //reason += validatePhone(theForm.BusPhone);
  reason += validateEmpty(theForm.Q1);
  reason += validateEmpty(theForm.Q2); 
  reason += validateEmpty(theForm.Q3); 
  reason += validateEmpty(theForm.Q4);
  reason += validateEmpty(theForm.first);
  reason += validateEmpty(theForm.last); 
  reason += validateEmpty(theForm.city); 
  reason += validateEmpty(theForm.state);
  reason += validateEmpty(theForm.street);
  reason += validateEmpty(theForm.zip);
  reason += validatePhone3(theForm.day_phone1); 
  reason += validatePhone3(theForm.day_phone2); 
  reason += validatePhone4(theForm.day_phone3);
  //reason += validateEmpty(theForm.BusDescription); 
  //reason += validateEmpty(theForm.BusGrantsUse); 
  //reason += validateEmpty(theForm.BusPlan); 
  if (reason != "") {
    alert("Please correct highlighted fields.");
    return false;
  }

  return true;
}
function validateGrantApp2(theForm) {
var reason = "";

  //reason += validateUsername(theForm.username);
  //reason += validatePassword(theForm.pwd);
  //reason += validateEmail(theForm.BusEmail);
  //reason += validatePhone(theForm.BusPhone);
  reason += validateEmpty(theForm.BillingName);
  reason += validateEmpty(theForm.BillingAddress); 
  reason += validateEmpty(theForm.BillingCity); 
  reason += validateEmpty(theForm.BillingZip);
  reason += validateEmpty(theForm.CSC); 
  reason += validateCC(theForm.CCNum); 
  //reason += validateEmpty(theForm.BusPlan); 
  if (reason != "") {
    alert("Please correct highlighted fields.");
    return false;
  }

  return true;
}


function validateSignUp(theForm) {
var reason = "";

  //reason += validateUsername(theForm.username);
  //reason += validatePassword(theForm.pwd);
  reason += validateEmail(theForm.Email2);
  reason += validatePhone(theForm.Phone);
  reason += validateEmpty(theForm.Name);
  reason += validateEmpty(theForm.Address);    
  if (reason != "") {
    alert("Please correct highlighted fields.");
    return false;
  }

  return true;
}
function validateContact(theForm) {
var reason = "";

  //reason += validateUsername(theForm.username);
  //reason += validatePassword(theForm.pwd);
  reason += validateEmail(theForm.EmailC);
  reason += validateEmpty(theForm.Name);
  reason += validateEmpty(theForm.Message);    
  if (reason != "") {
    alert("Please correct highlighted fields.");
    return false;
  }

  return true;
}
function validateDownloadEmail(theForm) {
var reason = "";

  //reason += validateUsername(theForm.username);
  //reason += validatePassword(theForm.pwd);
  reason += validateEmail(theForm.EmailDL);
  //reason += validatePhone(theForm.phone);
  //reason += validateEmpty(theForm.from);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}
function validateSomeThing(theForm) {
var reason = "";

  //reason += validateUsername(theForm.username);
  //reason += validatePassword(theForm.pwd);
  reason += validateEmail(theForm.Email);
  //reason += validatePhone(theForm.phone);
  //reason += validateEmpty(theForm.from);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}
function validateEmailList(theForm) {
var reason = "";

  //reason += validateUsername(theForm.username);
  //reason += validatePassword(theForm.pwd);
  reason += validateEmail(theForm.Email);
  //reason += validatePhone(theForm.phone);
  //reason += validateEmpty(theForm.from);
      
  if (reason != "") {
    alert(reason);
    return false;
  }

  return true;
}
function valIntSignUp(theForm) {
var reason = "";

  //reason += validateUsername(theForm.username);
  //reason += validatePassword(theForm.pwd);
  reason += validateEmptyZip(theForm.zip);
  //reason += validatePhone(theForm.phone);
  //reason += validateEmpty(theForm.boolHaveLTC);
      
  if (reason != "") {
    alert(reason);
    return false;
  }

  return true;
}
function validateEmptyZip(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "Please enter your zip code..\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validatePhone3(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 3)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}
function validatePhone4(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 4)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}
function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        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 validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password is the wrong length. \n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.style.background = 'Yellow';
    } 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 = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        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 = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}
function validateCC(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a credit card number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The credit card number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length >= 15)) {
        error = "The credit card number is the wrong length.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}
