/*
* 02/24/2003
* version: 1.1
*
* global.js - Common script used throughout the website
*/

var arrDynamicDivs = new Array();

/* ------------------------ User Agent Environment ----------------------------*/

var uAgent=navigator.userAgent.toLowerCase(); // convert all characters to lowercase to simplify testing
var uaOS = getUaOS();  // user agent OS
var uaMajVer; // major version of the user agent (e.g.- 5.0)
var uaMinVer; // minor version of the user agent
var isNav;  // boolean if user agent is navigator
var isNav3;
var isNav4; // is navigator 4
var isNav4up; // if navigator above 4
var isNavonly;
var isNav5;
var isNav5up;
var isNav4PC;
var isNS;
var isNS4;
var isIE;
var isIE5;
var isIE5_5;
var isIE6;
var isIE4PC;
var isStd;
var myUA = getUA();

/* -------------------------------Begin MacroMedia Dreamweaver functions------------------------------- */
MM_reloadPage(true); // invokes MacroMedia Dreamweaver function

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
/* ------------------------------- elijournals functions -------------------------------- */

/* THIS FUNCTION HAS NOT BEEN TESTED */
function isEmail(sEmail) {
  	var regEmail = /^([\w-]+\.?)*\w+@([\da-zA-z-]+\.)+[a-zA-z]{2,6}$/;
  	return regEmail.text(sEmail);
}

/* THIS FUNCTION HAS NOT BEEN TESTED */
/* NOTE: use of this function requires: the following form attributes:
 * 	<form name="mailform" id="mailform" onSubmit="return ValidateForm()" ...>
 * Also, note the name of the input tag needs to be 'email'.
 */
function ValidateForm() {
	var bValid = true;
	var sNoEmail = "You must include a valid Email address.";
	
	if(!isEmail(window.document.mailform.email.value)) {
		alert(sNoEmail);
		bValid = false;
		window.document.mailform.email.focus();
	}
	return bValid;
}

/* ------------------------------- Home Grown functions -------------------------------- */

function testEmail(str,sFormField) {
	if(sFormField == '') { sFormField = "document.contact_form.email"; } // example
	objFormField = eval(sFormField);
	
	if(str == '') { 
		alert("Your email address cannot be left blank.");
		objFormField.focus();
	} else if(str.search(/^.+@.+\..+/) == -1) {
		alert("Please enter a valid email address.");
		objFormField.focus();
	}
}

function WinOpen(FileName,sbVis) {
  	if(sbVis == null) {  sbVis = "yes"; }
    var myWin = open(FileName,"stdWin","width=640,height=480,toolbar=no,status=no,menubar=no,location=no,scrollbars="+sbVis+",resizable=1");
    myWin.focus();
}

function WinOpenMedium(FileName,sbVis) {
  	if(sbVis == null) {  sbVis = "yes"; }
    var myWin = open(FileName,"medWin","width=480,height=400,toolbar=no,status=no,menubar=no,location=no,scrollbars="+sbVis+",resizable=1");
    myWin.focus();
}

function WinOpenSmall(FileName,sbVis) {
  	if(sbVis == null) {  sbVis = "yes"; }
    var myWin = open(FileName,"smWin","width=320,height=240,toolbar=no,status=no,menubar=no,location=no,scrollbars="+sbVis+",resizable=1");
    myWin.focus();
}

function WinOpenSpecial(FileName,width,height,sbVis) {
  	if(sbVis == null) {  sbVis = "yes"; }
    var myWin = open(FileName,"spWin","width="+width+",height="+height+",toolbar=no,status=no,menubar=no,location=no,scrollbars="+sbVis+",resizable=1");
    myWin.focus();
}

/** adds the name of the div to the array of arrDynamicDivs
  *   - e: the event
  *   - whichMenu: the name of the div container for the menu
  */
function addDynamicDiv(menuName) {
  if(isIE5) { arrDynamicDivs[arrDynamicDivs.length] = menuName;
  } else { arrDynamicDivs.push(menuName); }
}

/** restores contentDiv
 *   - e: the event
 *   - whichMenu: the name of the div container for the menu
  */
function enlargeContentDiv(e,menuName){
  var menuObj = getDivObj(menuName);
  shrinkAllDivs();

  if (isNav4) { // NS 4
    menuObj.visibility="show"; 
  } else if(document.getElementById) { // Standards compliant && IE
    menuObj.style.display="block"; 
  } else { alert("Unsupported Browser"); } // Sorry Charlie!

}

/** Returns a div object; containerName is optional for all but NS4
  *  -divName = name of the div object
  *  -containerName = name of the container div relative to the root document object
  */
function getDivObj(divName,containerName){
  var divObj;
  if(isNav4) { // NS4
    if(containerName) {
        divObj = eval('document.' + containerName + '.document.' + divName);
     } else { divObj = eval('document.' + divName); }
     return(divObj);
  } else if(document.getElementById) { // Standards compliant
    return (document.getElementById(divName));
  }
  return (new Object());
}

