/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Francis Cocharrua :: http://scripts.franciscocharrua.com/ */

//global variables for all calendars ............................
var months = new Array('Januar','Februar','Mars','April','Mai','Juni','Juli','August','September','Oktober','November','Desember');
var week_day_header='<tr align="center" class = "n2"><td>Mån</td><td>Tir</td><td>Ons</td><td>Tor</td><td>Fre</td><td>Lør</td> <td>Søn</td></tr>';

 function g_select_date(txt_year,txt_month,day)
 {
//alert(txt_year+","+txt_month+","+day);
	if(day.length==1) {day1="0"+day}else{day1=day}
	if(txt_month.length==1) {txt_month="0"+txt_month}else{txt_month=txt_month}

	document.getElementById("UtreiseDay").value=txt_year+"-"+txt_month+"-"+day1;
	document.getElementById("dato").value=txt_year+"-"+txt_month+"-"+day1;

	var h_id=document.getElementById("g_h_id").value;
	//alert(h_id);
	if(h_id!="")
	{
		document.getElementById(h_id).style.backgroundColor='#61BE0A';
	}
	document.getElementById("g_td_"+day).style.backgroundColor="#FF8080";
	 document.getElementById("g_h_id").value="g_td_"+day;

	document.getElementById("dg_msg").innerHTML="";
 }

 function g_select_date1(txt_year,txt_month,day)
 {
//alert(txt_year+","+txt_month+","+day);
//txt_month=parseInt(txt_month)+1;
	if(day.length==1) {day1="0"+day}else{day1=day}
	if(txt_month.length==1) {txt_month="0"+txt_month}else{txt_month=txt_month}

	document.getElementById("UtreiseDay1").value=txt_year+"-"+txt_month+"-"+day1;
	document.getElementById("ReturDay1").value='ReturDato';
	document.getElementById("dato1").value=txt_year+"-"+txt_month+"-"+day1;
	document.getElementById("Nights").value='0';

	var h_id=document.getElementById("g_h_id1").value;
	//alert(h_id);
	if(h_id!="")
	{
		document.getElementById(h_id).style.backgroundColor='#61BE0A';
	}
	document.getElementById("g_td1_"+parseInt(day)).style.backgroundColor="#FF8080";
	 document.getElementById("g_h_id1").value="g_td1_"+parseInt(day);

	document.getElementById("dg_msg1").innerHTML="";
 }

 function r_select_date(txt_year,txt_month,day)
 {
	if(day==""){alert("Vennligst velg gå dager .........");return false;}
	if(day.length==1) {day1="0"+day}else{day1=day}
	if(txt_month.length==1) {txt_month="0"+txt_month}else{txt_month=txt_month}

	document.getElementById("ReturDay").value=txt_year+"-"+txt_month+"-"+day1;
//Set the two dates
var gdate=document.getElementById("dato").value;
var gdatearray=gdate.split('-');

if(txt_month==gdatearray[1])
{
	var goingdate =new Date(gdatearray[0],gdatearray[1],gdatearray[2]);
	var returndate=new Date(txt_year,txt_month,day);
	var one_day=1000*60*60*24
	//Calculate difference btw the two dates, and convert to days
	var dgval=Math.ceil((returndate.getTime()-goingdate.getTime())/(one_day));
	document.getElementById("dager").value=dgval;
	document.getElementById("dg_msg").innerHTML="<span class='textwhite'>Du søker med avreise "+gdate+" og Dager "+dgval+"</span>";
}
else
{
	var goingdate =new Date(gdatearray[0],gdatearray[1]-1,1);
	var returndate=new Date(txt_year,txt_month-1,1);
	var days_in_this_month=Math.round((returndate.getTime() - goingdate.getTime()) / (1000 * 60 * 60 * 24));
	//alert(goingdate+"/"+returndate+"/"+days_in_this_month);
	var days_diff_in_this_month=days_in_this_month-gdatearray[2];
	//Calculate difference btw the two dates, and convert to days
	var dgval=parseInt(days_diff_in_this_month)+parseInt(day);
	document.getElementById("dager").value=dgval;
	document.getElementById("dg_msg").innerHTML="<span class='textwhite'>Du søker med avreise "+gdate+" og Dager "+dgval+"</span>";
}

	var h_id=document.getElementById("r_h_id").value;
	//alert(h_id);
	if(h_id!="")
	{
		document.getElementById(h_id).style.backgroundColor='#61BE0A';
	}
	document.getElementById("r_td_"+day).style.backgroundColor="#FF8080";
	 document.getElementById("r_h_id").value="r_td_"+day;
 }

function r_select_date1(txt_year,txt_month,day)
 {
	if(document.getElementById("UtreiseDay1").value=="UtreiseDato"){alert("Vennligst velg gå dager .........");return false;}
	if(day.length==1) {day1="0"+day}else{day1=day}
	if(txt_month.length==1) {txt_month="0"+txt_month}else{txt_month=txt_month}

	document.getElementById("ReturDay1").value=txt_year+"-"+txt_month+"-"+day1;
//Set the two dates
var gdate=document.getElementById("dato1").value;
var gdatearray=gdate.split('-');

if(txt_month==gdatearray[1])
{
	var goingdate =new Date(gdatearray[0],gdatearray[1],gdatearray[2]);
	var returndate=new Date(txt_year,txt_month,day);
	var one_day=1000*60*60*24
	//Calculate difference btw the two dates, and convert to days
	var dgval=Math.ceil((returndate.getTime()-goingdate.getTime())/(one_day));
	if(dgval > 31){document.getElementById("ReturDay1").value="ReturDato";alert("Vennligst velg mindre enn 31 dager .........");return false;}
	document.getElementById("Nights").value=dgval;
	document.getElementById("dg_msg1").innerHTML="<span class='textwhite'>Du søker med avreise "+gdate+" og Dager "+dgval+"</span>";
}
else
{
	var goingdate =new Date(gdatearray[0],gdatearray[1]-1,1);
	var returndate=new Date(txt_year,txt_month-1,1);
	var days_in_this_month=Math.round((returndate.getTime() - goingdate.getTime()) / (1000 * 60 * 60 * 24));
	//alert(goingdate+"/"+returndate+"/"+days_in_this_month);
	var days_diff_in_this_month=days_in_this_month-gdatearray[2];
	//Calculate difference btw the two dates, and convert to days
	var dgval=parseInt(days_diff_in_this_month)+parseInt(day);
	if(dgval > 31){document.getElementById("ReturDay1").value="ReturDato";alert("Vennligst velg mindre enn 31 dager .........");return false;}
	document.getElementById("Nights").value=dgval;
	document.getElementById("dg_msg1").innerHTML="<span class='textwhite'>Du søker med avreise "+gdate+" og Dager "+dgval+"</span>";
}


	var h_id=document.getElementById("r_h_id1").value;
	//alert(h_id);
	if(h_id!="")
	{
		document.getElementById(h_id).style.backgroundColor='#61BE0A';
	}
	document.getElementById("r_td1_"+day).style.backgroundColor="#FF8080";
	 document.getElementById("r_h_id1").value="r_td1_"+day;
 }


