// muda as class dos níveis anteriores

function menu_mouseOverOut (HEADER,AREA,WHAT) {
	
	if (WHAT == 'OVER') {
		if (AREA) {
		  document.getElementById(AREA+'-header').className 	= 'menuArea_over';
		  document.getElementById(AREA+'-content').className 	= 'submenuArea_over';
		}
      if (HEADER!="" && document.getElementById(HEADER)!=null) {		
         document.getElementById(HEADER).style.display 		= 'block';
		
		   //while(document.getElementById(HEADER).style.display == 'block'){
//			document.getElementById(HEADER + '-ddheader').className 	= 'menu_active';
//		   }
		
		   if ( document.getElementById(HEADER).style.display == 'block' ) {
			document.getElementById(HEADER + '-ddheader').className 	= 'menu_active';
		   }
	
		   else if ( document.getElementById(HEADER).style.display == 'none' ) {
			document.getElementById(HEADER + '-ddheader').className 	= 'menu';
		   }
                }
	}

	else if (WHAT == 'OUT') {
		if (AREA) {
		  document.getElementById(AREA+'-header').className 	= 'menuArea';
		  document.getElementById(AREA+'-content').className 	= 'submenuArea';
		}
       
       if (HEADER!="" && document.getElementById(HEADER)!=null) {		
		   document.getElementById(HEADER).style.display 		= 'none';
		
		   if ( document.getElementById(HEADER).style.display == 'block' ) {
			document.getElementById(HEADER + '-ddheader').className 	= 'menu_active';
		   }
	
		   else if ( document.getElementById(HEADER).style.display == 'none' ) {
			document.getElementById(HEADER + '-ddheader').className 	= 'menu';
		   }
                }
	}
}

function menu_activeItem (HEADER) {
	
	var ACTIVE_MenuItem = document.getElementById('ACTIVE_item').value
	
	if (ACTIVE_MenuItem == HEADER)
	{
		document.getElementById('ACTIVE_item').value 			= HEADER;
		document.getElementById(HEADER + '-ddheader').className = 'menu_active';
	}
	else if (ACTIVE_MenuItem == "NONE")
	{
		document.getElementById('ACTIVE_item').value 			= HEADER;
		document.getElementById(HEADER + '-ddheader').className = 'menu_active';
	}
	else
	{
		document.getElementById(ACTIVE_MenuItem + '-ddheader').className 	= 'menu'
		document.getElementById('ACTIVE_item').value					 	= HEADER;
		document.getElementById(HEADER + '-ddheader').className 			= 'menu_active'
	}
}


var popUp; 

function OpenCalendar(idname, postBack)
{
	popUp = window.open('/pt/popup_calendar/Calendar.aspx?formname=' + document.forms[0].name + 
		'&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 
		'popupcal', 
		'width=165,height=208,left=200,top=250');
}

function SetDate(formName, id, newDate, postBack)
{
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	if (postBack)
		__doPostBack(id,'');
}		

function GoSearch(obj, evnt)
{
  if (obj && evnt.keyCode == 13)
  {
    try {
      evnt.cancelBubble = true; 
      evnt.returnValue = false;     
    } catch (exp) {}
    return SubmitSearch(obj);
  }
}

function FindSearchCriteria(idSearch)
{
  var obj = document.getElementById(idSearch);
  if (obj) return SubmitSearch(obj);
}

function SubmitSearch(obj)
{
    if( !obj.value || obj.title == obj.value ) {
      obj.value = "";
      //alert("Escolha um critério de pesquisa");
      obj.focus();
    }
    else {
      var loc = '/pt/pesquisa/default.aspx?Pesquisa=' + obj.value.replace('"','').replace('"','');
      if (!window.showModalDialog) {
        document.forms[0].action = loc;
        document.forms[0].submit();
      }
      else document.location = loc;
    }
}


function BlurText(obj, is_password)
{
    if ( obj && obj.value == "" ) {
        if ( obj.type == "password" ) {
            var oClearText = GetPreviousSibling(obj);
            if (oClearText) oClearText.style.display = "block";
            obj.style.display = "none";
            obj.value = "";
        }
        else obj.value = obj.title;
    }
}
function ClickText(obj, is_password)
{
    var oTxt = GetDescendant(obj, null, 'input');
    if ( oTxt ) {
        if ( is_password ) {
            if ( oTxt.style.display != "none" ){
                var oClearText = oTxt;
                oTxt = GetSibling(oClearText);
                oClearText.style.display = "none";
                oTxt.style.display = "block";
            }
            else oTxt = GetSibling(oTxt);
        }
        else if ( oTxt.value == oTxt.title ) oTxt.value = "";
        oTxt.focus();
        oTxt.select();
    }

}

function GetPreviousSibling(obj) {
    var oUncle = null;
	if (obj) {
		oUncle = obj.previousSibling;
		if ( oUncle.nodeName.toString().toLowerCase()=="#text" ) oUncle = oUncle.previousSibling;
	}
	return oUncle;
}

function GetDescendant(obj, descendantName, descendantTag) {
	var oDescendant = null;
	if ( !descendantTag ) descendantTag = "div";
	if ( obj ) {
		var k, arrDescendants = obj.getElementsByTagName(descendantTag);
		for ( k = 0; k < arrDescendants.length && !oDescendant; k++ ) {
			if ( (!descendantName) || GetElementName(arrDescendants[k]) == descendantName ) 
			    oDescendant = arrDescendants[k];
			}
    }
    return oDescendant;
}

function GetElementName(oElem) 
{
  if ( oElem ) {
	  if (!oElem.attributes) return "";
	  var sAtribName = "name";
    var oAtribs = oElem.attributes;
   	if ( oAtribs ) 
      var k;
      for ( k=0; k<oAtribs.length; k++ ) 
         try  {
			 if ( oAtribs[k].nodeName && oAtribs[k].nodeName.toString().toLowerCase() == sAtribName && oAtribs[k].nodeValue ) 
		 		return oAtribs[k].nodeValue.toString();
	     } catch (exp) {}
  }
  return "";
}

function GetSibling(obj) {
    var oUncle = null;
	if (obj) {
		oUncle = obj.nextSibling;
		if ( oUncle.nodeName.toString().toLowerCase()=="#text" ) oUncle = oUncle.nextSibling;
	}
	return oUncle;
}
