function isValidDate(day, month, year) {
	
	if(!IsNumeric(day) && !IsNumeric(month) && !IsNumeric(year))
		return false;
	
	if (month < 1 || month > 12) 
		return false;
	
	if (day < 1 || day > 31)
		return false;
	
	if ((month == 4 || month == 6 || month == 9 || month == 11) &&
		(day == 31)) {
		return false;
	}

	if (month == 2) {
		var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day == 29 && !leap)) {
			return false;
		}
	}
	
	return true;
}

function IsNumeric(sText){
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}

function IsFloat(sText){
	var ValidChars = "0123456789,";
	var IsNumber=true;
	var Char;
	var numComas=0;
	
	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
			IsNumber = false;
		}
	}
	
	
	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if (Char == ",")
		{
			numComas++;
		}
	}
	
	if(numComas>1){
		IsNumber=false;
	}
	
	return IsNumber;
}

function isValidHour(hora,minutos){
    if(!IsNumeric(hora) && !IsNumeric(minutos))
        return false;
    
    if (hora < 0 || hora > 23)
        return false;

    if (minutos < 0 || minutos >59)
        return false;
        
    return true;
}

function deseaSalir(){
	if(confirm('\xBFDesea salir de la aplicaci\xF3n?')){
		window.top.location = "login.do?metodo=logout";
	}
}

/**
 * Acciones sobre Select's 
 */
function seleccionaTodos(srcSelect){
	for(i=0;i<srcSelect.length;i++){
		srcSelect.options[i].selected = true;
	}
}

function moverTodos(srcSelect,destSelect){
	var i;
	for(i=0;i<srcSelect.length;i++){
		selectInsertaDatos(destSelect,srcSelect.options[i].value,srcSelect.options[i].text);
	}
	for(i=srcSelect.length;i>=0;i--){
		srcSelect.remove(i);
	}
}

function selectInsertaDatos(destSelect,valor,texto){
	var newElem = new Option();
	newElem.text = texto;
    newElem.value = valor;
    newElem.selected = true;
    destSelect.options.add(newElem);
}

function insertaValor(srcSelect,destSelect){
	var indice;
	indice = srcSelect.options.selectedIndex;
	if(indice>=0){
		selectInsertaDatos(destSelect,srcSelect.value,srcSelect.options[indice].text);
		srcSelect.remove(indice);
	}
}
	
function ClearList(OptionList, TitleName){
	OptionList.length = 0;
}
		
function move(side, idOrigen, idDestino){   
	var temp1 = new Array();
	var temp2 = new Array();
	var tempa = new Array();
	var tempb = new Array();
	var current1 = 0;
	var current2 = 0;
	var y=0;
	var attribute;
	
	//assign what select attribute treat as attribute1 and attribute2
	if (side == "right"){  
		attribute1 = document.getElementById(idOrigen); 
		attribute2 = document.getElementById(idDestino); 
	}else{  
		attribute1 = document.getElementById(idDestino);
		attribute2 = document.getElementById(idOrigen);
	}

	//fill an array with old values
	for (var i = 0; i < attribute2.length; i++){  
		y=current1++
		temp1[y] = attribute2.options[i].value;
		tempa[y] = attribute2.options[i].text;
	}

	//assign new values to arrays
	for (var i = 0; i < attribute1.length; i++){   
		if ( attribute1.options[i].selected ){  
			y=current1++
			temp1[y] = attribute1.options[i].value;
			tempa[y] = attribute1.options[i].text;
		}else{  
			y=current2++
			temp2[y] = attribute1.options[i].value; 
			tempb[y] = attribute1.options[i].text;
		}
	}

	//generating new options 
	for (var i = 0; i < temp1.length; i++){  
		attribute2.options[i] = new Option();
		attribute2.options[i].value = temp1[i];
		attribute2.options[i].text =  tempa[i];
	}

	//generating new options
	ClearList(attribute1,attribute1);
	if (temp2.length>0){	
		for (var i = 0; i < temp2.length; i++){   
			attribute1.options[i] = new Option();
			attribute1.options[i].value = temp2[i];
			attribute1.options[i].text =  tempb[i];
		}
	}
}

function countSelectedValues(ctrl) {
	count = 0;
	if (ctrl.length != undefined){
		for(i=0;i<ctrl.length; i++)
			if (ctrl[i].selected) count++;
	}else{
		if (ctrl.selected)
			count = 1;
	}
	return count;
}

function selectAll(ctrl){
	if(ctrl.length>0){
		for(i=0;i<ctrl.length;i++){
			ctrl.options[i].selected = true;
		}
	}
}

function desSelectAll(ctrl){
	if(ctrl.length>0){
		for(i=0;i<ctrl.length;i++){
			ctrl.options[i].selected = false;
		}
	}
}
function compareDates(desde,hasta)
{
	var desdeSplit =  desde.split("\/");
	var fechaDesde = new Date(desdeSplit[2].substring(0,4), desdeSplit[1]-1, desdeSplit[0]);

	var hastaSplit =  hasta.split("\/");
	var fechaHasta = new Date(hastaSplit[2].substring(0,4), hastaSplit[1]-1, hastaSplit[0]);

    	if (fechaDesde==fechaHasta) return 0;
    	if (fechaDesde<fechaHasta) return 1;
    	if (fechaDesde>fechaHasta) return 2;
}
