function validarAviso(errores) {
	// valido la cabecera
	if (!tieneLongitud(document.getElementById('cabecera'),1,25)) {
		errores += 1;
		marcarError('cabecera','form-td-error',1);
	} else {
			desmarcarError('cabecera','form-td-normal');
	}

	// valido la linea 1
	if (!tieneLongitud(document.getElementById('1linea'),3,35)) {
		errores += 1;
		marcarError('1linea','form-td-error',1);
	} else {
			desmarcarError('1linea','form-td-normal');
	}
	
	// valido url
	if (!tieneLongitud(document.getElementById('url'),5,35)) {
		errores += 1;
		marcarError('url','form-td-error',1);
	} else {
			desmarcarError('url','form-td-normal');
	}

	// valido url real
	if (!tieneLongitud(document.getElementById('urlreal'),5,1024)) {
		errores += 1;
		marcarError('urlreal','form-td-error',1);
	} else {
			desmarcarError('urlreal','form-td-normal');
	}
	
	return errores;
}

function validarCliente (errores) {
	// valido el nombre
	if (!tieneLongitud(document.getElementById('nombre'),3,255)) {
		errores += 1;
		marcarError('nombre','form-td-error',1);
	} else {
			desmarcarError('nombre','form-td-normal');
	}
	
	// valido el telefono
	if (!tieneLongitud(document.getElementById('telefono'),3,255)) {
		errores += 1;
		marcarError('telefono','form-td-error',1);
	} else {
			desmarcarError('telefono','form-td-normal');
	}
	
	// valido el email
	if (!tieneLongitud(document.getElementById('mail'),1,255)) {
		errores += 1;
		marcarError('mail','form-td-error',1);
	} else {
		if (!esEmail(document.getElementById('mail').value)) {
			errores += 1;
			marcarError('mail','form-td-error',2);
		} else {
			desmarcarError('mail','form-td-normal');
		}
	}
	
	// valido el numero de documento
	if (!tieneLongitud(document.getElementById('documento'),7,20)) {
		errores += 1;
		marcarError('documento','form-td-error',1);
	} else {
			desmarcarError('documento','form-td-normal');
	}
	
	// valido el numero de localidad
	if (!tieneLongitud(document.getElementById('localidad'),2,255)) {
		errores += 1;
		marcarError('localidad','form-td-error',1);
	} else {
			desmarcarError('localidad','form-td-normal');
	}
	
	// valido el numero de cpa
	if (!tieneLongitud(document.getElementById('cpa'),4,8)) {
		errores += 1;
		marcarError('cpa','form-td-error',1);
	} else {
			desmarcarError('cpa','form-td-normal');
	}

	// valido el numero de direccion
	if (!tieneLongitud(document.getElementById('direccion'),4,255)) {
		errores += 1;
		marcarError('direccion','form-td-error',1);
	} else {
			desmarcarError('direccion','form-td-normal');
	}
	
	// valido longitud del captcha
	if (!tieneLongitud(document.getElementById('captchacode'),4,4)) {
		errores += 1;
		marcarError('captchacode','form-td-error',1);
	} else {
			desmarcarError('captchacode','form-td-normal');
	}
	
	return errores;
}

function conmutarSubmit() {
	// Activo/desactivo el boton de "solicitar" segun se acepte o no las condiciones
		//Boton de Titular y Registrante iguales
		if (document.getElementById('btnEnviarForm').disabled) {
			document.getElementById('btnEnviarForm').disabled = false;
			document.getElementById('btnEnviarForm').style.color = '#333333';
		} else {
			document.getElementById('btnEnviarForm').disabled = true;
			document.getElementById('btnEnviarForm').style.color = '#999999';
		}
		document.getElementById('btnEnviarForm').refresh;
}

function poner2daParte() {
	var errores = 0;

	errores += validarAviso(errores);

	if (errores == 0) {
		if (document.getElementById('iniciar_btnsiguiente')) {
			document.getElementById('iniciar_btnsiguiente').style.display = 'none'; }
		
		if (document.getElementById('ejemplo_Adwords')) {
			document.getElementById('ejemplo_Adwords').style.display = 'none'; }

		if (document.getElementById('contratar_dominios_2')) {
			new Effect.BlindDown(document.getElementById('contratar_dominios_2'))
			new Effect.BlindDown(document.getElementById('contratar_dominios_check'))
		}
		
		// a los 2 segundos de mostrarse el div anterior situo el focus
		if (document.getElementById('nombre')) {
		setTimeout ("document.getElementById('nombre').focus();", 2000); }
	}	
} 

function enviarForm() {
	var errores = 0;
	
	errores += validarAviso(errores);
	errores += validarCliente(errores);
	
	if (errores == 0) {
		document.form_solicitar_publicidad.submit();
	}	
} 

