/*
** Configurable Directives
*/
var scripts = new Array('layerMaker', 'swfobject', 'expander', 'didYouKnow', 'textSizer', 'utilities');



/*
** Script Auto-loader, takes array of filenames
*/
var pathToRoot;
function dynLoadScript(scriptArr) {
	// Find the relative path to our javascript includes
	handler = document.getElementsByTagName("head")[0].getElementsByTagName("script");
	for(var x=0; x<handler.length; x++) {


	   // if(handler[x].getAttribute("src").match(/functions.js/)) {
		//    scriptPrefix = handler[x].getAttribute("src").replace(/functions.js/, "");
		//    pathToRoot = scriptPrefix.replace(/javascript/, "").replace(/\/\//, "/");
		//    if(pathToRoot == "/") {
		//	    pathToRoot = "";
		//    }
	   // }
	    
	}	
	var a = new Array();
	for(var x=0; x<scriptArr.length; x++) {
		// safari fails on dynamic loading, brute force
		//document.write('<script type="text/javascript" src="'+scriptPrefix+scriptArr[x]+'.js"></script>');
	}
	return false;
}
dynLoadScript(scripts);

function setAction() {
}
/*
** Basic site-wide and site-specific functionality
*/
function initSite() {
	// Loading external file functions first
	initUtilitiesArea();
	validateForm.prep();	
	layerMaker.init();
	//didYouKnow.init();

	setTimeout("", 2000);
	if(getCookie('sentThisPage') == "yes") {
		layerMaker.activate('Email This Page Confirmation', '');
		document.cookie = "sentThisPage=no";
	}
	if(getCookie('isHCP') == "yes") {
		layerSets['HCP Disclaimer']['isActive'] == false;
	}
}




function initUtilitiesArea() {
	if(document.getElementById('utilityLinksx')) {
		parentObj = document.getElementById('utilityLinks');
		//parentObj.getElementsByTagName("a")[0].onclick = function() { layerMaker.activate('Email This Page', this); return false; };
	}
	return false;
}

function submitEmailThisPage() {
	document.getElementById('emailThisPageSuccess').value = window.location.href;
	if(validateForm.initEmail(document.forms[document.forms.length-1])) {
		document.forms[document.forms.length-1].submit();
	} else {
		return false;
	}
}

function addFriendInput() {
	// Find relative path depth to determine location of images folder
	pathDepth = 0;
	hcpSide = false;
	var strHref = window.location.href;
	var handler = strHref.split('/');
	for(var i=0; i<handler.length; i++) {
		if(handler[i] == "info") {
			pathDepth = 1;
		}
		if(handler[i] == "about_azor" || handler[i] == "managing_hypertension" || handler[i] == "patient_resources" || handler[i] == "utilities" || handler[i] == "professional_resources") {
			pathDepth = 2;
		}
		if(handler[i] == "hcp") {
			hcpSide = true;
		}
	}
	if(hcpSide == true) {
		pathDepth++;
	}
	
	// Determine how many friend inputs currently exist
	counter = 1;
	for(var x=0; x<counter; x++) {
		if(document.getElementById('recipient'+counter)) {
			counter++;
		}
	}
	
	// If friend inputs number less than our limit AND first friend email is not blank, construct new input field
	if(counter <= 5) {
		if(counter == 5) {
			document.getElementById('addMoreFriendLink').style.display = "none";
		}
		document.getElementById('recipient1').innerHTML = "* Recipient's e-mail address 1";
		myDiv = document.getElementById('extraEmailInputs');
		
		var objFormListArea = document.createElement("div");
		myDiv.appendChild(objFormListArea);
		
		var objInputLabel = document.createElement("span");
		objInputLabel.setAttribute('id', 'recipient'+counter);
		objInputLabel.innerHTML = "&nbsp;&nbsp;Recipient's e-mail address "+counter;
		objFormListArea.appendChild(objInputLabel);
		
		var objInputArea = document.createElement("input");
		objInputArea.setAttribute('type', 'test');
		objInputArea.setAttribute('id', 'toAddress'+counter);
		objInputArea.setAttribute('name', 'toAddress');
		objFormListArea.appendChild(objInputArea);
		
		document.getElementById("extraEmailInputs").style.display = "block";
		var clearBothDiv = document.createElement("div");
		clearBothDiv.style.clear = "both";
		myDiv.appendChild(clearBothDiv);
	}
}


// Mozilla and Opera
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", initSite, false);
} else {
	if(window.onload) {
		oldOnloader = window.onload;
		window.onload = function() { oldOnloader(); window.onload; return false; };
	} else {
		window.onload = function() { initSite(); return false; };
	}
}

