//------------------------------------------------------------
// Object orientated calendar
// usage: var cal = new origoCalendar(configObj);
// this will initialize the calendar and build the table that contains the calendar
// For configObj see the readme file
//------------------------------------------------------------

// origoCalendar constructor
function origoCalendar(calConfigObj) {

// origoCalendar variables
    var configObj;
    var liveProjectPath;
    var localProjectPath;
    var cssPath;
    var CSSPATH;
    var JSHOSTPATH;
    var JSPATH;
    var JSLANGPATH;
    var calInp;
    var calImg;
    var calObj;
    var calLocale;
    var startCalDate;
    var startCalDateString;
    var endCalDate;
    var endCalDateString;
    var calendarType;
    var calendarid;
    var numberInList;
    var searchedDates;
    var dates;

    // methods that can be used by calling this.method or cal.method where cal is a origoCalendar object
    this.startCalNew = startCalNew;
    this.initJsHostPath = initJsHostPath;
    this.initHeader = initHeader;
    this.getFileFromString = getFileFromString;
    this.setInputElements = setInputElements;
    this.initCal = initCal;
    this.showCalendar = showCalendar;
    this.dateSetter = dateSetter;
    this.formatDate = formatDate;
    this.hideAll = hideAll;
    this.clickBody = clickBody;
    this.pad = pad;
    this.hideCal = hideCal;
    this.createCalObj = createCalObj;
    this.isAllDaysRule = isAllDaysRule;
    this.isFirstDayRule = isFirstDayRule;
    this.changeValRule = changeValRule;
    this.setStartDay = setStartDay;
    this.hideAllButThis= hideAllButThis;
    this.setEndDay = setEndDay;

    this.configObj = calConfigObj;
    this.numberInList = origoCalendar.nrOfCals;
    origoCalendar.nrOfCals++;

    this.JSHOSTPATH = location.protocol + '//' + location.host;
    this.calLocale = (this.configObj.calLocale) ? this.configObj.calLocale : 'EN';

    // this.configObj.valRule:
    // 1 : no dates can be selected before the this.configObj.startDay or today
    // 2 : all dates can be selected
    // array : only these dates can be selected
    if (!this.isAllDaysRule()) {
        this.startCalDate = (this.configObj.startDay)? this.configObj.startDay : new Date();
        this.startCalDateString = pad(this.startCalDate.getMonth() + 1) + '/' + pad(this.startCalDate.getDate()) + '/' + pad(this.startCalDate.getFullYear());
    }

    //Used when we want to set last selectable day in the cal,    
    if(this.configObj.endDay){
        this.endCalDate = this.configObj.endDay;
        this.endCalDateString = pad(this.endCalDate.getMonth() + 1) + '/' + pad(this.endCalDate.getDate()) + '/' + pad(this.endCalDate.getFullYear());
    }

    // nr of calendars that are initialized on construction
    this.nrOfInitCals = (this.configObj.nrOfInitCal) ? this.configObj.nrOfInitCal : 2;

    if (this.configObj.calType == 2) this.calendarType = 'CalendarGroup';
    else this.calendarType = 'Calendar';

    // containerDivId must be defined
    if (typeof(this.configObj.containerDivId) == 'undefined') {
        alert("Please include a containerDivId in the configObj \n" +
              "Usage: new origoCalendar({containerDivId : 'to'});\n" +
              "Where: containerDivId is the div that contains the calendar (and perhaps input and/or a image)");
        return;
    }

    createCalendarDiv(this.configObj.containerDivId, this.numberInList);
    this.setInputElements(this.configObj.containerDivId);
    origoCalendar.allCalendars[this.numberInList] = this;

    // initialize the calnedar if few enough calendars have been initialized
    // else initialize the calendar when the input/img element is pressed
    if(this.numberInList < this.nrOfInitCals){
        this.createCalObj();
        this.initCal();
    }

    if(this.numberInList == 0){
        this.startCalNew();
    }

    //set datemask
    if (this.configObj.dateMask != 'off') {
        if (this.calInp.value == '') {
            if (this.configObj.calLocale == 'en_US')
                this.calInp.value = "mm/dd/yyyy";
            else if(location.hostname.indexOf('nordicvisitor.se') != -1)
            	this.calInp.value = "dd.mm.\u00E5\u00E5\u00E5\u00E5";
            else
                this.calInp.value = "dd.mm.yyyy";
        }
    }

    // add listeners to the input boxes
    YAHOO.util.Event.addListener(this.calInp.id, 'click', createMethodReference(this, "showCalendar"), this, true);
    if (this.calImg) {
        YAHOO.util.Event.addListener(this.calImg.id, 'click', createMethodReference(this, "showCalendar"), this, true);
    }

    origoCalendar.allCalendars[this.numberInList] = this;
}

