// JavaScript Document

var x;
x=$(document);


function mail_smtp(id, mail)
{ 
	  var x;
	x=$("#"+id);
	var datos='';

datos='				  <form name="formu'+id+'" id="formu'+id+'" >';
datos+='				  <table width="100%" border="0" cellspacing="0" align="right" cellpadding="0">';
datos+='                  <tr>';
datos+='                  <td height="30"><img src="images/arrow_mail.gif" alt="Envie su consulta" width="18" height="15" align="absmiddle" /> <strong>Envie su consulta:</strong></td>';
datos+='                      </tr>';
datos+='                      <tr>';
datos+='                        <td align="center" valign="top"><table width="92%" border="0" cellspacing="3" cellpadding="0">';
datos+='                            <tr>';
datos+='                              <td width="10%" align="left" valign="top">Nombre:</td>';
datos+='                              <td width="42%" align="left" valign="top"><input name="nombre" type="text" class="consultas" id="nombre" size="60" /></td>';
datos+='                              <td width="10%" align="left" valign="top">Mail:</td>';
datos+='                              <td width="38%" align="left" valign="top"><input name="mail" type="text" class="consultas" id="mail" size="60" /></td>';
datos+='                            </tr>';
datos+='                            <tr>';
datos+='                              <td align="left" valign="top">Telefono:</td>';
datos+='                              <td align="left" valign="top"><input name="telefono" type="text" class="consultas" id="telefono" size="60" /></td>';
datos+='                              <td align="left" valign="top">Consulta:</td>';
datos+='                              <td align="left" valign="top"><textarea name="notes" cols="60" class="consultas" id="notes"></textarea></td>';
datos+='                            </tr>';
datos+='                            <tr>';
datos+='                              <td>&nbsp;</td>';
datos+='                              <td>&nbsp;</td>';
datos+='                              <td>&nbsp;</td>';
datos+='                              <td align="right" valign="middle"><a href="javascript:void(0);"><img src="images/bt_enviar.gif" onclick="doMail(\''+id+'\',\''+mail+'\');" style="border:none;" alt="Enviar" width="52" height="23" /></a><a href="javascript:void(0);"><img src="images/bt_cerrar.gif" onclick="Cancel_mail(\''+id+'\');" style="border:none;" alt="Cancelar" width="52" height="23" /></a></td>';
datos+='                            </tr>';
datos+='                        </table></td>';
datos+='                      </tr>';
datos+='                  </table></form>';

	x.html(datos);
	x.show("slow");
}
function Cancel_mail(id)
{ 
	  var x;
	x=$("#"+id);
	x.hide("slow");
	x.html("");
}
function doMail(id,mail)
{
  var x;
	if(valid(id))
	{
	$.post("./common/mail_smtp.php",{a_mail:mail,de:document.getElementById("formu"+id).nombre.value,de_mail:document.getElementById("formu"+id).mail.value,consulta:document.getElementById("formu"+id).notes.value,tel:document.getElementById("formu"+id).telefono.value},confirma);
	x=$("#"+id);
	x.hide("slow");
	}
}
function doMail_c(id,mail)
{
  var x;
	if(valid(id))
	{
	$.post("./common/mail_smtp_c.php",{a_mail:mail,de:document.getElementById("formu"+id).nombre.value,de_mail:document.getElementById("formu"+id).mail.value,consulta:document.getElementById("formu"+id).notes.value,tel:document.getElementById("formu"+id).telefono.value},confirma_c);
	x=$("#"+id);
	x.hide("slow");
	}
}
function valid(id)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("formu"+id).mail.value))
	{
		if(document.getElementById("formu"+id).notes.value=='')
		{
			alert("Debe Esribir una consulta");
		}
		else
		{ 
			return true;
		}

	}else
	{										
		window.alert ('Direccion de Mail Invalida');
		return false;
	}
}

function confirma(datos)
{
	if(datos=="1")
	{
		alert("No se pudo enviar el mail \n Por favor intente mas tarde ");
	}
}
function confirma_c(datos)
{
	if(datos=="1")
	{
		alert("No se pudo enviar el mail \n Por favor intente mas tarde ");
	}else
	{
		alert("Se Envio la Consulta");
		window.location.href="contacto.php";
	}
}
