	
	/**
	 * Cambia los select de los depentedientes de acuerdo al elemento seleccionado 
	 * en el select padre
	 * @param {Object} hotelId
	 */
	function cambiaSelect(selected, optionsList, selectOrigin, selectUpdate){
	  
      
	   if(typeof optionsList == "undefined") {
			//window.alert(typeof optionsList);
			return ;
	  }
	   var VALUE = 0; //ID_HOTEL = 0;
	   var TEXT = 1;  //NOMBRE_HOTEL = 1;

	   var myDestinoSelect = "";
       var i=0;
	   
  	   var mySelect = $(selectUpdate); // Select a actualizar...
	   var someNodeList = mySelect.getElementsByTagName('option');
       var nodes = $A(someNodeList);
      

       // Select donde tomamos los valores... seleccionado....
	   if($(selectOrigin)) { 					 
  	   	myDestinoSelect = $F(selectOrigin);
	   }

	   // Quitamos las opciones
	   /*
	    * 
	    * mySelect = document.getElementById('mySelect')
		  mySelect.remove(2) //removes the option with index 2
		
		  $(mySelect) # calls Element.extend(element) <- the culprit
		  mySelect.remove(2) //error because is calling prototype Element.remove()
	    */
		
       if(Prototype.Browser.IE)
	   {
	   	 nodes.each(function(node, index){ mySelect.options.remove(node);});
	   }else{
	   	 nodes.each(function(node, index){ node.remove();});
		 
	   }
	       
       // Hash con la relacion de destinos hoteles, se genera en add, edit director en el php
       /*  var hotelList = $H(
			{'cuba' : [['5','Habana Libre'], ['6', 'Gran Hotel Habana']],
			 'vallarta': [['1','Marriot'], ['2', 'Mayan Palace']]}
        );*/
      
	   //Accesamos al hash de la siguiente manera     hotelList[key] key=>nombreHotel
       //window.alert(optionsList.get(myDestinoSelect));
	   
	  //  myDestinoSelect --> Debe coincidir con el key de la tabla de hash
	   if(typeof optionsList.get(myDestinoSelect) != "undefined")
       {
           //window.alert(myDestinoSelect);
		   optionsList.get(myDestinoSelect).each(function(item) {
	          // window.alert('item id-->' + item[VALUE] + ' nombre-->' + item[TEXT]);
			   var newElem = document.createElement("option");
	           newElem.text = item[TEXT];
	           newElem.value = item[VALUE];
	           mySelect.options.add(newElem);
	           newElem = null;
          });
       } 
	   
	   // Mostramos seleccionada la opcion
	    if(selected != null && selected != '')
		{
			someNodeList = mySelect.getElementsByTagName('option');
			nodes = $A(someNodeList);
			nodes.each(function(node){ 
				if(node.value == selected)
				{
					node.selected = true;
					
				}
			});
		}
	  	//window.alert(hotelSeleccionado)
		
 	
       // Recorremos los valores del hash 
	}
	
	function addWorkedHours(setFocus){
		//window.alert("hola");
		var workedHours = 0;
		var totalHoras = 0;
		var i = 0;
		//var indice;
		
		// Indice
		for(i=0; i<wIndice; i++)
		{
			//window.alert(i);
			if($('workedHours' + i))
			{
				
				if (matchValidHour($F('workedHours' + i) + "")) {
					$('workedHours' + i).removeClassName('error');
					workedHours = validNumber($F('workedHours' + i));
					if (validNumber($F('workedHours' + i)) > 0) {
						totalHoras += workedHours;
					}
				}else{
					//alert("Formato de hora no valido -> " + $('workedHours' + i).value);
					//$('workedHours' + i).value = "";
					//$('workingAreas' + i).Element.focus($('workedHours' + i));
					$('workedHours' + i).addClassName('error');
					//$('workedHours' + i).activate();
					
				}
			}
			
		}
		//window.alert("Horas Trabajadas ->" + totalHoras);
		$('workedHours').update("");
		if($('workedHours'))
		{
			$('workedHours').update(totalHoras + " hrs.");			
		}

	}
	

	function toggleCosto(selected, showValue, elementId){
		//alert(selected);
		if(selected != showValue){
			$(elementId).hide();
		}else{
			$(elementId).show();
		}
		return;
	}
 /**
  *  Comprueba si una cadena hace match con el formato dado
  *  si no viene el parametro myRegExp se usa la expresion default
  * @param {Object} valor
  * @param {Object} myRegExp
  */
 function matchValidHour(valor, myRegExp){   
	var locRegExp = /^$|^(\d{1,2}(\.{1}5{1})?)$/;
	if(myRegExp != null)
	{
		locRegExp = regExpHour; // RegExpHour debe estar dado de alta en la pagina que llama
	}
	if (valor.match(locRegExp)) {   
		 return true;
	} else {     
		return false;
	}
 }

