
dojo.lang.extend(dojo.widget.Dialog,{
		placeModalDialog: function() {
			var scroll_offset = dojo.html.getScroll().offset;
			var viewport_size = dojo.html.getViewport();
			var mb;
			if(this.isShowing()){
				mb = dojo.html.getMarginBox(this.domNode);
			}else{
				dojo.html.setVisibility(this.domNode, false);
				dojo.html.show(this.domNode);
				mb = dojo.html.getMarginBox(this.domNode);
				dojo.html.hide(this.domNode);
				dojo.html.setVisibility(this.domNode, true);
			}

			var x = scroll_offset.x + (viewport_size.width - mb.width)/2;
			var y = scroll_offset.y + (viewport_size.height - mb.height)/2;

		    if (this.widgetId=='GalleryDialog') {
                if (y<=342) {
                            with(this.domNode.style) {
				              top = "342px";
			                }
                } else {
                            with(this.domNode.style) {
				              top = y + "px";
			                }
                };
            } else {
			    with(this.domNode.style) {
				  top = y + "px";
			    }
            }

			with(this.domNode.style){
				left = x + "px";
			}
		}

     }
)

function init() {
      dojo.event.connect(am, "toolbarclick", myfunc);
}

dojo.addOnLoad(init);

function onWindowResizeIE () {
		var h = document.body.offsetHeight;
		if (!dojo.lang.isUndefined(dojo.byId('alp_header'))) h -= dojo.byId('alp_header').offsetHeight;

        if (dojo.byId('custom_footer')==null) {
          if (!dojo.lang.isUndefined(dojo.byId('alp_footer'))) h -= dojo.byId('alp_footer').offsetHeight;

        } else {
          if (!dojo.lang.isUndefined(dojo.byId('custom_footer'))) h -= dojo.byId('custom_footer').offsetHeight;
        };
		if (!dojo.lang.isUndefined(dojo.byId('alp_main'))) dojo.byId("alp_main").style.height = h + "px";
		am.onresize();
}


if (dojo.render.html.ie55 || dojo.render.html.ie60 || dojo.render.html.ie70) {
	dojo.addOnLoad(function() {
        onWindowResizeIE();
        dojo.event.connect(am, "onload", onWindowResizeIE);
		dojo.event.connect(window, "onresize", onWindowResizeIE);

	});
}


function myfunc(btn) {
  if (btn.id=='am_infopanel') {
   am.getInfoPane("am_OOIPane").hide();
   am.getInfoPane("am_OOIPane").collapse(false);
   if(!dojo.lang.isUndefined(dojo.widget.byId('am_RoutingPane'))) {
     am.getInfoPane().show;
   } else {
    am.getInfoPane("am_AssistantPane").show();
    var mypane=am.getInfoPane("am_AssistantPane");
    am.getInfoPane().setActivePane(mypane);
   };
  }
  
  if (btn.id=='btn_assistant') {
   am.getInfoPane('am_AssistantPane').show();
   var mypane=am.getInfoPane('am_AssistantPane');
   am.getInfoPane().setActivePane(mypane);
   }
  if (btn.id=='btn_routing') {
   am.getInfoPane('am_RoutingPane').show();
   var mypane=am.getInfoPane('am_RoutingPane');
   am.getInfoPane().setActivePane(mypane);
   }
}


function show_content() {
   if (!dojo.lang.isUndefined(dojo.widget.byId('detail_container')))  dojo.widget.byId('detail_container').show();
}


function sizer() {
     var togo = dojo.widget.byId('am_InfoPane').containerNode;
     var innerHeight = dojo.html.getMarginBox(togo).height;
      if (dojo.render.html.ie) {
          if (dojo.lang.isUndefined(dojo.widget.byId('am_IntroductionPane'))) {
            var heightset = innerHeight-509;
           } else {
            var heightset = innerHeight-531;
           }
      } else {
           if (dojo.lang.isUndefined(dojo.widget.byId('am_IntroductionPane'))) {
            var heightset = innerHeight-479;
           } else {
            var heightset = innerHeight-505;
           }
      }
      if (heightset<20) {heightset=20};
      if (document.getElementById('detail_content_div')!=null)
      document.getElementById('detail_content_div').style.height=heightset+"px";
}

function zoom(source, sourceid, ooiid) {
 var treeentryid= am.tree.getEntryForSource(source, sourceid).id;
 am.displayLayer(treeentryid, true, function () {am.zoomToOOI(sourceid, ooiid, treeentryid, [50,350], false);});
}

