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 getXposition(whichelement)
  {
  var xpos = 0;
  if (whichelement.offsetParent)
	  {
    while (whichelement.offsetParent)
		  {
      xpos += whichelement.offsetLeft
      whichelement = whichelement.offsetParent;
      }
    }
  return xpos;
  }
	
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()
  {
  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('<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,32);
var left = (getWinWidth()/2) - 35;
var bTop;

if (isIE)
  {
  preloadedImg.src = 'mcIncludes/LoadingtestTube.jpg';
  }
else
 preloadedImg.src = 'mcIncludes/pageLoadingAnim.gif';


function setLoadingImage(newTop)
  {
  left = (getWinWidth()/2) - 30;
  if (isIE) left = left - 15;

  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";
  document.images['loadingImage'].style.zindex = 10000;

  if (isIE)
    {
    left -=40;
    document.images['loadingImage'].style.width="100px";
    document.images['loadingImage'].style.height="35px";
    document.images['loadingImage'].style.left=left;
    document.images['loadingImage'].style.top=bTop;
    document.images['loadingImage'].style.zIndex = 30000;

	iShake = left;
	iShakeIncr = 1;
	setInterval("shakeLoadingImage()", 10);
    }
  else
    {
    document.images['loadingImage'].style.width="22px";
    document.images['loadingImage'].style.height="22px";
    document.images['loadingImage'].style.left=left;
    document.images['loadingImage'].style.top= bTop;
    document.images['loadingImage'].style.zIndex = 30000;
    }
  }


var iShake;
var iShakeIncr;
function shakeLoadingImage()
  {
  iShake += iShakeIncr;
  document.images['loadingImage'].style.left=iShake + "px";
  if (iShake == (left + 75)) iShakeIncr = -1; if (iShake == left) iShakeIncr = 1;
  };  
  

function hideLoadingImage()
  {
  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;
  if (alertType == "information") {typeImageSrc = "mcIncludes/information2.jpg"; typeColor = "#006400";}
  if (alertType == "error") {typeImageSrc = "mcIncludes/error1.jpg"; typeColor = "#FF0000";}
  if (alertType == "warning") {typeImageSrc = "mcIncludes/exclamation2.jpg"; typeColor = "#D2691E";}
  $.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 style="font-family: verdana; font-size:16px; font-weight:bold; color:black;">' + 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 style="font-family: verdana; font-size:14px; font-weight:bold; color:' + typeColor + ';">' + alertText + '</span><br><br></div><hr style="width:410px; text-align: left; margin: 0 auto 0 0;"><br><!--[if IE]><br><br><![endif]-->'
      }
    );
  };
  
$.strPad = function(i,l,s)
  {
  var o = i.toString();
  if (!s) { s = '0'; }
  while (o.length < l)
    {
    o = s + o;
    }
  return o;
  };

