var thisBrowser = "";
var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0);
if (isIE) thisBrowser = "ie";
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) thisBrowser = "firefox";
if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)) thisBrowser = "chrome";
if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) thisBrowser = "opera";
if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)) thisBrowser = "safari";

var numb = '0123456789';
var numbDec = '0123456789.';
function isValid(parm,val)
  {
  if (parm == "") return true;
  for (i=0; i<parm.length; i++)
    {
    if (val.indexOf(parm.charAt(i),0) == -1) return false;
    }
  return true;
  }
function isNum(parm) {return isValid(parm,numb);}
function isNumDec(parm) {return isValid(parm,numbDec);}

function getCookie(Name)
  {
  var search = Name + "=";
  var returnvalue = "";
  if (document.cookie.length > 0)
    {
    offset = document.cookie.indexOf(search);
    // if cookie exists
    if (offset != -1)
      { 
      offset += search.length;
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end));
      }
    }
  return returnvalue;
  }  

function eraseCookie(Name)
  {
	writeCookie(Name, "", -1);
	}

function writeCookie(cookieName, value1, expiryMinutes)
  {
  // set expiry date
  var d = new Date();
  d.setTime(d.getTime() + (expiryMinutes * 60 * 1000)); 
  var cd = d.toGMTString();
 
  var c = cookieName + "=" + value1 + ";expires=" + cd + ";";
  // write cookie
  document.cookie = c;
  }
/*
function getYposition(whichelement)
  {
  var ypos = 0;
  if (whichelement.offsetParent)
    {
    while (whichelement.offsetParent)
      {
      ypos += whichelement.offsetTop
      whichelement = whichelement.offsetParent;
      }
    }
  return ypos;
  }
*/
function getYposition(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
          {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
          }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }


/*
function getXposition(whichelement)
  {
  var xpos = 0;
  if (whichelement.offsetParent)
	  {
    while (whichelement.offsetParent)
		  {
      xpos += whichelement.offsetLeft
      whichelement = whichelement.offsetParent;
      }
    }
  return xpos;
  }
*/

function getXposition(obj)
  {
  var curleft = 0;
    if(obj.offsetParent)
        while(1) 
          {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
          }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }



	
function getElementBottomPos(divEl)
  {
  var dTop = getYposition(divEl)
  var dHeight = divEl.offsetHeight;
  var dBott = dTop + dHeight;
  return dBott;
  }

function getDocumentHeight()
  {
  var doc = document;
  return Math.max(
    Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight),
    Math.max(doc.body.offsetHeight, doc.documentElement.offsetHeight),
    Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
    );
  }

// function to replace all instances of the given substring.
String.prototype.replaceAll = function( 
  strTarget, // The substring to replace
  strSubString // The string to replace with.
  )
  {
  var strText = this;
  var intIndexOfMatch = strText.indexOf( strTarget );

  // Keep looping while an instance of the target string
  // still exists in the string.
  while (intIndexOfMatch != -1)
    {
    // Replace out the current instance.
    strText = strText.replace( strTarget, strSubString )

    // Get the index of any next matching substring.
    intIndexOfMatch = strText.indexOf( strTarget );
    }

  // Return the updated string with ALL the target strings
  // replaced out with the new substring.
  return( strText );
  }



var lastClass;
var firstTimeThrough=true;
var statusBarText = "";
// Function to show the style class of an object
function showClass(thisClass, stringID)
  {
	if (showStylesJs == "return true") return true;
  if ((firstTimeThrough == false) && (lastClass != "") && (lastClass != thisClass)) return true;
  firstTimeThrough = false;
  statusBarText = "Style: " + thisClass.className;
  if ((stringID != null) && (stringID != ' '))
    {
	  stringID = stringID.replaceAll("$", "");
		statusBarText += "   Text ID: " + stringID;
    }
  setTimeout("setStatusBarText()", 200);  
  lastClass = thisClass;
  setTimeout('lastClass=""',500);
  return true;
  }

function setStatusBarText()
  {
  window.status = statusBarText;
  return true;
  } 


// This function kills the Quick Tip popups completely
function killQuickTips()
  {
  overlib=no_overlib;
  nd=no_overlib;
  ver3fix=true;
  }


function openLinkWindow(linkURL)
  {
  //var linkWin = window.open(linkURL,'WebMadcap', 'scrollbars=yes, menubar=no, toolbar=no, location=no, height=' + (screen.availHeight-90) + ', width=' + (screen.availWidth-30) + ', left=10,top=10');
  var linkWin = window.open(linkURL,'WebMadcap', 'location, scrollbars=yes, height=' + (screen.availHeight-90) + ', width=' + (screen.availWidth-30) + ', left=10,top=10');
  }

function doBeep()
  {
  
  if (document.getElementById("beeper")) document.getElementById("beeper").src = "mcIncludes/beepWeb.wav";
  }

