var contactchannel;

function send_contact() {
	if (document.getElementById('ingreso_texto').value=='') return;
	contactchannel = createIT();
	document.getElementById('avisoenviarcontacto').innerHTML= "&nbsp;Enviando tu mensaje...&nbsp;";
	document.getElementById('avisoenviarcontacto').style.background = "#0066ff";
	document.getElementById('avisoenviarcontacto').style.visibility='visible';
	contactchannel.onreadystatechange = handler_contact;
	contactchannel.open("POST", "/ajax/contact.php", true);		
	contactchannel.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	contactchannel.send("msg=" + encodeURIComponent(document.getElementById('ingreso_texto').value) + "&email=" + encodeURIComponent(document.getElementById('ingreso_contacto').value));
}

function handler_contact() {
	if (contactchannel.readyState == 4) {
		if(contactchannel.status != 200) { alert('Error de conexión. Reintenta en unos segundos.'); document.getElementById('avisoenviarcontacto').style.visibility='hidden'; return; }
		if (contactchannel.responseText=='1') {
			document.getElementById('avisoenviarcontacto').innerHTML= "&nbsp;Recibimos tu mensaje. Gracias!&nbsp;";
			document.getElementById('avisoenviarcontacto').style.background = "#cc0000";
			document.getElementById('avisoenviarcontacto').style.visibility='visible';
			document.getElementById('ingreso_texto').value='';
			document.getElementById('ingreso_contacto').value='';
		}
		else {
			document.getElementById('avisoenviarcontacto').innerHTML= "&nbsp;Indicanos tu mensaje y tu email&nbsp;";
			document.getElementById('avisoenviarcontacto').style.background = "#cc0000";
			document.getElementById('avisoenviarcontacto').style.visibility='visible';
		}
	}
}

function createIT()  /* ajax function*/
{
	var creation;

	/*@cc_on
	@if (@_jscript_version >= 5)
	try
	{ creation = new ActiveXObject("Msxml2.XMLHTTP");}
	catch (e)
	{ try {	creation = new ActiveXObject("Microsoft.XMLHTTP");}
	catch (e) {	creation = false; } }
	@else creation = false;
	@end @*/

	if (!creation && typeof XMLHttpRequest != 'undefined')
	{try{ creation = new XMLHttpRequest(); } catch (e)
		{ creation = false;	}	}
	return creation;
} 

