var changeSeas = "";
var changeSeas = "";

function getcookie(cookiename) {
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return "";
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length;
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
function createCookie(name,value,days)
{
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}else{
		var expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}
function split(word,separator)
{
	var array=new Array();
	var element=1;
	var start=0;
	var len;

	for (var i=0; i<=word.length; i++) {
		if (word.charAt(i)==separator || i==word.length) {
			array[element]=word.substring(start,i);
			start=i+1;
			element++;
		}
	}
	array[0]=element-1;
	if (element==1) array[1]=word;
	return array;
}

function CheckYear(where)
{
	if(typeof(where) == 'undefined'){
		where = '';
	}
	month2 		= document.form.DepartMonth.value;
	month 		= theDate.getMonth();
	year 		= theDate.getFullYear();
	month++;
	if ( month2 < month && month2 != '') {
		year++;
		for (i=0;i<document.form.DepartYear.length;i++) {
			if (document.form.DepartYear.options[i].value == year) {
				document.form.DepartYear.options[i].selected = true;
				break;
			}
		}
	} else if(month2 > 10 && month2 != '') {
		for (i=0;i<document.form.DepartYear.length;i++) {
			if (document.form.DepartYear.options[i].value == year) {
				document.form.DepartYear.options[i].selected = true;
				break;
			}
		}
	} else {
		document.form.DepartYear.options[0].selected = true;
	}
	if(month2 > "03" && month2 < "09"){
		//indien er meer dan 2 jaartallen staan dan moet dit onderstaande aangepast zijn door dit in comment.
		//		document.form.DepartYear.options[1].selected = true;
		document.form.DepartYear.options[0].selected = true;
	}
	changeDestResort();
	set_Rdate();
}

function Checkdatum(dateString,dateType) {

	var now = new Date();
	var today = new Date(now.getFullYear(),now.getMonth(),now.getDate());

	if (dateType == 1)
	var date = new Date(dateString.substring(0,4),
	dateString.substring(4,6)-1,
	dateString.substring(6,8));
	else if (dateType == 2)
	var date = new Date(dateString.substring(0,2),
	dateString.substring(2,4)-1,
	dateString.substring(4,6));
	else if (dateType == 3)
	var date = new Date(dateString.substring(6,10),
	dateString.substring(3,5)-1,
	dateString.substring(0,2));
	else if (dateType == 4)
	var date = new Date(dateString.substring(6,8),
	dateString.substring(3,5)-1,
	dateString.substring(0,2));
	else if (dateType == 5)
	var date = new Date(dateString.substring(0,4),
	dateString.substring(4,6),
	dateString.substring(6,8));

	else
	return false;

	if (Date.parse(date) < Date.parse(today)) {
		return false;
	} else {
		return true;
	}
}

function alert_it(str)
{
	var IP = document.form.IP.value;
	if(IP == '10.177.20.157'){
		alert(str);
	}
}

function bootValues()
{
	if(document.form.User.options[0].value == "0"){
		var uniuser				= document.form.User.options[2].value.substr(0,2);
	} else {
		var uniuser				= document.form.User.options[0].value.substr(0,2);
	}
	switch(uniuser){
		case "2_":
		var user			= "2";
		break;
		case "S2":
		var user			= "N";
		break;
		case "C2":
		var user			= "T";
		break;
		case "K2":
		var user			= "L";
		break;
		case "A2":
		var user			= "B";
		break;
	}

	var sseason				= (user == 2)?document.form.User.value.substr(2,1):top.document.form.User.value.substr(2,1);
	
	var ToDD 				= theDate.getDate();
	var ToDM 				= theDate.getMonth();
	var ToDY 				= theDate.getFullYear();
	ToDD =  top.document.form.DepartDay.options[top.document.form.DepartDay.selectedIndex].value;
	ToDM =  top.document.form.DepartMonth.options[top.document.form.DepartMonth.selectedIndex].value;
	ToDY =  top.document.form.DepartYear.options[top.document.form.DepartYear.selectedIndex].value;
	var Today				= new Date(ToDY,ToDM,ToDD);
	var Setday				= new Date(ToDY,(parseFloat(ToDM)-1),ToDD);
	loaded					= 1;
	var addMonth			= 1;

	switch(user){
		case '2':
		var check_date 	= vlieg_W;
		var check_date1	= vlieg_Z;
		addMonth			= 0;
		break;
		case 'B':
		var check_date 	= auto_W;
		var check_date1	= auto_Z;
		addMonth			= 0;
		break;
		case 'N':
		var check_date 	= sneeuw_W;
		var check_date1	= sneeuw_Z;
		addMonth			= 0;
		break;
		case 'L':
		var check_date 	= dicht_W;
		var check_date1	= dicht_Z;
		addMonth			= 0;
		break;
		case 'T':
		var check_date 	= city_W;
		var check_date1	= city_Z;
		addMonth			= 0;
		break;
	}
		
	var set_date			= ((sseason % 2) == 0)?check_date1:check_date;
	var month				= (Setday >= set_date)?(Setday.getMonth()+parseFloat(1)):(set_date.getMonth()+parseFloat(addMonth));
	if(typeof(set_seas) == 'undefined' && deel == getcookie('deel')){
		var Newday				= new Date(year,month,day);
		month					= (Setday > Newday)?(Setday.getMonth()+parseFloat(1)):month;
	}
	month					= (month < 10)?"0"+month:month;
	
	var form_set_user = ((uniuser == "2_")?"2":uniuser)+"_"+sseason+"_"+parseFloat(month);
	switch(form_set_user){
		case "2_7_10":
			form_set_user = "2_6_10";
		break;
		case "2_6_11":
			form_set_user = "2_7_11";
		break;
		case "K2_8_4":
			form_set_user = "K2_7_4";
		break;
	}
	document.form.User.value= form_set_user;

	changeDestResort();
	createCookie("mm",month,"");
}
function add_zero(str)
{
	var str = ""+str+"";
	var len = str.length;
	if(len < 2){
		str = 0 + str;
	}
	return str;
}
function over(imgName)
{
	if (document.images) {
		document.images[imgName].src = "/swimages/general/" + imgName + "_h.gif";
	}
}

function out(imgName)
{
	if (last == imgName) {
		document.images[imgName].src = "/swimages/general/" + imgName + "_h.gif";
	}
	else
	{
		document.images[imgName].src = "/swimages/general/" + imgName + ".gif";
	}
}

function high(imgName)
{
	if (last != "none") {
		document.images[last].src = "/swimages/general/" + last + ".gif";
	}
	document.images[imgName].src = "/swimages/general/" + imgName + ".gif";
	last = imgName;
}

function ChangeDestMap(code) {
	// code = is de variabele gekregen van resultaat-frame
	var arr_user		= document.form.User.value.split("_");
	if(arr_user.length > 1){
		var user			= arr_user[0]+"_"+arr_user[1];
	}else{
		var user			= arr_user[0];
	}
	var userNum			= user;
	var brochure 		= user;
	var string1 = "";

	for (var i=0;i<document.form.destination.length;i++) {
		if (code==document.form.destination.options[i].value) {
			document.form.destination.options[i].selected=true;
			break;
		}
	}
	if(!document.form.zoek){
		if (i >= document.form.destination.length) {
			string1 = "* Uw gekozen bestemming ";
			string1 += " is niet geldig in de brochure ";
			string1 += brochure;
		}
	}

	changeMenu()
	if (string1 != "") alert(string1);
}

function ChangeResortsMap(code) {
	var userNum			= document.form.User.value;
	var arr_user		= document.form.User.value.split("_");
	if(arr_user.length > 1){
		var user			= arr_user[0]+"_"+arr_user[1];
	}else{
		var user			= arr_user[0];
	}
	var brochure 	= user;
	for (var i=0;i<document.form.resort.length;i++) {
		if (code==document.form.resort.options[i].value) {
			document.form.resort.options[i].selected=true;
			break;
		}
	}

	var string1 = "";
	if(!document.form.zoek){
		if (i >= document.form.resort.length) {
			if (lng=="N") {
				string1 += "\n\n"
				string1 += "* Uw gekozen bestemming ";
				//  string1 +=  saveresorttext;
				string1 += " is niet geldig in de brochure ";
				string1 += brochure;
			} else {
				string1 += "\n\n"
				string1 = "* La destination ";
				//    string1 += saveresorttext;
				string1 += " n'est plus figurée dans la brochure ";
				string1 += brochure;
			}
		}
	}
	if (string1 != "") alert(string1);
}
function getSeason(set_seas)
{
	global_seas				= set_seas;
	createCookie("global_seas",set_seas,"");
	document.form.Season.value = global_seas;
}
function framePage(link)
{
	show_iframe();
	parent.resultaat.document.location.href=link;
}
function change_dest(code)
{
	document.form.destination.value= code;
	changeMenu();
}
function change_regio(landcode,regiocode)
{
	document.form.destination.value= landcode;
	changeMenu();
	document.form.resort.value= regiocode;
	SwitchMap();
}
function set_promo(hotelcode,day,month,year,airport,nights,what)
{
	day 			= addL_zero(day,2);
	month 			= addL_zero(month,2);
	var now			= new Date();
	year_now		= now.getFullYear();
	month_now		= now.getMonth() + 1;
	day_now			= now.getDate();
	var urlAdd		= "";
	var today 		= new Date(year_now,month_now,day_now);
	var date_link 	= new Date(year,month,day);
	if(document.form.listC){
		document.form.listC.checked = false;
	}

	if(day == 00){
		urlAdd		= "&dd="+parent.vulin.document.form.DepartDay.value;
	}else{
		urlAdd		= "&dd="+day;
	}
	if(month == 00){
		urlAdd		= urlAdd+"&mm="+parent.vulin.document.form.DepartMonth.value;
	}else{
		urlAdd		= urlAdd+"&mm="+month;
	}
	if(year == ''){
		urlAdd		= urlAdd+"&yy="+parent.vulin.document.form.DepartYear.value;
	}else{
		urlAdd		= urlAdd+"&yy="+year;
	}
	if(location.href.indexOf('bepages') == '-1'){
		if((what == 'auto' || what == 'dicht' || what == 'sneeuw' || what == 'city' || what == 'seagull')){
			parent.location.href="/index.php?deel="+what+"&hcode="+hotelcode+urlAdd+"&dur="+nights;
		}else{
			parent.location.href="/index.php?deel="+what+"&hcode="+hotelcode+urlAdd+"&air="+airport+"&dur="+nights;
		}
	}else{
		if((what == 'auto' || what == 'dicht' || what == 'sneeuw' || what == 'city' || what == 'seagull') && parent.vulin.document.form.deel.value != what){
			parent.location.href="index.php?deel="+what+"&hcode="+hotelcode+urlAdd;
		}else{
			if(day != '' && month != '' && year != ''){
				if(Date.parse(today) > Date.parse(date_link)){
					parent.vulin.document.form.DepartDay.value 		= add_zero(day_now);
					parent.vulin.document.form.DepartMonth.value	= add_zero(month_now);
					parent.vulin.document.form.DepartYear.value 	= year_now;
				}else{
					parent.vulin.document.form.DepartDay.value 		= day;
					parent.vulin.document.form.DepartMonth.value	= month;
					parent.vulin.document.form.DepartYear.value 	= year;
				}
			}
			changeSeas = "no";
			getSeason();
			parent.vulin.document.form.Hotelcode.value 		= hotelcode;
			if(parent.vulin.document.form.Duration && nights != ''){
				parent.vulin.document.form.Duration.value  	= parseFloat(nights);
			}
			if(parent.vulin.document.form.Airport && airport != ''){
				parent.vulin.document.form.luchthaven.value	= airport;
				parent.vulin.document.form.Airport.value  	= airport;
			}
			set_Rdate();
			show_loading();
			parent.vulin.Zoek();
			changeSeas = "";
		}
	}
}
function addL_zero(str,min) // toevoegen van lead zeros
{
	var len = str.length;
	var add_zero = "";
	if(len < min){
		teller = min - len;
		for(i=0;i<teller;i++){
			add_zero = add_zero + "0";
		}
		str = add_zero + str;
	}

	return str;
}
function select_hotel(code)
{
	document.form.Hotelcode.value = code;
	Zoek();
}
function set_dest_res(dest,res)
{
	parent.vulin.document.form.Hotelcode.value = "";
	if(parent.vulin){
		if(dest != ''){
			parent.vulin.document.form.destination.value=dest;
			parent.vulin.document.form.dest_resort.value="D"+dest;
		}
		parent.vulin.document.form.resort.value=res;
		parent.vulin.document.form.dest_resort.value="RD"+dest+"_"+res;
		if(parent.vulin.document.form.Airport){
			parent.vulin.changeAirport();
		}
		parent.vulin.Zoek();
	}else if(top.parent.vulin){
		if(dest != ''){
			top.parent.vulin.document.form.destination.value=dest;
			top.parent.vulin.document.form.dest_resort.value="D"+dest;
		}
		top.parent.vulin.document.form.resort.value=res;
		top.parent.vulin.document.form.dest_resort.value="RD"+dest+"_"+res;
		if(top.parent.vulin.document.form.Airport){
			top.parent.vulin.changeAirport();
		}
		top.parent.vulin.Zoek();
	}
}
function set_resort(dest,res)
{
	if(dest != ''){
		parent.vulin.document.form.destination.value=dest;
		parent.vulin.document.form.dest_resort.value="D"+dest;
	}
	parent.vulin.document.form.resort.value=res;
	parent.vulin.document.form.dest_resort.value="RD"+dest+"_"+res;
	parent.vulin.changeDestOrResort(parent.vulin.document.form.dest_resort);
}
function changeDestResort() //zorgt ervoor dat de javascript array gesplit wordt en vuld de selectbox op
{
	try{
		for(i=0;i<document.form.User.length;i++){
			if(document.form.User[i].checked){
				document.form.User.value = document.form.User[i].value;
			}
		}
	}catch(err){}

	var UniUser				= document.form.User.value.substr(0,2);

	switch(UniUser){
		case "2_":
		var User			= "2";
		break;
		case "S2":
		var User			= "N";
		break;
		case "C2":
		var User			= "T";
		break;
		case "K2":
		var User			= "L";
		break;
		case "A2":
		var User			= "B";
		break;
	}
	var Season				= (User == 2)?document.form.User.value.substr(2,1):document.form.User.value.substr(3,1);
	var child				= document.form.dest_resort;
	var destination			= document.form.destination.value;
	var lng					= document.form.Language.value;
	var resort 				= document.form.resort.value;
	getSeason(Season);
	var seas 				= global_seas;
	var accom				= "";
	
	try{
		if(User == 2){
			if(lng == "F"){
				array = eval("arr_overall_"+User+"_"+Season+"");
			} else {
				array = eval("arr_overall_"+User+"_"+Season);
			}
		} else {
			if((User == "B" || User == "T" || User == "L" || User == "N") && lng == "F"){
				array = eval("arr_overall_"+Season+User+"_fr");
			} else {
				array = eval("arr_overall_"+Season+User);
			}
		}
		var intStart = 4;
		if(User == "T"){
			intStart = 5;
		}
		var arr_len 		= array.length;
		var w				= 2;
		if(lng == 'N') {
			var naam 			= "Geen voorkeur";
			var tm1 			= 2;
			var tm2 			= 1;
		} else {
			var naam 			= "Pas de préférence";
			var tm1				= 3;
			var tm2 			= 2;
		}

		var code 		= "default";
		var stripes		= "- - - - - - - - - - - - - - - - - -";
		var a=new Option(naam,code,false,false);
		child.options[0]=a;
		var a=new Option(stripes,code,false,false);
		child.options[1]=a;
		for(i=0;i<arr_len;i++){
			var arr_sub_len = array[i].length;
			var Dcode = "D"+array[i][1];
			var naam = array[i][tm1];
			var a=new Option(naam,Dcode,false,false);
			child.options[w]=a;
			child.options[w].className='BLT';
			if(destination == array[i][1]){
				child.options[w].selected = true;
			}
			w++;
			for(j=intStart;j<arr_sub_len;j++){
				sub_code = "R"+Dcode+"_"+array[i][j][0];
				sub_naam = " » "+array[i][j][tm2];
				var a=new Option(sub_naam,sub_code,false,false);
				child.options[w]=a;
				child.options[w].className='pLeft';
				if(resort == array[i][j][0]){
					child.options[w].selected = true;
				}
				w++;
			}
		}
	}catch(exp){}
	set_Rdate();

}
function changeMenu()
{
	var dest 	= document.form.destination.value;
	var resort 	= document.form.resort.value;
	var len 	= document.form.dest_resort.options.length;
	for(i=0;i<len;i++){
		value = document.form.dest_resort.options[i].value;
		if(dest != ''){
			if(value == "D"+dest){
				document.form.dest_resort.options[i].selected = true;
			}
		}
		if(resort != ''){
			if(value.indexOf("_"+resort) != '-1'){
				document.form.dest_resort.options[i].selected = true;
				break;
			}
		}
	}
	if(document.form.Hotelcode.value == ''){
		SwitchMap();
	}
}
function dropLR()
{
	if(parent.document.getElementById('Lcode')){
		parent.document.getElementById('Lcode').value = "";
	}
	if(parent.document.getElementById('Rcode')){
		parent.document.getElementById('Rcode').value = "";
	}
	Lcode =	"";
	Rcode =	"";
}
function codeControle(el,what)
{
	if(what == 0 && el.value.indexOf("code") != '-1'){
		el.value = "";
	}
	if(what == 1 && el.value == ''){
		if(lng == 'N'){
			el.value = "hotel/code/regio";
		}else{
			el.value = "l'hôtel/code/region";
		}
	}
}
function set_Rdate()
{
	try{
		var day 	= document.form.DepartDay.value;
		var month 	= document.form.DepartMonth.value;
		var year 	= document.form.DepartYear.value;
		var dur		= document.form.Duration.value;
		for(i=0;i<document.form.Duration.length;i++){
			if(document.form.Duration[i].selected == true){
				var arr_text 	= document.form.Duration[i].text.split(" | ");
				var Rdate		= new Date(year,parseFloat(month) - 1,parseFloat(day) + (parseFloat(dur) - 1));
				var Nday		= Rdate.getDate();
				if(Nday < 10){
					Nday 		= "0"+Nday;
				}
				var Nmonth		= parseFloat(Rdate.getMonth()) + 1;
				if(Nmonth < 10){
					Nmonth 		= "0"+Nmonth;
				}


				document.form.Duration[i].text = arr_text[0] + " | " + Nday+" "+Nmonth+" "+Rdate.getFullYear();
			}else{
				var arr_text 	= document.form.Duration[i].text.split(" | ");
				document.form.Duration[i].text = arr_text[0];
			}
		}
	}catch(expc){}
}
function get_deelURL(deel,lng)
{
	var dest_url;
	switch(deel){
		case "vlieg":
		dest_url = (lng == "N" || lng == 1)? "vliegvakanties" : "vacances_en_avion";
		break;
		case "hotel":
		dest_url = (lng == "N" || lng == 1)? "enkel_hotel" : "hotel_seul";
		break;
		case "auto":
		dest_url = (lng == "N" || lng == 1)? "autovakanties" : "vacances_en_voiture";
		break;
		case "sneeuw":
		dest_url = (lng == "N" || lng == 1)? "sneeuwvakanties" : "neige";
		break;
		case "dicht":
		dest_url = (lng == "N" || lng == 1)? "dichtbijvakanties" : "pres_de_chez_vous";
		break;
		case "city":
		dest_url = (lng == "N" || lng == 1)? "citytrips" : "citytrips_fr";
		break;
		case "seagull":
		dest_url = (lng == "N" || lng == 1)? "seagull" : "seagull_fr";
		break;
		case "disney":
		dest_url = (lng == "N" || lng == 1)? "disneylandresortparijs" : "disneylandresortparis";
		break;
	}
	return dest_url;
}
function get_parameters()
{
	var form 		= document.form.elements;
	var formLen		= form.length;
	var parameters	= "";
	for(i=0;i<formLen;i++){
		var name	= form[i].name;
		switch(name){
			case "DepartDay":
			parameters	= parameters + "&dd="+form[i].value;
			break;
			case "DepartMonth":
			parameters	= parameters + "&mm="+form[i].value;
			break;
			case "DepartYear":
			parameters	= parameters + "&yy="+form[i].value;
			break;
			case "Duration":
			parameters	= parameters + "&dur="+form[i].value;
			break;
			case "Airport":
			parameters	= parameters + "&airpo="+form[i].value;
			break;
			case "Pax":
			parameters	= parameters + "&pax="+form[i].value;
			break;
			case "Child":
			parameters	= parameters + "&chd="+form[i].value;
			break;
			case "Infant":
			parameters	= parameters + "&inf="+form[i].value;
			break;
			case "Language":
			if(form[i].value == 'N'){
				parameters	= parameters + "&lng=1";
			}else{
				parameters	= parameters + "&lng=2";
			}
			break;
		}
	}
	parameters 		= parameters.substr(1,parameters.length);

	return parameters;
}
function replace_url(str)
{
	str 	= str.replace(" ","_");
	str 	= str.replace("-","");
	str 	= str.replace("'","_");
	str 	= str.replace("/","");
	return str;
}
function show_loading()
{
	processing = window.open("/bepages/"+lng_dir_marker+"/loading.htm","processing","top=300,left=450,width=300,height=200,toolbar=0, status=0");
}
function set_Pax()
{
	try{
		var Pax 		= document.form.Pax.value;
		var Child 		= document.form.Child.value;
		if(document.form.Infant){
			var Infant		= document.form.Infant.value;
			createCookie("Infant",Infant,"");
		}
		createCookie("Pax",Pax,"");
		createCookie("Child",Child,"");
	}catch(excp){}
}
