﻿/**
 * @author bokahotell
*/

		 $('#sortCheckBox_box').click(function(){ 
              	$('#rq_sort').css('border', '1px solid red'); 
                setTimeout(function(){$('#rq_sort').css('border', 'none');}, 300);     
          }); 



/* Tooltip */

	this.tooltip = function(){	
		/* CONFIG */		
			xOffset = 10;
			yOffset = 20;		
			// these 2 variable determine popup's distance from the cursor
			// you might want to adjust to get the right result		
		/* END CONFIG */	
			
		$("a.tooltip").hover(function(e){											  
			this.t = this.getAttribute("tooltip");
			$("#tooltip").html(this.t);		
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.css('display', 'block');		
		},
		function(){	
			$("#tooltip").css('display', 'none');
		});
		
		$("a.tooltip").mousemove(function(e){
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px");
		});
	
		$("a.tooltip").mouseout(function(e){
			$("#tooltip").css('display', 'none');
		});	
				
	};

/* S l i d e s h o w */

	var slideShowID;	
	var hideHover = true;
	
	function showImageHover(id)
	{
	 	$('#' + id +'_mainphoto_wrapper').stop().fadeTo(50, 0.50);
		$('#' + id +'_icon').stop().fadeTo(50, 0.50);
		//alert('test'); 
		hideHover = false;
		//showImageHoverGo(id);
		setTimeout("showImageHoverGo('" + id + "');", 50);
	}
	
	function showImageHoverGo(id)
	{	
		var element = $('#' + id + '_mainphoto');
		var offsetelement = $('#' + id +'_mainphoto_wrapper');
		
		var slideshow_wrapper = $('#slideshow_wrapper');
		var slideshow_content = $('#slideshow');
	
		var arrImageURLs = element.attr('images').split(",");
		var n = 0;
		
		var sNameBase;
		
		sNameBase = arrImageURLs[0];
			
		slideshow_content.empty();
	 	
		$.each(arrImageURLs, function( intIndex, objValue )
			{
				if(objValue.indexOf('.jpg') > 0)
				{
 					slideshow_content.append("<div><img src='" + objValue.replace('@', sNameBase) + "'></div>");
					n++;
				}
			}
		);
		
		var offsetLeft = Math.round(offsetelement.offset().left + parseInt(offsetelement.width()) + 10);
		//var offsetTop = Math.round(offsetelement.position().top + (parseInt(offsetelement.height()) / 2) - parseInt(slideshow_wrapper.height() / 2));
		var offsetTop = Math.round(offsetelement.offset().top + (parseInt(offsetelement.height()) / 2) - parseInt(slideshow_wrapper.height() / 2));
			

		//$('#' + id +'_mainphoto_wrapper').stop().fadeTo(150, 0.50);
				
		if(slideShowID!="") clearInterval(slideShowID);
		
		slideSwitch();
		slideShowID = setInterval('slideSwitch()', 2000);
		
		slideshow_wrapper.css('left', offsetLeft + 'px');	
		slideshow_wrapper.css('top', offsetTop +'px');	
		
		//setTimeout("$('#slideshow_wrapper').css('display', 'block');", 500);
		if (hideHover == false)
			slideshow_wrapper.css('display', 'block');		
	
	}
		
	function hideImageHover(id)
	{
		hideHover = true;

		$('#' + id +'_icon').stop().fadeTo(100, 1.0);
	 	$('#' + id +'_mainphoto_wrapper').stop().fadeTo(100, 1.0);	 	
		$('#slideshow_wrapper').css('display', 'none');	
		if(slideShowID!="") clearInterval(slideShowID);
	}
	
	function slideSwitch() {
 
 		var slideshow_wrapper = $('#slideshow_wrapper');
		var $active = $('#slideshow DIV.active');
		
		if ($active.length == 0) $active = $('#slideshow div:first');
		
		var $next =  $active.next().length ? $active.next()
					 : $('#slideshow DIV:first');

		$active.fadeTo(150, 0);
		$active.css('display', 'none');
	
		$next.css('opacity', 0.0);
		$next.css('display', 'block');
		
		if($next.find('IMG').width() > slideshow_wrapper.width())
		{
			$next.find('IMG').width(slideshow_wrapper.width());
			$next.find('IMG').height('auto');
		}
		
		if($next.find('IMG').height() > slideshow_wrapper.height())
		{
			$next.find('IMG').height(slideshow_wrapper.height());
			$next.find('IMG').width('auto');
		}
 		
		$next.fadeTo(150, 1);
		
		$active.removeClass('active');
		$next.addClass('active');
		
	}
	
