function ahah(url, target, delay) {
  document.getElementById(target).innerHTML = document.getElementById(target).innerHTML + '<span style="background: white;position:absolute;top: 5px; left: 5px; padding: 5px 5px 5px 5px;border: 2px dotted blue; "><img src="/wait.gif" align="absmiddle" /> Por favor espere...</span>';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {ahahDone(url, target, delay);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function ahahDone(url, target, delay) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML="ahah error:\n"+req.statusText;
    }
    if (delay != undefined) {
       setTimeout("ahah(url,target,delay)", delay); // resubmit after delay
	    //server should ALSO delay before responding
    }
  }
}

function verificarOperacion(titulo,url){
	if(confirm(titulo)){
         window.location.href=url;
    }
    return true;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function addUnloadEvent(func) {
  var oldOnunload = window.onunload;
  if (typeof window.onunload != 'function') {
    window.onunload = func;
  }
  else {
    window.onunload = function() {
      oldOnunload();
      func();
    }
  }
}

function desofuscar(id){
	var mail = document.getElementById(id).innerHTML.replace(" ARROBA ","@").replace(" PUNTO ",".");
	document.getElementById(id).innerHTML = ("<a href='mailto:" + mail + "'>" + mail + "</a>");
}

function setPestana(id,num){
	var i = 1;
	while (i<=10 || document.getElementById("_pestana_" + id + i)){
		if (document.getElementById("_pestana_" + id + i) && document.getElementById("_pestana_a_" + id + i) && document.getElementById( id + i)){
			document.getElementById("_pestana_" + id + i).className=(i==num?"tabberactive":"");
			document.getElementById("_pestana_a_" + id + i).href="javascript:void(null);";
			document.getElementById( id + i).className=(i==num?"tabbertabshow":"tabbertabhide");
		}
		i++;
	}
	return false;
}
