  
String.prototype.trim = function(){
var text = this;
var returnString = '';
var l = text.length;
for(x=0;x<l;x++)
{
   if((text.charAt(x) != '')&&(text.charAt(x) != ' '))
   {
	  returnString = returnString + text.charAt(x);
   }
   
}
return returnString;

}
  
 function ajaxCall(pagina,enviar)
{
	 var texto = "";
var xmlhttp=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
      // JScript gives us Conditional compilation, we can cope with old IE versions.
      // and security blocked creation of the objects.
      try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        try {
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
          xmlhttp = false;
        }
      }
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  try {
		xmlhttp = new XMLHttpRequest();
	  } catch (e) {
		xmlhttp=false;
	  }
    }
    if (!xmlhttp && window.createRequest) {
	  try {
	    xmlhttp = window.createRequest();
	  } catch (e) {
        xmlhttp=false;
	  }
    }
    if (enviar != null) {
	  xmlhttp.open("GET", pagina+"?"+enviar, true);
	} else {
      xmlhttp.open("GET", pagina, true);
	}
	  
		
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4) {
        if (xmlhttp.status==200) {
		  if (document.getElementById('xmlhttp_datos')) {
		    document.getElementById('xmlhttp_datos').innerHTML = xmlhttp.responseText;
		  } else {
				texto = xmlhttp.responseText;
  			eval(texto);
		  }

        }
        else if (xmlhttp.status==404) alert("La página solicitada no existe...")
        else alert("Status is "+xmlhttp.status)
      }
    }


    xmlhttp.send(null);
		
		return texto;
}


function xmlhttp_get(pagina,parametros,activa_editor) {
	 
    if (pagina=="") {
	  alert("Debe indicar la pagina que será llamada...");
	  return false; 
	}
	if (parametros=="") {
	  enviar = null;
	} else {
	  enviar = parametros;
	}

	mostrarCargando(true);
	ajaxCall(pagina,parametros,enviar);
	mostrarCargando(false);


}


    /* this function shows the pop-up when
     user moves the mouse over the link */
    function ShowPopUp()
    {
        var winW = 630, winH = 460;
        if (parseInt(navigator.appVersion)>3) {
         if (navigator.appName=="Netscape") {
          winW = window.innerWidth;
          winH = window.innerHeight;
         }
         if (navigator.appName.indexOf("Microsoft")!=-1) {
          winW = document.body.offsetWidth;
          winH = document.body.offsetHeight;
         }
        }


        var Popup = document.getElementById("Popup");

        if((Popup != null)&&(Popup != undefined))
    		{
    				Popup.style.display="block";
    				Popup.style.height = winH;
    				
    				var imagen = document.getElementById("imgCargando");
    
    				var top = (winH - imagen.height) / 2;
    				var left = (winW - imagen.width) / 2
    				imagen.top = top;
    				imagen.left = left;
			}
    }

    function HidePopUp()
    {
        var Popup = document.getElementById("Popup");
        if((Popup != null)&&(Popup != undefined))
				{
				   Popup.style.display="none";
				}
    }

		

	function mostrarCargando(mostrar)
	{
	 if(mostrar){
	 		ShowPopUp();
	 }else{
//		setTimeout("HidePopUp()", 2000);
 			HidePopUp();
	 }
	return true;	
	}
	
function checkAll(checkbox)
{
 var tabla = $('frm_listado');
 var checks = tabla.getElementsByTagName('input');
 for(var i=0; i < checks.length; i++)
 {
 	  checks[i].checked = checkbox.checked;
 }
}