// Banner switch

	var bannerID;

	function bannerSwitch() {
 
 		var tagName;
		tagName = "#banner";
 
 		//var slideshow_wrapper = $('#slideshow_wrapper');
		var $active = $(tagName + ' DIV.active');
		
		if ($active.length == 0) $active = $(tagName + ' div:first');
		
		var $next =  $active.next().length ? $active.next()
					 : $(tagName + ' DIV:first');

		$active.fadeTo(300, 0);
		$active.css('display', 'none');
	
		$next.css('opacity', 0.0);
		$next.css('display', 'block');
		
		$next.fadeTo(300, 1);
		
		$active.removeClass('active');
		$next.addClass('active');
		
		if(bannerID!="") clearInterval(bannerID);
		bannerID = setInterval('bannerSwitch()', 8000);
		
	}
	
	function startBannerSwitch()
	{
		var tagName;
		tagName = "#banner";
  
		var $active = $(tagName + ' DIV.active');
		$active.queue( [ ] ).stop();
		
		if(bannerID!="") clearInterval(bannerID);
		bannerSwitch()
 
	}
	
	function pauseBannerSwitch()
	{
		var tagName;
		tagName = "#banner";
 
 		var $active = $(tagName + ' DIV.active');
		$active.queue( [ ] ).stop();
		
		if(bannerID!="") clearInterval(bannerID);
		
	}

/* TIMER */

jQuery.timer = function (interval, callback)
 {

	var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };

/* MISC */
function ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}

function $E(_id)
{
	return document.getElementById(_id)	
}

/* TABS */
	function change_tab(clicked_tab, content_div)
	{
		
		$("#tab_container > div").removeClass("selected-tab"); 
		$("#tab_container > div").addClass("unselected-tab"); 
		
		$("#" + clicked_tab).removeClass("unselected-tab"); 
		$("#" + clicked_tab).addClass("selected-tab"); 
		
		$("#content_container > div").css('visibility', 'hidden');
		$("#content_container > div").css('display', 'none');
		 
		$("#" + content_div).css('visibility', 'visible');
		$("#" + content_div).css('display', 'block');

	}
	
	function show_image(image_url)
	{
		$('#main_img').attr('src', image_url);
		if($('#main_img').width()>356) $('#main_img').width(356);
	}

