function change(h, partner, tz, lang, mode, ttab) {
    newUrl = "?partner=" + partner + "&tz=" + tz + "&lang=" + lang + "&h=" + h + "&mode=" + mode + "&ttab=" + ttab;
    window.location = newUrl;
}
//settime according to timezone for customer time=19
function settimezone(tz, time)
{
    var x;
    x = time;
    var stringTime = new String(x);
    var first = new String(x).substring(0, 0);
    var second = new String(x).substring(1, 0);
    if (tz != 1) {
        if (first == "0") {
            x = Integer.parseInt(second);
        }
        x = x + tz - 1;
        if (x > 24) {
            x = x - 24;
        }
        if (x < 0) {
            x = x + 24;
        }
	//format time
        stringTime = new String(x);
    }

    if (stringTime.length == 1) {
        stringTime = "0" + stringTime;
    }
    document.write(stringTime);
}



//calctime for gametime sport starthours, startminutes ...
function calctime2(logic, hours, minutes, tz) {
    delay = 0;
    testy = minutes;
    period = 0;
    if (logic == "100" || logic == "150" || logic == "200") {
        delay = 15;
        period = 45;
    } else {
        document.write("&nbsp;");
    }
    if (period > 0) {
        //get daylightsaving setting
        var D = new Date;
        var DT = 2 * D.getTimezoneOffset() - (new Date(2004, 0)).getTimezoneOffset() - (new Date(2004, 6)).getTimezoneOffset();
        var dst = 0;
        if (DT >= 0) {
            dst = 1;
        } else {
            dst = 1;
        }
		//get starttime set by result
        starttime = new Date(); //16:00
        starttime.setHours(hours); //8:00
        starttime.setMinutes(minutes);
        timenow = new Date();
    // .getTimezoneOffset() gets the gmt offset in minutes/60 to get hours + 1hour to get the CET time
        var curHour = dst + timenow.getHours() + timenow.getTimezoneOffset() / 60
        timenow.setHours(curHour)
    //Get 1 minute in milliseconds
        one_minute = 1000 * 60
        diff = Math.ceil((timenow.getTime() - starttime.getTime()) / (one_minute))

        if (diff > 0) {
            if (diff >= (period + 4) && diff < (period + delay)) { //ie 49
                document.write(" HT&nbsp;&nbsp;")
            } else    if (diff >= period && diff < (period + delay)) { //ie 45
                document.write(" " + period + "'+")
            }
            if (diff == (period + delay)) {
                document.write(" " + (period + 1) + "'&nbsp;&nbsp;")
            }
            if (diff > (period + delay)) {
                if ((diff - delay) > 90 && (logic == "100" || logic == "150" || logic == "200")) {
                    document.write(" 90'+")
                } else {
                    document.write(" " + (diff - delay) + "'&nbsp;&nbsp;")
                }
            }
            if (diff < (period)) {
                document.write(" " + (diff) + "'&nbsp;&nbsp;")
            }
        } else {
            document.write(" 1'&nbsp;&nbsp;");
        }
    }
}
//selct checkboxes
function selectAllgames(current, primaryid) {
    for (i = 0; document.forms.selection.length > i; i++) {
        //do not check hidden spans
        if (window.name == "subscribe" && document.getElementById(document.forms.selection.elements[i].value).style.display == "block" && document.forms.selection.elements[i].name == "selgame" && document.forms.selection.elements[i].id == primaryid) {
            document.forms.selection.elements[i].checked = current.checked;
            persistCheckState(primaryid, document.forms.selection.elements[i].checked);
        }
        if (window.name != "subscribe" && document.forms.selection.elements[i].name == "selgame" && document.forms.selection.elements[i].id == primaryid) {
            document.forms.selection.elements[i].checked = current.checked;
            persistCheckState(primaryid, document.forms.selection.elements[i].checked);
        }
    }
}
function selectLeague(current, primaryid) {
    for (i = 0; document.forms.selection.length > i; i++) {
        if (document.forms.selection.elements[i].name == "selleague" && document.forms.selection.elements[i].value == primaryid) {
            document.forms.selection.elements[i].checked = true;
            persistCheckState(primaryid, document.forms.selection.elements[i].checked);
        }
    }
}
//get leagues when selecting from dropdown
function get_leagues(partner, day, tz, lang, er, ttab,pid,bid,css,eventId) {
    postSport = "?partner=" + partner + "&";
			//check if day=dateformat
    if (day.indexOf('/') != -1) {
        postSport = postSport + "day=" + day + "&lang=" + lang;
    } else {
        postSport = postSport + "day=" + day + "&lang=" + lang;
    }
			//added check if sports menu disabled
    if (document.sports) {
        sport = document.sports.sport.options[document.sports.sport.selectedIndex].value;
    } else {
        sport = "All";
    }
    if (ttab != null) {
        postSport = postSport + "&ttab=" + ttab;
    }
			//if(sport.indexOf('ER_')==-1&&(er=="true"||er==true)){
    //	sport="ER_"+sport;
    //}
    //if(sport.indexOf('ER_')!=-1&&(er=="false"||er==false)){
    //	sport=sport.substring(sport.indexOf('ER_')+sport.length-3);
    //}
    if (sport != "All" && sport != "ER_All") {
        postSport = postSport + "&sport=" + sport;
    }
    if (er == "true" || er == true) {
        postSport = postSport + "&h=er";
    }
    if (tz != 1) {
        postSport = postSport + "&tz=" + tz;
    }
    if(pid!=""&&pid!=null&&pid!="null"){
    	postSport = postSport + "&pid=" + pid;
    }
    if(bid!=""&&bid!=null&&bid!="null"){
    	postSport = postSport + "&bid=" + bid;
    }
    if(css!=""&&css!=null&&css!="null"){
    	postSport = postSport + "&css=" + css;
    }
    if(eventId!=""&&eventId!=null&&eventId!="null"){
    	postSport = postSport + "&eventId=" + eventId;
    }
    window.location = postSport;
}
//fix for openevent in parsed html
function openEvent2(eventId, partner, css, lang, tz) {
    tableJsp = "../stats/statistics2.jsp";
    eventURL = tableJsp + "?partner=" + partner + "&lang=" + lang + "&tz=" + tz;
    if (eventId != null && eventId != "") {
        eventURL = eventURL + "&eventId=" + eventId;
    }
    eventURL = eventURL + "&css=" + css;
    newwindow = window.open(eventURL, 'stat', 'width=700, height=700,scrollbars=yes,resizable=1,toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no');
    if (newwindow && newwindow.top) {
        if (window.focus) {
            newwindow.focus();
            return false;
        }
    } else {
    }
}

