/**
 * JS gfe
 * Created on 07.01.2010
 * Author: Mario Diaz @ mario-diaz.com
 * Project: gfe-blut
 */


/**
 * 
 */
function startFunction () {
	//alert(document.URL);
	iL = document.URL.length;
	sUrl = document.URL;
	sTmp = document.URL.substring(iL - 4, iL);
	//alert(sTmp);
	if (sTmp == 'id=3' || sUrl.indexOf('id=3&') != -1) {
		document.getElementById("footer").style.backgroundImage = "url(fileadmin/Layouts/images/bg_footer.gif)";
	}
	
	// layout got a bug: if screenW <= 1024 then display error. Try to fix it with JS:
	//alert(screen.availWidth);
	if (screen.availWidth <= 1024) {
		alert("correct layout");
		oContainerS = document.getElementById("container").style;
		oContainerS.marginRight = "0px";
		oContainerS.marginLeft = "0px";
		document.body.style.backgroundPosition = 'left';
	}
}




window.onload = startFunction;



/**
 * finds position of element
 * @param object obj
 * @return int array
 */
function findPos (obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft, curtop];
}


var bLoginVisible = false;

/**
 * shows login layer
 * @return void
 */
function showLoginLayer () {
	if (document.getElementById('login_input') && !bLoginVisible) {
		oLogin = document.getElementById('login_input');
		aTmp = findPos(document.getElementById('login_text'));
		//alert(aTmp[0]);
		oLogin.style.visibility = 'visible';
		//oLogin.style.top = (aTmp[1] + 30) + 'px';
		//oLogin.style.left = (aTmp[0] - 100) + 'px';
		document.getElementById("user").focus();
		bLoginVisible = true;
	} else if (bLoginVisible) {
		document.forms['login_form'].submit();
	}
}




var oMap;
var gdir;
var geocoder = null;
var addressMarker;

// TODO: lang


function loadMap () {

  		oMap = new GMap2(document.getElementById("gmaps"));
    	oMap.addControl(new GSmallMapControl());
		oMap.addControl(new GMapTypeControl());
		oMap.enableScrollWheelZoom();
		
		geocoder = new GClientGeocoder();
		// TODO: lang
		showAddress("Altenhöferallee 3, D-60438 Frankfurt am Main, Deutschland", "<span style='font-family: Verdana, Arial, sans-serif;'>Altenhöferallee 3&nbsp;&nbsp;<br />D-60438 Frankfurt am Main<br />Deutschland</span>");
  	
}



function showAddress(address, info, iNum) {
	geocoder.getLatLng(address,
						function (point) {
							if (!point) {
								alert("Could not find postcode " + address);
							} else {
								oMap.setCenter(point, 13);
								var marker = new GMarker(point);
								oMap.addOverlay(marker);
								marker.openInfoWindowHtml(info);
							}
						}
	);
}


function setDirections(fromAddress, toAddress, locale) {
  	gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
}

function handleErrors(){

   alert("An error occurred.");
   
}

function onGDirectionsLoad(){ 
  // Use this function to access information about the latest load()
  // results.

  // e.g.
  // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
}