function val_for_cal2_l_nav(date,sel_div,day_counter_req,sel_dgs)
{
//alert(date+","+sel_div+","+day_counter_req+","+sel_dgs);
	document.getElementById("h_val_for_cal2_l_nav").value='"'+date+'","'+sel_div+'","'+day_counter_req+'","'+sel_dgs+'"';
	document.getElementById("h_val_for_ret_cal_restore").value=sel_dgs;
}

function call_r_l_nav()
{
	h_val_for_cal2_l_nav=document.getElementById("h_val_for_cal2_l_nav").value;

	document.getElementById("r_l_nav").innerHTML='<span class="caltext" style="cursor:pointer;" title="tidligere" onclick=javascript:calendar2('+h_val_for_cal2_l_nav+');><<</span>';
}

function calendar1(date,sel_div,day_counter_req,sel_dgs) {
  // If no parameter is passed use the current date.
  //alert(date);
var depname=document.getElementById("fra").value;
var destname=document.getElementById("til").value;
//alert(depname+destname);
if(day_counter_req=="")
{
document.getElementById("g_h_id").value='';
}
if(date=='')
{
	document.getElementById("UtreiseDay").value="UtreiseDato";
}
document.getElementById("ReturDay").value="ReturDato";
document.getElementById("dg_msg").innerHTML="";

//data for date ddl , g_left_nav and g_right_nav collection start...........................................................................................

var dep_code_for_date=document.getElementById("fra").value;
var dest_code_for_date=document.getElementById("til").value;

//for specific month-year.................................................................

var date_option_val='<select name="ddl_date" id="ddl_date" class="textbox" style="-moz-border-radius: 3px;-webkit-border-radius:3px;-khtml-border-radius: 3px;border-radius: 3px 3px 3px 3px;" onchange=javascript:calendar1(this.value,"cal_div1","","");calendar2("ddl_date_change","cal_div2","","");>';
for(var desti=0;desti<DepDestArray.length;desti++)
{
	var t_option_val=DepDestArray[desti];
	var depdest_option_val=t_option_val.split(':');
	var dep_code_o=depdest_option_val[0];

	if(dep_code_o==dep_code_for_date)
	{
		var dest_code_name_o=depdest_option_val[1];
		var t_dest_code_name_o=dest_code_name_o.split(';');
		for(var pi=0;pi<t_dest_code_name_o.length;pi++)
		{
			var my_dest_code_name=t_dest_code_name_o[pi];
			var spli_my_dest_code_name=my_dest_code_name.split('.');
			var dest_code_o=spli_my_dest_code_name[0];
			//var dest_name_o=spli_my_dest_code_name[1];
			if(dest_code_o==dest_code_for_date)
			{
				var date_o=spli_my_dest_code_name[2];
				//alert(date_o);
				var t_date_o=date_o.split('-');
				var t_date_o_cnt=0;
				var t_date_o_array=Array();
				for(var doi=0;doi<t_date_o.length;doi++)
				{
					var my_t_date_o=t_date_o[doi];
					//alert(my_t_date_o);
					var mon_year_for_disp=my_t_date_o.split(',');
					if(my_t_date_o==date)
					{
						date_option_val+='<option value="'+my_t_date_o+'" selected>'+months[mon_year_for_disp[1]-1]+' '+mon_year_for_disp[0]+'</option>';
					}
					else
					{
						date_option_val+='<option value="'+my_t_date_o+'">'+months[mon_year_for_disp[1]-1]+' '+mon_year_for_disp[0]+'</option>';
					}

					t_date_o_array.push(my_t_date_o);
					if(t_date_o_cnt==0)
					{
						var first_t_date_o=my_t_date_o;
						document.getElementById("r_h_first_date_id").value=my_t_date_o;
					}
					t_date_o_cnt++;
				}
			}

		}
	}
}
date_option_val+='</select>';
//alert(date_option_val);


//data for date ddl , g_left_nav and g_right_nav collection end.......................................................................................................

//alert(date);
//alert(first_t_date_o);

if(date == "")
{
	var split_date=first_t_date_o.split(",");
	y1=split_date[0];m1=split_date[1];d1=split_date[2];
	date=new Date(y1,m1-1,d1);
}
else
{
	var split_date=date.split(",");
	y1=split_date[0];m1=split_date[1];d1=split_date[2];
	date=new Date(y1,m1-1,d1);
}
//alert(date);
  day = date.getDate();
  month = date.getMonth();
  year = date.getFullYear();

  var str_for_nav=year+','+(month+1)+','+day;
//alert(str_for_nav);
for(t_date_o_i=0;t_date_o_i<t_date_o_array.length;t_date_o_i++)
{
	var date_o_for_nav=t_date_o_array[t_date_o_i];

	if(date_o_for_nav==str_for_nav)
	{
		var index_for_nav=t_date_o_i;
		break;
	}
}
//alert(index_for_nav);
var right_nav_val="";
var left_nav_val="";
if(index_for_nav==0 && (t_date_o_array.length-1)>0)
{
	right_nav_val='<span class="caltext" style="cursor:pointer;" title="neste" onclick=javascript:calendar1("'+t_date_o_array[index_for_nav+1]+'","cal_div1","","");calendar2("'+t_date_o_array[index_for_nav+1]+'","cal_div2","","");>>></span>';
	left_nav_val='';
}
else if(index_for_nav!=0 && index_for_nav<(t_date_o_array.length-1))
{
	right_nav_val='<span class="caltext" style="cursor:pointer;" title="neste" onclick=javascript:calendar1("'+t_date_o_array[index_for_nav+1]+'","cal_div1","","");calendar2("'+t_date_o_array[index_for_nav+1]+'","cal_div2","","");>>></span>';
	left_nav_val='<span class="caltext" style="cursor:pointer;" title="tidligere" onclick=javascript:calendar1("'+t_date_o_array[index_for_nav-1]+'","cal_div1","","");calendar2("'+t_date_o_array[index_for_nav-1]+'","cal_div2","","");><<</span>';
}
else if(index_for_nav==0 && (t_date_o_array.length-1)==0)
{
	right_nav_val='';
	left_nav_val='';
}
else
{
	right_nav_val='';
	left_nav_val='<span class="caltext" style="cursor:pointer;" title="tidligere" onclick=javascript:calendar1("'+t_date_o_array[index_for_nav-1]+'","cal_div1","","");calendar2("'+t_date_o_array[index_for_nav-1]+'","cal_div2","","");><<</span>';
}
//alert("right="+right_nav_val);
//alert("left="+left_nav_val);

  this_month = new Date(year, month, 1);
  next_month = new Date(year, month + 1, 1);
//alert(this_month.getDay());
  // Find out when this month starts and ends.
  first_week_day = this_month.getDay()-1;
if(first_week_day==-1)
{
	first_week_day=6;
}
  days_in_this_month = Math.round((next_month.getTime() - this_month.getTime()) / (1000 * 60 * 60 * 24));
//alert(first_week_day);
  calendar_html = '<table cellpadding="0" cellspacing="2" class="cal_table">';
//  calendar_html += '<tr align="center" height="22px" class="cal_header"><td colspan="7">UtreiseDato Kalender</td></tr>';
  calendar_html += '<tr align="center" height="22px" class="cal_nav"><td id="g_laft_nav"></td><td colspan="5"><span id="date_span"></span></td><td id="g_right_nav"></td></tr>';
  calendar_html += week_day_header;
  calendar_html += '<tr align="center">';
//alert(first_week_day);
  // Fill the first week of the month with the appropriate number of blanks.
  for(week_day = 0; week_day < first_week_day; week_day++)
{
    calendar_html += '<td></td>';
}

  week_day = first_week_day;

var x_GoingDateArray=new Array();

switch (depname)
{
case "ALF": {for(my_ind=0;my_ind<GoingDateArrayALF.length;my_ind++){x_GoingDateArray.push(GoingDateArrayALF[my_ind]);}} break;
case "AES": {for(my_ind=0;my_ind<GoingDateArrayAES.length;my_ind++){x_GoingDateArray.push(GoingDateArrayAES[my_ind]);}} break;
case "BGO": {for(my_ind=0;my_ind<GoingDateArrayBGO.length;my_ind++){x_GoingDateArray.push(GoingDateArrayBGO[my_ind]);}} break;
case "BOO": {for(my_ind=0;my_ind<GoingDateArrayBOO.length;my_ind++){x_GoingDateArray.push(GoingDateArrayBOO[my_ind]);}} break;
case "EVE": {for(my_ind=0;my_ind<GoingDateArrayEVE.length;my_ind++){x_GoingDateArray.push(GoingDateArrayEVE[my_ind]);}} break;
case "HAU": {for(my_ind=0;my_ind<GoingDateArrayHAU.length;my_ind++){x_GoingDateArray.push(GoingDateArrayHAU[my_ind]);}} break;
case "KRS": {for(my_ind=0;my_ind<GoingDateArrayKRS.length;my_ind++){x_GoingDateArray.push(GoingDateArrayKRS[my_ind]);}} break;
case "KSU": {for(my_ind=0;my_ind<GoingDateArrayKSU.length;my_ind++){x_GoingDateArray.push(GoingDateArrayKSU[my_ind]);}} break;
case "LKL": {for(my_ind=0;my_ind<GoingDateArrayLKL.length;my_ind++){x_GoingDateArray.push(GoingDateArrayLKL[my_ind]);}} break;
case "MOL": {for(my_ind=0;my_ind<GoingDateArrayMOL.length;my_ind++){x_GoingDateArray.push(GoingDateArrayMOL[my_ind]);}} break;
case "OSL": {for(my_ind=0;my_ind<GoingDateArrayOSL.length;my_ind++){x_GoingDateArray.push(GoingDateArrayOSL[my_ind]);}} break;
case "RYG": {for(my_ind=0;my_ind<GoingDateArrayRYG.length;my_ind++){x_GoingDateArray.push(GoingDateArrayRYG[my_ind]);}} break;
case "SVG": {for(my_ind=0;my_ind<GoingDateArraySVG.length;my_ind++){x_GoingDateArray.push(GoingDateArraySVG[my_ind]);}} break;
case "TOS": {for(my_ind=0;my_ind<GoingDateArrayTOS.length;my_ind++){x_GoingDateArray.push(GoingDateArrayTOS[my_ind]);}} break;
case "TRD": {for(my_ind=0;my_ind<GoingDateArrayTRD.length;my_ind++){x_GoingDateArray.push(GoingDateArrayTRD[my_ind]);}} break;
case "TRF": {for(my_ind=0;my_ind<GoingDateArrayTRF.length;my_ind++){x_GoingDateArray.push(GoingDateArrayTRF[my_ind]);}} break;

//default: result = 'unknown';
}

for(day_counter = 1; day_counter <= days_in_this_month; day_counter++)
{
    week_day %= 7;
    if(week_day == 0)
      calendar_html += '</tr><tr align="center">';

			var chkDay=day_counter;
			var chkMon=month+1;

			var str=year+","+chkMon+","+chkDay;
			//alert(str);

myDateArray1=Array();
myDgArray1=Array();

for(mda=0;mda<x_GoingDateArray.length;mda++){var col_tot=x_GoingDateArray[mda];var col_array=col_tot.split(":");col_dest=col_array[0];if(col_dest==destname){t_col_date_dg=col_array[1];t_col_date_dg_array=t_col_date_dg.split(';');for(tddi=0;tddi<t_col_date_dg_array.length;tddi++){col_date_dg=t_col_date_dg_array[tddi];col_date_dg_array=col_date_dg.split('-');col_date=col_date_dg_array[0];col_dgs=col_date_dg_array[1];myDateArray1.push(col_date);myDgArray1.push(col_dgs);}}}

var found = -1;for (var i = 0; i < myDateArray1.length; i++){if (myDateArray1[i] == str){found = i;break;}}

			if(found!=-1)
			{
				var dgs=myDgArray1[found];
				//alert(dgs);
				var onclickval='onclick=javascript:calendar2("' +str+ '","cal_div2","' + day_counter + '","'+dgs+'");g_select_date("'+year+'","'+(parseInt(month)+1)+'","'+day_counter+'");val_for_cal2_l_nav("' +str+ '","cal_div2","' + day_counter + '","'+dgs+'");document.getElementById("dager").value="0" TITLE="'+dgs+'" id="g_td_'+day_counter+'">';

				calendar_html += '<td class="n_available" ' + onclickval + day_counter + '</td>';
			}
			else
			{
				calendar_html += '<td class="n">' + day_counter + '</td>';
			}


    week_day++;
}

  calendar_html += '</tr>';
  calendar_html += '</table>';

  // Display the calendar.
  //document.write(calendar_html);
//alert(calendar_html);
document.getElementById(sel_div).innerHTML=calendar_html;

document.getElementById("date_span").innerHTML=date_option_val;
document.getElementById("g_right_nav").innerHTML=right_nav_val;
document.getElementById("g_laft_nav").innerHTML=left_nav_val;
}

