/* function to add events */
function addEvent(obj, evType, fn){ 
	if (obj.addEventListener)	{ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	}	else if (obj.attachEvent)	{ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}	else{ 
		return false; 
	} 
}
function initVetLocator(){
	if(document.getElementById('zip_code')){
		var zip=document.getElementById('zip_code');
		addEvent(zip, 'click', function(){zip=document.getElementById('zip_code');if(zip.value=="Enter Zipcode")zip.value='';});
		addEvent(zip, 'change', function(){zip=document.getElementById('zip_code');if(zip.value=='')zip.value="Enter Zipcode";});
	}	
}
function vetLocatorCheck(){
		var zip = document.getElementById('zip_code').value;
		if(zip.length==5 && !isNaN(zip)){
			// document.getElementById('find_a_vet').target="VetLocatorWin";
			// window.open('','VetLocatorWin','width=800,height=600,scrollbars,resizable,status,toolbar,menubar').focus();
			return true;
		}
		else {
			alert('Please enter a five digit number for the zip code.')
			return false;
		}
}
// Make external links open in new windows
function externalLinks() {
	var anchors = document.getElementsByTagName("a");
	var i, href;
	for(i=0; i < anchors.length; i++){
		if(!anchors[i].href) continue;
		href = anchors[i].href;
		if(href.indexOf(location.host) == -1){ // Href is not a file on my server
			if(href.indexOf("javascript:") == -1){ // Href is not a javascript call
				if(!anchors[i].onclick){ // Href does not have an onclick event
					if(href.indexOf("mailto:") == -1){ // Href is not a mailto:
						if(href.indexOf("http://") != -1){ // Href is not relative (for Safari)
							anchors[i].setAttribute("target","_blank");
						}
					}
				}
			}
		}
	}
}
addEvent(window, 'load', externalLinks);
addEvent(window, 'load', initVetLocator);
