// JavaScript Document
/*************************************************************************
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2003 by Sharon Paine
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/
var temp_id;
var cert_name;
var img_caption ;
var image_type; //---//enhancement Image Type Can be JEG or PNG on 01-Dec-2008
var menuLayers = {
  timer: null,
  activeMenuID: null,
  offX: 4,   // horizontal offset
  offY: 6,   // vertical offset
  show: function(id, e,temp,cert, gPath, imageType) { //---//enhancement (added one more parameter) Image Type Can be JEG or PNG on 01-Dec-2008
  	temp_id=temp;
  	img_Path=gPath;
  	image_type = imageType; //---//enhancement Image Type Can be JEG or PNG on 01-Dec-2008
	
  	cert_name = cert;
    var mnu = document.getElementById? document.getElementById(id): null;
    if (!mnu) return;
    this.activeMenuID = id;
    if ( mnu.onmouseout == null ) mnu.onmouseout = this.mouseoutCheck;
    if ( mnu.onmouseover == null ) mnu.onmouseover = this.clearTimer;
    viewport.getAll();
    this.position(mnu,e);
  },

  hide: function() {
    this.clearTimer();
    if (this.activeMenuID && document.getElementById)
      this.timer = setTimeout("document.getElementById('"+menuLayers.activeMenuID+"').style.visibility = 'hidden'", 200);
  },

  position: function(mnu, e) {

    var x = e.pageX? e.pageX: e.clientX + viewport.scrollX;
    var y = e.pageY? e.pageY: e.clientY + viewport.scrollY;

    if ( x + mnu.offsetWidth + this.offX > viewport.width + viewport.scrollX )
      x = x - mnu.offsetWidth - this.offX;
    else x = x + this.offX;

    if ( y + mnu.offsetHeight + this.offY > viewport.height + viewport.scrollY )
      y = ( y - mnu.offsetHeight - this.offY > viewport.scrollY )? y - mnu.offsetHeight - this.offY : viewport.height + viewport.scrollY - mnu.offsetHeight;
    else y = y + this.offY;

    mnu.style.left = x + "px"; mnu.style.top = y + "px";
    //alert(menuLayers.activeMenuID);
    //img_path = "./certificates/template"+temp_id+"_large_600.jpg";
    img_path = img_Path+"/certificates/template"+temp_id+"_large_600."+image_type;//---//enhancement Image Type Can be JEG or PNG on 01-Dec-2008
    
    //if(cert_name)img_path ="./previews/"+cert_name+"_600.png";
    //if(cert_name)img_path ="./samples/"+cert_name+"_400.jpg";
    if(cert_name)img_path = img_Path+"/samples/"+cert_name+"_400."+image_type;//---//enhancement Image Type Can be JEG or PNG on 01-Dec-2008
    
    //alert(img_path);
    
    if(document.getElementById('imgpath')) 
    {
  		document.getElementById('imgpath').src = img_path;
  		document.getElementById('imgpath').value = temp_id;
  	}
	
  	img_caption = "img_text"+temp_id;

	//if(document.getElementById('fulltext')) document.getElementById('fulltext').innerHTML = document.getElementById(img_caption).value;
  	this.timer = setTimeout("document.getElementById('" + menuLayers.activeMenuID + "').style.visibility = 'visible'", 200);
  },

  mouseoutCheck: function(e) {
    e = e? e: window.event;
    // is element moused into contained by menu? or is it menu (ul or li or a to menu div)?
    var mnu = document.getElementById(menuLayers.activeMenuID);
    var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
    if ( mnu != toEl && !menuLayers.contained(toEl, mnu) ) menuLayers.hide();
  },

  // returns true of oNode is contained by oCont (container)
  contained: function(oNode, oCont) {
    if (!oNode) return; // in case alt-tab away while hovering (prevent error)
    while ( oNode = oNode.parentNode )
      if ( oNode == oCont ) return true;
    return false;
  },

  
  clearTimer: function() {
    if (menuLayers.timer) clearTimeout(menuLayers.timer);
  }

}