function calendar2(date,sel_div,day_counter_req,sel_dgs)
{  // If no parameter is passed use the current date.
//alert(date);
if(date=="ddl_date_change")
{
	date=document.getElementById("ddl_date").value;
}
//alert(date);
var flag_r=0;
var depname=document.getElementById("fra").value;
var destname=document.getElementById("til").value;
document.getElementById("r_h_id").value='';
document.getElementById("ReturDay").value="ReturDato";
document.getElementById("dg_msg").innerHTML="";

if(date == "")
{
	var split_date=document.getElementById("r_h_first_date_id").value.split(",");
	y1=split_date[0];m1=split_date[1];d1=split_date[2];
	date=new Date(y1,m1-1,d1);
}
else
{
	var split_date=date.split(",");
	y1=split_date[0];m1=split_date[1];d1=split_date[2];
	date=new Date(y1,m1-1,d1);
}
//alert(date);
  day = date.getDate();
  month = date.getMonth();
  year = date.getFullYear();

  this_month = new Date(year, month, 1);
  next_month = new Date(year, month + 1, 1);

  // Find out when this month starts and ends.
  first_week_day = this_month.getDay()-1;
if(first_week_day==-1)
{
	first_week_day=6;
}
  days_in_this_month = Math.round((next_month.getTime() - this_month.getTime()) / (1000 * 60 * 60 * 24));
//alert(days_in_this_month);
  calendar_html = '<table cellpadding="0" cellspacing="2" class="cal_table">';
 // calendar_html += '<tr align="center" height="22px" class="cal_header"><td colspan="7">ReturDato Kalender</td></tr>';
  calendar_html += '<tr align="center" height="22px" class="cal_nav"><td id="r_l_nav"></td><td colspan="5" class="caltext">' + months[month] + ' ' + year + '</td><td id="r_r_nav"></td></tr>';
  calendar_html += week_day_header;
  calendar_html += '<tr align="center">';

  // Fill the first week of the month with the appropriate number of blanks.
  for(week_day = 0; week_day < first_week_day; week_day++)
{
    calendar_html += '<td></td>';
}

  week_day = first_week_day;

var x_ReturnDateArray=new Array();
switch (depname)
{
case "ALF": {for(my_ind=0;my_ind<ReturnDateArrayALF.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayALF[my_ind]);}} break;
case "AES": {for(my_ind=0;my_ind<ReturnDateArrayAES.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayAES[my_ind]);}} break;
case "BGO": {for(my_ind=0;my_ind<ReturnDateArrayBGO.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayBGO[my_ind]);}} break;
case "BOO": {for(my_ind=0;my_ind<ReturnDateArrayBOO.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayBOO[my_ind]);}} break;
case "EVE": {for(my_ind=0;my_ind<ReturnDateArrayEVE.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayEVE[my_ind]);}} break;
case "HAU": {for(my_ind=0;my_ind<ReturnDateArrayHAU.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayHAU[my_ind]);}} break;
case "KRS": {for(my_ind=0;my_ind<ReturnDateArrayKRS.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayKRS[my_ind]);}} break;
case "KSU": {for(my_ind=0;my_ind<ReturnDateArrayKSU.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayKSU[my_ind]);}} break;
case "LKL": {for(my_ind=0;my_ind<ReturnDateArrayLKL.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayLKL[my_ind]);}} break;
case "MOL": {for(my_ind=0;my_ind<ReturnDateArrayMOL.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayMOL[my_ind]);}} break;
case "OSL": {for(my_ind=0;my_ind<ReturnDateArrayOSL.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayOSL[my_ind]);}} break;
case "RYG": {for(my_ind=0;my_ind<ReturnDateArrayRYG.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayRYG[my_ind]);}} break;
case "SVG": {for(my_ind=0;my_ind<ReturnDateArraySVG.length;my_ind++){x_ReturnDateArray.push(ReturnDateArraySVG[my_ind]);}} break;
case "TOS": {for(my_ind=0;my_ind<ReturnDateArrayTOS.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayTOS[my_ind]);}} break;
case "TRD": {for(my_ind=0;my_ind<ReturnDateArrayTRD.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayTRD[my_ind]);}} break;
case "TRF": {for(my_ind=0;my_ind<ReturnDateArrayTRF.length;my_ind++){x_ReturnDateArray.push(ReturnDateArrayTRF[my_ind]);}} break;
}
var nub_of_disp_date_cnt=0;