function onOpenEvent(eventId, partner, css, lang, tz, inNewWindow) {
    tableJsp = "../stats/statistics2.jsp";
    eventURL = tableJsp + "?partner=" + partner + "&lang=" + lang + "&tz=" + tz;
    if (eventId != null && eventId != "") {
        eventURL = eventURL + "&eventId=" + eventId;
    }
    eventURL = eventURL + "&css=" + css;
    if ('true' === inNewWindow) {
        newwindow = window.open(eventURL, 'stat', 'width=700, height=700,scrollbars=yes,resizable=1,toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no');
        if (newwindow && newwindow.top) {
            if (window.focus) {
                newwindow.focus();
                return false;
            }
        }

    } else {
        location = eventURL;
    }
}

function onopenScrollerUrl(part1, part2, eventId, partner, css, lang, tz, scrollerURL) {
	  if(scrollerUrl == "popup"){
	  		compareJsp = "/stats/statistics2.jsp";
    		compareURL = compareJsp + "?partner=" + partner + "&lang=" + lang + "&tz=" + tz + "&eventId=" + eventId;
    		compareURL = compareURL + "&participantId1=" + part1 + "&participantId2=" + part2;
    		compareURL = compareURL + "&css=" + css;
		    newwindow = window.open(compareURL, 'stat', 'width=700, height=700,scrollbars=yes,resizable=1');
		    if (newwindow && newwindow.top) {
		        if (window.focus) {
		            newwindow.focus();
		            return false;
		        }
		    } else {
			 	}
	  }else{
	  	 //scroller is used in iframe use parent adress
    	  parent.location.href=scrollerURL 
        //location = scrollerURL;
    }
}

