// TODO: delete this:
function correctHrefs() {
	document.getElementById('logo').innerHTML = '<a href="/index.php"><img alt="" src="fileadmin/templates/images/logo.png"></a>';
}

window.onload = correctHrefs;


/* *** google maps ******************************************************************** */
/**
 * shows google maps address
 * @param string address
 * @param string info
 * @return void
 */
function showAddress (address, info) {
	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);
							}
						}
	);
}


var gdir;


/**
 * calls method for displaying route in google maps api
 * @param string fromAddress
 * @param string toAddress
 * @param string locale
 * @return void
 */
function setDirections (fromAddress, toAddress, locale) {
  	gdir.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
}


/**
 * Use this function to access information about the latest load() results.
 * @return void
 */
function onGDirectionsLoad () { 
    
}


/**
 * handles error codes passed by google maps api
 * @return void
 */
function handleErrors () {
   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	   displayError("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	   displayError("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.<br /> Error code: " + gdir.getStatus().code);
   
   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	   displayError("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.<br /> Error code: " + gdir.getStatus().code);
   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	   displayError("The given key is either invalid or does not match the domain for which it was given.<br /> Error code: " + gdir.getStatus().code);

   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	   displayError("A directions request could not be successfully parsed.<br /> Error code: " + gdir.getStatus().code);
    
   else displayError("An unknown error occurred.");
}


/**
 * external news something
 * @param string url
 * @return void
 */
function OpenDownload(url){
	window.open("http://www.stb-aktuell.de/efvAufruf.php5?Urlnam="+url+"&Pfad="+document.location,"_blank","location=yes,menubar=no,toolbar=yes,scrollbars=yes,resizable=yes,width="+(screen.height/1.3)+",height="+(screen.height/1.3)+",left="+(screen.width/6)+",top="+(screen.height/10));
	return true;
}



/**
 * shows hint for lang en (only temp)
 * @param object oCaller
 * @return void
 */
function showLangHintEn (oCaller) {
	aTmp = findPos(oCaller);
	oLayer = document.getElementById('lang_hint_en');
	oLayer.style.display = 'block';
	oLayer.style.left = (aTmp[0] - oLayer.offsetWidth + oCaller.offsetWidth) + 'px';
	oLayer.style.top = (aTmp[1] + oCaller.offsetHeight) + 'px';
}


/**
 * hides lang hint
 * @return void
 */
function hideLangHintEn () {
	document.getElementById('lang_hint_en').style.display = 'none';
}


/**
 * 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];
}





