// $Id: hacks.js 2199 2009-10-27 07:57:02Z dhh $
//

var dest_first_page;
var curPerson_tostring = '';
var FIXME_readiness;
var loginIEhack = 1;
var loginIEhackD = 1;
var currentFloorPlan = false;
var currentDestPage = false;
var my_details_location = false;
var fader_big;
var search_is_dirty = false;
var dlg; // YAHOO dialog window
var listMenu = false;


var Holidays = new Array;


T['message_control'] = 1;
T['contacts'] = new Array();

var tv_width = "210px";
var fp_width = 616;
var fp_height = 344;
var pct = "25%";
if (document.all){
	pct = "33%";
}


function destination_minimenu (){
	var place = ge('d_minimenu');
	var h = '';
	if (place){
		h += place.innerHTML;

		var lft = '170';
		if(CM.object_id) {
			lft = '153';
		}
		h += '<div id="dmm" style="width:'+ lft +'px;"></div>';
	} else {
		h= "<hr>minimenu supposed to be here but was not found in DOM. Bad luck.";
	}
	return h;
}

function hide (id){
	var obj = ge(id);
	if (obj){
		obj.style.display='none';
	} else {
		alert('hacks::hide: object ' + id + ' not found!');
	}
}

function unify_table (tab_id){
	var t = ge(tab_id);
	if(t){
		t.width="100%";
		t.cellPadding="0";
		t.cellSpacing="0";
		t.border="0";
	}
	
}


function replace_propaganda_image (div_id){
	var img_td = ge('Propaganda_Propaganda::image');
	var ext_div = ge(div_id).cloneNode(true);
	reset_ss();
	paint_image_caption();
	img_td.removeChild(img_td.firstChild);
	img_td.appendChild(ext_div);
}


function init_for_map () {

	junk = ge('Propaganda_Propaganda::heading::curlang');
	junk.style.display = 'none';
	junk = ge('Propaganda_Propaganda::content::curlang');
	junk.className = 'gchd';
	junk.innerHTML = '';
	junk = ge('external_form');
	if(junk){
		junk.style.display = 'none';
	}
}



function restore_propaganda_td () {

	junk = ge('Propaganda_Propaganda::heading::curlang');
	if(junk) {
		junk.style.display = '';
	}
	junk = ge('Propaganda_Propaganda::content::curlang');
	if(junk) {
		junk.className = 'greycontent';
	}
	
	zap_if(ge('Destination_list'));
	zap_if(ge('external_extra'));
		
	var ef_td = ge('external_form');
	if(ef_td){
		ef_td.style.display = '';
		ef_td.style.height = '0px';
	} else {
		var prop_tab = ge('Propaganda_tab');
		var tr = prop_tab.insertRow(4);
		ef_td = tr.insertCell(0);
		ef_td.id = 'external_form';
		ef_td.className = 'justgrey';
		ef_td.colSpan="2";
	}
	
}

function replace_propaganda_image2gmap (div_id){
	var img_td = ge('Propaganda_Propaganda::image');
	reset_ss();
	paint_image_caption();
	rename_me_asap_later(div_id, img_td);
	loadGMap('world');
}

function replace_destination_image2gmap (div_id){
	var img_td = ge('Destination_Destination::area_info::image');
	reset_ss();
	paint_image_caption();
	rename_me_asap_later(div_id, img_td);
	loadGMap('point');
}

function replace_destination_image2book (){
	var img_td = ge('Destination_Destination::area_info::image');
	reset_ss();
	paint_image_caption();
	img_td.removeChild(img_td.firstChild);
	var ext_div = ge('bookings_template').cloneNode(true);
	ext_div.id = 'bookings_place';
	img_td.appendChild(ext_div);
	img_td.style.verticalAlign='top';

}

function rename_me_asap_later(div_id, img_td){
	var ext_div = ge(div_id).cloneNode(true);
	ext_div.id = 'map_google';
	var candidates = ext_div.getElementsByTagName("div");
	var wherefrom = img_td.id;
	var renamed = 0;
	var removed = 0;
	var to_remove;
	for (var i=0; i<candidates.length; i++){
		if (!candidates[i].id){
			continue;
		}
		if (candidates[i].id == 'gmap_template'){
			candidates[i].id = 'gmap';
			renamed = 1;
		}
		if (candidates[i].id == 'legend'){
			to_remove = i;
			removed = 1;
		}
		if (candidates[i].id == 'map_filter_type'){
			candidates[i].id = 'map_filter_type_';
			renamed = 1;
		}
		if (candidates[i].id == 'map_filter_av'){
			candidates[i].id = 'map_filter_av_';
			renamed = 1;
		}

		if (removed && renamed){
			break;
		}
	}
	if (wherefrom == 'Destination_Destination::area_info::image' && removed){
		zap(candidates[to_remove]);
	}
	
	img_td.removeChild(img_td.firstChild);
	img_td.appendChild(ext_div);

	var ext_div = ge('map_filter_av_');
	var candidates = ext_div.getElementsByTagName("input");
	for (var i=0; i<candidates.length; i++){
		if (!candidates[i].id){
			continue;
		}
		if(candidates[i].id.indexOf('ch_') != -1) {
			candidates[i].id = '_'+candidates[i].id;
		}
	}

	var ext_div = ge('map_filter_type_');
	var candidates = ext_div.getElementsByTagName("input");
	for (var i=0; i<candidates.length; i++){
		if (!candidates[i].id){
			continue;
		}
		if(candidates[i].id.indexOf('ch_') != -1) {
			candidates[i].id = '_'+candidates[i].id;
		}
	}

	
}

function restore_propaganda_image () {
	var img_td = ge('Propaganda_Propaganda::image');
	reset_ss();
	paint_image_caption();

	if (img_td.firstChild.nodeName != 'IMG'){
		img_td.removeChild(img_td.firstChild);
		var img = ce("IMG");
		img_td.appendChild(img);
	}
}

function restore_destination_image () {
	var img_td = ge('Destination_Destination::area_info::image');
	reset_ss();
	paint_image_caption();
	if (img_td && img_td.firstChild.nodeName != 'IMG'){
		img_td.removeChild(img_td.firstChild);
		var img = ce("IMG");
		img.style.display = 'block';
		img_td.appendChild(img);
	}
}


function make_ef_td(){
	var ef_td = ge('external_form');
	if (ef_td){
		if (ef_td.firstChild){
			var mtmp = ef_td.firstChild;
			ge('attic').appendChild(mtmp);
		}
	} else {
		var prop_tab = ge(target_id);
		var tr = prop_tab.insertRow(prop_tab.rows.length-1);
		ef_td = tr.insertCell(0);
		ef_td.id = 'external_form';
	}
	ef_td.className ='greycontent';
	ef_td.style.display = '';
	return ef_td;
}