//fix for openevent in parsed html
function openFixtures2(eventId, partner, css, lang, tz) {
    tableJsp = "../stats/statistics2.jsp";
    eventURL = tableJsp + "?partner=" + partner + "&lang=" + lang + "&tz=" + tz;
    if (eventId != null && eventId != "") {
        eventURL = eventURL + "&eventId=" + eventId;
    }
    eventURL = eventURL + "&css=" + css + "&next=y&offset=1";
    newwindow = window.open(eventURL, 'stat', 'width=700, height=700,scrollbars=yes,resizable=1,toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no');
    if (newwindow && newwindow.top) {
        if (window.focus) {
            newwindow.focus();
            return false;
        }
    } else {
    }
}
//fix for openevent in parsed css
function openEventNHL2(eventId, partner, css, lang, tz) {
    tableJsp = "/stats/statistics2.jsp";
    eventURL = tableJsp + "?partner=" + partner + "&lang=" + lang + "&tz=" + tz + "&eventId=" + eventId;
    eventURL = eventURL + "&css=" + css;
    newwindow = window.open(eventURL, 'stat', 'width=700, height=700,scrollbars=yes,resizable=1,toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no');
    if (newwindow && newwindow.top) {
        if (window.focus) {
            newwindow.focus();
            return false;
        }
    } else {
    }
}

function openEventMSL2(eventId, partner, css, lang, tz) {
    tableJsp = "../stats/statistics2.jsp";

    eventURL = tableJsp + "?partner=" + partner + "&lang=" + lang + "&tz=" + tz + "&eventId=" + eventId;
    eventURL = eventURL + "&css=" + css;
    newwindow = window.open(eventURL, 'stat', 'width=700, height=700,scrollbars=yes,resizable=1,toolbar=no,location=no,directories=no,status=no,menubar=no,titlebar=no');

    if (newwindow && newwindow.top) {
        if (window.focus) {
            newwindow.focus();
            return false;
        }
    }
}

function openCompare2(part1, part2, eventId, partner, css, lang, tz) {
    compareJsp = "../stats/statistics2.jsp";
    compareURL = compareJsp + "?partner=" + partner + "&lang=" + lang + "&tz=" + tz + "&eventId=" + eventId;
    compareURL = compareURL + "&participantId1=" + part1 + "&participantId2=" + part2;
    compareURL = compareURL + "&css=" + css;
    newwindow = window.open(compareURL, 'stat', 'width=700, height=700,scrollbars=yes,resizable=1');
    if (newwindow && newwindow.top) {
        if (window.focus) {
            newwindow.focus();
            return false;
        }
    } else {
    }
}

function openCompareNHL2(part1, part2, eventId, partner, css, lang, tz) {
    compareJsp = "../stats/statistics2.jsp";
    compareURL = compareJsp + "?partner=" + partner + "&lang=" + lang + "&tz=" + tz + "&eventId=" + eventId;
    compareURL = compareURL + "&participantId1=" + part1 + "&participantId2=" + part2;
    compareURL = compareURL + "&css=" + css;
    newwindow = window.open(compareURL, 'stat', 'width=700, height=700,scrollbars=yes,resizable=1');
    if (newwindow && newwindow.top) {
        if (window.focus) {
            newwindow.focus();
            return false;
        }
    } else {
    }
}
//subscribe functions


