var _appName=navigator.appName.toLowerCase(),_appVer=navigator.appVersion.toLowerCase()
var _ns=(_appName.indexOf('netscape')>=0)||(_appName.indexOf('mozilla')>=0),_ie=!_ns
var _mac=(_appVer.indexOf('macintosh')>=0)||(_appVer.indexOf('macos')>=0),_win=_appVer.indexOf('win')>=0
var _macIE=_ie&&_mac,_macNS=_ns&&_mac,_NULL
var _ie4=_ie&&(_appVer.indexOf("msie 4")>0),_moz=_ns&&parseInt(_appVer)>=5,_ns4=_ns&&!_moz
var _charCodes="¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ",_idCnt=1
function convStr(str,allowHTML)
{
	if (str==null) return null
	if (typeof(str) != "string") return str
	if (allowHTML==null) allowHTML=false
	var strOut="",c,code
	for (i=0;i<str.length;i++)
	{
		c=str.charAt(i)
		code=str.charCodeAt(i)
		if (_macIE)
		{
			if (code>127) c="&#"+code+";"	
			if (code<0) c="&#"+(256+code)+";"
		}
		if (_macNS) c=translateChar(c)

		if (!allowHTML)
		{
			if (c=="<") c="&lt;"
			if (c==">") c="&gt;"
			if (c=="&") c="&amp;"
			if (c=="'") c="&#39;"
		}
		strOut+=c
	}
	return strOut
}
function translateChar(c)
{
	if (_globalStringTable)
	{
		var index=_charCodes.indexOf(c)
		if (index>0) return _globalStringTable.charAt(index)
	}
	return c
}
var cbSign = null
function Cookie( name, value )
{
	this.name = name
	this.value = value 
	this.expires = null
	this.path = null
	this.domain = null
	this.secure = false
	this.Put = Cookie_Put
	this.Delete = Cookie_Delete
}
function Cookie_Put(name, value) 
{
	if ( this.name == "" ) return false;
	var cookiestr = this.name + "=" + escape (this.value)
	if ( this.expires ) cookiestr += "; expires=" + this.expires;
	if( this.path )	cookiestr += "; path=" + this.path;
	if ( this.domain ) cookiestr += "; domain=" + this.domain;
	if ( this.secure ) cookiestr += "; secure";
	document.cookie = cookiestr
	return true
}
function Cookie_Delete()
{
	var now = new Date()
	var d = new Date( now.getTime() - 1000 )
	this.expires = d.toGMTString();
	this.Put()
}
function GetCookie( name, defaultvalue ) 
{
	if ( name == "" ) return null;
	var cookie = new Cookie( name, defaultvalue )
	var arg = cookie.name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) 
	{
		var offset = i + alen;
		if (document.cookie.substring(i, offset) == arg)
		{
			var last = document.cookie.indexOf (";", offset);
			if (last == -1)
				last = document.cookie.length;
				
			cookie.value = document.cookie.substring(offset, last)
			break;
		}	
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) 
			break; 
	}
	return cookie;
}
function CheckCookie( redirect )
{
	var name = "Cookie" + escape( new Date() )
	var valueOK = "Cookie"
	var valueNOK = "NoCookie"
	var cookie = new Cookie( name, valueOK )
	cookie.Put()
	cookie = GetCookie( name, valueNOK )
	if ( cookie.value == valueOK )
	{
		cookie.Delete()
		return true;
	}
	else
	{
		if ( redirect )
			document.location.href = redirect
		return false;
	}
	return true;
}
EnterKeyCode = 13
function KeyUpHdl( e )
{
	if( (_ns&&e.which == EnterKeyCode) || (_ie && event.keyCode == EnterKeyCode) ) cbSign()
	return true
}
function VerifyLogin()
{
	var login = theForm.login.value
	if ( login == "" )
	{
		alert( GetLocalized("alert_login") )
		theForm.login.focus()
		return false;
	}
	if ( login.length<login.length > 32 )
	{
		alert( GetLocalized("alert_loginsize") )
		theForm.login.focus()
		return false;
	}
	if ( login.match( /^keeboo/ ) || login.match( /^\-/ ) || login.match( /^\_/ ) )
	{
		alert( GetLocalized("alert_loginforbidden") )
		theForm.login.focus()
		return false;
	}
	if ( login.match( /[^a-zA-Z0-9\-\_]/ ) || !(login.toLowerCase()==login) )
	{
		alert( GetLocalized("alert_logincarforbidden") )
		theForm.login.focus()
		return false;
	}
	return true;
}
function VerifyTruePassword()
{
	var password = theForm.password
	if ( password.value.length < 5 )
	{
		alert( GetLocalized("alert_password") )
		password.focus()
		return false;
	}
	return true;
}
function cbSignIn()
{
	if( !VerifyLogin() ) return false;
	if( !VerifyTruePassword() ) return false;
	if( !CheckCookie( "admin/troublecookie.php" ) ) return false;
	dbgWrite('signin');
	theForm.submit()
	return true;
}
function cbSignUp()
{
	document.location.href = "signing/newwriter.php"
	return true;
}
function BUTTON_cb( name )
{
	var func = eval( "window.cb" + name )
	if ( func ) func()
}
function winWidth()
{
	return _ns?window.innerWidth+(_ns4&&_win?4:0):document.body.offsetWidth
}
function showRequirements()
{
	var prop = "location=0,toolbar=0,resizable=1,scrollbars=0"

	var w = parseInt(GetLocalized( "RequirementsW" ))
	var h = parseInt(GetLocalized( "RequirementsH" ))
	prop += ",width=" + w
	prop += ",height=" + h
	var l,t
	if (_ns)
	{
		l=top.screenX;t=top.screenY+25;
	}
	else
	{
		l=top.screenLeft;t=top.screenTop;
	}
	l+=Math.round((winWidth()-w)/2)	
	if ( _ns4 )
		prop += ',screenX='+l+',screenY='+t
	else
		prop += ',left='+l+',top='+t
	window.open( "about/requirements.htm", "Requirements", prop )
}
function InitSignIn(writer)
{
	theForm = document.forms["SignIn"]
	if( Writer=="" ) 
		theForm.login.focus()
	cbSign = cbSignIn
	if(_ns4)
	{
		document.captureEvents(Event.KEYPRESS);
		document.onkeypress = KeyUpHdl;
	}
	else
		document.onkeyup = KeyUpHdl;
	document.images["libraryImg"].src = libraryImg	
	dbgWrite('homepage','done');
	dbgPrint();	
	return false;
}