// makes the div that surrounds the calendar
function createCalendarDiv(id, number){
    if(!document.getElementById('container' + number)){
        var newContainer = document.createElement('div');
        newContainer.setAttribute('class', 'calcontainer');
        newContainer.setAttribute('id', 'container' + number);
        newContainer.setAttribute('style', 'display: none;');
        document.getElementById(id).appendChild(newContainer);
    }
}

// creates the calendar object
function createCalObj(){

    var confObj;
    // pick the correct config object
    if(location.hostname == 'www.nordicvisitor.no'){
        confObj = new NOConfObj();
    }
    else if(location.hostname.indexOf('nordicvisitor.se') != -1)
    {
    	confObj = new SVConfObj();
    }
    else
    {
	confObj = new ENConfObj();
    }

    // this is done so yahoo wont get any hits when we push left/right
    confObj.properties.nav_arrow_left = '';
    confObj.properties.nav_arrow_right = '';

    // if valRule is a array of dates ["22/11/2006", "24/11/2006"]
    if (typeof(this.configObj.valRule) == 'object') {
        var splittedDates = this.configObj.valRule[0].split(",");
        var minDate = splittedDates[0].split("/");
        var maxDate = splittedDates[splittedDates.length - 1].split("/");
        var startDate = formatDateString(minDate[1], minDate[0], minDate[2]);
        var startMonth = minDate[0]-1;
        var startYear = minDate[2];

        if(this.startCalDateString && startDate - this.startCalDate < 0){
            startDate = this.startCalDateString;
            startMonth = this.startCalDate.getMonth();
            startYear = this.startCalDate.getFullYear();
        }

        confObj.properties.mindate = startDate;
        confObj.properties.maxdate = formatDateString(maxDate[1], maxDate[0], maxDate[2]);

        if(this.endCalDateString){
            confObj.properties.maxdate = this.endCalDateString;
        }

        if (this.calendarType == 'Calendar') {
            this.calObj = new YAHOO.widget.Calendar("origoCal" + this.numberInList, 'container' + this.numberInList, confObj.properties);
        }
        else {
            this.calObj = new YAHOO.widget.CalendarGroup("origoCal" + this.numberInList, 'container' + this.numberInList, confObj.properties);
        }

        this.calObj.setMonth(startMonth);
        this.calObj.setYear(startYear);
        this.calObj.render();

        origoCalendar.workingCalendarNr = this.numberInList;
        if(!origoCalendar.allCalendars[origoCalendar.workingCalendarNr]){
            origoCalendar.allCalendars[this.numberInList] = this;
        }
        // 3  render functions
        // cellActive renders a <a> tag that can be selected and adds "activeDate" and "selectable" class to the cell
        // renderCellInActive adds a "previous" class to the cell
        // renderCellSearched adds a "searched" class to the cell
        this.calObj.renderCellActive = function(activeDate, cell) {
            cell.innerHTML = '<a href="javascript:void(null);" >' + activeDate.getDate() + '</a>';
            YAHOO.util.Dom.addClass(cell, "activedate");
            YAHOO.util.Dom.addClass(cell, "selectable");

            var dateString = pad(activeDate.getMonth() + 1) + "/" + pad(activeDate.getDate()) + "/" + pad(activeDate.getFullYear());
            if (origoCalendar.allCalendars[origoCalendar.workingCalendarNr].configObj.searchedDates && origoCalendar.allCalendars[origoCalendar.workingCalendarNr].configObj.searchedDates[0].indexOf(dateString) != -1) {
                YAHOO.util.Dom.addClass(cell, "searched");
            }

            return YAHOO.widget.Calendar_Core.STOP_RENDER;
        };

        this.calObj.renderCellInActive = function(inactiveDate, cell) {
            cell.innerHTML = inactiveDate.getDate();
            YAHOO.util.Dom.addClass(cell, "previous");
            return YAHOO.widget.Calendar_Core.STOP_RENDER;
        };

        this.calObj.renderCellSearched = function(searchedDate, cell) {
            cell.innerHTML = searchedDate.getDate();
            YAHOO.util.Dom.addClass(cell, "searched");
            return YAHOO.widget.Calendar_Core.STOP_RENDER;
        };

        var inactiveDates = '';

        var tempDate = formatDateString(minDate[1], minDate[0], minDate[2]);
        var tempMaxDate = formatDateString(maxDate[1], maxDate[0], maxDate[2]);
        while (tempDate <= tempMaxDate) {
            var temp = pad(tempDate.getMonth() + 1) + '/' + pad(tempDate.getDate()) + '/' + pad(tempDate.getFullYear());
            if (this.configObj.valRule[0].indexOf(temp) == -1) {
                inactiveDates += temp + ',';
            }
            tempDate.setDate(tempDate.getDate() + 1);
        }

        inactiveDates = inactiveDates.substring(0, inactiveDates.length - 1);
        this.calObj.addRenderer(inactiveDates, this.calObj.renderCellInActive);
        if (this.configObj.searchedDates) {
            this.calObj.addRenderer(this.configObj.searchedDates[0], this.calObj.renderCellSearched);
        }
        this.calObj.addRenderer(this.configObj.valRule[0], this.calObj.renderCellActive);
    }
    else {
        if (!this.isAllDaysRule()) {
            confObj.properties.mindate = this.startCalDateString;
        }

        if(this.endCalDateString){
            confObj.properties.maxdate = this.endCalDateString;
        }


        if (this.calendarType == 'Calendar') {
            this.calObj = new YAHOO.widget.Calendar("origoCal" + this.numberInList, 'container' + this.numberInList, confObj.properties);
        }
        else {
            this.calObj = new YAHOO.widget.CalendarGroup("origoCal" + this.numberInList, 'container' + this.numberInList, confObj.properties);
        }
        if (!this.isAllDaysRule()) {
            this.calObj.setMonth(this.startCalDate.getMonth());
            this.calObj.setYear(this.startCalDate.getFullYear());            
        }
        this.calObj.render();
    }
    // if a date is selected then run dateSetter
    this.calObj.selectEvent.subscribe(dateSetter, this, true);

    return this
}

