// 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 fertig() {
	var mail = document.getElementById('mail').value;
	var nombre = escape(document.getElementById('nombre').value);
	var asunto  = escape(document.getElementById('asunto').value);
	var mensaje = escape(document.getElementById('mensaje').value);
	var contenedor = document.getElementById("mitexto");
	var enviar = "si";
ajax=nuevoAjax();
ajax.open("POST","contacto.php",true);
ajax.onreadystatechange = function() {
if(ajax.readyState==4) {
contenedor.innerHTML = ajax.responseText
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send("mail="+mail+"&nombre="+nombre+"&asunto="+asunto+"&mensaje="+mensaje+"&enviar="+enviar)
}

function verCorreo() {
mensajeerror = new String();
if(amail(document.getElementById('mail').value)) { mensajeerror += "Verifica la direccion de e-mail!\nRecuerda no dejar espacios y solo utilizar caracteres alfanumericos\n\n"; }
if (anombre(document.getElementById('nombre').value)) { mensajeerror += "Debes ingresar tu nombre!\n\n"; }
if (anombre(document.getElementById('asunto').value)) { mensajeerror += "Asigna un nombre a este mail en asunto!\n\n"; }
if (anombre(document.getElementById('mensaje').value)) { mensajeerror += "Escribe tu mensaje!\n\n"; }
if(mensajeerror.length>3) { alert(mensajeerror); return false; }
	if(confirm("Este correo sera enviado al propietario del dominio,\nno a la orquesta.\nSeguro desea continuar?")) {
	fertig();
	}
}

function amail(dir) {
if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(dir)) { return true; }
return false;
}

function anombre(dir) {
if (dir.length<4) { return true; }
return false;
}

function comunica() {
txthtml = "";
txthtml += "<table width='300' align='center' cellpadding='0' cellspacing='0'>";
txthtml += "<tr>";
txthtml += "<td>Tu direcci&oacute;n de e-mail<br>";
txthtml += "<input name='mail' type='text' id='mail'></td>";
txthtml += "<input name='enviar' type='hidden' id='enviar' value='si'></td>";
txthtml += "</tr>";
txthtml += "<tr>";
txthtml += "<td>Tu nombre<br>";
txthtml += "<input name='nombre' type='text' id='nombre'></td>";
txthtml += "</tr>";
txthtml += "<tr>";
txthtml += "<td>Asunto<br>";
txthtml += "<input name='asunto' type='text' id='asunto'></td>";
txthtml += "</tr>";
txthtml += "<tr>";
txthtml += "<td>Tu mensaje<br>";
txthtml += "<textarea name='mensaje' cols='40' rows='8' id='mensaje'></textarea></td>";
txthtml += "</tr>";
txthtml += "<tr>";
txthtml += "<td><input type='button' name='Submit' value='Enviar' onClick=\"verCorreo()\"></td>";
txthtml += "</tr>";
txthtml += "</table>";
document.getElementById("mitexto").innerHTML = txthtml;
}

function inicia() {
	var txt = "";
	txt += '<br><br><br><br><table width="500" border="2" align="center" cellpadding="3" cellspacing="3">';
	txt += '<tr><td><h1 align="center">www.orquestabillos.com<br></h1></td></tr></table><br><br>';
	txt += '<p align="center" id="mitexto">Si necesitas comunicarte urgente con el propietario <br>';
	txt += 'de este dominio,<a href="javascript:comunica();"> haz clic aqu&iacute;.</a><br>';
	txt += '<br>Por favor, no usarlo para contactar a la <b>orquesta</b>.<br>';
	txt += 'Correos dirigidos a la <b>orquesta</b> no ser&aacute;n respondidos.<br></p>';
	txt += '<p align="center"><br></p>';
	document.getElementById("general").innerHTML = txt;	
}