function scaleTableHeader(tableHeader, tableMain, scrollTest)	
  {
  if (document.getElementById(tableHeader) != null)
    {
    var tableHeaderObj = document.getElementById(tableHeader);
    var tableObj = document.getElementById(tableMain);
    var numColsTable = tableObj.rows[0].cells.length; // no of columns in the table
    var adjust = 2 + tableObj.cellPadding * 2;
    var c;
    var cellWidth;
    for (c=0; c < numColsTable; c++)
      {
      cellWidth = tableObj.rows[0].cells[c].offsetWidth; // width of cell in pixels
      if (cellWidth > tableHeaderObj.rows[0].cells[c].offsetWidth)
        {
        tableHeaderObj.rows[0].cells[c].style.width=cellWidth - adjust ; // Set the header cell width to match the table cell
        }
      else // Set the table cell width to match the header cell width
        {
        tableObj.rows[0].cells[c].style.width = tableHeaderObj.rows[0].cells[c].offsetWidth - adjust;
        }
      }
    setDivWidth();

    if (document.getElementById("resultsDiv") != null && scrollTest && document.getElementById("resultsDiv").scrollHeight > document.getElementById("resultsDiv").clientHeight)
      {
      if(tableHeaderObj.rows[0].lastChild.innerHTML == " ") tableHeaderObj.rows[0].removeChild(tableHeaderObj.rows[0].lastChild);
      var cell=document.createElement("th");
      var text=document.createTextNode(" ");
      cell.className="resultsTableHeadings";
      cell.appendChild(text);
      cell.style.width=11;
      tableHeaderObj.rows[0].appendChild(cell);
      }
    else if (document.getElementById("resultsDiv") != null && !scrollTest && document.getElementById("resultsDiv").scrollHeight > document.getElementById("resultsDiv").clientHeight)
      tableHeaderObj.rows[0].removeChild(tableHeaderObj.rows[0].lastChild); // kill the last cell if it was added because of a scroll bar
    }
  }

function printContent(contentId, title)
  {
  //if (document.getElementById('detailsHeader') != null)
    //scaleTableHeader('detailsHeader', 'detailsTable', true);

  var disp_setting="toolbar=no,location=no,directories=no,menubar=no,";
  disp_setting += "scrollbars=yes,width=1000, height=800, left=10, top=50";
  var content_vlue = document.getElementById(contentId).innerHTML;

  var docprint=window.open("","",disp_setting);
   docprint.document.open();
   //docprint.document.write('<html><head><title>' + title + '</title>');
   docprint.document.write('<html><head>');
   docprint.document.write('<script language=\"Javascript\"\>\n');
   
   docprint.document.write('function setDivWidthSpecific() {};\n');
   
   docprint.document.write('function showClass(obj, string) {};\n');
   docprint.document.write('</script\>\n');

   docprint.document.write('<style type="text/css">' + alertStyle + '</style\>');
   docprint.document.write('</head><body><center>');
   docprint.document.write(title + '<br><br>');
   docprint.document.write('<font size=-1>'); 
   docprint.document.write(content_vlue);
   
   docprint.document.write('<script\>');

   docprint.document.write('var resDiv = document.getElementById("resultsDiv");\n');
   docprint.document.write('if (resDiv != null) '); 
   docprint.document.write('{\n');   
   
   docprint.document.write('var killScroll = false; if (resDiv.scrollHeight > resDiv.clientHeight) killScroll=true;');
   
   docprint.document.write('resDiv.style.height = resDiv.scrollHeight;');
   docprint.document.write('resDiv.style.overflow="visible"};');
   
   docprint.document.write('if (killScroll) {');
   docprint.document.write('var tableHeaderObj = document.getElementById("detailsHeader");');
   docprint.document.write('if (tableHeaderObj != null) tableHeaderObj.rows[0].removeChild(tableHeaderObj.rows[0].lastChild);');
   docprint.document.write('};');   
  
   docprint.document.write('setTimeout("self.print()",100)');
   
   docprint.document.write('</script\>\n');
   
   docprint.document.write('</center></body></html>');
   docprint.document.close(); 
   docprint.focus();

  }


var preloadedImg = new Image(32,40);
var left = (getWinWidth()/2) - 35;
var bTop;

preloadedImg.src = 'mcIncludes/Loading.gif';

var shakeIntVal;
function setLoadingImage(newTop)
  {
  if (showLoadingImage == "false") return;
  left = (getWinWidth()/2) - 30;
  if (isIE) left = left - 35;

  var checkBanner = document.getElementById("selDisclText");
  if (checkBanner)
    {
    bTop = getYposition(checkBanner);
    bTop -= 45;
    }
  else if (document.getElementById("leftMenuDiv"))
    {
    if (document.getElementById("nameLine"))
      bTop = getYposition(document.getElementById("nameLine"))
    else if (document.getElementById("navBar"))
      bTop = getYposition(document.getElementById("leftMenuDiv")) - 92;
    else
      bTop = getYposition(document.getElementById("leftMenuDiv")) - 45;
    //if (isIE) bTop -= 10;
    }

  else bTop = (getWinHeight()/2)- 20;
  
  if (newTop != null) bTop += newTop;

  document.images['loadingImage'].src=preloadedImg.src;
  document.images['loadingImage'].style.display="block";

  if (isIE)
    {
    left +=20;
    }
  document.images['loadingImage'].style.width="40px";
  document.images['loadingImage'].style.height="20px";
  document.images['loadingImage'].style.left=left;
  document.images['loadingImage'].style.top= bTop+1;
  document.images['loadingImage'].style.zIndex = 30000;
  
  if (isIE)
    {
    iShake = left;
    shakeIntVal = setInterval("shakeLoadingImage()", 50);
    }
}


