﻿_using("calendar.utils");
_using("calendar.calendar");
_using("calendar.calendar-zh");
_using("calendar.calendar-setup");
/*
 * Given two dates (in seconds) find out if date1 is bigger, date2 is bigger or
 * they're the same, taking only the dates, not the time into account.
 * In other words, different times on the same date returns equal.
 * returns -1 for date1 bigger, 1 for date2 is bigger 0 for equal
 */

function compareDatesOnly(date1, date2) {
	var year1 = date1.getYear();
	var year2 = date2.getYear();
	var month1 = date1.getMonth();
	var month2 = date2.getMonth();
	var day1 = date1.getDate();
	var day2 = date2.getDate();

	if (year1 > year2) {
		return -1;
	}
	if (year2 > year1) {
		return 1;
	}

	//years are equal
	if (month1 > month2) {
		return -1;
	}
	if (month2 > month1) {
		return 1;
	}

	//years and months are equal
	if (day1 > day2) {
		return -1;
	}
	if (day2 > day1) {
		return 1;
	}

	//days are equal
	return 0;
}

function dateInRange(date) {
	var today = new Date();
	var compareToday = compareDatesOnly(date, today);
	if (compareToday > 0) {
		return(true);
	}

	return false;
	//alert(ret + " " + today + ":" + date + ":" + compareToday + ":" + days1 + ":" + days2);
	return(ret);
}


function BindCalendar(/*string*/ inputField, /*string*/ buttonField, /*object*/ options){
    var defaultOp = {
        dateStatusFunc: null,
        onUpdate: null
    }
    
    for(var item in options){
        defaultOp[item] = options[item];
    }

    Zapatec.Calendar.setup({
	    inputField     :    inputField,   // id of the input field
	    button         :    buttonField,  // What will trigger the popup of the calendar
	    ifFormat       :    "%Y-%m-%d ",       //  of the input field
	    timeFormat     :    "24",
	    showsTime      :     false,          //no time
	    electric       :     false,
	    dateStatusFunc :    defaultOp.dateStatusFunc,
	    onUpdate       :    defaultOp.onUpdate
    });
}