function setStartDay(startDay){
    this.configObj.startDay = startDay;
    this.startCalDate = (this.configObj.startDay)? this.configObj.startDay : new Date();
    this.startCalDateString = pad(this.startCalDate.getMonth() + 1) + '/' + pad(this.startCalDate.getDate()) + '/' + pad(this.startCalDate.getFullYear());
}

function setEndDay(endDay){
    this.configObj.endDay = endDay;
    if(this.configObj.endDay){
        this.endCalDate = (this.configObj.endDay)? this.configObj.endDay :null;
        this.endCalDateString = pad(this.endCalDate.getMonth() + 1) + '/' + pad(this.endCalDate.getDate()) + '/' + pad(this.endCalDate.getFullYear());
    }
}

function changeValRule(valRule){
    this.configObj.valRule = valRule;
    this.createCalObj();
    this.initCal();
}

function isAllDaysRule(){
    return this.configObj.valRule == 2;
}

function isFirstDayRule(){
    return this.configObj.valRule == 1;
}

// if this function is called, then it is the old version that is calling (one conf obj, and divs have class "calDiv")
function startCal(calConfObj){
    var calDivs = YAHOO.util.Dom.getElementsByClassName('caldiv', 'div', document);
    var calObjArr = new Array();

    for(var i in calDivs){
    	var mynum = new Number(i);
    	if(!isNaN(mynum))
    	{
		if(!calDivs[i].id){
		    calDivs[i].id = "containerDiv"+i;
		}

		calConfObj.containerDivId = calDivs[i].id;
		var cal = new origoCalendar(calConfObj);
		if(cal.nrInList == 0){
		    cal.startCalNew();
		}
		if(cal.numberInList < cal.nrOfInitCals){
		    cal.initCal();
		}

		calObjArr[cal.calInp.id] = cal;
        }
    }
    return calObjArr;
}