var iShake;
var iShakeIncr = 1;
function shakeLoadingImage()
  {
  iShake += iShakeIncr;
  document.images['loadingImage'].style.left=iShake + "px";
  if (iShake == (left + 5)) iShakeIncr = -1; if (iShake == left) iShakeIncr = 1;
  };  
  

function hideLoadingImage()
  {
  clearInterval(shakeIntVal);
  document.images['loadingImage'].style.display="none";
  }


function getWinWidth()
  {
  var x = 0;
  if (self.innerHeight)
    {
    x = self.innerWidth;
    }
  else if (document.documentElement && document.documentElement.clientHeight)
    {
    x = document.documentElement.clientWidth;
    }
  else if (document.body)
    {
    x = document.body.clientWidth;
    }
  return x;
  }
 
function getWinHeight()
  {
  var y = 0;
  if (self.innerHeight)
    {
    y = self.innerHeight;
    }
  else if (document.documentElement && document.documentElement.clientHeight)
    {
    y = document.documentElement.clientHeight;
    }
  else if (document.body)
    {
    y = document.body.clientHeight;
    }
  return y;
  }  
  
  
function getPopupHeight(window)
  {  
  //var pageWidth;
  var pageHeight;
  
  if ( window.innerHeight && window.scrollMaxY )
    {
    // Firefox
    //pageWidth = window.innerWidth + window.scrollMaxX;
    pageHeight = window.innerHeight + window.scrollMaxY;
    return pageHeight;
	}
  else if( window.document.body.scrollHeight > window.document.body.offsetHeight )
    {
    // all but Explorer Mac
    //pageWidth = window.document.body.scrollWidth;
    pageHeight = window.document.body.scrollHeight;
    return pageHeight; 	
    }
  else
    {
    // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    //pageWidth = window.document.body.offsetWidth + document.body.offsetLeft;
    pageHeight = window.document.body.offsetHeight + document.body.offsetTop;
    return pageHeight;      
	}  
  }    
  
  
  
var winHeight = 0;
var docAlert = null;
var totalBreaks = 0;
var thisWidth;


function showAlert(content, alertType, title, width)
  { 
  if (docAlert)
    {
    docAlert.close();
    docAlert = null;
    }
  
  if (!width) thisWidth = 400;
  else thisWidth = width;
//  var left=(screen.availWidth/2) - 225;
  var left=(screen.availWidth/2) - thisWidth / 2;
  var top=(screen.availHeight/2) - 200;
  var disp_setting="toolbar=0,location=0,directories=0,menubar=0, titlebar=0, status=0, ";
  disp_setting += "scrollbars=auto, width=" + thisWidth + ", height=100, left=" + left + ", top=" + top; 
  docAlert=window.open("","",disp_setting);
  if (!docAlert) {alert(content); return;}
  var spaces = "";
  for (i=0; i<100; i++) spaces += '&nbsp;'
  docAlert.border = "10px purple inset";
  docAlert.document.open();
  docAlert.document.write('<html><head><title>Information' + spaces + '</title\>');
  docAlert.document.write('<script language=\"Javascript\"\>\n');
  docAlert.document.write('function showClass(obj, string) {};\n');
  docAlert.document.write('</script\>\n');
  docAlert.document.write('<style type="text/css">' + alertStyle + '</style\>');
  docAlert.document.write('</head><body style="border: inset silver 6px; padding: 10px; margin: 0 0 10 0; padding : 10 10 10 10; background-color: ivory;" onBlur="self.focus()">');
  if (alertType.toUpperCase() == "ERRORICON") docAlert.document.write('<img src="mcIncludes/error1.jpg"></img\>');
  else if  (alertType.toUpperCase() == "EXCLAMICON") docAlert.document.write('<img src="mcIncludes/exclamation2.jpg">');
  else docAlert.document.write('<img src="mcIncludes/information2.jpg"></img\>');
  if (title != "" && title != null)
    {
    docAlert.document.write('<center><nobr class="infoText2"  style="position:relative; top: -30px;">' + title + '</nobr></center>');
    docAlert.document.write('<center><p name="textPara" id="textPara" class="infoText1" style="word-wrap: break-word; position:relative; top: -0px;">');
    }
  else docAlert.document.write('<center><p name="textPara" id="textPara" class="infoText1" style="word-wrap: break-word; position:relative; top: -15px;">');	  
  docAlert.document.write(content.replace(/\n/g, ""));
  docAlert.document.write('<br><br><input type=button class="buttonStyleNorm" value="&nbsp;&nbsp;OK&nbsp;&nbsp;" onClick="self.close(); opener.docAlert = null">');
  docAlert.document.write('</p\>');  
  docAlert.document.write('<br></center></body\></html\>');
  docAlert.document.write('<script>setTimeout("self.close()", 600000)</script\>');
  docAlert.document.close();
  //docAlert.blur();

  totalBreaks = content.split('<br>').length;

  setTimeout("setAlertWinHeight(thisBrowser, thisWidth)", 100);
  
  }  

