function dashboard(){
	if(document.getElementById) {
		var dashB = getDash();
		var pre_ = document.getElementsByTagName("pre");
		for (i = 0; i < pre_.length; i++) {			if (pre_[i].className == "") { pre_[i].className = "h";			} else { pre_[i].className = "";}		}
    	if(dashB.className == "") {
    		dashB.className = "dactivo";
    		dashB.style.display= "";
    		dashB.innerHTML = '<p class="loadboard">Cargando Dashboard...</p>';
            var initdashB = function (oXML) { 
            	dashB.innerHTML = oXML.responseText; 
            	document.getElementById("igoogle").focus();
            };
            query("dashboard=index",initdashB);
    	} else {
    		show("dashboard");
    	}
    }
}

function getDash(){
	if(!document.getElementById("dashboard")) {
		var inBody = document.getElementsByTagName("body")[0];
		var dashB = document.createElement("div");
		dashB.id = "dashboard";
		dashB.style.display= "none";
		inBody.appendChild(dashB);
	} else {
		var dashB= document.getElementById("dashboard");
	}
	if(heightdashboard()) dashB.style.height = heightdashboard()+"px";
	return dashB;
}

function google() {
	var search = document.getElementById("igoogle").value;
	var gsearch = document.getElementById("gsearch");
	if(search != "") {
		gsearch.innerHTML = '<h4>Buscando en google...</h4><p>Un momento por favor.</p>';
        var qgoogle = function (oXML) { gsearch.innerHTML = oXML.responseText; };
        query("google="+escape(search),qgoogle);
	}
}

function query(params,funcion) {
	var myConn = new dXHConn();
    if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
    myConn.connect("/dashboard/ajax.dashboard.php", "GET", params, funcion);
}

function show(targetID) {
    if(document.getElementById)
    {
        var target= document.getElementById(targetID);
        if(target.style.display == "none") { target.style.display= "";
        } else { target.style.display = "none"; }
    }  
}

function heightdashboard() {	
	if (window.scrollHeight) {		return window.scrollHeight;	} else if (document.documentElement && document.documentElement.scrollHeight != 0) {
		return document.documentElement.scrollHeight;	} else if (document.body) {
		return document.body.scrollHeight;	}	return false;
}

/*
* Idea de movimiento de capas: http://www.forgetfoo.com/
*/var menuHeight=0;var growHeight=-100;var growMax=0;var displayMenu=true;
function openMenu() {	growHeight+=30;	if(growHeight<=growMax) {		document.getElementById("board").style.top=growHeight+"px";		setTimeout("openMenu()",50)	} else {		document.getElementById("board").style.top="0px";		displayMenu=false;	}}
function closeMenu() {	growHeight-=30;	if(growHeight>=-100) {		document.getElementById("board").style.top=growHeight+"px";		setTimeout("closeMenu()",50)	} else {		document.getElementById("board").style.top="-258px";		displayMenu=true;	}}

function openwidgets() {
	if (displayMenu) { openMenu();	} else { closeMenu();}
}

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function dXHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);

        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}