// initialize the calendar
function startCalNew() {
    this.localProjectPath = (this.configObj.localProjectPath)? this.configObj.localProjectPath: "origo-icelandair";
    this.liveProjectPath = (this.configObj.liveProjectPath)? this.configObj.liveProjectPath: "origo-portlets";
    this.cssPath = (this.configObj.cssPath)? this.configObj.cssPath: "/javascript/origo-calendar/css/";
    this.initJsHostPath(this.localProjectPath, this.liveProjectPath, this.cssPath);
    this.initHeader(this.configObj.calLocale, this.configObj.cssFiles);
}

function initJsHostPath(localProjectPath, liveProjectPath, cssPath) {
    if (cssPath.indexOf('pub_module') != -1) {
        this.CSSPATH = this.JSHOSTPATH + cssPath;
    }
    if (this.JSHOSTPATH.indexOf('localhost') > -1) {
        this.JSHOSTPATH = this.JSHOSTPATH + '/' + localProjectPath;
    } else {
        this.JSHOSTPATH = this.JSHOSTPATH + '/' + liveProjectPath;
    }
    if (cssPath.indexOf('/') != 0) {
        cssPath = '/' + cssPath;
    }
    if (cssPath.indexOf('pub_module') == -1) {
        this.CSSPATH = this.JSHOSTPATH + cssPath;
    }
    this.JSPATH = this.JSHOSTPATH + '/javascript/YAHOO/yui/build/';
    this.JSLANGPATH = this.JSHOSTPATH + '/javascript/origo-calendar/';
}


//------------------------------------------------------------
// Incluedes relevant files to the the header of the calendar
//------------------------------------------------------------
function initHeader(calLocale, cssFiles) {
    var initScript;

    var scripts = document.getElementsByTagName('script');
    var css = document.getElementsByTagName('link');
    var header = document.getElementsByTagName('head')[0];
    var existingJSfiles = new Array();
    var existingCSSfiles = new Array();

    //Get all css files from header and store in array
    for (var i = 0; i < css.length; i++) {
        var str = this.getFileFromString(css[i].href);
        existingCSSfiles[str] = str;
    }
    //Get all js files from header and store in array
    for (var i = 0; i < scripts.length; i++) {
        var str = this.getFileFromString(scripts[i].src);
        existingJSfiles[str] = str;
        if (str.search('origoCalendar') != -1)
            initScript = scripts[i];
    }

    //Attach required files in cssFilse to the header if they to not already exist
    if (cssFiles) {
        for (var i = 0; i < cssFiles.length; i++) {
            if (!existingCSSfiles[cssFiles[i]]) {
                var newCss = document.createElement('link');
                newCss.setAttribute('rel', 'stylesheet');
                newCss.setAttribute('type', 'text/css');
                newCss.setAttribute('media', 'screen');
                newCss.setAttribute('href', this.CSSPATH + cssFiles[i]);
                header.appendChild(newCss);
            }
        }
    }
}

//returns the file in a url
function getFileFromString(path) {
    var lindex = path.lastIndexOf('/');
    var len = path.length;
    return path.substring(lindex + 1, len);
}

//------------------------------------------------------------
// Puts input element and perhaps an image element in the calendar
// so that they can listen to onclick events that call
// showCalendar function.
//------------------------------------------------------------
function setInputElements(calDivId) {

    var caldiv = document.getElementById(calDivId);

    var dateInput = caldiv.getElementsByTagName('input')[0];
    if (dateInput.id) {
        var inpId = dateInput.id;
    }
    else {
        dateInput.id = 'ycal_' + this.numberInList;
    }

    this.calInp = dateInput;


    //Check if there is a calendar image
    var localCalImg = caldiv.getElementsByTagName('img')[0];
    if (localCalImg) {
        localCalImg.id = dateInput.id + '_img';
        this.calImg = localCalImg;
    }
}

//  render the calendar
function initCal() {
    this.calObj.render();

    origoCalendar.allCalendars[this.numberInList] = this;
    this.hideAll();
}

// function that is called to put a function in a argument without calling it
// f.ex YAHOO.util.Event.addListener(id, 'click', createMethodReference(this, "showCalendar"), this, true);
function createMethodReference(object, methodName) {
    return function () {
        object[methodName].apply(object, arguments);
    };
}