for(day_counter = 1; day_counter <= days_in_this_month; day_counter++)
{
    week_day %= 7;
    if(week_day == 0)
      calendar_html += '</tr><tr align="center">';

			var chkDay=day_counter;
			var chkMon=month+1;

			var str=year+","+chkMon+","+chkDay;
			//alert(str);

var dg_array=sel_dgs.split(",");


if(day_counter_req!="")
{
	//var com_day_counter=parseInt(day_counter_req)+6;      //for first time > num day  display
var com_day_counter=0;

var found = -1;
//searchString = depname+","+destname+":"+str;

for (var i = 0; i < x_ReturnDateArray.length; i++){var t_dest_date_array=x_ReturnDateArray[i].split(':');if(t_dest_date_array[0]==destname){var t_dates=t_dest_date_array[1];var t_dates_array=t_dates.split(';');for(var tdi=0;tdi<t_dates_array.length;tdi++){if (t_dates_array[tdi] == str){found = tdi;break;}}}}

			if(found!=-1)
			{
				if(day_counter > com_day_counter)
				{
					flag_dg=0;
					for(idg=0;idg<dg_array.length;idg++)
					{
						var com_dg=dg_array[idg];
						if(day_counter==parseInt(day_counter_req)+parseInt(com_dg))
						{
							flag_dg=1;
							break;
						}
					}

					if(flag_dg==1)
					{
						var onclickval='onclick=javascript:r_select_date("'+year+'","'+(parseInt(month)+1)+'","'+day_counter+'"); id="r_td_'+day_counter+'">';

						calendar_html += '<td class="n_available" '+ onclickval + day_counter + '</td>';
						flag_r=1;
						nub_of_disp_date_cnt++;
					}
					else
					{
						calendar_html += '<td class="n">' + day_counter + '</td>';
					}
				}
				else
				{
					calendar_html += '<td class="n">' + day_counter + '</td>';
				}
			}
			else
			{
				calendar_html += '<td class="n">' + day_counter + '</td>';
			}

}
else
{
	if(document.getElementById('req_ret_day_for_select'))
	{
		var req_ret_day_for_select=document.getElementById('req_ret_day_for_select').value;
	}
	var com_day_counter=0;   //for first time all display

var found = -1;
//searchString = depname+","+destname+":"+str;
for (var i = 0; i < x_ReturnDateArray.length; i++){var t_dest_date_array=x_ReturnDateArray[i].split(':');if(t_dest_date_array[0]==destname){var t_dates=t_dest_date_array[1];var t_dates_array=t_dates.split(';');for(var tdi=0;tdi<t_dates_array.length;tdi++){if (t_dates_array[tdi] == str){found = tdi;break;}}}}

			if(found!=-1)
			{
				if(day_counter > com_day_counter)
				{
					if(sel_dgs=="")
					{
						/*if(day_counter==req_ret_day_for_select)
						{
							calendar_html += '<td class="n_available" style="background-color: #FF8080;">' + day_counter + '</td>';
						}
						else
						{*/
							var onclickval='onclick=javascript:r_select_date("","",""); id="r_td_'+day_counter+'">';
							calendar_html += '<td class="n_available" '+ onclickval + day_counter + '</td>';
						/*}*/
					}
					else
					{
						var onclickval='onclick=javascript:r_select_date("'+year+'","'+(parseInt(month)+1)+'","'+day_counter+'"); id="r_td_'+day_counter+'">';

						calendar_html += '<td class="n_available" '+ onclickval + day_counter + '</td>';
					}
					flag_r=1;
				}
				else
				{
					calendar_html += '<td class="n">' + day_counter + '</td>';
				}
			}
			else
			{
				calendar_html += '<td class="n">' + day_counter + '</td>';
			}
}

    week_day++;
}

  calendar_html += '</tr>';
  calendar_html += '</table>';

  // Display the calendar.
  //document.write(calendar_html);
