/***********************************************************************

	External JavaScript Utility for common functionality to be
	included on all pages on the site.

***********************************************************************/


// preload images
if(document.images) {
var imgDir = "/psychsource/images/";

	navOn = new Image;
	navOn.src = imgDir + "leftnav_arrow_selected.gif";
	navOff = new Image;
	navOff.src = imgDir + "leftnav_arrow_white.gif";

	contactus1 = new Image;
	contactus1.src = imgDir + "contactus_on.gif";
	aboutus1 = new Image;
	aboutus1.src = imgDir + "aboutus_on.gif";
	azsites1 = new Image;
	azsites1.src = imgDir + "azsites_on.gif";
	sitemap1 = new Image;
	sitemap1.src = imgDir + "sitemap_on.gif";

	contactus0 = new Image;
	contactus0.src = imgDir + "contactus.gif";
	aboutus0 = new Image;
	aboutus0.src = imgDir + "aboutus.gif";
	azsites0 = new Image;
	azsites0.src = imgDir + "azsites.gif";
	sitemap0 = new Image;
	sitemap0.src = imgDir + "sitemap.gif";
}

// rollover function
function swap(x,y) {
	if(document.images)
		document.images[x].src = eval(y + ".src");
}


// left Nav Rollover 
function leftNavRoll(el, imgEl) {
//alert(document.getElementById(el).style.backgroundColor);
/*
	
	if (document.all) {
		if(document.all[el].style.backgroundColor != "#C2C2E0") {
			document.all[el].style.backgroundColor = "#C2C2E0";
			//document.images[imgEl].src = "images/leftnav_arrow_white.gif";
		}
		else {
			document.all[el].style.backgroundColor = "transparent";
			//document.images[imgEl].src = "images/leftnav_arrow_selected.gif";
		}
	}

	 else if (document.getElementById) {
		var elColor = document.getElementById(el).style.backgroundColor;
*/
		
		if((document.getElementById(el).style.backgroundColor != "#C2C2E0")) {
			document.getElementById(el).style.backgroundColor = "transparent";
			//document.images[imgEl].src = "images/leftnav_arrow_white.gif";
//			(document.getElementById(el).style.backgroundColor == null) || 
		}
		else {
			document.getElementById(el).style.backgroundColor = "#C2C2E0";
			document.images[imgEl].src = imgDir + "leftnav_arrow_selected.gif";
		}
//	}
}

function leavingSite() {
	var msg = "You are now leaving www.mingtaotaichi.com";
	if (confirm(msg)) 
		return true;
	else
		return false;
}

function newWin(url,w,h,t) {
		var theTarget;
		if(t) {
			theTarget = t;
		}
		else {
			theTarget = "win";
		}
		objNewWin = window.open("",t,'status=1,scrollbars=1,resizable=1,width=' + w + ',height=' + h);
        objNewWin.location = url;
        objNewWin.focus();
}

function displayWindow(url, width, height) {
	if (!window.Win || Win.closed)
	    var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=1,toolbar=yes' );
	else
		Win.location = url;
		Win.focus();
}


function addBookmark(addUrl, addName) {
myUserAgent = navigator.userAgent.toLowerCase();
	if (myUserAgent.indexOf("msie") != -1) {
		var addName = "PsychiatrySource.com - " + addName;
		window.external.AddFavorite(addUrl, addName);
	}
	else {
		alert ('If you are using Netscape or Mozilla, you can press CTRL+D on your keyboard to bookmark this site.')	
	}
}

function whichSearch(frm) {
	var theForm = document.forms[0];
	var appDir = "/psychsource/";
	
	if (frm == "drug") {
		if(theForm.txtDrugSearch.value == "") {
			alert("Please enter a Drug Name.");
			theForm.txtDrugSearch.focus();
			return false;
		}

		//theForm.action = "/psychsource/test/DrugInteractionsPopup.aspx";
		//theForm.target = "win";
		//onSubmit = newWin("","550","400");		
		theForm.action = appDir + "DesktopDefault.html?tabid=47&tabindex=8";

		theForm.submit();
	}

	else if(frm == "psych") {
		if(theForm.txtPsychSearch.value == "") {
			alert("Please enter a Search Term.");
			theForm.txtPsychSearch.focus();
			return false;
		}
		theForm.action = appDir + "DesktopDefault.html?tabid=44&tabindex=6";
		theForm.submit();
		//return true;
	}
}

// links back to the window that opened the current window.
function linkToOpener(url) {
	window.opener.location = url;
	window.opener.focus();
}

function validateForms(frm) {
	var myForm = document.forms[0];
	// contact us
	if(frm == "contact") {
		if(myForm.txtName.value == "") {
			alert("Please enter Your Name...");
			myForm.txtName.focus();
			return false;
		}
		if(myForm.txtEmail.value == "") {
			alert("Please enter Your E-Mail Address...");
			myForm.txtEmail.focus();
			return false;
		}
		if(myForm.txtMessage.value == "") {
			alert("Please enter a Message...");
			myForm.txtMessage.focus();
			return false;
		}
	}
	myForm.submit();
}

/*
	Added by Jigar for common TabSearch
*/
function tabSearch(term,tab,appDir) {
	var theForm = document.forms[0];
	if(term == "") {
		alert("Please enter a Search Term.");
		return false;
	}
	var searchterm = URLEncode(term);
	location = appDir + "/default.aspx?tabid=227&cat=" + tab + "&searchterm=" + searchterm;
}

function enterEvent(term,tab,appDir,objEvent) { 
    if ((objEvent.which && objEvent.which == 13) || (objEvent.keyCode && objEvent.keyCode == 13)) {
		tabSearch(term,tab,appDir);
		return false;
    } else return true;
} 

function displayInfo() {
	alert("References to \"AstraZeneca\", \"Group\", \"we\", \"us\" and \"our\" \nare references to AstraZeneca PLC and its affiliates.  \nYou can contact AstraZeneca by sending an e-mail to [insert e-mail contact address].");
}

function URLEncode(plaintext )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    /*
			    alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +
				        "(URL encoding only supports 8-bit characters.)\n" +
						"A space (+) will be substituted." );
				*/
				encoded += "+";
				
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function isHealthCareProfessionalMsg() {
msg = "PsychiatrySource.com contains information and tools prepared strictly for health professionals.";
msg += "The information on this website is not intended as a substitute for medical advice.\n\n\n";
msg += "Please visit 'http://www.patienthealthinternational.com/' for patient information.";

alert(msg);
/*	if (confirm(msg)) 
		return true;
	else
		return false;
*/
}