//------------------------------------------------------------
// Display calendar
//------------------------------------------------------------
function showCalendar(e) {
    if(typeof(this.calObj) == 'undefined'){
        this.createCalObj();
        this.initCal();
        origoCalendar.allCalendars[this.numberInList] = this;
    }

    this.hideAllButThis();
    var target = this.calInp;
    //set calendar position to configured element
    var posEl = this.configObj.positionElement;
    var currentDateInp = (posEl)? document.getElementById(posEl) : target;

    this.calObj.oDomContainer.style.display = 'block';    
    // input dimensions and postion
    var pos = YAHOO.util.Dom.getXY(currentDateInp);
    YAHOO.util.Dom.setXY(this.calObj.oDomContainer, [pos[0], pos[1] + currentDateInp.offsetHeight + 1]);
    var inpH = currentDateInp.offsetHeight;
    var inpW = currentDateInp.offsetWidth;
    // page dimensions
    var pWidth = YAHOO.util.Dom.getViewportWidth();
    if (navigator.userAgent.indexOf('MSIE') != -1)
        var pHeight = YAHOO.util.Dom.getViewportHeight() + document.documentElement.scrollTop;
    else
        var pHeight = YAHOO.util.Dom.getViewportHeight() + window.pageYOffset;
    // calendar dimensions
    var calRegion = YAHOO.util.Dom.getRegion(this.calObj.oDomContainer);
    var calBottom = pos[1] + currentDateInp.offsetHeight + this.calObj.oDomContainer.offsetHeight;
    var calRegionW = calRegion.right - calRegion.left;
    var calRegionH = calRegion.bottom - calRegion.top;

    // set calendar position
    var setX = (pWidth <= calRegion.right)? pos[0] - (calRegionW - inpW) - 5: pos[0];
    var setY = (pHeight <= calRegion.bottom)? pos[1] - calRegionH - 5: pos[1] + inpH + 1;

    var offsetPosX = (this.configObj.calOffsetPosX)?this.configObj.calOffsetPosX:0;
    YAHOO.util.Dom.setY(this.calObj.oDomContainer, setY);
    YAHOO.util.Dom.setX(this.calObj.oDomContainer, setX + offsetPosX);

    this.clickBody(this.calObj);
    origoCalendar.allCalendars[this.numberInList] = this;
}

function getCalDiv(target){
    var parent = pElement(target.id).parentNode;
    var divs = parent.getElementByTagName("div");

    for(var i in divs){
        if(divs[i].id.indexOf("container")){
            return divs[i].id;
        }
    }
    return "";
}

//------------------------------------------------------------
// Select Date
//------------------------------------------------------------
function dateSetter(type, args, obj) {

    var newDate = args[0][0];
    var selectedDate = newDate[1]+'/'+newDate[2]+'/'+newDate[0];
    var selectedDateObj = new Date(newDate[1]+'/'+newDate[2]+'/'+newDate[0])
    var caldiv = this.calObj.oDomContainer.parentNode;
    var inp = caldiv.getElementsByTagName('input')[0];
    inp.value = this.formatDate(formatDateString(newDate[2], newDate[1], newDate[0]));
    
    if (this.configObj.setDateFunction) {
        this.configObj.setDateFunction.call();
    }
    
    if (this.isFirstDayRule() && this.numberInList == 0) {
        var index = this.numberInList ;
        if(origoCalendar.allCalendars[(index+1)]){
            var nextcal = origoCalendar.allCalendars[(index+1)].calObj;            
            nextcal.cfg.setProperty('mindate', selectedDate);

            nextcal.setMonth(newDate[1]-1);
            nextcal.setYear(newDate[0]);
            nextcal.render();

            var firstTable = nextcal.oDomContainer.getElementsByTagName('table')[0];
            var selectedClass = 'd'+newDate[2];
            var selCell = YAHOO.util.Dom.getElementsByClassName(selectedClass,'td',firstTable)[0];
            nextcal.pages[0].renderCellStyleSelected(selectedDateObj, selCell);
        }
    }
}


//------------------------------------------------------------
// Format date string
//------------------------------------------------------------
function formatDate(date) {

    var month = date.getMonth() + 1;
    if (this.calLocale == 'en_US') {
        return pad(month) + '/' + pad(date.getDate()) + '/' + pad(date.getFullYear());
    }
    else {
        return pad(date.getDate()) + '.' + pad(month) + '.' + pad(date.getFullYear());
    }
}