function setAlertWinHeight(browser, width)
  {
  var thisWidth;
  if (!width) thisWidth = 400;
  else thisWidth = width;
  
  winHeight = getPopupHeight(docAlert);  
  if (browser == "firefox") docAlert.resizeTo(thisWidth, winHeight + 30);
  else if (browser == "opera") docAlert.resizeTo(thisWidth, winHeight + 40);
  else if (browser == "ie") docAlert.resizeTo(thisWidth, winHeight + 30);
  else if (browser == "chrome") docAlert.resizeTo(thisWidth, winHeight + 70);
  else docAlert.resizeTo(thisWidth, winHeight + 30);

  docAlert.focus();
  }

  
function pauseComp(millis) 
  {
  var date = new Date();
  var curDate = null;
  do { curDate = new Date(); } 
  while(curDate-date < millis);
  }

function resizeFrames(preference)
  {
  if (preference == 1)
    {
    window.frames.topandbottom.rows = '105%,0%';
    }
  if (preference == 2)
    {
    window.frames.topandbottom.rows = '0%,105%';
    }
  }


function disableDivContents(id, disabled)
  {
  if ( !document.getElementById || !document.getElementsByTagName) return;

  var nodesToDisable = {button :'', input :'', optgroup :'', option :'', select :'', textarea :'', nobr :''};

  var node, nodes;
  var div = document.getElementById(id);
  if (!div) return;

  nodes = div.getElementsByTagName('*');
  if (!nodes) return;

  var i = nodes.length;
  while (i--)
    {
    node = nodes[i];
    if ( node.nodeName && node.nodeName.toLowerCase() in nodesToDisable )
      {
      node.disabled = disabled;
      }
    }
  }

function getStyleClass (className)
  {
  var theRules = new Array();
  var re = new RegExp("\\." + className + "$", "gi");

  if (document.all || document.getElementById)
    {
    for (var s = 0; s < document.styleSheets.length; s++)
      {
      if (document.styleSheets[s].cssRules)
	      theRules = document.styleSheets[s].cssRules;
      else if (document.styleSheets[s].rules)
        theRules = document.styleSheets[s].rules;
      for (var r = 0; r < theRules.length; r++)
        {
        if ((theRules[r].selectorText.search(re) != -1) || (theRules[r].selectorText.indexOf("." + className,0) != -1))
          {
          return theRules[r].style;
          }
        }
      }
    }
  else if (document.layers)
    return document.classes[className].all;
  return null;
  }

function getStyleClassProperty (className, propertyName)
  {
  var styleClass = getStyleClass(className);
  if (styleClass)
    {
    return styleClass[propertyName];
    }
  else
    return null;
  }



function disableButton(buttId, dis)
  {
  var butt = document.getElementById(buttId);
  if (butt != null)
	  {
    var styleClassName = butt.className;
    var styleColor=getStyleClassProperty(styleClassName, "color");
    if (dis)
	    {
		  if (!isIE) butt.style.color="lightgrey";
		  //if (!isIE) butt.style.color="GrayText";
		  butt.disabled = true;
		  }
	  else
	    {
		  if (!isIE) butt.style.color=styleColor;
      butt.disabled = false;
		  }
   }
	}
	
document.getElementsByClassName = function(clsName)
  {
  var retVal = new Array();
  var elements = document.getElementsByTagName("*");
  for(var i = 0;i < elements.length;i++)
    {
    if(elements[i].className.indexOf(" ") >= 0)
      {
      var classes = elements[i].className.split(" ");
      for(var j = 0;j < classes.length;j++)
        {
        if(classes[j] == clsName) retVal.push(elements[i]);
        }
      }
    else if(elements[i].className == clsName) retVal.push(elements[i]);
    }    return retVal;
  }
  

var blinkLinks;
var origClassName;
var blinkLinksLength;
var linkCount;
var blink_on;

function blink()
  { 
  blinkLinks =document.getElementsByClassName("infoText5Alert");
	blink_on = new Array(blinkLinks.length);
	
	for(i=0; i <blink_on.length -1; i++)
	  {
		blink_on[i] = 1;
		} 
  blink_y = 1 
  doBlinks();
  } 

function doBlinks()
  { 
	if (blinkLinks.length)
	  {	
    linkCount = 0;
    while (linkCount < blinkLinks.length)
	    {
      if(blink_on[linkCount]==1 && blinkLinks[linkCount].className != "stopBlink")
	      { 
        blink_on[linkCount]=0; 
        blink_y++; 
        blinkLinks[linkCount].className="infoText5Alert";
        }
      else
        { 
        if (blinkLinks[linkCount].className != "stopBlink")
				{
				blink_on[linkCount]=1; 
        blink_y++; 
        blinkLinks[linkCount].className="infoText5";
				}
        }
      linkCount ++;
			}
    if (blink_y < blinkLinks.length * 15)
	    {
		  setTimeout('doBlinks()', 250);
		  }
    else
      {
		  for (l = 0; l < blinkLinks.length; l++)
			  {
			  blinkLinks[l].className="infoText5Alert";
			  }
      }
    } 
  }

function stopBlink(which)
  {
	which.className="stopBlink";
	}

// Calculator stuff
var calculation = "";
var resultDone = false;