/** Returns a text representation of major browsers
  */
function getUA() {
  setUaVar();
  if(isStd) { return("Standards Compliant"); }
  else if(isIE5) { return("Internet Explorer 5.0"); }
  else if(isIE5_5) { return("Internet Explorer 5.5"); }
  else if(isIE6) { return("Internet Explorer 6.0"); }
  else if(isNS4) { return("Netscape 4.x"); }
  else { return("Not a Major Browser"); }
  return("getUA(): Error in function");
}

/** Returns the OS of the user agent
  */
function getUaOS() {
  var uaOS = "unknown";

  if(uAgent.indexOf('linux') != -1) { uaOS = "Linux";
  } else if(uAgent.indexOf('win') != -1) {
    if(uAgent.indexOf('95') != -1) { uaOS = "Windows95";
    } else if(uAgent.indexOf('98') != -1) { uaOS = "Windows98";
    } else if(uAgent.indexOf('nt') != -1) { uaOS = "Windows NT, Windows 2000, or XP";
    } else { uaOS = "Windows"; }
  } else if(uAgent.indexOf('mac') != -1) { uaOS = "Macintosh";
  } else { uaOS = "other"; }

  return(uaOS);
}

/** Hides all dynamic DIVs in the array of arrDynamicDivs
  */
function hideAllDivs(){
  var i,j,found;
  for(i=0;i<arrDynamicDivs.length;i++) {
    menuObj = getDivObj(arrDynamicDivs[i]); // Convert string name to a div object
    if(isNav4) { // NS4
      menuObj.visibility="hide";
    } else if(document.getElementById) { // Standards compliant
      menuObj.style.visibility="hidden";
    }  else { alert("Unsupported Browser"); } // Let'm have it!
  }
  return true;
}

/** Displays alert box with approved legal language so user is aware they are
  * leaving the site
  */
function lvSiteMsg() {
		var msg;
		
		msg = "The link you have selected will take you outside of the secure ";
		msg += "Roche Diagnostics MyLabOnline web site.  Roche Diagnostics is ";
		msg += "not responsible for the information you are about to view.  ";
		msg += "Roche Diagnostics may provide financial support to organizations ";
		msg += "or websites to which the Roche Diagnostics website provides links.";
		
		alert(msg);
		return true;
}

/** Identifies the user agent and sets the global user agent variables
  */
function setUaVar () {
// note: on IE5, these return 4, so use isIE5up to detect IE5.
  uaMajVer = parseInt(navigator.appVersion);
  uaMinVer = parseFloat(navigator.appVersion);
  isNav  = ((uAgent.indexOf('mozilla')!=-1)
              && (uAgent.indexOf('spoofer')==-1)
              && (uAgent.indexOf('compatible') == -1)
              && (uAgent.indexOf('opera')==-1)
              && (uAgent.indexOf('webtv')==-1));
  isNav4 = (isNav && (uaMajVer == 4));
  isNav4up = (isNav && (uaMajVer >= 4));
  isNavonly = (isNav && ((uAgent.indexOf(";nav") != -1) ||
                        (uAgent.indexOf("; nav") != -1)) );
  isNav5 = (isNav && (uaMajVer == 5));
  isNav5up = (isNav && (uaMajVer >= 5));
  isNS = (navigator.appName == "Netscape");
  isNS4 = (isNS && isNav4);
  isIE   = (uAgent.indexOf("msie") != -1);
  isIE5  = (isIE && (uaMajVer == 4) && (uAgent.indexOf("msie 5.0")!=-1) );
  isIE5_5  = (uAgent.indexOf("msie 5.5")!=-1);
  isIE6  = (uAgent.indexOf("msie 6.0")!=-1);
  isStd = (document.getElementById && !isIE);
  isIE4PC = (isIE && uaOS != "macintosh");
  isNav4PC = (isNav4 && uaOS != "macintosh");
}

/** shows contentDiv
 *   - e: the event
 *   - whichMenu: the name of the div container for the menu
  */
function showContentDiv(e,menuName){
  var menuObj = getDivObj(menuName);
  hideAllDivs();

  if (isNav4) { // NS 4
    menuObj.visibility="show"; 
  } else if(document.getElementById) { // Standards compliant && IE
    menuObj.style.visibility="visible"; 
  } else { alert("Unsupported Browser"); } // Sorry Charlie!

}

/** Shrinks and hides all dynamic DIVs in the array of arrDynamicDivs
  */
function shrinkAllDivs(){
  var i,j,found;
  for(i=0;i<arrDynamicDivs.length;i++) {
    menuObj = getDivObj(arrDynamicDivs[i]); // Convert string name to a div object
    if(isNav4) { // NS4
      menuObj.visibility="hide";
    } else if(document.getElementById) { // Standards compliant
      menuObj.style.display="none";
    }  else { alert("Unsupported Browser"); } // Let'm have it!
  }
  return true;
}
