// JavaScript Document
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 oculta(obj){
	document.getElementById(obj).style["display"] = "none";
}
/////////////////////////////////////////////
function mostrar(obj){
	document.getElementById(obj).style["display"] = "";
}

function validar(){

		var ok = "";
		var error = "error_form";
	    var enviar = true;

	if (document.contactar.nombre.value==""){
			document.contactar.nombre.className = error;
			document.contactar.nombre.focus()
			return false;
	}else
		document.contactar.nombre.className = ok;
	
	if (document.contactar.apellido.value==""){
			document.contactar.apellido.className = error;
			document.contactar.apellido.focus()
			return false;
	}else
		document.contactar.apellido.className = ok;
		

	if (document.contactar.correo.value==""){
			document.contactar.correo.className = error;
			document.contactar.correo.focus();
			return false;
	}else{
			if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.contactar.correo.value)){
				document.contactar.correo.className = error;
				document.contactar.correo.focus()
				return false;
			}else
				document.contactar.correo.className = ok;
	}
	
	if (document.contactar.comentario.value==""){
			document.contactar.comentario.className = error;
			document.contactar.comentario.focus()
			return false;
	}else
		document.contactar.comentario.className = ok;
	
	
	return enviar;

}

function validar_recomendar(){

		var ok = "input";
		var error = "error_form";
	    var enviar = true;

	if (document.recomendar_form.nombre.value==""){
			document.recomendar_form.nombre.className = error;
			document.recomendar_form.nombre.focus()
			return false;
	}else
		document.recomendar_form.nombre.className = ok;
	
	if (document.recomendar_form.nombre2.value==""){
			document.recomendar_form.nombre2.className = error;
			document.recomendar_form.nombre2.focus()
			return false;
	}else
		document.recomendar_form.nombre2.className = ok;
		

	if (document.recomendar_form.correo.value==""){
			document.recomendar_form.correo.className = error;
			document.recomendar_form.correo.focus();
			return false;
	}else{
			if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.recomendar_form.correo.value)){
				document.recomendar_form.correo.className = error;
				document.recomendar_form.correo.focus()
				return false;
			}else
				document.recomendar_form.correo.className = ok;
	}
	
	if (enviar==true){
			recomendar();
		}
	
	return enviar;

}


function popUp(URL , W , H  ) { 
	day = new Date(); 
	id = day.getTime();
	if (!W) W = 500;
	if (!H) H = 400;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+W+",height="+H+",left=150,top=184');"); 
}

function enviar_mensaje(){
	var caja = document.getElementById("mensaje");
	var nombre = document.getElementById("nombre").value;
	var correo = document.getElementById("correo").value;
	var tel = document.getElementById("telefono").value;
	var mensaje = document.getElementById("comentario").value;
	ajax=nuevoAjax();
	caja.innerHTML = '<p align="center"><img src="ajax-loader.gif" width="188" height="19" style="margin:100px 0 0px 0" /><br /><b>enviando</b></p><br /><br />';
	ajax.open("GET", "ajax.php?nombre="+nombre+"&correo="+correo+"&tel="+tel+"&mensaje="+mensaje,true);
	ajax.onreadystatechange=function() {
			if (ajax.readyState==4){
				caja.innerHTML = ajax.responseText;
			}
	}
	ajax.send(null)	
}


function recomendar(){
	var caja = document.getElementById("recomendar_data");
	var nombre = document.getElementById("nombre").value;
	var nombre2 = document.getElementById("nombre2").value;
	var correo = document.getElementById("correo").value;
	ajax=nuevoAjax();
	caja.innerHTML = '<p align="center"><img src="ajax-loader.gif" style="margin:35px 0px 0px 0px"/>';
	ajax.open("GET", "ajax.php?nombre="+nombre+"&correo="+correo+"&nombre2="+nombre2,true);
	ajax.onreadystatechange=function() {
			if (ajax.readyState==4){
				caja.innerHTML = ajax.responseText;
			}
	}
	ajax.send(null)	
}

function new_recomendar() {
	var algo = '<form id="recomendar_form" name="recomendar_form" method="post" action="">              <table width="280" border="0" cellpadding="0" cellspacing="0"><tr><td height="26" class="text_recomendar"><strong>Recomendar</strong></td>                  <td valign="top" ><div align="right" ><a href="#" onclick="oculta(\'recomendar_data\')" style="color:#FF0000;">X</a></div></td>                </tr><tr><td width="112" class="text_recomendar"><div align="left">Su nombre</div></td><td width="168" ><div align="left">                    <label><input type="text" name="nombre" id="nombre" class="input" /></label></div></td></tr><tr><td class="text_recomendar"><div align="left">El de su Amigo</div></td><td><div align="left"><label><input type="text" name="nombre2" id="nombre2" class="input" /></label></div></td></tr><tr><td class="text_recomendar"><div align="left">Correo de tu Amigo</div></td><td><div align="left"><label><input type="text" name="correo" id="correo" class="input" /></label></div></td></tr><tr><td>&nbsp;</td<td><div align="left"> <input type="button" name="button" id="button" value="Invitar" style="margin:5px;" onclick="validar_recomendar()" /></div></td></tr></table></form>';
    var caja = document.getElementById("recomendar_data");
	caja.innerHTML = algo;
}