function enviarAAmigo() {
	// valido el email
	if (!tieneLongitud(document.getElementById('amigo-mail'),3,255) || !esEmail(document.getElementById('amigo-mail').value)) {
		document.getElementById('faltante-amigo-mail').style.display = '';
		document.getElementById('td-amigo-mail').className = 'form-td-error';
		document.getElementById('amigo-mail').focus();
	} else {
		document.getElementById('faltante-amigo-mail').style.display = 'none';
		document.getElementById('td-amigo-mail').className = 'form-td-normal';
		url = 'acciones/enviarnoticia.php?tipo=3&email='+document.getElementById('amigo-mail').value+'&destinatario='+document.getElementById('amigo-nombre').value+'&remitente='+document.getElementById('amigo-remitente').value;
		document.getElementById('div-avisarle-amigo-bak').innerHTML = document.getElementById('div-avisarle-amigo').innerHTML;
		document.getElementById('div-avisarle-amigo').innerHTML = "<div id='div-demo' style='height:130px; padding-left:70px; padding-top:50px'><h1><img src='imagenes/loader.gif' alt='Trabajando...' width='16' height='16' align='absmiddle' /> Enviando...</h1></div>";
		setTimeout ("ajaxURL('enviarnoticia',url);", 500);
	}
} 

function tratarVentanaMensajeAAmigo() {
	if (document.getElementById('div-avisarle-amigo')) {
		new Effect.toggle(document.getElementById('div-avisarle-amigo'));
		setTimeout("document.getElementById('amigo-mail').focus()",2000);
	}
}

function ajaxRespuestaEnviarNoticia(respuesta) {
	if(respuesta == "1") {
		document.getElementById('div-avisarle-amigo').innerHTML = "<div id='div-demo' style='height:130px; padding-left:70px; padding-top:50px'><h1><img src='imagenes/iconos/tilde.gif' alt='listo' width='18' height='18' align='absmiddle' /> Listo! ya se le envi&oacute; la noticia !!! </h1></div>";	
		document.getElementById('amigo-mail').value = '';
		document.getElementById('amigo-nombre').value = '';
		document.getElementById('amigo-remitente').value = '';
		setTimeout("tratarVentanaMensajeAAmigo()",2000);
	} else if (respuesta == "0") {	
		document.getElementById('div-avisarle-amigo').innerHTML = "<div id='div-demo' style='height:130px; padding-left:70px; padding-top:50px'><h1><img src='imagenes/iconos/seguridad.gif' alt='error' width='18' height='18' align='absmiddle' /> Problemas! no se le pudo enviar la noticia a esta cuenta de eMail, revise e intente de nuevo.</h1></div>";
	} else {
		document.getElementById('div-avisarle-amigo').innerHTML = "<div id='div-demo' style='height:130px; padding-left:70px; padding-top:50px'><h1><img src='imagenes/iconos/email.gif' alt='email' width='18' height='18' align='absmiddle' /> No se lo notific&oacute; porque alguien ya lo hizo.  Gracias.</h1></div>";
	}
	setTimeout("document.getElementById('div-avisarle-amigo').innerHTML=document.getElementById('div-avisarle-amigo-bak').innerHTML",4000);
}

function autocompletar_cabecera(texto) {	
	if (texto.length > 2 && texto.length < 26) {
		if (document.getElementById('adwords_titulo')) {
			document.getElementById('adwords_titulo').innerHTML = texto;
		}
	} else {
		if (document.getElementById('adwords_titulo')) {
			document.getElementById('adwords_titulo').innerHTML = "Publicidad en Google";
		}
	};
}

function autocompletar_linea1(texto) {
	if (texto.length > 2 && texto.length < 36) {
		if (document.getElementById('adwords_linea1')) {
			document.getElementById('adwords_linea1').innerHTML = texto;
		}
	} else {
		if (document.getElementById('adwords_linea1')) {
			document.getElementById('adwords_linea1').innerHTML = "Avisos inteligentes con Adwords";
		}
	};
}

function autocompletar_linea2(texto) {
	if (texto.length > 2 && texto.length < 36) {
		if (document.getElementById('adwords_linea2')) {
			document.getElementById('adwords_linea2').innerHTML = texto;
		}
	} else {
		if (document.getElementById('adwords_linea2')) {
			document.getElementById('adwords_linea2').innerHTML = "lo mejor en publicidad online";
		}
	};
}

function autocompletar_url(texto) {
	if (texto.length > 4 && texto.length < 36) {
		if (document.getElementById('adwords_url')) {
			document.getElementById('adwords_url').innerHTML = texto;
		}
	} else {
		if (document.getElementById('adwords_url')) {
			document.getElementById('adwords_url').innerHTML = "www.TECSID.com";
		}
	};
}
