var daysInMonth = new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30 ,31);
var mDay="El valor del Día no es correcto.";
var mMonth="El valor del Mes no es correcto.";
var mYear="El valor del Año no es correcto.";
var mHour="El valor de la Hora no es correcto.";
var mMinute="El valor de los Minutos no es correcto.";
var mDate="La fecha no es válida.";
var mDates="Intervalo de fechas no válido.";


function posarInputTextABlancs (element)
{
        element.value = "";
        return true;        
}


function anularClicks (grupoRadios)
{
        if (typeof grupoRadios =='undefined')
        { }
        else
        {
                for (var i=0; i<grupoRadios.length;i++)
                {
                        grupoRadios[i].checked=false;
                                        
                }
        }
        return true;       
}

function anularClicksCheck (grupoRadios)
{

        if (typeof grupoRadios =='undefined')
        { }
        else
        {
               grupoRadios.checked=false;
                                        
        }
        return true;       
}


function alertInvalid (theField, s) {
   theField.focus()
   theField.select()
   alert(s)
   return false
}

function twoDigits(theField){
   if( theField.value.length==1) theField.value='0'+theField.value;
}


function isEmpty(s){
   return ((s == null) || (s.length == 0))
}


function checkDay (theField) {
   twoDigits(theField);
   if (isEmpty(theField.value) || !isDay(theField.value)) return alertInvalid (theField, mDay);
   else return true;
}

function isDay (value) {
   num = parseInt(value, 10);
   if( !isNaN(num) ) if( num>=1 && num<=31 ) return true;
   return false;
}

function checkMonth (theField) {
   twoDigits(theField);
   if (isEmpty(theField.value) || !isMonth(theField.value)) return alertInvalid (theField, mMonth);
   else return true;
}

function isMonth (value) {
   num = parseInt(value, 10);
   if( !isNaN(num) ) if( num>=1 && num<=12 ) return true;
   return false;
}

function checkYear (theField) {
   if (isEmpty(theField.value) || !isYear(theField.value)) return alertInvalid (theField, mYear);
   else return true;
}

function isYear (value){
   num = parseInt(value, 10);
   if( !isNaN(num) ) if( num>=2000 && num<2100 ) return true;
   return false;
}

function checkHour (theField) {
   twoDigits(theField);
   if (isEmpty(theField.value) || !isHour(theField.value)) return alertInvalid (theField, mHour);
   else return true;
}

function isHour (value){
   num = parseInt(value, 10);
   if( !isNaN(num) ) if( num>=0 && num<=23) return true;
   return false;
}

function checkMinute (theField) {
   twoDigits(theField);
   if (isEmpty(theField.value) || !isMinute(theField.value)) return alertInvalid (theField, mMinute);
   else return true;
}

function isMinute (value){
   num = parseInt(value, 10);
   if( !isNaN(num) ) if( num>=0 && num<=59) return true;
   return false;
}


function checkDate (yearField, monthField, dayField) {
   if( !checkYear(yearField) ) ;
   else if( !checkMonth(monthField) );
   else if( !checkDay(dayField) ) ;
   else if( !isDate(yearField.value, monthField.value, dayField.value)) return alertInvalid (dayField, mDate);
   else return true;
}

function isDate (year, month, day){
   var intYear = parseInt(year);
   var intMonth = parseInt(month);
   var intDay = parseInt(day);
   if (intDay > daysInMonth[intMonth]) return false; 
   if ((intMonth == 2) && (intDay > (year % 4 == 0 ? 29 : 28) )) return false;
   return true;
}

function minuscules(str)
{
	if(str==null) return str;

	re = /$_/;
	str = trim(str);
	name = str.split(re);
	return(name.toLowerCase());
}

function majuscules(str)
{
	if(str==null) return str;

	re = /$_/;
	str = trim(str);
	name = str.split(re);
	// JJ - 20/02/2008 - Correccions Firefox/Safari -->
	name = name + "";
	// <-- JJ - 20/02/2008 - Correccions Firefox/Safari
	return(name.toUpperCase());
}


function trim(stri)
{
	if (stri==null) return "";
	
	var aa=0;	
    var strfinal = stri;

	while ((aa <= parseInt(stri.length)) && (stri.charAt(aa)==" "))
	{
	  strfinal = stri.substring(aa+1,parseInt(stri.length));
	  aa++;
    }
   return strfinal;
}

//CLUB_SERVICAIXA->
function validarNumero(elm)
{
	if (elm==null) return false;
		
	for (var i = 0; i < elm.length; i++) 
	{
		if (elm.charAt(i) < "0" || elm.charAt(i) > "9")
			return false;
	}	   
	return true;
}
//<-CLUB_SERVICAIXA

function conteCaractersIncorrectes(pInputHTML)
{
	if(pInputHTML != null && pInputHTML.value != null)
	{
		return cadenaConteCaractersIncorrectes(pInputHTML.value);
	}
	return false;
};

function cadenaConteCaractersIncorrectes(strEntrada)
{
	if(strEntrada != null && strEntrada.length > 0)
	{
		if (strEntrada.indexOf('<') >= 0 
		|| strEntrada.indexOf('>') >= 0 
//		|| strEntrada.indexOf('-') >= 0 
		|| strEntrada.indexOf('+') >= 0 
		|| strEntrada.indexOf('*') >= 0 
		|| strEntrada.indexOf('=') >= 0 
		|| strEntrada.indexOf('/') >= 0 
		|| strEntrada.indexOf('?') >= 0 
		|| strEntrada.indexOf('¿') >= 0 
		|| strEntrada.indexOf('!') >= 0 
		|| strEntrada.indexOf('¡') >= 0 
		|| strEntrada.indexOf('&') >= 0)
		{
			return true;
		}
	}
	
	return false;
}