/**
 * Copyright (c)2005-2007 Matt Kruse (javascripttoolbox.com)
 * 
 * Dual licensed under the MIT and GPL licenses. 
 * This basically means you can use this code however you want for
 * free, but don't claim to have written it yourself!
 * Donations always accepted: http://www.JavascriptToolbox.com/donate/
 * 
 * Please do not link to the .js files on javascripttoolbox.com from
 * your site. Copy the files locally to your server instead.
 * 
 */
var Position = (function() {
  // Resolve a string identifier to an object
  // ========================================
  function resolveObject(s) {
    if (document.getElementById && document.getElementById(s)!=null) {
      return document.getElementById(s);
    }
    else if (document.all && document.all[s]!=null) {
      return document.all[s];
    }
    else if (document.anchors && document.anchors.length && document.anchors.length>0 && document.anchors[0].x) {
      for (var i=0; i<document.anchors.length; i++) {
        if (document.anchors[i].name==s) { 
          return document.anchors[i]
        }
      }
    }
  }
  
  var pos = {};
  pos.$VERSION = 1.0;
  
  // Set the position of an object
  // =============================
  pos.set = function(o,left,top) {
    if (typeof(o)=="string") {
      o = resolveObject(o);
    }
    if (o==null || !o.style) {
      return false;
    }
    
    // If the second parameter is an object, it is assumed to be the result of getPosition()
    if (typeof(left)=="object") {
      var pos = left;
      left = pos.left;
      top = pos.top;
    }
    
    o.style.left = left + "px";
    o.style.top = top + "px";
    return true;
  };
  
  // Retrieve the position and size of an object
  // ===========================================
  pos.get = function(o) {
    var fixBrowserQuirks = true;
      // If a string is passed in instead of an object ref, resolve it
    if (typeof(o)=="string") {
      o = resolveObject(o);
    }
    
    if (o==null) {
      return null;
    }
    
    var left = 0;
    var top = 0;
    var width = 0;
    var height = 0;
    var parentNode = null;
    var offsetParent = null;
  
    
    offsetParent = o.offsetParent;
    var originalObject = o;
    var el = o; // "el" will be nodes as we walk up, "o" will be saved for offsetParent references
    while (el.parentNode!=null) {
      el = el.parentNode;
      if (el.offsetParent==null) {
      }
      else {
        var considerScroll = true;
        /*
        In Opera, if parentNode of the first object is scrollable, then offsetLeft/offsetTop already 
        take its scroll position into account. If elements further up the chain are scrollable, their 
        scroll offsets still need to be added in. And for some reason, TR nodes have a scrolltop value
        which must be ignored.
        */
        if (fixBrowserQuirks && window.opera) {
          if (el==originalObject.parentNode || el.nodeName=="TR") {
            considerScroll = false;
          }
        }
        if (considerScroll) {
          if (el.scrollTop && el.scrollTop>0) {
            top -= el.scrollTop;
          }
          if (el.scrollLeft && el.scrollLeft>0) {
            left -= el.scrollLeft;
          }
        }
      }
      // If this node is also the offsetParent, add on the offsets and reset to the new offsetParent
      if (el == offsetParent) {
        left += o.offsetLeft;
        if (el.clientLeft && el.nodeName!="TABLE") { 
          left += el.clientLeft;
        }
        top += o.offsetTop;
        if (el.clientTop && el.nodeName!="TABLE") {
          top += el.clientTop;
        }
        o = el;
        if (o.offsetParent==null) {
          if (o.offsetLeft) {
            left += o.offsetLeft;
          }
          if (o.offsetTop) {
            top += o.offsetTop;
          }
        }
        offsetParent = o.offsetParent;
      }
    }
    
  
    if (originalObject.offsetWidth) {
      width = originalObject.offsetWidth;
    }
    if (originalObject.offsetHeight) {
      height = originalObject.offsetHeight;
    }
    
    return {'left':left, 'top':top, 'width':width, 'height':height
        };
  };
  
  // Retrieve the position of an object's center point
  // =================================================
  pos.getCenter = function(o) {
    var c = this.get(o);
    if (c==null) { return null; }
    c.left = c.left + (c.width/2);
    c.top = c.top + (c.height/2);
    return c;
  };
  
  return pos;
})();

	



/* ====================================================================== */

function fcastGraphSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) 
  {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } 
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

