//Valida el nombre de fichero pasado por parámetro con las extensiones separadas por comas
//pasadas como string
function checkFileExtesion( pathName, allowedExt ){

	var ext = allowedExt.split( "," );

	for ( i=0; i < ext.length; i++ ){
		
		if ( pathName.toUpperCase().lastIndexOf( "." + Trim( ext[i].toUpperCase() ) ) > -1 ){
			return true;
		}
		
	}
	
	return false;

}

//Se encarga de chequear-deschequear un grupo de checkbox con el mismo "name" 
//a partir de otro checkbox selector
function HeaderCheck( selector, checkboxArray ){
	
	var chkState = selector.checked;
	
	if ( checkboxArray ){
		
		if ( checkboxArray.length ){
	
			for( i=0; i < checkboxArray.length; i++ ){
				checkboxArray[i].checked = chkState;
			}
		
		} else {
		
			checkboxArray.checked = chkState;
		
		}
	
	}
	
}

//Pasado un array de checkbox devuelve el número de elementos seleccionados
function CountSelectedCheckboxes( checkboxArray ){
	
	var checkedCount = 0;
	
	if ( checkboxArray ){
	
		if ( checkboxArray.length ){
		
			for( i=0; i < checkboxArray.length; i++ ){
			
				if( checkboxArray[i].checked ) 
					checkedCount++
					
			}
		
		} else {
		
			if( checkboxArray.checked ) 
					checkedCount++
		
		}
	
	}
	
	return checkedCount;

}

// Modifica la imagen de todos los "radiobuttons" a una determinada(src)
function uncheckall(obj, src) {
		
	var sId;

	if(obj) {
				
		if(obj.length) {
						
			for(i=0;i<obj.length;i++) {
				sId = obj[i].id.substring(1);
				document.getElementById(sId).src = src;
			}
			
		}
		else {
				sId = obj.id.substring(1);
				document.getElementById(sId).src = src;
		}
				
	}
			
}

// Activa/Desactiva una caja de texto
function activate(objid, action) {

	var obj;
	obj = document.getElementById(objid);

	if(obj) {
	
		if (action == true) {
			
			obj.disabled = false;
			obj.focus();
			
		}
		else {
			
			obj.disabled = true;
			obj.value = "";
			
		}
	
	}
	
}

// Funcion que valida un mail
// Recibe como parámetro el campo del form
function emailFormatValidator(pscampo)
{
   if (pscampo.value.length > 0){
      if(pscampo.value.match(/^\w+([\.\-]\w+)*@(\w+\-*\w+\.)+[a-z]{2,4}$/i))
       {
        return true;
       }else{
        return false
       }
   }
}

// Función que valida que un campo sea un entero positivo
function isIntegerInput( objInput, fieldName )
{
	var ValidChars;
	var IsNumber=true;
	var Char;
	
	ValidChars = "0123456789";
	
	if ( isNaN( objInput.value ) ){

		IsNumber = false;
		
	} else {
		
		for (i = 0; i < objInput.value.length && IsNumber == true; i++) 
		{ 
			Char = objInput.value.charAt(i); 
			if (ValidChars.indexOf(Char) == -1) 
			{
				IsNumber = false;
				break;
			}
		}
		
	}
	
	if( !IsNumber )
	{
		if ( fieldName != "" ){
			
			alert( "El campo " + fieldName + " debe ser un entero positivo." );
			
		} else {
		
			alert( "El campo debe ser un entero positivo." );
	
		}
		
		objInput.focus();
		return false;	
		
	} else {
	
		return true;
		
	}
}
