//'----------------------------------------------------------------------------
//' %MODULE:
//'   locnsByProdLn.js
//' 
//' %DESCRIPTION: 
//'   Common JavaScript Include 
//'     for use on mapped location pages using pushpins
//'     where locations are shown by product line
//'
//' %AUTHOR:
//'   EDS
//'
//' %ASSUMPTIONS:
//'     Assumes includer defines var SelectedProdLn and sets this
//'     to number of current product line
//'
//' %COPYRIGHT:
//'   Copyright (c) 2006 Electronic Data Systems. All Rights Reserved.
//'
//'----------------------------------------------------------------------------
<!--


   var oAllPins = null;
   var bFree = false;
   
   // -- -1:  Locking disabled;
   // --  0:  Locking enabled; unlocked
   // --  1:  Locking enabled: locked
   // -- -------------------------------------
   var tristateLocking = -1;
   

   function initProdLnSelection (passedProdLn) {
      var oEle = document.getElementById('ddProdLns');
      if (oEle) {

            if ( arguments.length > 0 && passedProdLn.length > 0) {
               // -- check if passed prod line in dropdown
               var bGotIt = false;
               for (var i=0; i < oEle.length; i++) {
                  if (oEle.options[i].value == passedProdLn) {
                     oEle.selectedIndex = i;
                     if (typeof(changeProdLn) != 'undefined') {
                        changeProdLn (oEle);
                     }
                     
                     bGotIt = true;
                     break;
                  }
               }
               if (bGotIt) {
                  // -- nada
               }
               else {
                  oEle.selectedIndex = 0;
               }
            }
            else {
               oEle.selectedIndex=0;
            }
      }
      else {
         oEle = document.getElementById('theProdLnNum');
         if (oEle) {
            SelectedProdLn = oEle.innerHTML;
         }
      }
      return false;
      
   }
   
   function scrollToNextLocn (sEleId) {
      // alert ('ScrollTo:  ' + sEleId);
      var oEle = document.getElementById(sEleId);
      
      var iX = 0;
      var iY = 0;
      
      while (oEle != null) {
         iX += oEle.offsetLeft;
         iY += oEle.offsetTop;
         oEle = oEle.offsetParent;
      }
      
      window.scrollTo(iX,iY);
   
      return false;
   }


   function pinClick (strPinId) {
   
      var rc = false;
      
      if (tristateLocking > -1 ) {
         tristateLocking = 1 - tristateLocking;
         
         if ( typeof ( myPinClick ) != "undefined" ) {
            // -- includer has his own click routine
            rc = myPinClick(strPinId);
         }

      }
      
      return (rc);
   }
   
   
   function showPin (strPinId) {
      
      var rc = false;
      if (bFree && tristateLocking < 1) {
         bFree = false;
         rc = showHideElement (strPinId, true, true);
         bFree = true;
      }
      return rc;
   }

   function hidePin (strPinId) {
      var rc = false;

      if (bFree && tristateLocking < 1) {
         bFree = false;
         rc = showHideElement (strPinId, false, false);
         bFree = true;
      }
      
      return rc;
   }

   function showAllPins() {
      var rc = false;

      if (bFree) { 
         bFree = false;
         rc = showHidePins(true);
         bFree = true;
      }
      
      return rc;
   }


   function hideAllPins() {
      var rc = false;

      if (bFree) {
         bFree = false;
         rc = showHidePins(false);
         bFree = true;
      }
      
      return rc;
   }

   
   
   function pins_onLoad() {
      bFree = true;
      // showHideLinkForAll(false);
   }

   function setPinsObj () {
      if ( self.loading ) return false;

      if (oAllPins == null) {
         oAllPins = document.getElementById("allPins");
         if (oAllPins != null) 
            return true;
         else
            return false;
      }
   }


   function showHideElement (strEleId, bShow, bHideAllFirst) {
      // -- pass the id of the pushpin so
      // -- all locns in that pin are hidden/displayed
      // --
      
      //if ( self.loading ) return false;

      var rc = false;
      var ele = null;
      var strDisplay = "none";
      var arEleIds;
      
      if (bHideAllFirst) {
         showHidePins(false);
      }


      if (bShow) {
         strDisplay = "block";
      }

      arEleIds = strEleId.split(",");
      rc = true;
      
      for(var i=0; i < arEleIds.length; i++) {
         // -- alert ("showHide: " + arEleIds[i]);
         ele = document.getElementById(arEleIds[i]);

         if (ele != null) {
            // -- alert (strEleId + ":" + strDisplay);
            
            // -- if more than one location under pin
            // -- show those with current prodLn;
            // -- hide those without current prodLn
               // -- if hiding the whole pin, don't worry
               // -- about showing/hiding its contained locations
            if (bShow) {
               var oDivs;
               var oCurrLocn;
               
               // -- if more than one location will display,
               // -- all but the last contain a link in the header
               // -- to scroll to next location (Down For More [DFM] link)
               // --
               var oPrevDFMLink = null;
               
               var lNumElements;
               //alert ('doc' + ele.id);
               if (document.getElementById('doc' + ele.id).innerHTML == '1') {
                  // -- only one location in this pin;
                  // -- no work to do
               }
               else {
                  // -- this pin has more than one location
                  // -- traverse locations and show/hide
                  // -- depending on whether they have the
                  // -- current product line

                  oDivs = ele.getElementsByTagName("DIV");
                  lNumElements = oDivs.length;
                  for (var i=0; i < lNumElements; i++) {
                     oCurrLocn = oDivs.item(i);
                     
                     if (oCurrLocn.className == 'rolloverMap' ) {
                        // -- alert (document.getElementById('doc' + oCurrLocn.id).innerHTML + '|' + SelectedProdLn + '|');
                        
                        if ( (SelectedProdLn == '*') || (document.getElementById('doc' + oCurrLocn.id).innerHTML.indexOf(',' + SelectedProdLn + ',') > -1) ) {
                           // -- current prod line in this location
                           oCurrLocn.style.display = "block";
                           
                           // -- hide the current location's DFM link in case
                           // -- it was displayed by a previous prod line
                           document.getElementById('aDFM' + oCurrLocn.id).style.display = 'none';
                           
                           if (oPrevDFMLink != null) {
                              // -- need to show the previous locations DFM link
                              oPrevDFMLink.style.display = 'inline';
                           }
                           oPrevDFMLink = document.getElementById('aDFM' + oCurrLocn.id);
                        }
                        else {
                           oCurrLocn.style.display = "none";
                        }
                     }
                  }
                  
               }
            }
            
            
            ele.style.display = strDisplay;
         }
         else {
            rc = false;
         }
      }

      return rc;

   }


   function showHidePins (bShow) {

      var oPins = null;
      var sID = '';

      var lCount = 0;
      var strDisplay = "none";

      // -- if ( self.loading ) return false;

      setPinsObj();
      if ( oAllPins != null ) {
         if (bShow) {
            strDisplay = "block";
         }
         
         oPins = oAllPins.getElementsByTagName('div');
         
         lCount = oPins.length;

         for (var i=0; i < lCount; i++) {
            sID = oPins.item(i).id;
            if ( sID.length > 2) {
               if (sID.substring(0,3) == 'PIN') {
                  // -- have a push pin DIV
                  // --
                  oPins.item(i).style.display = strDisplay;
               }
            }
         }
         
         // -- hide show all link if already showing all; 
         // -- else show it
         // -- showHideLinkForAll(!bShow);
         
         return true;

      }
      else {
        return false;
      }
   }
   
   function showHideLinkForAll(bShow) {
      var strDisplay = "";
      var oEle;
      
      if (bShow) {
         strDisplay = "block";
      }
      else {
         strDisplay = "none";
      }
      oEle = document.getElementById("rShowAll1");
      oEle.style.display = strDisplay;
   
   }
   


// -->

