//Functions to check and set the ECM User ID
//Plus other ECM functions
//
//Revised 9/19/11
//Copyright 2009 - 2011 Glicksman Associates Inc.  All rights reserved

var ScriptURL = '../../weboi/oecgi2.exe/'

//function to hide or display an element on a page
//ShowIt can = 'visible' or 'hidden'

function ShowHide(ElementID,ShowIt)
{ 
  if (ElementID.substring(0,7) == "opener_")
    {
      ElementID = ElementID.substring(7);
      var ThisElement=window.opener.document.getElementById(ElementID);
    }
  else
    {
      var ThisElement=document.getElementById(ElementID);
    }
    ThisElement.style.visibility=ShowIt;
}


//function to get a specific cookie
function getCookie(c_name)
{
  if (document.cookie.length>0)
    {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
      {
      c_start=c_start + c_name.length+1;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
      }
    }
  return "";
}
//This sets the ECM_UserID cookie
  function SetUserID(c_value)
  {
    document.cookie = "ECM_USER_ID" + "=" + c_value;
  }

//This checks for the ECM_USERID cookie and sets Variable ECMUserID
function CheckUserID()
{
var ECMUserID = 0;
if (document.cookie.length>0)
  {
  ECMUserID=getCookie('ECM_USER_ID');
  }

}

//Inserts a selected name into the PLANTNAME editline of the search form of the calling window
//and closes the child window
function InsertName(NameText)
  {
    window.opener.document.PLANTSEARCH.PLANTNAME.value = NameText;
    window.opener.document.PLANTSEARCH.PLANTNAME.style.backgroundImage = 'none'
    window.opener.document.PLANTSEARCH.FINDPLANT.click();
    window.close();
  }

//Inserts a selected location code into the LOC_CODE editline of the search form of the calling window
//and closes the child window
function InsertLocation(LocCode)
  {
    window.opener.document.LOCSEARCH.LOC_CODE.value = LocCode;
    window.opener.document.LOCSEARCH.FINDLOC.click();
    window.close();
  }

//Pull up a plant name info sheet in a new tab
function Get_Name_Sheet(NameNum)
  {
    var DetailFl;
    if (document.DetailForm.DetailType[1].checked)
      {DetailFl = 1;}
    else
      {DetailFl = 0;}
    window.location = ScriptURL + 'INET_ECM_DispPl?NAMENUM=' + NameNum + '&DETAIL=' + DetailFl
  }

//Pull up a plant name info sheet in the same tab
function Get_Name_Sheet_Here(NameNum)
  {
    var DetailFl;
    if (document.DetailForm.DetailType[1].checked)
      {DetailFl = 1;}
    else
      {DetailFl = 0;}
    window.location = ScriptURL + 'INET_ECM_DispPl?NAMENUM=' + NameNum + '&DETAIL=' + DetailFl
  }

//Pull up a plant name info sheet in a new tab with dead plants option
function Get_DName_Sheet(NameNum)
  {
    var DeadFl;
    if (document.Options.DeadCheck.checked)
      {DeadFl = 1;}
    else
      {DeadFl = 0;}
    window.open(ScriptURL + 'INET_ECM_DispPl?NAMENUM=' + NameNum + '&INCLUDEDEAD=' + DeadFl)
  }

//Pull up a plant name info sheet in the same tab with dead plants option
function Get_DName_Sheet_Here(NameNum)
  {
    var DeadFl;
    if (document.Options.DeadCheck.checked)
      {DeadFl = 1;}
    else
      {DeadFl = 0;}
    window.location = ScriptURL + 'INET_ECM_DispPl?NAMENUM=' + NameNum + '&INCLUDEDEAD=' + DeadFl
  }

//Pull up a plant name info sheet in the same create a tour popup
function Get_Name_Sheet_Tour(NameNum)
  {
    window.location = ScriptURL + 'INET_ECM_DispPl?NAMENUM=' + NameNum + '&DETAIL=TOUR'
  }

//Pull up a plant info sheet in the same tab
function Get_Plant_Sheet_Here(Accnum, TourMode)
  {
    var DetailFl;
    if (document.DetailForm.DetailType[1].checked)
      {DetailFl = 1;}
    else
      {DetailFl = 0;}
    window.location = ScriptURL + 'INET_ECM_DisplayPlant?ACCNUM=' + Accnum + '&DETAIL=' + DetailFl + '&TOURMODE=' + TourMode
  }

//Add a plant or Garden Feature to a tour
function Tour_Add(RecordKey)
  {
    window.opener.document.EditTour.AddItem.value = RecordKey;
    window.opener.document.EditTour.AddButton.click();
    ShowAlert2('Item Added to Tour', RecordKey + ' has been added.', 'TourConfirm');
    setTimeout("HideAlert2();", 1500);
  }

//Rearrange the tour to start at a particular item
function Tour_Arrange(ItemNumber)
  {
    window.document.EditTour.AddItem.value = 'ARRANGE-' + ItemNumber;
    window.document.EditTour.AddButton.click();
  }

//Delete a plant or Garden Feature from a tour
function Tour_Delete(RecordKey)
  {
    var ans;
    ans=window.confirm('Delete this item from your tour?');
    if (ans==true)
      {
        window.document.EditTour.DeleteItem.value = RecordKey;
        window.document.EditTour.DeleteButton.click();
      }
  }

//Clear a tour
function Tour_Clear()
  {
    var ans;
    ans=window.confirm('Do you wish to clear all items from your tour?');
    if (ans==true)
      {
        window.document.EditTour.DeleteItem.value ='ALL';
        window.document.EditTour.DeleteButton.click();
      }
  }

//Substitute a different image on rollover
function roll_over(img_name, img_src)
   {
   document[img_name].src = img_src;
   }

//Display a Glossary Word
function GlossaryDisplay(GlossaryWord)
  {
    PopupSmallPage(ScriptURL + 'INET_ECM_GLOSSARY_DISPLAY?WORD=' + GlossaryWord);
  }

function CheckNameSpelling()
//Checks if the name entered in the self-test is correct
{
  var RealName = document.TypeNameForm.REALNAME.value;
  var CheckName = document.TypeNameForm.PLANTNAME.value;
  var YesMessage = document.TypeNameForm.YESMSG.value;
  var NoMessage = document.TypeNameForm.NOMSG.value;
  if (CheckName == '')
    {alert('Enter a name please.');}
  else
    {
      if (CheckName == RealName)
        {alert(YesMessage);}
      else
        {alert(NoMessage);}
    }
}

