function consul(id,tip)
{
	if ( validaFrm()== false ) return false;
	
	var nombre, email, tel, cons, id, tipo;
	//
	nombre = document.getElementById("nombre").value;
	email = document.getElementById("email").value;
	tel = document.getElementById("telefono").value;
	cons = document.getElementById("txtconsulta").value;
	suc = document.getElementById("sucursal").value;
	id = id;
	tipo = tip;
	//
	x_consultafrmf (nombre, email, tel, cons, id, tipo, suc, consultafrmf_Result);
	//
}

consultafrmf_Result = function (t)
{
	alert("Su consulta ha sido recibida correctamente.");
	document.getElementById("form").reset();
}

function printcp(idd,idt)
{
	if ( validaFrmd()== false ) return false;
	
	var nombre, email, tel, dni, idd, idt, env;
	//
	nombre = document.getElementById("nombre").value;
	email = document.getElementById("email").value;
	tel = document.getElementById("telefono").value;
	dni = document.getElementById("dni").value;
	env = document.getElementById("env").checked;
	idd = idd;
	idt = idt;
	//
	x_printcupon (nombre, email, tel, dni, idd, idt, env, printcupon_Result);
	//
}

printcupon_Result = function (t)
{		
	if (t!=""){
	alert("Cupón de descuento generado correctamente.")
	window.open("http://www.esperienza.com.ar/"+t,"","width=800,height=400,scrollbars=no,status=no,toolbar=yes");
	document.getElementById("formd").reset();
	}
}

validaFrm = function ()
{
	var email, nombre, tel, cons;
	email=nombre=tel=cons="";
	//
	var retVal = true;
	var msg = "Mensaje: \n";
	//
	if (document.getElementById("email")) {
		email = document.getElementById("email").value;
		document.getElementById("email").style.backgroundColor = "#ffffff";
	}
	//
	if (document.getElementById("nombre")) {
		nombre = document.getElementById("nombre").value;
		document.getElementById("nombre").style.backgroundColor = "#ffffff";
	}
	//
	if (document.getElementById("telefono")) {
		tel = document.getElementById("telefono").value;
		document.getElementById("telefono").style.backgroundColor = "#ffffff";
	}
	if (document.getElementById("txtconsulta")) {
		cons = document.getElementById("txtconsulta").value;
		document.getElementById("txtconsulta").style.backgroundColor = "#ffffff";
	}
	//
	if ((email == "") || (!validadorEmails(email)))
	{
		retVal = false;
		msg += "- Direccion de email no valida\n";
		document.getElementById("email").style.backgroundColor = "#ffff99";
	}
	if ((nombre == "") || (nombre.length < 3))
	{
		retVal = false;
		msg += "- campo Nombre vacio \n";
		document.getElementById("nombre").style.backgroundColor = "#ffff99";
	}
	//
	if ((tel == "") || (tel.length < 3))
		{
			retVal = false;
			msg += "- campo Teléfono vacio\n";
			document.getElementById("telefono").style.backgroundColor = "#ffff99";
		}
	//
	if ((cons == "") || (cons.length < 3))
	{
		retVal = false;
		msg += "- campo Consulta vacio\n";
		document.getElementById("txtconsulta").style.backgroundColor = "#ffff99";
	}
	//
	if (retVal==false) alert(msg);
	return retVal;
}

validadorEmails = function(mail)
{
	var filter=/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;
	if (mail.length > 3) {
		if (!filter.test(mail)) return false;
		return true;
	}
	return false;
}

function registro()
{
	if ( validaFrmr()== false ) return false;
	
	var email;
	//
	email = document.getElementById("remail").value;
	suc = document.getElementById("sucureg").value;
	//
	x_regist (email,suc, regist_Result);
	//
}

regist_Result = function (t)
{
	alert("Se ha registrado correctamente.");
	document.getElementById("formr").reset();
}

validaFrmr = function ()
{
	var email;
	email="";
	//
	var retVal = true;
	var msg = "Mensaje: \n";
	//
	if (document.getElementById("remail")) {
		email = document.getElementById("remail").value;
		document.getElementById("remail").style.backgroundColor = "#ffffff";
	}
	//
	if ((email == "") || (!validadorEmails(email)))
	{
		retVal = false;
		msg += "- Direccion de email no valida\n";
		document.getElementById("remail").style.backgroundColor = "#ffff99";
	}
	//
	if (retVal==false) alert(msg);
	return retVal;
}

function openVent(winName, theURL, features) {
  window.open(theURL,winName,features);
}