function addToCalc(val)
  {
  if(isNaN(val) && isNaN(calculation.substring(calculation.length-1, calculation.length)))
    return false;

  if(!isNaN(val) && resultDone)
    {
    resetCalc();
    resultDone = false;
    }
  else if(isNaN(val) && resultDone)
	{
    resultDone = false;
    }
  calculation += val;
  showResult();
  }

function addToCalcDirect(val)
  {
  calculation = val;
  }

function resetCalc()
  {
  calculation = "";
  showResult();
  document.getElementById("result").focus();
  }

function positiveNegative()
  {
  if(calculation.substring(0, 1) == "-")
    calculation = calculation.substring(1, calculation.length);
  else
    calculation = "-" + calculation;
  showResult();
  }

function calculate()
  {
  if(calculation != "")
    {
    try
	  {
      calculation = eval(calculation);
      }
    catch(e)
	  {
      reportError("Error!");
      }
    resultDone = true;
    showResult();
    }
  else
    return false;
  }

function percentage()
  {
  try
    {
    calculation = eval(calculation) / 100;
    }
  catch(e)
    {
    reportError("Error!");
    }
  resultDone = true;
  showResult();
  }

function squareRoot()
  {
  try
    {
    calculation = Math.sqrt(eval(calculation));
    }
  catch(e)
    {
    reportError("Error!");
    }
  resultDone = true;
  showResult();
  }

function showResult()
  {
  calculation = calculation.toString();
  if(calculation == "NaN")
    {
    reportError("Error!");
    }
  else
    {
    document.getElementById("result").value = calculation;
    }
  }

function reportError(msg)
  {
  calculation = msg;
  document.getElementById("result").value = msg;
  }

function closeCalculator()
  {
  document.getElementById("calculator").style.display = "none";
  }

function about()
  {
  msg = "Floating Calculator for Madcap Web\n\n";
  alert(msg);
  }

var ie = document.all;
var ns6 = document.getElementById && !document.all;
var dragapproved=false;
var z, x, y;

function move(e)
  {
  if (dragapproved)
    {
    z.style.left=ns6? temp1+e.clientX-x: temp1+event.clientX-x;
    z.style.top=ns6? temp2+e.clientY-y : temp2+event.clientY-y;
    return false;
    }
  }

function drags(e)
  {
  if (!ie&&!ns6)
    return;
  var firedobj = ns6? e.target : event.srcElement;
  var topelement = ns6? "HTML" : "BODY";
  while (firedobj.tagName != topelement&&firedobj.className != "dragCalc")
    {
    firedobj = ns6? firedobj.parentNode : firedobj.parentElement;
    }
  if (firedobj.className == "dragCalc")
    {
    dragapproved = true;
    z = firedobj;
    temp1 = parseInt(z.style.left+0);
    temp2 = parseInt(z.style.top+0);
    x = ns6? e.clientX: event.clientX;
    y = ns6? e.clientY: event.clientY;
    document.onmousemove=move;
    return false;
    }
  }
document.onmousedown=drags;
document.onmouseup=new Function("dragapproved=false");

// End of calculator stuff

function stringBetween(inString,startString,endString)
  {
  var startPos = inString.indexOf(startString) + startString.length;
  var endPos = inString.indexOf(endString);
  return inString.slice(startPos,endPos);
  }

// Simon Willison's addLoadEvent - won't always work on Firefox 3
function addLoadEvent(func)
  {
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
    {
    window.onload = func;
    }
  else
    {
    window.onload = function()
      {
      if (oldonload)
        {
        oldonload();
        }
      func();
      }
    }
  }

// Google earth
function focusEarthWin()
  {
  if (earthWin) earthWin.focus();
  }

var earthWin;
function openGoogleEarthWinLocal(latandlong,farmId,helpText)
  {
  var width  = 920;
  var height = 870;
  var left   = (screen.width  - width)/2;
  var top    = ((screen.height - height)/2) - 20;
  var params = 'width='+width+', height='+height;
  params += ', top='+top+', left='+left;
  params += ',resizable=yes';
  var thisLatLngArray = latandlong.split(",");
  earthWin = window.open('','eWin',params);

  var helpTextOut = "<span style='font-face:tahoma; font-weight:bold; font-size:14px; color:darkgreen;'>" + helpText + "</span>";
	
  var inner = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">\n';
  inner += '<html><head><title>Google Earth View for the farm of ' + farmId + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</title>\n';
  inner += '<script src="http://maps.google.com/maps/api/js?sensor=false"></script\>\n';
  inner += '<script>function doInitialise() {googleEarthInitialise(lat,lng,"' + farmId + '")}</script\>\n';
  inner += '<script>function googleEarthInitialise(lat,lng,farmId)';
  inner += '  {';
  inner += '  var myLatlng = new google.maps.LatLng(lat,lng);';
  inner += '  var myOptions = {';
  inner += '    zoom: 17,';
  inner += '    center: myLatlng,';
  inner += '    mapTypeId: google.maps.MapTypeId.HYBRID,';
  inner += '  	frame: true';
  inner += '    };';
  inner += '  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);';
  inner += '  var marker = new google.maps.Marker({';
  inner += '    position: myLatlng,';
  inner += '    map: map,';
  inner += '    title: farmId,';
  inner += '    draggable: true,';
  inner += '    autoPan: true';
  inner += '    })';
  inner += '  };';
  inner += '</script\>';
  inner += '<script> var lat=' + thisLatLngArray[0] + '; var lng=' + thisLatLngArray[1] + '; </script\></head>\n';
  inner += '<body onLoad=setTimeout("doInitialise()",200) onBlur=setTimeout("window.opener.focusEarthWin()",500)>';
  inner += '<div id="map_canvas" style="width: 900px; height: 700px;"></div>\n'
  inner += '<center><button onClick="self.close()">Close</button></center>'
  inner += '<div id="helpDiv" name="helpDiv" style="width:880px; height:150px;">' + helpTextOut + '</div>\n'
  inner += '</body></html>\n';
  earthWin.document.open();
	earthWin.document.write(inner);
	earthWin.document.close();

  if(isIE && earthWin && !earthWin.closed)
    {
    earthWin.location.reload(false);
    earthWin.focus();
    }
  }

