
/**
* nova koda za iskalnik_levo
* 
* 17.4.2008
*/
 function workOutDeptDate(){
        var dtMonthYr, dtDay, dtCheckout, dtNoOfNights,  dtYr, dtDisplayDate, dtDisplayDay, dtDisplayMonth, dtDisplayYear, dtReturnMonthYr
        var dtDisplayCheckout, dtMonth
        
         //Get Departure Date
        dtNoOfNights = document.iskalnik_levo.Nights.value
        dtMonthYr = document.iskalnik_levo.DeptMonthYr.value
        dtDay = document.iskalnik_levo.DeptDay.value
        dtDisplayMonth = dtMonthYr.substring(0,2)
        dtYr = dtMonthYr.substring(2,7)
        
        //Remove 1 from Month as Months are zero based in Javascript
        dtDisplayMonth = dtDisplayMonth - 1
        
        //Add No of Nights
         dtDay = parseInt(dtDay) + parseInt(dtNoOfNights)
        
        //create DISPLAY date
        dtCheckout = new Date(dtYr, dtDisplayMonth, dtDay)
        
        //Break Date Down
        dtDisplayDay = dtCheckout.getDate().toString()
        dtDisplayMonth = dtCheckout.getMonth().toString()
        dtDisplayYear = dtCheckout.getFullYear().toString()
        
        //Add a zero to day 
        if (dtDisplayDay.valueOf() < 10){
            dtDisplayDay = "0" +  dtDisplayDay
        }
        
        var monthName
        monthName = new Array();
        monthName[0] = prevod_mesec[1];
        monthName[1] = prevod_mesec[2];
        monthName[2] = prevod_mesec[3];
        monthName[3] = prevod_mesec[4];
        monthName[4] = prevod_mesec[5];
        monthName[5] = prevod_mesec[6];
        monthName[6] = prevod_mesec[7];
        monthName[7] = prevod_mesec[8];
        monthName[8] = prevod_mesec[9];
        monthName[9] = prevod_mesec[10];
        monthName[10] = prevod_mesec[11];
        monthName[11] = prevod_mesec[12];
        
        //write out dates to Display Fields
        document.getElementById("DisplayDate").innerHTML = dtDisplayDay + " " + monthName[dtDisplayMonth] + " " + dtDisplayYear
        
        //add +1 back for the ASP date
        dtDisplayMonth = parseInt(dtDisplayMonth)
        dtDisplayMonth =  dtDisplayMonth + 1
        
        //Add a zero to month
        
        if (dtDisplayMonth.valueOf() < 10){
            dtDisplayMonth = "0" +  dtDisplayMonth
        }
        
        dtReturnMonthYr = dtDisplayMonth + dtDisplayYear
        
        //write out dates to Hidden Fields
        document.iskalnik_levo.ReturnMonthYr.value = dtReturnMonthYr 
        document.iskalnik_levo.ReturnDay.value = dtDisplayDay
    }
    
    
//YAHOO.namespace("example.calendar"); 
//YAHOO.util.Event.addListener(window, "load", init);
     
        function init() { 
            workOutDeptDate();

            YAHOO.example.calendar.cal1 = new YAHOO.widget.CalendarGroup("cal1","cal1Container",  
                { 
                title: prevod_koledar['check_in_date'], 
                close: true,
                mindate: nastavi_min_date(), 
                maxdate: nastavi_max_date(),
				weekdays_short: [prevod['ned'], prevod['pon'], prevod['tor'], prevod['sre'], prevod['cet'], prevod['pet'], prevod['sob']],
				months_long: [prevod_mesec[1], prevod_mesec[2], prevod_mesec[3], prevod_mesec[4], prevod_mesec[5], prevod_mesec[6], prevod_mesec[7], prevod_mesec[8], prevod_mesec[9], prevod_mesec[10], prevod_mesec[11], prevod_mesec[12]],
                START_WEEKDAY: 1
                } 
            ); 
                                                  
            YAHOO.example.calendar.cal1.selectEvent.subscribe(selectHandler, YAHOO.example.calendar.cal1, true); 
            YAHOO.example.calendar.cal1.render(); 
            
            var oElement = document.getElementById("calImage");
            YAHOO.util.Event.addListener(oElement, "click", YAHOO.example.calendar.cal1.show, YAHOO.example.calendar.cal1, true); 
            
            var daySelect = document.getElementById("DeptDay");
            YAHOO.util.Event.addListener(daySelect, "change", updateCal); 
            
            var monthSelect = document.getElementById("DeptMonthYr");
            YAHOO.util.Event.addListener(monthSelect, "change", updateCal); 
            
            YAHOO.example.calendar.cal1.cfg.setProperty("MDY_DAY_POSITION", 1); 
            YAHOO.example.calendar.cal1.cfg.setProperty("MDY_MONTH_POSITION", 2); 
            YAHOO.example.calendar.cal1.cfg.setProperty("MDY_YEAR_POSITION", 3); 	  
        } 
            
        function updateCal() { 
            var DeptDay = document.getElementById("DeptDay"); 
            var DeptMonthYr = document.getElementById("DeptMonthYr");   
            
            var newDate = DeptDay.value + "/" + DeptMonthYr.value.substring(0,2) + "/" + DeptMonthYr.value.substring(2,6) ;
         
            // Select the date typed in the field 
            YAHOO.example.calendar.cal1.select(newDate);  
             
            var firstDate = YAHOO.example.calendar.cal1.getSelectedDates()[0]; 
             
            // Set the Calendar's page to the earliest selected date 
            YAHOO.example.calendar.cal1.cfg.setProperty("pagedate", (firstDate.getMonth()+1) + "/" + firstDate.getFullYear());  
             
            YAHOO.example.calendar.cal1.render(); 
        } 	      
        var selectHandler = function(type,args,obj) { 
        var selectedDates = args[0]; 
        var date = selectedDates[0]; 
        
        var year = date[0], month = date[1], day = date[2]; 
        
        var DeptDay = document.getElementById("DeptDay");
        DeptDay.value = day;//day + "/" + month + "/" + year;
        var DeptMonthYr = document.getElementById("DeptMonthYr");
        if(month<10)month="0"+month;
        DeptMonthYr.value = month + "" + year;	    
        
        var oElement = document.getElementById("cal1Container");
        oElement.style.display="none"; 
        
        workOutDeptDate();	    	  
    };
    
	function nastavi_min_date(){
		var datum = new Date();
		
		var datum_oblika = (parseInt(datum.getMonth())+1)+"/"+parseInt(datum.getDate())+"/"+parseInt(datum.getFullYear());
		
		return(datum_oblika);
	}
	
	function nastavi_max_date(){
		var datum = new Date();
		
		var datum_oblika = '12/31/'+(parseInt(datum.getFullYear())+1);
		return(datum_oblika);
	}