var myTimeOut;
var old = "";
var isactive;

function hideTimer(nm) {
     window.myTimeOut = setTimeout("hideLyr('"+nm+"')",500);
     isactive = "";
}
function hideLyr(nm) {
	if(nm != isactive){
		var lyr = document.getElementById(nm);
	    if(!lyr) {return;}
	    lyr.style.visibility = 'hidden';
    }
	manipulateSelects('visible');
}
function cTI(nm){
	isactive = nm;
	if(old!=null && old == nm) { 
		clearTimeout(window.myTimeOut);
	}
}

function manipulateSelects(show) {
	for (var i = 0; i<document.forms[0].elements.length; i++) {
		if (document.forms[0].elements[i].type == 'select-one') {
			document.forms[0].elements[i].style.visibility = show;
		}
	}
}

function showMenu(id, lnk, w, xOffset, yOffset) {
	var lyr = document.getElementById(id);
	var t = document.getElementById(lnk.name);

	var offsTop = 0;
	var offsLeft = 0;
	lyr.style.top = (getAnchorPosition(lnk.name)).y + lnk.offsetHeight + yOffset + 1+"px";
	lyr.style.left = xOffset + ((getAnchorPosition(lnk.name)).x - 10)+"px";

	if(!lyr) {
		return;
	}
	lyr.style.visibility = 'visible';
	if(id!=old && old!="") {	
		var t = document.getElementById(old);
		if(t!=null) { t.style.visibility = 'hidden'; }
	}
	old = id;
	manipulateSelects('hidden');
}

/*
2) Your anchor tag MUST contain both NAME and ID attributes which are the 
   same. For example:
   <A NAME="test" ID="test"> </A>

*/ 
// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		//fix for netscape 7 works fine in ver 6 too
		//		x=o.offsetLeft;
		//		y=o.offsetTop;
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}

function $id(id) {
	return document.getElementById(id);
}
function updateInnerHTML(obj, id, str) {
	$id(id).innerHTML = str;
}
function addClassName(obj, id, strClassName){
	var strCurrentClass = $id(id).className;
	if(!new RegExp(strClassName, "i").test(strCurrentClass)){
		$id(id).className = strCurrentClass + ((strCurrentClass.length > 0)? " " : "") + strClassName;
	}
}
function removeClassName(obj, id, strClassName){
	var oClassToRemove = new RegExp((strClassName + "\s?"), "i");
	$id(id).className = $id(id).className.replace(oClassToRemove, "").replace(/^\s?|\s?$/g, "");
}


function DL_GetElementLeft(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE
                                     
   var nLeftPos = eElement.offsetLeft;       // initialize var to store calculations 
   var eParElement = eElement.offsetParent;  // identify first offset parent element                            

   while (eParElement != null)                 
   {                                         // move up through element hierarchy
      if(DL_bIE)
      {
         if(eParElement.tagName == "TD")     // if parent a table cell, then...
         {
            nLeftPos += eParElement.clientLeft; // append cell border width to calcs
         }
      }

      nLeftPos += eParElement.offsetLeft;    // append left offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nLeftPos;                          // return the number calculated
}
    
function DL_GetElementTop(eElement)
{
   if (!eElement && this)                    // if argument is invalid
   {                                         // (not specified, is null or is 0)
      eElement = this;                       // and function is a method
   }                                         // identify the element as the method owner

   var DL_bIE = document.all ? true : false; // initialize var to identify IE
                                     
   var nTopPos = eElement.offsetTop;       // initialize var to store calculations 
   var eParElement = eElement.offsetParent;  // identify first offset parent element                            

   while (eParElement != null)                 
   {                                         // move up through element hierarchy
      if(DL_bIE)
      {
         if(eParElement.tagName == "TD")     // if parent a table cell, then...
         {
            nTopPos += eParElement.clientTop; // append cell border width to calcs
         }
      }

      nTopPos += eParElement.offsetTop;    // append top offset of parent
      eParElement = eParElement.offsetParent; // and move up the element hierarchy
   }                                         // until no more offset parents exist
   return nTopPos;                          // return the number calculated
}

/*
* for look 2
*/
function prepareMenu(){
  if(document.getElementById && document.getElementsByTagName){
    if(document.getElementById('tabmenu') ){
      var gallery = document.getElementById( 'tabmenu' );
      var links = gallery.getElementsByTagName( 'a' );
      for( var i=0; i < links.length; i++ ){
      	var found = false;
      	if(links[i].parentNode.attributes['class']) {
		    found = links[i].parentNode.attributes['class'].value=='active';
      	} else {
  	     	found = links[i].parentNode.getAttribute('class')=='active';
      	}
      	if(found) {
 			var id = links[i].id.substring(4,5);
 			var m = document.getElementById('sub'+id);
 			if(m) {
 				m.style.visibility = 'visible';
 			}
      	}
      }
    }
  }
}
function addEvent2(obj, evType, fn, useCapture, params){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
  	obj.myparams = params;
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    r.myparams = params;
    return r;
  } else {
    alert("Handler could not be attached");
  }
}

function addEvent(obj,type, fn, p ){
	obj["e"+type+fn] = fn;
	if (obj.addEventListener){
		eval( 'obj.addEventListener( type, function(event){	obj["e"+type+fn](event, ' + p + ')}, false );' 
		);
	} else if (obj.attachEvent){
		obj[type+fn] = function() { 
			eval ( 'obj["e"+type+fn](window.event, ' + p + ');' ); 
		}
		obj.attachEvent("on"+type, obj[type+fn]);
	}
}



addEvent(window, 'load', prepareMenu);UIMessage = new Object();
/**
* private methods
**/
UIMessage._dn = function(uid, msg, cls) {
	addEvent(window, 'load', this._cn, "'"+uid+"', '"+msg+"', '"+cls+"'");
	if(cls=='popup') {
		addEvent(window, 'click', this._cp, "'"+uid+"', '"+msg+"', '"+cls+"'");
	}
}
UIMessage._cp = function(obj, uid, msg, cls) {
	$id('messages').style.display='none';
		
}
UIMessage._cn = function(obj, uid, msg, cls) {
	var doc = $id('messages');
	var newNode = document.createElement('DIV');
	var mess = "";
	if(cls=='popup') {
		mess = "<p>"+ msg+"</p>";
		newNode.className = cls;
	} else {
		mess = '<div class="head"><h5>'+msg+'</h5></div><div class="body">&nbsp;</div>';
		newNode.className = "itembox centerbox "+cls;
	}
	newNode.innerHTML = mess;
	doc.insertBefore(newNode,doc.firstChild);
	var r = $id(uid);
	if(r) {
		r = r.parentNode;
		var n = document.createElement('span');
		n.style.color='#f00';
		n.innerHTML=' (!)';
		r.appendChild(n);
	}
	
}
/**
* public methods
**/

//display node
UIMessage.dn = UIMessage._dn;

