$(document).ready(function (){
	$(".popup.error.1").hide();
	$(".popup.error.2").hide();
	$(".popup.error.3").hide();
	$(".popup.error.4").hide();
	$(".popup.error.5").hide();
	$(".popup.error.6").hide();
	$(".popup.error.10").hide();
	$(".popup.error.11").hide();

	$('.div_blue_int .aviso.1').css({display: "none"});
	$('#contenedor_int #content_left .aviso.1').css({display: "none"});
	$('.div_blue_int .aviso.2').css({display: "none"});
	$('#contenedor_int #content_left .aviso.2').css({display: "none"});
	$('.div_blue_int .aviso.3').css({display: "none"});
	$('#contenedor_int #content_left .aviso.3').css({display: "none"});
	$('.div_blue_int .aviso.4').css({display: "none"});
	$('#contenedor_int #content_left .aviso.4').css({display: "none"});

});

function getRadioButtonSelectedValue(ctrl)
{
    for(i=0;i<ctrl.length;i++)
        if(ctrl[i].checked) return ctrl[i].value;
}

function validaFormPaypal() {
	var valor = document.getElementById("amount").value;
	var select_proyecto = getRadioButtonSelectedValue(document.form_proyectos.select_proyecto);
	var item_name = document.getElementById("item_name").value;
	//alert("longitud: "+valor.length);
	//alert("indexof: "+valor.indexOf('.'));
	//alert("valor: "+valor);
	//alert("select_proyecto: "+select_proyecto);
	//alert("item_name: "+item_name);
	if(valor.length > 0){
		if(valor.indexOf(',') != '-1'){
			document.getElementById("amount").value = valor.replace(',','.');
		}
		if(valor.indexOf('.') == '-1'){
			document.getElementById("amount").value = valor+'.00';
		}
	}
	if(select_proyecto.length > 0){
		document.getElementById("item_name").value = item_name + ' ' + select_proyecto + '.';
	}
	
	//alert(document.getElementById("listado_donaciones").value);
	
	document.getElementById("donaciones_amount").value = valor;
	document.getElementById("donaciones_proyecto").value = select_proyecto;
	//document.getElementById("donaciones_facebook").value = document.getElementById("compartir_facebook").value;
	//document.getElementById("donaciones_listado_donaciones").value = document.getElementById("listado_donaciones").value;
	//document.getElementById("donaciones_nombre_donante").value = document.getElementById("nombre_donante").value;
	//document.getElementById("donaciones_localidad_donante").value = document.getElementById("localidad_donante").value;
	
}

function sendForms(){
	setTimeout("document.form_paypal.submit();",10);
	setTimeout("document.form_donaciones.submit();",100);
}

function validaFormContacto() {
	error = "";
	$(".popup.error.1").hide();
	$(".popup.error.2").hide();
	$(".popup.error.3").hide();
	$(".popup.error.4").hide();
	$(".popup.error.5").hide();
	$(".popup.error.6").hide();
	$(".popup.error.7").hide();
	
	email = $("#EMAIL").val();
	emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	
	if ($("#NAME").val() == "") {
		error += 'Por favor, rellene el campo nombre \n';
		$(".popup.error.1").show();
	}
	/*else if ($("#SURNAME").val() == "") {
		error += 'Por favor, rellene el campo apellidos\n';
		$(".popup.error.2").show();
	}*/
	else if ($("#EMAIL").val() == "") {
		error += 'Por favor, rellene el campo Email\n';
		$(".popup.error.3").show();
	}
	else if(!emailReg.test(email)) {
  		error += 'Por favor, introduzca una dirección de email válida';
  		$(".popup.error.4").show();
  	}
	/*else if ($("#PHONE").val() == "") {
		error += 'Por favor, rellene el campo Teléfono\n';
		$(".popup.error.5").show();
	}*/
	else if ($("#COMMENT").val() == "") {
		error += 'Por favor, rellene el campo Consulta\n';
		$(".popup.error.6").show();
	}
	else if ($("#CONDICIONES").is(':checked') == false) {
		error += 'Debe aceptar los términos y condiciones\n';
		$(".popup.error.7").show();
	}
	/*else if (document.le_escribimos.disclaimer.checked == false) {
		error += 'Debe aceptar los tÃ©rminos y condiciones\n';
		$(".popup.error.4").show();
	}*/
		
	/*email = $("#email-escribimos").val();
	emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;*/

	if(error!="") {
		//alert(error);
		return false;			
	}
	else {
		//alert('Información enviada. Gracias');
		return true;
	}
}

function validaFormNewsletter() {
	error = "";
	$('.div_blue_int .aviso.1').css({display: "none"});
	$('#contenedor_int #content_left .aviso.1').css({display: "none"});
	$('.div_blue_int .aviso.2').css({display: "none"});
	$('#contenedor_int #content_left .aviso.2').css({display: "none"});
	$('.div_blue_int .aviso.3').css({display: "none"});
	$('#contenedor_int #content_left .aviso.3').css({display: "none"});
	
	email = $("#email").val();
	emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	
	if ($("#name").val() == "") {
		error += 'Por favor, rellene el campo Nombre \n';
		$('.div_blue_int .aviso.1').css({display: "block"});
		$('#contenedor_int #content_left .aviso.1').css({display: "block"});
	}
	else if ($("#email").val() == "") {
		error += 'Por favor, rellene el campo Email\n';
		$('.div_blue_int .aviso.2').css({display: "block"});
		$('#contenedor_int #content_left .aviso.2').css({display: "block"});
	}
	else if(!emailReg.test(email)) {
  		error += 'Por favor, introduzca una dirección de email válida';
  		$('.div_blue_int .aviso.3').css({display: "block"});
		$('#contenedor_int #content_left .aviso.3').css({display: "block"});
  	}
  	else if (document.frmemail.conditions.checked == false) {
		error += 'Debe aceptar las condiciones legales\n';
		$('.div_blue_int .aviso.4').css({display: "block"});
		$('#contenedor_int #content_left .aviso.4').css({display: "block"});
	}
	if(error!="") {
		//alert(error);
		return false;			
	}
	else {
		//alert('Información enviada. Gracias');
		return true;
	}
}

function validaFormRinconSocio() {
	error = "";
	$(".popup.error.1").hide();
	$(".popup.error.2").hide();
	$(".popup.error.3").hide();
	$(".popup.error.4").hide();
	$(".popup.error.5").hide();
	$(".popup.error.6").hide();
	$(".popup.error.10").hide();
	$(".popup.error.11").hide();
	
	email = $("#EMAIL").val();
	emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	
	if ($("#USER").val() == "") {
		error += 'Por favor, rellene el campo ussuario \n';
		$(".popup.error.10").show();
	}
	else if ($("#PASSWORD").val() == "") {
		error += 'Por favor, rellene el campo contraseña\n';
		$(".popup.error.11").show();
	}
	
	if(error!="") {
		//alert(error);
		return false;			
	}
	else {
		//alert('Información enviada. Gracias');
		return true;
	}
}

