function menuSwitch( par) {		
	var nxt = par.nextSibling;
	while( nxt != null && nxt.className != "boxBody" ) nxt = nxt.nextSibling;
	
	if( nxt && nxt.className == "boxBody" ) {
		//alert(nxt.className + "/" + nxt.nodeName + "/" + nxt.style.display);
		if( nxt.style.display == "none" || nxt.style.display == "")  {
			nxt.style.display = "block";
		} else {
			nxt.style.display = "none";
		}
	} 
}


startList = function() {
  if( Unicm.Browser.IE && correctPNG ) correctPNG();
  
	if (document.all&&document.getElementById) {		

		navRoot = document.getElementById("docTools");
		for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.className =="bxTitle") {
					node.onmouseover=function() {
						this.nextSibling.style.display="block";
					}
					node.onmouseout=function() {
						this.nextSibling.style.display="none";
					}
				}

				if (node.className=="bxBody") {
					node.onmouseover=function() {
						this.style.display="block";
					}
					node.onmouseout=function() {
						this.style.display="none";
					}
				}
		}		
		navRoot = document.getElementById("docArhiveBox");
		if( navRoot && navRoot.className=="box") {
			navRoot.onmouseover=function() {
				this.firstChild.nextSibling.style.display="block";
			}
			navRoot.onmouseout=function() {
				this.firstChild.nextSibling.style.display="none";
			}
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];

				if (node.className=="bxBody") {
					node.onmouseover=function() {
						this.style.display="block";
					}
					node.onmouseout=function() {
						this.style.display="none";
					}
				}
			}
		}		
	}
  
  var inn = $('inner');
  if( Unicm.Browser.IE && Unicm.IEVer() < 7 ) {
    inn.style.width = "" + (parseInt(inn.offsetWidth)-3) + "px";
  }
}


function Toggle(e) {
	if( !e) return;
	if (e.checked) {
	    Highlight(e);
	    document.list.all.checked = AllChecked();
	} else {
	    Unhighlight(e);
	    document.list.all.checked = false;
	}
}

function ToggleMe(e) {
        if( !e) return;
        if (e.checked) {
            Highlight(e);
	    if( document.list.all) document.list.all.checked = AllChecked();
        } else {
            Unhighlight(e);
            if( document.list.all) document.list.all.checked = false;
        }
}


function ToggleAll(e) {
	if (e.checked) {
	    CheckAll();
	}
	else {
	    ClearAll();
	}
}

function Check(e) {
	e.checked = true;
	Highlight(e);
}


function Clear(e) {
	e.checked = false;
	Unhighlight(e);
}


function CheckAll() {
	var ml = document.list;
	var len = ml.elements.length;
	for (var i = 0; i < len; i++) {
	    var e = ml.elements[i];
	    if (e.type && e.type== "checkbox" && (e.name.indexOf("Id", 0) != -1 || e.name.indexOf("id", 0) != -1))  {
		    Check(e);
	    }
	}
	ml.all.checked = true;
}


function ClearAll()  {
	var ml = document.list;
	var len = ml.elements.length;
	for (var i = 0; i < len; i++) {
	    var e = ml.elements[i];
	    if (e.type && e.type == "checkbox" && (e.name.indexOf("Id", 0)  != -1 || e.name.indexOf("id", 0) != -1)) {
		    Clear(e);
	    }
	}
	ml.all.checked = false;
}


function Highlight(e) {
	var r= null;
    	
	if (e.parentElement) {
	    r = e.parentElement;
	} else if (e.parentNode) {
	    r = e.parentNode;
	}
	
	if ( r.className =="checkbox") {
		 r.className = "highlight";
	}
}


function Unhighlight(e) {
	var r= null;
    	
	if (e.parentNode) {
	    r = e.parentNode;
	} else if (e.parentElement) {
	    r = e.parentElement;
	}
	
	if (r.className =="highlight") {
		 r.className = "checkbox";
	}
}


function AllChecked()
    {
	ml = document.list;
	len = ml.elements.length;
	for(var i = 0 ; i < len ; i++) {
	    if (ml.elements[i].name && (ml.elements[i].name.indexOf("id") != -1 || ml.elements[i].name.indexOf("del") != -1) && !ml.elements[i].checked) {
		return false;
	    }
	}
	return true;
}

