/*==============================================================*/
/* gemScripts.js			                                  */
/*                                                              */
/* Copyright (c) 2008                                           */
/* Artificial Intelligence in Medicine Inc.                     */
/*                                                              */
/* generic javascript file which contains all the scripts for   */
/* the GEM project public site.					    */
/*--------------------------------------------------------------*/
/* Dependencies:                                                */
/*--------------------------------------------------------------*/
/*                                                              */
/* Rev#	Date		Author Comments                         */
/*--------------------------------------------------------------*/
/* 1    	2008-03-28  D.P.	 Original code                    */
/*==============================================================*/


/*==============================================================*/
/* setLang()			                                  */
/*                                                              */
/* Copyright (c) 2008                                           */
/* Artificial Intelligence in Medicine Inc.                     */
/*                                                              */
/* Simply modifies the current window's URL to set it to a new  */
/* 2 letter language code (either "en" or "fr")			    */
/*--------------------------------------------------------------*/
/* Dependencies:                                                */
/*--------------------------------------------------------------*/
/*                                                              */
/* Rev#	Date		Author Comments                         */
/*--------------------------------------------------------------*/
/* 1    	2008-03-28  D.P.	 Original code                    */
/*==============================================================*/
function setLang(langID) {
	 var theHref = window.location.href;
	 
	 // if there is already a lang= in the query string, remove it.
	 if(theHref.indexOf("lang=") >= 0) {
		   theHref = theHref.substring(0,theHref.indexOf("lang=")) + theHref.substring(theHref.indexOf("lang=") + 8);
	 }
	 
	 if(theHref.indexOf("?") >= 0) {
		if(theHref.indexOf("?") == (theHref.length - 1)) theHref += "lang="+langID;
		else theHref += "&lang="+langID;
	 }
	 else {
		theHref += "?lang="+langID;
	 }
	 window.location = theHref;
}

/*==============================================================*/
/* spamproofemail(user, host, ext)                              */
/*                                                              */
/* Copyright (c) 2008                                           */
/* Artificial Intelligence in Medicine Inc.                     */
/*                                                              */
/* Since webspiders can't interpret javascript (or at least, not*/
/* yet), this blocks a large majority of automated email gatherer*/
/* robots and spiders, that spammers use.  It builds an email   */
/* based on arguments, and document.writes them onto the page.   */
/* In the case of a compound extension (ie: ".on.ca", rather than */
/* ".com" submit the whole extension, but without the leading "." */
/*--------------------------------------------------------------*/
/* Dependencies:                                                */
/*--------------------------------------------------------------*/
/*                                                              */
/* Rev#	Date		Author Comments                         */
/*--------------------------------------------------------------*/
/* 1    	2008-03-28  D.P.	 Original code                    */
/*==============================================================*/
function spamproofemail(user, host, ext) {
	  var genericEmail = user + "&#64;" + host + "." + ext;
	  document.write("<a href=\"mailto:");
	  for (var y=0;y<genericEmail.length;y++) {
		document.write(genericEmail.charAt(y));
	  }
	  document.write("\">");
	  for (var y=0;y<genericEmail.length;y++) {
		document.write(genericEmail.charAt(y));
	  }
	  document.write("</a>");
}


function showDiv(e, divID) {
	  var posX = 0;
	  var posY = 0;
	  var windowHeight = 0;
	  var windowWidth = 0;
	  if(!e) var e = window.event;
	  
	  posX = e.clientX;
	  posY = e.clientY;
	  var theDiv = document.getElementById(divID);
	  if(theDiv.style.display == "none" || theDiv.style.display == "") {
		    theDiv.style.display = "block";
		    if(window.innerHeight) {
				windowHeight = window.innerHeight;
				windowWidth = window.innerWidth;
		    }
		    else {
				windowHeight = document.body.clientHeight;
				windowWidth = document.body.clientWidth;
		    }
		   
		    if((windowHeight - posY-15) < 70) {
				posY = posY - 100;
		    }
		    if((posX - 15 + theDiv.clientWidth) > windowWidth) {
				posX = windowWidth - theDiv.clientWidth;
		    }
		   
		    if((posY - 15 +theDiv.clientHeight) > windowHeight) {
				theDiv.style.top = (posY-45) + "px";
				theDiv.style.left = (posX-15) + "px";
				theDiv.style.height = windowHeight - (posY-15);
		    }
		    else {
				theDiv.style.top = (posY-15) + "px";
				theDiv.style.left = (posX-15) + "px";
		    }
		    
	  }
}

