window.onresize = null;

var absoluteServerPath_Hostname = 'http://' + location.hostname;

var absoluteServerPath = {
    efa : absoluteServerPath_Hostname,
    vlTiles: 'http://maps1.anachb.at',
    mapTiles : 'http://maps1.anachb.at',
    mapBroker: absoluteServerPath_Hostname,
    virtDir: absoluteServerPath_Hostname + '/vip2/'
};

function divlink(anker) {
    
    if (window.location.hash) {
        window.location.href = window.location.href.replace(/#\w+/, '#'+anker);
        return;
    }
    window.location.href += '#' + anker;
}

function setMapHeight () {
    if (mdvMap && mdvMap.mdvMap) {
	 	mdvMap.mdvMap.resize();
	 	if (mdvMap.mdvMiniMap) {
            mdvMap.mdvMiniMap.resize();
        }
    }
}

function ResizeMap() {
    return true;
}

function openAdvancedOption(id, noToggle) {
	
    var elem = mdvLib.$(id);
 
    if (!elem) {
        return;
    }

    mdv.common.createBlockDiv();
    
    // put popupDiv at centre of screen...
    mdvLib.style([elem], {
        top:  '100px',
        left: ((mdv.common.getInnerBrowser().width - parseInt(mdv.common.getStyle(elem, 'width'), 10)) / 2) + 'px',
        zIndex: 5001
    });
    
    if (arguments.length < 2) {
        // ...and display it unless noToggle is set
        mdv.common.toggleElem(elem);
    }	
	
	// resize overlay
	if (document.getElementById(id) && document.getElementById(id).offsetHeight > mdv.common.getInnerBrowser().height - 200) {
		document.getElementById(id).style.height = mdv.common.getInnerBrowser().height - 200 + 'px';
		document.getElementById(id + '_content').style.height = mdv.common.getInnerBrowser().height - 224 + 'px';
	}
}

function closeAdvancedOption(id) {
    mdv.common.toggleElem(mdvLib.$(id));
    mdv.common.undoBlockDiv();
}

function openMyRouteOptions () {
	document.forms[0].itdLPxx_individualRoute.value = '1';
}

function resetButton (language, currentPage) {
    location.href= window.location.pathname;
}

MDVMapEFATrips.prototype.processMarkers = function () {

		var sessionID=0; var requestID=0;
		
		// We need session and request for distributed map fetching
		for (var p=0; p < this.response.parameters.length; p++ ) {
			if (this.response.parameters[p].name == 'sessionID')
				sessionID = this.response.parameters[p].value;
			if (this.response.parameters[p].name == 'requestID')
				requestID = this.response.parameters[p].value;
		}
		
		var markers = new Array();
		
		// store references to markers in a sequence
  		for(var p=0; p < this.polylines.length; p++) {
  			var polyline = this.polylines[p];
  			markers.push([p, 'departure', polyline.markers['departure']]);
  			markers.push([p, 'arrival', polyline.markers['arrival']]);		
  		}
		
  		var map = '';
		var size = new MDVPoint(220, 124);
		
		if (this.mdvMap.config.get('trips.marker.size.width') && this.mdvMap.config.get('trips.marker.size.height'))
			size = new MDVPoint(this.mdvMap.config.get('trips.marker.size.width'), this.mdvMap.config.get('trips.marker.size.height'));
  		
  		// process the sequence; add tool tip for each marker; add marker to layer
  		for (var m=markers.length-1; m >= 0; m--) {
  			var marker = markers[m];  			
  			
  			var text = '';
  			
			if (marker[2].point && marker[2].point.desc)
		  		text = marker[2].point.desc;
		  	
            // make img path absolute for plone            
            text = text.replace(/img src="img/g, 'img src="/intermodal/img');    
                
		  	if (this.mdvMap.config.get('useBubbleForEFATrips') && this.mdvMap.config.get('useBubbleForEFATrips') == 'false') {
		  		marker[2].setToolTip(this.mdvMap.createToolTip(text));
		  	} else {
		  		marker[2].setToolTip(this.mdvMap.createToolTip(size, text));
		  	}				
			
			// force addMarker to supress re-draw
			this.layer.addMarker(marker[2], false);
  		}  		
		
  };

function stopEvent(e) {
    
    if (!e) {
        return true;
    }

    e.cancelBubble = true;
    e.returnValue = false;

    if (e.stopPropagation) {
        e.stopPropagation();
    }
    if (e.preventDefault) {
        e.preventDefault();
    }
    return false;
 };