function append_extra_to_std_form (extra_id, target_id){
	var ef_td = make_ef_td();

	if (extra_id == 'RegionDHH_list') {
		hidepcc();
		ef_td.innerHTML = '';
	} else if (extra_id == 'search_form') {
		hidepcc();
		ef_td.innerHTML = '';
		toggleAllRegions();
	} else if (extra_id == 'DestinationType_list') {
		hidepcc();
		var rows = getElementsByAttribute(ge(extra_id), 'att', 'list_link','li');
		for (var r = 0; rows.length > r; r++){
			rows[r].setAttribute('style','font-weight:normal;'); 
		}
	} else if (extra_id == 'faq_custom_faq') {
		hidepcc();
	} else if( extra_id == 'faq_custom_contact') {
		hidepcc();
	} else if (extra_id == 'faq_custom_diff') {
		hidepcc();
	} else if (extra_id == 'faq_custom_matters') {
		hidepcc();
	} else if (extra_id == 'InfoRequest' || extra_id == 'UsingTheClub' || extra_id == 'TellAFriend') {
		translate_form_bits(extra_id);
	}


	hideUnwantedFields(extra_id);
		
	var frm = ge(extra_id);
	if(!frm){		
		ef_td.innerHTML = jssm['hacks']['loading_form'];
		var r = new Object;
		r.typ = 'form';
		if (extra_id.indexOf('faq') == -1){
			r.params = 'w=gforms';
		} else {
			r.params = 'w=gtext';
		}
		r.clas = extra_id;
		current_page_ext_form['id'] = extra_id;		
		form_requests.push(r);
		try_count[extra_id] = 0;
		//checkFormArrived(extra_id);
	} else {
		ef_td.appendChild(frm);
		init_edit();
		return true;
	}

}

function translate_form_bits (frm){
	var email_dd = ge('IRCM_rr');
	if (email_dd){
		for (var i=0; i<email_dd.options.length; i++){
			if (email_dd.options[i].value == 'email'){
				email_dd.options[i].text = jssm.Forms.send_email;
			} else {
				email_dd.options[i].text = jssm.Forms.send_post;
			}
		}
	}
	var half_dd = ge('IR_half');
	if (half_dd){
		for (var i=0; i<half_dd.options.length; i++){
			if (half_dd.options[i].value == 'am'){
				half_dd.options[i].text = jssm.Forms.am;
			} else {
				half_dd.options[i].text = jssm.Forms.pm;
			}
		}
	}
}





function hidepcc(){
	var t = ge('Propaganda_Propaganda::content::curlang');
	t.innerHTML = '';
	t.className = 'gchd';

}

function append_extra_data_to_std_form (target_id, data){

	var ef_td = ge('external_data_'+target_id);
	if (ef_td){

	} else {
		var prop_tab = ge(target_id);
		var tr = prop_tab.insertRow(prop_tab.rows.length-1);
		ef_td = tr.insertCell(0);
		ef_td.id = 'external_data_'+target_id;
		ef_td.colSpan = "2";
//		ef_td.height="150px";
//		ef_td.style.verticalAlign="top";
	}

	ef_td.innerHTML = data;
	ef_td.className ='greycontent';
}


function append_form_to_propaganda (frm_id){
	return append_extra_to_std_form (frm_id, 'Propaganda_tab');
}



function remove_appended_form (){
	current_page_ext_form = new Array();
	
	var ef_td = ge('external_form');
	if (ef_td){
		if (ef_td.firstChild){
			ge('attic').appendChild(ef_td.firstChild);
		}
	}
}











// minimenu functions


var allThumbs = Array();
var allFloorplans = Array();
var allTopImages = Array();
var allAreaImages = Array();
var current_thumb = 0;
var current_show = 0;
var hcurrent_show = 1;
var show_active = 0;


function changeTopImage() {

	var newImg = ge('Destination_Destination::layout_image').firstChild;
	var oldImg = ge('Destination_Destination::area_info::image').firstChild;
	if(fader_big == 0) {
		create_fader(allTopImages[current_thumb]);
	}
	fader_big.changeImage(fader_big,allTopImages[current_thumb]);

}

var dest_img;
var now_at_location;
var launch_date;
var closure_date;

function init_now_at_location (dest){
	var lc = dest.now_at_location.local_c;
	now_at_location = new Date(Date.UTC(lc.year,lc.month-1,lc.day));
}

function init_destination (obj) {

	init_now_at_location(obj);

	var ld = obj.launch_date.local_c;
	launch_date = new Date(Date.UTC(ld.year,ld.month-1,ld.day));	
	var cld = obj.closure_date.local_c;
	closure_date = new Date(Date.UTC(cld.year,cld.month-1,cld.day));	
	FIXME_readiness = obj.readiness.code;
	reset_ss();
	paint_image_caption();
	current_thumb = 0;
	fader = 0;
	fader_big = 0;
	allThumbs = Array();
	allTopImages = Array();
	allAreaImages = Array();
	allFloorplans = Array();
	if (currentDestPage){
		ge('l_'+currentDestPage).className = 'subnav3';
		currentDestPage=false;
	}

	next_cached_dest_image ();
	
	ainfo_img = ge('Destination_Destination::area_info::image').firstChild.src;
	ainfo_img_obj = fix_old_image(ge('Destination_Destination::area_info::image').firstChild);
	ainfo_img_obj.id = 'big_image_fader';
	ainfo_img_obj.style.display = 'block';
	
	area_html = ge('Destination_Destination::area_info::info::curlang').innerHTML;
	overview_html = ge('Destination_Destination::overview::info::curlang').innerHTML;

	dest_name = obj.name.curlang;
	dest_street_name = obj.street_name.curlang;
	
	tv_set = dest_first_page;
	

	var e_img = new Object;
	e_img.src = obj.overview.image;
	e_img.caption = obj.caption_overview_image.curlang;
	set_images_and_thumbs(e_img);
	set_area_images(obj);
	dest_img = obj.overview.image.src;

	if(obj.more_images){
		for (var i =0; i<obj.more_images.length; i++){
			set_images_and_thumbs(obj.more_images[i]);
		}
	}

	if(obj.fp_images){
		ge('l_floorplan').style.display = '';		
		for (var i=0; i<obj.fp_images.length; i++){
				allFloorplans.push('/images/'+obj.fp_images[i].src);
		}
	} else {
		ge('l_floorplan').style.display = 'none';
	}

	if (obj.is_mobile.yn == 'N'){
		ge('l_schedule').style.display = 'none';		
	} else {
		ge('l_schedule').style.display = '';		
	}


	var booking = getCookie('booking');
	if (booking){
		click_on_smenu('book');
		SetCookie('booking','',-1);
	} else {
		var frommap = getCookie('frommap');
		if (frommap){
			SetCookie('frommap','',-1);
			if(allThumbs.length > 1) {
				current_thumb = 1;
			} else {
				current_thumb = 0;
			}
			click_on_smenu('overview');
		} else {
			click_on_smenu('overview');
		}
	}

		
	
	tv_set = ge('d_tv').innerHTML;

	if (booking){
		if (ge('telek')){
			ge('telek').style.display='none';
		}
	} else {
		if(allThumbs.length <= 1) {
			ge('telek').style.display='none';
		} else {
			ge('telek').style.display='';
		}
	}

	var dmm = ge('dmm');
	dmm.innerHTML = list_all_destinations();

	var lb = ge('l_book');
	if (lb){
		if (FIXME_readiness != 'active'){
			lb.style.display='none';
		} else {
			lb.style.display='';
		}
	}
	var d_add = ge('dinfo_add');
	var d_add_html = "<b>Occupancy for this Property is " +obj.enhanced.occupancies[0].capacity+ " guests</b>.";
	if (obj.discount_class.val != 1){
		d_add_html += "<br/><br/><b>Cost for this Property is "+Math.round(7*obj.discount_class.val)+" Membership Days for 7 nights stay.";
	}
	d_add.innerHTML = d_add_html;
	overview_html += d_add_html;
	var d_dyn = ge('dinfo_dyn');
// commented out for now
//	var d_dyn_html = '<br/><br/><b><a href="javascript:csb();">Click here</a> for availability and online bookings.</b>';
//	d_dyn.innerHTML = d_dyn_html;
//	overview_html += d_dyn_html;
	toggleThumbButtons();
	toggle_fav();
}