function GiveDec(Hex)
  {
   if(Hex == "A")
      Value = 10;
   else
   if(Hex == "B")
      Value = 11;
   else
   if(Hex == "C")
      Value = 12;
   else
   if(Hex == "D")
      Value = 13;
   else
   if(Hex == "E")
      Value = 14;
   else
   if(Hex == "F")
      Value = 15;
   else
      Value = eval(Hex)
   return Value;
  }

function colorHexToDec(hexIn)
  {
  var hex;
  if (hexIn.substring(0,1) == "#") hex = hexIn.substring(1,7);
  else hex=hexIn;
   hex = hex.toUpperCase();

   a = GiveDec(hex.substring(0, 1));
   b = GiveDec(hex.substring(1, 2));
   c = GiveDec(hex.substring(2, 3));
   d = GiveDec(hex.substring(3, 4));
   e = GiveDec(hex.substring(4, 5));
   f = GiveDec(hex.substring(5, 6));

   x = (a * 16) + b;
   y = (c * 16) + d;
   z = (e * 16) + f;

   return x + "," + y + "," + z; // This is RGB in the form 12,34,56
  }

function extractColoursFromRGBstring(inRGB)
  {
  return inRGB.substring(inRGB.indexOf("(") + 1, inRGB.indexOf(")"));
  }

function getStyle(el, cssprop){
 if (el.currentStyle) //IE
  return el.currentStyle[cssprop];
 else if (document.defaultView && document.defaultView.getComputedStyle) //Firefox
  return document.defaultView.getComputedStyle(el, "")[cssprop];
 else //try and get inline style
  return el.style[cssprop];
}

function getBackgroundColor(div)
  {
  var bodyBgOrig = document.bgColor;
  var retColor;
  if (document.getElementById(div))
    {
    document.body.style.background = getStyle(document.getElementById(div), 'backgroundColor');
    retColor = document.bgColor;
		document.body.style.background = bodyBgOrig;
    return retColor;
    }
  else return "#FFFFFF";
  }
  
function getBgColorFromColorname(colorName)
  {
  var bodyBgOrig = document.bgColor;
  var retColor;
  document.body.style.background = colorName;
  retColor = document.bgColor;
  document.body.style.background = bodyBgOrig;
  return retColor;
  }

// jQuery section
$.showAlert = function(alertType, alertHeading, alertText)
  {
  var typeImageSrc;
  var typeColor;
  var typeFontSize = "";
  if (alertType == "information") {typeImageSrc = "mcIncludes/information2.jpg"; typeColor = "#006400";}
  if (alertType == "error") {typeImageSrc = "mcIncludes/error1.jpg"; typeColor = "#FF0000"; typeFontSize = " font-size:16px; "}
  if (alertType == "warning") {typeImageSrc = "mcIncludes/exclamation2.jpg"; typeColor = "#D2691E"; typeFontSize = " font-size:14px; "}
  $.fancybox
    (
      {
      'padding' : 20,
      'width' : 440,
      'height' : 'auto',
      'transitionIn' : 'fade',
      'transitionOut' : 'fade',
      'speedIn' : 500,
      'speedOut' : 500,
      'autoDimensions' : false,
      'scrolling' : 'no',
      'overlayColor' : '#778899',
      'onComplete' : function(){$("#fancybox-wrap").easydrag();},
      'content' : '<img style="width:30px;height:30px; vertical-align:middle; margin-right:20px;" src="' + typeImageSrc + '"><span class="infoText2">' + alertHeading + '</span><br><![if !IE]><br><![endif]><hr style="width:410px; text-align: left; margin: 0 auto 0 0;"><div style="width:410px; "><br><span class="infoText1" style="color:' + typeColor + ';' + typeFontSize + '">' + alertText + '</span><br><br></div><hr style="width:410px; text-align: left; margin: 0 auto 0 0;"><br><br><span style="font-face: Tahoma, sans-serif; color:darkgray; font-size: 9px;">Click and hold to drag</span><br><!--[if IE]><br><br><![endif]-->'
      }
    );
  };

//$.showTip = function(objIn,alertText)

