
function displayQCalendar(m, y){
    document.getElementById("quickCalender").innerHTML = '<img src="buttons/loading.gif">';
    var xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            if (response) {
                document.getElementById("quickCalender").innerHTML = xmlHttp.responseText;
            }
        }
    }
    xmlHttp.open('GET', '?ajax=yes&module=cal&m=' + m + '&y=' + y);
    xmlHttp.send(null);
}

function displayAllGames(t){
    //document.getElementById("games").innerHTML = '<img src="buttons/loading.gif">';
    var xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            if (response) {
                document.getElementById("games").innerHTML = xmlHttp.responseText;
            }
        }
    }
    xmlHttp.open('GET', '?ajax=yes&module=allgames&team=' + t);
    xmlHttp.send(null);
}

function collapseGames(t){
    //document.getElementById("games").innerHTML = '<img src="buttons/loading.gif">';
    var xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            if (response) {
                document.getElementById("games").innerHTML = xmlHttp.responseText;
            }
        }
    }
    xmlHttp.open('GET', '?ajax=yes&module=collapsegames&team=' + t);
    xmlHttp.send(null);
}


function displayAllResults(t){
    //document.getElementById("results").innerHTML = '<img src="buttons/loading.gif">';
    var xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            if (response) {
                document.getElementById("results").innerHTML = xmlHttp.responseText;
            }
        }
    }
    xmlHttp.open('GET', '?ajax=yes&module=allresults&team=' + t);
    xmlHttp.send(null);
}

function collapseResults(t){
    //document.getElementById("results").innerHTML = '<img src="buttons/loading.gif">';
    var xmlHttp = GetXmlHttpObject();
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            var response = xmlHttp.responseText;
            if (response) {
                document.getElementById("results").innerHTML = xmlHttp.responseText;
            }
        }
    }
    xmlHttp.open('GET', '?ajax=yes&module=collapseresults&team=' + t);
    xmlHttp.send(null);
}


function showCategory(str, num){
    document.getElementById(str).innerHTML = '<img src="buttons/loading.gif">';
    var xmlHttp = GetXmlHttpObject();
    var url = "admin.php";
    var params = "ajax=yes&action=catChoice&catChoice=" + str + "&num=" + num;
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            document.getElementById(str).innerHTML = xmlHttp.responseText;
        }
    }
    xmlHttp.open("POST", url, true);
    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(params)
}

function expandFotolist(str){

    document.getElementById("foto_table").innerHTML = '<img src="buttons/loading.gif">';
    var xmlHttp = GetXmlHttpObject();
    
    var url = "admin.php";
    var params = "ajax=yes&action=expandFotolist&listsize=" + str;
    
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            document.getElementById("foto_table").innerHTML = xmlHttp.responseText;
        }
    }
    xmlHttp.open("POST", url, true);
    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(params);
}

function showGallery(str){
    document.getElementById("gal_edit").innerHTML = '<img src="buttons/loading.gif">';
    var xmlHttp = GetXmlHttpObject();
    var url = "admin.php";
    var params = "ajax=yes&action=galEdit&gall_id=" + str;
    xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            document.getElementById("gal_edit").innerHTML = xmlHttp.responseText;
        }
    }
    xmlHttp.open("POST", url, true);
    //Send the proper header information along with the request
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.send(params);
}


function GetXmlHttpObject(){
    var objXMLHttp = null;
    if (window.XMLHttpRequest) {
        objXMLHttp = new XMLHttpRequest();
    }
    else 
        if (window.ActiveXObject) {
            objXMLHttp = new ActiveXObject('Microsoft.XMLHTTP');
        }
        else {
            alert('Problem creating the XMLHttpRequest object');
        }
    return objXMLHttp;
}

function clearDefault(el){
    if (el.defaultValue == el.value) 
        el.value = ""
}

var bgFlip = 1;
function cycleBackground(){
    switch (bgFlip) {
        case 0:
            document.getElementsByTagName('body')[0].style.background = '#ff8000 url(../buttons/bg.png) repeat-x';
            document.getElementById('bg_flip').innerHTML = 'Black';
            setCookie('FreyungBBall[bg]', 'tequila');
            break;
        case 1:
            document.getElementsByTagName('body')[0].style.background = '#000000';
            document.getElementById('bg_flip').innerHTML = 'Xmas';
            setCookie('FreyungBBall[bg]', 'black');
            break;
        default:
            document.getElementsByTagName('body')[0].style.background = '#ff8000 url(../buttons/xmas_bg.gif) repeat';
            document.getElementById('bg_flip').innerHTML = 'Tequila';
            setCookie('FreyungBBall[bg]', 'xmas');
            break;
    }
    bgFlip++;
    if (bgFlip > 2) 
        bgFlip = 0;
}

var sizeFlip = 0;
function cycleSize(){
    switch (sizeFlip) {
        case 1:
            document.getElementById('wrap').style.width = '750px';
            document.getElementById('head').style.width = '750px';
            document.getElementById('columns').style.width = '750px';
            document.getElementById('left_sidebar').style.width = '150px';
            document.getElementById('main_content').style.width = '585px';
            document.getElementById('main_content').style.left = '150px';
            document.getElementById('footer').style.width = '750px';
            document.getElementById('size_flip').innerHTML = '1024px';
            setCookie('FreyungBBall[screensize]', '800');
            break;
        default:
            document.getElementById('wrap').style.width = '900px';
            document.getElementById('head').style.width = '900px';
            document.getElementById('columns').style.width = '900px';
            document.getElementById('left_sidebar').style.width = '175px';
            document.getElementById('main_content').style.width = '710px';
            document.getElementById('main_content').style.left = '175px';
            document.getElementById('footer').style.width = '900px';
            document.getElementById('size_flip').innerHTML = '800px';
            setCookie('FreyungBBall[screensize]', '1024')
            break;
            
    }
    sizeFlip++;
    if (sizeFlip > 1) 
        sizeFlip = 0;
}

function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}				

function setCookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

