var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;
	
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}		
	}	
}

/* Control de Formulario */

function enterField(inputField)
{
   if (inputField && inputField.style)
   {
     inputField.style.background='#FFFFFF';
   }
}

function exitField(inputField)
{
   if (inputField && inputField.style)
   { 
	 if (inputField.name == 'nombre' || inputField.name == 'apellido' || inputField.name == 'ciudad'){
		if (inputField.value == '') 
           inputField.style.background='#FEE8D6';
	  }
	 if (inputField.name == 'email' || inputField.name == 'repemail'){
		var s = inputField.value;
		var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
		//if (s.length == 0 ) return true;
		if (filter.test(s))
			return true;
		else
			inputField.style.background='#FEE8D6';
			return false;
	 }
   }
}

var nav4 = window.Event ? true : false;
function acceptNum(evt){ 
// NOTA: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 
var key = nav4 ? evt.which : evt.keyCode; 
return (key <= 13 || (key >= 48 && key <= 57));
}

/* Contador de Caracteres de un campo de texto */
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) 
field.value = field.value.substring(0, maxlimit);
else 
countfield.value = maxlimit - field.value.length;
}


function asignarValor(campo,valor,tipo){
   document.getElementById(campo).value = valor;
   document.getElementById('tipopublic').value = tipo;
   tabber1.next();
   //Recalcula el monto a pagar cuando se cambia la subcategoria
   textoCalculo();
}

function CambiarImagen(img_name, lnk_name, mov) {
    if (mov == 1)
      imagen_actual = imagen_actual - 1;
    if (mov == 2)
      imagen_actual = imagen_actual + 1;
    if (imagen_actual == imagen_max)
      imagen_actual = 0;
    if (imagen_actual < 0)
      imagen_actual = imagen_max - 1;
    var t = document.getElementById("texto");
    t.innerHTML="Viendo imagen " + (imagen_actual+1) + " de " + imagen_max;
    var vinculo = document.getElementById(lnk_name);
    vinculo.href=vinculos[imagen_actual];
    document[img_name].src = imagenes[imagen_actual];
    document[img_name].width = ancho[imagen_actual];
    document[img_name].height = alto[imagen_actual];
}


function HabRadioFoto(nombreCapaFoto){
	if(document.getElementById('tienda').checked){
		document.getElementById(nombreCapaFoto).style.visibility="visible";
	} else {
		document.getElementById(nombreCapaFoto).style.visibility="hidden";
	} 
}

//Abre Popup
function abrirWindow(page,window)
{
  //Abrir ventana popup si window viene con valor
  if (window != ''){
     OpenWindow(window);
     //document.forms[0].target=window;  
  }
//  document.forms[0].submit();
  //document.forms[0].target='';
}

//----------------------------------------------------------
//Funcion que sirve para crear una ventana popup 
function OpenWindow(page, nombre) 
{
   var windowName=nombre;
   var windowPage=page;
   var features =  'width='        + 400 +
                   ',height='      + 195 +
                   ',directories=' + 0 +
                   ',location='    + 0 +
                   ',menubar='     + 0 +
                   ',scrollbars='  + 0 +
                   ',status='      + 0 +
                   ',toolbar='     + 0 +
                   ',screenX='     + 150 +
                   ',screenY='     + 150 +
                   ',top='         + 200 +
                   ',left='        + 300 +
                   ',resizable='   + 0;
              
   //Abre el popup con los parametros de la var features
   window.open (windowPage, windowName, features);
}

//Funcion que sirve para crear una ventana popup
function OpenChatWindow(page, nombre) 
{
   var windowName=nombre;
   var windowPage=page;
   var features =  'width='        + 420 +
                   ',height='      + 420 +
                   ',directories=' + 0 +
                   ',location='    + 0 +
                   ',menubar='     + 0 +
                   ',scrollbars='  + 0 +
                   ',status='      + 0 +
                   ',toolbar='     + 0 +
                   ',screenX='     + 150 +
                   ',screenY='     + 150 +
                   ',top='         + 100 +
                   ',left='        + 300 +
                   ',resizable='   + 0;
              
   //Abre el popup con los parametros de la var features
   window.open (windowPage, windowName, features);
}

