function tabSwap(id) {
	if(id=="home") {
		document.getElementById(id).src="images/home-active-p.jpg";
	}
	
	if(id=="what-is") {
		document.getElementById(id).src="images/what-is-active-p.jpg";
	}
	
	if(id=="join") {
		document.getElementById(id).src="images/join-today-active-p.jpg";
	}
	
	if(id=="login") {
		document.getElementById(id).src="images/login-active-p.jpg";
	}
	
	if(id=="contact") {
		document.getElementById(id).src="images/contact-info-active-p.jpg";
	}
	
	if(id=="detail") {
		document.getElementById(id).src="images/details-active-p.jpg";
	}
}

function tabReset(id) {
	if(id=="home") {
		document.getElementById(id).src="images/home-button.jpg";
	}
	
	if(id=="what-is") {
		document.getElementById(id).src="images/what-is-button.jpg";
	}
	
	if(id=="join") {
		document.getElementById(id).src="images/join-today-button.jpg";
	}
	
	if(id=="login") {
		document.getElementById(id).src="images/login-button.jpg";
	}
	
	if(id=="contact") {
		document.getElementById(id).src="images/contact-info-button.jpg";
	}
	
	if(id=="detail") {
		document.getElementById(id).src="images/details-button.jpg";
	}
}

function ltrim ( s ) {
	return s.replace( /^\s*/, "" );
}

function rtrim ( s ) {
	return s.replace( /\s*$/, "" );
}

function trim ( s ) {
	return rtrim(ltrim(s));
}

function validate(form) {

	document.form1.username.value= trim(document.form1.login.value);

	if(document.form1.login.value == ""){
		alert ("Please enter a valid login user name.");
		document.form1.login.focus();
		return false;
	}
		
	document.form1.password.value= trim(document.form1.password.value);

	if (document.form1.password.value == "") {
		alert ("Please enter a valid password.");
		document.form1.password.focus();
		return false;
	}
			      
}

function validate2(form) {

	if(document.joinForm.golden_rule_id.value == "") {
		alert("Please enter your Golden Rule ID.");
		document.joinForm.golden_rule_id.focus();
		return false;
	}
	
	if(document.joinForm.license_number.value == "") {
		alert("Please enter your Home State License Number.");
		document.joinForm.license_number.focus();
		return false;
	}

	if(document.joinForm.first_name.value == "") {
		alert("Please enter your first name.");
		document.joinForm.first_name.focus();
		return false;
	}
	
	if(document.joinForm.last_name.value == "") {
		alert("Please enter your last name.");
		document.joinForm.last_name.focus();
		return false;
	}

	if(document.joinForm.address_street.value == "") {
		alert("Please enter your street address.");
		document.joinForm.address_street.focus();
		return false;
	}
	
	if(document.joinForm.address_city.value == "") {
		alert("Please enter your City in which you live.");
		document.joinForm.address_city.focus();
		return false;
	}
	
	if(document.joinForm.address_state.value == "") {
		alert("Please enter the state in which you live.");
		document.joinForm.address_state.focus();
		return false;
	}
	
	if(document.joinForm.address_postalcode.value == "" || isNaN(document.joinForm.address_postalcode.value)) {
		alert("Please enter your Zip Code.");
		document.joinForm.address_postalcode.value = "";
		document.joinForm.address_postalcode.focus();
		return false;
	}
	
	if(document.joinForm.phone.value == "") {
		alert("Please enter the best phone number to contact you at.");
		document.joinForm.phone.focus();
		return false;
	}
	
	if(document.joinForm.email1.value =="") {
		alert("Please enter a valid email address.\nYour email address should use the form \"name@domain.com\"");
		document.joinForm.email1.focus();
		return false;
	}
	
	if(!emailCheck(document.joinForm.email1.value)) {
		return false;	
	}
	
	if(document.joinForm.company_name.value == "") {
		alert("Please enter your Company\'s Name.");
		document.joinForm.company_name.focus();
		return false;
	}
	
	if (textareaAtEnd(document.joinForm.agreement)) {

		if(document.joinForm.disagree_to_terms.checked == true) {
			alert("You have not accepted the terms of the agreement.")
			return false;
		}
	
		if(document.joinForm.agree_to_terms.checked == false) {
			alert("Please accept the terms of the agreement.");
			document.joinForm.agree_to_terms.focus();
			return false;
		}

	} else {
		alert ("Please scroll to the end of the terms and conditions.")
		return false;
	}

	return true;
}

function textareaAtEnd(textareaObj) {

	return ((textareaObj.scrollTop + textareaObj.offsetHeight) > textareaObj.scrollHeight);

}

function emailCheck(emailStr){
   var emailPat=/^(.+)@(.+)$/
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
   var validChars="\[^\\s" + specialChars + "\]"
   var quotedUser="(\"[^\"]*\")"
   var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
   var matchArray=emailStr.match(emailPat)
   if(matchArray==null){alert("Email address seems incorrect (check @ and .'s)");return false;}
   var user=matchArray[1];
   var domain=matchArray[2];
   if(user.match(userPat)==null){alert("The username of the email address doesn't seem to be valid.");return false;}
   var IPArray=domain.match(ipDomainPat);
   if(IPArray!=null){for(var i=1;i<=4;i++){if(IPArray[i]>255){alert("Destination IP address is invalid!");return false;}}return true;}
   var domainArray=domain.match(domainPat);
   if(domainArray==null){alert("The domain name doesn't seem to be valid.");return false;}
   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;
   if(domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
	   alert("The email address must end in a three-letter domain, or two letter country.");
	   return false;
	}
   if(len<2) {
	   var errStr="This address is missing a hostname!";
	   alert(errStr);
	   return false;
	}
	return true;
}