// JavaScript Document
var topbar;
var googlemap;
var mapdiv;
var ticker = false;
var left = 840;
var tickerWidth =0;
var traceflag = true;
var tracetarget =false;
var tickerOver =false;
var menuul = null;
var menuulis = false;
var testmodus=false;
var tickerInterval;
var dimension;
var agent;
var homebase = false;

//


window.onload = function () {
		init();
}
function disclaimer() {
	if(!homebase)return;
	url='/index.php?id=49&L=1';
	var wininner;
	new Ajax.Request(url, {
		method: 'get',
		onSuccess: function(transport) {
    		wininner = '<div id="disclaimer">'+transport.responseText.split("<!--TYPO3SEARCH_begin-->")[1].split("<!--TYPO3SEARCH_end-->")[0]+'</div>';
			wininner = wininner.replace(/id\=2\"/, 'id=2" onclick="Dialog.okCallback(); return false"');
	        Dialog.alert(wininner, {className: "alphacube", width:800, buttonClass: "nonedisplay"});
		}
	});
	return false;
}

function flashbanner(){
	return;
	var so = new SWFObject('/fileadmin/template/flashbanner/bannerloys_2.swf', 'flashbanner', "598",  "166",  "8");
	so.useExpressInstall('/fileadmin/template/___js/swfobject1-5/expressinstall.swf');
	so.setAttribute('xiRedirectUrl', 'http://www.loys.de'); 
	so.addParam("wmode", "transparent");
	so.write('flashbanner');
}

function init() {
	//new Insertion.Bottom(document.body, '<div id="flashbanner"></div>');
	//flashbanner();
	if(window.location.host.match(/www\.loys/))homebase=true;
	if(get_query("modus") == "test")testmodus=true;
	//sizeSidebar();
	//topbar = document.getElementById("topbarkerneldefault");
	//if(topbar)topbar.innerHTML = showtopflash();
	mapdiv = $('map');
	if(mapdiv)mapload();
	agent = getAgent();
	startTicker();
	getFondInfo();
	menuul = $('nav').getElementsByClassName('on');
	//nur wenn es eine klasse on gibt
	if(menuul!="" && menuul.length > 0) {
		menuul = menuul[0];
		if(menuul.childNodes.length > 1)menuul=menuul.lastChild;
		else menuul = null;
	}
	else menuul = null;
	return true;
}

function getAgent() {
	if(navigator.appVersion.indexOf("MSIE 5")>-1)return "ie5";
	if(navigator.appVersion.indexOf("MSIE 6")>-1)return "ie6";
	if(navigator.appVersion.indexOf("MSIE 7")>-1)return "ie7";
	else return "standard";
}

/*
function mapload() {
	if (GBrowserIsCompatible()) {
		googlemap = new GMap2(map);
		googlemap.addControl(new GSmallMapControl());
		googlemap.addControl(new GMapTypeControl());
		googlemap.setCenter(new GLatLng(53.155211964490505, 8.186682720184326), 7);
		var point = new GLatLng(53.155211964490505, 8.166682720184326);
		googlemap.addOverlay(createMarker(point, 1));
	}
}

function createMarker(point, number) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml("F�hrungsakademie f�r den Mittelstand GmbH<br />Reinhard Nagel<br />Marie-Curie-Stra�e 1<br />26129 Oldenburg<br /><br />Telefon: 0441 - 361 164 64<br />Telefax: 0441 - 361 164 69");
  });
  return marker;
}
*/
function logoinfo(l, bool) {
	if(!homebase)return;
	if(bool){
		if(l=="de")new Ajax.Updater('logoinfo', '/fileadmin/template/_genuin/_genuin_de.php', { method: 'post', parameters: {ajax: '1', limit: 12} });
		if(l=="en")new Ajax.Updater('logoinfo', '/fileadmin/template/_genuin/_genuin_de.php', { method: 'post', parameters: {ajax: '1', limit: 12} });
		$('logoinfo').style.display="block";
	}
	else $('logoinfo').style.display="none";
	/*
	try {
			urchinTracker('/fileadmin/template/_genuin/_genuin_de.php');
	}
	catch(e) {
		if(testmodus)trace(e);
	}
	*/
}


function getFondInfo(){
	//deutsch vs english
	return true;
	if($('fondinfo')){
		new Ajax.Updater('fondinfo', '/fileadmin/databaseOP/___bewertung_table_de.php?i=4', { method: 'post', parameters: {company: 'example', limit: 12} });
	}
	if($('fundinfo')){
		new Ajax.Updater('fundinfo', '/fileadmin/databaseOP/___bewertung_table_en.php?i=4', { method: 'post', parameters: {company: 'example', limit: 12} });
	}
}

function expande(name) {
	$(name+"_dl").show();
	$("fondinfomore_"+name).hide();
	return true;
}

function getChart(fund) {
	if(!homebase)return;
	if(agent == "ie5")return false;
	dimensions = getPageSize();
	//trace(dimensions[2]+"   "+dimensions[3]);
	wwidth = dimensions[2]-(dimensions[2]/3-100);
	gwidth = wwidth - 100;
	wheight = dimensions[3]-(dimensions[3]/3-80);;
	gheight = wheight - 20;
	Dialog.alert({url: "/fileadmin/databaseOP/LOYS_"+fund+"_chart.php?graphwidth="+gwidth+"&graphheight="+gheight+"&ajax=1", options: {method: 'get'}}, {className: "alphacube", width:wwidth, okLabel: ""});
	try {
		urchinTracker('/fileadmin/databaseOP/LOYS_'+fund+'_chart.php?');
	}
	catch(e) {
	}
	return true;
}
function getChart_en(fund) {
	if(!homebase)return;
	if(agent == "ie5")return false;
	dimensions = getPageSize();
	//trace(dimensions[2]+"   "+dimensions[3]);
	wwidth = dimensions[2]-(dimensions[2]/3-100);
	gwidth = wwidth - 100;
	wheight = dimensions[3]-(dimensions[3]/3-80);;
	gheight = wheight - 20;
	Dialog.alert({url: "/fileadmin/databaseOP/LOYS_"+fund+"_chart_en.php?graphwidth="+gwidth+"&graphheight="+gheight+"&ajax=1", options: {method: 'get'}}, {className: "alphacube", width:wwidth, okLabel: ""});
	try {
		urchinTracker('/fileadmin/databaseOP/LOYS_'+fund+'_chart_en.php?');
	}
	catch(e) {
	}
	return true;
}

function getChartIn(fund, w, h, m) {
	new Ajax.Updater('fundchartbox', '/fileadmin/databaseOP/LOYS_'+fund+'_chart.php?graphwidth='+w+'&graphheight='+h+'&d='+m+'&ajax=1', { method: 'post', parameters: {company: 'example', limit: 12} });
	return true;
}
function getChartIn_en(fund, w, h, m) {
	new Ajax.Updater('fundchartbox', '/fileadmin/databaseOP/LOYS_'+fund+'_chart_en.php?graphwidth='+w+'&graphheight='+h+'&d='+m+'&ajax=1', { method: 'post', parameters: {company: 'example', limit: 12} });
	return true;
}
function getChartIn_en_usd(fund, w, h, m) {
	new Ajax.Updater('fundchartbox', '/fileadmin/databaseOP/LOYS_'+fund+'_chart_en_usd.php?graphwidth='+w+'&graphheight='+h+'&d='+m+'&ajax=1', { method: 'post', parameters: {company: 'example', limit: 12} });
	return true;
}

function get_query(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
		//trace(pair[1]);
      return pair[1];
    }
  } 
  //trace('queryV ' + variable + ' nicht gefunden');
}

