
function login() {  
    var delay = 300;
    isLogged = readCookie("loggedIn");
    if (isLogged=="1") {
    	delay = 1300;
    }
	target = 'loginStatus';
	url = 'login.php';
	theForm = findLastForm('frmLogin');
	parms = "Username=" + theForm.Username.value + "&Password=" + theForm.Password.value;	
	myAjax = new Ajax.Updater(target, url, {method: 'post', postBody: parms});
	setTimeout('afterLogin();', delay);
}

function cookieLogIn() {  
	target = 'loginStatus';
	url = 'login.php';
	myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: ''});
	setTimeout('afterLoginCookie();', 200);
}

var repostedLogin=0;
function afterLogin() {
    isLogged = readCookie("loggedIn");
	if (isLogged=="0") {
	    if (repostedLogin>=10)
	 		showContentWithTitle("error", "loginerror.html"); 
	 	else {
	 	 	repostedLogin++;
			setTimeout('afterLogin();', 300);
	 	}
	}
	else if (isLogged=="1") {
		repostedLogin=0;
	    showLoginPanel('none');
		top.findRootElement('time').style.height = "95px";
		top.findRootElement('time').style.width = "140px";
		top.findRootElement('divDownload').innerHTML = "";
		top.findRootElement('divToolIcons').style.visibility = "";
		top.myGangName = readCookie("gangName");
		top.phptarget.location = "loadBookmarks.php";
		if (top.autoContent==1)
			setTimeout("top.javaShowTargetPage();", 300);
		else
			setTimeout("showContent('forums2/index.php');", 300);
		if (readCookie("webbg")>0)
			top.setWebBackground(readCookie("webbg"));
	}
	else 
		setTimeout('afterLogin();', 150);
}

function afterLoginCookie() {
    isLogged = readCookie("loggedIn");
	if (isLogged=="0") {
		if (top.autoContent==1)
			setTimeout("top.javaShowTargetPage();", 1);
	}
	else if (isLogged=="1") {
		showLoginPanel('none');
		top.findRootElement('time').style.width = "140px";
		top.findRootElement('time').style.height = "95px";
		top.findRootElement('divDownload').innerHTML = "";
		top.findRootElement('divToolIcons').style.visibility = "";
		top.phptarget.location = "loadBookmarks.php";
		if (top.autoContent==1)
			setTimeout("top.javaShowTargetPage();", 300);
		else
			setTimeout("showContent('forums2/index.php');", 300);
		if (readCookie("webbg")>0)
			top.setWebBackground(readCookie("webbg"));
	}
	else 
		setTimeout('afterLoginCookie();', 100);
}

function logout() {
	target = 'loginStatus';
	url = 'logout.php';
	myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: ''}); 
	showLoginPanel('');
	top.findRootElement('divToolIcons').style.visibility = "hidden";
}

function stayLogged2() {
	top.phptarget.location='stayLogged.php'; 
}

function stayLogged() {
    setTimeout('stayLogged2();', 3000);
	target = 'loginStatus';
	url = 'login.php?stayLogged=1';
	myAjax = new Ajax.Updater(target, url, {method: 'get', parameters: ''}); 
}
