function validateForm(f) {

	if (trim(f.nombre.value)=="") {		
		document.getElementById('lb_nombre').style.color="red";
		alert("El campo Nombre es obligatorio");
		f.elements['nombre'].focus();
		return false;
		}
	else
	{   
		document.getElementById('lb_nombre').style.color="black";		
	}
	
	if (trim(f.apellidos.value)=="") {
		document.getElementById('lb_apellidos').style.color="red";
		alert("El campo Apellidos es obligatorio");		
		f.elements['apellidos'].focus();
		return false;
		}
	else
	{
		document.getElementById('lb_apellidos').style.color="black";
	}	
	
	if (trim(f.direccion.value)=="") {
		document.getElementById('lb_direccion').style.color="red";
		alert("El campo Dirección es obligatorio");		
		f.elements['direccion'].focus();
		return false;
		}
	else
	{
		document.getElementById('lb_direccion').style.color="black";
	}	
	
	if (trim(f.cp.value)=="") {
		document.getElementById('lb_cp').style.color="red";
		alert("El campo CP es obligatorio");		
		f.elements['cp'].focus();
		return false;
		}
	else
	{
		document.getElementById('lb_cp').style.color="black";
	}
	
	if (trim(f.poblacion.value)=="") {
		document.getElementById('lb_poblacion').style.color="red";
		alert("El campo Población es obligatorio");		
		f.elements['poblacion'].focus();
		return false;
		}
	else
	{
		document.getElementById('lb_poblacion').style.color="black";
	}
	
	if (trim(f.provincia.value)=="") {
		document.getElementById('lb_provincia').style.color="red";
		alert("El campo Provincia es obligatorio");		
		f.elements['provincia'].focus();
		return false;
		}
	else
	{
		document.getElementById('lb_provincia').style.color="black";
	}				
	
	if (trim(f.telefono.value)=="") {
		document.getElementById('lb_telefono').style.color="red";
		alert("El campo Teléfono es obligatorio");		
		f.elements['telefono'].focus();
		return false;
		}
	else
	{
		document.getElementById('lb_telefono').style.color="black";
	}		
	
	if (trim(f.dni.value)=="") {
		document.getElementById('lb_dni').style.color="red";
		alert("El campo DNI es obligatorio");		
		f.elements['dni'].focus();
		return false;
		}
	else
	{
		document.getElementById('lb_dni').style.color="black";
	}
	
	if (f.mes.value==0) {
		document.getElementById('lb_mes').style.color="red";
		alert("El campo Mes de suscripcion es obligatorio");		
		f.elements['mes'].focus();
		return false;
		}
	else
	{
		document.getElementById('lb_mes').style.color="black";
	}	
	
	/*OBTENER valor del radioButton*/
	val = radioValue(f.pago);	

    /*	
	if (val==2){
	    
	    if (trim(f.cheque.value)=="") {
		    document.getElementById('lb_cheque').style.color="red";
		    alert("El campo Cheque es obligatorio");		
		    f.elements['cheque'].focus();
		    return false;
		    }
	    else
	    {
		    document.getElementById('lb_cheque').style.color="black";
	    }	    
	
	}
	*/
	
	if (val==3){
	
	    var cuentaA = trim(f.bcuentaA.value);
	    var cuentaB = trim(f.bcuentaB.value);
	    var cuentaC = trim(f.bcuentaC.value);
	    var cuentaD = trim(f.bcuentaD.value);
	    
	    if (trim(f.bcuentaA.value)=="" || cuentaA.length < 4 || trim(f.bcuentaB).value=="" || cuentaB.length < 4 || trim(f.bcuentaC.value)==""  || cuentaC.length < 2 || trim(f.bcuentaD.value)=="" || cuentaD.length < 10) {
		    document.getElementById('lb_bcuenta').style.color="red";
		    alert("El campo Cuenta bancaria no es correcto");		
		    f.elements['bcuentaA'].focus();
		    return false;
		    }
	    else
	    {
		    document.getElementById('lb_bcuenta').style.color="black";
	    }	
    	
	    if (trim(f.btitular.value)=="") {
		    document.getElementById('lb_btitular').style.color="red";
		    alert("El campo Titular es obligatorio");		
		    f.elements['btitular'].focus();
		    return false;
		    }
	    else
	    {
		    document.getElementById('lb_btitular').style.color="black";
	    }    	    	    
	    	    
	
	}	
		
	return true;
	
}

function formaPago(forma) {

    var resetTransferencia;
    var resetBanco;

    if (forma==1){        
        resetTransferencia=1;
        resetBanco=1;    
    } 

    if (forma==2){        
        resetBanco=1;          
    } 
    
    if (forma==3){
        resetTransferencia=1;    
    }         
    
    if (resetTransferencia==1){
        document.getElementById('cheque').value="";        
        document.getElementById('lb_cheque').style.color="black";
    }             
    
    if (resetBanco==1){
    
        document.getElementById('banco').value="";
        document.getElementById('bdomicilio').value="";
        document.getElementById('bpoblacion').value="";
        document.getElementById('bcp').value="";
        document.getElementById('bprovincia').value="";
        document.getElementById('bcuentaA').value="";
        document.getElementById('bcuentaB').value="";
        document.getElementById('bcuentaC').value="";
        document.getElementById('bcuentaD').value="";
        document.getElementById('btitular').value="";
        
        document.getElementById('lb_banco').style.color="black";
        document.getElementById('lb_bdomicilio').style.color="black";
        document.getElementById('lb_bpoblacion').style.color="black";
        document.getElementById('lb_bcp').style.color="black";
        document.getElementById('lb_bprovincia').style.color="black";
        document.getElementById('lb_bcuenta').style.color="black";
        document.getElementById('lb_btitular').style.color="black";
        
    }       
    
}

function calcularPrecio() {

    var f = document.getElementById('formulario_suscripcion');
    var sel = document.getElementById('mes');
    var elemento = document.getElementById('suscripcion_precio');
    
    var miFecha = new Date() 
    var mesActual = miFecha.getMonth() +1;
    var mesSeleccionado = sel.options[sel.selectedIndex].value;    
    
    if (mesSeleccionado==0){
    
         elemento.innerHTML = "";
    
    } else {
        
        var totalMeses = (mesActual - mesSeleccionado) + (12 - mesActual) +1;
        
        /*OBTENER valor del radioButton*/
	    var val = radioValue(f.origenpago);
	    
        if (val==1) {
            var precio = totalMeses * 3.315;
        } 
        else if (val==2) {
            var precio = totalMeses * 3.187;        
        }
        else if (val==3) {
            var precio = totalMeses * 6.127;        
        }
        else if (val==4) {
            var precio = totalMeses * 8.490;        
        }        
        
        elemento.innerHTML = roundit(precio,2) + " Euros";
    
    }
    
}

function roundit(Num, Places) {
   if (Places > 0) {
      if ((Num.toString().length - Num.toString().lastIndexOf('.')) > (Places + 1)) {
         var Rounder = Math.pow(10, Places);
         return Math.round(Num * Rounder) / Rounder;
      }
      else return Num;
   }
   else return Math.round(Num);
}

function radioValue(radioButton)
{
    for (x = 0; x <= radioButton.length; x++)
    {
        if (radioButton[x].checked == true) return radioButton[x].value;
    }
         // if it didn't find anything, return the .value  (behaviour of single radio btn)
        return radioButton.value;
}