function initSubnav(){
	var subnav = document.getElementById('subnav');
	var subnavas = subnav.getElementsByTagName('a');
	for (var a=0; a<subnavas.length; a++){
		var currenthref=String(subnavas[a].href);
		var currentloc=String(document.location);
		if (unescape(currenthref)==unescape(currentloc)){
			subnavas[a].className="current"
		}
	}
}

function initLinks(){
	var hostname = window.location.hostname;
	hostname = hostname.replace("www.","").toLowerCase();
	var a = document.getElementsByTagName("a");	
	this.check = function(obj){
		var href = obj.href.toLowerCase();
		return (href.indexOf("http://")!=-1 && href.indexOf(hostname)==-1) ? true : false;				
	};
	this.set = function(obj){
		obj.target = "_blank";
		obj.className += " external";
		obj.title += "This link will open in a new window.";
	};
	for (var i=0;i<a.length;i++){
		if(check(a[i])) set(a[i]);
		if (a[i].className.indexOf("popproc") != -1) addAnEvent(a.item(i),'click',popproc);
		if (a[i].className.indexOf("popdoc") != -1) addAnEvent(a.item(i),'click',popdoc);
	};		
};

function popproc(){
    appWindow = window.open (this.href,"appWindow","width=420,height=326,toolbar=0,resizable=0,scrollbars=1");
    appWindow.focus ();
    return false;
}

function popdoc(){
    appWindow = window.open (this.href,"appWindow","width=620,height=426,toolbar=1,resizable=1,scrollbars=1");
    appWindow.focus ();
    return false;
}

function initButtons(){
	var inputs = document.getElementsByTagName("input");
	for (var i = 0; i<inputs.length; i++){
		if(inputs[i].type=="image"){
			addAnEvent(inputs.item(i),'mouseover',buttonHover);
			addAnEvent(inputs.item(i),'mouseout',buttonHoverout);
			inputs.item(i).style.borderWidth = "0px"
		}
		if(inputs[i].disabled == true){
			inputs[i].className = "disabled";
		}
	}
	
	var images = document.getElementsByTagName("img");
	for (var i = 0; i<images.length; i++){
		if(images[i].className=="button"){
			addAnEvent(images.item(i),'mouseover',buttonHover);
			addAnEvent(images.item(i),'mouseout',buttonHoverout);
		}
	}
}
function buttonHover(){
	if (this.src.indexOf("1") == -1){
		var file = this.src.split(".gif");
		this.src = file[0] + "1.gif";
	}
}
function buttonHoverout(){
	var file = this.src.split("1.gif");
	this.src = file[0] + ".gif";
}

function initPatientForm(){
	var a = document.getElementById("currpatient");
	addAnEvent(a,'click',togglePatientForm);
	togglePatientForm();
}

function togglePatientForm(){
	var a = document.getElementById("currpatient");
	var am = document.getElementById("newpatient");
	if (a.checked == false) {
		am.style.display = "none";
	}
	else {
		am.style.display = "block";
	}
}

function siteEmail(user){
	document.write("<a href=" + "mail" + "to:" + user + "@dryankie.com>" + user + "@dryankie.com</a>")
}

function addAnEvent(target, eventName, functionName){
	eval('target.on'+eventName+'=functionName');
}

function initPage(){
	if (document.getElementById){
		if (document.getElementById("subnav")) initSubnav();
		initLinks();
		initButtons();
		if (document.getElementById("newpatient")) {initPatientForm();}
	}
}

window.onload=initPage;
