String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function CountryChosen() {
	box = document.forms[0].country;
	destination = box.options[box.selectedIndex].value;
	state = document.forms[0].stateProvince;
	destinationstate = state.options[state.selectedIndex].value;
	error = false;
	msg = '';
	if (destination == 'US' && destinationstate == 'null'){
		msg = 'Please choose a state before searching the US.\n';	
	}
	if (destination == 'CA' && destinationstate == 'null'){
		msg = 'Please choose a province before searching Canada.\n';	
	}
	city = document.forms[0].cityText.value;
	if(!city){
		msg =  msg + 'Please choose a city.';		
	}
	if(msg){
		alert(msg);
		return false;
	}
}

function checkforadults() {
	adults = document.forms[0].adults;
	adultsvalue = adults.options[adults.selectedIndex].value;
	seniors = document.forms[0].seniors;
	seniorsvalue = seniors.options[seniors.selectedIndex].value;
	if(adultsvalue == 0 && seniorsvalue == 0){
		alert('There must be at least one adult or senior selected.');
		return false;
	}
}

function noAmenities(){	
	var form = document.forms[0];
	var total = 0;
	var max = form.amenity.length;
	if (eval("form.noamenities.checked") == true){
		for (var idx = 0; idx < max; idx++) {
			form.amenity[idx].checked = false;
		}
	}
}

function amenitiescheckbox(){
	var form = document.forms[0];
	var total = 0;
	var max = form.amenity.length;
	form.noamenities.checked = false;
	for (var idx = 0; idx < max; idx++) {		
		if (eval("form.amenity[" + idx + "].checked") == true && form.amenity[idx].value != 0) {
			if(total == 3){
				return false;
			}
			total += 1;					
	    }		
	} 
}



function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href")){
		var thisurl = anchor.getAttribute("href");
		if(thisurl.search("pettravelcenter") == -1 && thisurl.search("http") != -1){
			anchor.target = "_blank";
		}
		if(thisurl.search("pettravelcenter") == 1 && thisurl.search("https") == 1){
			thisurl.replace('https','http');
		}
	}
  }
  
  
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//--><!]]>

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "-";
var minyear=1800;
var maxyear=2200;

