function dateAddExtention(p_Interval, p_Number){

   var thing = new String();
   
   if(isNaN(p_Number)){   
      //Only accpets numbers 
      //throws an error so that the coder can see why he effed up   
      throw "The second parameter must be a number. \n You passed: " + p_Number;
      return false;
   }

   p_Number = new Number(p_Number);
   switch(p_Interval.toLowerCase()){
      case "yyyy": {// year
         this.setFullYear(this.getFullYear() + p_Number);
         break;
      }
      case "q": {      // quarter
         this.setMonth(this.getMonth() + (p_Number*3));
         break;
      }
      case "m": {      // month
         this.setMonth(this.getMonth() + p_Number);
         break;
      }
      case "y":      // day of year
      case "d":      // day
      case "w": {      // weekday
         this.setDate(this.getDate() + p_Number);
         break;
      }
      case "ww": {   // week of year
         this.setDate(this.getDate() + (p_Number*7));
         break;
      }
      case "h": {      // hour
         this.setHours(this.getHours() + p_Number);
         break;
      }
      case "n": {      // minute
         this.setMinutes(this.getMinutes() + p_Number);
         break;
      }
      case "s": {      // second
         this.setSeconds(this.getSeconds() + p_Number);
         break;
      }
      case "ms": {      // second
         this.setMilliseconds(this.getMilliseconds() + p_Number);
         break;
      }
      default: {      
         //throws an error so that the coder can see why he effed up and
         //a list of elegible letters.
         throw   "The first parameter must be a string from this list: \n" +
               "yyyy, q, m, y, d, w, ww, h, n, s, or ms.  You passed: " + p_Interval;
         return false;
      }
   }
   return this;
}

function dateCloneExtension(){
	var tempDate = new Date();
	tempDate.setTime(this.valueOf());
	return tempDate;
}

Date.prototype.dateAdd = dateAddExtention;
Date.prototype.clone = dateCloneExtension;

function restarFechas(fechaInicio,fechaFin) {
    var diferencia = fechaFin.getTime() - fechaInicio.getTime();

	var dias = Math.round(diferencia / (1000 * 60 * 60 * 24))

	return dias;
}

function cambioDias(diaInit, diaEnd, inputDias) {
	// Aun no hay salida, actualizamos límites y fecha
	tempFechaEntrada = fechaEntrada.date.clone().dateAdd('d', 1);		
	fechaSalida.setMinDate(tempFechaEntrada);
	if(fechaEntrada.date > fechaSalida.date){
		if(diaEnd != ''){
			alert("Ha seleccionado una fecha de salida anterior a la fecha de entrada, se actualizará la fecha de salida.");
		}
		fechaSalida.setDate(tempFechaEntrada.clone().dateAdd('ms', 10));
		fechaSalida.refreshDate();
		fechaSalida.callHandler();
	}	

	ficc = fechaEntrada.textDate().split("-");
	ficc = new Date(ficc[2],ficc[1]-1,ficc[0]);

	ficc2 = fechaSalida.textDate().split("-");
	ficc2 = new Date(ficc2[2],ficc2[1]-1,ficc2[0]);

	inputDias.value = restarFechas(ficc, ficc2);
}