﻿/*
*	Validación de los campos del formulario
*	de donaciones
*/

function prospero(b) {
    document.theform.amount.value=b;
    document.theform.amount.focus;
}

function prosperoM(b)
{
	document.theform.normalAmount.value=b
	document.theform.normalAmount.focus
}

function combine(x) {
    if (document.theform.MC_newsletter.checked==true) {
        document.theform.MC_newsletter.value="optedin"
    } else {
        document.theform.MC_newsletter.value="optedout"
    }
    document.theform.cartId.value = document.theform.MC_firstname.value + " " + document.theform.MC_lastname.value + "," + document.theform.MC_newsletter.value;
}
function formCheck(checkThisEmail) {
	
	if ( (document.theform.amount != null && document.theform.amount.value == "") || (document.theform.normalAmount != null && document.theform.normalAmount.value == "") ) {
		alert("Seleccione la cantidad que desea donar."); return false;
	}
//    if (document.theform.amount.value == "") {alert("Seleccione la cantidad que desea donar."); return false;}
    if (document.theform.MC_firstname.value == "") {alert("Por favor escriba su nombre."); return false;}  
    if (document.theform.MC_lastname.value == "") {alert("Por favor escriba su apellido."); return false;} 
    if (document.theform.paymentType.value == "") {alert("Por favor seleccione el tipo de tarjeta con la que va a pagar."); return false;} 
    if (document.theform.address.value == "") {alert("Por favor escriba su dirección."); return false;} 
//    if (document.theform.postcode.value == "") {alert("Please provide your postcode."); return false;} 
    if (document.theform.country.options[0].selected == true) {alert("Por favor seleccione su país."); return false;} 
    if (document.theform.email.value == "") {alert("Por favor escriba su e-mail."); return false;}
    
    var myEMailIsValid = true;
    
    var myAtSymbolAt = checkThisEmail.indexOf('@');
    if (myAtSymbolAt < 1) {myEMailIsValid = false}

    var myLastDotAt = checkThisEmail.lastIndexOf('.');
    if (myLastDotAt < myAtSymbolAt) {myEMailIsValid = false}

    var myLength = checkThisEmail.length;            
    if (myLength - myLastDotAt <= 2) {myEMailIsValid = false}
    
    var mySpaceAt = checkThisEmail.indexOf(' ');
    if (mySpaceAt != -1) {myEMailIsValid = false}
    
    if (myEMailIsValid == false) {alert("Dirección de e-mail inválida. Por favor escríbala cuidadosamente ya que le enviaremos el recibo de su donación de su tarjeta de crédito a esta dirección.")}

	//if( myEMailIsValid ) { hiddenFloatingDiv('formResult'); void(0); }
	
    return myEMailIsValid;
}
function checkmail(email) {
    if (document.theform.firstname.value == "") {alert("Por favor escriba su nombre."); return false;}
    if (document.theform.lastname.value == "") {alert("Por favor escriba su apellido."); return false;}
    if (document.theform.emailaddress.value == "") {alert("Por favor escriba su e-mail."); return false;}
//    if (document.theform.postcode.value == "") {alert("Please provide your Zip/Postal Code."); return false;} 
    if (document.theform.country.options[0].selected == true) {alert("Por favor seleccione su país."); return false;} 
    if (document.theform.telephone.value == "") {alert("Por favor escriba su número de teléfono."); return false;} 
   
    var myEMailIsValid = true;

    var myAtSymbolAt = email.indexOf('@');
    if (myAtSymbolAt < 1) {myEMailIsValid = false}

    var myLastDotAt = email.lastIndexOf('.');
    if (myLastDotAt < myAtSymbolAt) {myEMailIsValid = false}

    var myLength = email.length;            
    if (myLength - myLastDotAt <= 2) {myEMailIsValid = false}

    var mySpaceAt = email.indexOf(' ');
    if (mySpaceAt != -1) {myEMailIsValid = false}
    
    if (myEMailIsValid == false) {alert("Dirección de e-mail no válida! Por favor vuelva a escribirla, ya que la necesitamos para enviarle el boletín.")}

    return myEMailIsValid;
}

function validate_required(field,alerttxt) {
	with (field) {
		if (value==null||value=="") {
			alert(alerttxt);
			return false;
		} else {
			return true;
		}
	}
}

function validate_form(thisform) {
	with (thisform) {


		if (validate_required(puemail,"Por favor escriba su e-mail!")==false) {
			puemail.focus();
			return false;
		}

		if (validate_required(pucity,"El campo Ciudad debe llenarse!")==false) {
			pucity.focus();
			return false;
		}

		if (validate_required(coi,"El campo País debe llenarse!")==false) {
			coi.focus();
			return false;
		}

		if (validate_required(puconcern,"Su inquietud debbe llenarse!")==false) {
			puconcern.focus();
			return false;
		}

		if (validate_required(pucomplaint,"Debe enviar su queja!")==false) {
			pucomplaint.focus();
			return false;
		}

		if (validate_required(securityImageValue,"El código de seguridad de escribirse!")==false) {
			securityImageValue.focus();
			return false;
		}	}
}

function validate_IGO(thisform) {
	with (thisform) {

		if (validate_required(form_email,"Por favor escriba su e-mail!")==false) {
			form_email.focus();
			return false;
		}

		if (validate_required(form_city,"Por favor escriba su Ciudad!")==false) {
			form_city.focus();
			return false;
		}
		if (form_coi.options[0].selected==true) {
			alert("Por favor escriba su País!");
			form_coi.focus();
			return false;

		}
		if (validate_required(form_complaint,"Debe escribir una queja para enviar!")==false) {
			form_complaint.focus();
			return false;
		}

	}
}

function validate_contact(thisform) {
	with (thisform) {

		if (validate_required(form_firstname,"Por favor escriba su nombre!")==false) {
			form_firstname.focus();
			return false;
		}

		if (validate_required(form_lastname,"Por favor escriba su apellido!")==false) {
			form_lastname.focus();
			return false;
		}

		if (validate_required(form_email,"Por favor escriba su e-mail!")==false) {
			form_email.focus();
			return false;
		}
		if (form_coi.options[0].selected==true) {
			alert("Por favor seleccione su país!");
			form_coi.focus();
			return false;

		}
		if (validate_required(form_question,"Debe escribir una pregunta para enviar!")==false) {
			form_question.focus();
			return false;
		}

	}
}