//----------------------------------------------------------
//Funcion que sirve para crear una ventana popup de dimensiones grandes
function OpenFullWindow(page, nombre) 
{
   var windowName=nombre;
   var windowPage=page;
   var features =  'width='        + 860 +
                   ',height='      + 500 +
                   ',directories=' + 0 +
                   ',location='    + 0 +
                   ',menubar='     + 0 +
                   ',scrollbars='  + 0 +
                   ',status='      + 0 +
                   ',toolbar='     + 0 +
                   ',screenX='     + 10 +
                   ',screenY='     + 10 +
                   ',top='         + 10 +
                   ',left='        + 10 +
                   ',resizable='   + 0;
              
   //Abre el popup con los parametros de la var features
   window.open (windowPage, windowName, features);
}

function OtherOpenFullWindow(page, nombre) 
{
   var windowName=nombre;
   var windowPage=page;
   var features =  'width='        + 1000 +
                   ',height='      + 600 +
                   ',directories=' + 0 +
                   ',location='    + 0 +
                   ',menubar='     + 0 +
                   ',scrollbars='  + 1 +
                   ',status='      + 0 +
                   ',toolbar='     + 0 +
                   ',screenX='     + 1 +
                   ',screenY='     + 1 +
                   ',top='         + 1 +
                   ',left='        + 1 +
                   ',resizable='   + 0;
              
   //Abre el popup con los parametros de la var features
   window.open (windowPage, windowName, features);
}

function cerrarWindow(){
	window.close();
	window.opener.location.reload();
}

function llamarCalculo(){
	if(confirm('Esta a punto de correr el proceso de actualizacion de cuentas corrientes.\nDesea continuar?')){
		OtherOpenFullWindow('calculodecuentas.php','calculo');
	} else {
		return;
	}	
}

function cambiarDestacado(){
	var objetoSPAN = document.getElementById("texdestac");
	
	if(document.getElementById('artdesta').value == ''){
		document.getElementById('artdesta').value = 'D';
		document.getElementById('imgdest').src = 'imagenes/star_on.png';
		objetoSPAN.innerHTML = "<h1>Mi articulo ser&aacute; Destacado en CRParts !</h1>";
	} else {
		document.getElementById('artdesta').value = '';
		document.getElementById('imgdest').src = 'imagenes/star_off.png';
		objetoSPAN.innerHTML = "<h1>Quiero destacar mi articulo</h1>";
	}
	document.getElementById('destacararticulo').className = (document.getElementById('destacararticulo').className == 'desmarcardestacado') ? 'marcardestacado' : 'desmarcardestacado';
	
	//Recalcula el monto a pagar cuando se cambia la condicion de destacado
	textoCalculo();
}

function textoCalculo(){
	
	var objetoSPAN = document.getElementById("textocalculo");
	var precio = document.getElementById('preciopub'+document.getElementById('tipopublic').value).value;
	var meses = document.getElementById('periodpub'+document.getElementById('tipopublic').value).value;
	var leyendames = ' mes.';
	
	if(document.getElementById('artdesta').value=='D'){
		 precio = parseInt(precio) + parseInt(document.getElementById('destaqpub'+document.getElementById('tipopublic').value).value);
	}
	
	if(meses > 1){ leyendames= ' meses.';}
	
	//Free World !
	//objetoSPAN.innerHTML = "El precio de su publicacion es de <span class=\"textcalculo\">$ " + precio + '.-</span>  por un periodo de <span class=\"textcalculo\">' + meses + leyendames + '</span>';
}


/* Control del formulario de Registracion */
function submitRegistrar(){
	var errores = '';
	if(!document.forms[1].conditions.checked){
		errores = errores + '- Debe aceptar los terminos y condiciones y la politica de privacidad del sitio\n';
	}
	if(document.forms[1].nombre.value.length <= 3){
		errores = errores + '- Debe indicar un nombre mayor a tres caracteres\n';
	}	
	if(document.forms[1].apellido.value.length <= 3){
		errores = errores + '- Debe indicar un apellido mayor a tres caracteres\n';
	}
	if(document.forms[1].ciudad.value.length <= 3){
		errores = errores + '- No ha indicado una ciudad\n';
	}
	if(document.forms[1].provincia.value == ""){
		errores = errores + '- No ha indicado una provincia\n';
	}
	if(document.forms[1].apodo.value.length <= 4){
		errores = errores + '- Debe ingresar su apodo, y debe tener al menos 5 caracteres\n';
	}
	if(document.forms[1].clave.value.length <= 4){
		errores = errores + '- La clave debe tener al menos 5 caracteres\n';
	} else {
		if(document.forms[1].clave.value != document.forms[1].repclave.value){
			errores = errores + '- La clave y su control no coinciden\n';
		}
	}
	if(document.forms[1].email.value.length <= 4){
		errores = errores + '- El E-Mail no es valido\n';
	} else {
		if(document.forms[1].email.value != document.forms[1].repemail.value){
			errores = errores + '- El E-Mail y su control no coinciden\n';
		}
	}
	
	if(errores!=''){
		alert('Se han encontrado los siguientes errores: \n\n' + errores);
	} else {
    	document.getElementById("registrarme").value = "Registrando...";
    	document.getElementById("registrarme").disabled = true;
		document.forms[1].submit();
	}
	
}

