function k_sendorderinfo()
{
	var name = $('orderinfo-name').value;
	var contact = $('orderinfo-contact').value;
	var message = $('orderinfo-message').value;

	$('orderinfo-fieldsmissing').style.display = 'none';

	if( name == '' || contact == '' || message == '' )
	{
		$('orderinfo-fieldsmissing').style.display = 'block';
		return;
	}

    new Ajax.Request( '/common/ajax/ordering.js.php', {
		method: 'post',
		parameters: { name: name, contact: contact, message: message }
    } );
}

function getWindowHeight()
{
	var windowHeight = 0;
	if( typeof( window.innerHeight ) == 'number')
		windowHeight = window.innerHeight;
	else
	{
		if( document.documentElement && document.documentElement.clientHeight )
			windowHeight = document.documentElement.clientHeight;
		else
		{
			if( document.body && document.body.clientHeight )
				windowHeight = document.body.clientHeight;
		}
	}
	return windowHeight;
}

function getWindowWidth()
{
	var windowWidth = 0;
	if( typeof( window.innerWidth ) == 'number')
		windowWidth = window.innerWidth;
	else
	{
		if( document.documentElement && document.documentElement.clientWidth )
			windowWidth = document.documentElement.clientWidth;
		else
		{
			if( document.body && document.body.clientWidth )
				windowWidth = document.body.clientWidth;
		}
	}
	return windowWidth;
}

function setCenterVertical( contentElement )
{
	if( document.getElementById )
	{
		var windowHeight = getWindowHeight();
		if( windowHeight > 0 )
		{
			var contentHeight = contentElement.offsetHeight;
			contentElement.style.top = ( (windowHeight / 2) - (contentHeight / 2) ) + 'px';
		}
	}
}

function setCenterHorizontal( contentElement )
{
	if( document.getElementById )
	{
		var windowWidth = getWindowWidth();
		if( windowWidth > 0 )
		{
			var contentWidth = contentElement.offsetWidth;
			contentElement.style.left = ( (windowWidth / 2) - (contentWidth / 2) ) + 'px';
		}
	}
}

var mapbox;
var map;
function mapboxOpen( lat, long )
{
	var point = new GLatLng( lat, long );
    map.setCenter( point, 14 );
    map.clearOverlays();
    map.addOverlay( new GMarker( point ) );
	mapbox.style.display = 'block';
}

function mapboxClose()
{
	mapbox.style.display = 'none';
}

function mapboxInit()
{
	mapbox = $('mapbox');
	setCenterVertical( mapbox );
	setCenterHorizontal( mapbox );

    map = new GMap2( $('mapbox-map') );
    map.addControl( new GLargeMapControl() );
    map.addControl( new GMapTypeControl() );
    map.enableScrollWheelZoom();

    var overviewmap = new GOverviewMapControl( new GSize( 150, 100 ) );
    map.addControl( overviewmap );

	mapboxClose();
}

var mouseX;
var mouseY;
var mouseTmpX;
var mouseTmpY;
var mousedown;
function mapboxMove( e )
{
    if( document.all ) // IE
    {
		mouseX = event.clientX + document.body.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop;
    }
    else
    {
		mouseX = e.pageX;
		mouseY = e.pageY;
    }

    if( mouseX < 0 )
		mouseX = 0;
    if( mouseY < 0 )
		mouseY = 0;

    if( mouseTmpX != -1 && mouseTmpY != -1 )
    {
        mapbox.style.left = ( parseInt( mapbox.style.left, 10 ) + ( mouseX-mouseTmpX ) ) + 'px';
		mapbox.style.top = ( parseInt( mapbox.style.top, 10 ) + ( mouseY-mouseTmpY ) ) + 'px';
    }
    mouseTmpX = mouseX;
    mouseTmpY = mouseY;
}

function mapboxDragStart( e )
{
    if( document.all )
    {
        document.attachEvent( "onmousemove", mapboxMove );
        document.attachEvent( "onmouseup", mapboxDragStop );
		window.event.cancelBubble = true;
		window.event.returnValue = false;
    }
    else
    {
		document.addEventListener( "mousemove", mapboxMove, true );
		document.addEventListener( "mouseup", mapboxDragStop, true );
		e.preventDefault();
    }
				    
    if( !mapbox.style.left )
		mapbox.style.left = '0px';
    if( !mapbox.style.top )
        mapbox.style.top = '0px';

    mouseTmpX = -1;
    mouseTmpY = -1;
}

function mapboxDragStop()
{
    if( document.all ) // IE
    {
		document.detachEvent( "onmousemove", mapboxMove );
        document.detachEvent( "onmouseup", mapboxDragStop );
    }
    else
    {
		document.removeEventListener( "mousemove", mapboxMove, true );
		document.removeEventListener( "mouseup",   mapboxDragStop, true );
    }
}

window.onload = function() { setCenterVertical( $('container') ); if( $('mapbox') ) { mapboxInit(); } }
window.onresize = function() { setCenterVertical( $('container') ); }
window.onunload = function() { if( $('mapbox') ) { GUnload(); } }