function toggleVisibility(elemId, chck){
	var c = null; var p = null; var f = null;
	c = document.getElementById("c"+elemId)
	p = document.getElementById("p"+elemId)
	f = document.getElementById("f"+elemId)
	if(  chck.checked ) {
		if( f) f.className = "visible"
		if( c) c.className = "visible";
		if( p) p.className = "visible";
	} else {
		if( c) c.className = "hidden";
		if( f) f.className = "hidden";
		if( p) p.className = "hidden";
	}
}

/*
function toggleVisibility(elemId, chck){
	var r = null;
	r = document.getElementById(elemId)
	if (r) {
		if( chck.checked ) {
		    r.className = "visible";
		} else {
    		r.className = "hidden";
		}
	}
}
*/

function toggleBiVisibility(elemId, chck){
	var normal = null;
	var alt = null;
	normal = document.getElementById(elemId)
	alt = document.getElementById(elemId + "Alt")
	if (normal && alt) {
		if( chck.checked ) {
			normal.className = "hidden";
		    alt.className = "visibleS";
		} else {
			normal.className = "visibleS";
		    alt.className = "hidden";
		}
	}
}

function delBox(titlu, url ) {
  if ( confirm( titlu ) ) {
        location.href=url
  }
}

function delBoxNoUrl(titlu ) {
  return confirm( titlu );
}




// This next little bit of code tests whether the user accepts cookies.
var WM_acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
    if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) {
	WM_acceptsCookies = true; 
    }// If it succeeds, set variable
} else { // there was already a cookie
  WM_acceptsCookies = true;
}


function WM_setCookie (name, value, hours, path, domain, secure) {
    if (WM_acceptsCookies) { // Don't waste your time if the browser doesn't accept cookies.
	var not_NN2 = (navigator && navigator.appName 
		       && (navigator.appName == 'Netscape') 
		       && navigator.appVersion 
		       && (parseInt(navigator.appVersion) == 2))?false:true;

	if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
    }
} // WM_setCookie


function WM_readCookie(name) {
    if(document.cookie == '') { // there's no cookie, so go no further
	return false; 
    } else { // there is a cookie
	var firstChar, lastChar;
	var theBigCookie = document.cookie;
	firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
	var NN2Hack = firstChar + name.length;
	if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
	    if(lastChar == -1) lastChar = theBigCookie.length;
	    return unescape(theBigCookie.substring(firstChar, lastChar));
	} else { // If there was no cookie of that name, return false.
	    return false;
	}
    }	
} // WM_readCookie

function WM_killCookie(name, path, domain) {
  var theValue = WM_readCookie(name); // We need the value to kill the cookie
  if(theValue) {
      document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
  }
} // WM_killCookie


function switchLang(value) {
	WM_killCookie("language", null, null);
	if( value != "" )  {
		WM_setCookie("language", value, 24*365*10, "/", null, false);
	}	
	document.forms['langSwitchForm'].submit();
}

//window.onload=startList;	

if( typeof(Unicm) == 'undefined') Unicm = {};

Unicm.Browser = {
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
}

function $(element) {  
  if (typeof element == 'string') element = document.getElementById(element);
  return element;
}

Unicm.HideOnOut= function(event) {
  if (typeof(event) == 'undefined') event = window.event;
  var tg = $(event.target || event.srcElement);
  if (tg.nodeName != 'DIV') return;
  var reltg = $(event.relatedTarget || event.toElement);
  while (reltg != tg && reltg.nodeName != 'BODY') reltg= reltg.parentNode
  if (reltg== tg) return;
  if( tg && tg.style ) {  
    tg.style.display = "none"; 
  }
}

Unicm.ShowAsAbsolute = function(idOrInstance, positionElem) {
  idOrInstance = $(idOrInstance);  
  if( typeof(positionElem) != 'undefined') positionElem = $(positionElem);
  
  if( positionElem)  {
    var elPos = Unicm.positionedOffset(positionElem);
    idOrInstance.style.left = "" + (elPos.left + parseInt(positionElem.offsetWidth) + 5 - 400) + "px";
    idOrInstance.style.top = "" + elPos.top + "px";
    idOrInstance.style.position = "absolute";
  } else {
    Unicm.absolutize(idOrInstance);
  }
  if( idOrInstance && idOrInstance.style ) idOrInstance.style.display = 'block';
}


