var mWindows = false;
var oCount = 0;
var HP = null;

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 OpenPaymentWin(){
	var wWidth  = 550; 
	var wHeight = ( screen.availHeight > 600 ) ? 685 : 550; 
	var wLeft   = screen.availWidth/2 - wWidth/2; 
	var wTop    = screen.availHeight/2 - wHeight/2; 
	PaymentWindow = window.open('/Account/payment/default.asp','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 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 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 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; } } }


function getTopVar(varName, defaultValue) {
    var retValue, mainWin;
    try {
        if (top.opener && !top.opener.closed && top.opener.top && top.opener.top.grnav) {
            if (typeof (top.opener.top.grnav[varName]) != 'undefined ') {
                retValue = top.opener.top.grnav[varName];
            } else {
                retValue = defaultValue;
                top.opener.top.grnav[varName] = defaultValue;
            }
        } else {
            if (top.grnav) {
                if (typeof (top.grnav[varName]) != 'undefined ') {
                    retValue = top.grnav[varName];
                } else {
                    retValue = defaultValue;
                    top.grnav[varName] = retValue;
                }
            } else {
                retValue = defaultValue;
            }
        }
    }
    catch (e) { retValue = defaultValue; }
    if (typeof (retValue) != typeof (defaultValue) || 
        (typeof (retValue) == 'object' && retValue.length != defaultValue.length) ){
        retValue = defaultValue;
    }
    return retValue;
}

function OpenWindow(UrlToShow) {
    var posNN, actNN,actWin;
    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);
    actNN = actNN.replace(/./gi, "X");
    actNN = actNN.replace(/_/gi, "Y");
    actNN = actNN.replace(/-/gi, "Z");
    if (UrlToShow.indexOf("hp_new.asp") >= 0 || UrlToShow.indexOf("hp.asp") >= 0 ||
        UrlToShow.indexOf("gu.asp") >= 0 || UrlToShow.indexOf("ug.asp") >= 0 ||
        UrlToShow.indexOf("gb.asp") >= 0 || UrlToShow.indexOf("videos.asp") >= 0) {
        if (getTopVar('UserSettingsHpMultiWin', 0) == 1) {
            winName = 'HP' + actNN;
        }
        else {
            winName = 'HPall';
        }
        winSize = getTopVar('GRHPSize', size);
	}

	/* Beginn neues Messagefenster */
	var dx = new Date(); 
	var tx = dx.getTime();
	if (UrlToShow.indexOf("msg.asp") > -1) {
		var wHeigh = (UrlToShow.indexOf("id=") != -1) ? (screen.availHeight - 300) : 408;
		winSize    = getTopVar('GRWinMsgSize', [0, 0, 471, wHeigh]).join(',').split(',');
		winSize[2] = (winSize[2] < 471) ? 471 : winSize[2];
		winSize[3] = (UrlToShow.indexOf("id=") != -1) ? winSize[3] : 408;
		winName = 'MSG' + actNN + tx;
	}
	if (UrlToShow.indexOf("msg_new.asp") > -1) {
		winSize    = getTopVar('GRWinMsgSize', [0, 0, 471, 408]).join(',').split(',');
		winSize[2] = (winSize[2] < 471) ? 471 : winSize[2];
		winSize[3] = 408;
		winName    = 'MSGNEW' + tx;
	}
	if (UrlToShow.indexOf("history.asp") > -1) {
		winSize    = getTopVar('GRWinMsgSize', [0, 0, 471, (screen.availHeight - 300)]).join(',').split(',');
		winSize[2] = (winSize[2] < 471) ? 471 : winSize[2];
		winSize[3] = (screen.availHeight - 300);
		winName    = 'MSGHISTORY' + tx;
	}
	/* Ende neues Messagefenster */

    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;
        HP = window.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 (HP == null || (typeof HP) != 'object') {
        	alert(TXT_ALERT_POPUPBLOCK);
        }
        else {
            HP.focus();
        }
        return true;
    } else {
        return false;
    }
}

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 GetIcon(Icon,Default){
	if (typeof(Icon)=="undefined")
		return Default;
	else
		return Icon;
}

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();}

window.onerror = errHandler;

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;
		//default: alert(code);
	}
	top.stopEvent(ev);
 }

var SmartView = false;
activePage = false;
isLoaded = false;
actP = false;
maxP = false;
var changeTrys = 0;

if (top.addEvent) {
	top.addEvent(this, 'load', createNavigation);
}

function doChangeDesign(doit) {
    changeTrys++;
    if ((changeTrys > 2) && top.grnav && top.grnav.ChangeDesign && top.grnav.DesignInfo) {
        if (isNaN(doit)) {
            if (top.grnav.DesignInfo.split('|').length == 4) {
                top.grnav.did = top.grnav.DesignInfo.split('|')(1);
                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) {
        for (var i = 0; i < document.getElementsByTagName('INPUT').length; i++) {
            if (document.getElementsByTagName('INPUT')[i].type == 'radio' ||
                document.getElementsByTagName('INPUT')[i].type == 'checkbox'){
                document.getElementsByTagName('INPUT')[i].style.backgroundColor = 'transparent';
                document.getElementsByTagName('INPUT')[i].style.borderWidth = '0px';
            }
        }
    }
}

