function checkform(f) {
   var message=""; //initialise message to null
   for(i=0;i<fldArr.length;i++){
	     if (f[fldArr[i]].value.length==0){ 
	        message = message + msg[fldArr[i]];
	     }
		}
	for(i=0;i<fldArr.length;i++){
     if (f[fldArr[i]].value.toUpperCase()==fldArr[i].toUpperCase( )){
        message = message + msg[fldArr[i]];
     }
	}
	posmail = busca(fldArr,"mail");
	if(!posmail){ posmail = busca(fldArr,"email"); }
	pospob = busca(fldArr,"poblacion");
	if(f[fldArr[pospob]].value.substring(0,7)=="Poblaci"){
		message = message + msg[fldArr[pospob]];
	}
	if(posmail){
		if(!mail(f[fldArr[posmail]].value)){
			message = message + msg[fldArr[posmail]];
		}
	}
   for(i=0;i<radioArr.length;i++)
	if (!getSelectedRadio(f[radioArr[i]])) {
        	message = message + msg[radioArr[i]];
	}
   if(message=="") {
     return true 
   }
   else { 	
     alert(message);
     return false;
   }
} // end of the function checkform()

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return true
         }
      }
   } else {
      if (buttonGroup.checked) { return true; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return false;
} // Ends the "getSelectedRadio" function


function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function
function mail(texto){

    var mailres = true;            
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
    
    var arroba = texto.indexOf("@",0);
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
    
    var punto = texto.lastIndexOf(".");
                
     for (var contador = 0 ; contador < texto.length ; contador++){
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
            mailres = false;
            break;
     }
    }

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
     mailres = true;
    else
     mailres = false;
                
    return mailres;
}
function busca(varble,valor){
	for(i=0;i<fldArr.length;i++)
     if (fldArr[i]==valor){
        pos = i;
		return pos;
     }
	 return false;
}
//var checkBoxArr = getSelectedCheckbox(document.forms[0].MyCheckBox);
//if (checkBoxArr.length == 0) { alert("No check boxes selected"); }
