//JavaScript preload images

topImage=new Image
topImage.src = "images/top.jpg"

nav_bar=new Image
nav_bar.src = "images/navBG.jpg"

buttonHomeO=new Image
buttonHomeO.src="images/buttonHome.jpg"

buttonHomeH= new Image
buttonHomeH.src = "images/buttonHomeH.jpg"

buttonNewsO=new Image
buttonNewsO.src="images/buttonNews.jpg"

buttonNewsH= new Image
buttonNewsH.src = "images/buttonNewsH.jpg"

buttonBoardO=new Image
buttonBoardO.src="images/buttonBoard.jpg"

buttonBoardH= new Image
buttonBoardH.src = "images/buttonBoardH.jpg"

buttonDirO=new Image
buttonDirO.src="images/buttonDir.jpg"

buttonDirH= new Image
buttonDirH.src = "images/buttonDirH.jpg"

buttonMembersO=new Image
buttonMembersO.src="images/buttonMembers.jpg"

buttonMembersH= new Image
buttonMembersH.src = "images/buttonMembersH.jpg"

buttonResourcesO=new Image
buttonResourcesO.src="images/buttonResources.jpg"

buttonResourcesH= new Image
buttonResourcesH.src = "images/buttonResourcesH.jpg"

buttonServicesO=new Image
buttonServicesO.src="images/buttonServicesO.jpg"

buttonServicesH= new Image
buttonServicesH.src = "images/buttonServicesH.jpg"




// JavaScript functions to show/hide information

function showInfo(choice){
	document.getElementById(choice).style.visibility="visible";
}

function hideInfo(choice){
	document.getElementById(choice).style.visibility="hidden";

}
/*

function getFocus(OtherAnimal){
	 document.mem.OtherAnimal.focus();
}
	

function showOther(OtherModality){
	
	if(document.mem.Modality.options[document.mem.Modality.selectedIndex].value == "More"){
		showInfo(document.mem.OtherModality);
	}

}

function showOther(otherFoundText){
	
	if(document.mem.FoundUs.options[document.mem.FoundUs.selectedIndex].value == "OtherFound"){
		showInfo(otherFoundText);
	}

}
		
function unSelect(Modality){
	
	document.mem.Modality.selectedIndex = -1;
}
*/
function unCheckBoxes(uncheck,total_boxes){
	for (i = 0; i < total_boxes; i++){
		document.forms[0].Animal[i].checked=false;
	}
}

function clearText(OtherAnimal){
	if(document.mem.dues[0].checked == false)
	{
		document.mem.OtherAnimal.value ="";
	}
}

function clearText2(OtherModality){
	if(document.mem.dues[1].checked == false)
	{
		document.mem.OtherModality.value ="";
	}
}
function unSelect(Modality){
	
	document.mem.Modality.selectedIndex = -1;
}


//JavaScript functions for validating form

