
// JavaScript functions to show/hide information

function showInfo(choice){
	document.getElementById(choice).style.visibility="visible";
}

function hideInfo(choice){
	document.getElementById(choice).style.visibility="hidden";

}

var maxamt = 9999.00;
var minamt = 25.00;
function ChkAmt (obj1) {  // check any qty limits on items
var amt;
  amt = obj1.amount.value;
  if (isNaN (amt)) {
    alert ("Please enter a number equal to or greater than 25.");
    ClrAmt ();            // always clear the values!
    return false;
  }

//  if (amt > maxamt) {
//    alert ("You cannot order more than " + maxqty + " items!");
//    ClrQty ();
//    return false;
//  }

  if (amt < minamt) {
    alert ("Please fill in at least $" + minamt + "!");
    ClrAmt ();
    return false;
  }
  ClrAmt ();
  return true;
}

function ClrAmt () {  // Clear out the limits
  maxamt = 9999.00;  //not used unless you want to set some max amount.
  minamt = 25.00;   //set the minimum amount for a donation
}

function Dollar (val) {     // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");  // should be one, but OK if not
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;               // return valid string
}


/*

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;
	 }
}

function MonthTxt (MonthNumber){
		var Month = new Array();
		Month[1] = "January";
		Month[2] = "February";
		Month[3] = "March";
		Month[4] = "April";
		Month[5] = "May";
		Month[6] = "June";
		Month[7] = "July";
		Month[8] = "August";
		Month[9] = "September";
		Month[10] = "October";
		Month[11] = "November";
		Month[12] = "December";
	return Month[MonthNumber];
	}

function WeekDayTxt (DayNumber){
	var dayName = new Array
	dayName[0] = "Sunday";
	dayName[1] = "Monday";
	dayName[2] = "Tuesday";
	dayName[3] = "Wednesday";
	dayName[4] = "Thursday";
	dayName[5] = "Friday";
	dayName[6] = "Saturday";
	return dayName[DayNumber];
	}