var falselogo = false;
var clickedDasviele = false;

function goto(hash)
{

	try {
		var pageTracker = _gat._getTracker("UA-9828962-1");
		pageTracker._trackPageview();
	} catch(err) {}

	undwir_left_moveMe();
	$.history.load(hash);
	if(falselogo == false)
	{
		try{
			document.getElementById('myId').fadeUp();
		}catch(e){}
		falselogo = true;
	}
}


function undwir_left_moveMe(xxx)
{
	//console.info("--> "+xxx);
	try{
		document.getElementById('undwir_left').moveMe(xxx);
	}catch(e){}
}

function setMenu(hash)
{
	try{
		var flash_m = top.document.getElementById('flash_menu');
		flash_m.setHash(hash);
	}catch(e)
	{
		setTimeout(function(){
			try{
				var flash_m = top.document.getElementById('flash_menu');
				flash_m.setHash(hash);
			}catch(e)
			{
				setMenu(hash)
			}
		},100);
	}
}


function setMenuDasViele(hash)
{
	try{
		var flash_m = top.document.getElementById('main_header_swf');
		flash_m.setHash(hash);
	}catch(e)
	{
		setTimeout(function(){
			try{
				var flash_m = top.document.getElementById('main_header_swf');
				flash_m.setHash(hash);
			}catch(e)
			{
				setMenuDasViele(hash)
			}
		},100);
	}
}

var recCheck = 0;

function pageload(hash) {


	document.getElementById('rightbox').innerHTML = "";

	var div_main = "main_wrapper";
	var hash_splitted = hash.split("/");


	var div = "";

	if (hash_splitted.length == 2)
	{
		var frame_holder = hash_splitted[0];
		div = frame_holder+"_wrapper";

		//console.info("Subframe Load Hash: "+hash+" -> "+div);


		if (document.getElementById(div) == null)
		{
			$("#"+div_main).load("getcontent/?"+frame_holder,{},function(){

				setTimeout(function(){

					recCheck++;
					pageload(hash);

				},200);

			});
			return;
		}

	}
	else
	{
		div = div_main;
	}

	recCheck = 0;

	$("#"+div).html('');

	if (hash == "download_media_content")
	{
		show_download_media_content();
		return;
	}


	if(hash) {
		$("#"+div).load("getcontent/?"+hash);
		setMenu(hash);
	} else {
		$("#"+div).load("getcontent/?index");
		setMenu(hash);
	}
}

function ani_done()
{
	goto('start');
}

$(document).ready(function() {
	$.history.init(pageload);
});

var hc = 0;

function headline(text,width,height)
{
	hc++;

	if (typeof height == 'undefined') height = 27;

	document.writeln("<div id='head_"+hc+"' style='width:"+width+"px;height:"+height+"px;'></div>");

	var flashvars = { t: text };
	var params = { menu: "false", wmode: "transparent" };
	var attributes = {
		id	: "head_"+hc,
		name: "head_"+hc
	};
	swfobject.embedSWF("swf/headline.swf", "head_"+hc, width, height, "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
}

function headx(id,text,width,height)
{
	if (typeof height == 'undefined') height = 27;

	var flashvars = { t: text };
	var params = { menu: "false", wmode: "transparent" };
	var attributes = {
		id	: id,
		name: id
	};
	swfobject.embedSWF("swf/headline.swf", id, width, height, "9.0.0", "swf/expressInstall.swf", flashvars, params, attributes);
}


$(document).ready(function() {
	if (document.getElementById('fpopupwrapper') == null)
	{

		var newdiv = document.createElement('div');
		newdiv.setAttribute('id', 'fpopupwrapper');
		newdiv.style.position = "absolute";
		newdiv.style.top = "0px";
		newdiv.style.left = "0px";
		document.body.appendChild(newdiv);

		newdiv.innerHTML = "<div id='fpopup'></div>";

		var flashvars = {};
		var params = {
			menu: "false",
			wmode: "transparent"
		};
		var attributes = {
			id: "fpopup",
			name: "fpopup"
		};
		swfobject.embedSWF("swf/popschup.swf", "fpopup", "300", "300", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
	}

});



function hidePopUp()
{
	document.getElementById('fpopupwrapper').style.top = "-500px";
}

function showPop(e,el,text2show)
{
	el.onmouseout = function() { hidePopUp(); }  //register mouseout event
	var XY = getXY(e); // get mouse XY

	document.getElementById('fpopupwrapper').style.top = (XY.y-300)+"px";
	document.getElementById('fpopupwrapper').style.left = XY.x+"px";
	document.getElementById('fpopup').setInfoTxt(text2show);

}

function getXY(e)
{
	var x,y;
	e = e || window.event;
	if (navigator.appName.indexOf('Microsoft') != -1)
	{
		var parent = e.srcElement;
		x=e.clientX + document.body.scrollLeft;
		y=e.clientY + document.body.scrollTop;
	}
	else
	{
		x =e.pageX
		y= e.pageY
	}
	var XY = new Object();
	XY.x = x;
	XY.y = y;
	return XY;
}


function pwd_vergessen()
{
	var check_mail = document.getElementById('email_vergessen').value.split(' ').join('');

	if (check_mail == "")
	{
		alert("Bitte geben Sie Ihre E-Mail Adresse ein.");
		return;
	}

	$.get("/mediareg/pwd_lost.php",{'m' : check_mail}, function(data){
		alert("Das Passwort wurde per email verschickt. ");
	});
}



function show_download_media_content()
{
	//	document.getElementById('main_wrapper').innerHTML = "";
	$("#main_wrapper").load("/mediareg/show.php");
}

function anmelden()
{
	var email 	= document.getElementById('email').value.split(' ').join('');
	var pwd 	= document.getElementById('pwd').value;

	if ((email == "") || (pwd == ""))
	{
		alert("E-Mail oder Passwort ist nicht angegeben.");
		return;
	}

	$.get("/mediareg/reg_access.php",{'m' : email, 'p' : pwd}, function(data){
		if (data == "NOK")
		{
			alert("E-Mail oder Passwort ist falsch.");
			return;
		}

		goto('download_media_content');

	});
}


function registrieren()
{
	var name 			= document.getElementById('name').value;
	var medium 			= document.getElementById('medium').value;
	var ressort 		= document.getElementById('ressort').value;
	var email_redaktion = document.getElementById('email_redaktion').value;
	var email 			= document.getElementById('email').value.split(' ').join('');
	var pwd 			= document.getElementById('pwd').value;
	var pwd2 			= document.getElementById('pwd2').value;

	if ((email == "") || (pwd == "") || (pwd2 == ""))
	{
		alert("E-Mail oder Passwort ist nicht angegeben.");
		return;
	}

	if (pwd != pwd2)
	{
		alert("Passwörter sind unterschiedlich.");
		return;
	}

	var datax = {
	'name' : name,
	'medium' : medium,
	'ressort' : ressort,
	'email_redaktion' : email_redaktion,
	'email' : email,
	'pwd' : pwd
	};

	$.get("/mediareg/reg_new.php",datax, function(data){
		goto('download_media_content');
	});
}