/* MOVIMIENTOS DE USUARIOS */
/* Manejo de las funcion de borrado de movimientos de staff */
	function hideMovement(elementId)
	{
		if($(elementId))
		{   
			Effect.Fade(elementId, {duration:.07, afterFinish: removeMovementTasks });
			//$(elementId).remove();
			//decoracionTabla('movements');
		}
	}
	
	/* Tareas de remocion de elementos despues de que terminar el efecto */
	function removeMovementTasks(obj)
	{
		removeMovement(obj);
		indice = decoracionTabla('movements');
		if(indice == 0)
		{
			Effect.Fade('movementsSection', {duration:.07, afterFinish: removeMovement });	
		}
		
	}
	
	function removeMovement(obj)
	{
		Element.remove('' + obj.element.id + '');
	}
	
	
	function decoracionTabla(elementId){
		
	    var tableBody = $(elementId);
        var trNodeList = tableBody.getElementsByClassName('tr');
        var nodes = $A(trNodeList);
		var i = 0;
		
		nodes.each(function(tr) {
           	tr.removeClassName('even');
			tr.removeClassName('odd');
		   if((i % 2) == 0)
		   {
			  tr.addClassName('even');
			  tr.addClassName('gerae');
		   }else{
			   tr.addClassName('odd');
			   tr.addClassName('geraa');
		   }
		   i++;
       });
	   
	   return i;
	  
	 }

/* FORMATERO DE CANTIDADES */
	function validNumber(valor){
 	  //window.alert('Antes de Parse->' + valor + ' Despues->' +  parseFloat(valor));
	  
	 valor += '';
	 valor = valor.toString().replace(/\$|\,/g,''); 
	 valor = parseFloat(valor);

      if (isNaN(valor)){
            return  parseFloat('0');
      } else {
            return valor;
      }
	}

//----------------------------------------------------------
//-- Manipula una cadena para el hacerlo formato moneda --
//----------------------------------------------------------
/*
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	num = parseFloat(num,10);
	var signo = '';
	if(isNaN(num)) 
		return(false);
	if(num<0){
		signo = '-'
		num = Math.abs(num);
	}
	num = num.toFixed(2); 
	*/ //<--
	// Redondea a dos decimales...
	/*---------------------------
	
	//cents = Math.floor((num*100+0.5)%100);
	cents =Math.ceil((num*100)%100);
	//window.alert(cents);
	num = Math.floor((num*100+0.5)/100).toString();
	if(cents < 10) 
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
		num = num.replace(/-,/, '-');
	return (signo + '' + num + '.' + cents);
	
	-----------------------------*/
	/*return (signo + '' + num);
}*/

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '' + dblValue + '.' + strCents);
}


/**
 * Formatea un numero 
 * 
 * @param {Object} num -> the number to format
 * @param {Object} decimalNum -> the number of decimal places to format the number to
 * @param {Object} bolLeadingZero  -> true / false - display a leading zero for
	 								numbers between -1 and 1
 * @param {Object} bolParens -> true / false - use parenthesis around negative numbers
 * @param {Object} bolCommas -> put commas as number separators.
 */

function FormatNumber(num, decimalNum, bolLeadingZero, bolParens, bolCommas){
	/**********************************************************************
 	 http://www.4guysfromrolla.com/webtech/code/FormatNumber.shtml
	 IN:
	 NUM - the number to format
	 decimalNum - the number of decimal places to format the number to
	 bolLeadingZero - true / false - display a leading zero for
	 numbers between -1 and 1
	 bolParens - true / false - use parenthesis around negative numbers
	 bolCommas - put commas as number separators.
	 
	 RETVAL:
	 The formatted number!
	 **********************************************************************/
	if (isNaN(parseInt(num))) 
		return "NaN";
	
	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1; // Get sign of number
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10, decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10, decimalNum);
	tmpNum *= iSign; // Readjust for sign
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);
	
	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0) 
		if (num > 0) 
			tmpNumStr = tmpNumStr.substring(1, tmpNumStr.length);
		else 
			tmpNumStr = "-" + tmpNumStr.substring(2, tmpNumStr.length);
	
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0) 
			iStart = tmpNumStr.length;
		
		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0, iStart) + "," + tmpNumStr.substring(iStart, tmpNumStr.length)
			iStart -= 3;
		}
	}
	
	// See if we need to use parenthesis
	if (bolParens && num < 0) 
		tmpNumStr = "(" + tmpNumStr.substring(1, tmpNumStr.length) + ")";
	
	return tmpNumStr; // Return our formatted string!
}