function showTip(objIn,alertText)
  {
//alert("objIn = " + objIn);

  var typeColor = "#006400";;
  var typeFontSize = " font-size:14px; ";

//var topPos = obj.position().top;
//var leftPos = obj.position().left;

//var topPos = objIn.offsetTop;
//var leftPos = objIn.offsetLeft;
/*
alert("top1 = " + topPos + "   left1 = " + leftPos);
*/
topPos = getYposition(objIn);
leftPos = getXposition(objIn);
//alert("top2 = " + topPos + "   left2 = " + leftPos);

//topPos = $(thisOne).position().top;
//leftPos = $(thisOne).position().left;
//alert("top2 = " + topPos + "   left2 = " + leftPos);

  $.fancybox
    (
      {
      'padding' : 20,
      'height' : 'auto',
      'transitionIn' : 'fade',
      'transitionOut' : 'fade',
      'speedIn' : 10,
      'speedOut' : 10,
      'autoDimensions' : true,
      'showCloseButton' : false,
      'scrolling' : 'no',
      'overlayColor' : '#778899',
      'onComplete' : function() {$("#fancybox-wrap").css("top",topPos).css("left",leftPos);},
      'content' : '<div style="z-index:40000;"><span class="infoText4" style="color:' + typeColor + ';' + typeFontSize + '">' + alertText + '</span></div><!--[if IE]><br><br><br><![endif]-->'
      }
    );
  };


function showTipClose()
  {
  setTimeout("$.fancybox.close()",500);
  }




$.showConfirm = function (msg, heading, yesnocancel, callback)
  {
  var yesButtText = "";
  var noButtText = "";
	if (yesnocancel.toUpperCase() == "YESNO") {yesButtText = "Yes"; noButtText = "No";}
	else { yesButtText = "OK"; noButtText = "Cancel";}
	
	var ret;
  var typeImageSrc;
  var typeColor;
  typeImageSrc = "mcIncludes/confirmXQuest.jpg"; typeColor = "#D2691E";
		
  $.fancybox(
    {
    'modal' : true,
    'showCloseButton' : false,
    'padding' : 20,
    'width' : 440,
    'height' : 'auto',
    'transitionIn' : 'fade',
    'transitionOut' : 'fade',
    'speedIn' : 300,
    'speedOut' : 300,
    'autoDimensions' : false,
    'scrolling' : 'no',
    'overlayColor' : '#778899',
    'onComplete' : function(){$("#fancybox-wrap").easydrag();
			 $("#fancyConfirm_cancel").click(function() {ret = false;	$.fancybox.close();})
			 $("#fancyConfirm_ok").click(function() { ret = true; $.fancybox.close(); })},
    'onClosed' : function() {setTimeout(function(){callback.call(this,ret);},600)},	
    'content' : '<img style="width:30px;height:30px; vertical-align:middle; margin-right:20px;" src="' + typeImageSrc + '"><span style="font-family: verdana; font-size:16px; font-weight:bold; color:black;">' + heading + '</span><br><![if !IE]><br><![endif]><hr style="width:410px; text-align: left; margin: 0 auto 0 0;"><div style="width:410px; "><br><span style="font-family: verdana; font-size:14px; font-weight:bold; color:' + typeColor + ';">' + msg + '</span><br><br></div><div style="margin-top:10px;"><center><input id="fancyConfirm_cancel" style="width:80px; margin:3px; padding:0px;  color:#050; font-weight: bold; font-face: verdana; font-size:14px; background-color:#fed; border: 2px outset; border-color: lightgray; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffffff,EndColorStr=#ffffaaaa); background: -moz-linear-gradient(top, #ffffff, #ffaaaa);" type="button" value="&nbsp;&nbsp;' +noButtText + '&nbsp;&nbsp;"><input id="fancyConfirm_ok" style="width:80px; margin:3px;padding:0px; color:#050; font-weight: bold; font-face: verdana; font-size:14px; background-color:#fed; border: 2px outset; border-color: lightgray; filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#ffffffff,EndColorStr=#ffaaddaa); background: -moz-linear-gradient(top, #ffffff, #aaddaa);" type="button" value="&nbsp;' + yesButtText + '&nbsp;"></center></div><br><hr style="width:410px; text-align: left; margin: 0 auto 0 0;"><br><!--[if IE]><br><br><![endif]-->'
		});
  }
// usage example for Bill F's confirm box above:
/*
function confirmTestShort()
  {
	$.showConfirm("Could it be that I am a genius?", "Please confirm:", "yesno", function(ret)
	  {
		alert("We got the result - " + ret + "!");
		})
	}
*/

$.strPad = function(i,l,s)
  {
  var o = i.toString();
  if (!s) { s = '0'; }
  while (o.length < l)
    {
    o = s + o;
    }
  return o;
  };

function sortSelectBoxByText(selectId) {

        // Keep track of the selected option.
        var selectedValue = $(selectId).val();
        // Sort all the options by text.
        $(selectId).html($("option", $(selectId)).sort(function(a, b) {
            return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
       }));
        // Select one option.
        $(selectId).val(selectedValue);
}