function submitLogin(){

	var errores = '';
	var t1, t2, contenedor;
	if(document.getElementById("login_user").value.length <= 4){
		errores = errores + '- Debe ingresar un usuario valido\n';
	}
	if(document.getElementById("login_pass").value.length <= 4){
		errores = errores + '- Debe ingresar una contraseña valida\n';
	}
	if(errores!=''){
		alert('Se han encontrado los siguientes errores: \n\n' + errores);
	} else {
		contenedor = document.getElementById("resultlogin")
		t1 = document.getElementById("login_user").value;
		t2 = document.getElementById("login_pass").value;
    	
		//document.getElementById("login_submit").value = "Ingresando...";
    	//document.getElementById("login_submit").disabled = true;
		//document.formlogin.submit();
		//cargarContenido();
		
		ajax=nuevoAjax();
		ajax.open("GET", "validlogin.php?user="+t1+"&pass="+t2+"&action=popup", true);
		ajax.onreadystatechange=function() {
			if (ajax.readyState==1){
				contenedor.innerHTML = '<img src="imagenes/ajax-loader.gif" align="center">';
			}
			if (ajax.readyState==4) {
				contenedor.innerHTML = ajax.responseText
				var scripts = contenedor.getElementsByTagName('script');
				for (var i = 0; i < scripts.length; i++) {
					eval(scripts[i].text);
				}
			}
		}
		ajax.send(null);
	}
	
}

function submitLoginAjax(){

	var errores = '';
	if(document.getElementById("login_user").value.length <= 4){
		errores = errores + '- Debe ingresar un usuario valido\n';
	}
	if(document.getElementById("login_pass").value.length <= 4){
		errores = errores + '- Debe ingresar una contraseña valida\n';
	}
	if(errores!=''){
		alert('Se han encontrado los siguientes errores: \n\n' + errores);
	} else {
		cargarContenido();
	}
	
}

function inicializarLogin(){
	
	document.getElementById("login_user").value = "";
	document.getElementById("login_pass").value = "";
	document.getElementById("login_submit").value = "Ingresar";
    
}

function submitAltaArticulo(){
	
	var errores = '';
	
	if(document.forms[1].idsubcat.value==''){
		errores = errores + '- Debe asignar su Articulo a una categoria (En el paso 1)\n';
	}
	if(document.forms[1].titulo.value.length<=5){
		errores = errores + '- Debe asignar un titulo a su publicacion y debe contener al menos 5 caracteres\n';
	}
	if(!document.forms[1].consultar.checked){
		if(document.forms[1].importe_int.value.length==0||document.forms[1].importe_int.value==0){
			errores = errores + '- Debe asignar un precio a su publicacion\n';
		}
	}
	if(document.forms[1].file1.value.length!=0){
		var mensaje = LimitAttach(document.forms[1], document.forms[1].file1.value);
		if(mensaje!=""){errores = errores + '- Imagen 1: ' + mensaje + '\n';}
	}
	if(document.forms[1].file2.value.length!=0){
		var mensaje = LimitAttach(document.forms[1], document.forms[1].file2.value);
		if(mensaje!=""){errores = errores + '- Imagen 2: ' + mensaje + '\n';}
	}	
	if(document.forms[1].file3.value.length!=0){
		var mensaje = LimitAttach(document.forms[1], document.forms[1].file3.value);
		if(mensaje!=""){errores = errores + '- Imagen 3: ' + mensaje + '\n';}
	}
	
	if(errores!=''){
		alert('Se han encontrado los siguientes errores: \n\n' + errores);
	} else {
		/* Consultas que solicitan confirmacion */
    	if(document.forms[1].subtitu.value.length==0){
			if(!confirm("No ha especificado un subtitulo.\nEl subtitulo mejora su publicación sumando información que\npuede ser de gran utilidad para sus potenciales compradores.\n\n Continua de todas formas ?")){
				return;
			}
		}
    	if(document.forms[1].file1.value.length==0&&document.forms[1].file2.value.length==0&&document.forms[1].file3.value.length==0){
			if(!confirm("No ha incorporado imagenes a su publicación.\nLas imagenes hacen que sus potenciales compradores\ntengan mayor interés en su producto.\n\nContinua de todas formas ?")){
				return;
			}
		}
		if(document.getElementById("deschtml").value.length==0){
			if(!confirm("No ha especificado información adicional (Paso 3).\nUtilizando la información adicional puede complementar\nlas características de su producto o servicio.\n\n Continua de todas formas ?")){
				return;
			}
		}
				
		document.getElementById("submitarticulo").disabled = true;
		document.forms[1].submit();
	}
	
}