function formatDateString(date, month, year) {
    var dateObj = new Date();
    dateObj.setFullYear(year, month - 1, date);
    return dateObj;
}
//------------------------------------------------------------
// Functions for hiding calendar
//------------------------------------------------------------
function hideAll() {
    for (var i in origoCalendar.allCalendars) {
        if (origoCalendar.allCalendars[i].calObj) {
            origoCalendar.allCalendars[i].calObj.hide();
        }
    }
    var body = document.getElementsByTagName('body')[0];
    YAHOO.util.Event.removeListener(body, 'click', createMethodReference(this, "hideAll"), false);
}

function hideAllButThis() {
    for (var i in origoCalendar.allCalendars) {
        if (origoCalendar.allCalendars[i].calObj) {
            if(this && this.numberInList != i){
                origoCalendar.allCalendars[i].calObj.hide();
            }
        }
    }
    var body = document.getElementsByTagName('body')[0];
    YAHOO.util.Event.removeListener(body, 'click', createMethodReference(this, "hideAll"), false);
}

function clickBody(cal) {
    var body = document.getElementsByTagName('body')[0];
    YAHOO.util.Event.addListener(body, 'click', createMethodReference(this, "hideCal"));
}

function hideCal(e) {
    if (!(getTarget(e).nodeName == 'INPUT' || getTarget(e).nodeName == 'IMG' || getTarget(e).className == 'calheader')) {
        var body = document.getElementsByTagName('body')[0];
        this.calObj.hide();
        YAHOO.util.Event.removeListener(body, 'click', createMethodReference(this, "hideCal"));
    }
}

//------------------------------------------------------------
// Misc. helper functions
//------------------------------------------------------------
function getTarget(e) {

    if (window.event) {
        return window.event.srcElement;
    }
    else {
        return e.target;
    }
}
function pad(num) {

    if (num < 10)
        return 0 + '' + num;
    else
        return num;
}

var cal1;

// public variables
origoCalendar.nrOfCals = 0;
origoCalendar.workingCalendarNr = 0;
origoCalendar.allCalendars = new Object();
origoCalendar.timerAdded = false;


// constructors for the conf objects 
/*
function DAConfObj(){
     this.properties = {'MONTHS_SHORT' : ["Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"],'MONTHS_LONG' : ["Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December"],'WEEKDAYS_1CHAR' : ["S", "M", "T", "O", "T", "F", "L"],'WEEKDAYS_SHORT' : ["Sø", "Ma", "Ti", "On", "To", "Fr", "Lø"],'WEEKDAYS_MEDIUM' : ["Søn", "Man", "Tir", "Ons", "Tor", "Fre", "Lør"],'WEEKDAYS_LONG' : ["Søndag", "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag"],'START_WEEKDAY' : 1};
}

function DEConfObj() {
    this.properties = {'MONTHS_SHORT' : ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],'MONTHS_LONG' : ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],'WEEKDAYS_1CHAR' : ["S", "M", "D", "M", "D", "F", "S"],'WEEKDAYS_SHORT' : ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],'WEEKDAYS_MEDIUM' : ["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"],'WEEKDAYS_LONG' : ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"],'START_WEEKDAY' : 1};
}

function en_USConfObj(){
    this.properties = {"MONTHS_SHORT": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],"MONTHS_LONG": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],"WEEKDAYS_1CHAR": ["S", "M", "T", "W", "T", "F", "S"],"WEEKDAYS_SHORT": ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],"WEEKDAYS_MEDIUM": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],"WEEKDAYS_LONG": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],'START_WEEKDAY' : 1};
}

function FRConfObj(){
    this.properties = {"MONTHS_SHORT":  ["Jan", "Fev", "Mar", "Avr", "Mai", "Jui", "Jui", "Aou", "Sep", "Oct", "Nov", "Dec"],"MONTHS_LONG": ["Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre"],"WEEKDAYS_1CHAR": ["D", "L", "M", "M", "J", "V", "S"],"WEEKDAYS_SHORT": ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],"WEEKDAYS_MEDIUM": ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"],"WEEKDAYS_LONG": ["Dimanche", "Lundi ", "Mardi ", "Mercredi ", "Jeudi ", "Vendredi ", "Samedi"],'START_WEEKDAY' : 1};
}

function GBConfObj(){
    this.properties = {"MONTHS_SHORT": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],"MONTHS_LONG": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],"WEEKDAYS_1CHAR": ["S", "M", "T", "W", "T", "F", "S"],"WEEKDAYS_SHORT": ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],"WEEKDAYS_MEDIUM": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],"WEEKDAYS_LONG": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],'START_WEEKDAY' : 1};
}

function ISConfObj() {
    this.properties = {"MONTHS_SHORT": ["Jan", "Feb", "Mar", "Apr", "Maí", "Jún", "Júl", "Ágú", "Sep", "Okt", "Nóv", "Des"],"MONTHS_LONG": ["Janúar", "Febrúar", "Mars", "Apríl", "Maí", "Júní", "Júlí", "Ágúst", "September", "Október", "Nóvember", "Desember"],"WEEKDAYS_1CHAR": ["S", "M", "Þ", "M", "F", "F", "L"],"WEEKDAYS_SHORT": ["Su", "Má", "Þr", "Mi", "Fi", "Fö", "La"],"WEEKDAYS_MEDIUM": ["Sun", "Mán", "Þri", "Mið", "Fim", "Fös", "Lau"],"WEEKDAYS_LONG": ["Sunnudagur", "Mánudagur", "Þriðjudagur", "Miðvikudagur", "Fimmtudagur", "Föstudagur", "Laugardagur"],'START_WEEKDAY' : 1};
}

function NLConfObj() {
    this.properties = {"MONTHS_SHORT": ["Jan", "Feb", "Mrt", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],"MONTHS_LONG": ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "Novemberr", "December"],"WEEKDAYS_1CHAR": ["Z", "M", "D", "W", "D", "V", "Z"],"WEEKDAYS_SHORT": ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za"],"WEEKDAYS_MEDIUM": ["Zon", "Maa", "Din", "Woe", "Don", "Vri", "Zat"],"WEEKDAYS_LONG": ["Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag"],'START_WEEKDAY' : 1};
}
*/