function csb(){
	click_on_smenu('book');
}

function set_area_images (obj){
	var t_img = new Image;
	var t = new Object;
	t.img = t_img;
	t_img.src = '/images/'+obj.area_info.image;
	t.caption = obj.caption_area_image.curlang;
	allAreaImages.push(t);

	if (obj.area_images && obj.area_images.length > 0){
		for (var i=0; i<obj.area_images.length; i++){
			var t_img = new Image;
			var t = new Object;
			t.img = t_img;
			t.caption = obj.area_images[i].caption;
			t_img.src = '/images/'+obj.area_images[i].src;
			allAreaImages.push(t);
			
		}
	}
	
}


function set_images_and_thumbs (image) {
		var src = image.src;
		var dot = src.lastIndexOf('.');
		var thumb = src;
		var ext = src.substring(dot,src.length);
		thumb = src.substring(0,dot);
		thumb += '_thumb' + ext;

		var im = new Object;
		var img = new Image;
		img.src = '/images/' + src;
		im.img = img;
		im.caption = image.caption;	
		var im_t = new Object;
		var i_t = new Image;
		i_t.src = '/images/'+thumb;
		im_t.img = i_t;
		im_t.caption = image.caption;
		allThumbs.push(im_t);
		allTopImages.push(im);

}

function create_fader(e_image) {

	var cm =  ge('Destination_Destination::area_info::image');
	if (cm){
		var check_map = cm.firstChild;
		if(check_map.id == 'map_google' || check_map.id == 'bookings_place' || check_map.id == 'floorplan_place'){
			var im = fix_old_image(ge('Destination_Destination::area_info::image').firstChild);
			im.id = 'big_image_fader';
			im.src = e_image.img.src;
			im.height = '344';
			im.style.height = '344px';
			im.style.display = 'block';
			fader_big = 0;
		}
	}

	if(fader_big == 0){

		var loaded=e_image.img.complete;
		if (loaded){
			ge('big_image_fader').src = e_image.img.src;
			fader_big = new Fader('big_image_fader');
		} else {
			buffer_big_image.img = new Image;
			buffer_big_image.img.src = e_image.img.src;
			buffer_big_image.img.onload = function(){
				ge('big_image_fader').src = buffer_big_image.img.src;
				fader_big = new Fader('big_image_fader');
			}
		}
	} else {
		fader_big.changeImage(fader_big,e_image);
	}


}




