﻿// JScript File
var startCal;
var startCal4Location;
var cmbDay;
var cmbDay4Location;
var cmbMonthYear;
var cmbMonthYear4Location;

function CalendarLoad(position,objDay,objMonth,startDate,endDate,todayDate,dayName,shortMonthName,fullMonthName, isLanguageRightToLeft) {
    if (objDay == "cmbDay") {
        cmbDay = document.getElementById(objDay);
        cmbMonthYear = document.getElementById(objMonth);
    } else {
        cmbDay4Location = document.getElementById(objDay);
        cmbMonthYear4Location = document.getElementById(objMonth);    
    }
    
    if (typeof Calendar == "function") {
	    var start = startDate;
	    var end = endDate;
    	
	    var config = new Calendar.Config();
	    config.startDate = new Date(start);
	    config.endDate = new Date(end);
	    config.className = 'calendar';
	    config.width = 240;
	    config.displayPosition = position;
	    config.selectDate = new Date(todayDate);

	    config.Caption = dayName;
	    config.ShortMonthNames = shortMonthName;
	    config.MonthNames = fullMonthName;
	    config.autoHide = false;
	    config.callBack = function (iDay,iMonth,iYear,obj) {
	                            selectDate(iDay,iMonth,iYear,obj);
						    };
    	config.isLanguageRightToLeft = isLanguageRightToLeft;
    	if (objDay == "cmbDay") {
	        startCal = new Calendar('startCal',config);
	    } else {
	        startCal4Location = new Calendar('startCal4Location',config);
	    }
    }
}

function selectDate(iDay,iMonth,iYear,obj) {
    var strSelectedDate;
    var objDay;
    var objMonthYear;
    
    if (obj.id == "startCal") {
        objDay = cmbDay;
        objMonthYear = cmbMonthYear;    
    } else {
        objDay = cmbDay4Location;
        objMonthYear = cmbMonthYear4Location;        
    }
    
    if (objDay) {
        for (var i = 0; i < objDay.options.length; i++) {            
            objDay.options[i].selected = (iDay == objDay.options[i].value);
        }
    }
        
    if (objMonthYear) {
        iMonth++;
        
        strSelectedDate = '00' + iMonth;
        strSelectedDate = strSelectedDate.substring(strSelectedDate.length - 2,strSelectedDate.length);
        strSelectedDate +=  '/' + iYear;
        
        for (var i = 0;i < objMonthYear.options.length;i++) {
            //alert(strSelectedDate);
            if (objMonthYear.options[i].value == strSelectedDate)
                objMonthYear.options[i].selected = true;
            else
                objMonthYear.options[i].selected = false;
        }
    }
    
    if ($) $(objDay).trigger("change");
}
