﻿function SelectTab(obj,ContentContainerDIV){
    if (obj.id.indexOf('Selected')==-1){
        var selectedTabNum = 0;
        var stopCounting = false;
        //DEHIGHLIGHT ALL TABS AND FIND WHICH ONE IS SELECTED. THE STOPCOUNTING SHIT IS DUE TO MOZILLA'S WHITESPACING SHIT
        for (i=0;i<obj.parentNode.childNodes.length;i++){
            if (obj.parentNode.childNodes[i].tagName == 'DIV'){
                obj.parentNode.childNodes[i].className = 'blackTab';
                if (!stopCounting) selectedTabNum++;
                if (obj == obj.parentNode.childNodes[i]) stopCounting=true;
                        
            }
        }
        
        //HIGHLIGHT SELECTED TAB
        obj.className = 'whiteTab';
        
        //SHOW THE CORRESPONDING CONTENT DIV. AGAIN USE OF VARIABLE countenCounter IS DUE TO MOZILLA'S WHITESPACING SHIT
        var contentObj = document.getElementById(ContentContainerDIV);
        var contentCounter = 0;
        for (i=0;i<contentObj.childNodes.length;i++){
            if (contentObj.childNodes[i].tagName == 'DIV'){
                if (contentCounter == selectedTabNum - 1)
                    contentObj.childNodes[i].style.display = '';
                else
                    contentObj.childNodes[i].style.display = 'none';
                contentCounter++;

            }
        }
    }
}

function SelectTabImage(obj,ContentContainerDIV){
    if (obj.id.indexOf('Selected')==-1){
        var selectedTabNum = 0;
        var stopCounting = false;

        //SHOW BLACK IMAGES FOR ALL
        for (j=0;j<document.getElementsByTagName('IMG').length;j++){
            if (document.getElementsByTagName('IMG')[j].id.indexOf('TheTab')>-1)
                document.getElementsByTagName('IMG')[j].src = document.getElementsByTagName('IMG')[j].src.replace('_Selected','')
        }

        //DEHIGHLIGHT ALL TABS AND FIND WHICH ONE IS SELECTED. THE STOPCOUNTING SHIT IS DUE TO MOZILLA'S WHITESPACING SHIT
        for (i=0;i<obj.parentNode.childNodes.length;i++){
            if (obj.parentNode.childNodes[i].tagName == 'DIV'){
                obj.parentNode.childNodes[i].className = 'blackTab';
                if (!stopCounting) selectedTabNum++;
                if (obj == obj.parentNode.childNodes[i]) stopCounting=true;
            }
        }
        
        //HIGHLIGHT SELECTED TAB
        obj.className = 'whiteTab';
        
        //SHOW THE CORRESPONDING CONTENT DIV. AGAIN USE OF VARIABLE countenCounter IS DUE TO MOZILLA'S WHITESPACING SHIT
        var contentObj = document.getElementById(ContentContainerDIV);
        var contentCounter = 0;
        for (i=0;i<contentObj.childNodes.length;i++){
            if (contentObj.childNodes[i].tagName == 'DIV'){
                if (contentCounter == selectedTabNum - 1){
                    contentObj.childNodes[i].style.display = '';
                    //Find The Image and swap it
                    for (j=0;j<document.getElementsByTagName('IMG').length;j++){
                        if (document.getElementsByTagName('IMG')[j].id.indexOf('TheTab')>-1){
                            //alert(document.getElementsByTagName('IMG')[j].src);
                            if (document.getElementsByTagName('IMG')[j].src.indexOf('Tab' + selectedTabNum)>-1)
                                document.getElementsByTagName('IMG')[j].src = document.getElementsByTagName('IMG')[j].src.replace('.gif','_Selected.gif')
                        }
                    }
                }
                else
                    contentObj.childNodes[i].style.display = 'none';
                contentCounter++;

            }
        }
    }
}

//SOCCER TV AND CHAT LIVEBET FUNCTIONS
function ChatRoomMatch(Team1,Team2,Apodosi1,Apodosi2,Apodosi3,Org,Channel,Time){
    this.Team1 = Team1;this.Team2 = Team2;
    this.Apodosi1 = Apodosi1;this.Apodosi2 = Apodosi2;this.Apodosi3 = Apodosi3;
    this.Org = Org;this.Channel = Channel;this.Time = Time;
}

function LoopChatRoomMatches(){
    if (currentChatRoomLooper+1>CHtc.length) currentChatRoomLooper = 0
    
    Team1.innerHTML = CHtc[currentChatRoomLooper].Team1;
    Team2.innerHTML = CHtc[currentChatRoomLooper].Team2;
    Apodoseis.innerHTML = CHtc[currentChatRoomLooper].Apodosi1 + ' - ' + CHtc[currentChatRoomLooper].Apodosi2 + ' - ' + CHtc[currentChatRoomLooper].Apodosi3;
    
    Org.innerHTML = CHtc[currentChatRoomLooper].Org;
    Time.innerHTML = CHtc[currentChatRoomLooper].Time;
    Channel.innerHTML = CHtc[currentChatRoomLooper].Channel;
    currentChatRoomLooper++;
    setTimeout("LoopChatRoomMatches()",5000)
}

function LoopMatches(){
    if (currentMatchLooper+1>mtc.length) currentMatchLooper = 0

    MatchDiv.innerHTML = mtc[currentMatchLooper];
    currentMatchLooper++;
    setTimeout("LoopMatches()",5000)
}

//SBX STATS
function SwapSBXStatsTables(mode){
    if (mode==1){
        document.getElementById('StatsTable').style.display='';
        document.getElementById('StatsPlusTable').style.display='none';
    }
    else{
        document.getElementById('StatsTable').style.display='none';
        document.getElementById('StatsPlusTable').style.display='';
    }       
}

//
function StringIsEmail(email){
	var reg = new RegExp(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/g);
	if (!reg.test(email))
	    return false
	else
	    return true;
}