function submitModifArticulo(){
	
	var errores = '';
	
	if(document.forms[1].idsubcat.value==''){
		errores = errores + '- Debe asignar su Articulo a una categoria (En el paso 1)\n';
	}
	if(document.forms[1].titulo.value.length<=5){
		errores = errores + '- Debe asignar un titulo a su publicacion y debe contener al menos 5 caracteres\n';
	}
	if(document.forms[1].importe_int.value.length==0||document.forms[1].importe_int.value==0){
		errores = errores + '- Debe asignar un precio a su publicacion\n';
	}
	
	if(errores!=''){
		alert('Se han encontrado los siguientes errores: \n\n' + errores);
	} else {
		/* Consultas que solicitan confirmacion */
    	if(document.forms[1].subtitu.value.length==0){
			if(!confirm("No ha especificado un subtitulo.\nEl subtitulo mejora su publicación sumando información que\npuede ser de gran utilidad para sus potenciales compradores.\n\n Continua de todas formas ?")){
				return;
			}
		}
    	
		if(document.getElementById("deschtml").value.length==0){
			if(!confirm("No ha especificado información adicional (Paso 3).\nUtilizando la información adicional puede complementar\nlas características de su producto o servicio.\n\n Continua de todas formas ?")){
				return;
			}
		}
		
		document.getElementById("submitarticulo").disabled = true;
		document.forms[1].submit();
	}
	
}

function habPrecio(){
	
	if(!document.forms[1].consultar.checked){
		document.forms[1].importe_int.disabled = false;
		document.forms[1].importe_dec.disabled = false;
		document.forms[1].moneda.disabled = false;
	} else {
		document.forms[1].importe_int.disabled = true;
		document.forms[1].importe_dec.disabled = true;
		document.forms[1].moneda.disabled = true;
	}
		
}

function submitBusqueda(){
	var palabraBusqueda = document.getElementById("wordsearch").value;
	var text = 'Escribe aqui la palabra que quieras buscar';
	if((palabraBusqueda.length<3)||(palabraBusqueda==text)){
		alert('Debe ingresar una palabra valida para efectuar la busqueda !');
		return;
	} else {
		var irPage='listado.php?wordsearch=' + palabraBusqueda;
		document.location.href = irPage;
	}
	
}

function ordenBusqueda(){
	    var tipoOrden = document.getElementById("order").value;
		var irPage='listado.php?static=1&order=' + tipoOrden;
		document.location.href = irPage;
}

function focoCampoBusqueda(){
	if(document.getElementById('wordsearch').value=='Escribe aqui la palabra que quieras buscar'){
		document.getElementById('wordsearch').value='';
	}
}
function blurCampoBusqueda(){
	if(document.getElementById('wordsearch').value==''){
		document.getElementById('wordsearch').value='Escribe aqui la palabra que quieras buscar';
	}
}

function quickCat(){
	url = document.getElementById('quickcat').options[document.getElementById('quickcat').selectedIndex].value
	if (url != "") window.location = url;
}

/* Controla las extensiones de Archivo que se intentan subir al servidor */
extArray = new Array(".jpg", ".gif", ".png");
function LimitAttach(form, file) {
allowSubmit = false;
if (!file) return "";
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extArray.length; i++) {
if (extArray[i] == ext) { allowSubmit = true; break; }
}
if (allowSubmit) return "";
else return "Error en el tipo de archivo a publicar, solo con extension " + (extArray.join("  ")); 
}

/* Funciones para manejo de ajax */