function showMenu(o, bool) {
	if(agent == "ie5")return false;
	menuulis = bool;
	if(menuul!=null)hideMenuNow();
	//pr�fen, ob es mindestens zwei kindKnoten gibt, sonst existiert kein untermen�
	if(o.childNodes.length > 1) {
		menuul=o.lastChild;
		menuul.style.zIndex= "1000000";
		menuul.style.display = "block";
	}
	else menuul= null;
}

function hideMenu(o, bool) {
	//if(!bool)setTimeout("hideMenuNow()", 1000);
	//trace("hide");
}
function hideMenuNow() {
	if(agent == "ie5")return false;
	if(menuul==null)return;
	menuul.style.zIndex= "10";
	menuul.style.display = "none";
}


function startTicker() {
	if(!ticker && $('ticker')){
		ticker=$('tickerkernel');
		ticker.update(tickerText+tickerText+tickerText+tickerText+tickerText+tickerText);
		ticker.observe('mouseover', function(event){
			tickerOver  = true;
			clearInterval(tickerInterval);
		});
		ticker.observe('mouseout', function(event){
			tickerOver = false;
			tickerInterval = setInterval("scrollTicker()", 40);
		});
		tickerInterval = setInterval("scrollTicker()", 40);
	}
}
function scrollTicker() {
	left -= 2;
	ticker.style.left = left+"px";
}