function click_on_smenu (who){

	if(currentDestPage && who == currentDestPage) {
		return false;
	}

	T['ttd_open_section'] = null;
	T['ttd_open_item'] = null;
	if (currentDestPage){
		ge('l_'+currentDestPage).className = 'subnav3';
	}

	currentDestPage = who;
	ge('l_'+who).className = 'subnav3_n';
	google_stats(who);


	ge('d_tv').innerHTML = tv_set;
	var tv = ge('d_tv');



	if(allThumbs.length <= 1) {
		ge('telek').style.display='none';
		ge('d_tv').style.width = '1px';
	
	} else {

		if (who == 'area') {
			ge('telek').style.display='none';
			ge('d_tv').style.width = '1px';
			
		} else {
			ge('telek').style.display='';
			ge('d_tv').style.width = '250px';
		}
	}

	toggleThumbButtons(1, who);
	var newImg;
	var mainPlace = ge('Destination_Destination::area_info::info::curlang');
	var headPlace = ge('Destination_Destination::name::curlang');

	var img_td = ge("Destination_Destination::area_info::image");
	img_td.align = 'right';

	if(who == 'area'){
		paint_image_caption();
		headPlace.innerHTML = dest_name;
		mainPlace.innerHTML = area_html;
		show_active = 1;
		run_slideshow();
		
		var invt = ge('Destination_Destination::inventory_info::curlang');	
		zap_if(ge('dest_inventory'));

		var inv = ce('div');
		inv.id = 'dest_inventory';

		inv.innerHTML = '';

		tv.appendChild(inv);
		

	} else if (who == 'overview') {
		reset_ss();
		paint_image_caption();
		headPlace.innerHTML = dest_street_name;
		mainPlace.innerHTML = overview_html;
		var tmp_src = ge('Destination_Destination::overview::image').firstChild.src;	
		var e_img = new Object;
		var e_i = new Image;
		e_i.src = tmp_src;
		e_img.img = e_i;
		create_fader(e_img);
		
		var invt = ge('Destination_Destination::inventory_info::curlang');
		zap_if(ge('dest_inventory'));

		var inv = ce('div');
		inv.id = 'dest_inventory';
		inv.align = "left";
		if (FIXME_readiness == 'active'){
			inv.innerHTML = '<h3>'+jssm['hacks']['inventory_title']+'</h3>'+'<div id="ivtr">'+invt.innerHTML+'</div>';
		}
		tv.appendChild(inv);
		

	} else if (who == 'floorplan') {
		reset_ss();
		paint_image_caption();
		reset_mg();
		currentFloorPlan = 0;
		newImg = allFloorplans[1];	
		
		fader_big = 0;

		if(allFloorplans.length > 1) {
			
			ge('telek').style.display='none';
			
			var cont = ge('Destination_Destination::area_info::image');
			var txt='';
			
			txt += '<table id="floorplan_place" cellpadding="0" cellspacing="0" border="0" width="100%">';
			txt += '<tr><td id="flpl_place" width="'+fp_width+'" height="'+fp_height+'" style="background-color:#FFF;" >';
			txt += build_floorplan(newImg,allFloorplans[0]);
			txt += '</td><td width="100%" style="background-color:#FFF;padding-bottom:20px" valign="bottom"><br/><br/>';

			if(allFloorplans.length > 3) {

				txt += '<div id="floorplan_menu" class="fsubnav" style="z-index:1;">';
	
				for(var i = 0; i<allFloorplans.length; i++) {
					var tmp = allFloorplans[i].split('/');
					var title = tmp[tmp.length-1];
					var sm_check = title.split('_');
					var u_check = sm_check[sm_check.length-1].split('.');
					if(u_check[0] != 'small'){
						var nt = title.split('.');
						title = nt[0] + '_small.'+u_check[1];
						var big_title =  nt[0] + '.'+u_check[1];
						var st = nt[0].split('_');
						st = st.join(' ');
						tmp[tmp.length-1] = title;
						var tlink = tmp.join('/');
						tmp[tmp.length-1] = big_title;
						var big_link = tmp.join('/');
						txt += '<ul id="fp_'+i+'" class="fsubnav"><li style="z-index:1"><a href="javascript:void(0);" onClick="return change_fp(\''+tlink+'\',\''+big_link+'\','+i+')">'+st+'</a></li></ul>';
					}
				}

				txt += '</div>';
			}

			txt += '</td></tr></table>';
			cont.innerHTML = txt;


			if(allFloorplans.length > 3) {
				replaceClass(ge('fp_0'),'fsubnav','fsubnav_n fsubnav');
			}

		}
	
		
	} else if (who == 'inventory') {
	
		var inv = ge('Destination_Destination::inventory_info::curlang');
		tv.innerHTML = '<h3>'+jssm['hacks']['inventory_title']+'</h3>'+inv.innerHTML;
	
	} else if (who == 'activities') {
		reset_ss();
		mainPlace.innerHTML = jssm['lolo']['loading_title'];
		var tz = jssm['hacks']['activities_title'];
		if (currentLanguage != 'en'){
			tz += '<br/><br/><span class="greycontent">'+jssm['hacks']['english_only']+'</span>';
		}
		headPlace.innerHTML = tz;

		request_things_to_do(current_object, 'things_to_do');

//		tv.innerHTML = '';
	
	} else if (who == 'prinfo') {
		reset_ss();
		mainPlace.innerHTML = jssm['lolo']['loading_title'];
		var tz = jssm['hacks']['practical_title'];
		if (currentLanguage != 'en'){
			tz += '<br/><br/><span class="greycontent">'+jssm['hacks']['english_only']+'</span>';
		}
		headPlace.innerHTML = tz;

		request_things_to_do(current_object, 'prinfo');

//		tv.innerHTML = '';

	} else if (who == 'holidays') {
		reset_ss();
		headPlace.innerHTML = jssm['hacks']['holidays_title'];
		var ho='<table border="1" cellpadding="4" id="special_holidays">';
		for (var i =0; i< Holidays.length; i++ ){
			var i_y = Holidays[i].when.substring(0,4);
			var i_m = Holidays[i].when.substring(4,6);
			var i_d = Holidays[i].when.substring(6,8);
			ho += '<tr><td>';
			ho += LongDateIntl(i_d,i_m,i_y)+ '</td>';
			ho += '<td typ="'+Holidays[i].typ+'" h_id="'+Holidays[i].id+'" id="holidays_'+Holidays[i].id+'">' + Holidays[i].what + '</td></tr>';
		}
		ho += '</table>';
		mainPlace.innerHTML = ho;
	} else if (who == 'schedule') {
		reset_ss();
		headPlace.innerHTML = jssm['hacks']['schedule_title'];
		mainPlace.innerHTML = get_schedule();
	
	} else if (who == 'map') {

		paint_image_caption();
		reset_ss();
		google_stats('gmap');
		tv.innerHTML =  '';
	 	replace_destination_image2gmap('map_custom');

		
	} else if (who == 'book'){
		var img_td = ge("Destination_Destination::area_info::image");
		img_td.align = '';

		paint_image_caption();
		reset_ss();
		var when = getCookie('booking');
		if (when){
			SetCookie('booking','',-1);
		} else {
		
		}
		replace_destination_image2book();
		if (CFO.is_mobile.yn == 'Y'){
//			tv.innerHTML =  '';
			headPlace.innerHTML = jssm['hacks']['schedule_title'];
			mainPlace.innerHTML = get_schedule();
		}
		init_slider(when);
	}
	init_edit();	
	return false;
}


function reset_ss(){
	show_active = 0;
	if (ss_to){
		window.clearTimeout(ss_to);
	}
}
function reset_ss2(){
	hshow_active = 0;
	if (ss_to2){
		window.clearTimeout(ss_to2);
	}
}

function request_availability (obj_id, what) {

	var r = new Object;
	r.typ = what;
	r.params = 'id='+obj_id+'&w='+what;
	r.clas = 'Availability';
	r.aborted = false;
	action_requests.push(r);

}



function request_things_to_do (obj_id, what) {

	var r = new Object;
	r.typ = what;
	r.params = 'id='+obj_id+'&w='+what;
	r.clas = 'ThingToDo';
	r.aborted = false;
	action_requests.push(r);

}



function attach_things_to_do (data) {

	ge('Destination_Destination::area_info::info::curlang').innerHTML = data;
	init_edit();
}

function fix_old_image (oldImg){
	if (oldImg.nodeName != 'IMG'){
		var parent =  oldImg.parentNode;
		parent.removeChild(oldImg);
		oldImg = ce('IMG');
		parent.appendChild(oldImg);
	}

	return oldImg;
}


function shmap(){
	google_stats('gmap');
	otherlist_1('dhh_logo_Destination');
	replaceClass(ge('l_map'),'subnav3','subnav3_n subnav3');
	var hhtml = "<table><tr><td>Pan map to local attractions:</td></tr>";
	hhtml += "<tr><td>";
	hhtml += "<a href='#' onclick='gogo_tour(0,current_point,1); return false;'>Eiffel Tower</a>";
	hhtml += "</td></tr><tr><td>";
	hhtml += "<a href='#' onclick='gogo_tour(1,current_point,1); return false';>Nos Ancetres les Gaulois</a>";
	hhtml += "</td></tr><tr><td>";
	hhtml += "<a href='#' onclick='gogo_tour(2,current_point,1); return false;'>La Tour D'Argent</a>";
	hhtml += "</td></tr><tr><td>";

	hhtml += "</td></tr></table>";
	
//TODO	if (current_object != '1635ECD6515A1A0BE040007F01002F7B' && current_object != '17BAE04EE9EA9491E040010A05013524'){
		hhtml = '';
//	}
	ge('d_tv').innerHTML = hhtml;
 	replace_destination_image2gmap('map_custom');
	return false;
}

function otherlist_1(id){

    var otherlist1 = getElementsByClass( ge(id), 'subnav_n', 'ul' );

    for ( var i = 0; i < otherlist1.length; i++ )
    {
      replaceClass( otherlist1[i], 'subnav_n', 'subnav' );
    }

}


function otherlist_fp(id){

    var otherlist1 = getElementsByClass( ge(id), 'fsubnav_n', 'ul' );

    for ( var i = 0; i < otherlist1.length; i++ )
    {
      replaceClass( otherlist1[i], 'fsubnav_n', 'fsubnav' );
    }

}