function clearBox(thefield){
   if (thefield.defaultValue==thefield.value)
   thefield.value = ""
}
  

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
		return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm-dd-yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(strYear)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || strYear==0 || strYear<minyear || strYear>maxyear){
		//alert("Please enter a valid 4 digit year between "+minyear+" and "+maxyear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}

function validate_form (form)
{
    valid = true;
	var alertmsg = "";
    //form.other.label = "test";
	phoneRegex = /^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/;
	if ( form.title && form.title.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Name of Event' field." );
    	valid = false;
    }
	if ( form.cphone && (form.cphone.value == "" || phoneRegex.test(form.cphone.value) != true))
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Contact Phone' field with a valid phone number." );
    	valid = false;
    }
	if ( form.phone && (form.phone.value == "" || phoneRegex.test(form.phone.value) != true))
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Phone' field with a valid phone number." );
    	valid = false;
    }
    if ( form.bname && form.bname.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Business Name' field." );
        valid = false;
    }
	 if ( form.dob && (form.dob.value != "" && isDate(form.dob.value)==false) )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Birthday' field in the format mm-dd-YYYY." );
        valid = false;
    }
    if ( form.startdate && (form.startdate.value == "" || isDate(form.startdate.value)==false))
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Start Date' field with the format MM-DD-YYYY." );
        valid = false;
    }
    if ( form.enddate && (form.enddate.value == "" || isDate(form.enddate.value)==false))
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'End Date' field with the format MM-DD-YYYY." );
        valid = false;
    }
    if ( form.petbio && form.petbio.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Pet Bio' field." );
        valid = false;
    }
    if ( form.phone1 && !form.dogPark.checked && (form.phone1.value == "" || phoneRegex.test(form.phone1.value) != true))
    {
		alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Business Phone (primary)' field with a valid phone number." );
        valid = false;
    }
    if ( form.fname && form.fname.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'First Name' field." );
        valid = false;
    }
    if ( form.lname && form.lname.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Last Name' field." );
        valid = false;
    }
	if ( form.name && form.name.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Name' field." );
        valid = false;
    }
	if ( form.zip && form.zip.value == "" && ((location.href).search("checkout")) != -1)
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Zip' field." );
        valid = false;
    }
	if ( form.address1 && form.address1.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Street (line 1)' field." );
        valid = false;
    }
    if ( form.petname && form.petname.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Pet's Name' field." );
        valid = false;
    }
    if ( form.userfile && form.userfile.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please choose a file to upload." );
        valid = false;
    }
    if ( form.bemail && form.confirmbemail && form.bemail.value != "" && form.bemail.value != form.confirmbemail.value)
    {
        alertmsg = alertmsg + "\n" +  ( "The business email address and the confirm business email address must match.  Please enter the same address in both fields." );
        valid = false;
    } 
    if ( form.cemail && form.cemail.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Contact Email' field." );
        valid = false;
    } 
	
    if ( form.cemail && form.confirmemail && form.cemail.value != "" && form.cemail.value != form.confirmemail.value)
    {
        alertmsg = alertmsg + "\n" +  ( "The email address and the confirm email address must match.  Please enter the same address in both fields." );
        valid = false;
    } 
    if ( form.email && form.email.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Email' field." );
        valid = false;
    } 
    if ( form.email && form.confirmemail && form.email.value != "" && form.email.value != form.confirmemail.value)
    {
        alertmsg = alertmsg + "\n" +  ( "The email address and the confirm email address must match.  Please enter the same address in both fields." );
        valid = false;
    } 

    if ( form.dcsc && form.dcsc.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Departure City, State/Province, Country' field." );
        valid = false;
    }
    if ( form.acsc && form.acsc.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Arrival City, State/Province, Country' field." );
        valid = false;
    }
    if ( form.movedata && form.movedate.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Estimated Move Date' field." );
        valid = false;
    }
    if ( form.reason && form.reason.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Reason For Relocation' field." );
        valid = false;
    }
    if ( form.pets && form.pets.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Your Pets' field." );
        valid = false;
    }



    if ( form.question && form.question.value.trim() == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Question' field." );
        valid = false;
    }
    if ( form.comments && form.comments.value == "" && (location.href.search("community_calendar")) == -1)
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Details' field." );
        valid = false;
    }
	
	if ( form.shipname && form.shipname.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping Name' field." );
        valid = false;
    }
	if ( form.shipzip && form.shipzip.value == "" )

    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping Zip' field." );
        valid = false;
    }
	if ( form.shipaddress1 && form.shipaddress1.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping Street (line 1)' field." );
        valid = false;
    }
	if ( form.shipcity && form.shipcity.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping City' field." );
        valid = false;
    }
	if ( form.shipstate && form.shipstate.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping State' field." );
        valid = false;
    }
	if ( form.shipphone && (form.shipphone.value == "" || phoneRegex.test(form.shipphone.value) != true))
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping Phone' field with a valid phone number." );
    	valid = false;
    }
	if ( form.cardname && form.cardname.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Name on Card' field." );
    	valid = false;
    }
	if ( form.cardnum && form.cardnum.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Card Number' field." );
    	valid = false;
    }
	if ( form.secode && form.secode.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Card Security Code' field." );
    	valid = false;
    }
	if ( form.expy && form.expy.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Expiration Year' field." );
    	valid = false;
    }
	
	if ( form.label && form.label.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Ad Label' field." );
    	valid = false;
    }
	if ( form.captcha_text && form.captcha_text.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Image Text' field." );
    	valid = false;
    }
	if ( form.url && form.url.value == "" && location.href.search("ad") != -1)
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Ad Website (URL)' field." );
    	valid = false;
    }


	
	
	if(valid == false){
		alert(alertmsg);
	}
    return valid;
}

