function showElement(id) {
	
	if(document.getElementById(id).style.display != 'block'){
		document.getElementById(id).style.display= 'block';
		document.getElementById(id).style.visibility = 'visible';
		document.getElementById(id).style.position = 'static';
	}else {
		document.getElementById(id).style.display= 'none';
		document.getElementById(id).style.visibility = 'hidden';
		document.getElementById(id).style.position = 'static';
	}
}


	 var captureKeys = function(ev) { 

     
	 ev = ev || window.event;             // gets the event in ie or ns
     kCode = ev.keyCode || ev.which;   // gets the keycode in ie or ns
  
     /* in ie, when pressing the ctrl + shift + key, it gives the key code for the capitalized key (probably because shift is pressed) 
        in ns pressing ctrl, shift and another key doesn't change the keycode
        thus, the || and two different numbers */
  
     if (ev.ctrlKey && ev.shiftKey && kCode == 19 || ev.ctrlKey && ev.shiftKey && kCode == 66
     			    && document.location.pathname.match('admin')==null) {   		 // ctrl+alt+b
       
	       $j("#adminref").trigger('click');
           return false;  // make it so the browser ignores key combo
     }
     else if (ev.ctrlKey && ev.shiftKey && kCode == 19 || ev.ctrlKey && ev.shiftKey && kCode == 70
     				&& document.location.pathname.match('admin')) {    // ctrl+alt+f
           $j("#frontref").trigger('click');
           return false;  // make it so the browser ignores key combo
     }
      
     if (ev.ctrlKey && kCode == 119) { // ctrl+w
         closeWin();  // run your own script to close the window 
                      	            // doesn't work in ie, ie just closes the window
         return false;
     }
}
/* Create a new XMLHttpRequest object to talk to the Web server */



var xmlHttp = false;

/*@cc_on @*/
/*@if (@_jscript_version >= 5)

try {

  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

  try {

    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

  } catch (e2) {

    xmlHttp = false;

  }

}

@end @*/



if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}



///////////////////////////////////////////////////////////////////

  // 1. Get whatever data you need from the Web form.

  // 2. Build the URL to connect to.

  // 3. Open a connection to the server.

  // 4. Set up a function for the server to run when it's done.

  // 5. Send the request.

///////////////////////////////////////////////////////////////////



var params = new Array(); 




function updatePage() {

   if (xmlHttp.readyState == 1) {}
   if (xmlHttp.readyState == 2) {}
   if (xmlHttp.readyState == 3) {}
   if (xmlHttp.readyState == 4) {

  	//alert (xmlHttp.responseText);
  	var response = xmlHttp.responseText;
  	var brokenstring=response.split(':-:');
    var elem = brokenstring[1];    
    var response_content = brokenstring[2];
   	
    var container = document.getElementById(elem);
   
   	container.style.display = "none";
    container.innerHTML =response_content;   
    $j(container).slideToggle("slow");    
		location.reload();
    document.getElementById('lnk'+elem.substring(4)).onclick = '';
    $j('#lnk'+elem.substring(4)).click(function(){
    $j(container).slideToggle("slow"); 
		return false;
	} );
     
    
  }
}

function callAjaxServer2(params,funcao,div) {

   
   
   
   var params_array=params.split(':');
   var params = new Array();
   var url = "ajax_serve.php?elem="+div+"&f="+escape(funcao);

   for (i = 0; i < params_array.length ; i+=2)
		{
	    	    url+='&'+escape(params_array[i])+'=';
				url+=params_array[i+1];

   		}

   // for( keyVar in params_array) {		}
   // alert(url);
   // Open a connection to the server
   xmlHttp.open("GET", url, true);
   // Setup a function for the server to run when it's done
   xmlHttp.onreadystatechange = updatePage;
   // Send the request
   xmlHttp.send(null);

}

function callAjaxServer(params,funcao,div) {
 
   var params_array=params.split(':');
   var params = new Array();
   var url = "ajax_serve.php?elem="+div+"&f="+escape(funcao);
   
   for (i = 0; i < params_array.length ; i+=2)
	   {  	    url+='&'+escape(params_array[i])+'=';
				url+=params_array[i+1];
   		}
   //alert(url);
   // Open a connection to the server
   xmlHttp.open("GET", url, true);
   // Setup a function for the server to run when it's done
   xmlHttp.onreadystatechange = updatePage;
   // Send the request
   xmlHttp.send(null);

}

activateMenu = function(nav) {




var len =document.location.href.split("/").length;
var arr = document.location.href.split("/");

    if (arr[len-2] !='admin'){
    /* currentStyle restricts the Javascript to IE only */
	if (document.getElementById(nav).currentStyle) {  		
		var navroot = document.getElementById(nav);
		
		/* Get all the list items within the menu */
		var lis=navroot.getElementsByTagName("LI");		
		for (i=0; i<lis.length; i++) {
			
		   /* If the LI has another menu level */
			if(lis[i].lastChild.tagName=="UL"){
			
				/* assign the function to the LI */
				lis[i].onmouseover=function() {	
				   
				   /* display the inner menu */
				   this.lastChild.style.display="block";
				   
				}
				lis[i].onmouseout=function() {                       
				   this.lastChild.style.display="none";
				}
			}
		}
	}
	}
}

window.onload= function(){
	
	var urlHalves = String(document.location).split('\/');
	var s = urlHalves.length;
	var st = urlHalves[s-1];
	
	re = new RegExp("biblioteca"); 
	if (st.match(re))		return true;
	else activateMenu('listagem');
	 
}


function changeDisplay( elementId, setTo ) { // setTo: block or none
  var theElement;
  if( document.getElementById ) {
    //DOM
    theElement = document.getElementById( elementId );
  } else if( document.all ) {
    //Proprietary DOM
    theElement = document.all[ elementId ];
  }
  if( !theElement ) {
    /* The page has not loaded, or the browser claims to
    support document.getElementById or document.all but
    cannot actually use either */
    return;
  }
  //Reference the style ...
  if( theElement.style ) { theElement = theElement.style; }
  if( typeof( theElement.display ) == 'undefined' ) {
    //The browser does not allow us to change the display style
    //Alert something sensible (not what I have here ...)
    window.alert( 'Your browser does not support this' );
    return;
  }
  //Change the display style
  theElement.display = setTo;
}

function toggleAddGroup() {
	var el = document.getElementById('add_group');
	
	if(el.style.display == 'none') el.style.display = 'block';
	else el.style.display = 'none';
}

function voltar(){
	history.go(-1);
}

