/** 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 reemplazoString(dato){
	return escape(dato);
	}

function XHConn()
{
  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;
}

function idajx(url,params,updater){
	
	document.getElementById(updater).innerHTML = "<table width=100% height=300 border=0><tr><td align=center valign=middle><img src=\"/imagenes/imgCargando.gif\"></td></tr></table>";
	
	var ajx_actualiza = function(objeto){ 
		var obj = document.getElementById(updater);
			obj.innerHTML=objeto.responseText;
		}
	
	myajax.connect(url,"POST",params,ajx_actualiza)
		
	}
	
function idajx_html(url,params,updater){
	document.getElementById(updater).innerHTML = "<table width=100% height=300 border=0><tr><td align=center valign=middle><img src=\"/imagenes/imgCargando.gif\"></td></tr></table>";
	
	var ajx_actualiza = function(objeto){ 
		var obj = document.getElementById(updater);
			obj.innerHTML=objeto.responseText;
			init();
}
	
	myajax.connect(url,"POST",params,ajx_actualiza)
	
	}
	
function idformsend(url,formid,updater){
	 var Formulario = document.getElementById(formid);
	 var longitudFormulario = Formulario.elements.length;
	 var cadenaFormulario = ""
	 var sepCampos
	 sepCampos = ""
	 for (var i=0; i <= Formulario.elements.length-1;i++) {
		 if ((Formulario.elements[i].type=="checkbox") || (Formulario.elements[i].type=="radio")){
			 if (Formulario.elements[i].checked){
				 cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURIComponent(reemplazoString(Formulario.elements[i].value));
			 }
		 } else {
			 cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURIComponent(reemplazoString(Formulario.elements[i].value));}
		 sepCampos="&";
	 }
	 idajx(url,cadenaFormulario,updater);
}

function getValor(id){
	var oEditor = FCKeditorAPI.GetInstance( id ) ;
	document.getElementById(id).value=oEditor.GetXHTML();
	}
	
function confirmar(pregunta){
	if (confirm(pregunta+"?")){
			return true;
		} else {
			return false;
		}
	}
	
function idLimpiaDiv(iddiv){
	document.getElementById(iddiv).innerHTML = "";
	}
	
function changeValue(recurso,valor){
	document.getElementById(recurso).value=valor;
	}
	
function cambiaDisplay(idobjeto){
	objeto = document.getElementById(idobjeto);

	if (objeto.style.display == "block"){
		objeto.style.display = "none";
	} else {
		objeto.style.display = "block";
	}			
}

function cambiaDisplayOn(idobjeto){
	objeto = document.getElementById(idobjeto);
	objeto.style.display = "block";
	}

function cambiaDisplayOff(idobjeto){
	objeto = document.getElementById(idobjeto);
	objeto.style.display = "none";
	}

function chequeaLength(idcampo,maxlong){

	campo = document.getElementById(idcampo);

	if (campo.value.length > maxlong){
		alert('Ha superado el maximo de caracteres.');
		campo.value=campo.value.substring(0, maxlong);
	}
}

function popup (pagina,ancho,alto) {
	var opciones="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width="+ancho+",height="+alto+",top=85,left=140";
	window.open(pagina,"",opciones);
}