
function SlideInfoBox(vchElement, intBaseTop)
{
  var intNewTop = 0;
  var obj = document.getElementById(vchElement);
  
  if (isNaN(intBaseTop) == true)
     {intBaseTop = 300;}
  
  if (document.body.scrollTop > intBaseTop)
     {intNewTop = document.body.scrollTop;}
  else
     {intNewTop = intBaseTop;}
  
  obj.style.y = intNewTop;
  obj.style.top = obj.style.y;
     
 return -1;
}


function Trim(vchString)
{
 try
    {
     if (vchString.length < 1){return "";}
     
     while(vchString.indexOf(" ") == 0) 
        {vchString = vchString.substr(1, vchString.length - 1);}
     
     if (vchString.length < 1){return "";}
     
     while(vchString.lastIndexOf(" ") == vchString.length -1) 
        {vchString = vchString.substr(0, vchString.length - 1);}


     return vchString;
    }
 catch (err)
    {
     status = err;
     return "";
    }

}


/* ---------------------------------------------------------------------------------------
   Sets a new image reference for an img object
   
   obj = Name (id) of the respective img object
   FileName = Path and filename of the new picture reference
--------------------------------------------------------------------------------------- */
function SetImageSource(obj, FileName)
{
  if (!obj){return};
  document.images[obj].src = FileName;
}

/* ---------------------------------------------------------------------------------------
   Returns the object.style property
   
   obj = Name (id) of the respective (div) object
--------------------------------------------------------------------------------------- */
function GetObjectStyle(obj)
{
  
  if (document.all)
     {return document.all[obj].style;}
  else if (document.getElementById)
     {return document.getElementById(obj).style;}

}


//-----------------------------------------------------------------------------------------------------
//  Code created and compiled May 8, 2000  by Duncan Kabinu, Florida Department
//  of Agriculture.  This code may be used free of charge for any purpose as long as
//  this notice is left intact. Feedback would be greatly appreciated, send email to
//  kabinud@doacs.state.fl.us

function weekNo(now) {
  var totalDays = 0;         
  var days = new Array(12);   // Array to hold the total days in a month
  days[0] = 31;
  days[2] = 31;
  days[3] = 30;
  days[4] = 31;
  days[5] = 30;
  days[6] = 31;
  days[7] = 31;
  days[8] = 30;
  days[9] = 31;
  days[10] = 30;
  days[11] = 31;

  //  Check to see if this is a leap year

   if (Math.round(now.getYear()/4) == now.getYear()/4) {
     days[1] = 29
  }else{
     days[1] = 28
  }

//  If this is January no need for any fancy calculation otherwise figure out the
//  total number of days to date and then determine what week

  if (now.getMonth() == 0) {      
     totalDays = totalDays + now.getDate();
  }else{
     var curMonth = now.getMonth();
     for (var count = 1; count <= curMonth; count++) {
         totalDays = totalDays + days[count - 1];
     }
     totalDays = totalDays + now.getDate();
   }
   var week = Math.round(totalDays/7);

 return week;
}

/* ---------------------------------------------------------------------------------------
   Validates a date input and return the date format dd.mm.yyyy or a number
   
   0 = empty string
   -1 = invalid input
   -2 = date to far away e.g. before 1.1.1970
   -3 = unknown error
   
   vchDateString = date input as string
--------------------------------------------------------------------------------------- */
 function CheckDateInput(vchDateString)
 {
   try
     {
      if (Trim(vchDateString) == "")
         {return 0;}
         
      var vchDateParts = vchDateString.split(".");
      
      if (isNaN(vchDateParts[0]) == true || isNaN(vchDateParts[1]) == true || isNaN(vchDateParts[2] == true))
         {return -1;}
         
      vchDateParts[1] = vchDateParts[1] - 1; //Month starts with 0 in JavaScript!!
      
      var dDate = new Date(vchDateParts[2], vchDateParts[1], vchDateParts[0], 12,0,0);
      if (dDate.getTime() < 0)
         {return -2;}
      
      var vchResult = dDate.getDate() + '.' + (dDate.getMonth()+1) + '.' + dDate.getYear();
      var intNewValue = dDate.getTime() / 1000;
      
      return intNewValue;
     }
  catch (err)
     {return -3;}
  
 }


function MarkMenu(vchObject, intHighlight)
{
 obj = document.getElementById(vchObject);
 if (intHighlight == -1)
    {
     obj.style.backgroundColor = 'navy';
     obj.style.color = 'white';
    }
 else
    {
     obj.style.backgroundColor = '#D4D0C8';
     obj.style.color = 'black';
    }
} 


function CheckTextLength(obj, intMaxLength)
{
 if (obj.value.length > intMaxLength)
    {
     var vchText = obj.value;
     obj.value = vchText.substring(0, intMaxLength);
     return true;
    }
 else
    {return true;}
}

        