function validate_form_country_chosen (form)
{
    valid = true;
	var alertmsg = "";
    //form.other.label = "test";
	phoneRegex = /^((\+[1-9]{1,4}[ \-]*)|(\([0-9]{2,3}\)[ \-]*)|([0-9]{2,4})[ \-]*)*?[0-9]{3,4}?[ \-]*[0-9]{3,4}?$/;
	if ( form.title && form.title.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Name of Event' field." );
    	valid = false;
    }
	if ( form.cphone && (form.cphone.value == "" || phoneRegex.test(form.cphone.value) != true))
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Contact Phone' field with a valid phone number." );
    	valid = false;
    }
	if ( form.phone && (form.phone.value == "" || phoneRegex.test(form.phone.value) != true))
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Phone' field with a valid phone number." );
    	valid = false;
    }
    if ( form.bname && form.bname.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Business Name' field." );
        valid = false;
    }
	 if ( form.dob && (form.dob.value != "" && isDate(form.dob.value)==false) )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Birthday' field in the format mm-dd-YYYY." );
        valid = false;
    }
    if ( form.startdate && (form.startdate.value == "" || isDate(form.startdate.value)==false))
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Start Date' field with the format MM-DD-YYYY." );
        valid = false;
    }
    if ( form.enddate && (form.enddate.value == "" || isDate(form.enddate.value)==false))
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'End Date' field with the format MM-DD-YYYY." );
        valid = false;
    }
    if ( form.petbio && form.petbio.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Pet Bio' field." );
        valid = false;
    }
    if ( form.phone1 && !form.dogPark.checked && (form.phone1.value == "" || phoneRegex.test(form.phone1.value) != true))
    {
		alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Business Phone (primary)' field with a valid phone number." );
        valid = false;
    }
    if ( form.fname && form.fname.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'First Name' field." );
        valid = false;
    }
    if ( form.lname && form.lname.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Last Name' field." );
        valid = false;
    }
	if ( form.name && form.name.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Name' field." );
        valid = false;
    }
	if ( form.zip && form.zip.value == "" && ((location.href).search("checkout")) != -1)
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Zip' field." );
        valid = false;
    }
	if ( form.address1 && form.address1.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Street (line 1)' field." );
        valid = false;
    }
	if ( form.lname && form.lname.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Last Name' field." );
        valid = false;
    }
    if ( form.petname && form.petname.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Pet's Name' field." );
        valid = false;
    }
    if ( form.userfile && form.userfile.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please choose a file to upload." );
        valid = false;
    }
    if ( form.bemail && form.confirmbemail && form.bemail.value != "" && form.bemail.value != form.confirmbemail.value)
    {
        alertmsg = alertmsg + "\n" +  ( "The business email address and the confirm business email address must match.  Please enter the same address in both fields." );
        valid = false;
    } 
    if ( form.cemail && form.cemail.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Contact Email' field." );
        valid = false;
    } 
	
    if ( form.cemail && form.confirmemail && form.cemail.value != "" && form.cemail.value != form.confirmemail.value)
    {
        alertmsg = alertmsg + "\n" +  ( "The email address and the confirm email address must match.  Please enter the same address in both fields." );
        valid = false;
    } 
    if ( form.email && form.email.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Email' field." );
        valid = false;
    } 
    if ( form.email && form.confirmemail && form.email.value != "" && form.email.value != form.confirmemail.value)
    {
        alertmsg = alertmsg + "\n" +  ( "The email address and the confirm email address must match.  Please enter the same address in both fields." );
        valid = false;
    } 
    if ( form.question && form.question.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Question' field." );
        valid = false;
    }
    if ( form.comments && form.comments.value == "" && (location.href.search("community_calendar")) == -1)
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Details' field." );
        valid = false;
    }
	
	if ( form.shipname && form.shipname.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping Name' field." );
        valid = false;
    }
	if ( form.shipzip && form.shipzip.value == "" )

    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping Zip' field." );
        valid = false;
    }
	if ( form.shipaddress1 && form.shipaddress1.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping Street (line 1)' field." );
        valid = false;
    }
	if ( form.shipcity && form.shipcity.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping City' field." );
        valid = false;
    }
	if ( form.shipstate && form.shipstate.value == "" )
    {
        alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping State' field." );
        valid = false;
    }
	if ( form.shipphone && (form.shipphone.value == "" || phoneRegex.test(form.shipphone.value) != true))
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Shipping Phone' field with a valid phone number." );
    	valid = false;
    }
	if ( form.cardname && form.cardname.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Name on Card' field." );
    	valid = false;
    }
	if ( form.cardnum && form.cardnum.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Card Number' field." );
    	valid = false;
    }
	if ( form.secode && form.secode.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Card Security Code' field." );
    	valid = false;
    }
	if ( form.expy && form.expy.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Expiration Year' field." );
    	valid = false;
    }
	
	if ( form.label && form.label.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Ad Label' field." );
    	valid = false;
    }
	if ( form.captcha_text && form.captcha_text.value == "")
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Image Text' field." );
    	valid = false;
    }
	if ( form.url && form.url.value == "" && location.href.search("ad") != -1)
    {
    	alertmsg = alertmsg + "\n" +  ( "Please fill in the 'Ad Website (URL)' field." );
    	valid = false;
    }
	
	box = document.getElementById('country');
	if(!box.selectedIndex){
		box.selectedIndex = 0;
		destination = 'US';
	} else {
		destination = box.options[box.selectedIndex].value;		
	}
	state = form.state;
	destinationstate = state.options[state.selectedIndex].value;
	if (destination == 'US' && (destinationstate == 'null' || !destinationstate)){
		alertmsg = alertmsg + '\nPlease choose a state for addresses in the US.';
		valid = false;
	}
	if (destination == 'CA' && (destinationstate == 'null' || !destinationstate)){
		alertmsg = alertmsg +  '\nPlease choose a province for addresses in Canada.';	
		valid = false;
	}
	if (destination == 'AU' && (destinationstate == 'null' || !destinationstate)){
		alertmsg = alertmsg +  '\nPlease choose a province for addresses in Australia.';	
		valid = false;
	}
	city = form.city;
	if(!city){
		alertmsg =  alertmsg + '\nPlease fill in the \'City\' field.';		
		valid = false;
	}
	if(form.iagree && form.iagree.checked == false){
		valid = false;
		alertmsg = alertmsg + '\nYou must agree to the policy and terms.';
	}
	if(form.iagree2 && form.iagree2.checked == false){
		valid = false;
		alertmsg = alertmsg + '\nYou must agree to the reservation change conditions.';
	}
	if(valid == false){
		alert(alertmsg);
	}
    return valid;
}