function add_thumb_caption (idx){
	var c = ge('thumb_cap');
	if (!c){
		c = ce('DIV');
		var t = ge('img_thumb');
		t.title = jssm['hacks']['click_to_enlarge'];
		c.id = 'thumb_cap';	
		c.className = 'thumb_caption';
		t.parentNode.appendChild(c);
	}
	if (allTopImages[idx] && allTopImages[idx].caption){
		c.innerHTML = allTopImages[idx].caption;
	} else {
		c.innerHTML = '&nbsp;';
	}
}

function toggleThumbButtons(miss, who){
	if(fader == 0 && allThumbs[current_thumb]){

		thumb_img = ge('img_thumb');
		if(current_thumb == 0) {
			current_thumb = 1;
		}
		if(allThumbs[current_thumb]) {
			thumb_img.src = allThumbs[current_thumb].img.src;
		}
		fader = new Fader('img_thumb');
		
	}
	
	if(fader != 0 && miss && allThumbs[current_thumb]){
		
		thumb_img = ge('img_thumb');
		
		if(who == 'area') {
			current_thumb = 1;
			thumb_img.src = allThumbs[current_thumb].img.src;
		} else {
			if(allThumbs[1]) {
				current_thumb = 1;
				thumb_img.src = allThumbs[current_thumb].img.src;
			} else {
			
				current_thumb = 0;
				thumb_img.src = allThumbs[current_thumb].img.src;
			}
		}
		fader = new Fader('img_thumb',100);

	}
	else if(fader != 0 && allThumbs[current_thumb]){
		fader.changeImage(fader,allThumbs[current_thumb]);
	}
	
	add_thumb_caption(current_thumb);

}


function next_thumb(){
    
    current_thumb ++;
	if(allThumbs.length == current_thumb) {
		current_thumb = 0;
	}
	toggleThumbButtons();

}

function prev_thumb(){
    
    current_thumb --;
	if(current_thumb < 0) {
		current_thumb = allThumbs.length-1;
	}
	toggleThumbButtons();

}

function explain_destination( thedivid , contentid ) {
    var otherlist1 = getElementsByClass( ge('contentleft'), 'subnav', 'ul' );
    for ( var i = 0; i < otherlist1.length; i++ ) {
      replaceClass( otherlist1[i], 'subnav_n', 'subnav' );
    }


        var thedivid_tmp;
        if(thedivid == 'thumb'){
                thedivid_tmp = 'area';
        }
        else if(thedivid == 'thumb1'){
                thedivid_tmp = 'overview';
                thedivid='thumb';
        }
        else {
                thedivid_tmp=thedivid;
				}
    var menu = ge('l_' + thedivid_tmp);
    replaceClass( menu, '', 'subnav_n' );
        if(thedivid!='layout'){
            var otherlist = getElementsByClass( ge(contentid), 'exp-show', 'div' );
            for ( var i = 0; i < otherlist.length; i++ )
            {
              replaceClass( otherlist[i], 'exp-show', 'exp-noshow' );
            }
            var thediv = ge( thedivid );
            replaceClass( thediv, 'exp-noshow', 'exp-show' );
           if ( document.recalc )
            {
              document.recalc();
            }
    }
    return false;
}



function compareRegions(a, b){
	if (a.regiondhh<b.regiondhh){
		return -1;
	} else if (a.regiondhh>b.regiondhh){
		return 1;	
	}
	return 0;
}


function resize_last_row(tab, row, how){
	var t = ge(tab);
	var r = t.rows[t.rows.length-1+row];
	r.style.height=how;	
	r.style.border='solid 1px red';
	r.style.visibility='visible';
}


// Update contact method from InfoRequest Form
function update_IRCM (val, t){

	var trans;

	var tmp = ge('IRCM_r');
	

	if (tmp.checked && ge('IRCM_rr').value == 'email') {
		trans = 'by Email';

		ge('IC_addr').style.display = 'none';

		ri_clean_postal();

	} else if (tmp.checked && ge('IRCM_rr').value == 'post') {
		trans = 'by Post';

		ge('ri_locality').setAttribute('nullable','N');
		ge('ri_city').setAttribute('nullable','N');
		ge('ri_region').setAttribute('nullable','N');
		ge('InfoRequest_InfoRequest::address::postal_code').setAttribute('nullable','N');

		ge('IC_addr').style.display = '';
	} else {

		ri_clean_postal();
		ge('IC_addr').style.display = 'none';
	
	}

	if(ge('IRCM_r').checked && t){
		ge('IRCM').value = trans;
	} else if (!t) {
		ge('IRCM').value = trans;
	}

}

function ri_clean_postal () {

	ge('ri_locality').setAttribute('nullable','Y');
	ge('ri_city').setAttribute('nullable','Y');
	ge('ri_region').setAttribute('nullable','Y');
	ge('InfoRequest_InfoRequest::address::country::object_id').setAttribute('nullable','Y');
	ge('InfoRequest_InfoRequest::address::postal_code').setAttribute('nullable','Y');

	ge('InfoRequest_InfoRequest::address::country::object_id').firstChild.value = '';

	ge('ri_add1').value = '';
	ge('ri_add2').value = '';
	ge('ri_pobox').firstChild.value = '';
	ge('ri_locality').firstChild.value = '';
	ge('ri_city').firstChild.value = '';
	ge('ri_region').firstChild.value = '';
	ge('InfoRequest_InfoRequest::address::postal_code').firstChild.value = '';



}
function update_IRCM1 (){

	var c = ge('bcm1');
	var trans='';
	if(c.checked) {
		trans = 'Call me';
		ge('IR_timetocall2').style.display = '';
//		ge('IR_pnum').style.display = '';
		ge('IR_expl_area').style.display = '';
	} else {
		ge('IR_timetocall2').style.display = 'none';
//		ge('IR_pnum').style.display = 'none';
	}

//	if(ge('IRCM_r').checked && t){
//		ge('IRCM').value = trans;
//	} else if (!t) {
		ge('IRCM').value = trans;
//	}

}

function UpdateIRttc (){
	var hour = ge('IR_hour').value;
	var min = ge('IR_min').value;
	var half = ge('IR_half').value;
	
	ge('IR_ttc').value = hour+':'+min+' '+half;
}

function explain_IR(what) {

	var t = ge('IR_expl');
	t.innerHTML = '';
	var lbl=ce('span');		
	
	if(what == 'country_code') {
		lbl.innerHTML = 'Country Code';
	} else if(what == 'area_code') {
		lbl.innerHTML = 'Area Code';
	} else if(what == 'phone_number') {
		lbl.innerHTML = 'Phone Number';
	} else {
		lbl.innerHTML = '&nbsp;';
	}
	t.appendChild(lbl);
}

function explain_IR1(what) {

	var t = ge('IR_expl1');
	t.innerHTML = '';
	var lbl=ce('span');	
	
	if(what == 'num') {
		lbl.innerHTML = 'Number/Apt';
	} else if(what == 'name') {
		lbl.innerHTML = 'Street name';
	} else {
		lbl.innerHTML = '&nbsp;';
	}
	t.appendChild(lbl);
}