document.getElementById(sel_div).innerHTML=calendar_html;

//alert(nub_of_disp_date_cnt+" / "+dg_array.length);
if(nub_of_disp_date_cnt>0 && nub_of_disp_date_cnt<dg_array.length)
{
	//alert("return date at next moth remaining");
	var sel_dgs_rem_for_next_mon="";
	for(sel_dgs_remi=nub_of_disp_date_cnt;sel_dgs_remi<dg_array.length;sel_dgs_remi++)
	{
		var col_sel_dgs_rem_for_next_mon=dg_array[sel_dgs_remi];
		if(sel_dgs_remi!=dg_array.length-1)
		{
			sel_dgs_rem_for_next_mon+=col_sel_dgs_rem_for_next_mon+',';
		}
		else
		{
			sel_dgs_rem_for_next_mon+=col_sel_dgs_rem_for_next_mon;
		}
	}
	//alert(sel_dgs_rem_for_next_mon);
	var str_for_next=y1+','+m1+','+day_counter_req;

	document.getElementById("r_r_nav").innerHTML='<span class="caltext" style="cursor:pointer;" title="neste" onclick=javascript:calendar2("'+str_for_next+'","cal_div2","'+day_counter_req+'","'+sel_dgs_rem_for_next_mon+'");call_r_l_nav();>>></span>';
}
//alert(flag_r);
if(flag_r!=1)
{
	var day_cnt_rem=days_in_this_month-day_counter_req;
	//alert(day_cnt_rem);
	//alert(sel_dgs);
	var sel_dgs_new="";
	var spl_sel_dgs_new=sel_dgs.split(',');
	for(spl_sel_dgs_newi=0;spl_sel_dgs_newi<spl_sel_dgs_new.length;spl_sel_dgs_newi++)
	{
		if(spl_sel_dgs_newi!=spl_sel_dgs_new.length-1)
		{
			sel_dgs_new+=(spl_sel_dgs_new[spl_sel_dgs_newi]-day_cnt_rem)+",";
		}
		else
		{
			sel_dgs_new+=(spl_sel_dgs_new[spl_sel_dgs_newi]-day_cnt_rem);
		}
	}
	var mon=parseInt(month)+2;
	if(mon==13){mon=1;year+=1;}

	var date_val=year+","+mon+","+"1";
	//alert(sel_dgs_new);
	if(parseInt(sel_dgs_new)>0)
	{
		//alert(sel_dgs_new);
		calendar2(date_val,"cal_div2","0",sel_dgs_new);
	}
}

}


//global variables for calendar 3 and 4............................
//alert(mydafault_dg);
/*
if(mydafault_dg==0)
{
	var dafault_dg=2;
}
else
{
	//var dafault_dg=mydafault_dg;
	var dafault_dg=0;
}
*/
//alert(dafault_dg);
var dafault_dg=2;
var max_option_val='';
var max_count_month=12;