/* POPUP */
	var sCurrentWindowUrl = '';
	var g_PopupIFrame;
	
	function setWindowFrameSize(iWidth, iHeight)
	{
		// resize code here
	}
	
	function showWindowFrame(sUrl, sUniqueID)
	{
		
		if(sUrl != sCurrentWindowUrl)
		{
			//alert($('#window_content_' + sUniqueID) + ' ' + sUrl);
			$('#window_content_' + sUniqueID).attr('src', sUrl);
			sCurrentWindowUrl = sUrl;
		}	
		
		var iOffset = 0; 	
		iOffset = pageYoffset();
			
		$('#root_' + sUniqueID).css('top', (iOffset + 100) + 'px');
		$('#rootCover_' + sUniqueID).css('top', (iOffset + 100) + 'px');
		
		show('root_' + sUniqueID);
		
		//if(window.ie) 
		if($.browser.msie) 
			show('rootCover_' + sUniqueID);	
	}
	
	function hideWindowFrame(sUniqueID)
	{
		hide('root_' + sUniqueID);
		
		if($.browser.msie) 
			hide('rootCover_' + sUniqueID);	
	}

	function pageYoffset()
	{
		var ScrollTop = document.body.scrollTop;
		
		if (ScrollTop == 0)
		{
		    if (window.pageYOffset)
		        ScrollTop = window.pageYOffset;
		    else
		        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
 
		return ScrollTop;
	}

/* REVIEWS */

	function rev_highlight(sCategory, iValue)
	{
		for(var n = 1;n<=5;n++)
		{
			if(n==iValue)
			{
				$(sCategory + '-' + n).css('color', '');
				$(sCategory + '-' + n).css('font-weight', 'bold');
			}
			else
			{
				$(sCategory + '-' + n).css('color', '#888888');
				$(sCategory + '-' + n).css('font-weight', '');
			}			
		}
	}

/*  RESULT LIST UTIL */
	
		var iHotels=0;
		var h = new Array();
		var filters = new Array(9);
		var iNumFilters = 9;
		
		function sorthotels(iSortBy)
		{
			var cSelBox = $E('rq_lmark');

			if(iSortBy==5)
			{
				if(cSelBox)
				{
					if(cSelBox.selectedIndex == 0)
					{
						iSortBy = -1;
					}
				}
				else
					iSortBy = -1;
			}
			
			if($E('rq_lmarkRefresh'))
			{	
				if($E('rq_lmarkRefresh').value==1) {computeDistance();$E('rq_lmarkRefresh').value=0;};
			}
			
			switch(iSortBy)
			{
				case '1': h.sort(sortByScore);break;
				case '2': h.sort(sortByName);break;
				case '3': h.sort(sortByRating);break;
				case '4': h.sort(sortByLowestRate);break;
				case '5': h.sort(sortByDistance);break; 
			}
			
			if(iSortBy == -1) $('rq_sort').selectedIndex = 0;
		}
		
		function computeDistance()
		{
if($E('rq_lmark'))
{
			var cSelBox = $E('rq_lmark');
			var sValue = cSelBox.options[cSelBox.selectedIndex].value.split('|');
	
			var sTitle = sValue[2];
			var refLat = parseFloat(sValue[0].replace(',','.'));
			var refLong = parseFloat(sValue[1].replace(',','.'));
			var sdist;var result;
			var tagname;

			for(var n = 1;n<=iHotels;n++)
			{
				if(h[n-1])
				{
					if(!(h[n-1].lt == 0 || h[n-1].lg == 0))
					{
						 
						sdist =  dist(h[n-1].lt, h[n-1].lg, refLat, refLong);
						result = result + h[n-1].hotelName + ' ' + sdist + '\n'
						
						h[n-1].distance = parseFloat(sdist);
						
						sdist = sdist / 1000
						sdist = Math.round(sdist * 100) / 100
						
						if(sdist > 1)
							sdist = sdist + " km"
						else 
							sdist = sdist * 1000 + " m";
 
						  tagname = "#hotel" + (n) + " div[name='distance']";
						 
						$(tagname).empty();
						$(tagname).append("<b>" + sdist + ' fr&aring;n ' + sTitle + '</b><br>');
					 
						h[n-1].HTML = $('#hotel' + n).html();
 
					}
				}
			}
}	
		}
		
		function Right(str, n){
			if (n <= 0)
			   return "";
			else if (n > String(str).length)
			   return str;
			else {
			   var iLen = String(str).length;
			   return String(str).substring(iLen, iLen - n);
			}
		}

	
		var lastIndexTime = 0;
		var lastLabelTime = 0;
	
		function createIndex()
		{
			var tempDate = new Date();
  
			if ((tempDate.getTime() - lastIndexTime < 1500) && loadComplete == false) return;
			if (createIndexFlag == false) return;
			
			lastIndexTime = tempDate.getTime();
			
			var htemp;
			h = new Array();
			
			for(var n = 1;n<=iHotels;n++)
			{
				htemp = $('#hotel' + n);
				
				if(htemp)
				{
					//alert(n);
					//if(!htemp.attr('hotelname')) alert('empty' + n);
					
					h[n-1] = new hotel(htemp.attr('hotelid'), 
						parseInt(parseFloat(htemp.attr('lowestrate'))), 
					 	parseInt(parseFloat(htemp.attr('hotelrating'))), 
						htemp.html(),
						htemp.attr('hotelname'),
						parseInt(htemp.attr('a1')),
						parseInt(htemp.attr('a2')),
						parseInt(htemp.attr('a3')),
						parseInt(htemp.attr('a4')),
						parseInt(htemp.attr('a5')),
						parseInt(htemp.attr('a6')),
						parseInt(htemp.attr('a7')),
						parseInt(htemp.attr('a8')),
						parseInt(htemp.attr('a9')),
						parseFloat(htemp.attr('lt')),
						parseFloat(htemp.attr('lg')),
						parseInt(htemp.attr('score'))
						)
				}
			}
			 
		}
		
		function setResetStatus(srcbox)
		{
				var element = $E(srcbox.form.name).elements;
				var resetChecked = true;
				
				for (var n = 0; n <= element.length; n++)
				{
					if(element[n])
						if(element[n].name=='req_am' && element[n].checked) resetChecked = false;	
				}
				
				for (var n = 0; n <= element.length; n++)
				{
					if(element[n])
						if(element[n].name=='am_reset') element[n].checked = resetChecked;	
				}
		}
		
		function resetFilters(srcbox)
		{
				var element = $E( srcbox.form.name).elements;
			
				for (var n = 0; n <= element.length; n++)
				{
					if(element[n])
						if(element[n].name=='req_am' && element[n].checked) element[n].checked = false;	
				}
				
				srcbox.checked = true;
				updateFilterLabel();
		}
			
		function collectFilters()
		{
				var element = document.getElementsByName('req_am');
				var n;
				
				for (n = 0; n <= iNumFilters; n++)
					filters[n] = -3;
				
				for (n = 0; n <= iNumFilters; n++)
				{
					if(element[n])
					{
						if(element[n].form.name=='sortform')
						{
							if(element[n].checked) 
							{	
								filters[parseInt(element[n].value)] = -1;
							}
							else 
								filters[parseInt(element[n].value)] = 0;
						}

					}
				}
		}
		
		function checkFilter(h)
		{
		
			var minStars = $E("req_minstars").options[$E("req_minstars").selectedIndex].value
			//alert(minStars + ' ' + h.rating);
			
			for (var n = 1; n <= iNumFilters; n++)
			{				
				if((filters[n] == -1 && parseInt(h.a[n]) != -1))//|| filters[n] == 0
				{	
						return 0;
				}
			}
			
			if(parseInt(minStars, 10) > parseInt(h.rating, 10))
				return 0
			else
				return 1;
		}
		
		function countFilterMatch() 
		{
			collectFilters();
			var iMatch = 0;

			for(var n = 1;n<=iHotels;n++)
			{
				if(h[n-1])
				{
					if(checkFilter(h[n-1])==1) 
						iMatch ++;
				}
			}
				
			return iMatch;
		}
		
		
		
		function updateFilterLabel()
		{
			
			if (createIndexFlag == false) 
			{	
				return;
			}
			
			var tempDate = new Date();
			if (tempDate.getTime() - lastLabelTime < 1500 && loadComplete == false) return;
			
			lastLabelTime = tempDate.getTime();
			
			if($E('filterlabel'))
			{
				var iMatch = countFilterMatch();
				$E('filterlabel').innerHTML  = iMatch;
			}
		}
		
		function outputCollection()
		{
			if(!loadComplete) return false;
			show('loading-indicator');
			setTimeout(outputCollectionGO, 10);
		}
		
		function outputCollectionGO()
		{
			
			if(!loadComplete) return false;
			
			var hitem;
			var sortSelect = $E('rq_sort');
			
			sorthotels(sortSelect.options[sortSelect.selectedIndex].value);
			collectFilters();

			for(var n = 1;n<=iHotels;n++)
			{
				//hitem = $('#hotel' + n);
				hitem = $E('hotel' + n);	
				//alert(hitem);
				
				if(hitem && h[n-1])
				{
					//hitem.html(h[n-1].HTML);
					hitem.innerHTML =  h[n-1].HTML;
					if(checkFilter(h[n-1])==0) 
						hide('hotel' + (n))
					else
						show('hotel' + (n))
				}
			}
			
			hide('loading-indicator');
			return false;
		}
		
		function sortByRating(a, b) {
		    var x = a.rating;
		    var y = b.rating;
		    return ((x > y) ? -1 : ((x < y) ? 1 : 0));
		}
		
		function sortByName(a, b) {
		    var x = a.hotelName.toLowerCase();
		    var y = b.hotelName.toLowerCase();
		    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
		}
		
		function sortByLowestRate(a, b) {
		    var x = a.lowestRate;
		    var y = b.lowestRate;
		    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
		}
		
		function sortByDistance(a, b) {
		    var x = a.distance;
		    var y = b.distance;
		    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
		}
		
		function sortByScore(a, b) {
		    var x = a.score;
		    var y = b.score;
		    return ((x > y) ? -1 : ((x < y) ? 1 : 0));
		}
		
		function hotel(hotelId, lowestRate, rating, HTML, hotelName, a1, a2, a3, a4, a5, a6, a7, a8, a9, lt, lg, score) {
		    this.hotelId = hotelId;
		    this.lowestRate = lowestRate;
		    this.rating = rating;
			this.HTML = HTML;
			this.hotelName = hotelName;
			this.lt = lt;
			this.lg = lg;
			this.score = score;
			this.a = new Array();
			this.a[1] = a1;this.a[2] = a2;this.a[3] = a3;this.a[4] = a4;this.a[5] = a5;this.a[6] = a6;this.a[7] = a7;this.a[8] = a8;this.a[9] = a9;
			this.distance = parseFloat('999999.99');
		}

/*  FORM UTIL */

			function openWindow(sUrl, iWidth, iHeight, sId)
			{
				window.open(sUrl,sId,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+iWidth+",height="+iHeight+",target=_blank");
				return true;
			}
			
			function openWindowWithToolbar(sUrl, iWidth, iHeight, sId)
			{
				if($.browser.msie && $.browser.version > 6)
					window.open(sUrl,sId,"toolbar=0,location=1,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+iWidth+",height="+iHeight+",target=_blank")
				else
					window.open(sUrl,sId,"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+iWidth+",height="+iHeight+",target=_blank");
					
				return true;
			}
			
			function view_map(map_id)
			{
				var url = "mapengine.aspx?id=" + map_id
				window.open(url,"Info","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=480,height=480");
				return false;
			}
			
			function view_faq(q, lang, sbaseurl)
			{
				var url = sbaseurl + "faq.aspx?lang=" + lang + "#" + q;
				window.open(url,q,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=555,height=430,target=_blank");
			}
			
			function view_map2(mapurl)
			{
			
				window.open(mapurl,"bokahotellmap","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=480,height=480");
				return false;
			}
			
			function view_maptn(hid, hname)
			{
		
				if(hname == "") hname = "Karta";
				
				var url = "http://www.bokahotell.se/xml/mapnew.asp?prop=" + hid + ":" + hname + "&cid=68797&locale=se";
				
				window.open(url, "Karta", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=640,height=480");
			}
			
			function req_numrooms_change(sFormName)
			{
				 
				//hide nonused rooms
				var numrooms = parseInt($('form[name=' + sFormName + ']  select[name=req_numrooms]').val());
				var cElement, cLabel;
				
				for (var n = 1; n <= 8; n++)
				{					
					//cElement = $('select[#' + sFormName + '_room' + n + ']')
					//cLabel = $('select[#' + sFormName + '_room' + n + 'title]')
					
					sElement = sFormName + '_room' + n
					sLabel = sFormName + '_room' + n + 'title'
					
					if(n>numrooms)
					//{	hide('room' + n);hide('room'+ n + 'title');}cLabel.hide()
					{	hide(sElement);hide(sLabel);}
					else
					{	show(sElement);show(sLabel);}
				}	
				
				childlabelVis(sFormName);
			}
			
			function req_numchildren_change(sRoom, sFormName)
			{
				//TODO: replace with faster code:
				
				var numchildren = parseInt($('form[name=' + sFormName + ']  select[name=req_' + sRoom + '_numchildren]').val());
				//var element = document.getElementsByName('req_' + sRoom + '_childages');
				var element = $('form[name=' + sFormName + ']  select[name=req_' + sRoom + '_childages]	');
						
				if(element)
				{
					for (var n = 0; n <= 2; n++)
					{
						if((n+1)>numchildren)	{
							if(element[n])
								element[n].style.visibility="hidden";
						}
						else {
							if(element[n])
								element[n].style.visibility="visible";}
					}
				}
				
				childlabelVis(sFormName);
			}
			
			function childlabelVis(sFormName)
			{
				var numchildren 
				var bVisible = false;
				
				var numrooms = parseInt($('form[name=' + sFormName + ']  select[name=req_numrooms]').val()); 
				//var numrooms = parseInt($('#req_numrooms]').val()); 
				var numchildren;
				
				for (var n = 0; n <= numrooms; n++)
				{
					numchildren = $('form[name=' + sFormName + ']  select[name=req_rm' + n + '_numchildren]');
					if (numchildren)
						 
						if (parseInt(numchildren.val()) > 0)
						{
							bVisible = true;
							if($E(sFormName + "_childagelabel" + n))
									$('#' + sFormName + '_childagelabel' + n).css('visibility', 'visible');  
						}
						else
									$('#' + sFormName + '_childagelabel' + n).css('visibility', 'hidden');
				}

				if (bVisible)
				{
					//show(sFormName + '_childagelabel');show(sFormName + '_childbed');
					$('#' + sFormName + '_childagelabel').css('visibility', 'visible');
					show(sFormName + '_childbed');
					//$('#' + sFormName + '_childbed').css('visibility', 'visible');
					 
				}
				else
				{
					$('#' + sFormName + '_childagelabel').css('visibility', 'hidden');
					hide(sFormName + '_childbed');
					//$('#' + sFormName + '_childbed').css('visibility', 'hidden');
				}
			}
					
			function show(sElement)
			{
				var cElement = $("#" + sElement);
				if (cElement)
				{
					cElement.css('visibility', 'visible');
					cElement.css('display', 'block');
				}
			}
			
			function hide(sElement)
			{
				var cElement = $("#" + sElement);

				if (cElement)
				{
					cElement.css('visibility', 'hidden');
					cElement.css('display', 'none');
				} 
				
			}
			
			function toggle_searchform(sContainerName, bShow)
			{
			    if ($(sContainerName))
			    {
			        if (bShow==true) 
					{
						show(sContainerName);
						hide('showsearchform');
						show('hidesearchform');
					}
			        else 
					{
						hide(sContainerName);
						show('showsearchform');
						hide('hidesearchform');
					}
			    }
			
			}
			
			function adjust_form()
			{
				var n, q, sFormName;
				var arrForms = [ "largeSearchForm", "sideform", "searchform" ];

				$.each(
					arrForms,
					function( intIndex, objValue ){
						if($E(objValue))
						{
							req_numrooms_change(objValue);
							for(n=1;n<=4;n++)
							{	
								req_numchildren_change('rm'+n, objValue );					
							}
						}
					})

				//for(q=1;q<=2;q++)
				//{
				//	if(q==1) 
				//		sFormName = 'sideform' 
				//	else sFormName = 'searchform';
					
				//	req_numrooms_change(sFormName);
				//	for(n=1;n<=4;n++)
				//	{
				//		req_numchildren_change('rm'+n, sFormName);					
				//	}		
				//}
			}
				
/* Geo */

	function dist(lat1, lon1, lat2, lon2) {
	  var a = 6378137, b = 6356752.3142,  f = 1/298.257223563;  // WGS-84 ellipsiod
	  var L = (lon2-lon1).toRad();
	  var U1 = Math.atan((1-f) * Math.tan(lat1.toRad()));
	  var U2 = Math.atan((1-f) * Math.tan(lat2.toRad()));
	  var sinU1 = Math.sin(U1), cosU1 = Math.cos(U1);
	  var sinU2 = Math.sin(U2), cosU2 = Math.cos(U2);
	  
	  var lambda = L, lambdaP = 2*Math.PI;
	  var iterLimit = 20;
	  while (Math.abs(lambda-lambdaP) > 1e-12 && --iterLimit>0) {
	    var sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda);
	    var sinSigma = Math.sqrt((cosU2*sinLambda) * (cosU2*sinLambda) + 
	      (cosU1*sinU2-sinU1*cosU2*cosLambda) * (cosU1*sinU2-sinU1*cosU2*cosLambda));
	    if (sinSigma==0) return 0;  // co-incident points
	    var cosSigma = sinU1*sinU2 + cosU1*cosU2*cosLambda;
	    var sigma = Math.atan2(sinSigma, cosSigma);
	    var sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma;
	    var cosSqAlpha = 1 - sinAlpha*sinAlpha;
	    var cos2SigmaM = cosSigma - 2*sinU1*sinU2/cosSqAlpha;
	    if (isNaN(cos2SigmaM)) cos2SigmaM = 0;  // equatorial line: cosSqAlpha=0 (�6)
	    var C = f/16*cosSqAlpha*(4+f*(4-3*cosSqAlpha));
	    lambdaP = lambda;
	    lambda = L + (1-C) * f * sinAlpha *
	      (sigma + C*sinSigma*(cos2SigmaM+C*cosSigma*(-1+2*cos2SigmaM*cos2SigmaM)));
	  }
	  if (iterLimit==0) return NaN  // formula failed to converge
	
	  var uSq = cosSqAlpha * (a*a - b*b) / (b*b);
	  var A = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq)));
	  var B = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq)));
	  var deltaSigma = B*sinSigma*(cos2SigmaM+B/4*(cosSigma*(-1+2*cos2SigmaM*cos2SigmaM)-
	    B/6*cos2SigmaM*(-3+4*sinSigma*sinSigma)*(-3+4*cos2SigmaM*cos2SigmaM)));
	  var s = b*A*(sigma-deltaSigma);
	  
	  s = s.toFixed(3); // round to 1mm precision
	  return s;
	}
	

	String.prototype.parseDeg = function() {
	  if (!isNaN(this)) return Number(this);                 // signed decimal degrees without NSEW
	
	  var degLL = this.replace(/^-/,'').replace(/[NSEW]/i,'');  // strip off any sign or compass dir'n
	  var dms = degLL.split(/[^0-9.]+/);                     // split out separate d/m/s
	  for (var i in dms) if (dms[i]=='') dms.splice(i,1);    // remove empty elements (see note below)
	  switch (dms.length) {                                  // convert to decimal degrees...
	    case 3:                                              // interpret 3-part result as d/m/s
	      var deg = dms[0]/1 + dms[1]/60 + dms[2]/3600; break;
	    case 2:                                              // interpret 2-part result as d/m
	      var deg = dms[0]/1 + dms[1]/60; break;
	    case 1:                                              // decimal or non-separated dddmmss
	      if (/[NS]/i.test(this)) degLL = '0' + degLL;       // - normalise N/S to 3-digit degrees
	      var deg = dms[0].slice(0,3)/1 + dms[0].slice(3,5)/60 + dms[0].slice(5)/3600; break;
	    default: return NaN;
	  }
	  if (/^-/.test(this) || /[WS]/i.test(this)) deg = -deg; // take '-', west and south as -ve
	  return deg;
	}
	
	Number.prototype.toRad = function() {  // convert degrees to radians
	  return this * Math.PI / 180;
	}


