var easterCount = 0;

function easter()
{
    var easter = document.getElementById('easter');
    easterCount++;
    if(easterCount == 10)
    {
        easter.innerHTML = '<div id="ident"><img src="img/easter.gif"></div>';
    }
    if(easterCount == 15)
    {
        easter.innerHTML = '<div id="ident"><img src="img/easter2.gif"></div>';
    }
    if(easterCount == 20)
    {
        easter.innerHTML = '<div id="ident"><img src="img/easter3.gif"></div>';
    }
}
	

// Easter


// LIGHTBOX

function modalwindow(url) {
 Lightview.show({
    href: url,
    rel: 'ajax',
    options: {
      autosize: true,
			closeButton: false,
      ajax: {
        method: 'get',
        evalScripts: true,
        onComplete: function(){ $('name').focus(); }
      }
    }
  });
}

//// LIGHTBOX LOADING

//function lightbox_loading(url){	
//  Lightview.show({
//    href: url,
//    rel: 'ajax',
//    options: {
//      autosize: true,
//	  menubar: false,
//	  keyboard: false,
//	  overlayClose: false,
//	  closeButton: false,
//    }
//  });
//}



// SWITCH VIEW

function switchView(parent, id) {
	$(parent).childElements().each(Element.hide);	
	$(id).show();	
}

// PHOTO SWITCH

function switchPhoto(id, text){
	
	// lazy switch	
	
	if(id == "6"){
		idnext = "1";
		}
	
	if(id == "5"){
		idnext = "6";
		}
	
	if(id == "4"){
		idnext = "5";
		}
	
	if(id == "3"){
		idnext = "4";
		}
	
	if(id == "2"){
		idnext = "3";
		}
	
	if(id == "1"){
		idnext = "2";
		}
		
	
		
	// end lazy switch	
		
	var newfunc = "switchPhoto('"+idnext+"','Klikk for &aring; se neste bilde')";
	
	$('body').replace('<div onClick="'+newfunc+'" id="body"<p><img src="/ux-content/hotels/kautokeino-photos-0'+id+'.jpg"></p><h5>'+text+'</h5>')	
	
	
	
	}

// DATE

function dayNameFind(tdf,dateField){
	dayDate(tdf);
	removeDayClass(dateField);
	$(dateField).toggleClassName(dayName);
}

function removeDayClass(dateField){
	// Removes any day classes the field might have
	// Could be a for loop with the array created **
	$(dateField).removeClassName('sun');
	$(dateField).removeClassName('mon');
	$(dateField).removeClassName('tue');
	$(dateField).removeClassName('wed');
	$(dateField).removeClassName('thu');
	$(dateField).removeClassName('fri');
	$(dateField).removeClassName('sat');
}


function usaDate(date){
	var ddmmyy = date;
	var dd = ddmmyy.substring(0,2);
	var mm = ddmmyy.substring(3,5);
	var yy = ddmmyy.substring(6,11);
	newDate = mm + '/' + dd + '/' + yy;
	return newDate;
	}



function dayDate(date){
	usaDate(date);
	date = newDate;
	var mydate=new Date(date);
	var year=mydate.getYear();
	
	if (year < 1000){
		year+=1900;
	}
	
	var day=mydate.getDay();
	var month=mydate.getMonth();
	var daym=mydate.getDate();
	
	if (daym<10){
		daym="0"+daym;
	}
	//Navn som korrosponderer med css
	var dayarray=new Array("sun","mon","tue","wed","thu","fri","sat");
	
	//Genererer også navn på måned, om det kan være nyttig senere
    //	var montharray=new Array("Januar","Februar","Mars","April","Mai","Juni","Juli","August","September","Oktober","November","Desember");
	
		dayName = dayarray[day];
	return dayName;
}

