//JavaScript 

addEvent(window,'load',Carga,false);

function Carga(e)
{
	var boton = document.getElementById('enviar');
	addEvent(boton,'click',Enviar,false);
	
}

function Enviar()
{
	
	//Datos del formulario 1
	var _empresa = document.getElementById('_empresa');
	var _contacto = document.getElementById('_contacto');
	var _tel = document.getElementById('_tel');
	var _celular = document.getElementById('_celular');
	var _email = document.getElementById('_email');
	var _productos = document.getElementById('_productos');
	var _comentarios = document.getElementById('_comentarios');

	
	//Datos del formulario 2
	var empresa = document.getElementById('empresa');
	var contacto = document.getElementById('contacto');
	var tel = document.getElementById('tel');
	var celular = document.getElementById('celular');
	var email = document.getElementById('email');
	var productos = document.getElementById('productos');
	var comentarios = document.getElementById('comentarios');
	
	
	var forma = document.getElementById('donde_comprar');
	
	
	var listo = Comprobar(_empresa)&&Comprobar(_contacto)&&ComprobarTelefono(_tel)
	&&ComprobarTelefono(_celular)&&ComprobarMail(_email)&&Comprobar(_productos)&&Comprobar(_comentarios);
	
	if(listo)
	{
		empresa.value = _empresa.value;
		contacto.value = _contacto.value;
		tel.value = _tel.value;
		celular.value = _celular.value;
		email.value = _email.value;
		productos.value = _productos.value;
		comentarios.value = _comentarios.value;
		forma.submit();
		
	}
	
	
}

function Comprobar(c)
{
	if(c.value=="")
	{
		alert("No debe haber campos vacíos");
		c.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function ComprobarPregunta(c)
{
	if(c.value=="Escribe tu pregunta")
	{
		alert("Escribe tu pregunta");
		c.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function ComprobarVendedor(c)
{
	if(c.value=="0")
	{
		alert("Seleccione a su vendedor");
		c.focus();
		return false;
	}
	else
	{
		return true;
	}
}


function ComprobarMail(campo)
{
	var RegExPattern = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
    var errorMessage = 'Email incorrecto';
    if ((campo.value.match(RegExPattern)) && (campo.value!='')) {
        return true; 
    } else {
        alert(errorMessage);
        campo.focus();
		return false;
    } 				
	
}

function ComprobarTelefono(campo)
{
  var RegExPattern = /^[0-9]{2,3}-? ?[0-9]{6,10}$/;
    var errorMessage = 'Teléfono incorrecto';
    if ((campo.value.match(RegExPattern)) && (campo.value!='')) {
        return true; 
    } else {
        alert(errorMessage);
        campo.focus();
		return false;
    } 								 
}







//Código para que el sistema trabaje con varios navegadores

function addEvent(elemento,nomevento,funcion,captura)
{
	if(elemento.attachEvent)
	{
		elemento.attachEvent('on'+nomevento,funcion);
		return true;
	}
	else
	if(elemento.addEventListener)
	{
		elemento.addEventListener(nomevento,funcion,captura);
		return true;
	}
	else
		return true;
}
