

/////////////////// Plug-in file for CalendarXP 7.0 /////////////////
// This file is totally configurable. You may remove all the comments in this file to shrink the download size.
/////////////////////////////////////////////////////////////////////

///////////// Calendar Onchange Handler ////////////////////////////
// It's triggered whenever the calendar gets changed.
// d = 0 means the calendar is about to switch to the month of (y,m); 
// d > 0 means a specific date [y,m,d] is about to be selected.
// Return a true value will cancel the change action.
// NOTE: DO NOT define this handler unless you really need to use it.
////////////////////////////////////////////////////////////////////
function fOnChange(y,m,d) {
	return false;  // return true to cancel the change.
}


///////////// Calendar AfterSelected Handler ///////////////////////
// It's triggered whenever a date gets fully selected.
// The selected date is passed in as y(ear),m(onth),d(ay)
// NOTE: DO NOT define this handler unless you really need to use it.
////////////////////////////////////////////////////////////////////
function fAfterSelected(y,m,d) {
	//	alert(y+'-'+m+'-'+d);
	try{
		gdCtrl.focus();
	}catch(er){}
	return;
}


///////////// Calendar Cell OnDrag Handler ///////////////////////
// It triggered when you try to drag a calendar cell. (y,m,d) is the cell date. 
// aStat = 0 means a mousedown is detected (dragstart)
// aStat = 1 means a mouseover between dragstart and dragend is detected (dragover)
// aStat = 2 means a mouseup is detected (dragend)
// Return true to skip the set date action, if any.
// NOTE: DO NOT define this handler unless you really need to use it.
////////////////////////////////////////////////////////////////////
// function fOnDrag(y,m,d,aStat) {}


// ====== Following are self-defined and/or custom-built functions! =======

function fStartPop(startc,endc,ExcludeDate) {
  var sd=fParseDate(endc.value); 
  if (!sd) sd=gEnd;
  if(ExcludeDate && ExcludeDate.value.length>0){
     eval("fPopCalendar(startc, [gBegin,sd,sd,"+ExcludeDate.value+"])");
  }else{
	 fPopCalendar(startc, [gBegin,sd,sd]);
  }//if
}

function fEndPop(startc,endc,ExcludeDate) {
  var sd=fParseDate(startc.value);
  if (!sd) sd=gBegin; 
  if(ExcludeDate && ExcludeDate.value.length>0){
	eval("fPopCalendar(endc, [sd,gEnd,sd,"+ExcludeDate.value+"])");
  }else{
	fPopCalendar(endc, [sd,gEnd,sd]);
  }//if
}

function fBetweenPop(dateCtrl, startc, endc, ExcludeDate){
  var sd=fParseDate(startc.value);
  var ed=fParseDate(endc.value);  
  if(sd && ed){
	  if(ExcludeDate && ExcludeDate.value.length>0){
		  eval("fPopCalendar(dateCtrl, [sd,ed,sd,"+ExcludeDate.value+"])");
	  }else{
		  fPopCalendar(dateCtrl, [sd,ed,sd]);
	  }//if
  }else{
	fPopCalendar(dateCtrl);
  }
}


function fDateDiff(startDateV ,finishDateV){
	var arrayDate  = startDateV.split("/");
	var _date = (Math.abs(arrayDate[1]))+"/"+(Math.abs(arrayDate[0]))+"/"+(Math.abs(arrayDate[2]));
	var	startDate  = new Date(Date.parse(_date));
	
	arrayDate = finishDateV.split("/");
	_date =  (Math.abs(arrayDate[1]))+"/"+(Math.abs(arrayDate[0]))+"/"+(Math.abs(arrayDate[2]));
	var finishDate = new Date(Date.parse(_date));
	
	return parseInt((finishDate - startDate)/(1000*60*60*24));
}

function fDateAdd(DateV, numDays, numMonths, numYears)
{
	//
	var sdate = DateV.split("/");
	var indate = (Math.abs(sdate[1]))+"/"+(Math.abs(sdate[0]))+"/"+(Math.abs(sdate[2]));
	startDate = new Date(Date.parse(indate));
	//

	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = parseInt(numYears);
	
	var month = parseInt(returnDate.getMonth())+ parseInt(numMonths);

	if (month > 11)
	{
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += parseInt(numYears);
	}
	
	returnDate.setMonth(parseInt(month));
	returnDate.setFullYear(returnDate.getFullYear()+ yearsToAdd);
	returnDate.setTime(returnDate.getTime()+1000*60*60*24*numDays);
	
	if(gbPadZero)
		return (returnDate.getDate()<10?"0"+returnDate.getDate():returnDate.getDate())+"/"+((returnDate.getMonth()+1)<10?"0"+(returnDate.getMonth()+1):returnDate.getMonth()+1)+"/"+(returnDate.getFullYear());
	else
		return (returnDate.getDate())+"/"+(returnDate.getMonth()+1)+"/"+(returnDate.getFullYear());

}
