/* ########################################################################################
 *
 *  utilities.js
 *    General utilty functions
 *
 *  WIREGROOVE TECHNOLOGY, LLC
 *  Copyright (c) 2009.  All rights reserved.
 *
 *   Date      Author              Description
 *   --------  -----------------   -----------------------------------------------------
 *   09/2009   Donny M. Hansen     Modified form.
 *
 * ######################################################################################## */

function copyAddress() {
    if(document.frmEditRecord.billingSameAsPhysical.checked){
        document.frmEditRecord.billingAddressOne.value = document.frmEditRecord.physicalAddressOne.value;
        document.frmEditRecord.billingAddressTwo.value = document.frmEditRecord.physicalAddressTwo.value;
        document.frmEditRecord.billingAddressThree.value = document.frmEditRecord.physicalAddressThree.value;
        document.frmEditRecord.billingCity.value = document.frmEditRecord.physicalCity.value;
        document.frmEditRecord.billingState.value = document.frmEditRecord.physicalState.value;
        document.frmEditRecord.billingZip.value = document.frmEditRecord.physicalZip.value;
    } else {
        document.frmEditRecord.billingAddressOne.value = '';
        document.frmEditRecord.billingAddressTwo.value = '';
        document.frmEditRecord.billingAddressThree.value = '';
        document.frmEditRecord.billingCity.value = '';
        document.frmEditRecord.billingState.value = '--';
        document.frmEditRecord.billingZip.value = '';
    }
}

// This function is used in the plantView.php file to show the large image of a thumbnail
function showPic (link, ownerId) {
  document.getElementById('mainImage').src = link;
  document.getElementById('ownerInfo').childNodes[0].nodeValue = 'Photo courtesy of'+owner;
}

// function to check browser compatibility with the site
function browserCheck(pageType) {
  var MIN_FIREFOX_VERSION = 3;
  var MIN_IE_VERSION = 7;

  var nVer = navigator.appVersion;
  var nAgt = navigator.userAgent;
  var browserName  = navigator.appName;
  var fullVersion  = ''+parseFloat(navigator.appVersion);
  var majorVersion = parseInt(navigator.appVersion,10);
  var nameOffset,verOffset,ix;

  // In MSIE, the true version is after "MSIE" in userAgent
  if ((verOffset=nAgt.indexOf("MSIE"))!=-1) {
   browserName = "Microsoft Internet Explorer";
   fullVersion = nAgt.substring(verOffset+5);
  }
  // In Opera, the true version is after "Opera"
  else if ((verOffset=nAgt.indexOf("Opera"))!=-1) {
   browserName = "Opera";
   fullVersion = nAgt.substring(verOffset+6);
  }
  // In Chrome, the true version is after "Chrome"
  else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) {
   browserName = "Chrome";
   fullVersion = nAgt.substring(verOffset+7);
  }
  // In Safari, the true version is after "Safari"
  else if ((verOffset=nAgt.indexOf("Safari"))!=-1) {
   browserName = "Safari";
   fullVersion = nAgt.substring(verOffset+7);
  }
  // In Firefox, the true version is after "Firefox"
  else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) {
   browserName = "Firefox";
   fullVersion = nAgt.substring(verOffset+8);
  }
  // In most other browsers, "name/version" is at the end of userAgent
  else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) )
  {
   browserName = nAgt.substring(nameOffset,verOffset);
   fullVersion = nAgt.substring(verOffset+1);
   if (browserName.toLowerCase()==browserName.toUpperCase()) {
    browserName = navigator.appName;
   }
  }
  // trim the fullVersion string at semicolon/space if present
  if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
  if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);

  majorVersion = parseInt(''+fullVersion,10);
  if (isNaN(majorVersion)) {
   fullVersion  = ''+parseFloat(navigator.appVersion);
   majorVersion = parseInt(navigator.appVersion,10);
  }

  if(browserName == 'Firefox'){
    if(majorVersion < MIN_FIREFOX_VERSION){
      location.href = pageType + 'message.php?typeCode=updateFF';
    }
  }

  if(browserName == 'Microsoft Internet Explorer'){
    if(majorVersion < MIN_IE_VERSION){
      location.href = pageType + 'message.php?typeCode=updateIE';
    }
  }

  //alert('Browser name  = '+browserName+'<br>');
  //alert('Full version  = '+fullVersion+'<br>');
  //alert('Major version = '+majorVersion+'<br>');
  //alert('navigator.appName = '+navigator.appName+'<br>');
  //alert('navigator.userAgent = '+navigator.userAgent+'<br>');
}
