function ajaxEspera(pagina, parametros)
{
	 var texto = "";
	 
    if (pagina=="") {
	  alert("Debe indicar la pagina que será llamada...");
	  return false; 
	}
	if (parametros=="") {
	  enviar = null;
	} else {
	  enviar = parametros;
	}
    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, false);
	} else {
      xmlhttp.open("GET", pagina, false);
	}
	  
    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) {
	 var texto = "";
	 
    if (pagina=="") {
	  alert("Debe indicar la pagina que será llamada...");
	  return false; 
	}
	if (parametros=="") {
	  enviar = null;
	} else {
	  enviar = parametros;
	}
    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 check_all(checkbox)
{
 var tabla = $('tblDatos');
 var checks = tabla.getElementsByTagName('input');
 for(var i=0; i < checks.length; i++)
 {
 	  checks[i].checked = checkbox.checked;
 }
}

  function hide(toHide) // esconder un elemento, recibel el id del elemento o todo el elemento
  {
	if(typeof(toHide) == 'string')
	{
		var toHide = $(toHide);
	}
	toHide.style.display = 'none';
	return true
  }

	function isHide(toHide)
	{
		var ret = true;
		if(typeof(toHide) == 'string')
		{
			var toHide = $(toHide);
		}
		
		if(toHide.style.display != 'none')
		{
			ret = false;
		}
		return ret;
	}

  function show(toShow) // mostrar un elemento, recibel el id del elemento o todo el elemento
  {
	if(typeof(toShow) == 'string')
	{
		var toShow = $(toShow);
	}
	
	toShow.style.display = '';
	return true
  }

  function removeElements(idE)
	{
		if(typeof(idE) == 'object')
		{
			var fila = idE
		}
		else
		{
	    	var fila = $(idE);
		}
	    while (fila.firstChild) {
  		 fila.removeChild(fila.firstChild);
     }
	}

	function initTable()
	{
	  var pagina = 1;
	  cargarTabla(pagina);
	  var linkB = $("linkAtras");
		linkB.onclick = function(){
		   anterior();
		}

	  var linkN = $("linkAdelante");
		linkN.onclick = function(){
		   siguiente();
		}
	}
	
	function siguiente()
	{
	  pagina = pagina + 1;
	  cargarTabla(pagina);
	  return true;
	}
	
	function anterior()
	{
	  pagina = pagina - 1;
		if(pagina >= 0)
		{
  	  		cargarTabla(pagina);
		}
		else
		{
		 	hideBackButton();
		}
		return true;
	}
	
	function hideBackButton()
	{
		hide("linkAtras");
		return true;
	}

	function hideNextButton()
	{
		hide("linkAdelante");
		return true;
	}

	function add2Shopping(checkbox)	
	{
		xmlhttp_get('ajax.php?accion=5&cid=' + checkbox.value + '&method=' + checkbox.checked,'',false);
		return true;
	}

	function removeFromShopping(checkbox)	
	{
		xmlhttp_get('ajax.php?accion=5&cid=' + checkbox.value + '&method=' + !checkbox.checked,'',false);
		return true;
	}

	function getFormData(form) // serialize the form
	{
		if(typeof(form) == 'string')	
		{
			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;

			if(selects[x].multiple)
			{
				var selecciones = selects[x];
				var nOps = selecciones.length;

				for(iX = 0; iX < nOps; iX++)
				{
					if(
					   	(selecciones[iX].selected)&&(selecciones[iX].value != '-1')
					  )
					{
						ret = ret + "&" + name + "=" + selecciones[iX].value;
					}
				}
			}
			else
			{
				var value = escape($F(id));
				if(value != '-1')
				{
					ret = ret + "&" + name + "=" + value;
				}
			}
		}
		
		
		return ret;
	}

	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 cargarZonas(idP, seleccion)
	{
		if(seleccion == undefined)
		{
			var seleccion = -1;
		}
		var txtSelect = "&parametro2=" + seleccion;
	
		xmlhttp_get('ajax.php?STP=0&accion=31&parametro=' + idP + txtSelect);
		return true;
	}
	

var pagina = 1;
	