function sortDateSelectBoxByText(selectId, dateStyle, asc)
  {
	// Remember the selected option.
  var selectedValue = $(selectId).val();

	// Sort all the options by text.
  $(selectId).html($("option", $(selectId)).sort(function(a, b)
	  {
    if (dateStyle == "dd/mm/yyyy" || dateStyle == "mm/dd/yyyy")						
      {
      // re-order to yyyy/mm/dd
      var thisDateText;
			var aRev;
      var bRev;

      if (dateStyle == "dd/mm/yyyy")
        {
        thisDateText = a.text.split("/");
			  aRev = thisDateText[2] + '/' + thisDateText[1] + '/' + thisDateText[0];
        thisDateText = b.text.split("/");
        bRev = thisDateText[2] + '/' + thisDateText[1] + '/' + thisDateText[0];
				}
      else if (dateStyle == "mm/dd/yyyy")
			  {
        thisDateText = a.text.split("/");
			  aRev = thisDateText[2] + '/' + thisDateText[0] + '/' + thisDateText[1];
        thisDateText = b.text.split("/");
        bRev = thisDateText[2] + '/' + thisDateText[0] + '/' + thisDateText[1];
				}			
		
			if (asc==true)
			  return aRev == bRev ? 0 : aRev < bRev ? -1 : 1
      else				
			  return aRev == bRev ? 0 : aRev < bRev ? 1 : -1
      }				
    else
      {
      // assume yyyy/mm/dd
			 if (asc==true)
			   return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
			else
			  return a.text == b.text ? 0 : a.text < b.text ? 1 : -1
      }						
    }));
    // Select the originally selected option.
    $(selectId).val(selectedValue);

	}
	

Date.prototype.getMonthName = function()
  {
  var m = ['January','February','March','April','May','June','July','August','September','October','November','December'];
  return m[this.getMonth()];
  }

Date.prototype.getDayName = function()
  {
  var d = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  return d[this.getDay()];
  }

function daysInMonth(month,year)
  {
  var m = [31,28,31,30,31,30,31,31,30,31,30,31];
  if (month != 2) return m[month - 1];
  if (year%4 != 0) return m[1];
  if (year%100 == 0 && year%400 != 0) return m[1];
  return m[1] + 1;
  }

function setFirstDayByName(thisDate, thisStartDay)
  {
  thisDate.setDate(1); // Start from 1st day
  while (thisDate.getDayName().toUpperCase().indexOf(thisStartDay.toUpperCase()) == -1)
    {
    thisDate.setDate(thisDate.getDate() + 1);
    }
  }

function setLastDayByName(thisDate, thisStartDay)
  {
  thisDate.setDate(daysInMonth(thisDate.getMonth()+1, thisDate.getFullYear())); // Start from last day of this month
  while (thisDate.getDayName().toUpperCase().indexOf(thisStartDay.toUpperCase()) == -1)
    {
    thisDate.setDate(thisDate.getDate() - 1);
    }
  }
	
function setFirstDayByDayNameIndex(thisDate, thisIndex, thisStartDayName)
  {
  var count = 0;
	for (var i = 0; count < thisIndex; i ++ )
	  {
		if (thisDate.getDayName().toUpperCase().indexOf(thisStartDayName.toUpperCase()) != -1)
      {
			count ++; // count this day name instance
      if (count == thisIndex) break;
			else thisDate.setDate(thisDate.getDate() + 1);
			}
		else 	thisDate.setDate(thisDate.getDate() + 1);
		}
  }

function setLastDayByDayNameIndex(thisDate, thisIndex, thisEndDayName)
  {
  var count = 0;
	for (var i = 0; count < thisIndex; i ++ )
	  {
		if (thisDate.getDayName().toUpperCase().indexOf(thisEndDayName.toUpperCase()) != -1)
      {
			count ++; // count this day name instance
      if (count == thisIndex) break;
			else thisDate.setDate(thisDate.getDate() + 1);
			}
		else 	thisDate.setDate(thisDate.getDate() + 1);
		}
  }

//var menuids=new Array("verticalmenu") //Enter id(s) of UL menus, separated by commas
var menuids=["verticalmenu"]
var submenuoffset=-12 //Offset of submenus from main menu. Default is -2 pixels.

function createcssmenu()
{
if (document.getElementById(menuids[0]))
  {
  setTimeout("createFunc()", 100);
  }
}

function createFunc()
  {
  for (var i=0; i<menuids.length; i++)
    {
    var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++)
      {
      var spanref=document.createElement("span")
		  spanref.className="arrowdiv"
		  spanref.innerHTML="&nbsp;&nbsp;"
		  ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
      ultags[t].parentNode.onmouseover=function()
        {
        this.style.zIndex=10000
        this.getElementsByTagName("ul")[0].style.left=this.parentNode.offsetWidth+submenuoffset+"px"
        this.getElementsByTagName("ul")[0].style.display="block"
        //this.getElementsByTagName("ul")[0].style.zIndex=0
        }
      ultags[t].parentNode.onmouseout=function()
        {
        this.style.zIndex=0;
        this.getElementsByTagName("ul")[0].style.display="none"
        this.getElementsByTagName("ul")[0].style.zIndex=0;
        }
      ultags[t].onmouseup=function(){setLoadingImage()};
      }
    }
  }


if (window.addEventListener)
  window.addEventListener("load", createcssmenu, false);
else if (window.attachEvent)
  window.attachEvent("onload", createcssmenu);