function sizeSidebar() {
	if($("sidebareast").getHeight()+100>$("canvaskernel").getHeight())$("canvaskernel").style.height = ($("sidebareast").getHeight()+70)+"px";
}


function mapload() {
	if (GBrowserIsCompatible()) {
		googlemap = new GMap2(document.getElementById("map"));
		googlemap.addControl(new GSmallMapControl());
		googlemap.addControl(new GMapTypeControl());
		googlemap.setCenter(new GLatLng(53.138410706378444, 8.223073482513428), 13);
		var pointing = new GLatLng(53.138410706378444, 8.223073482513428);
		googlemap.addOverlay(createMarker(pointing, 1));
	}
}

function createMarker(point, number) {
  var marker = new GMarker(point);
  GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml("LOYS GmbH <br />Alte Amalinenstr. 30<br />26135 Oldenburg<br /><br />Telefon: (0441) 925 86-0<br />Telefax: (0441) 925 86-11");
  });
  return marker;
}


/**BESCHREIBUNG:
	*Author: Tim Gebken 28.11.2006
	*liest die dimensionen f�r den ViewPort aus
*/
// 
// getPageSize() 
// Returns array with page width, height and window width, height 
// Core code from - quirksmode.org 
// Edit for Firefox by pHaez 
// 
function getPageSize(){ 
	var xScroll, yScroll; 
  
	if (window.innerHeight && window.scrollMaxY) { 
		xScroll = document.body.scrollWidth; 
		yScroll = window.innerHeight + window.scrollMaxY; 
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac 
		xScroll = document.body.scrollWidth; 
		yScroll = document.body.scrollHeight; 
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 
		xScroll = document.body.offsetWidth; 
		yScroll = document.body.offsetHeight; 
	} 
  
	var windowWidth, windowHeight; 
	if (self.innerHeight) { // all except Explorer 
		windowWidth = self.innerWidth; 
		windowHeight = self.innerHeight; 
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode 
		windowWidth = document.documentElement.clientWidth; 
		windowHeight = document.documentElement.clientHeight; 
	} else if (document.body) { // other Explorers 
		windowWidth = document.body.clientWidth; 
		windowHeight = document.body.clientHeight; 
	} 
  
	// for small pages with total height less then height of the viewport 
	if(yScroll < windowHeight){ 
		pageHeight = windowHeight; 
	} else { 
		pageHeight = yScroll; 
	} 

	// for small pages with total width less then width of the viewport 
	if(xScroll < windowWidth){ 
		pageWidth = windowWidth; 
	} else { 
		pageWidth = xScroll; 
	}
	// top/leftScroll modified by timGebken
	var topScroll = document.documentElement.scrollTop || document.body.scrollTop;
	var leftScroll = document.documentElement.scrollLeft || document.body.scrollLeft;
	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight, xScroll, yScroll, leftScroll, topScroll);
	return arrayPageSize;
}

//debugging
var tracebar = '<textarea cols="30" rows="100" id="tracebar" name="trace"></textarea>';
var traceflag = true;
var tracetarget;

function trace(s) {
	if(!traceflag)return;
	if(!tracetarget)startTrace();
	tracetarget.value = s+"\n"+tracetarget.getValue();
}
function startTrace() {
	document.body.innerHTML+=tracebar;
	tracetarget = $('tracebar');
}



/*
 * 2010 for englisch page www.loys-funds.com/index.php=id=49 Disclaimer
 * 
 * 
 * 
 * 
 * 

Juli 2010 => Anfaeng zum Programmieren jQuery hat keine $ mehr, wegen anderes Framework.



function trace(str){
	if(!window.console){
		return;
	}
	else {
		console.log(str);
	}
}
jQuery(function(){
	trace('geht los');
	jQuery('#disclaimerform').submit(function(){
		jQuery('#disclaimerform :checkbox').each(function(){
			trace('submit');
		});
		return false;
	});
});
*/