var last = null;
var lastd = 0;
var g_maxAllotment;
var lastcolor = '#FFEA97';
function omoChange(ob, color) {
	if (last != ob) {
		light(ob, color);
	}
}

function actoggle(ob, d, m, y, cid, duration, min, max, tid, accoPrice, resCost, isAllotment, maxAllotment, onePersonExtra, morePersonDiscount, morePersonTrigger, color) {
	g_maxAllotment = parseInt(maxAllotment);
	var msg = document.getElementById("seldate");
	var msg2= document.getElementById("selnights");
	if(last != null) {
		light(last, lastcolor);
	}	
	if(d == lastd) {
		//alert('a'+maxAllotment);
	
		document.search.day.value = "0";
		document.search.month.value = "0";
		document.search.year.value = "0";
		document.search.cid.value = "0";
		document.search.tid.value = "0";
		document.search.nights.value = "0";
		document.search.accoPrice.value = "0";
		msg.innerHTML = '<i>klik op een datum</i>';
		msg2.innerHTML = '<i>klik op een datum</i>';
		lastd = 0;
		var s = document.search.adults;
		s.disabled = true;
		document.search.rooms.disabled = true;
		selectItem(document.search.rooms, 1);
		setPriceList(resCost, 0, 0);
		last = null;
	}else{
	//alert('b'+maxAllotment);

		if (color) {
			light(ob, '#'+color);
		} else {
			light(ob, '#ffcc00');
		}
		document.search.day.value = d;
		document.search.month.value = m;
		document.search.year.value = y;
		document.search.cid.value = cid;
		document.search.nights.value = duration;
		document.search.tid.value = tid;
		document.search.accoPrice.value = accoPrice;
		document.search.onePersonExtraTemp.value = onePersonExtra;
		document.search.morePersonDiscountTemp.value = morePersonDiscount;
		buildPersonOptions(min, max);
		buildRoomOptions(isAllotment, parseInt(maxAllotment));
		setPriceList(resCost, document.search.adults.value, accoPrice, document.search.rooms, onePersonExtra, morePersonDiscount, morePersonTrigger);
//' ' + document.dateselect.month[document.dateselect.month.selectedIndex].text +
		var yValue = document.dateselect.year.value;
		var mValue = document.dateselect.month.value;

		msg.innerHTML =  d + '-' + mValue + '-' + yValue;
		msg2.innerHTML = duration;

		lastd = d;
	last = ob;
	}

}

function buildPersonOptions(mi, ma) {
	var s = document.search.adults;
	s.disabled = false;
	if (s.options) {
		s.options.length = ma - mi;
		var j = 0;
		for(var i = mi; i <= ma; i++) {
			s.options[j] = new Option(i,i);
			if(i == 2) {
				s.selectedIndex = j;
			}
			j++;
		}
	}
}

function buildRoomOptions(isAllotment, maxAllotment) {
	var s = document.search.rooms;
	s.disabled = false;
	var max = maxAllotment;
	if(maxAllotment > 5 || isAllotment == 0) max = 5;

	if (s.options) {
		s.options.length = max;
		for(var i = 1; i <= max; i++) {
			s.options[i - 1] = new Option(i,i);
		}
	}
}

function submitSearchForm() {
	if(document.search.day.value != "0" && document.search.day.value != "") {
		document.search.submit();
	}else{
		alert('Selecteer een aankomst datum');
	}
}

function groupbooking(id) {
	window.location = '/groepsboeking/'+id+'/'+document.search.year.value+'_'+document.search.month.value+'_'+document.search.day.value;
}

function changeForm() {
	var d = document.getElementById('yearoptions');
	var yearmonth = d.value;
	var year = yearmonth.substring(0, 4);
	var month = yearmonth.substring(yearmonth.indexOf('-') + 1);
	document.dateselect.month.value = month;
	document.dateselect.year.value =  year;
	document.dateselect.submit();
}
var bullseyeSet = false;
var g_el, g_curday, g_month, g_year, g_cid, g_lastduration, g_lastmin, g_lastmax, g_lasttid, g_accoPrice, g_rescosts, g_isAllotment, g_maxAllotment, g_onePersonExtra, g_morePersonDiscount;

function setBullseye(el, curday, month, year, cid, lastduration, lastmin, lastmax, lasttid, accoPrice, rescosts, isAllotment, maxAllotment, onePersonExtra, morePersonDiscount) {
	bullseyeSet = true;
	g_el = el;
	g_curday = curday;
	g_month = month;
	g_year = year;
	g_cid = cid;
	g_lastduration = lastduration;
	g_lastmin = lastmin;
	g_lastmax = lastmax;
	g_lasttid = lasttid;
	g_accoPrice = accoPrice;
	g_rescosts = rescosts;
	g_isAllotment = isAllotment;
	g_maxAllotment = maxAllotment;
	g_onePersonExtra = onePersonExtra;
	g_morePersonDiscount = morePersonDiscount;
}

function changeBigshot(k) {
	var im = document.getElementById("bigshot");
	im.src = "/getimage/accommodations/212/159/"+k;
}

function changeRooms(v, min, max, res, a, b) {
	setPriceList(res, v*min, document.search.accoPrice.value, v, a, b)
	buildPersonOptions(min * v, max * v);
}

var g_confs = 0;
function updateFoundConfigurations(){
	g_confs++;
}

function checkAvailability(doloop) {
	if(g_confs == 0 && document.search.loopcheck.value <= 5 && (doloop == 1 || document.search.doloop.value == 1)) {
		var month = document.search.month.value;
		var year = document.dateselect.year.value;
		month++;
		if(month > 12) {
			year++;
			month = 1;
		}
		document.search.month.value = month;
		document.search.year.value = year;
		document.search.day.value = "0";
		document.search.go.value = "trip";
		document.search.action.value = "acco";
		document.search.loopcheck.value = parseInt(document.search.loopcheck.value) + 1;
		document.search.doloop.value = 1;
		document.search.submit();
	}else{
		document.search.loopcheck.value = 0;
	}
}