//var x = 0;
var tempLink = '';
//for (j in document.links)
for (x=0;x<=document.links.length-1;x++)
{
  
  tempLink = document.links[x].href;
  if (tempLink.match("getFcastGraphList.do") || tempLink.match("getIceWebMap.do") || tempLink.match("getIceWebStatusMap.do") || tempLink.match("getOrgWindDisplay.do")) 
  {
    document.links[x].href = document.links[x].href + "?x="+myWidth+"&y="+myHeight;
  }
  //x++;
  
}


/* for (i=1;i<=document.forms.length-1;i++)
{
 document.forms[i].screenResHeight.value = myHeight;
 document.forms[i].screenResWidth.value = myWidth;
}
// document.forms[3].screenResHeight.value = myHeight; 

*/

 
}


function open_win() 
{
window.open("graphKey.jsp","SameWindow","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=400, height=400");
}

function updateSelectBox()
{
  var dateString = document.getElementById("tDate");
  var daySelect = document.getElementById("startDay");
  var monthSelect = document.getElementById("startMonth");
  var yearSelect = document.getElementById("startYear");
  var hourSelect = document.getElementById("startHour");
  var minSelect = document.getElementById("startMin");


  daySelect.selectedIndex = dateString.value.substring(0,2); 
  monthSelect.selectedIndex = dateString.value.substring(3,5); 
  //var yearIndex = parseInt(dateString.value.substring(8,10)) + parseInt(1);
  yearSelect.selectedIndex = dateString.value.substring(8,10); 
  yearSelect.selectedIndex = yearSelect.selectedIndex + 1;
  if (hourSelect != null)
  {
    hourSelect.selectedIndex = dateString.value.substring(11,13);
    hourSelect.selectedIndex = hourSelect.selectedIndex + 1;
    minSelect.selectedIndex = dateString.value.substring(14,16);
    minSelect.selectedIndex = minSelect.selectedIndex +1;
  }

}



function updateSelectBox2()
{
  var dateString = document.getElementById("tDate");
  var daySelect = document.getElementById("endDay");
  var monthSelect = document.getElementById("endMonth");
  var yearSelect = document.getElementById("endYear");
  var hourSelect = document.getElementById("endHour");
  var minSelect = document.getElementById("endMin");


  daySelect.selectedIndex = dateString.value.substring(0,2); 
  monthSelect.selectedIndex = dateString.value.substring(3,5); 
  //var yearIndex = parseInt(dateString.value.substring(8,10)) + parseInt(1);
  yearSelect.selectedIndex = dateString.value.substring(8,10); 
  yearSelect.selectedIndex = yearSelect.selectedIndex + 1;
  if (hourSelect != null)
  {
    hourSelect.selectedIndex = dateString.value.substring(11,13);
    hourSelect.selectedIndex = hourSelect.selectedIndex + 1;
    minSelect.selectedIndex = dateString.value.substring(14,16);
    minSelect.selectedIndex = minSelect.selectedIndex +1;
  }

}



function loadTopMenu() 
{	
if (document.all&&document.getElementById) 
 {		
  menunavParent = document.getElementById("nav");	
	
   for (x=0; x < menunavParent.childNodes.length; x++) 
     {		
        menunode = menunavParent.childNodes[x];
			
           if (menunode.nodeName=="LI") 
             {			
              menunode.onmouseover=function() 
                {				
                this.className+=" over";			
                }			
                menunode.onmouseout=function() 
                {				
                  this.className=this.className.replace(" over", "");
	  }
           }
        }
     }
}


function obsGraphSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) 
  {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } 
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  document.GraphConfigFormBean.screenResWidth.value = myWidth;
  document.GraphConfigFormBean.screenResHeight.value = myHeight;
  // window.alert( 'Width x= ' + myWidth + ' and height y = ' + myHeight );
}


function toggleSaveZoom()
{
  
  var panel = document.getElementById("saveZoom");
  if (panel.style.visibility == 'hidden')
  {
    panel.style.visibility = 'visible';
    window.location.hash='savePanel';
  }
  else
  {
    panel.style.visibility = 'hidden';
  }

}


/*
function findPos(obj) 
{
  var frame = document.getElementById("frame");
  var curleft = curtop = 0;
  if (obj.offsetParent) 
  {
    do 
    {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } 
  while (obj = obj.offsetParent);
  }
  alert('pos '+curleft+' : '+curtop);
  frame.top = curtop;
  frame.left = curleft;
  return [curleft,curtop];
}


function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

*/
