function ncl (m,c,l) { document.location.href = m.cells[c].getElementsByTagName('a')[l].href; }
function tcl (m,l) { document.location.href = m.getElementsByTagName('a')[l].href; }
function nwd (m,c,l) { window.open(m.cells[c].getElementsByTagName('a')[l].href); }
function InsSm(sm) { var s = document.form1.stext; s.focus(); s.value += sm;return true; }

function chkField(sField) {
	var v=sField.value; var n=sField.name; var l=v.length; var T=chgFieldOK; var F=chgFieldFalse;
	switch(sField.name)
	{
		case 'sforename': 		z=(l >= 2 )?T:F;break;
		case 'ssurname':		z=(l >= 2 )?T:F;break;	
		case 'sstreet':		z=(l >= 3 && document.getElementById('shousenumber').value.length >=1 )?T:F;break;
		case 'spostalcode':			z=(l > 3 )?T:F;break;	
		case 'splace':			z=(l >=3)?T:F;break;
		case 'ncountrynr':			z=(v != 0 )?T:F;break;	
		case 'nprovincenr':	z=(v != 0 )?T:F;break;	
		case 'nphoneprefixnr':	z=(v != 0 && document.getElementById('nphonenumber').value.length >= 6 )?T:F;break;	
		case 'ssexid':	z=(v == 'male' || v=='female' )?T:F;break;	
		case 'nBirthDay':		var sBirthday = document.getElementById('nBirthDay').value+'-'+document.getElementById('nBirthMonth').value+'-'+document.getElementById('nBirthYear').value;
						z=(sBirthday != '1-1-1998' ) ?T:F;break;
		
		case 'bAGB':			z=(sField.checked)?T:F;break;
	}
	z(n);
}
function chgFieldOK(sField)   { var x='/images/layout/icons/thumbs_'; document.getElementById('IMG_'+sField).src = x+'up.png'; }
function chgFieldFalse(sField){ var x='/images/layout/icons/thumbs_'; document.getElementById('IMG_'+sField).src = x+'down.png'; }
function print_text(nTextNR,sLangID) {
window.open('/'+sLangID+'/raw_text_print/'+nTextNR,'print_text','width=800,height=800,scrollbars=auto');
}
function textCounter(sText,sCount,nLimit)
{
	var matched_char = 0;
	var last_pos = -1;
	var field = document.getElementById(sText);
	var countfield = document.getElementById(sCount);
    var maxlimit = nLimit;

	while ( last_pos != field.value.lastIndexOf("\n") )
	{
		last_pos = field.value.indexOf("\n", last_pos+1);
		if ( last_pos != -1 )
		{
			/*special part for none IE browser*/
			if ( field.value.lastIndexOf("\r") == -1 )
			{
				matched_char++;
			}
		}
	}

	if ( (field.value.length + matched_char) > maxlimit )
	{
		field.value = field.value.substring(0, (maxlimit - matched_char));
		window.alert("Sie haben die maximale Zeichenanzahl von " + maxlimit + " erreicht");
	}
	else
	{
		countfield.value = maxlimit - (field.value.length + matched_char);
	}
}

function dynLoad(sF,sAction,nPK,nS)
{
    alert('deprecated usage of dynLoad found. please alert an moderator: ' + window.location.href);
}

function MozAddEngine(name,ext,cat)
{
    if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) 
	{ 
		window.sidebar.addSearchEngine(
		"http://www.lyrix.at/addons/searchplugin/firefox/"+name+".src",
		"http://www.lyrix.at/addons/searchplugin/firefox/"+name+"."+ext, name, cat
		);
	} else {
	alert("Sorry, you need a Mozilla-based browser to install a search plugin.");
	} 
}

openNotificationPopup = function (doIt, locale, name){
    var popupblocked_de = 'Soeben wurde ein Benachrichtigungsfenster von deinem Browser geblockt.\n Bitte deaktiviere deinen Popup Blocker für Lyrix.at um die Seite korrekt zu nutzen.';
    var popupblocked_en = 'Your Browser prevented a messaging-popup from Lyrix.at! \nPlease disable your Popupblocker for our site lyrix.at!';

    if(doIt){
        var sOpenGB = window.open('/' + locale +'/'+ name,name,"width=300,height=200,left=30,top=50,menubar=yes,resizeable=yes,scrollbars=yes,status=yes,toolbar=yes");
        if(sOpenGB == null && locale == "de") {
            alert(popupblocked_de);
        }
        if(sOpenGB == null && locale == "en") {
            alert(popupblocked_en);
        }
    }
};

toggleUpdate = function( elem, valNew ){
    var valOld = elem.html();
    if(valNew != valOld)
    {
        elem.toggle('fast');
        elem.html(valNew);
        elem.toggle('fast');
    }
};

stats_stayonline = function()
{
        jQuery.ajax({
          type: 'POST',
          url: "/stats_stayonline.php",
          data: { },
          success: function( json)
            {
                var isLoggedIn = json.isLoggedIn;
                var locale = json.locale;
                var userOnline = json.userOnline;
                var lyrix = json.lyrix;
                var user = json.user;
                var hasNewMsg = json.hasNewMsg;
                var hasNewGB = json.hasNewGB;
                var hasNewFriendshipRequest = json.hasFriendshipRequest;
                var hasFriendshipAccepted = json.hasFriendshipAccepted;
                var new_interval = json.interval;

                openNotificationPopup(hasNewGB, locale, 'notify_GBEntry');
                openNotificationPopup(hasNewMsg, locale, 'notify_Message');
                openNotificationPopup(hasNewFriendshipRequest, locale, 'notify_FriendshipRequest');
                openNotificationPopup(hasFriendshipAccepted, locale, 'notify_FriendshipAccepted');

                if(!isLoggedIn)
                {
                    jQuery('#profBtn').hide(400);
                    jQuery('#settingsBtn').hide(400);
                    jQuery('#friendsBtn').hide(400);
                    jQuery('#msgBtn').hide(400);

                }
                else
                {
                    jQuery('#profBtn').show(400);
                    jQuery('#settingsBtn').show(400);
                    jQuery('#friendsBtn').show(400);
                    jQuery('#msgBtn').show(400);
                }

                toggleUpdate(jQuery('#lyrixCntSpan'), lyrix);
                toggleUpdate(jQuery('#userCntSpan'), user);
                toggleUpdate(jQuery('#userOnlineCntSpan'), userOnline);


                window.setTimeout(stats_stayonline, new_interval);
            },
          error: function( ) {f_networkError( );},
          dataType: 'json'
        });
};


changeLang = function(newLang)
{
    document.cookie = 'siteLang='+newLang+';  expires=Thu, 2 Aug 2020 20:47:11 UTC; path=/';

    var newLocation = '';
    if(window.location.href.indexOf('/de/') >= 0 && newLang != "de")
    {
        newLocation = window.location.href.replace(/\/de\//, "/"+newLang+"/");
    }
    if(window.location.href.indexOf('/en/') >= 0 && newLang != "en")
    {
        newLocation = window.location.href.replace(/\/de\//, "/"+newLang+"/");
    }

    if(newLocation != '' && newLocation != window.location.href)
    {
        window.location.href = newLocation;
    }
    else
    {
        window.location.reload();
    }
    return false;
};