
/* 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];
   	//alert(elem);
    var container = document.getElementById(elem);
  	container.style.display = "none";
    container.innerHTML =response_content;   
    $j(container).slideToggle("slow");    
    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);
}

function array_search( needle, haystack, argStrict ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brettz9.blogspot.com)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
    // *     returns 1: 'surname'

    var strict = !!argStrict;
    var key = '';

    for(key in haystack){
        if( (strict && haystack[key] === needle) || (!strict && haystack[key] == needle) ){
            return key;
        }
    }

    return false;
}
function isBO() {
    var url =document.location.href;
    var urlparts = url.split('/');
    if (array_search ("admin",urlparts))
    return true;
    return false;
 
}

activateMenu = function(nav) {
    /* currentStyle restricts the Javascript to IE only */
    if (document.getElementById(nav) != null){
    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";
				}
			}
		}
	}}
}
if (!isBO()){
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');
	 
}}
