ambobase = '';
ambopage = '{ambopage}';
groupid = '';

setTimeout("AmboInit();", 3000);

function AmboInit(){
	ctSenden('menu');
	ctSenden('content',ambopage);
	ctSenden('overview');
	ctSenden('date');
	ctSenden('version');
	setInterval("AmboRefresh();",120000);
}

function AmboRefresh(){
	if (ambopage.substr(0,11) == "page=server"){ctSenden('content2',ambopage);}
	if (ambopage == "page=online"){ctSenden('content2',ambopage);}
	SendNavBox('server','Status');
}

function AmboRedirect(url){
    setTimeout("ctSenden('content2', '" + url + "', {evalScripts: true});", 1000);
}

function SearchMap(){
	param = '&mapname=' + $F('mapname');
	ctSenden('content2','page=mapsearch' + param);
}

function SearchPlayer(){
	param = '&playername=' + $F('playername');
	ctSenden('content2','page=search' + param);
}

function SendRegister(){
	param = 'page=register';
	param+= '&action=add_user';
	param+= '&groupid=' + $F('groupid');
	ctSenden('content2',param);
}

function SendLogIn(){
	param = '&user=' + $F('user');
	param+= '&pass=' + $F('pass');
	ctSenden('content2','page=login&action=check&formsubmit=1' + param);
    setTimeout("SendLogInSuccess();", 1000);
}

function SendLogInSuccess(){
	ambopage = 'page=kills';
	ctSenden('menu');
	ctSenden('content2',ambopage);
}

function SendLogOut(){
	ctSenden('content2','page=logout');
    setTimeout("SendLogOutSuccess();", 1000);
}

function SendLogOutSuccess(){
	ambopage = 'page=kills';
	ctSenden('menu');
	ctSenden('content2',ambopage);
}

function Ambo2Status(){
	SendNavBox('server','Status');
//	setTimeout("Ambo2Status();",120000);
}

function SendNavBox(file,navbox){
	ctSenden('ambo2' + navbox,'page=' + file + '&navbox=' + navbox);
}
	
function ctSenden(ct,param,opt){
	switch(ct){
	case "menu":
		new Ajax.Updater({success: 'menu'}, 'ambostats_test/index.php?ct=menu' + groupid, {evalScripts: true});
		break;
	case "content":
		new Ajax.Updater({success: 'content'}, 'ambostats_test/index.php?ct=content&page=redirect&action=newpage', {evalScripts: true});
//		setTimeout("ctSenden('content2', '" + param + "', '" + opt + "', {evalScripts: true});", 1000);
		AmboRedirect(param);
		break;
	case "content2":
		ambopage = param;
		new Ajax.Updater({success: 'content'}, 'ambostats_test/index.php?ct=content' + groupid + '&ambotype=phpkit&ambopath=ambostats_test/&' + param, opt, {evalScripts: true});
		break;
	case "overview":
		new Ajax.Updater({success: 'overview'}, 'ambostats_test/index.php?ct=overview', {evalScripts: true});
		break;
	case "date":
		new Ajax.Updater({success: 'date'}, 'ambostats_test/index.php?ct=date', {evalScripts: true});
		break;
	case "version":
		new Ajax.Updater({success: 'version'}, 'ambostats_test/index.php?ct=version', {evalScripts: true});
		break;
	default:
		new Ajax.Updater({success: ct}, 'ambostats_test/index.php?ct=navbox&' + param + '&ambotype=phpkit&ambopath=ambostats_test/', {evalScripts: true});
		break;
	}
}
