var fot_debug=false;
var pluginCount = 0;
var baseLiveUrl = '/harbour/mapper/fotballplugger/module/live?1=1';
var containerID = 'fot_plugContainer_live';
var liveUrlHolder = new Object();
var liveContainerIdHolder = new Object();

<!-- switch profile box -->
function fot_displayProfile(parentElem, tableid) {
    var tables = parentElem.getElementsByTagName('div');
    var i = 0;
    for (i = 0; i < tables.length; i++) {
        if (tables[i].id.indexOf('team')==0 || tables[i].id.indexOf('person')==0)
            if (tables[i].id == (tableid)) {
                tables[i].style.display = "block";
            } else {
                tables[i].style.display = "none";
            }
    }
}

function fot_displayTeam(bodyContainer, divid, headContainer,selectedClass, otherClass) {
    var divs = bodyContainer.getElementsByTagName('div');
    var i = 0;
    for (i = 0; i < divs.length; i++) {
        if (divs[i].id.indexOf('team')==0)
            if (divs[i].id == (divid)) {
                divs[i].style.display = "block";
            } else {
                divs[i].style.display = "none";
            }
    }
    
    var links = headContainer.getElementsByTagName('a');
    i = 0;
    for (i = 0; i < links.length; i++) {
        if (links[i].id.indexOf('team')==0)
            if (links[i].id == (divid)) {
                links[i].className = selectedClass;
            } else {
                links[i].className = otherClass;
            }
    } 
}

<!-- countDown live plugg -->
function fot_countDown(year, month, day, hour, minute, dayText, hourText, minText, secText, containerID, suffix) {
    var today = new Date();
    var todaysDate = (new Date(today.getFullYear(),today.getMonth(), today.getDate(),today.getHours(), today.getMinutes(), today.getSeconds())).getTime();
    var targetDate = (new Date(year, month, day, hour, minute, 00)).getTime();
    var timeLeft = Math.round((targetDate - todaysDate + time_difference) / (1000));

    if(timeLeft > 0){
        var days = Math.floor(timeLeft/(60*60*24));
        timeLeft %= (60*60*24);
        var hours = Math.floor(timeLeft/(60*60));
        timeLeft %= (60*60);
        var minutes = Math.floor(timeLeft/60);
        timeLeft %= (60);
        var seconds = timeLeft;
        document.getElementById('fot_cDay'+suffix).innerHTML = days + " ";
        document.getElementById('fot_cHour'+suffix).innerHTML = hours + " ";
        document.getElementById('fot_cMin'+suffix).innerHTML = minutes + " ";
        document.getElementById('fot_cSec'+suffix).innerHTML = seconds + " ";
        document.getElementById('fot_iDay'+suffix).innerHTML = dayText + " ";
        document.getElementById('fot_iHour'+suffix).innerHTML = hourText + " ";
        document.getElementById('fot_iMin'+suffix).innerHTML = minText + " ";
        document.getElementById('fot_iSec'+suffix).innerHTML = secText + " ";
        setTimeout('fot_countDown(' + year+','+month+','+day+','+hour+','+minute+',"'+dayText+'","'+hourText+'","'+minText+'","'+secText+'","'+containerID+'",'+suffix+')', 999);
		
    } else {
       apiAjax2(liveUrlHolder['id'+suffix], 'fot_replaceContent', '"'+containerID+'"');
    }
}

function apiGetTransport() {
    var xmlhttp = false;
    if(window.XMLHttpRequest) {
        xmlhttp=new XMLHttpRequest();
    } else if(window.ActiveXObject){
        try{
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
        } catch(e) {
            try{
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
            }catch(E){
                xmlhttp=false
            }
        }
    }
    return xmlhttp;
}

function apiAjax2(url, callback, params){
    var xmlhttp = new apiGetTransport();
    if(xmlhttp)xmlhttp.onreadystatechange = function(){
        if(xmlhttp && xmlhttp.readyState==4)if(xmlhttp.status==200){
            var functionToCall = callback + '(xmlhttp.responseText,'+params+')';
            if(fot_debug){
                alert(xmlhttp.responseText);alert(functionToCall);
            }
            eval(functionToCall);
        } else {
    //throw(xmlhttp.statusText);
    }
    }
    xmlhttp.open("GET",url,true);xmlhttp.send(null);
}
 
 
 
 
function fot_replaceContent(markup, containerID){
    var documentDiv = document.getElementById(containerID);
    var tmpDiv = document.createElement('tmpDiv');
    tmpDiv.innerHTML = markup;
    
    var innerDivs =  tmpDiv.getElementsByTagName("div");
    var markupDiv = '';
    var compID = containerID.substring(0, containerID.length-1);
    var i = 0; for(i = 0; i < innerDivs.length; i++) {
        if (innerDivs[i].id == compID){
            markupDiv = innerDivs[i];
        };
    } 
    
    documentDiv.innerHTML = markupDiv.innerHTML;
}            


// Function for expanding and collapsing the team table
function hideOrShowRowOnTable(action, idToTableToAccess, idToHideLink, idToShowLink){

    // Handling the rows in the target table
    var tableToAccess = document.getElementById(idToTableToAccess);
    var trs = tableToAccess.getElementsByTagName('tr');
    var i = 0;
    for (i = 0; i < trs.length; i++) {
        if(trs[i].className.indexOf("fotMFIsOpen") == -1  && trs[i].className.indexOf("fotMFIsCurrent") == -1){
            if(action == "show"){
                if (trs[i].style.display == "none") {
                    trs[i].style.display = "";
                }
            }
            if(action == "hide"){
                if (trs[i].style.display == "") {
                    trs[i].style.display = "none";
                }
            }
        }
    }

    // Handling the display of collaps and expand table links
    var hideLink = document.getElementById(idToHideLink);
    var showLink = document.getElementById(idToShowLink);
    if(action == "show"){
        hideLink.style.display = "block";
        showLink.style.display = "none";
    }

    if(action == "hide"){
        hideLink.style.display = "none";
        showLink.style.display = "block";
    }

}

function fot_updateElementId(elementID, suffix) {
    var elem = document.getElementById(elementID);
    if (elem) {
        elem.id = elem.id + suffix;
    }
}