function SVConfObj() {
    this.properties = {"MONTHS_SHORT": ["Jan", "Feb", "Mar", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"],"MONTHS_LONG": ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"],"WEEKDAYS_SHORT": ["S&ouml", "M&aring", "Ti", "On", "To", "Fr", "L&ouml"],"WEEKDAYS_MEDIUM": ["S&oumln", "M&aringn", "Tis", "Ons", "Tor", "Fre", "L&oumlr"],"WEEKDAYS_LONG": ["S&oumlndag", "M&aringndag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "L&oumlrdag"],'START_WEEKDAY' : 1};
}


function NOConfObj() {
    this.properties = {"MONTHS_SHORT": ["Jan", "Feb", "Mar", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Des"],"MONTHS_LONG": ["Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Desember"],"WEEKDAYS_1CHAR": ["S", "M", "T", "O", "T", "F", "L"],"WEEKDAYS_SHORT": ["S&oslash;", "Ma", "Ti", "On", "To", "Fr", "L&oslash;"],"WEEKDAYS_MEDIUM": ["S&oslash;n", "Man", "Tir", "Ons", "Tor", "Fre", "L&oslash;r"],"WEEKDAYS_LONG": ["S&oslash;ndag", "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "L&oslash;rdag"],'START_WEEKDAY' : 1};
}

function ENConfObj() {
    this.properties = {"MONTHS_SHORT": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],"MONTHS_LONG": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],"WEEKDAYS_1CHAR": ["S", "M", "T", "W", "T", "F", "S"],"WEEKDAYS_SHORT": ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],"WEEKDAYS_MEDIUM": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],"WEEKDAYS_LONG": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],'START_WEEKDAY' : 1};
}

function initCalendar(){	
	var calConfigObj = { calType : 2, calOffsetPosX : -130};
	startCal(calConfigObj);	
}            

function initCalendar2(){	
	var calConfigObj = { calType : 2, calOffsetPosX : 0};
	startCal(calConfigObj);	
}            

function initCalendar3(){	
	var calConfigObj = { calType : 2, calOffsetPosX : -150, valRule : 2};
	startCal(calConfigObj);	
}  

function initCalendar4(){	
	var thisDate = new Date();
	thisDate.setDate(thisDate.getDate() + 2);
	var calConfigObj = { calType : 2, calOffsetPosX : 0, startDay : thisDate};
	startCal(calConfigObj);	
}                