
function getLangInt(langStr) {
	if (langStr=="es")
		return 1;
	else if (langStr=="pt")
		return 2;
	return 0;
}

function getLangStr(langInt) {
	if (langInt==1)
		return "es";
	else if (langInt==2)
		return "pt";
	return "en";
}

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);
}

function showVentrilo() {
	// switch the 'Spotlight' section of the website to ventrillo status after login
	sHTML = 'Ventrilo VOIP Server<BR><font class=whitetiny>Password: ask a Marshal in the lobby</font><iframe width=186 height=250 frameborder=0  src="http://view.light-speed.com/ventrilo.php?IP=vent17.light-speed.com&PORT=8686&STYLE=2&CHANNEL_WNOUSER=NO&SHOW_IP_PORT=YES&HELP=YES&CONLINK=NO&WIDTH=160&FONTSIZE=10&BGCOLOR=561303&SN_BGCOLOR=003300&SN_COLOR=FFFFFF&INFO_BGCOLOR=669966&INFO_COLOR=FFFFFF&HELP_BGCOLOR=CCCC99&HELP_COLOR=000000&CHANNEL_BGCOLOR=CCCCCC&CHANNEL_COLOR=FFFFFF&UN_BG=000000&UN=FFFFFF" />';
	var fl = top.findRootElement('divSpotlight');
	fl.innerHTML = sHTML;	
	// refresh every 1 minute
	setTimeout('showVentrilo();', 60000);
}

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 = "";
		showVentrilo();
		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"));
		if (readCookie("lang")>0) {
			ls = getLangStr(readCookie("lang"));
			top.viewLanguage = ls;
			top.translateDivs(top.document,ls,false);
		}
	}
	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 = "";
		showVentrilo();
		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"));
		if (readCookie("lang")>0) {
			ls = getLangStr(readCookie("lang"));
			top.viewLanguage = ls;
			top.translateDivs(top.document,ls,false);
		}
	}
	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: ''}); 
}