function openInfoPanelTour(lang, skin, source, app, sourceid, geoactivetype, ooiid, name, multisource, commune, focus, startpoint, sel, from, to, str_id) {

 commune = (typeof commune == 'undefined') ? '0' : commune;
 focus = (typeof focus == 'undefined') ? 'all' : focus;
 startpoint = (typeof startpoint == 'undefined') ? 'all' : startpoint;

 dojo.event.connectOnce(dojo.widget.byId('am_OOIPane'), "onexpandend", show_content);

 if (multisource!="") {
    var treeentryid= am.tree.getEntryForSource(multisource, source+'_'+sourceid).id;
    am.displayLayer(treeentryid, true, function () {am.zoomToOOI(source+'_'+sourceid, source+'_'+ooiid, treeentryid, [50,350], false);});
 } else {
    var treeentryid= am.tree.getEntryForSource(source, sourceid).id;
    am.displayLayer(treeentryid, true, function () {am.zoomToOOI(sourceid, ooiid, treeentryid, [50,350], false);});
 };

 am.getInfoPane('am_OOIPane').setTitleText(name);
 urlicon = '/rhoen/site/regional_portal/skin/'+skin+'/images/'+geoactivetype+'.png';
 am.getInfoPane('am_OOIPane').setTitleIcon(urlicon);

 url  = '/rhoen/site/regional_portal/portal_detailpane.php?source='+source;
 url += '&app='+app;
 url += '&sourceid='+sourceid;
 url += '&id='+ooiid;
 url += '&lang='+lang;
 url += '&commune='+commune;
 url += '&tourfocus='+focus;
 url += '&startpoint='+startpoint;
 url += '&sel='+sel;
 url += '&from='+from;
 url += '&to='+to;

 am.openInfoPanel(url, false);
 am.getInfoPane("am_AssistantPane").show();
}


function openInfoPanelPOI(url, title, skin) {
  var skin = (skin == null) ? "common" : skin;
  dojo.event.connectOnce(dojo.widget.byId('am_OOIPane'), "onexpandend", show_content);
  am.getInfoPane('am_OOIPane').setTitleText(title);
  urlicon = '/rhoen/site/regional_portal/skin/'+skin+'/images/info.gif';
  am.getInfoPane('am_OOIPane').setTitleIcon(urlicon);
  am.openInfoPanel(url);
  am.getInfoPane("am_AssistantPane").hide();
}

function setStars(stars, spanid, sum, skin) {
             var j = sum-stars;
             var s = '';
              for (var i = 1; i <= stars; i++)   {
                s = s+'<div style="float:left; width:5px; height:8px; margin-right:3px; padding:0px; margin-top:0px; margin-bottom:0px;" class="bgcolor_dark"></div>';

	              }
              for (var i = 1; i <= j; i++) {
                 s = s+'<div style="float:left;width:5px; height:8px; margin-right:3px; padding:0px; margin-top:0px; margin-bottom:0px; background-color: white;padding:0px;"></div>';

	             }
              document.getElementById(spanid).innerHTML = s;
          }

var prev_pic;

function onParamChanger(source, app, sourceid, lang, geoactivetype, action, commune, season) {

	var el_tourfocus =document.getElementById('id_tourfocus');
	if (el_tourfocus != null) {
        var val_tourfocus = el_tourfocus.options[el_tourfocus.selectedIndex].value;
    } else {
        var val_tourfocus='all';
    }

	var el_startingpoint =document.getElementById('id_startingpoint');
	if (el_startingpoint != null) {
       var val_startingpoint = encodeURI(el_startingpoint.options[el_startingpoint.selectedIndex].value);
    } else {
        var val_startingpoint='all';
    }
	
	var el_sel =document.getElementById('id_sel');
	var val_sel = el_sel.options[el_sel.selectedIndex].value;
	var el_sel_from =document.getElementById('id_sel_from');
	var val_sel_from = el_sel_from.options[el_sel_from.selectedIndex].value;
	var el_sel_to =document.getElementById('id_sel_to');
	var val_sel_to = el_sel_to.options[el_sel_to.selectedIndex].value;

	am.getInfoPane('am_AssistantPane').useScriptSrcIO = false;
	
	var assistant_url = '/rhoen/site/regional_portal/assistant.php?source='+source+'&app='+app+'&sourceid='+sourceid+'&lang='+lang+'&commune='+commune+'&geoactivetype='+geoactivetype+'&action='+action+'&current_page=1&sel='+val_sel+'&tourfocus='+val_tourfocus+'&startpoint='+val_startingpoint+'&from='+val_sel_from+'&to='+val_sel_to;
	
	if (season!='none') assistant_url += '&season='+season;
	
	am.getInfoPane('am_AssistantPane').setUrl(assistant_url);
}