function explain_IR2(what) {

	var t = ge('IR_expl2');
	t.innerHTML = '';
	var lbl=ce('span');
	
	if(what == 'first') {
		lbl.innerHTML = 'First'; 
	} else if(what == 'middle') {
		lbl.innerHTML='Middle'; 
	} else if(what == 'last') {
		lbl.innerHTML='Last'; 
	} else {
 		lbl.innerHTML='&nbsp'; 
	}
	t.appendChild(lbl);
}

function warn_future(){
	alert(jssm['hacks']['warn_future']);
        return false;
}


function toggle(id) {

	if(id == '1') {
		if(ge('s_1').style.display == 'none') {
			for (var x = 1; x < 13 ; x++ ) {
				ge('s_' + x).style.display='';
			}

			if(ge('t_1').style.display == '') {
				for (var x = 1; x < 13 ; x++ ) {
					ge('t_' + x).style.display='none';
				}
			}

		} else {
			for (var x = 1; x < 13 ; x++ ) {
				ge('s_' + x).style.display='none';
			}
		}
	} else if (id == '2') {

		if(ge('t_1').style.display == 'none') {
			for (var x = 1; x < 13 ; x++ ) {
				ge('t_' + x).style.display='';
			}
			
			if(ge('s_1').style.display == '') {
				for (var x = 1; x < 13 ; x++ ) {
					ge('s_' + x).style.display='none';
				}
			}

		} else {
			for (var x = 1; x <13 ; x++ ) {
				ge('t_' + x).style.display='none';
			}

		}

	}

}



function checked_floorplan(){
        alert('Floorplans for this destination coming soon.');
        return false;
}

function build_floorplan (sm,big)  {
	var txt;
	txt = '<div style="float:left;" onmouseover="zoom_on(event,fp_width,fp_height,\''+sm +'\',\''+ big + '\');" onmousemove="zoom_move(event);" onmouseout="zoom_off();">' +
		'<img height="'+fp_height+'" width="'+fp_width+'" id="floorplan_image" src="'+sm +'" style="padding:0;margin:0;border:0;display:block;"/></div>';
	return txt;
}

function change_fp (sm, big,x) {
	if(x == currentFloorPlan) {
		return false;
	}
	currentFloorPlan = x;
	ge('flpl_place').innerHTML = build_floorplan(sm,big);
	otherlist_fp('floorplan_menu');
	replaceClass(ge('fp_'+x+''),'fsubnav','fsubnav_n fsubnav'); 
	reset_mg();
	return false;

}

function lIEhackD () {
	if(loginIEhackD && loginIEhackD == 1 ){
		loginIEhackD=2;
		loginIEhack=2;
		ge('menu_to_login').style.display='block';
	}

	return false;

}

function lIEhack () {
	if(loginIEhack && loginIEhack == 1){
		loginIEhack=2;
		ge('menu_to_login').style.display='none';
	}
	return false;
}
var show_tm = 6500;
var show_tm2 = 4500;
var start_image = 0;

function run_slideshow (){

	var im = allAreaImages[start_image];
	create_fader(im);
	paint_image_caption(im.caption);

	if (allAreaImages.length > 1){
		current_show = 1;
		ss_to = setTimeout('ss()', show_tm);
	}
}

function ss(){
	var im = allAreaImages[current_show];
	current_show++;
	if (current_show == allAreaImages.length){
		current_show = 0;
	}
	if (show_active){
		create_fader(im);
		paint_image_caption(im.caption);
		ss_to = setTimeout('ss()', show_tm);
	} else {
		create_fader(dest_img);
	}
}

function run_slideshow2 (){
	paint_image_caption();
	var seen = getCookie('dhhHomeSlides');
	if (seen && !allowed){
		var im = homepageSlides[homepageSlides.length-1];
	} else {
		var im = homepageSlides[1];
	}
	create_fader(im);
	paint_image_caption(im.caption);
	if ((!seen || allowed) && hshow_active){
		ss_to2 = setTimeout('ss2()', show_tm2);
	}
}

function move_on(){
	if (!nomove){
		goto('the+promise');
	}
}


function ss2(){
	if (hshow_active == 0){return;}
	mmoved = 0;
	hcurrent_show++;
	if (hcurrent_show >= homepageSlides.length){
		if (!allowed){
			SetCookie('dhhHomeSlides',1);
			if (!mmoved && !nomove){
				mo_to = setTimeout('move_on()', 5000);
			}
			return;
		} else {
			hcurrent_show = 0;
		}
	}
	var im = homepageSlides[hcurrent_show];
	create_fader(im);
	paint_image_caption(im.caption);
	ss_to2 = setTimeout('ss2()', show_tm2);
}



function kill_image_caption() {
	var cp = ge('im_caption');
	if (cp){
		cp.style.display = 'none';
	}
}

function ihs(){
	if (!allowed) {return;}
	var path = 'info';
	var page = 'home.html';
	if (window.location.pathname.split('/').length > 2){
		path = window.location.pathname.split('/')[2];
		page = window.location.pathname.split('/')[3];
	}
	if (page == 'home.html'){
		init_homepage_slides();
	}
}

function init_homepage_slides(){
	var img = ge('Propaganda_Propaganda::image').firstChild;
	img.id = 'big_image_fader';
	img.style.display = 'block';
	var seen = getCookie('dhhHomeSlides');
	if (!seen || allowed){
		fader_big = new Fader('big_image_fader');
//		ss_to2 = window.setTimeout(run_slideshow2, show_tm2);
		ss_to2 = window.setTimeout(ss2, show_tm2);
	} else {
//		var im = homepageSlides[homepageSlides.length-1].img;
//		img.src = im.src;
//    	paint_image_caption(im.caption);
	}
}


function init_fadeup(){
	hcurrent_show = 0;
	if (document.all){return;}
return;
	if (window.location.pathname && window.location.pathname.indexOf('home.html')==-1){
//???		return;
	}
	if (getCookie('DHHsession')){
		return;
	}
	mmoved = 0;
//	var login = ge('WebAuth_WebAuth::login').firstChild;
//	login.onclick = dontmove;
	init_homepage_slides();
	var seen = getCookie('dhhHomeSlides');
	if (!seen){
		window.setTimeout(fu1, 6000);
		window.setTimeout(fu2, 14000);
	} else {
		dontmove();
		show_fus();
	}
}


function show_fus(){
	var fu1 = ge('fadeup1');
	var fu2 = ge('fadeup2');
	if (fu1){
		set_opacity(fu1, 100);
	}
	if (fu2){
		set_opacity(fu2, 100);
	}
}

function fu1(){
	var fu1 = ge('fadeup1');
	if (!fu1){
		return;
	}
	fadeup(fu1);
}

function fu2(){
	var fu2 = ge('fadeup2');
	if (!fu2){
		return;
	}
	fadeup(fu2);
}

