/*

BROWSER DETECTION

*/


/******
FUNCTION BrowserDetector()
ARGUMENTS: none
RETURNS: none

This function actually defines a new class (of type BroswerDetector)
whose members contain information about the user's browser, including:
-browser
-platform
-full version
-major version
-minor version

USAGE: var bd = new BrowserDetector();
*******/

function BrowserDetector() {

  var ua = navigator.userAgent;
  
  // Defaults
  this.browser = "Unknown";
  this.platform = "Unknown";
  this.version = "";
  this.majorver = "";
  this.minorver = "";

  uaLen = ua.length;

  // ##### Split into stuff before parens and stuff in parens
  var preparens = "";
  var parenthesized = "";

  i = ua.indexOf("(");
  if (i >= 0) {
    preparens = Trim(ua.substring(0,i));
        parenthesized = ua.substring(i+1, uaLen);
        j = parenthesized.indexOf(")");
        if (j >= 0) {
          parenthesized = parenthesized.substring(0, j);
        }
  }
  else {
    preparens = ua;
  }
  
  

  // ##### First assume browser and version are in preparens
  // ##### override later if we find them in the parenthesized stuff
  var browVer = preparens;

  var tokens = parenthesized.split(";");
  var token = "";
  
  // # Now go through parenthesized tokens
  for (var i=0; i < tokens.length; i++) {
    token = Trim(tokens[i]);
        //## compatible - might want to reset from Netscape
        if (token == "compatible") {
          //## One might want to reset browVer to a null string
          //## here, but instead, we'll assume that if we don't
          //## find out otherwise, then it really is Mozilla
          //## (or whatever showed up before the parens).
        //## browser - try for Opera or IE
    }
        else if (token.indexOf("MSIE") >= 0) {
      browVer = token;
    }
    else if (token.indexOf("Opera") >= 0) {
      browVer = token;
    }
        //'## platform - try for X11, SunOS, Win, Mac, PPC
    else if ((token.indexOf("X11") >= 0) || (token.indexOf("SunOS") >= 0) || (token.indexOf("Linux") >= 0)) {
      this.platform = "Unix";
    }
	
    else if (token.indexOf("Win") >= 0) {
      this.platform = token;
    }
	
    else if ((token.indexOf("Mac") >= 0) || (token.indexOf("PPC") >= 0) || (token.indexOf("Mac_PowerPC") >= 0)) {
      this.platform = token;
    }
  }

  var msieIndex = browVer.indexOf("MSIE");
  if (msieIndex >= 0) {
    browVer = browVer.substring(msieIndex, browVer.length);
  }

  var leftover = "";
  if (browVer.substring(0, "Mozilla".length) == "Mozilla") {
    this.browser = "Netscape";
    leftover = browVer.substring("Mozilla".length+1, browVer.length);
  }

  else if (browVer.substring(0, "Lynx".length) == "Lynx") {
    this.browser = "Lynx";
	leftover = browVer.substring("Lynx".length+1, browVer.length);
  }
  else if (browVer.substring(0, "MSIE".length) == "MSIE") {
    this.browser = "IE";
    leftover = browVer.substring("MSIE".length+1, browVer.length);
  }
  else if (browVer.substring(0, "Microsoft Internet Explorer".length) == "Microsoft Internet Explorer") {
    this.browser = "IE";
	leftover = browVer.substring("Microsoft Internet Explorer".length+1, browVer.length);
  }
  else if (browVer.substring(0, "Opera".length) == "Opera") {
    this.browser = "Opera"
    leftover = browVer.substring("Opera".length+1, browVer.length);
  }

  leftover = Trim(leftover);
  
  
  // # Try to get version info out of leftover stuff
  i = leftover.indexOf(" ");
  if (i >= 0) {
    this.version = leftover.substring(0, i);
  }
  else
  {
    this.version = leftover;
  }
  j = this.version.indexOf(".");
  if (j >= 0) {
    this.majorver = this.version.substring(0,j);
    this.minorver = this.version.substring(j+1, this.version.length);
  }
  else {
    this.majorver = this.version;
  }



}