function validData(){
	
	var error_string = "";
	

	// check the name fields
	if ((document.mem.first_name.value == '')|| (document.mem.first_name.value.length <=1)){
		error_string += "First Name.\n";
		document.getElementById("first").style.color="#FF0000";
	}else{	
		document.getElementById("first").style.color="#000";
	}
	
	if ((document.mem.last_name.value == '')|| (document.mem.last_name.value.length <=1)){
		error_string += "Last Name.\n";
		document.getElementById("last").style.color="#FF0000";
	}else{	
		document.getElementById("last").style.color="#000";
	}
	
	//check address field
	if ((document.mem.address1.value =='')||(document.mem.address1.value.length <=1)){
		error_string += "Address.\n";
		document.getElementById("addr").style.color="#FF0000";
	}else{	
		document.getElementById("addr").style.color="#000";		
	}
	
	//check city field
	if ((document.mem.city.value =='')||(document.mem.city.value.length <=1)){
		error_string += "City.\n";
		document.getElementById("cty").style.color="#FF0000";
	}else{	
		document.getElementById("cty").style.color="#000";		
	}
	
	//check state information
	if(document.mem.state.selectedIndex <0){
		error_string += "State.\n";
		document.getElementById("ste").style.color="#FF0000";
	}else{	
		document.getElementById("ste").style.color="#000";		
	}
	
	//check zipcode
	
		if (checkZip(document.mem.zip.value)== true){
			error_string += "Zipcode.\n";
		document.getElementById("zipC").style.color="#FF0000";
	}else{	
		document.getElementById("zipC").style.color="#000";			
		}
		
	
	//check phone
		
		if (checkPhone(document.mem.phone.value) == true){
			error_string += "Phone Number.\n";
		document.getElementById("phoneNum").style.color="#FF0000";
	}else{	
		document.getElementById("phoneNum").style.color="#000";			
		}	
	
	//check e-mail
		
		if (checkEmail(document.mem.email.value) == true){
			error_string += "E-mail address.\n";	
		document.getElementById("eml").style.color="#FF0000";
	}else{	
		document.getElementById("eml").style.color="#000";			
		}
	
	//check website
	
		if ((document.mem.website.value != "") && (isURL(document.mem.website.value) == true)){
			error_string +="Website address.\n";
		document.getElementById("ws").style.color="#FF0000";
	}else{	
		document.getElementById("ws").style.color="#000";			
		}
	
	//check radio buttons
	
	var rad = "no";
	

	for (var loop = 0; loop < document.mem.dues.length; loop++){
		if(document.mem.dues[loop].checked == true){
		
			rad = "yes";
			document.getElementById("lft").style.color="#000";			
		}
	}	
	if (rad == "no"){
		error_string += "You must choose a type of membership.\nOwner or Professional.";
		document.getElementById("lft").style.color="#FF0000";		
	}
	
	//check animal choice
	
	if(document.mem.dues[0].checked == true){
		
		var animal=0;
				
		for (var i = 0; i < document.mem.Animal.length; i++){
			if(document.mem.Animal[i].checked==true){
				animal += 1;
			document.getElementById("animl").style.color="#000";				
			}
		}
		if(animal == 0){
			error_string += "Please tell us what type of animal you own.";	
			document.getElementById("animl").style.color="#FF0000";			
		}
				
	}
	
	//check professional modality
	
	if((document.mem.dues[1].checked==true) && (document.mem.Modality.selectedIndex == -1) ){
		
		error_string += "Please tell us what your modalities are.";
		document.getElementById("pro").style.color="#FF0000";
	}else{	
		document.getElementById("pro").style.color="#000";		
	}	
	
	
	if(error_string ==""){
		return true;
	}
	else{
		error_string = "Please double-check the following entries: \n" +error_string;
		alert(error_string);
		return false;
	}
}
	
	
	
function checkEmail(addy){

	var emailFilter = /^[a-z][\w\.]*@[\w\.]+\.[a-z]{2,3}/i;
	var illegalChars = /[\(\)\<\>\,\;\:\\\"[\]]/;
	
	
	if((addy == "") || (!(emailFilter.test(addy))) || (addy.match(illegalChars))){
		return true;
	}
}

function checkZip(zipcode){
	var i;
	var legalChars = "0123456789()-+ " 
	
	if((zipcode=="") || (!(zipcode.length<=10))|| (!(zipcode.length>=5))){
		return true;
	}
	
	for (i =0; i <= zipcode.length -1; i++) {
		if (legalChars.indexOf(zipcode.charAt(i)) == -1) {
		
		return true;
		}
	}
}
		
function checkPhone(numString){
	
	var i;
	var regex=/^s*\d{3}\s*?-?\d{4}$/;	
	var regexA=/^\(?\d{3}\)?-?\s*\d{3}\s*?-?\d{4}$/;

	
	if((!(regex.test(numString))) && (!(regexA.test(numString))) ){
		return true;
	}	
	
	
}



function isURL (url) {
 	 var urlPattern = /^(?:(?:ftp|https?):\/\/)?(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|coop|aero|[a-z][a-z])\b(?:\d+)?(?:\/[^;"'<>()\[\]{}\s\x7f-\xff]*(?:[.,?]+[^;"'<>()\[\]{}\s\x7f-\xff]+)*)?/i;

	 if (!(urlPattern.test(url))){
		 return true;
	 }
}