function calendar3(date,sel_div,day_counter_req,sel_dgs) {

//var default_day_counter_req=-1;     //it should be (1-default_dg)
// If no parameter is passed use the current date.
//alert(date+","+sel_div+","+day_counter_req+","+sel_dgs);
/*if(date=='')
{
document.getElementById("dato1").value="Avresedato";
}*/
document.getElementById("Nights").value="0";
document.getElementById("dg_msg1").innerHTML="";
//alert(depname+destname);

if(day_counter_req=="")
{
document.getElementById("dato1").value="Avresedato";
document.getElementById("g_h_id1").value='';
}

if(document.getElementById("dato1").value=="Avresedato")
{
	document.getElementById("UtreiseDay1").value="UtreiseDato";
}

//data for date ddl , g_left_nav and g_right_nav collection start...........................................................................................

//for specific month-year.................................................................

//data for date ddl , g_left_nav and g_right_nav collection end.......................................................................................................

//alert(date);
//alert(first_t_date_o);
//date11=new Date();
date11=myServerdate;
 day11 = date11.getDate();
 month11 = date11.getMonth();
 year11 = date11.getFullYear();

if(date == "")
{
	//date=new Date();
	date=myServerdate;
}
else
{
	var split_date=date.split(",");
	y1=split_date[0];m1=split_date[1];d1=split_date[2];
	date=new Date(y1,m1,d1);
}
//alert(date);
  day = date.getDate();
  month = date.getMonth();
  year = date.getFullYear();

//alert(day+","+month+","+year);

var date_option_val='<select name="ddl_date1" id="ddl_date1" class="textbox" style="-moz-border-radius: 3px;-webkit-border-radius:3px;-khtml-border-radius: 3px;border-radius: 3px 3px 3px 3px;" onchange=javascript:calendar3(this.value,"cal_div_hotel1","","");calendar4("ddl_date_change1","cal_div_hotel2","1","'+dafault_dg+'");>';
var ddlyi=year11;
var count_month=0;
//alert(year+","+month+",1");
for(var ddlmi=month11;;ddlmi++)
{
	if(ddlmi==12)
	{
		ddlmi=0;
		ddlyi++;
	}
	if(count_month > max_count_month)
		break;

	var my_date_option_val=ddlyi+","+ddlmi+",1";
	//if(ddlmi==month && ddlyi==year)
	if(my_date_option_val==year+","+month+",1")
	{
		date_option_val+='<option value="'+my_date_option_val+'" selected>'+months[ddlmi]+' '+ddlyi+'</option>';
	}
	else
	{
		date_option_val+='<option value="'+my_date_option_val+'">'+months[ddlmi]+' '+ddlyi+'</option>';
	}
max_option_val=my_date_option_val;
count_month++;
}
date_option_val+='</select>';
//alert(max_option_val);
var right_nav_val="";
var left_nav_val="";

if(month == month11 && year==year11)
{
	var month_next=parseInt(month)+1;
	var year_next=year;
	if(month_next==12)
	{
		month_next=0;
		year_next=parseInt(year_next)+1;
	}
	right_nav_val='<span class="caltext" style="cursor:pointer;" title="neste" onclick=javascript:calendar3("'+year_next+','+month_next+',1","cal_div_hotel1","","");calendar4("'+year_next+','+month_next+',1","cal_div_hotel2","1","'+dafault_dg+'");>>></span>';
	left_nav_val='';
}
else
{
	var month_next=parseInt(month)+1;
	var year_next=year;
	var month_prev=parseInt(month)-1;
	var year_prev=year;
	if(month_next==12)
	{
		month_next=0;
		year_next=parseInt(year_next)+1;
	}
	if(month_prev==0)
	{
		month_prev=12;
		year_prev=parseInt(year_prev)-1;
	}
	if(year+','+month+',1' == max_option_val)
	{
		right_nav_val='';
	}
	else
	{
		right_nav_val='<span class="caltext" style="cursor:pointer;" title="neste" onclick=javascript:calendar3("'+year_next+','+month_next+',1","cal_div_hotel1","","");calendar4("'+year_next+','+month_next+',1","cal_div_hotel2","1","'+dafault_dg+'");>>></span>';
	}
	left_nav_val='<span class="caltext" style="cursor:pointer;" title="tidligere" onclick=javascript:calendar3("'+year_prev+','+month_prev+',1","cal_div_hotel1","","");calendar4("'+year_prev+','+month_prev+',1","cal_div_hotel2","1","'+dafault_dg+'");><<</span>';
}

  this_month = new Date(year, month, 1);
  next_month = new Date(year, month + 1, 1);
//alert(this_month.getDay());
  // Find out when this month starts and ends.
  first_week_day = this_month.getDay()-1;
if(first_week_day==-1)
{
	first_week_day=6;
}
  days_in_this_month = Math.round((next_month.getTime() - this_month.getTime()) / (1000 * 60 * 60 * 24));
//alert(first_week_day);
  calendar_html = '<table cellpadding="0" cellspacing="2" class="cal_table">';
  //calendar_html += '<tr align="center" height="22px" class="cal_header"><td colspan="7">UtreiseDato Kalender</td></tr>';
  calendar_html += '<tr align="center" height="22px" class="cal_nav"><td id="g_laft_nav3"></td><td colspan="5"><span id="date_span1"></span></td><td id="g_right_nav3"></td></tr>';
  calendar_html += week_day_header;
  calendar_html += '<tr align="center">';
//alert(first_week_day);
  // Fill the first week of the month with the appropriate number of blanks.
  for(week_day = 0; week_day < first_week_day; week_day++)
{
    calendar_html += '<td></td>';
}

  week_day = first_week_day;
//var x=parseInt(days_in_this_month)-parseInt(dafault_dg);
//alert(x);
for(day_counter = 1; day_counter <= days_in_this_month; day_counter++)
{
    week_day %= 7;
    if(week_day == 0)
      calendar_html += '</tr><tr align="center">';

			var chkDay=parseInt(day_counter);
			var chkMon=month;

			var str=year+","+chkMon+","+chkDay;
			//alert(str);
/*
			var sel_date=new Date(str);
			//var my_sel_date=sel_date.setFullYear(year+","+chkMon+","+(parseInt(chkDay)+parseInt(dafault_dg)));
			var my_sel_date = new Date(sel_date.setDate(sel_date.getDate()+dafault_dg-2));
			//alert(my_sel_date);
			var my_sel_year=my_sel_date.getFullYear();
			var my_sel_month=my_sel_date.getMonth()+1;
			var my_sel_date=my_sel_date.getDate();
			var str1=my_sel_year+","+my_sel_month+","+my_sel_date;
*/
				if(month == month11 && year==year11)
				{
					if(day_counter < day11)
					{
						calendar_html += '<td class="n">' + day_counter + '</td>';
					}
					else
					{

						/*if(day_counter> x)
						{
							var y=parseInt(day_counter)-parseInt(x);
							var day_counter1=y-dafault_dg;
						}
						else
						{
							var day_counter1=day_counter;
						}*/

						var onclickval='onclick=calendar4("' +str+ '","cal_div_hotel2","' + day_counter + '","'+dafault_dg+'");g_select_date1("'+year+'","'+(parseInt(month)+1)+'","'+day_counter+'"); id="g_td1_'+day_counter+'">';
						//var onclickval='onclick=calendar4("' +str1+ '","cal_div_hotel2","' + my_sel_date + '","'+dafault_dg+'");g_select_date1("'+year+'","'+(parseInt(month)+1)+'","'+day_counter+'"); id="g_td1_'+day_counter+'">';
						calendar_html += '<td class="n_available" ' + onclickval + day_counter + '</td>';
					}
				}
				else
				{
						/*if(day_counter> x)
						{
							var y=parseInt(day_counter)-parseInt(x);
							var day_counter1=y-dafault_dg;
						}
						else
						{
							var day_counter1=day_counter;
						}*/

						var onclickval='onclick=calendar4("' +str+ '","cal_div_hotel2","' + day_counter + '","'+dafault_dg+'");g_select_date1("'+year+'","'+(parseInt(month)+1)+'","'+day_counter+'"); id="g_td1_'+day_counter+'">';
						//var onclickval='onclick=calendar4("' +str1+ '","cal_div_hotel2","' + my_sel_date + '","'+dafault_dg+'");g_select_date1("'+year+'","'+(parseInt(month)+1)+'","'+day_counter+'"); id="g_td1_'+day_counter+'">';
					calendar_html += '<td class="n_available" ' + onclickval + day_counter + '</td>';
				}




    week_day++;
}

  calendar_html += '</tr>';
  calendar_html += '</table>';

  // Display the calendar.
  //document.write(calendar_html);
//alert(sel_div);
document.getElementById(sel_div).innerHTML=calendar_html;

document.getElementById("date_span1").innerHTML=date_option_val;
document.getElementById("g_right_nav3").innerHTML=right_nav_val;
document.getElementById("g_laft_nav3").innerHTML=left_nav_val;
}