function close_image(){
	 prev_pic="";
}


function selectGalleryImage(idx, thumb_node) {
 	                dojo.byId("hg_photo").src = dojo.html.getAttribute(thumb_node, "largesrc");
 	                dojo.byId("hg_caption").innerHTML =  dojo.html.getAttribute(thumb_node, "title");
}


function show_gallery_image(end, id, imgpath, text, str_image_paths, str_image_texts){

 document.getElementById('text').innerHTML = text;
 document.getElementById('image').onload = function setExt () {

        document.getElementById('previmage').onclick = function prev_pic(){
	 											pic_id = id-1;
												if (pic_id>0) {
   													arr_image_paths = str_image_paths.split(" ");
   													arr_image_texts = str_image_texts.split("|");
										            pic_path = arr_image_paths[pic_id-1];
													pic_text = arr_image_texts[pic_id-1];
													dojo.lfx.html.fadeOut('image', 500, dojo.lfx.easeIn,function callback () {show_gallery_image(end, pic_id, pic_path, pic_text, str_image_paths, str_image_texts)}).play();
     											}
											   };

        document.getElementById('nextimage').onclick = function next_pic(){
	 											pic_id = id+1;
													arr_image_paths = str_image_paths.split(" ");
   													arr_image_texts = str_image_texts.split("|");
												if (pic_id<=arr_image_paths.length) {
										            pic_path = arr_image_paths[pic_id-1];
													pic_text = arr_image_texts[pic_id-1];
													dojo.lfx.html.fadeOut('image', 500, dojo.lfx.easeIn,function callback () {show_gallery_image(end, pic_id, pic_path, pic_text, str_image_paths, str_image_texts)}).play();
     											}
											   };

        if (prev_pic != 'image_div') {
          dojo.widget.byId('GalleryDialog').show();
          document.getElementById("image_div_inv").style.visibility= 'visible';
        }

        dojo.lfx.html.fadeIn('image', 500).play();
        prev_pic = end;

  }

 document.getElementById('image').src = imgpath;
 document.getElementById('image').alt = text;
}


function buildlink() {
    var to = "";
    var from = "";
	var link = "";
    if (document.getElementById('sel2').checked) {
        from = document.getElementById('from').value;
		to = document.getElementById('selection1').value;
		link = "http://reiseauskunft.bahn.de/bin/query.exe/dn?datesel=custom&searchMode=ADVANCED&REQ0JourneyStopsZA=1&REQ0JourneyStopsSA=1&selection=&REQ0JourneyStopsZG=" + escape(to) + "&REQ0JourneyStopsSG=" + escape(from);
    }
    if (document.getElementById('sel3').checked) {
		to = document.getElementById('to').value;
		from = document.getElementById('selection2').value;
		link = "http://reiseauskunft.bahn.de/bin/query.exe/dn?datesel=custom&searchMode=ADVANCED&REQ0JourneyStopsZA=1&REQ0JourneyStopsSA=1&selection=&REQ0JourneyStopsZG=" + escape(to) + "&REQ0JourneyStopsSG=" + escape(from);
    }
	if (document.getElementById('sel1').checked) {
		to = document.getElementById('sel1').value;
		link = "http://reiseauskunft.bahn.de/bin/bhftafel.exe/dn?input=" + escape(to) + "&productsFilter=1111111111";
    }
	document.getElementById('link').href = link;
}


function assistantOnPage(source, app, sourceid, lang, geoactivetype, action, current_page, sel, tourfocus, startpoint, from, to, season) {
	am.getInfoPane('am_AssistantPane').useScriptSrcIO = false;

	url = '/rhoen/site/regional_portal/assistant.php?source='+source+'&app='+app+'&sourceid='+sourceid+'&lang='+lang;
	url += '&geoactivetype='+geoactivetype+'&action='+action+'&current_page='+current_page+'&sel='+sel+'&tourfocus='+tourfocus;
	url += '&startpoint='+startpoint+'&from='+from+'&to='+to;
	
	if (season!='none') url += '&season='+season;

	am.getInfoPane('am_AssistantPane').setUrl(url);

	return false;
}

function createSWF(file, width, height, fullscreen, autostart, id_p) {
        var s1 = new SWFObject('/rhoen/flvplayer/flvplayer.swf','single',width,height,'7');
        s1.addParam('allowfullscreen',fullscreen);
        s1.addVariable('file',file);
        s1.addVariable('width',width);
        s1.addVariable('height',height);
        s1.addVariable('autostart',autostart);
        s1.write(id_p);
}