function nuevoAjax(){
var xmlhttp=false;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
//-----------------------------------------------------------
function cargarContenido(){
var t1, t2, contenedor;
contenedor = document.getElementById('contenedor');
t1 = document.getElementById('login_user').value;
t2 = document.getElementById('login_pass').value;
t3 = document.getElementById('login_remember').checked;
ajax=nuevoAjax();
ajax.open("GET", "validloginajax.php?user="+t1+"&pass="+t2+"&rem="+t3,true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
contenedor.innerHTML = ajax.responseText
}
}
ajax.send(null)
}
//-----------------------------------------------------------
function resultadoOlvido(){
var t1, t2, contenedor;
contenedor = document.getElementById('resultado');
t1 = document.getElementById('email').value;
t2 = document.getElementById('clave').value;
ajax=nuevoAjax();
ajax.open("GET", "envio_olvido.php?email="+t1+"&clave="+t2,true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
contenedor.innerHTML = ajax.responseText
}
}
ajax.send(null)
}
//-----------------------------------------------------------
function resultadoRecomendar(){
var t1, t2, contenedor;
contenedor = document.getElementById('resultado');
t1 = document.getElementById('miemail').value;
t2 = document.getElementById('minombre').value;
t3 = document.getElementById('suemail').value;
t4 = document.getElementById('sunombre').value;
t5 = document.getElementById('clave').value;
ajax=nuevoAjax();
ajax.open("GET", "envio_recomendar.php?miemail="+t1+"&minombre="+t2+"&suemail="+t3+"&sunombre="+t4+"&clave="+t5,true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
contenedor.innerHTML = ajax.responseText
}
}
ajax.send(null)
}
//-----------------------------------------------------------
function resultadoConcepto(){
var t1, t2, contenedor;
contenedor = document.getElementById('resultado');
t1 = document.getElementById('accion').value;
t2 = document.getElementById('apodo').value;
t3 = document.getElementById('periodo').value;
t4 = document.getElementById('concepto').value;
if(t4=='99'){
   t5 = 'CR';
} else {
   t5 = 'DB';
}

if(t1!='dele'){
	t8 = document.getElementById('importe').value;
	if(t5=='CR'){
		t6 = document.getElementById('factura').value;
		t7 = document.getElementById('codigopago').value;
	} else {
		t6 = 0;
		t7 = 0;
	}
}else{
	t8 = 0;
	t6 = 0;
	t7 = 0;
}

ajax=nuevoAjax();
ajax.open("GET", "mant_concepto.php?accion="+t1+"&apodo="+t2+"&periodo="+t3+"&concepto="+t4+"&tipo="+t5+"&factura="+t6+"&codigopago="+t7+"&importe="+t8,true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
contenedor.innerHTML = ajax.responseText
}
}
ajax.send(null)
}

//-----------------------------------------------------------
function resultadoUsuarioxConcepto(){
var t1, t2, contenedor;
contenedor = document.getElementById('resultado');
t1 = document.getElementById('accion').value;
t2 = document.getElementById('apodo').value;
t3 = document.getElementById('concepto').value;
ajax=nuevoAjax();
ajax.open("GET", "mant_usuarioxconcepto.php?accion="+t1+"&apodo="+t2+"&concepto="+t3,true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
contenedor.innerHTML = ajax.responseText
}
}
ajax.send(null)
}

//-----------------------------------------------------------
function controlarUser(campo,criterio){
var contenedor, t1;
contenedor = document.getElementById(campo+'Res');
t1 = criterio.value;
ajax=nuevoAjax();
ajax.open("GET", "control_onthe_fly.php?campo="+campo+"&criterio="+t1,false);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
contenedor.innerHTML = ajax.responseText
}
}
ajax.send(null)
}

//-----------------------------------------------------------
function submitMessage(){
	
	document.getElementById('btn_r').disabled = true;
		
	var errores = '';
	var t1, t2, t3, t4, t5, contenedor;
	contenedor = document.getElementById('res_msg');
	
	t1 = RemoveBad(document.getElementById('n').value);
	t2 = RemoveBad(document.getElementById('e').value);
	t3 = RemoveBad(document.getElementById('c').value);
	if(document.getElementById('w').checked){
		t4 = 'Si'; }
	else{
		t4 = 'No';
	}
	
	t5 = RemoveBad(document.getElementById('m').value);
	
	ajax=nuevoAjax();
	ajax.open("GET", "sendmail.inc.php?n="+t1+"&e="+t2+"&c="+t3+"&w="+t4+"&m="+t5, true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==1){
			contenedor.innerHTML = '<img src="imagenes/ajax-loader.gif" align="center">';
		}
		if (ajax.readyState==4) {
			contenedor.innerHTML = ajax.responseText
			var scripts = contenedor.getElementsByTagName('script');
			for (var i = 0; i < scripts.length; i++) {
				eval(scripts[i].text);
			}
		}
	}
	ajax.send(null);
}

function RemoveBad(strTemp) { strTemp = strTemp.replace(/\<|\>|\"|\'|\%|\;|\(|\)|\&|\+/g,""); return strTemp; }
