var mWindows = false;
var oCount = 0;
var HP = null;
var isBlocked = (navigator.appVersion.indexOf('MSIE') > -1 && document.all && !window.opera);
var SmartView = false;
var activePage = false;
var isLoaded = false;
var actP = false;
var maxP = false;
var changeTrys = 0;

if (top.addEvent) { top.addEvent(this, 'load', createNavigation); }

window.onerror = errHandler;

function OpenWindow(UrlToShow) {
	var posNN, actNN, actWin;
	var topWin = getOpener(top).top;
	var winSize, winOffset, aw, winName;
	winName = '';
	var availW = screen.availWidth || 800;
	var size = [0, 0, 0, 0];
	if (!isNaN(screen.availLeft)) { size[1] = screen.availLeft + (availW < 1025 ? availW - 781 : availW - 921); } 
	else { size[1] = (availW < 1025 ? availW - 781 : availW - 921); }
	size[2] = availW < 1025 ? 781 : 921;
	size[3] = availW < 1025 ? 530 : 600;
	UrlToShow = UrlToShow.toLowerCase();
	if (UrlToShow.indexOf('gu.asp') > -1) {
		UrlToShow = UrlToShow.replace(/gu.asp/, 'hp.asp');
		UrlToShow = UrlToShow.replace(/&id=/, '&startgid=');
		UrlToShow = UrlToShow + '&show=gal';
	}
	else if (UrlToShow.indexOf('videos.asp') > -1) {
		UrlToShow = UrlToShow.replace(/videos.asp/, 'hp.asp');
		UrlToShow = UrlToShow.replace(/id=/, 'show=vid&uid=');
	}
	posNN = UrlToShow.indexOf("nickname=") + 9;
	actNN = UrlToShow.substr(posNN, UrlToShow.length - 1);
	if (actNN.indexOf('&') > 1) {
		actNN = actNN.substring(0, actNN.indexOf('&'));
	}
	actNN = actNN.replace(/\W/gi, '_').toUpperCase();
	if (/(hp_new|hp|gu|ug|gb|videos)\.asp/.test(UrlToShow)) {
		winName = 'HP' + ((getTopVar('UserSettingsHpMultiWin', 0) == 1) ? actNN : 'all');
		winSize = getTopVar('GRHPSize', size);
	}

	/* begin chat */
	var chat = { open: ((/(msg|conv)\.asp/.test(UrlToShow)) || (/chat.*\?/.test(UrlToShow))), winH: null, maxH: null, qs: null, ibr: false, vch: '' };
	if (chat.open) {
		chat.winH = screen.availHeight - 300;
		chat.maxH = 664;
		chat.qs = UrlToShow.split('?');
		winName = 'CHAT';
		winSize = getTopVar('GRWinMsgSize', [0, 0, 471, chat.winH]);
		winSize[2] = 518; 
		winSize[3] = ((screen.availHeight - 68) < chat.maxH) ? (screen.availHeight - 68) : chat.maxH;
		if (typeof (topWin.infobar) != 'undefined') { chat.ibr = topWin.infobar; }
		if (chat.ibr) { if (typeof (chat.ibr.IBR_vchat) != 'undefined') { chat.vch = (chat.ibr.IBR_vchat) ? 'v' : ''; } }
		UrlToShow = '/chat/' + chat.vch + 'default.asp?act=tabs&' + chat.qs[1];
		if (!getTopVar('ValidSession', false)) {
		    topWin.focus();
		    try { topWin.forceLogin(); } catch (e) { };
		    return true;
		} 
	} /* end chat */

	if (winName != '') {
		winOffset = getTopVar('GRWinOffset', [0, 0, 0, 0]);
		iTop = winSize[0] - winOffset[0];
		iTop = iTop < 0 ? 0 : iTop;
		iLeft = winSize[1] - winOffset[1];
		iLeft = iLeft < 0 ? 0 : iLeft;
		iWidth = winSize[2] - winOffset[2];
		iWidth = iWidth < 300 ? 300 : iWidth;
		iHeight = winSize[3] - winOffset[3];
		iHeight = iHeight < 300 ? 300 : iHeight;
		var winCount, iCount, iFound;
		winCount = 0;
		iFound = -1;
		if (topWin.w != null) {
			for (iCount = 0; iCount < topWin.w.length; iCount++) {
				try {
					if (topWin.w[iCount] && !topWin.w[iCount].closed) {
						topWin.w[winCount] = topWin.w[iCount];
						if (topWin.w[winCount].name == winName) { iFound = winCount; }
						winCount++;
					}
				} catch (ex) { }
			}
			for (iCount = winCount; iCount < topWin.w.length; iCount++) {
				topWin.w[iCount] = false;
			}
		} else {
			topWin.w = [];
		}
		if (iFound < 0) {
			var openWin = isBlocked ? top : topWin;
			topWin.w[winCount] = openWin.open(UrlToShow, winName, 'width=' + iWidth + ',height=' + iHeight + ',left=' + iLeft + ',top=' + iTop + ',screenX=' + iLeft + ',screenY=' + iTop + ',scrollbars=yes,status=yes,resizable=yes,menubar=no,toolbar=no');
			if (topWin.w[winCount] == null || (typeof topWin.w[winCount]) != 'object') {
				if (top != openWin) {
					topWin.w[winCount] = top.open(UrlToShow, winName, 'width=' + iWidth + ',height=' + iHeight + ',left=' + iLeft + ',top=' + iTop + ',screenX=' + iLeft + ',screenY=' + iTop + ',scrollbars=yes,status=yes,resizable=yes,menubar=no,toolbar=no');
				}
				if (topWin.w[winCount] == null || (typeof topWin.w[winCount]) != 'object') {
					alert(TXT_ALERT_POPUPBLOCK);
				} else {
					isBlocked = true;
					iFound = winCount;
				}
			} else { iFound = winCount; }
		}
		if (iFound > -1) {
			if (winName.indexOf('CONV') == -1 && winName != 'CHAT' && typeof(openWin) == 'undefined') {
				topWin.w[iFound].location.href = UrlToShow;
			}
			if (winName == 'CHAT') {
				if ((typeof (topWin.w[iFound].chats) != 'undefined') && (typeof (topWin.w[iFound].chats.addPartner) != 'undefined')) {
		            var f = UrlToShow.indexOf('filter=');
		            f = (f > -1 && !isNaN(parseInt(UrlToShow.substring(f + 7)))) ? parseInt(UrlToShow.substring(f + 7), 10) : 0;
					var tw = topWin.w[iFound].chats;
					var nx = getNN(UrlToShow);
		            if (chat.vch == 'v') {
		                if (UrlToShow.indexOf('vchat=') != -1) {
                            var v = parseInt(UrlToShow.substring(UrlToShow.indexOf('vchat=') + 6));
		                    v = isNaN(v) ? 2: v;
		            		if (UrlToShow.indexOf('agr=1') != -1) { tw.addPartner(nx, f, v, 1); }
		            		else { tw.addPartner(nx, f, v); }
						} else { tw.addPartner(nx, f); }
					} else { tw.addPartner(nx, f); }
	            } else { topWin.w[iFound].location.href = UrlToShow;}
			}
			topWin.w[iFound].focus();
		}
		return true;
	} else {
		return false;
	}
}
function getNN(url) {
	var io = url.toLowerCase().indexOf("nickname=");
	if (io != -1) {
		var NN = url.substr((io + 9), url.length - 1);
		if (NN.indexOf('&') > 1) { NN = NN.substring(0, NN.indexOf('&')); }
		return NN;
	} else { return ''; }
}
function OpenHPWindow(URL) {
	oCount++;
	if (OpenWindow(URL)) { return; }
	var iLeft = window.screen.availWidth + window.screen.availLeft - 580;
	var iHeight = window.screen.availHeight - 300;
	var iWidth = 570;
	var iTop = 0;
	var Fenster = (mWindows) ? "HP" + oCount : "HP";
	var WinURL = new String();
	WinURL = URL;
	WinURL = WinURL.toLowerCase();
	if (WinURL.indexOf('hp.asp') > -1) {
		WinURL = WinURL.replace(/hp.asp/, 'hp_new.asp');
	}
	else if (WinURL.indexOf('gu.asp') > -1) {
		WinURL = WinURL.replace(/gu.asp/, 'hp_new.asp');
		WinURL = WinURL.replace(/&id=/, '&startgid=');
		WinURL = WinURL + '&show=gal';
	}
	else if (WinURL.indexOf('videos.asp') > -1) {
		WinURL = WinURL.replace(/videos.asp/, 'hp_new.asp');
		WinURL = WinURL.replace(/id=/, 'show=vid&uid=');
	}
	posNN = WinURL.indexOf("nickname=") + 9;

	actNN = WinURL.substr(posNN, WinURL.length - 1);
	actNN = actNN.replace(/./gi, "X");
	actNN = actNN.replace(/_/gi, "Y");
	actNN = actNN.replace(/-/gi, "Z");

	if (WinURL.indexOf("hp_new.asp") >= 0 || WinURL.indexOf("hp.asp") >= 0 || WinURL.indexOf("gu.asp") >= 0 || WinURL.indexOf("ug.asp") >= 0 || WinURL.indexOf("gb.asp") >= 0 || WinURL.indexOf("videos.asp") >= 0) {
		var aw = window.screen.availWidth;
		if (aw < 1025) { iWidth = 781; iHeight = 530; }
		else { iWidth = 921; iHeight = 600; }
		iLeft = screen.availWidth - iWidth;
		iTop = 0;
		var win = null;
		try {
			if (top.opener && !top.opener.closed && top.opener.top && top.opener.top.grnav) {
				if (top.opener.top.grnav.GRHPSize) {
					var HPSize = top.opener.top.grnav.GRHPSize;
				} else {
					var HPSize = [iTop, iLeft, iWidth, iHeight, 0, 0, 0, 0];
					top.opener.top.grnav.GRHPSize = HPSize;
				}
			} else {
				if (top.grnav) {
					if (top.grnav.GRHPSize) {
						var HPSize = top.grnav.GRHPSize;
					} else {
						var HPSize = [iTop, iLeft, iWidth, iHeight, 0, 0, 0, 0];
						top.grnav.GRHPSize = HPSize;
					}
				} else {
					var HPSize = [iTop, iLeft, iWidth, iHeight, 0, 0, 0, 0];
				}
			}
		}
		catch (e) { var HPSize = [iTop, iLeft, iWidth, iHeight, 0, 0, 0, 0]; }
		iTop = HPSize[0] - HPSize[4];
		iTop = iTop < 0 ? 0 : iTop;
		iLeft = HPSize[1] - HPSize[5];
		iLeft = iLeft < 0 ? 0 : iLeft;
		iWidth = HPSize[2] - HPSize[6];
		iWidth = iWidth < 300 ? 300 : iWidth;
		iHeight = HPSize[3] - HPSize[7];
		iHeight = iHeight < 300 ? 300 : iHeight;
		if (UserSettingsHpMultiWin == 1) {
			Fenster = "HP" + actNN;
		}
		else {
			Fenster = "HPsinglewindow";
		}

	}
	if (win != null && typeof (win.top.HP) != 'undefined') {
		HP = win.top.HP;
	} else
		HP = null;
	if (WinURL.indexOf("msg.asp") > -1 || WinURL.indexOf("msg_new.asp") > -1) {
		iWidth = 471;

		if (WinURL.indexOf("id=") == -1) {
			iHeight = 408;
		}
		WinURL = URL;
		myDate = new Date();
		myWin = myDate.getMilliseconds() + "_" + myDate.getMinutes() + "_" + myDate.getHours() + "_" + myDate.getDay() + "_" + myDate.getMonth();
		Fenster = "MSG" + myWin;
		iLeft = 0;
		iTop = 0;
	}
	if ((WinURL.indexOf("history.asp") >= 0) || (WinURL.indexOf("history_dev.asp") >= 0)) {
		WinURL = URL;
		Fenster = "HIST";
		iLeft = 10;
		iTop = 30;
		iWidth = 471;
	}
	var f = self;
	while (f != top) {
		f = f.parent;
	}
	if (WinURL.indexOf("?") == -1) {
		WinURL += "?1=1";
	}
	if (f.name == Fenster) {
		f.document.location.href = WinURL;
		f.focus();
		HP = f;
	} 
	else {
		var fT = "";
		try{fT = HP.name; } catch (e){fT = ""; }
		if (HP != null && fT == Fenster) {
			WinURL = WinURL.replace(/hp.asp/, 'hp_new.asp');
			if (HP.document.location.href.indexOf(WinURL) == -1) { HP.document.location.href = WinURL; }
		} 
		else { HP = window.open(WinURL, Fenster, 'width=' + iWidth + ',height=' + iHeight + ',screenX=' + iLeft + ',screenY=' + iTop + ',left=' + iLeft + ',top=' + iTop + ',scrollbars=yes,status=yes,resizable=yes,menubar=no,toolbar=no'); }
	}
	if (HP == null || (typeof HP) != 'object') { alert(TXT_ALERT_POPUPBLOCK); }
	else { HP.focus(); }
	if (win != null) { win.top.HP = HP; }
}
function OpenPaymentWin(offer) {
	var wWidth = 550;
	var wHeight = (screen.availHeight > 600) ? 685 : 550;
	var wLeft = screen.availWidth / 2 - wWidth / 2;
	var wTop = screen.availHeight / 2 - wHeight / 2;
	var url = '/Account/payment/default.asp';
	if (offer != undefined) { url = url + '?offer=' + offer; }
	PaymentWindow = window.open(url, 'PaymentWindow', 'width=' + wWidth + ',height=' + wHeight + ',screenX=' + wLeft + ',screenY=' + wTop + ',left=' + wLeft + ',top=' + wTop + ',scrollbars=yes,status=yes,resizable=yes,menubar=no,toolbar=no');
	PaymentWindow.focus();
}
function SHSearch(Element) {
	if (document.getElementById || document.all) {
		Container = document.getElementById(Element);
		if (Container.style.display == "none") {
			Container.style.display = "block";
			if (typeof searchBtn != 'undefined' && document.all && !window.opera)
				searchBtn.scrollIntoView(true);
			return false;
		}
		else Container.style.display = "none";
	}
}
function getTopVar(vN, dV) {
	var rV = dV; var w = getOpener(top, 10);
	try {
		if (w.grnav) { w = w.grnav; } else { if (top.grnav) { w = top.grnav; } else { w = null; } }
		if (w != null) { if (typeof (w[vN]) != 'undefined ') { rV = w[vN]; } else { w[vN] = dV; } }
	}
	catch (e) { }
	if (typeof (rV) != typeof (dV) || (typeof (rV) == 'object' && rV.length != dV.length)) { rV = dV; }
	return rV;
}
function GetIcon(Icon, Default) {
	if (typeof (Icon) == "undefined") { return Default; }
	else { return Icon; }
}
function doNav(ev) {
	ev = ev || window.event;
	var el = ev.target || ev.srcElement;
	top.frames['grnav'].grNavGoto(el.getAttribute('Page'));
	try { top.frames['grnav'].grNavGoto(el.getAttribute('Page')) } catch (e) { }
	return false;
}
function InfobarReset() {
	try { if (top.infobar) { top.infobar.IBR_leaveframeEx(); } } catch (e) { }
}
function createNavigation() {
	top.removeEvent(this, 'load', createNavigation);
	if (!actP || !maxP) { return; }
	if (!isLoaded) {
		isLoaded = true;
		setTimeout('createNavigation()', 5);
		return;
	}
	var isSelected = false;
	var selDIV = document.createElement('DIV');
	selDIV.id = 'navigationDIV';
	for (var i = 0; i < maxP; i++) {
		isSelected = (i == actP - 1);
		var newEntry = document.createElement('P');
		newEntry.href = '#';
		newEntry.appendChild(document.createTextNode((i + 1) + "/" + maxP));
		newEntry.setAttribute('Page', (i + 1));
		newEntry.onmousedown = doNav;
		selDIV.appendChild(newEntry);
	}
	selDIV.style.display = 'none';
	selDIV.style.height = (i * 11 > 200 ? 200 : i * 11) + 'px';
	document.getElementsByTagName('FORM')[0].appendChild(selDIV);
}
function showNavigation() {
	if (!actP || !maxP || !isLoaded || document.getElementById('navigationDIV') == null) { return; }
	document.getElementById('navigationDIV').style.top = document.body.scrollTop + 'px';
	document.getElementById('navigationDIV').style.display = 'block';
	activePage = actP;
	setTimeout('this.document.forms[0].focus()', 10);
	top.addEvent(document, 'keydown', keyEvent);
	top.addEvent(document, 'click', hideNavigation);
	top.addEvent(this, 'scroll', hide);
	top.addEvent(this, 'mousewheel', hide);
	top.addEvent(this.document, 'mousewheel', hide);
}
function hideNavigation() {
	if (!actP || !maxP || !isLoaded || document.getElementById('navigationDIV') == null) { return; }
	top.removeEvent(document, 'keydown', keyEvent);
	top.removeEvent(document, 'click', hideNavigation);
	top.removeEvent(this, 'scroll', hide);
	top.removeEvent(this, 'mousewheel', hide);
	top.removeEvent(this.document, 'mousewheel', hide);
	document.getElementById('navigationDIV').style.display = 'none';
}
function hide(ev) {
	ev = ev || window.event;
	el = ev.target || ev.srcElement;
	if (el == this || el == this.document || el == null) { hideNavigation(); }
}
function keyEvent(ev) {
	ev = ev || window.event;
	var myKeyCode = ev.keyCode || ev.which;
	switch (myKeyCode) {
		case 27:
			hideNavigation();
			break;
		case 38:
			activePage--;
			activePage = (activePage < 0) ? 0 : activePage;
			if (document.getElementById('navigationDIV').childNodes.length - activePage > 10) { document.getElementById('navigationDIV').childNodes[activePage].scrollIntoView(true); }
			break;
		case 40:
			activePage++;
			if (document.getElementById('navigationDIV').childNodes.length - activePage > 10) { document.getElementById('navigationDIV').childNodes[activePage].scrollIntoView(true); }
			break;
	}
	top.stopEvent(ev);
}
function doChangeDesign(doit) {
	changeTrys++;
	if ((changeTrys > 2) && top.grnav && top.grnav.ChangeDesign && top.grnav.dsg) {
		if (isNaN(doit)) {
			top.grnav.did = top.grnav.dsg.dsi;
			top.grnav.ChangeStyles();
		} else {
			top.grnav.ChangeDesign(doit);
		}
	} else {
		if (changeTrys < 10)
			setTimeout('doChangeDesign("' + doit + '")', 500);
	}
}
function makeIEInputNice() {
	if (navigator.appVersion.indexOf('MSIE') > -1 && document.all && !window.opera) {
		var ix = document.getElementsByTagName('INPUT');
		for (var i = 0; i < ix.length; i++) {
			if (ix[i].type == 'radio' || ix[i].type == 'checkbox') {
				ix[i].style.backgroundColor = 'transparent';
				ix[i].style.borderWidth = '0px';
			}
		}
	}
}
function getOpener() {
	var w = arguments.length > 0 ? arguments[0] : self;
	var i = 0; var j = arguments.length > 1 ? arguments[1] : 10; var x;
	try {
		while (w.opener && !w.opener.closed && i < j) {
			if (typeof (w.opener.top) == 'object' && typeof (w.opener.top.location) == 'object' && (x = w.opener.top.name))
			{ w = w.opener.top; i++; } else { i = j; }
		}
	} catch (e) {
		if (typeof (w) != 'object' || typeof (w.location) != 'object') w = self;
	}
	return w;
}
function fChange(NickName) { NickName = NickName.replace(/-/gi, ""); NickName = NickName.replace(/./gi, ""); return NickName; }
function setBuddy(NickName) { window.open("/Freunde/list.asp?NickName=" + NickName + "&Type=hidden", "buddy", "width=100,height=100,scrollbars=no,resizable=no,menubar=no,toolbar=no,screenX=200000,screenY,20000,left=20000,top=20000"); }
function showMsg(NickName, Icon) { Icon = GetIcon(Icon, "/images/gr2/Nachricht.gif"); Title = TXT_ICO_MSG.replace(/\%\%NICKNAME\%\%/, NickName); document.writeln("<a href=\"#\" onclick=\"OpenHPWindow('/Homepages/msg.asp?Nickname=" + NickName + "');return false;\" title=\"" + Title + "\"><IMG vspace=\"2\" width=\"15\" height=\"15\" border=\"0\" SRC=\"" + Icon + "\"></a>"); }
function showFav1(NickName, Icon) { Icon = GetIcon(Icon, "/images/gr2/delfav.gif"); document.writeln("<a href=\"#\" onclick=\"setBuddy('" + NickName + "');return false;\" title=\"" + TXT_ICO_FAV1 + "\"><img vspace=\"2\" src=\"" + Icon + "\" width=\"15\" height=\"15\" border=\"0\"></a>"); }
function showFav2(NickName, Icon) { Icon = GetIcon(Icon, "/images/gr2/favorit.gif"); document.writeln("<a href=\"#\" onclick=\"setBuddy('" + NickName + "');return false;\" title=\"" + TXT_ICO_FAV2 + "\"><img vspace=\"2\" src=\"" + Icon + "\" width=\"15\" height=\"15\" border=\"0\"></a>"); }
function showG(NickName, Icon) { Icon = GetIcon(Icon, "/images/gr2/galerie.gif"); document.writeln("<a href=\"#\" onclick=\"OpenHPWindow('/Homepages/gu.asp?Nickname=" + NickName + "');return false;\" title=\"" + TXT_ICO_GAL + "\"><IMG vspace=\"2\" width=\"15\" height=\"15\" border=\"0\" SRC=\"" + Icon + "\"></a>"); }
function tdOut(Element) { Element.className = Element.className.replace("_over", ""); }
function tdOver(Element) { Element.className = Element.className + "_over"; }
function tdClick(Element) { Element.children[0].click(); }
function MLOver(was) { if (document.all || document.documentElement || window.opera) { was.style.backgroundColor = "#277ABA"; } }
function MLOut(was) { if (document.all || document.documentElement || window.opera) { was.style.backgroundColor = "#003863"; } }
function MLGo(was) { parent.frames['content'].location = was; }
function errHandler() { return true; }
function retFalse() { if (!window.opera) return false; }
function OpenCenterWin(URL, Name, Width, Height) { var wWidth = Width; var wHeight = Height; var wLeft = screen.availWidth / 2 - wWidth / 2; var wTop = screen.availHeight / 2 - wHeight / 2; NewCenterWin = window.open(URL, Name, 'width=' + wWidth + ',height=' + wHeight + ',screenX=' + wLeft + ',screenY=' + wTop + ',left=' + wLeft + ',top=' + wTop + ',scrollbars=yes,status=yes,resizable=yes,menubar=no,toolbar=no'); NewCenterWin.focus(); }
function ChangeRegion() { Selection = document.konfigform.Land.value; while (document.konfigform.Region.length > 1) document.konfigform.Region.options[document.konfigform.Region.length - 1] = null; if (Selection > 0) { x = eval("Region" + Selection); for (i = 1; i <= x.length - 1; i++) { NewValue = new Option(x[i], i); document.konfigform.Region.options[document.konfigform.Region.length] = NewValue; } } document.konfigform.Region.selectedIndex = 0; }
function SelectByValue(Element, Value) { Element = eval("document.konfigform." + Element); for (i = 0; i < Element.options.length; i++) { if (Element.options[i].value == Value) { Element.options[i].selected = true; break; } } }