/* Menus */
	
	function expand(s)
	{
	  var td = s;
	  var d = td.getElementsByTagName("div").item(0);
	
	  if(td) td.className = "menuHover";
	  if(d) d.className = "menuHover";
	}
	
	function collapse(s)
	{
	  var td = s;
	  var d = td.getElementsByTagName("div").item(0);
	
	  if(td) td.className = "menuNormal";
	  if(d) d.className = "menuNormal";
	}
	
/* DRAG AND DROP */
	
	var Drag = {

	obj : null,

	init : function(sO, sRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		
		var o = document.getElementById(sO);
		var oRoot = document.getElementById(sRoot);
				
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;
		o.rootCover = $E(sRoot + '_cover');
			
		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;
		
		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		
		Drag.obj.rootCover.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.rootCover.style[o.vmode ? "top" : "bottom"] = ny + "px";
		
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

	function printDiv(sDivName)
	{
		var a = window. open('','test','toolbar=1,location=1,resizable=1,menubar=1,scrollbars=yes,width=700,height=800');
		
		a.document.open("text/html");
		a.document.writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">')
		a.document.writeln('<html><head>')
		a.document.writeln('<link rel="stylesheet" href="bokahotellv3.css" />')
		a.document.writeln('<scr' + 'ipt type="text/javascript">window.onerror = function onErrorHandler(msg, url, lno){}</sc' + 'ript>')
		a.document.writeln('<style type="text/css">;td {color:#1B3664;font-family:Lucida Sans Unicode,Lucida Grande,Verdana,Arial,sans-serif;font-size:11px;};</style></head>')
		a.document.writeln('<body style="padding-left:20px;background: url(imagesv2/spacer.gif) top center no-repeat;">')
		a.document.writeln('<div id="outer" style="background-color:#FFFFFF;text-align:left;background: url(imagesv2/spacer.gif) top center no-repeat;"">');
	
		a.document.writeln('<div style="width:575px;margin-top:20px;margin-bottom:10px;">');
		a.document.writeln('<div style="float:left;">');
		a.document.writeln('<img border="0" alt="bokahotell.se" src="imagesv2/logos/logo-255x52.gif" width="255" height="52">');
		a.document.writeln('</div><div style="float:right;padding-top:5px;" class="normal11">');
		a.document.writeln('<b>BOKA hotell och konferenser</b><br>');
		a.document.writeln('- bokahotell.se<br>');
		a.document.writeln('Telefon: +46 - (0)8 - 54 59 10 10<br>');
		a.document.writeln('E-post:  info@bokahotell.se');
		a.document.writeln('</div><div style="clear:both;">&nbsp;</div></div>');

		a.document.writeln('<div style="width:640px;">')
		a.document.writeln(document.getElementById(sDivName).innerHTML);
		a.document.writeln('</div>')
		
		a.document.writeln('</div></body></html>');
		a.document.close();
		a.print();
		
	}
	
	

	
	
		
		   
		  
		   
		
		   
		  
		   
		