/***************************************************************************

  ROLLOVER SCRIPTS

***************************************************************************/

// takes name of image, returns reference to that image
//  searches one layer deep
function getImageRef(index) {
	
	if (bd.browser=="Netscape") {
		var docRef = document;
		if (docRef.images[index] == null) {
			for(var i=0; i < document.layers.length; i++) {
				if (docRef.layers[i].document.images[index] != null) {
					docRef = docRef.layers[i].document;
					break;
				}
			}
			
		}
		
		return docRef.images[index];
		
	} else if (bd.browser=="IE") {
	  return document.images[index];	  
	}

}




function secRollover(imageRef){
  if (loaded){
    var evalString = "document." + imageRef + "_rollover.src=secNavRollover.src";
	eval(evalString );
	eval("document.rollover_tag.src=" + imageRef + "_tag.src");
  }
}


function secRestore(imageRef){
  if (loaded){
    var evalString = "document." + imageRef + "_rollover.src=" + imageRef + "_rollover_off.src"
    eval(evalString);
  }
}


function imageSwap(imageName){
  if (loaded){
    var imageRef = getImageRef(imageName);
	imageRef.src = rolloverArray[imageName + "_on"].src;
  }
}
	  
function imageRestore(imageName){
  if (loaded){
    var imageRef = getImageRef(imageName);
	imageRef.src = rolloverArray[imageName + "_off"].src;		  
  }
}

// FUNCTION ja_image_load
// creates array of image refs -- useful for images scattered over various layers
function ja_image_load(){

  var layerName = arguments[0];
	
  for ( i=1; i<arguments.length; i++ ){
  
    if (bd.browser=="Netscape"){
	  imageArray[arguments[i]] = document.layers[layerName].document.images[arguments[i]]
	} else if (bd.browser=="IE") {
	  imageArray[arguments[i]] = document.all[arguments[i]]
	}
  
  }

}

// FUNCTION ja_rollover_preload
// loads on and off states
function ja_rollover_preload(){
  
  //if ((rolloverArray) && (imageArray)){
  
	var imagePath = arguments[0];
	
    for ( i=1; i<arguments.length; i++ ){
	
	  var imageName = arguments[i];
	  // create off state image
	  rolloverArray[imageName+"_off"] = new Image();
	  rolloverArray[imageName+"_off"].src = imagePath + imageName + "_off.gif";
		  
	  // create on state image
	  rolloverArray[imageName+"_on"]  = new Image();
	  rolloverArray[imageName+"_on"].src  = imagePath + imageName + "_on.gif";
	  
	}
	
	return true;
	  
 /* } else {
		
	alert("There was a problem preloading the rollover images");
    return false;
		
  } */

}





/*

UTILITY FUNCTIONS

*/

/******
FUNCTION netscapeResize()
ARGUMENTS: none
RETURNS: none

If browser is netscape, check if browser
*******/

var initWidth  = window.innerWidth;
var initHeight = window.innerHeight;

function netscapeResize(){
  if (navigator.appName == 'Netscape'){
	if ((window.innerWidth != initWidth) || (window.innerHeight != initHeight)){
	  location.reload();
	}
  }
}

/******
FUNCTION Trim()
ARGUMENTS: string inString
RETURNS: string

This function trim spaces from both ends of a string
*******/

function Trim(inString) {
  var retVal = "";
  var start = 0;
  while ((start < inString.length) && (inString.charAt(start) == ' ')) {
    ++start;
  }
  var end = inString.length;
  while ((end > 0) && (inString.charAt(end - 1) == ' ')) {
    --end;
  }
  retVal = inString.substring(start, end);
  return retVal;
}



/*

  LAYER MANIPULATION

*/

function ja_getLayerRef(layerName){

  var ref
  if (bd.browser=="Netscape" && bd.majorver == "5"){
    ref = document.getElementById(layerName);
  } else {    
	ref = (bd.browser=='Netscape') ? document.layers[layerName] : document.all[layerName];
  }
  return ref;

}