function calendar4(date,sel_div,day_counter_req,sel_dgs) {
//alert(sel_dgs);
 var date_my_chk_array=date.split(",");
  // If no parameter is passed use the current date.
  //alert(date+","+sel_div+","+day_counter_req+","+sel_dgs);
if(date=="ddl_date_change1")
{
	date=document.getElementById("ddl_date1").value;
}
/*if(date=='')
{
document.getElementById("dato1").value="Avresedato";
}*/
document.getElementById("Nights").value="0";
document.getElementById("dg_msg1").innerHTML='';
document.getElementById("r_h_id1").value='';
//alert(depname+destname);

if(day_counter_req=="")
{
document.getElementById("dato1").value="Avresedato";
//document.getElementById("r_h_id1").value='';
}
/*
if(date=='')
{
	document.getElementById("UtreiseDay1").value="UtreiseDato";
}
*/
//data for date ddl , g_left_nav and g_right_nav collection start...........................................................................................

//for specific month-year.................................................................

//data for date ddl , g_left_nav and g_right_nav collection end.......................................................................................................

//alert(date);
//alert(first_t_date_o);
//date11=new Date();
date11=myServerdate;
 day11 = date11.getDate();
 month11 = date11.getMonth();
 year11 = date11.getFullYear();


if(date == "")
{
	//date=new Date();
	date=myServerdate;
}
else
{
	var split_date=date.split(",");
	y1=split_date[0];m1=split_date[1];d1=split_date[2];
	date=new Date(y1,m1,d1);
}

  day = date.getDate();
  month = date.getMonth();
  year = date.getFullYear();

//alert(day+","+month+","+year);

var right_nav_val="";
var left_nav_val="";
if(month == month11 && year==year11)
{
	var month_next=parseInt(month)+1;
	var year_next=year;
	if(month_next==12)
	{
		month_next=0;
		year_next=parseInt(year_next)+1;
	}
	right_nav_val='<span class="caltext" style="cursor:pointer;" title="neste" onclick=javascript:calendar4("'+year_next+','+month_next+',1","cal_div_hotel2","-1","");>>></span>';
	left_nav_val='';

}
else
{
	var month_next=parseInt(month)+1;
	var year_next=year;
	var month_prev=parseInt(month)-1;
	var year_prev=year;
	if(month_next==12)
	{
		month_next=0;
		year_next=parseInt(year_next)+1;
	}
	if(month_prev==0)
	{
		month_prev=12;
		year_prev=parseInt(year_prev)-1;
	}
	if(year+','+month+',1' == max_option_val)
	{
		right_nav_val='';
	}
	else
	{
		right_nav_val='<span class="caltext" style="cursor:pointer;" title="neste" onclick=javascript:calendar4("'+year_next+','+month_next+',1","cal_div_hotel2","-1","");>>></span>';
	}
	var my_chk_val_array=document.getElementById("ddl_date1").value.split(",");

	//alert(date_my_chk_array[0]+date_my_chk_array[1]+"=="+my_chk_val_array[0]+my_chk_val_array[1]);

	if(date_my_chk_array[0]+date_my_chk_array[1]==my_chk_val_array[0]+my_chk_val_array[1])
	{
		left_nav_val='';
	}
	else
	{
		left_nav_val='<span class="caltext" style="cursor:pointer;" title="tidligere" onclick=javascript:calendar4("'+year_prev+','+month_prev+',1","cal_div_hotel2","-1","");><<</span>';
	}
}

  this_month = new Date(year, month, 1);
  next_month = new Date(year, month + 1, 1);
//alert(this_month.getDay());
  // Find out when this month starts and ends.
  first_week_day = this_month.getDay()-1;
if(first_week_day==-1)
{
	first_week_day=6;
}
  days_in_this_month = Math.round((next_month.getTime() - this_month.getTime()) / (1000 * 60 * 60 * 24));
//alert(first_week_day);

  calendar_html = '<table cellpadding="0" cellspacing="2" class="cal_table">';
  //calendar_html += '<tr align="center" height="22px" class="cal_header"><td colspan="7">UtreiseDato Kalender</td></tr>';
  calendar_html += '<tr align="center" height="22px" class="cal_nav"><td id="r_laft_nav3"></td><td colspan="5">' + months[month] + ' ' + year + '</td><td id="r_right_nav3"></td></tr>';
  calendar_html += week_day_header;
  calendar_html += '<tr align="center">';
//alert(first_week_day);
  // Fill the first week of the month with the appropriate number of blanks.
  for(week_day = 0; week_day < first_week_day; week_day++)
{
    calendar_html += '<td></td>';
}

  week_day = first_week_day;
//alert(day_counter_req+"="+month+"=="+month11);
				if(day_counter_req=='' && month==month11 && year==year11)
				{
					day11=parseInt(day11)+parseInt(dafault_dg);
				}
				else if(day_counter_req=='' && month!=month11 && year==year11)
				{
					day11=dafault_dg;
				}
				else if(day_counter_req=='-1' && month==month11 && year==year11)
				{
					day11=parseInt(day11)+parseInt(dafault_dg);
				}
				else if(day_counter_req=='-1' && month!=month11 && year==year11)
				{
					day11=1;
				}
				else
				{
					day11=parseInt(day_counter_req)+parseInt(dafault_dg);
				}

//alert(day11);

for(day_counter = 1; day_counter <= days_in_this_month; day_counter++)
{
    week_day %= 7;
    if(week_day == 0)
      calendar_html += '</tr><tr align="center">';

			//var chkDay=day_counter;
			//var chkMon=month+1;

			//var str=year+","+chkMon+","+chkDay;
			//alert(str);

/*
				if(month == month11 && year==year11)
				{*/
					if(day_counter < day11)
					{
						calendar_html += '<td class="n">' + day_counter + '</td>';
					}
					else
					{
						var onclickval='onclick=r_select_date1("'+year+'","'+(parseInt(month)+1)+'","'+day_counter+'"); id="r_td1_'+day_counter+'">';
						calendar_html += '<td class="n_available" ' + onclickval + day_counter + '</td>';
					}
				/*}
				else
				{
						var onclickval='onclick=r_select_date1("'+year+'","'+(parseInt(month)+1)+'","'+day_counter+'"); id="r_td1_'+day_counter+'">';
					calendar_html += '<td class="n_available" ' + onclickval + day_counter + '</td>';
				}*/




    week_day++;
}

  calendar_html += '</tr>';
  calendar_html += '</table>';

  // Display the calendar.
  //document.write(calendar_html);
//alert(sel_div);
document.getElementById(sel_div).innerHTML=calendar_html;

//document.getElementById("date_span").innerHTML=date_option_val;
document.getElementById("r_right_nav3").innerHTML=right_nav_val;
document.getElementById("r_laft_nav3").innerHTML=left_nav_val;
}

