function recaptcha () {
	document.getElementById('captcha').src='antispam.php?aux='+Math.floor(Math.random()*1001);
}

function bValidaMail (Email)
{
	if (Email == null) return false;
	var Reason = "";
	var checkStr = Email;
	var ix = (checkStr.length - 4);
	var RC = true;
	var x = AtSignValid = DoublePeriod = PeriodValid = SpaceValid = ExtValid = RL = 0;
	for (i = 0; i < checkStr.length; i++) {
		if (checkStr.charAt(i) == '@')
			AtSignValid++;
		else if (checkStr.charAt(i) == '.') {
			if (x == (i-1))
				DoublePeriod++;
			else {
				x = i;
				PeriodValid++;
			}
		}
		else if (checkStr.charAt(i) == ' ') SpaceValid ++;
	}
	RL = Reason.length;
	if (AtSignValid != 1)
		Reason += "Debe existir un signo @ único en la dirección del E-mail. ";
	if (PeriodValid == 0)
		Reason += "La dirección del E-mail debe contener al menos un punto. ";
	if (SpaceValid > 0)
		Reason += "No se deben introducir espacios en el E-Mail ";
	if (DoublePeriod > 0)
		Reason += "La dirección de E-Mail contiene múltiples puntos sucesivos. ";
	if (RL != Reason.length) {
		RC= false;
	}
	else {
		RC= true;
	}
	return RC;
}

function check(formulario) {
	//var formulario = null;
	var msg = "";
	//formulario = document.getElementById("finfo");
	name = formulario.first_name.value.replace(/^\s+|\s+$/gi,'');
	lastname = formulario.last_name.value.replace(/^\s+|\s+$/gi,'');
	title = formulario.title.value.replace(/^\s+|\s+$/gi,'');
	company = formulario.company.value.replace(/^\s+|\s+$/gi,'');
	email = formulario.email.value.replace(/^\s+|\s+$/gi,'');
	phone = formulario.phone.value.replace(/^\s+|\s+$/gi,'');
	anti_spam_code2 = formulario.capt.value.replace(/^\s+|\s+$/gi,'');
	
	if (name.length==0) {
		msg = "Empty Name";
	}
	else if (lastname.length==0) {
		msg = "Empty Last Name";
	}
	else if (title.length==0) {
		msg = "Empty Title";
	}
	else if (company.length==0) {
		msg = "Empty Company";
	}
	else if ($("#country").val()=="") {
	msg = "Country field is required";
	}
	else if (email.length==0) {
	msg = "Empty e-mail";
	}
	else if (phone.length==0) {
	msg = "Empty Phone";
	}
	else if (anti_spam_code2.length==0) {
	msg = "Insert the image validation code, please.";
	}
	else if (!bValidaMail(formulario.email.value)) {
	msg = "Incorrect e-mail";
	}
	else {
		$('#00N200000021OAE').val($('#00N200000021OAE').val()+'\n\nIP: '+formulario.source_ip.value+'\nReceive advertising mail: '+((formulario.receiveads.checked) ? 'no' : 'yes'));
		//alert($('#00N200000021OAE').val());
		formulario.submit();
	};
	if (msg!="") { alert(msg); return false;}
}

function check_captcha () {
    if (!document.finfo.iaccept.checked) {
        alert("You must accept our Privacy Policy"); return false;
    } else {
        $.ajax({
            type: "GET",
            url: "c.php?code="+document.finfo.capt.value,
            data: "",
            async: false,
            success: function(msg){
                if (msg == "1") check(document.finfo);
                else { alert("Incorrect validation code"); return false; }
            }
        });
    }
}