Unicm.returnOffset = function(l, t) {
  var result = [l, t];
  result.left = l;
  result.top = t;
  return result;
}


Unicm.positionedOffset = function(element) {
    var valueT = 0, valueL = 0;
    do {
      valueT += element.offsetTop  || 0;
      valueL += element.offsetLeft || 0;
      element = element.offsetParent;
      if (element) {
        if (element.tagName == 'BODY') break;
        var p = element.style.position;
        if (p == 'relative' || p == 'absolute') break;
      }
    } while (element);
    return Unicm.returnOffset(valueL, valueT);
}


 Unicm.absolutize = function(element) {
    element = $(element);
    if (element.style.position == 'absolute') return;

    var offsets = Unicm.positionedOffset(element);
    var top     = offsets[1];
    var left    = offsets[0];
    var width   = element.clientWidth;
    var height  = element.clientHeight;

    element._originalLeft   = left - parseFloat(element.style.left  || 0);
    element._originalTop    = top  - parseFloat(element.style.top || 0);
    element._originalWidth  = element.style.width;
    element._originalHeight = element.style.height;

    element.style.position = 'absolute';
    element.style.top    = top + 'px';
    element.style.left   = left + 'px';
    element.style.width  = width + 'px';
    element.style.height = height + 'px';
    return element;
  }
  
  
Unicm.MenuToggle = function(startNode) {
  startNode = $(startNode);
  
  var getParent = function() {
    var result = startNode;
    while( result && (result.tagName != 'LI' || result.className != "menuItem")) result = result.parentNode;
    if( result && result.tagName == 'LI' && result.className == "menuItem") return result;
    return null;
  }
  
  var getMenuBlock = function(navRoot) {
    var idx, childNode;
    for (idx=0; idx<navRoot.childNodes.length; idx++) {
        childNode = navRoot.childNodes[idx];
        if( childNode && childNode.tagName == 'UL' && childNode.className == 'menu') return childNode;        
    }
  }
  
  var menuBlock = getMenuBlock(getParent());
  if( menuBlock) {    
    if( menuBlock.style.display == 'none' ||  menuBlock.style.display == '') menuBlock.style.display = 'block';
    else menuBlock.style.display = 'none';
  }
  return false;
} 




/* 
 *
 */
function correctPNG()  {
   for(var i=0; i<document.images.length; i++) {
    var img = document.images[i]
    var imgName = img.src.toUpperCase()
    if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
     var imgID = (img.id) ? "id='" + img.id + "' " : ""
     var imgClass = (img.className) ? "class='" + img.className + "' " : ""
     var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
     var imgStyle = "display:inline-block;" + img.style.cssText 
     if (img.align == "left") imgStyle = "float:left;" + imgStyle
     if (img.align == "right") imgStyle = "float:right;" + imgStyle
     if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
     var strNewHTML = "<span " + imgID + imgClass + imgTitle
     + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
       + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
     + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
     img.outerHTML = strNewHTML
     i = i-1
       }
      }
} 


/*
 *
 */
function editCombo(idName) {
  var editBox = document.getElementById(idName + ".edit");
  var button = document.getElementById(idName + ".editBut");
  var combo = document.getElementById(idName);

  if( editBox.style.display == "none") {
    editBox.value = combo.value;
    combo.style.display = "none";
    editBox.style.display = "inline";
    button.value = "Aplica";
  } else {
    editBox.style.display = "none";
    combo.style.display = "inline";
    button.value = "Modifica";
    if( combo.value != editBox.value ) {
      var new_opt = new Option(editBox.value, editBox.value);
          new_opt.selected = true;
          combo.options[combo.options.length] = new_opt;
    }
  }
}


function reload(widget) {
  if( widget && widget.form) widget.form.submit();
}


function loadDialog(location) {
  window.open(location, 'display', 'width=640,height=325,location=yes,depend');
  return false
} 


Unicm.IEVer = function() {
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer') {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}
