
//return yyyy-mm-dd  format
Date.prototype.asString = function(){
	
	var d = this.getDate().toString();
	var m = (this.getMonth()+1).toString();
	var y = this.getFullYear().toString();

	return (y+"-"+m+"-"+d);

}

//add interval to date
Date.prototype.add = function (sInterval, iNum){
  var dTemp = this;
  if (!sInterval || iNum == 0) return dTemp;
  switch (sInterval.toLowerCase()){
    case "ms":
      dTemp.setMilliseconds(dTemp.getMilliseconds() + iNum);
      break;
    case "s":
      dTemp.setSeconds(dTemp.getSeconds() + iNum);
      break;
    case "mi":
      dTemp.setMinutes(dTemp.getMinutes() + iNum);
      break;
    case "h":
      dTemp.setHours(dTemp.getHours() + iNum);
      break;
    case "d":
      dTemp.setDate(dTemp.getDate() + iNum);
      break;
    case "mo":
      dTemp.setMonth(dTemp.getMonth() + iNum);
      break;
    case "y":
      dTemp.setFullYear(dTemp.getFullYear() + iNum);
      break;
  }
  return dTemp;
}

//set the correct index of combos from the date value
Date.prototype.fillCombos = function(cboday,cbomonth,cboyear){
		
		this.fillCombo(cboyear,"year");
		this.fillCombo(cbomonth,"month");
		this.fillCombo(cboday,"day");
}


//set the correct index of a combo from date value
Date.prototype.fillCombo = function(cbo,t){
	
	var type = (t==undefined)?((cbo.length>3)?((cbo.length>12)?"day":"month"):"year"):t;

	switch(type){
	case "day":
		cbo.selectedIndex = (parseInt(Math.abs(this.getDate()))-1);
		break;
	
	case "month":
		cbo.selectedIndex = (parseInt(Math.abs(this.getMonth())));
		break;
	case "year":
		for(n=0;n<cbo.options.length;n++){
			if(cbo.options[n].value== this.getFullYear()){
				cbo.selectedIndex = n;
			}
		}
		break;
	}

}

Date.prototype.setToDate = function(s){
	var dTemp = this;
	var a =  s.split("-");
	try{
		dTemp.setDate(parseInt(Math.abs(a[2])));
		dTemp.setMonth(parseInt(Math.abs(a[1]))-1);
		dTemp.setFullYear(a[0]);
	}catch(e){}
	
	return dTemp;
	
}


Date.prototype.DaysDiff = function (dtcompare){
	
	//alert((this.getTime()/86400000) + " "   + (dtcompare.getTime()/86400000));
	
		var diff = Math.floor(this.getTime()/86400000) - Math.floor(dtcompare.getTime()/86400000);//(this.getTime()-dtcompare.getTime());
		//var daysdiff = (Math.abs(diff)>86400000)?(diff/86400000):0;
		var days = diff; //Math.floor(diff);
		
		//alert(days);
		return days;	
}
