function initDirections(){
	// init directions
	gDirectionsPanel = document.getElementById("gMapDirections")
	gDirections = new GDirections(gMap, gDirectionsPanel)
}

function showDirections(from, to) {
	// show directions
	gDirections.load("from: " + from + " to: " + to)
}

function showDirectionsToWinkel(frm) {
	var lat_to = frm.lat_to.value
	var lng_to = frm.lng_to.value
	var to = lat_to + "," + lng_to
	var coords_to = new GLatLng(parseFloat(lat_to), parseFloat(lng_to))
		
	gGeocoder.getLatLng(frm.address.value, function(point) {
		if (!point) {
			alert(frm.address.value + " niet gevonden.")
		} else {
			var lat_from = point.lat()
			var lng_from = point.lng()
			var from = lat_from + "," + lng_from
			// show directions
			showDirections(from, to)
		}
	})
}

function showDirectionsInPopup(frm) {
	
	if(trim(frm.address.value).length > 0) {
		gGeocoder = new GClientGeocoder()
		gGeocoder.getLatLng(frm.address.value, function(point) {
			if (!point) {
				alert(frm.address.value + " niet gevonden.")
				return false
			} else {
				var lat_from = point.lat()
				var lng_from = point.lng()
				var from = lat_from + "," + lng_from
				
				// open popup
				var url = _webfolder + 'view.cfm?website_id=' + _website_id + '&template=directions&object_id=' + frm.object_id.value + '&from=' + from
				var newWin = window.open(url, 'directionsPopup', "width=800,height=600,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no", true)
				
				// focus on popup
				newWin.focus()
				
				return newWin
			}
		})
	
	} else {
		alert("Voer een start punt is!")
		return false
	}
}

function showDirectionsInIFrame(frm) {
	if(trim(frm.address.value).length > 0) {
		theAddress = frm.address.value
		
		// do some trick if a zip is entered
		if (theAddress.match("^([1-9]{1}[0-9]{3}) ?([a-zA-z]{2})?$")) {
			theAddress = theAddress.replace("^,? ?(nl|nederland|netherlands)$", "")
			theAddress += ", NL"
		}
		
		gGeocoder = new GClientGeocoder()
		gGeocoder.getLatLng(theAddress, function(point) {
			if (!point) {
				alert(frm.address.value + " niet gevonden.")
				return false
			} else {
				var lat_from = point.lat()
				var lng_from = point.lng()
				var from = lat_from + "," + lng_from
				
				// open popup
				var url = _webfolder + 'view.cfm?website_id=' + _website_id + '&template=directions&orgkey=' + frm.orgkey.value + '&from=' + from
				// load url into iframe
				if (!browserDetect.isIE) displayIFrame(true)
				oIFrame.src = url
			}
		})
	
	} else {
		alert("Voer een start punt is!")
		return false
	}
}

function displayIFrame(bln) {
	var dsp = (bln == true) ? 'block' : 'none'
	// set new height of iframe
	setTimeout('resizeIFrame()', 250)
	// show iframe
	document.getElementById('overlay').style.display = dsp
	document.getElementById('lightbox').style.display = dsp
	document.getElementById('lightbox_contents').style.display = dsp
}

function resizeIFrame() {
	var xtrHeight = 0
	if (!browserDetect.isIE) xtrHeight = 15
	
	if (oIFrame && oIFrame.document && typeof(oIFrame.document.body) == 'object')
		oIFrame.style.height = oIFrame.document.body.offsetHeight + 'px'
	else if (oIFrame && oIFrame.contentDocument && typeof(oIFrame.contentDocument.body) == 'object')
		oIFrame.style.height = (oIFrame.contentDocument.body.offsetHeight + xtrHeight) + 'px'
}

function resetIFrame() {
	if (!browserDetect.isIE) oIFrame.src = _webfolder + 'view.cfm?website_id=' + _website_id + '&template=loading'
	hideIFrame()
}

function hideIFrame() {
	var dsp = 'none'
	// hide
	document.getElementById('lightbox_contents').style.display = dsp
	document.getElementById('lightbox').style.display = dsp
	document.getElementById('overlay').style.display = dsp
}