function ja_showHideLayers(){
  // args will be passed in - layer, layer, layer, ..., visibility
    
    var args = ja_showHideLayers.arguments;
	var argVal = "";
	var endLyr = "";
	
	for (index=0; index < args.length; index++){
	
	  var layerString = "";
			
	  do {
	  
	    argVal = args[index];
	  
	    if ( argVal != 'visible' && argVal != 'hidden'){
		  
		  if (document.layers){
		  
		    layerString += "document.layers['" + argVal + "'].";
		  
		  } else if (document.all) {
		  
		    layerString = "document.all." + argVal + ".style.";
		  		   
	      }
		
		  index++;
		  
		  endLyr = argVal;  
		
	    }
	  	  	  
	  } while ( argVal != 'visible' && argVal != 'hidden');
	  
	  
	  if (bd.browser=="Netscape" && bd.majorver=="5") {
		var ns6Lyr = ja_getLayerRef(endLyr);
		ns6Lyr.style.visibility = argVal;
		ns6Lyr.style.display = (argVal=="visible") ? "" : "none";
	  } else {  
	    eval(layerString + "visibility = '" + argVal + "'");	  
	  }

	  
	  
	}
	
}

  
  
  function openLabAlert(url){
  // sized for lab alert window
  
    window.open(url,'child_labAlert','width=339,height=199,scrollbars=no');
  
  
  }


// use for HELP  
function openHelp(url) {
    win = window.open(url,'',"resizable=yes,status=no,toolbar=no,menubar=no,width=800,height=500,scrollbars=yes");
}

// use for adding an item
function openAddTemplate(url) {
    win = window.open(url,'',"status=no,toolbar=no,menubar=no,width=520,height=300,scrollbars=yes");
}

function openWin(w, h, url) {
    win = window.open(url,'',"status=no,toolbar=no,menubar=no,width="+w+",height="+h+",scrollbars=yes");
}

function openWinBig(url) {
    win = window.open(url,'',"status=no,toolbar=no,menubar=no,width=700,height=660,scrollbars=yes");
}

function openWinMid(url) {
    win = window.open(url,'',"status=no,toolbar=no,menubar=no,width=540,height=540,scrollbars=yes");
}

function openWinSmall(url) {
    win = window.open(url,'',"status=no,toolbar=no,menubar=no,width=540,height=340,scrollbars=yes");
}

function openWinSmall(url,name) {
    win = window.open(url,name,"status=no,toolbar=no,menubar=no,width=540,height=340,scrollbars=yes");
    win.focus();
}

function openWinSuperBig(url) {
    win = window.open(url,'',"status=no,toolbar=no,menubar=no,width=860,height=660,scrollbars=yes");
}

// use for 2nd nav.
function terNavSelect(imgName){
      var selected = (imgName == currentTerNav);
      if (selected){
            return true;
      } else {
            if (currentTerNav != "") imageRestore(currentTerNav);
            currentTerNav = imgName;
            document.images[imgName].src = "/images/" + imgName + "_current.gif";
            return true;
      }
}  

function Check(e)
{
      e.checked = true;
}

function Clear(e)
{
      e.checked = false;
}

function getVetUrl()
{
        var myUrl = "https://" + location.hostname + "/control/clinichome";
        return location.href=myUrl;
}
function getGroupUrl()
{
        var myUrl = "https://" + location.hostname + "/control/group/grouphome";
        return location.href=myUrl;
}

//remove spaces
function rmSpace(e) {
      e.value = e.value.replace(/^[\s]+/g,"");
      e.value = e.value.replace(/[\s]+$/g,"");
}

function getYear()
{
	today = new Date();
	return today.getFullYear();;
}

function goConSult() {
     window.location = "/control/labconsult_vendor" + window.location.search;
}
function PrintPage() {
     window.print();
}

function getGoogleAnalyticAcct()
{
        var myAcct = "UA-1666512-1"; /*default to production*/
	if (location.hostname == "dev2.zoasis.com") {
		myAcct = "UA-1967486-1";
	}
        return myAcct;
}