function marca_celda(idR, colorMarcado, colorDesmarcado)
{
  var check = $("eliminar_varios_" + idR);
	if(check.checked)
	{
	   color = colorMarcado;
	}
	else
	{
	  color = colorDesmarcado;
	}
  	var fila = $("row_" + idR);
//		set_bgcolor(fila,color);
		 	 											
	/*
    while (fila.hasChild) {
  		//element.removeChild(element.firstChild);
    }
	*/		 
}


  function removeElements(idE)
	{
	    var fila = document.getElementById(idE);
		if(fila != undefined)
		{
			while (fila.firstChild) {
			 fila.removeChild(fila.firstChild);
			}
		}
		return true;
	}

	function initTable()
	{
	  cargarTabla(1);
	  var linkB = $("linkAtras");
		linkB.onclick = function(){
		   anterior();
		}

	  var linkN = $("linkAdelante");
		linkN.onclick = function(){
		   siguiente();
		}

	}
	
	function siguiente()
	{
	  pagina = pagina + 1;
	  cargarTabla(pagina);
	}
	
	function anterior()
	{
	  pagina = pagina - 1;
		if(pagina >= 0)
		{
  	  cargarTabla(pagina);
		}
		else
		{
		 hideBackButton();
		}
	}
	
	function hideBackButton()
	{
	  var aLink = $("linkAtras");
		aLink.style.display = 'none'; 
	}

	function hideNextButton()
	{
	  var aLink = $("linkAdelante");
		aLink.style.display = 'none'; 
	}
	
  var pagina = 1;

	
	function getFormData(form) // serialize the form
	{
		if(typeof(form) == 'st	ring')	
		{
			form = $(form);	
		}
		
		var inputs = form.getElementsByTagName('input');
		var n = inputs.length;
		var ret = "";
		
		for(x=0;x<n;x++)
		{
			var id = inputs[x].id;
			var name = inputs[x].name;
			var value = escape($F(id));
			var tipo = inputs[x].type;
			var checked = inputs[x].checked;
			var concatenar = false;
			
			if(((tipo == 'radio') || (tipo == 'checkbox') )&& checked)
			{
				concatenar = true;
			}
			else if(tipo == 'text')
			{
				concatenar = true;
			}
			
			if(concatenar)
			{
				ret = ret + "&" + name + "=" + value;
			}
		}
		
		
		var areas = form.getElementsByTagName('textarea');
		var n = areas.length;
		for(x=0;x<n;x++)
		{
			var id = areas[x].id;
			var name = areas[x].name;
			var value = escape($F(id));
			
			ret = ret + "&" + name + "=" + value;
		}
		
		
		var selects = form.getElementsByTagName('select');
		var n = selects.length;
		for(x=0;x<n;x++)
		{
			var id = selects[x].id;
			var name = selects[x].name;
			var value = escape($F(id));
			
			ret = ret + "&" + name + "=" + value;
		}
		
		
		return ret;
	}

	function hide(element)
	{
		if(typeof(element) == 'string')
		{
			element = $(element);	
		}
		
		element.style.display = 'none';
		return true
	}
	
	function show(element)
	{
	    if(typeof(element) == 'string')
		{
			element = $(element);	
		}
		element.style.display = '';
		return true
	}
	
	function isHide(element)
	{

		if(typeof(element) == 'string')
		{
			element = $(element);	
		}

		if(element.style.display == 'none')
		{
		  return true;
		}
		else
		{
			return false;
		}
		
	}


	function isMail(emailString)
	{
		emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
		return emailpat.test( emailString );
	}
	
	function disableMenuButton(button)
	{
		
		var td = $('td' + button);
		var lk = $('lk' + button);
	
		td.innerHTML = lk.innerHTML;
		return true;	
	}

	function changeStatus(table, field, id)
	{
		var parametros = "accion=998";
		if(table == undefined)
		{
			var table = "";
		}
		if(field == undefined)
		{
			var field = "";
		}
		var idC = parseInt(id, 10);
		if(isNaN(idC))
		{
			idC = 0;	
		}
		
		parametros = parametros + "&parametro1=" + table + "&parametro2=" + field + "&parametro3=" + id;
		ajaxCall('ajax.php',parametros);		
		return true;
	}