function call_dep(page)
{
if(page=="search_page")
	var dep_option_val='<select id="fra" name="fra" class="textbox" style="width:170px;cursor: pointer;" onchange="javascript:call_dest(this.value,\'search_page\');document.getElementById(\'dager\').value=\'0\';document.getElementById(\'cal_div1\').innerHTML=\'<font color=#3399CC>Velg destinasjon for tilgjengelighet</font>\';document.getElementById(\'cal_div2\').innerHTML=\'\';document.getElementById(\'dg_msg\').innerHTML=\'\';"><option style="padding-bottom: 3px;font-weight: bold;font-style:italic;" value="0">Avreise fra</option>';
else
	var dep_option_val='<select id="fra" name="fra" class="textbox" style="width:170px;cursor: pointer;" onchange="javascript:call_dest(this.value);document.getElementById(\'dato\').value=\'Avreisedato\';document.getElementById(\'dager\').value=\'0\';document.getElementById(\'cal_span\').style.display=\'none\';toggle_cnt_func();"><option style="padding-bottom: 3px;font-weight: bold;font-style:italic;" value="0">Avreise fra</option>';

for(var depi=0;depi<allDepArray.length;depi++)
{
	var d_option_val=allDepArray[depi];
	var de_option_val=d_option_val.split(',');
	var dep_code_o=de_option_val[0];
	var dep_name_o=de_option_val[1];
	dep_option_val+='<option value="'+dep_code_o+'">&nbsp;&nbsp;'+dep_name_o+'</option>';
}
dep_option_val+='</select>';
//alert(dep_option_val);
document.getElementById("dep_span").innerHTML=dep_option_val;
}

function call_dest(departure_value,page)
{
document.getElementById("UtreiseDay").value='';
document.getElementById("ReturDay").value='';

var option_array=Array();

for(var desti=0;desti<DepDestArray.length;desti++)
{
	var t_option_val=DepDestArray[desti];
	var depdest_option_val=t_option_val.split(':');
	var dep_code_o=depdest_option_val[0];

	if(dep_code_o==departure_value)
	{
		var dest_code_name_o=depdest_option_val[1];
		var t_dest_code_name_o=dest_code_name_o.split(';');
		for(var pi=0;pi<t_dest_code_name_o.length;pi++)
		{
			var my_dest_code_name=t_dest_code_name_o[pi];
			var spli_my_dest_code_name=my_dest_code_name.split('.');
			var dest_code_o=spli_my_dest_code_name[0];
			var dest_name_o=spli_my_dest_code_name[1];
			var country_name_o=spli_my_dest_code_name[3];

			var str=country_name_o+'-'+dest_name_o+'-'+dest_code_o;
			option_array.push(str);
			//dest_option_val+='<option value="'+dest_code_o+'">'+country_name_o+'-'+dest_name_o+'</option>';
		}
	}
}

option_array.sort();

if(page=="search_page")
	var dest_option_val='<select id="til" name="til" class="textbox" style="width:170px;cursor: pointer;" onchange=\'call_calendars();document.getElementById("dager").value="0";\'>';
else
	var dest_option_val='<select id="til" name="til" class="textbox" style="width:170px;cursor: pointer;" onchange=document.getElementById(\'dato\').value=\'Avreisedato\';document.getElementById(\'dager\').value=\'0\';document.getElementById(\'cal_span\').style.display=\'none\';toggle_cnt_func();>';

if(departure_value=="AES")
{
	dest_option_val+='<option style="padding-bottom: 3px;font-weight: bold;font-style:italic;" value="0">Mest søkte reisemål</option><option value="AYT">&nbsp;&nbsp;Tyrkia-Antalya,Alanya,Kemer,Side,Belek</option><option value="CHQ">&nbsp;&nbsp;Hellas-Kreta Chania</option><option value="RHO">&nbsp;&nbsp;Hellas-Rhodos</option><option value="PMI">&nbsp;&nbsp;Spania-Mallorca</option><option value="LPA" style="padding-bottom: 3px;">&nbsp;&nbsp;Spania-Gran Canaria</option>';
}
else if(departure_value=="BGO")
{
	dest_option_val+='<option style="padding-bottom: 3px;font-weight: bold;font-style:italic;" value="0">Mest søkte reisemål</option><option value="AYT">&nbsp;&nbsp;Tyrkia-Antalya,Alanya,Kemer,Side,Belek</option><option value="CHQ">&nbsp;&nbsp;Hellas-Kreta Chania</option><option value="RHO">&nbsp;&nbsp;Hellas-Rhodos</option><option value="PMI">&nbsp;&nbsp;Spania-Mallorca</option><option value="LPA">&nbsp;&nbsp;Spania-Gran Canaria</option><option value="SSH" style="padding-bottom: 3px;">&nbsp;&nbsp;Egypt-Sharm El Sheik</option>';
}
else if(departure_value=="OSL")
{
	dest_option_val+='<option style="padding-bottom: 3px;font-weight: bold;font-style:italic;" value="0">Mest søkte reisemål</option><option value="AYT">&nbsp;&nbsp;Tyrkia-Antalya,Alanya,Kemer,Side,Belek</option><option value="CHQ">&nbsp;&nbsp;Hellas-Kreta Chania</option><option value="HER">&nbsp;&nbsp;Hellas-Kreta Heraklion</option><option value="RHO">&nbsp;&nbsp;Hellas-Rhodos</option><option value="PMI">&nbsp;&nbsp;Spania-Mallorca</option><option value="LPA">&nbsp;&nbsp;Spania-Gran Canaria</option><option value="SSH" style="padding-bottom: 3px;">&nbsp;&nbsp;Egypt-Sharm El Sheik</option>';
}

dest_option_val+='<option style="padding-bottom: 3px;font-weight: bold;font-style:italic;" value="0">Alle reisemål</option>';

var option_group_val1="";
var option_group_val2="";
for(var oi=0;oi<option_array.length;oi++)
{
	//alert("came");
	var ind_option_array=option_array[oi].split('-');

	option_group_val2=ind_option_array[0];
	if(option_group_val2!=option_group_val1)
	{
		dest_option_val+='<optgroup style="background-color: #5AADAD;color: #000000;padding-top: 5px;padding-bottom: 3px;" label="'+option_group_val2+'"></optgroup>';
	}
	dest_option_val+='<option value="'+ind_option_array[2]+'">&nbsp;&nbsp;'+ind_option_array[1]+'</option>';
	option_group_val1=ind_option_array[0];
}
dest_option_val+='</select>';
//alert(dest_option_val);
document.getElementById("dest_span").innerHTML=dest_option_val;

}
