function limpiaRadio(ctrl) {
	var i 
    for (i=0;i<ctrl.length;i++){ 
       ctrl[i].checked=false;
    } 
}

function limpia(){
	document.getElementById('InputField-1').selectedIndex=0;
	limpiaRadio(document.srvEncuesta['InputField-2']);
	limpiaRadio(document.srvEncuesta['InputField-3']);
	document.getElementById('InputField-4').selectedIndex=0;
	document.getElementById('InputField-5').value='';
	document.getElementById('InputField-6').value='';
}	

function validaCampoVacio(cadena) {
	for ( i = 0; i < cadena.length; i++ ) {
		if ( cadena.charAt(i) != " " ) {
			return true
		}
	}
	return false
}

function validaFormatoEmail(cadena) {

	var str=document.getElementById("InputField-6").value;
	var filter=/^.+@.+\..{2,3}$/;

	if (filter.test(str))
	{
		return true;
	}
	else
	{
		return false
	}
}

function validaRadio(ctrl) {
	var i
    for (i=0;i<ctrl.length;i++){ 
       if (ctrl[i].checked) 
          return true; 
    } 
	return false;
}

function getRadioIndex(ctrl) {
	var i
    for (i=0;i<ctrl.length;i++){ 
       if (ctrl[i].checked) 
          return i; 
    } 
	return -1;
}

function validaSelect(CB) {
	
	if (CB.selectedIndex == null) return false;
	if (CB.selectedIndex == 0) return false;
	
	return true
}

function validaCampoNumerico(numero) {

    for (i=0;i<numero.length;i++){
        var car_num = numero.substr(i,1);
        var car_validos = "0123456789";
        var correcto = false;
        for (j=0;j<car_validos.length;j++){
                var car;
                car = car_validos.substr(j,1);
                if (car==car_num){
                    correcto = true;
                    j=car_validos.length;
                }
        }
        if (correcto==false){
            return false;
        }
    }
    return true;
} 

function validaRangoEdad(edad) {
	
	if (parseInt(edad)>=55 && parseInt(edad)<=110) return true
		
	return false
}

	
function enviar() {
				
	var msgerror = "";
					
	// validate field 'Destino'
	if (!(validaSelect(document.getElementById('InputField-1')))) msgerror = msgerror + destino + errorLista + '\n';
													
	// validate field 'Duracion'
	if (!(validaRadio(document.srvEncuesta['InputField-2']))) msgerror = msgerror + numDias + errorRadio + '\n';
												
	// validate field 'Actividad'
	if (!(validaRadio(document.srvEncuesta['InputField-3']))) msgerror = msgerror + actividades + errorRadio + '\n';			
											
	// validate field 'Pais'
	if (!(validaSelect(document.getElementById('InputField-4')))) msgerror = msgerror + paisOrigen + errorLista + '\n';	
											
	// validate field empty 'CP'
	if (!(validaCampoVacio(document.getElementById('InputField-5').value))) 
	{
		msgerror = msgerror + cpMal + errorCampoVacio + '\n';
	}else{			
		// validate field numeric 'CP'
		if (!(validaCampoNumerico(document.getElementById('InputField-5').value))) msgerror = msgerror + cpMal + errorCampoNumerico + '\n';	
	}
														
	// validate field empty 'Email'
	if (!(validaCampoVacio(document.getElementById('InputField-6').value))) 
	{
		msgerror = msgerror + emailMal + errorCampoVacio + '\n';
	}else{			
		// validate field format 'Email'
		if (!(validaFormatoEmail(document.getElementById('InputField-6').value))) msgerror = msgerror + emailMal + errorFormatoEmail + '\n';	
	}
									
	if (msgerror!="")
	{
		alert(msgerror)
	}else{
		document.srvEncuesta.submit();
	}				
}