function fadeup(obj){
	var opacity = parseInt(obj.getAttribute('opa_MS'));
	if (!opacity){
		opacity = 0;
	}
	if (opacity < 100) {
		set_opacity(obj, opacity);
		obj.setAttribute('opa_MS', opacity+2);
		window.setTimeout( function(){fadeup(obj)}, 5 );
	}

}


function set_opacity( obj, opacity ) {
	opacity = (opacity == 100)?99.999:opacity;
	opacity = (opacity <= 0)?0.001:opacity;
  // IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
  // Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
  // Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

function get_schedule(){
	var ho = '';
		if (CFO.schedule){
			ho = '<table border=1 id="schedule_tab">';
			for (var i=0; i<CFO.schedule.length; i++){
				ho += '<tr>';
				var sd = 'Present';
				var ed = 'TBA';
				if (date_perl2js(CFO.schedule[i].start_date) > now_at_location){
					sd = date_formatted(CFO.schedule[i].start_date);
				}
				if (i != CFO.schedule.length-1){
					var ed = js_date_formatted(addDays2Date(date_perl2js(CFO.schedule[i+1].start_date), -1));
				}
				ho += '<td nowrap valign="top">'+sd + ' - ' + ed +'</td>';
				ho += '<td valign="top" id="schedule_'+CFO.schedule[i].object_id+'" s_id="'+CFO.schedule[i].object_id+'"';
				if (CFO.schedule[i].is_available.yn == 'N'){
					ho += 'style="color:red;"';
				}
				var tname;
				if (CFO.schedule[i].is_transit.yn == 'Y'){
					ho += 'style="color:orange;"';
					tname = 'in transit';
				} else {
					tname = CFO.schedule[i].short_description.curlang;
				}
				ho += '>';
				ho += tname;
				ho += '</td>';
				ho += '</tr>';
			}
			ho += '</table>';
		} else {
			ho = 'No schedule loaded yet';
		}
	return ho;
}


function tf_get_to(){
	var ar = getElementsByName(ge('TellAFriend'), 'TellAFriend::email');
	var txt = '';
	var t = new Array();
	for (var i=0; i<ar.length; i++){
		if (ar[i].value != ''){
			t.push(ar[i].value);
		}
	}
	return t.join(', ');
}

function tf_send_from_preview(){
	sp_close();
	tf_submit();
}

function tf_submit(){
	tf_remove_empty();
	submitRequest(ge('Propaganda'),'TellAFriend',12);
	
}

function tf_remove_empty(){


}

function tf_preview (noshow){
	
	var from = ge('TellAFriend::sender').value;
	var message = '<div class="sp_content">'+ge('tf_template').innerHTML;
	if (ge('TellAFriend::note').value != ''){
		message  += '<br/>' + ge('TellAFriend::note').value;
	}
	message += '</div>';
	var to = tf_get_to();
	var controls = '<br/><input type="button" value="Send" onclick="tf_send_from_preview();">';
	controls += '&nbsp;&nbsp;<input type="button" value="Cancel" onclick="sp_close();">';

	var t = ce('TABLE');
	var r0 = t.insertRow(0);
	var c00 = r0.insertCell(0);
	c00.innerHTML = 'From:';
	var c01 = r0.insertCell(1);
	c01.innerHTML = from;

	var r1 = t.insertRow(1);
	var c10 = r1.insertCell(0);
	c10.innerHTML = 'To:';
	c10.style.verticalAlign='top';
	
	var c11 = r1.insertCell(1);
	c11.innerHTML = to;

	var r2 = t.insertRow(2);
	var c20 = r2.insertCell(0);
	c20.innerHTML = 'Message:';
	c20.style.verticalAlign='top';
	var c21 = r2.insertCell(1);
	c21.innerHTML = message;

	var r3 = t.insertRow(3);
	var c30 = r3.insertCell(0);
	c30.innerHTML = controls;
	c30.colSpan="2";
	c30.style.textAlign='center';


	if (!noshow){
		simple_pop(t);
	}
}

function simple_pop (obj){
	var d = ce('DIV');
	d.className='simplePop';
	d.id = 'simplePopDiv';
	d.appendChild(obj);
	document.body.appendChild(d);
	tf_disable_controls();
}

function sp_close(){
	tf_enable_controls();
	zap(ge('simplePopDiv'));
}

function tf_disable_controls (){
	ge('TellAFriend_preview_button').disabled = true;
	ge('TellAFriend_submit_button').disabled = true;
	ge('TellAFriend_more_link').href = 'javascript:void(0);';

}

function tf_enable_controls (){
	ge('TellAFriend_preview_button').disabled = false;
	ge('TellAFriend_submit_button').disabled = false;
	ge('TellAFriend_more_link').href = 'javascript:tf_addMoreEmail();';

}


var tf_cnt = 1;

function tf_addMoreEmail(){
	if (tf_cnt >= 5){
		alert('We think that emailing 5 friends at once should be enough :-)');
		return;
	}
	tf_cnt++;
	var t = ge('TellAFriend');
	var idx = tf_find_idx(t);
	var tr = t.insertRow(idx);
	var c0 = tr.insertCell(0);
	c0.innerHTML = 'Email address';
	c0.style.visibility='hidden';
	var c1 = tr.insertCell(1);
	c1.setAttribute('dt', 'Email');
	c1.setAttribute('nullable','Y');
	var i = ce('INPUT');
	i.name = 'TellAFriend::email';
	i.id = 'TellAFriend::email';
	i.onblur = tf_email_onblur;
	c1.appendChild(i);
}

function tf_email_onblur(){
	if (this.value == ''){
		zap(this.parentNode.parentNode);
	}
}

function tf_find_idx (t){
	for (var i = 0; i<t.rows.length; i++){
		if (t.rows[i].id == 'add_more_tr'){
			return i;
		}
	}
	return null;
}

var Prices='new';
function pswitch(){
	var prt = ge('plans_table').rows[1];
	var pra = ge('plans_table').rows[0];
	var psab = ge('plans_table').rows[3];
	var pfam = ge('plans_table').rows[5];
	if (Prices == 'new'){
		Prices = 'old';
		ge('new_price').innerHTML = OPM;
		for (var i = 0; i< NP.length; i++){
			prt.cells[i+1].innerHTML=NP[i].price;
			psab.cells[i+1].innerHTML=NP[i].sab_window;
			pfam.cells[i+1].innerHTML=NP[i].family_days;
			pra.cells[i+1].innerHTML=NP[i].name;
			pra.cells[i+1].setAttribute('explain', NP[i].object_id);
			pra.cells[i+1].onmouseover = eexplain2;
			pra.cells[i+1].className = 'white_plan';
		}
	} else {
		Prices = 'new';
		ge('new_price').innerHTML = NPM;
		for (var i = 0; i< OP.length; i++){
			prt.cells[i+1].innerHTML=OP[i].price;
			psab.cells[i+1].innerHTML=OP[i].sab_window;
			pfam.cells[i+1].innerHTML=OP[i].family_days;
			pra.cells[i+1].innerHTML=OP[i].name;
			pra.cells[i+1].setAttribute('explain', OP[i].object_id);
			pra.cells[i+1].className = 'white_plan';
			pra.cells[i+1].onmouseover = eexplain2;
		}
	}
}


function eexplain (cell){
	explain(cell.getAttribute('explain'));
}

var buff;
var buff_head;
function mexplain (cell){
	var so = ge('desc_'+cell.getAttribute('explain'));
	var de = ge('Propaganda_Propaganda::content::curlang');
	de.setAttribute('explain',cell.getAttribute('explain'));
	buff = de.innerHTML;
	de.innerHTML=so.innerHTML;

	so = ge('head_'+cell.getAttribute('explain'));
	de = ge('Propaganda_Propaganda::heading::curlang');
	de.setAttribute('explain',cell.getAttribute('explain'));
	buff_head = de.innerHTML;
	de.innerHTML=so.innerHTML;
}

function expout(){
	var de = ge('Propaganda_Propaganda::content::curlang');
	de.innerHTML = buff;
	de = ge('Propaganda_Propaganda::heading::curlang');
	de.innerHTML = buff_head;
}

var PT;
function mexplain_p (cell){
	PT='Plan_Plan';	
	mexplain(cell);
}
function mexplain_t (cell){
	PT='Term_Term';	
	mexplain(cell);
}

function eexplain2 (){
	explain(this.getAttribute('explain'));
}



function mkdate(){
        ge('InfoRequest::interested_date_id').value = ge('id_InfoRequest::interested_month').value + ' ' +ge('id_InfoRequest::interested_year').value;
}

function get_clippings(year){
	if (year){
		requester('get_clippings','&year='+year);
	} else {
		requester('get_clippings');
	}
	return false;
}

function get_releases(year){
	if (year){
		requester('get_releases','&year='+year);
	} else {
		requester('get_releases');
	}
	return false;
}


function get_pr(id){
	requester('get_release','&id='+id);
}

function done_get_pr(pr){
	var d = ce('DIV');
	d.width="100%";
	var t = ce('TABLE');
	t.width="100%";
	d.appendChild(t);
	var r0 = t.insertRow(0);
	var td0 = r0.insertCell(0);
	td0.className="pr_subject";
	td0.innerHTML = pr.subject;
	var r1 = t.insertRow(1);
	var td1 = r1.insertCell(0);
	td1.innerHTML = date_formatted(pr.release_date)+'<br/>'+pr.place;
	td1.className="pr_date";
	var r2 = t.insertRow(2);
	var td2 = r2.insertCell(0);
	td2.innerHTML = pr.body;
	var r3 = t.insertRow(3);
	td3 = r3.insertCell(0);
	td3.innerHTML = '<a href="javascript:void(0);" onclick = "close_art();">Back to the list</a>';
	if (!ge('art_buffer')){
		var d1 = ce('DIV');
		d1.id = 'art_buffer';
		ge('attic').appendChild(d1);
	}
	ge('art_buffer').innerHTML = ge('art_place').innerHTML;
	ge('art_place').innerHTML = d.innerHTML;
}

function close_art(){
	ge('art_place').innerHTML = ge('art_buffer').innerHTML;
}

function d_onclick(object_id, uri){
	if (CM.object_id){
		if (CM.is_guest){
			SetCookie('booking','',-1);
		}
		yoyo(object_id,'Destination');
	} else if (CA.object_id || SS.object_id){
		open_bookings_list(object_id, getCookie('booking'));
		SetCookie('booking','',-1);		
	}
	return false;
}

function request_avail_list (){
	var ef_td = make_ef_td();
	hidepcc();
	var h=0;
	for (i=0; i<ddd.length; i++){
		if (ddd[i].readiness == 'active'){
			h++;
		}
	}
	h = h*100;
	ef_td.style.height=h+'px';
	ef_td.innerHTML = jssm['hacks']['loading_form'];
	requester('destination_availability');
}

function build_avail_list (ds){
	var cy = now_at_server.getFullYear();
	var ny = cy+1;
	var ef_td = ge('external_form');
	var t = ce('table');
	var r0 = t.insertRow(0);
	var t0 = r0.insertCell(0);
	t0.colSpan=2;
	t0.innerHTML = jssm['Destination']['destination_avail'];
	t0.style.textAlign='center';
	t0.style.fontSize='10pt';
	var t1 = r0.insertCell(1);
	t1.innerHTML = jssm['Destination']['available_in']+' '+cy+':';
	t1.style.fontSize='10pt';
	t1.style.width="30%";	
	t1.style.textAlign='center';
	var t2 = r0.insertCell(2);
	t2.innerHTML = jssm['Destination']['available_in']+' '+ny+':';
	t2.style.fontSize='10pt';
	t2.style.width="30%";	
	t2.style.textAlign='center';
	for (var i=0; i<ds.length; i++){
		var r = t.insertRow(i+1);
		var d0 = r.insertCell(0);
		d0.innerHTML = '<img src="'+ds[i].image+'" height="120px" width="160px">';
		var d1 = r.insertCell(1);
		d1.style.verticalAlign='top';
		var dt = '<b><a href="javascript:goto(\''+ds[i].uri+'\');">' + ds[i].name + '</a></b><br/>';
		dt += ds[i].desc;
		d1.innerHTML = dt;
		d1.style.fontSize='12pt';
		var d2 = r.insertCell(2);
		var dt2 = ds[i].current.free_days + ' '+jssm['Destination']['out_of'] +' '+ ds[i].current.total_days + ' '+jssm['Destination']['of_days'];
		if (ds[i].current.total_days != 0){
			dt2 += '<br/>(' + ((ds[i].current.free_days/ds[i].current.total_days)*100).toFixed(0) + '%)';
		}
		d2.innerHTML = dt2;
		d2.style.fontSize='12pt';
		d2.style.verticalAlign='top';
		d2.style.textAlign='center';
		var d3 = r.insertCell(3);
		var dt3 = ds[i].following.free_days + ' '+jssm['Destination']['out_of'] +' ' + ds[i].following.total_days + ' '+jssm['Destination']['of_days'];
		dt3 += '<br/>(' + ((ds[i].following.free_days/ds[i].following.total_days)*100).toFixed(0) + '%)';
		d3.innerHTML = dt3;
		d3.style.fontSize='12pt';
		d3.style.verticalAlign='top';
		d3.style.textAlign='center';
	}
	ef_td.innerHTML='';
	ef_td.appendChild(t);

}

function corp_plans(flag){
	if (flag == 1){
		ge('nocorp').style.display='none';
		ge('prep').style.display='none';
		ge('corp').style.display='';
	} else if (flag == 0){
		ge('nocorp').style.display='';
		ge('prep').style.display='none';
		ge('corp').style.display='none';
	} else {
		ge('nocorp').style.display='none';
		ge('prep').style.display='';
		ge('corp').style.display='none';
	}
	urchinTracker("/en/plans.html");
}