function help2(partner, css, lang) {
    var strURL = "";
    if (partner == "aftonbladet") {
        helpJsp = "help_swe_aft.jsp";
    } else if (partner == "sydsvenskan") {
        helpJsp = "help/help_sydsv.jsp";
    } else if (partner == "playit") {
        helpJsp = "help/help_playit.jsp";
    } else if (partner == "iltasanomat" || partner == "iltalehti" || partner == "mtv3fi") {
        helpJsp = "help/help_fin.jsp";
    } else if (lang == "ger") {
        helpJsp = "help/help_ger.jsp";
    } else if (lang == "ita") {
        helpJsp = "help/help_ita.jsp";
    }else if (lang=="tur"){
				helpJsp="help/help_tur.jsp";
		}else if (lang=="swe"){
				helpJsp="help/help_swe.jsp";
		}else if (lang=="esp"){
				helpJsp="help/help_esp.jsp";
		}else {
				helpJsp="help/help.jsp";
		}
    strURL = strURL + helpJsp + "?css=" + css;
    newwindow = window.open(strURL, "help", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,width=516');
    if (newwindow && newwindow.top) {
        if (window.focus) {
            newwindow.focus();
            return false;
        }
    } else {
    }
}

function sms2(eid, partner, css, ename) {
    // FIXME [eugenek] Hack!!
    // TODO [eugenek] create resolving context/servlet url
    strURL = "sms_swe.jsp";


    strURL = strURL + "?partner=" + partner + "&eid=" + eid + "&ename=" + ename + "&css=" + css;
    newwindow = window.open(strURL, "sms", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,width=516');
    if (newwindow && newwindow.top) {
        if (window.focus) {
            newwindow.focus();
            return false;
        }
    } else {
    }
}
function webtv(eid, partner, css, ename) {
    strURL = "http://webtv.canalplus.se/";
		//strURL=strURL+"?partner="+partner+"&eid="+eid+"&ename="+ename+"&css="+css;
    newwindow = window.open(strURL, "webtv", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,width=800');
    if (newwindow && newwindow.top) {
        if (window.focus) {
            newwindow.focus();
            return false;
        }
    } else {
    }
}

function betslip(eid, partner, css, ename, lang, pid, bid) {
	  if(partner=="betacademy"){
	  	if(lang == "gre"){
	  		strURL = "http://ads.expekt.com/affiliates/redirect.aspx?pid=24232&bid=5285";
	  	}else{
	  		strURL = "http://ads.expekt.com/affiliates/redirect.aspx?pid=24232&bid=5287";
	  	}
		}else if(partner == "score24"){
	  	strURL = "http://record.affiliatelounge.com/_k8a4wJgqXsiuqxJ1W5ErsWNd7ZgqdRLk/1";
		}else if(partner == "sportti"){
	  	strURL = "http://ads.expekt.com/affiliates/redirect.aspx?pid=32902&bid=5292";
		}else if(partner == "expektaffeng"){
	  	strURL = "http://ads.expekt.com/affiliates/redirect.aspx?pid="+pid+"&bid="+bid;
		}else{
    	strURL = "http://www.expekt.com"; //index.jsp?location=/livebetting/index.jsp&utm_source=expektLIVE&utm_medium=banner&utm_campaign=expektLIVE";
		}
	newwindow = window.open(strURL, "_blank");
    if (newwindow && newwindow.top) {
        if (window.focus) {
            newwindow.focus();
            return false;
        }
    } else {
    }
}

function selectAllgames(current, primaryid) {
    for (i = 0; document.forms.selection.length > i; i++) {
        //do not check hidden spans
        if (window.name == "subscribe" && document.getElementById(document.forms.selection.elements[i].value).style.display == "block" && document.forms.selection.elements[i].name == "selgame" && document.forms.selection.elements[i].id == primaryid) {
            document.forms.selection.elements[i].checked = current.checked;
        }
        if (window.name != "subscribe" && document.forms.selection.elements[i].name == "selgame" && document.forms.selection.elements[i].id == primaryid) {
            document.forms.selection.elements[i].checked = current.checked;
        }
    }
}
function selectLeague(current, primaryid) {
    for (i = 0; document.forms.selection.length > i; i++) {
        if (document.forms.selection.elements[i].name == "selleague" && document.forms.selection.elements[i].value == primaryid) {
            document.forms.selection.elements[i].checked = true;
        }
    }
}
//      switchcontent functions
var enablepersist = "on" //Enable saving state of content structure? (on/off)
if (document.getElementById) {
    document.write('<style type="text/css">')
    document.write('.switchcontent{display:none;}')
    document.write('.switchcontent2{display:block;}')
    document.write('</style>')
}
//resize kod
function getRefToDivMod(divID, oDoc) {
    if (!oDoc) {
        oDoc = document;
    }
    if (document.layers) {
        if (oDoc.layers[divID]) {
            return oDoc.layers[divID];
        } else {
            for (var x = 0, y; !y && x < oDoc.layers.length; x++) {
                y = getRefToDivNest(divID, oDoc.layers[x].document);
            }
            return y;
        }
    }
    if (document.getElementById) {
        return oDoc.getElementById(divID);
    }
    if (document.all) {
        return oDoc.all[divID];
    }
    return document[divID];
}
function resizeWinTo(idOfDiv) {
    var oH = getRefToDivMod(idOfDiv);
    if (!oH) {
        return false;
    }
    var oW = oH.clip ? oH.clip.width : oH.offsetWidth;
    var oH = oH.clip ? oH.clip.height : oH.offsetHeight;
    if (!oH) {
        return false;
    }
    var x = window;
    x.resizeTo(oW + 200, oH + 200);
    var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
    if (x.innerWidth) {
        myW = x.innerWidth;
        myH = x.innerHeight;
    }
    else if (d && d.clientWidth) {
        myW = d.clientWidth;
        myH = d.clientHeight;
    }
    else if (b && b.clientWidth) {
        myW = b.clientWidth;
        myH = b.clientHeight;
    }
    if (window.opera && !document.childNodes) {
        myW += 16;
    }
    if (navigator.appName.indexOf("Netscape") != -1) {
        x.resizeTo(oW + 16 + ( ( oW + 200 ) - myW ), oH + 16 + ( (oH + 200 ) - myH ));
    } else {
        x.resizeTo(oW + ( ( oW + 200 ) - myW ), oH + ( (oH + 200 ) - myH ));
    }
}

//end resize kod
//switchcontent kod, revive gameinfo functions.
var selectedItem;
function getElementbyClass(classname) {
    ccollect = new Array()
    var inc = 0 //document.getElementById("liveScoreBody").
    if (document.getElementsByTagName("span")) {
        var alltags = document.getElementsByTagName("span")//document.all? document.all : document.getElementsByTagName("span")
        for (i = 0; i < alltags.length; i++) {
            if (alltags[i].className == classname)
                ccollect[inc++] = alltags[i]
        }
    }
}
function getElementbyClass2(classname) {
    ccollect2 = new Array()
    var inc = 0
	//if(document.getElementsByTagName("span")){
    var alltags2 = document.all ? document.all : document.getElementsByTagName("tr")
    for (i = 0; i < alltags2.length; i++) {
        if (alltags2[i].className.indexOf(classname) != -1)
            ccollect2[inc++] = alltags2[i]
    }
	//}
}

function contractcontent(omit) {
    if (typeof ccollect == "undefined") {
        getElementbyClass("switchcontent");
    }
    var inc = 0
    while (ccollect[inc]) {
        if (ccollect[inc].id != omit)
            ccollect[inc].style.display = "none"
        inc++
    }
}
/*
function expandcontent(cid) {
    if (typeof ccollect == "undefined") {
        getElementbyClass("switchcontent");
    }
    if (typeof ccollect != "undefined") {
        //document.getElementById(cid).style.visibility = (document.getElementById(cid).style.visibility!="visible")? "visible":"hidden";
        document.getElementById(cid).style.display = (document.getElementById(cid).style.display != "block") ? "block" : "none";
        persistStyle(cid, document.getElementById(cid).style.display);
    }
    if (window.name == "subscribe") {
        resizeWinTo('subscribe')
    }
}
*/
function addSelected() {
    if (typeof ccollect == "undefined") {
        getElementbyClass("switchcontent");
    }
    selectedItem = ""
    var inc2 = 0
    while (ccollect[inc2]) {
        if (ccollect[inc2].style.display == "block") {
            if (selectedItem != "") {
                selectedItem = selectedItem + "|" + ccollect[inc2].id
            }
            else {
                selectedItem = ccollect[inc2].id
            }
        }
        inc2++
    }
}

function revivecontent() {
    selectedItem = getselectedItem();
    if (selectedItem != 0) {
        selectedComponents = selectedItem.split("|");
        i = 0;
        while (i < selectedComponents.length) {
            if (document.getElementById(selectedComponents[i])) {
                document.getElementById(selectedComponents[i]).style.display = "block";
            }
            i++;
        }
    }
}

function reviveGames() {
    var inc = 0;
    while (ccollect2[inc]) {
        ccollect2[inc].style.display = "none";
        inc++;
    }
    selectedGames = get_cookie("gamecookie");
    if (selectedGames != 0) {
        selectedGameArray = selectedGames.split("_");
        i = 0;
        while (i < selectedGameArray.length) {
            var gid = selectedGameArray[i];
			//alert("going to hide:" + gid);
            if (document.getElementById(gid) != null) {
                document.getElementById(gid).style.display = "block";
            }
            i++;
        }
    }
}

function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) {
            offset += search.length
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            returnvalue = unescape(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;
}
function getselectedItem() {
    if (get_cookie(window.location.pathname) != "") {
        selectedItem = get_cookie(window.location.pathname)
        return selectedItem
    }
    else
        return ""
}
function saveswitchstate() {
    if (typeof selectedItem != "undefined") {
        addSelected()
        document.cookie = window.location.pathname + "=" + selectedItem
    }
}

function do_onload() {
    if (enablepersist == "on")
        revivecontent()
    if (window.name == "subscribe") {
        getElementbyClass2("trpart")
        reviveGames()
        resizeWinTo('subscribe')
    }
}

if (window.addEventListener)
    window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
    window.attachEvent("onload", do_onload)
else if (document.getElementById)
    window.onload = do_onload
if (enablepersist == "on" && document.getElementById)
    window.onunload = saveswitchstate