function nightsToDate(){
	
	// Get the date in from field
	var fromDateValue = $("date_from").value;
	
	//turn it into javascript friendly
	usaDate(fromDateValue);
	fromDateValue = newDate;
	
	//calculate
	var startDateInput = new Date(fromDateValue);
	var days = $("nights").value;;
	var nightsToDateSum = 0; 
	nightsToDateSum = new Date(startDateInput.getTime() + days*24*60*60*1000);
	
	// Debug - $("console").value = $("console").value+startDateInput+"+"+days+"= "+nightsToDateSum;
	var day=nightsToDateSum.getDate();
	var month=nightsToDateSum.getMonth();
	var year=nightsToDateSum.getYear();
	
	month = month +1;
	day = makeTwoChars(day);
	month = makeTwoChars(month);
	if (year < 1000){
	year+=1900;
	}
	
	//write date
	$("date_to").value = day+"."+month+"."+year;
	
	//Update day name plate
	dayNameFind($("date_to").value,"date_to");

	}



function makeTwoChars(inp) {
        return String(inp).length < 2 ? "0" + inp : inp;
}



var initAttempts = 0;

function setReservationDates(e) {
	
        // Internet Explorer will not have created the datePickers yet so we poll the datePickerController Object using a setTimeout
        // until they become available (a maximum of ten times in case something has gone horribly wrong)

        try {
                var sd = datePickerController.getDatePicker("date_from");
                var ed = datePickerController.getDatePicker("date_to");
        } catch (err) {
                if(initAttempts++ < 10) setTimeout("setReservationDates()", 50);
                return;
        }

        // Check the value of the input is a date of the correct format
        var dt = datePickerController.dateFormat(this.value, sd.format.charAt(0) == "m");

        // If the input's value cannot be parsed as a valid date then return
        if(dt == 0) return;

        // At this stage we have a valid YYYYMMDD date
		// Run the day label marker
		dayNameFind(this.value,this.id);
		

        // Grab the value set within the endDate input and parse it using the dateFormat method
        // N.B: The second parameter to the dateFormat function, if TRUE, tells the function to favour the m-d-y date format
        var edv = datePickerController.dateFormat(document.getElementById("date_to").value, ed.format.charAt(0) == "d");

        // Set the low range of the second datePicker to be the date parsed from the first
        ed.setRangeLow( dt );
        
        // If theres a value already present within the end date input and it's smaller than the start date
        // then clear the end date value
        if(edv < dt) {
                document.getElementById("date_to").value = "";
				removeDayClass("date_to");
        }
		
		
	
}

function removeInputEvents() {
        // Remove the onchange event handler set within the function initialiseInputs
        datePickerController.removeEvent(document.getElementById("date_from"), "change", setReservationDates);
}


//__

function initialiseInputs() {
        // Clear any old values from the inputs (that might be cached by the browser after a page reload)
        //document.getElementById("date_from").value = "02.12.2008";
        //document.getElementById("date_to").value = "03.12.2008";

        // Add the onchange event handler to the start date input
        datePickerController.addEvent(document.getElementById("date_from"), "change", setReservationDates);
		datePickerController.addEvent(document.getElementById("date_to"), "change", setReservationDates);
}

datePickerController.addEvent(window, 'load', initialiseInputs);
datePickerController.addEvent(window, 'unload', removeInputEvents);


//______ Room funcktions __________________________________________________________

function childrenHide(){
	$('room_beds-0').hide();
	$('room_beds-1').hide();
	$('room_beds-2').hide();
	$('room_beds-3').hide();
	}
	
function roomsHide(){
	$('room_people-0').hide();
	$('room_people-1').hide();
	$('room_people-2').hide();
	$('room_people-3').hide();
	}
	
	

// Todo: mekke loop **	
	
function roomsShow(){
	roomsHide();

if($F('rooms') == "1") {
	$('room_people-0').show();	
	}
	
if($F('rooms') == "2") {
	$('room_people-0').show();	
	$('room_people-1').show();		
	}	
	
if($F('rooms') == "3") {
	$('room_people-0').show();	
	$('room_people-1').show();	
	$('room_people-2').show();	
	}	

if($F('rooms') == "4") {
	$('room_people-0').show();	
	$('room_people-1').show();		
	$('room_people-2').show();		
    $('room_people-3').show();		
}	
}
	
	
function childrenShow(){
	childrenHide();

if($F('children-0') != "0") {
	$('room_beds-0').show();	
	}
	
if($F('children-1') != "0") {
	$('room_beds-1').show();	
	}
	
if($F('children-2') != "0") {
	$('room_beds-2').show();	
	}
	
if($F('children-3') != "0") {
	$('room_beds-3').show();	
	}
}

	