function joinGame(gID, sel) {
    var jGmLnk = document.getElementById(sel).options;
    var tID = jGmLnk[jGmLnk.selectedIndex].value;
    window.top.ToffPopup.ShowLoading(null);
    window.top.location.replace("PickSquad.aspx?" + ToffConstant.GAMEID + "=" + gID + "&t=" + tID);
}

function createNewTeamName() {
    var tfid = "&" + ToffConstant.TOFFUSERID + "=" + document.forms[0].elements[ToffConstant.TOFFUSERID].value;
    window.top.ToffPopup.ShowLoading("../Dialog/DialogTeamName.aspx?" + ToffConstant.PAGEREFERER + "=../Game/Join.aspx" + tfid);
}

function fridayAlert() {
    showMessage("You cannot select teams on friday evenings");
}

function deadlineAlert() {
    showMessage("You cannot select a team for this game because this game is past it's deadline.");
}

var loadingStr = '<span style="float:left; padding:10px"><h3>Loading..... </h3></span><img src="' + ToffConstant.ROOT + 'images/loading.gif" alt="loading ..." width="60" height="60" style="float:left" /><span style="float:left; padding:10px"><h3> Please wait.</h3></span>';

function showMessage(messg) {
	var m = '<center><p>' + messg + '</p><input type="button" class="btn" onclick="window.top.ToffPopup.Hide()" value="OK" onmouseover="this.className=\'btn2\';" onmouseout="this.className=\'btn\';"></center>';
    window.top.ToffPopup.ShowMessage(m, 300, 130);
}

function showDesc(gID) {
    hideGmInnTDs(gID);
    showGmInn(gID);
    document.getElementById("gmDesc" + gID).style.display = "";
    document.getElementById("gmInnTtl" + gID).innerHTML = "Game Description";
    ajaxObjects["ajaxDesc" + gID] = new sack();
    ajaxObjects["ajaxDesc" + gID].requestFile = "AsyncViewGameDescription.ashx";
    ajaxObjects["ajaxDesc" + gID].setVar("GameID", gID);
    ajaxObjects["ajaxDesc" + gID].onCompletion = new Function("getDescComplete(" + gID + ");");
    ajaxObjects["ajaxDesc" + gID].runAJAX();
}

function getDescComplete(gID) {
    var response = ajaxObjects["ajaxDesc" + gID].response;
    ajaxObjects["ajaxDesc" + gID] = false;
    if (response)
        document.getElementById("gmDesc" + gID).innerHTML = response;
    else {
        document.getElementById("gmDesc" + gID).innerHTML = "";
        showMessage("Error: No Response", 300, 130);
    }
}

function showMatches(gID, tID) {
    hideGmInnTDs(gID);
    showGmInn(gID);
    var x = document.getElementById("gmMtTD" + gID);
    document.getElementById("gmInnTtl" + gID).innerHTML = "Soccer Match List";
    x.style.display = "";
    if (x.innerHTML != "") return;
    x.innerHTML = loadingStr;
    ajaxObjects["ajaxMatches" + gID] = new sack();
    ajaxObjects["ajaxMatches" + gID].requestFile = "AsyncViewGameMatches.ashx";
    ajaxObjects["ajaxMatches" + gID].setVar("GameID", gID);
    ajaxObjects["ajaxMatches" + gID].onCompletion = new Function("getMatchesComplete(" + gID + ");");
    ajaxObjects["ajaxMatches" + gID].runAJAX();
}

function getMatchesComplete(gID) {
    var response = ajaxObjects["ajaxMatches" + gID].response;
    ajaxObjects["ajaxMatches" + gID] = false;
    if (response)
        document.getElementById("gmMtTD" + gID).innerHTML = response;
    else {
        document.getElementById("gmMtTD" + gID).innerHTML = "";
        showMessage("Error: No Response", 300, 130);
    }
}

function hideGmInnTDs(gID) {
    document.getElementById("gmDesc" + gID).style.display = "none";
    document.getElementById("gmMtTD" + gID).style.display = "none";
}

function hideGmInn(gID) {
    document.getElementById("gmInn" + gID).style.display = "none";
    document.getElementById("gmFt" + gID).className = "bxFt2";
}

function showGmInn(gID) {
    document.getElementById("gmInn" + gID).style.display = "";
    document.getElementById("gmFt" + gID).className = "bxFt1";
}

