///////////////////////////////////////////////////////////////
//
// Function to Open a new window for logging into the GreeHouse App
//
//
///////////////////////////////////////////////////////////////
function LoginToHE()

{
    hePageStat.logPage('greenhouse_login.php');
    //alert("The Green House is down for maintenance\nIt will be back online in the very near future\nPlease check back with us soon");
    window.open("https://go.harvestearnings.com/GreenHouse/Login/Login.aspx","_blank"," resizable=no scrollbars=yes menubar=no location=no status=yes toolbar=no");

}

///////////////////////////////////////////////////////////////
//
// Declare the HE Effects class
//
//
///////////////////////////////////////////////////////////////
var heEffects = {
    makeSlider: function(strFilter) {
        /*
          This setup assumes thatthe slider content area, the open and close knobs are siblings of the same parent div
          It is also assumed that the ID suffix of the open knob is opn and that the class of the div to be slided is defined in the passed var strFilter
        */
        var sliders = [];
        $(strFilter).each(function(sliderIndexl) {

            // save the element to be slided up or down
            var slider = this;

           // get the parent element
            var prnt = $(this).parent();
            
           $(prnt).find(".knob").each(function(knobIndex) {
               var idSufix = $(this).attr("id").substring($(this).attr("id").length-3);
               var opnKnob = null;
               $(this).attr('sliderinex', knobIndex);
               //console.log('idSufix ="'+ idSufix +'"\n sliderIndex=' +sliderIndex );
               if (idSufix == "opn"){
                   //sliders[sliderIndex].openKnob = knob;
                   $(this).click(function(){
                    //  $(slider).toggle();
                      $(slider).slideToggle("slow",function (){
                            //window.location.href= window.location.href.substring(0,window.location.href.indexOf('#')) + '#' + $(prnt).find('a[name$="opn"]').attr('name');
                            $.scrollTo($(prnt).find('a[name$="opn"]'),1500);
                          });
                      $(this).toggle();
                   });
               } else {
                   //sliders[sliderIndex].closeKnob = knob;
                   $(this).click(function(){
                      $(prnt).find('a[id$="opn"]').toggle();
                      $(slider).slideToggle('slow',function (){
                            //window.location.href= window.location.href.substring(0,window.location.href.indexOf('#')) + '#' + $(prnt).find('a[name$="opn"]').attr('name');
                            $.scrollTo($(prnt).find('a[name$="opn"]'),1500);
                          });
                   });
               }
              });
        });
    },
    hideValidaitons : function(selector){
       $(selector).validationEngine('hideAll');
    }
};

///////////////////////////////////////////////////////////////
//
// Declare the HE page Stat class
//
//
///////////////////////////////////////////////////////////////
var hePageStat = {
   pausecomp : function (wtsms){
      wtsd = new Date();
      while (1){
         wtsmill=new Date();
         wtsdiff = wtsmill-wtsd;
         if(wtsdiff > wtsms){
           break;
         }
      }
   },
   
   // Get the URL to use for logging the visit
   getLogURL : function (page_name){
      var uid ='al224786';
      var dbn = '3';
      var ssl = 'http';
      var invisible = '';
      var text_counter ='';
   
      if (! page_name || page_name == '#'){
         page_name = '';
      }
   
      if (page_name.indexOf(' ')> -1 ){
         page_name = page_name.replace(/ /gi,'_');
         page_name += '.php'
      }
   
   
      if (document.location.protocol == 'https:' || ssl == 'https'){
         var prefix = 'https';
      }
      else {
         var prefix = 'http';
      }
   
      if (dbn == 1){
         var prefix = prefix+'://server2.web-stat.com';
      }
      else if (dbn == 2){
         var prefix = prefix+'://server3.web-stat.com';
      }
      else if (dbn == 3){
         var prefix = prefix+'://server4.web-stat.com';
      }
      else if (dbn == 4){
         var prefix = prefix+'://server2.web-stat.com';
      }
      else {
         var prefix = prefix+'://server2.web-stat.com';
      }
   
   
      try { var wtsb=top.document;
            var wtsr=wtsb.referrer;
            var wtsu=wtsb.URL;
          }
      catch(e){ var wtsb=document;
                var wtsr=wtsb.referrer;
                var wtsu=wtsb.URL;
              }
      // Make sure the 'URL' is the same as the page name
      wtsu=page_name;
   
      var qry= uid+':'+ dbn +'::'+ escape(wtsr) +'::'
             + screen.width+'x'+screen.height+'::'+screen.colorDepth+'::'
             + escape(page_name)+'::'+invisible+'::'+Math.random()+'::'
             + escape(wtsu)+'::'+escape(document.title)+'::'+navigator.cookieEnabled;
   
     // Finish the full URL
     var ajaxURL = prefix +'/count.pl?' + qry ;
     return ajaxURL
   
   },

   logPage : function(page_name){
     var ajaxURL = this.getLogURL(page_name);
     // Now we need to perform an AJAX call to record teh visit
     //$.get(ajaxURL);
      $('#webstatlog').append('<img src="'+ ajaxURL + '" />');
      this.pausecomp(500);
      $('#webstatlog').empty();
   }
};



