var _SelfcareGeoCheckBaseURL = 'http://video.uefa.com';
var agent = navigator.appName;
var PlayerWidth = "360"; 
var PlayerHeight = "352";
//var PlayerWidth = "512";
//var PlayerHeight = "350";
var playerVer = "7.0";
//var playerVer = "6.4";
var _AccountID = "uefa"; //'uvs';
var videoBaseURL = 'http://video.uefa.com';
var baseURL = 'http://' + document.location.host;
//if (baseURL.indexOf('staging')>-1)
//	_SelfcareBaseURL = 'https://secure.video.staging.infra.uefa.com/Selfcare/default.aspx';
//else
//	_SelfcareBaseURL = 'https://secure.video.uefa.com/Selfcare/default.aspx';	
var _eHelpURL = 'http://support.video.uefa.com/refer.asp?ln=en&context=2';
var _iHelpURL = 'http://support.video.uefa.com/refer.asp?ln=it&context=1';
var _fHelpURL = 'http://support.video.uefa.com/refer.asp?ln=fr&context=2';
var _dHelpURL = 'http://support.video.uefa.com/refer.asp?ln=de&context=1';
var _sHelpURL = 'http://support.video.uefa.com/refer.asp?ln=es&context=1';
var _pHelpURL = 'http://support.video.uefa.com/refer.asp?ln=pt&context=1';

function SetMatchdayRound(Competition) 
{
	if (Competition.toLowerCase() =='ucl' || Competition.toLowerCase() =='uefacup' || Competition.toLowerCase() =='supercup') {		
		return 'Matchday';
	}
	else {		
		return 'Round';
	}
} 

function CompetitionName(CompetitionID) 
{ 
	switch (CompetitionID) 
	{ 
		case '1': case 1 : return ('UCL'); 
		case '3': case 3 : return ('EURO');
		case '5': case 5 : return ('Futsal');
		case '9': case 9 : return ('SuperCup'); 
		case '13': case 13 : return ('Under21'); 
		case '14': case 14 : return ('UefaCup');
		case '23': case 23 : return ('Under17');
		case '24': case 24 : return ('Under19');
		case '25': case 25 : return ('WUnder19');
		case '27': case 27 : return ('FutsalCup');
		case '28': case 28 : return ('WomenCup');
		case '101': case 101 : return ('WUnder17');
		default: return (''); 
	} 
}

function readCookie(name) 
{ 
	var nameEQ = name + '='; 
	var ca = document.cookie.split(';'); 
	for(var i=0;i < ca.length;i++) 
		{ 
 			var c = ca[i]; 
 			while (c.charAt(0)==' ') c = c.substring(1,c.length); 
 			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); 
		} 
	return null; 
} 

function readCookieParam(name, param) 
{ 
	var nameEQ = name + '='; 
	var namePR = param + '='; 
	var ca = document.cookie.split(';'); 
	for(var i=0;i < ca.length;i++) 
	{ 
 		var c = ca[i]; 
 		while (c.charAt(0)==' ') c = c.substring(1,c.length); 
 		if (c.indexOf(nameEQ) == 0) { 
 			var cb = c.substring(nameEQ.length,c.length).split('&'); 
 			for(var j=0;j < cb.length;j++) 
 				{ 
 				var d = cb[j]; 
 				while (d.charAt(0)==' ') d = d.substring(1,d.length); 
 				if (d.indexOf(namePR) == 0) { 
						return d.substring(namePR.length,d.length); 
 				} 
 			} 
 		} 
	} 
	return null; 
} 

function SetCookie (name, value, duration, path, domain, secure) 
{
  var expString = ((duration == null) ? "" : ("; expires=" + getexpirydate(duration)));
  var pathString = ((path == null) ? "" : ("; path=" + path));
  var domainString = ((domain == null) ? "" : ("; domain=" + domain));
  var secureString = ((secure == true) ? "; secure" : "");
  parent.document.cookie = name + "=" + escape (value) + expString + pathString + domainString + secureString;
}

function GetCookie (name) 
{
  var result = null;
  var myCookie = " " + document.cookie + ";";
  var searchname = " " + name + "=";
  var startOfCookie = myCookie.indexOf(searchname);
  var endOfCookie;
  if (startOfCookie != -1) {
    startOfCookie += searchname.length; // skip past cookie name
    endOfCookie = myCookie.indexOf(";", startOfCookie);
    result = unescape(myCookie.substring(startOfCookie, endOfCookie));
  }/*alert('result : ' + result);*/
  return result;
}

function getArgs() 
{ 
    var args = new Object(); 
    var query = unescape(location.search.substring(1)); 
    var pairs = query.split('&'); 

    for(var i = 0; i < pairs.length; i++) { 
            var pos = pairs[i].indexOf('='); 
            if (pos == -1) continue; 
            var argname = pairs[i].substring(0,pos); 
            var value = pairs[i].substring(pos+1); 
            args[argname] = unescape(value); 
    } 
    return args; 
}

//refresh parent window after user logs-in in the order path
function LoginStatusUpdate(){
	if (readCookie('manSession') != null) { // && readCookie('manSession') != '' && readCookie('manSession') != 'null'
		if (window.opener) {
			//window.opener.location.href='http://' + document.location.host + '/Video/index.html';
			try{
				//window.opener.document.location.reload();
				opener.location.reload();
			}
			catch (e)
			{//alert(e);
				window.opener.location.href='http://' + document.location.host + '/Video/index.html';
			}
		}
		else {
			window.location.reload();
			//window.open('http://' + document.location.host + '/Video/index.html');
		}
	}
}

function WinClose() {
	window.focus();
	self.setTimeout('window.close()', 5000);
}

function ReloadUCLMatch(Season,Matchday,MatchID) 
{	
	rpcInvoke(1,'/Video/Competitions/UCL/Season=' + Season + '/Matchday=' + Matchday + '/Match=' + MatchID + '/_MatchVideo.html?rpcTargetDIV=MatchContainer');
}

function ReloadUCUPMatch(Season,Matchday,MatchID) 
{	
	rpcInvoke(1,'/Video/Competitions/UefaCup/Season=' + Season + '/Matchday=' + Matchday + '/Match=' + MatchID + '/_MatchVideo.html?rpcTargetDIV=MatchContainer');
}

function ReloadEUROMatch(Season,Round,MatchID) 
{	
	rpcInvoke(1,'/Video/Competitions/EURO/Season=' + Season + '/Round=' + Round + '/Match=' + MatchID + '/_MatchVideo.html?rpcTargetDIV=MatchContainer');
}

// Toggle to display score in matchboxes
function toggleDisplay(matchid){
	var buttonName = 'ScoreButton' + matchid;
	var scoreName = 'LatestScore' + matchid;
	document.getElementById(buttonName).style.visibility='hidden';
	document.getElementById(buttonName).style.display='none';
	document.getElementById(scoreName).style.visibility='visible';
	document.getElementById(scoreName).style.display='block';
}
// Toggle to display score in matchboxes of ucl final package homep.
function toggleDisplayM(matchid){
	var buttonName = 'ScoreButtonM' + matchid;
	var scoreName = 'LatestScoreM' + matchid;
	document.getElementById(buttonName).style.visibility='hidden';
	document.getElementById(buttonName).style.display='none';
	document.getElementById(scoreName).style.visibility='visible';
	document.getElementById(scoreName).style.display='block';
}

// Toggle to display TBD in matchboxes
function toggleDisplayTBD(code,tbd){
	var buttonName = 'ScoreButton'+code + tbd;
	var scoreName = 'LatestScore'+code + tbd;
	document.getElementById(buttonName).style.visibility='hidden';
	document.getElementById(buttonName).style.display='none';
	document.getElementById(scoreName).style.visibility='visible';
	document.getElementById(scoreName).style.display='block';
}

// Toggle to display match related video tab
function toggleMatchClips(){
	if (document.getElementById('MatchClips') != null){
		document.getElementById('MatchClips').style.visibility='visible';
		document.getElementById('MatchClips').style.display='block';
	}
	if (document.getElementById('MatchEvents') != null){
		document.getElementById('MatchEvents').style.visibility='hidden';
		document.getElementById('MatchEvents').style.display='none';
	}
}

// Toggle to display match related events tab
function toggleMatchEvents(){
	if (document.getElementById('MatchEvents') != null){
		document.getElementById('MatchEvents').style.visibility='visible';
		document.getElementById('MatchEvents').style.display='block';
	}
	if (document.getElementById('MatchClips') != null){
		document.getElementById('MatchClips').style.visibility='hidden';
		document.getElementById('MatchClips').style.display='none';
	}
}
/**/
function RPCGen_Matchbox(CompetitionID,Season,Matchday,MatchID)
{
	var refUrl = document.URL.toLowerCase();
	var refreshURL;
	if (refUrl.indexOf("vod/competitions/geoindex.html") > -1){
		refreshURL = "vod";
	}
	else if(refUrl.indexOf("video/geoindex.html") > -1){
		refreshURL = "hp";	
	}
	if (CompetitionID==1 || CompetitionID==9 || CompetitionID==14) {
		fnOpenWindow('/Video/Competitions/' + CompetitionNameInt(CompetitionID) + '/Season=' + Season + '/Matchday=' + Matchday + '/Match=' + MatchID + '/vod_popupFlash.html?r=' + refreshURL, 'VODPopUp', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 848, 610, '', '');return false;
	}
	else {
		fnOpenWindow('/Video/Competitions/' + CompetitionNameInt(CompetitionID) + '/Season=' + Season + '/Round=' + Matchday + '/Match=' + MatchID + '/vod_popupFlash.html?r=' + refreshURL, 'VODPopUp', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 848, 610, '', '');return false;
	}	
}

function BuySubscription(Kind,lang)
{
	//var OPlanguage = SetLanguage(lang);
	//var ReturnURL = baseURL + '/video/VOD/BuySubscription.htmx?PackageType=' + Kind;
	if (readCookie('manSession') == null) {
		var ReturnURL = _OrderURL + "Replay/landing.html?catId=" + Kind + "&r=" + encodeURIComponent(_OrderURL + "Replay/myaccount/index.html");
	}
	else {
		var ReturnURL = _OrderURL + "Replay/confirmSelection/index.html?catId=" + Kind + "&r=" + encodeURIComponent(_OrderURL + "Replay/myaccount/index.html");
	}
	fnOpenWindow(ReturnURL, 'VideoService', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 848, 610, '', '');
}

function preLoadImages(){
	if (document.images){
		var imageFiles = preLoadImages.arguments;
		var preLoadMatrix = new Array();
		for (var i=0; i<imageFiles.length; i++){
			preLoadMatrix[i] = new Image;
			preLoadMatrix[i].src = imageFiles[i];
			}
		}
}

function ToogleDiv(divID,flag) 
{
	if (flag == 'visible') {
        document.getElementById(divID).style.visibility='visible';
        if(agent.indexOf("Microsoft")>-1){
			document.getElementById(divID).style.display= 'inline-block';
        }
        else{
			document.getElementById(divID).style.display= 'inline';
			 if(divID == 'list1' || divID == 'list2' || divID == 'list4'){
				document.getElementById(divID).style.cssFloat='left';
				document.getElementById(divID).style.marginLeft="0px";
				document.getElementById(divID).style.position='absolute';
				if(divID == 'list4'){
					document.getElementById(divID).style.marginTop="45px";
				}
			}
			if(divID == 'list5' || divID == 'list6'){
				document.getElementById(divID).style.cssFloat='right';
				if(agent.indexOf("Microsoft")==-1){
					if(document.getElementById('list1').style.visibility=='hidden' && document.getElementById('list2').style.visibility=='hidden'){
						document.getElementById(divID).style.cssFloat='left';
						document.getElementById(divID).style.visibility='visible';
					}
				}
				if(divID == 'list6'){
					document.getElementById(divID).style.marginLeft="205px";
					document.getElementById(divID).style.position='absolute';
				}
			}			
        }
	}
	else if (flag == 'hidden') {
        document.getElementById(divID).style.visibility='hidden';
        document.getElementById(divID).style.display='none';	
	}	
}

function hideDivs(divID,howMany) 
{ 
	for (i = 1;i<=howMany;i++) { 
		var divName = divID + i; 
		document.getElementById(divName).style.visibility='hidden' 
		document.getElementById(divName).style.display='none' 
	} 
} 

function CheckStatusAndPlay(URL)
{
	if(document.location.search.indexOf('&noImg')>-1){
		if (getArgs().MediaURL){
			PlayFreeVideo(MediaURL);
		}
	}
	else {
		if (readCookie('manSession') != null){
			PlayVideoWM(URL);
			HighlightRow(getMediaID(URL));
		}
	}
}

function fnOpenWindow(address, target, toolbar, location, directories, status, menubar, scrollbars, resizable, width, height, top, left) 
{
	if (!(top > '0'))
	{
		top = (window.screen.availHeight / 2) - (height / 2);
	}
	if (!(left > '0'))
	{
		left = (window.screen.availWidth / 2) - (width / 2);
	}
	var option = "toolbar="+toolbar+",location="+location+"directories="+directories+",status="+status+",menubar="+menubar+",scrollbars="+scrollbars+",resizable="+resizable+",width="+width+",height="+height+",top="+top+",left="+left;
	var objWindow = window.open(address, target, option);
	objWindow.focus();
}

function fnOpenWindowFree(address, target, toolbar, location, directories, status, menubar, scrollbars, resizable, width, height, top, left) 
{
	address = address + '&noImg=y';
	if (!(top > '0'))
	{
		top = (window.screen.availHeight / 2) - (height / 2);
	}
	if (!(left > '0'))
	{
		left = (window.screen.availWidth / 2) - (width / 2);
	}
	var option = "toolbar="+toolbar+",location="+location+"directories="+directories+",status="+status+",menubar="+menubar+",scrollbars="+scrollbars+",resizable="+resizable+",width="+width+",height="+height+",top="+top+",left="+left;
	var objWindow = window.open(address, target, option); 
	objWindow.focus();
}

function fnOpenHide(address,target,toolbar)
{
	var option = toolbar + ",top=10000,left=10000";
	var objWindow = window.open(address,target,option);
	objWindow.blur();
	//objWindow.focus();
	document.getElementById('metanavLoggedIn').style.visibility='hidden';
	document.getElementById('metanavLoggedIn').style.display='none';
	document.getElementById('metanavLoggedOut').style.visibility='visible';
	document.getElementById('metanavLoggedOut').style.display='block';
}

function pageNavigateNews(step, psize, src, section)
{
	var next = psize;

	if (next < 0){
		if (section == 'player')
			var pl = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/PlayerOfTheWeek.html');
		else if (section == 'team')
			var team = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/TeamOfTheWeek.html');
		else if (section == 'top5')
			var top = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/Top5Goals.html');
		else if (section == 'gs')
			var gs = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/GroupSummaries.html');
		else if (section == 'goal')
			var goal = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/TopGoals.html',{method:'get',evalScripts:true,parameters:{First:'10'},encoding:'UTF-8'});
		else
			var txt = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/VodSearch.htmx',{method:'get',evalScripts:true,parameters:{First:'10',srchString:src},encoding:'UTF-8'});
	}
	else{
		if (section == 'player')
			var pl = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/PlayerOfTheWeek,page='+step+'.htmx',{method:'get',evalScripts:true,parameters:{First:next},encoding:'UTF-8'});
		else if (section == 'team')
			var team = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/TeamOfTheWeek,page='+step+'.htmx',{method:'get',evalScripts:true,parameters:{First:next},encoding:'UTF-8'});
		else if (section == 'top5')
			var top = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/Top5Goals,page='+step+'.htmx',{method:'get',evalScripts:true,parameters:{First:next},encoding:'UTF-8'});
		else if (section == 'gs')
			var gs = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/GroupSummaries,page='+step+'.htmx',{method:'get',evalScripts:true,parameters:{First:next},encoding:'UTF-8'});
		else if (section == 'goal')
			var goal = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/TopGoals,page='+step+'.htmx',{method:'get',evalScripts:true,parameters:{First:next},encoding:'UTF-8'});
		else
			var txt = new Ajax.Updater('listMatches',baseURL +'/video/VOD/Archive/VodSearch,page='+step+'.htmx',{method:'get',evalScripts:true,parameters:{First:next,srchString:src},encoding:'UTF-8'});
	}
	
}
function getResult (what,x, y)
{
    var i;
    var z = x;
    //
    if (what == "add")
    {
		for (i = 1; i <= y; i++)
		{
			z++;
		}
    }
    else
    {
		for (i = 1; i <= y; i++)
		{
			z--;
		}
    }
    return z;
}
function pageNavigateSearchNews(step, psize)
{
	if (!window.baseUrl) {
		baseUrl = document.location.pathname;
	}
	var page = parseInt(psize,10)-1;
	var pre = "page=";
	var begin = baseUrl.indexOf(pre);
	var newIndex = 1;
	if (begin > 0) {
		begin += pre.length;
		var ixEnd = baseUrl.lastIndexOf('.');
		var oldIndex = parseInt(baseUrl.substring(begin, ixEnd),10);
		newIndex = oldIndex + parseInt(step,10);
		var newsLink;
		if (newIndex > 0)
			newsLink = baseUrl.substring(0,begin) + newIndex + baseUrl.substr(ixEnd);
		else {
			var pre2 = ",page=" + oldIndex;
			begin = baseUrl.indexOf(pre2);
			newsLink = baseUrl.substring(0,begin) + baseUrl.substring(begin + pre2.length);
		}
	}
	else {
		var pre2 = ".htm";
		begin = baseUrl.indexOf(pre2);
		newsLink = baseUrl.substring(0,begin) + ',page=1' + baseUrl.substring(begin);
	}

	newsLink = newsLink.substring(0,newsLink.length-1) + 'x';
	
	window.location.href = newsLink;
}

function SetCurrency(CountryISO) 
{ 
	switch (CountryISO)
	{ 
		case 'BE': return ('EUR');
		case 'BA': return ('EUR');
		case 'BG': return ('EUR');
		case 'HR': return ('EUR');
		case 'CY': return ('EUR');
		case 'CZ': return ('EUR');
		case 'DK': return ('EUR');
		case 'EE': return ('EUR');
		case 'FO': return ('EUR');
		case 'FI': return ('EUR');
		case 'FR': return ('EUR');
		case 'DE': return ('EUR');
		case 'GR': return ('EUR');
		case 'HU': return ('EUR');
		case 'IS': return ('EUR');
		case 'IT': return ('EUR');
		case 'IE': return ('EUR');
		case 'LV': return ('EUR');
		case 'LI': return ('EUR');
		case 'LT': return ('EUR');
		case 'LU': return ('EUR');
		case 'MK': return ('EUR');
		case 'MT': return ('USD');
		case 'ME': return ('EUR');
		case 'MD': return ('EUR');
		case 'NL': return ('EUR');
		case 'NO': return ('EUR');
		case 'PL': return ('EUR');
		case 'PT': return ('EUR');
		case 'RO': return ('EUR');
		case 'RU': return ('EUR');
		case 'SM': return ('EUR');
		case 'RS': return ('EUR');
		case 'SK': return ('EUR');
		case 'SI': return ('EUR');
		case 'ES': return ('EUR');
		case 'SE': return ('EUR');
		case 'CH': return ('EUR');
		case 'TR': return ('EUR');
 		case 'UA': return ('EUR');
		case 'VA': return ('EUR');
		case 'SE': return ('EUR');
		case 'CH': return ('EUR');
		case 'TR': return ('EUR');
		case 'UA': return ('EUR');
		case 'VA': return ('EUR');
		case 'GB': return ('GBP');
		//case '': return ('EUR');
		default: return ('USD');   
	} 
} 

function CompetitionNameInt(CompetitionID) 
{ 
	switch (CompetitionID)
	{ 
		case 1: return ('UCL'); 
		case 3: return ('EURO');
		case 5: return ('Futsal');
		case 9: return ('SuperCup'); 
		case 13: return ('Under21'); 
		case 14: return ('UefaCup');
		case 23: return ('Under17');
		case 24: return ('Under19');
		case 25: return ('WUnder19');
		case 27: return ('FutsalCup');
		case 28: return ('WomenCup');
		case 101: return ('WUnder17');
		default: return (''); 
	} 
} 

// Clear Cookie
function ClearCookie (name) 
{
  var ThreeDays = 3 * 24 * 60 * 60 * 1000;
  var expDate = new Date();
  expDate.setTime (expDate.getTime() - ThreeDays);
  document.cookie = name + "=ImOutOfHere; expires=" + expDate.toGMTString();
}

function DisableAdlink() 
{
	if(document.getElementById('adlinkcontainer') != null){
	document.getElementById('adlinkcontainer').style.visibility='hidden'; 
	document.getElementById('adlinkcontainer').style.display='none'  ;
	}
}

/*--------used for XML client side processing------------*/
function openFeed(sFilename) {
	var i = sFilename.indexOf('/') +1;
	if(i>=0)
		i += sFilename.substr(i).indexOf('/') +1;
	if(i>=0)
		i += sFilename.substr(i).indexOf('/') +1;
	if(i>=0)
		transformXml(sFilename, sFilename.substr(i), 'feed.xslt','divFeed');
}
function init(sFilename,xslt,divName) {
	transformXml(null, sFilename, xslt, divName);
	var feed = getArgs().feed;
	if(feed)
		openFeed(feed)
	return;
}
function transformXml(url, sFilename, xsl, div) {
    var oXmlDom = zXmlDom.createDocument();
	oXmlDom.async = false;
	oXmlDom.load(sFilename);
	var root = oXmlDom.documentElement;
	var node = zXPath.selectSingleNode(root,'channel',null);
	if(node)
	{	
		var feedurl = oXmlDom.createElement('feedurl');
		feedurl.setAttribute('url',url);
		node.appendChild(feedurl);
	}

    var oXslDom = zXmlDom.createDocument();
	oXslDom.async = false;
	oXslDom.load(xsl);

	var str = zXslt.transformToText(oXmlDom,oXslDom);
	document.getElementById(div).innerHTML = str;
}

 function GetCountryCookie(lang,competitionID) {
	var broadcaster = ""; //TODO : reinserire getArgs().B per la redirect alla white label match list
	if (getArgs().L){
		var language = getArgs().L;
		var url = baseURL.substring(baseURL.indexOf("//")+2,baseURL.length);
		if (url.indexOf("www") >-1)
			url = url.replace("www.","");
		if (language == "en")
			var UVSbaseURL = "http://" + url;
		else
			var UVSbaseURL = "http://" + language + "." + url;
	}
	else
		var UVSbaseURL = baseURL;
	if (getArgs().C){
		var competitionID = getArgs().C;
	}
	var countrycode = '';	
	countrycode = getArgs().CountryCode;
	
	var suffix = '';
	if (broadcaster) {
		suffix = '?B=' + broadcaster;
	}
	if (readCookie('geo') == null || readCookie('geo') == '') { //|| readCookie('geo') == 'null'
		if(countrycode != '' && countrycode != null && typeof(countrycode) != "undefined") {
			if (broadcaster) {
				document.location.href= UVSbaseURL + '/Video/Live/Competitions/' + CompetitionName(competitionID) + '/Country=' + countrycode + '/Broadcaster=' + broadcaster + '/MatchList.html'; 
			}
			else{
				document.location.href= UVSbaseURL + '/Video/Live/Competitions/' + CompetitionName(competitionID) + '/Country=' + countrycode + '/MatchList.html' + suffix; 
			}
		}
		else {
			document.location.href= _SelfcareGeoCheckBaseURL + '/video/VideoService/GeoCookie.htmx?rUrl=' + UVSbaseURL + '/Video/Live/Competitions/' + CompetitionName(competitionID) + '/index.html' + suffix; 
		}
	} 
	else { 
		var cookieValue=readCookieParam('geo','CountryCode'); 
		if (cookieValue == '' || cookieValue == '##') {
			if (broadcaster) {
				document.location.href= UVSbaseURL + '/Video/Live/Competitions/' + CompetitionName(competitionID) + '/Country=0/Broadcaster=' + broadcaster + '/MatchList.html';
			}
			else{
				document.location.href= UVSbaseURL + '/Video/Live/Competitions/' + CompetitionName(competitionID) + '/Country=0/MatchList.html' + suffix;
			}
		} 
		else {
			if (broadcaster) {
				document.location.href= UVSbaseURL + '/Video/Live/Competitions/' + CompetitionName(competitionID) + '/Country=' + cookieValue + '/Broadcaster=' + broadcaster + '/MatchList.html'; 
			}
			else{
				document.location.href= UVSbaseURL + '/Video/Live/Competitions/' + CompetitionName(competitionID) + '/Country=' + cookieValue + '/MatchList.html'; 
			}
		} 
	}
}

function selectAttr(sFilename, nodeToselect, attributeToselect) {
    var oXmlDom = zXmlDom.createDocument();
	oXmlDom.async = false;
	oXmlDom.load(sFilename);
	
	var root = oXmlDom.documentElement;
	var _node = zXPath.selectSingleNode(root,nodeToselect,null);

	if(_node)
	{
		return _node.getAttribute(attributeToselect);
	}
	else {
		return 'false';	
	}
}
/**/
function selectAttrLive(nodeToselect, attributeToselect) {
	FireFoxXPath();
	try{
		var parser=new DOMParser();
		var DOMObject=parser.parseFromString($("hiddenXML").value,"text/xml");
		node = DOMObject.selectFxSingleNode(nodeToselect,DOMObject);	
	}
	catch(e){
		DOMObject = XMLnewDocument();
		DOMObject.async = "false";
		DOMObject.loadXML($("hiddenXML").value);
		node = DOMObject.selectSingleNode(nodeToselect);	
	}
	if (node)
		return node.getAttribute(attributeToselect);
	return false;
}

function XMLnewDocument()
{
	if (document.implementation && document.implementation.createDocument) {   
		// This is the W3C standard way to do it   
		return document.implementation.createDocument("", "", null);   
	}
	else
		return doc = new ActiveXObject("MSXML2.DOMDocument");
}

function checkFileExists(sFilename) {
	
	var oXmlHttp = zXmlHttp.createRequest();
	oXmlHttp.open("get", sFilename, false);
	oXmlHttp.send(null);

	if (oXmlHttp.status != 200) {
		return false; 
	} 
	else {
		return true;
	}
}
 
function DisplayBC (BroughtText,LaunchText,qstring,hires,fullvoc,helpvoc,lang) {
 if (qstring.indexOf(',itemID=')>-1 && qstring.indexOf(',LeadID=')>-1 ) { 
 itemid = qstring.substring(qstring.indexOf(',itemID=')+8,qstring.indexOf(',LeadID='));
 var Mid = itemid.substring(1,7);  
 channelid = qstring.substring(0,qstring.indexOf(',itemID='));   
 leadid = qstring.substring(qstring.indexOf(',LeadID=')+8,qstring.indexOf(',player16-9='));
 //var is169 = qstring.substring(qstring.indexOf(',player16-9=')+12,qstring.length);
 var is169 = qstring.substring(qstring.indexOf(',player16-9=')+12,qstring.indexOf(',isaudio='));
 parsedelements = leadid.split('_'); 
 compstring = parsedelements[0]; 
 broadcasterid = parsedelements[1];
 }
var req = new evaluateXPath();
var nodeToselect = '//fixtures/round/matchday/session/match[@code=' + Mid + ']/livevideo[@broadcaster=' + broadcasterid + ']';
//var bcHome = selectAttr('/applets/uvs/' + compstring + '/UVSLiveStreams.xml', nodeToselect, 'broadcasterHomePage');
var res = req.createRequest(compstring,"UVSLiveStreams");
var bcHome = req.selectXPath(res,nodeToselect,'broadcasterHomePage');
var nodeHiRes = "//fixtures/round/matchday/session/match[@code=" + Mid + "]/livevideo[@broadcaster=" + broadcasterid + " and @StreamResolution=2]";
//var attHiRes = selectAttr("/applets/uvs/" + compstring + "/UVSLiveStreams.xml", nodeHiRes, "StreamResolution");
var attHiRes = req.selectXPath(res,nodeHiRes,'StreamResolution');
if (attHiRes){
	var nodeLowRes = "//fixtures/round/matchday/session/match[@code=" + Mid + "]/livevideo[@broadcaster=" + broadcasterid + " and @StreamResolution=1]";
	//var urlLow = selectAttr("/applets/uvs/" + compstring + "/UVSLiveStreams.xml", nodeLowRes, "url");
	var urlLow = req.selectXPath(res,nodeLowRes,'url');
	var LowasxUrl = 'http://video.uefa.com/MultimediaFiles/UVSLiveASX/' + urlLow + '.asx'; 
	var functLow = "LaunchLiveVideo('"+fullvoc+"','"+LaunchText+"','"+helpvoc+"','"+lang+"','"+LowasxUrl+"','"+is169+"');replaceButton('"+hires+"','"+BroughtText+"','"+bcHome+"','"+compstring+"','"+broadcasterid+"','"+urlLow+"','"+fullvoc+"','"+LaunchText+"','"+helpvoc+"','"+lang+"','"+is169+"')";
	//var urlHi = selectAttr("/applets/uvs/" + compstring + "/UVSLiveStreams.xml", nodeHiRes, "url");
	var urlHi = req.selectXPath(res,nodeHiRes,'url');
	var HiasxUrl = 'http://video.uefa.com/MultimediaFiles/UVSLiveASX/' + urlHi + '.asx'; 
	var functHi = "LaunchLiveVideo('"+fullvoc+"','"+LaunchText+"','"+helpvoc+"','"+lang+"','"+HiasxUrl+"','"+is169+"');replaceButton('"+hires+"','"+BroughtText+"','"+bcHome+"','"+compstring+"','"+broadcasterid+"','"+urlHi+"','"+fullvoc+"','"+LaunchText+"','"+helpvoc+"','"+lang+"','"+is169+"')";

	if (channelid.indexOf("L") == -1)
		var images = "<a href=\"#\" onfocus=\"this.blur()\" onclick=\""+functLow+"\"><img id=\"Limg\" src=\"/ml/images/video/uvs/ppv/buy_uefa_lo_popup.gif\" border=\"0\"/></a>&nbsp;&nbsp;<img id=\"Himg\" src=\"/ml/images/video/uvs/ppv/buy_uefa_hi_popup_inactive.gif\" border=\"0\"/>";
	else if (channelid.indexOf("H") == -1)
		var images = "<img id=\"Limg\" src=\"/ml/images/video/uvs/ppv/buy_uefa_lo_popup_inactive.gif\" border=\"0\"/>&nbsp;&nbsp;<a href=\"#\" onfocus=\"this.blur()\" onclick=\""+functHi+"\"><img id=\"Himg\" src=\"/ml/images/video/uvs/ppv/buy_uefa_hi_popup.gif\" border=\"0\"/></a>";
	//var images = "<a href=\"#\" onfocus=\"this.blur()\" onclick=\""+functHi+"\"><img src=\"/ml/images/video/uvs/ppv/buy_uefa_hi_popup.gif\" border=\"0\"/></a>&nbsp;&nbsp;<a href=\"#\" onfocus=\"this.blur()\" onclick=\""+functLow+"\"><img src=\"/ml/images/video/uvs/ppv/buy_uefa_lo_popup.gif\" border=\"0\"/></a>";
	var BDtext="<div id=\"divHres\"><b>" + hires + " :&nbsp;&nbsp;</b>" + images + "</div><HR size=\"0.2\"><div id=\"textLeft\"><b>" + BroughtText + ":</b></div><div><a href=\"#\" onfocus=\"this.blur()\" onclick=\"window.open('" + bcHome + "', '_blank','toolbar=yes,location=yes,directories=yes,resizable=yes,scrollbars=yes'); return false;\"><img src=\"/ml/images/Video/uvs/broadcaster/logos/" + compstring + "/" + broadcasterid + "_player.gif\" width=\"200\" height=\"80\" border=\"0\"/></a></div>";
}
else{
	var BDtext="<div id=\"textLeft\"><b>" + BroughtText + ":</b></div><BR><a href=\"#\" onfocus=\"this.blur()\" onclick=\"window.open('" + bcHome + "', '_blank','toolbar=yes,location=yes,directories=yes,resizable=yes,scrollbars=yes'); return false;\"><img src=\"/ml/images/Video/uvs/broadcaster/logos/" + compstring + "/" + broadcasterid + "_player.gif\" width=\"200\" height=\"80\" border=\"0\"/></a>";
}
document.getElementById("Broadcaster").innerHTML=BDtext;
}
function replaceButton(hires,BroughtText,bcHome,compstring,broadcasterid,url,fullvoc,LaunchText,helpvoc,lang,isplayer169)
{
	if (url.indexOf("L") == -1){
		var newUrl = url.replace("H","L");
		var asxUrl = "http://video.uefa.com/MultimediaFiles/UVSLiveASX/"+newUrl+".asx";
		var funct = "LaunchLiveVideo('"+fullvoc+"','"+LaunchText+"','"+helpvoc+"','"+lang+"','"+asxUrl+"','"+isplayer169+"');replaceButton('"+hires+"','"+BroughtText+"','"+bcHome+"','"+compstring+"','"+broadcasterid+"','"+newUrl+"','"+fullvoc+"','"+LaunchText+"','"+helpvoc+"','"+lang+"','"+isplayer169+"')";
		var images = "<a href=\"#\" onfocus=\"this.blur()\" onclick=\""+funct+"\"><img id=\"Limg\" src=\"/ml/images/video/uvs/ppv/buy_uefa_lo_popup.gif\" border=\"0\"/></a>&nbsp;&nbsp;<img id=\"Himg\" src=\"/ml/images/video/uvs/ppv/buy_uefa_hi_popup_inactive.gif\" border=\"0\"/>";
	}
	else if (url.indexOf("H") == -1){
		var newUrl = url.replace("L","H");
		var asxUrl = "http://video.uefa.com/MultimediaFiles/UVSLiveASX/"+newUrl+".asx";
		var funct = "LaunchLiveVideo('"+fullvoc+"','"+LaunchText+"','"+helpvoc+"','"+lang+"','"+asxUrl+"','"+isplayer169+"');replaceButton('"+hires+"','"+BroughtText+"','"+bcHome+"','"+compstring+"','"+broadcasterid+"','"+newUrl+"','"+fullvoc+"','"+LaunchText+"','"+helpvoc+"','"+lang+"','"+isplayer169+"')";
		var images = "<img id=\"Limg\" src=\"/ml/images/video/uvs/ppv/buy_uefa_lo_popup_inactive.gif\" border=\"0\"/>&nbsp;&nbsp;<a href=\"#\" onfocus=\"this.blur()\" onclick=\""+funct+"\"><img id=\"Himg\" src=\"/ml/images/video/uvs/ppv/buy_uefa_hi_popup.gif\" border=\"0\"/></a>";
	}
	var BDtext="<div id=\"divHres\"><b>" + hires + " :&nbsp;&nbsp;</b>" + images + "</div><HR size=\"0.2\"><div id=\"textLeft\"><b>" + BroughtText + ":</b></div><div><a href=\"#\" onfocus=\"this.blur()\" onclick=\"window.open('" + bcHome + "', '_blank','toolbar=yes,location=yes,directories=yes,resizable=yes,scrollbars=yes'); return false;\"><img src=\"/ml/images/Video/uvs/broadcaster/logos/" + compstring + "/" + broadcasterid + "_player.gif\" width=\"200\" height=\"80\" border=\"0\"/></a></div>";
	document.getElementById("Broadcaster").innerHTML=BDtext;
}
function trackStreamClose() {
	//----------HBX tracking-----------
    var Qstring = getArgs().ChannelID;
	if (Qstring && Qstring.indexOf(',itemID=')>-1 && Qstring.indexOf(',LeadID=')>-1 ) {
		broadcaster = Qstring.substring(Qstring.indexOf(',LeadID=')+8,Qstring.indexOf(',player16-9='));
		parsedelements = broadcaster.split('_'); 
		compstring = parsedelements[0]; 
		broadcasterid = parsedelements[1];
	}
	if (broadcaster && broadcaster != '')  
	{	
		if (readCookie('geo') != ''){
			var cookieValue=readCookieParam('geo','CountryCode');
			if (cookieValue == 'CN'){
				_hbPageView('close', '/e/uvs/tracking/live/' + compstring + '/B' + broadcasterid + '/Country=' + cookieValue);
			}
			else{
				_hbPageView('close', '/e/uvs/tracking/live/' + compstring + '/B' + broadcasterid);
			}
		}
		else{
			_hbPageView('close', '/e/uvs/tracking/live/' + compstring + '/B' + broadcasterid);
		}
		//_hbPageView('close', '/e/uvs/tracking/live/' + compstring + '/B' + broadcasterid);
	}
}

function openVideo(affiliate,option,URL,country,item,broadcaster,competition,season,matchday,match,BCHomepage,lang,price)
{ 
	var affiliationBC;
	var suffix = '';
	if (getArgs().B) {
		suffix = '?B=' + getArgs().B; 
	}
	var CountryValuefromCookie;
	var leadid;
	/**/
	if ((readCookieParam('geo','CountryCode')==null) && country != "audio") {
		//redirect to page that sets the cookie
		document.location.href = baseURL + '/video/Live/Competitions/' + CompetitionNameInt(parseInt(competition)) + '/index.html';		
	}
	else {
		CountryValuefromCookie = readCookieParam('geo','CountryCode');	
	}
	//TODO: RIMUOVERE!!!
	/*country = 'IT';
	CountryValuefromCookie = 'IT';*/
	/*----DIFF COUNTRY IN URL CONTROL ONLY IN PRODUCTION------------------*/
	if (CountryValuefromCookie != country && country != "audio"){ 
	/*--------------------------------------------------------------------*/
		if (CountryValuefromCookie != country){ 
			affiliationBC = getArgs().B;
			if(typeof(CountryValuefromCookie) != "undefined")
			{ 
				if (lang == 'I') {
					alert('Abbiamo identificato che il suo paese non corrisponde a questa lista. Clicca su "OK" per essere reindirizzato.');
				}
				else if (lang == 'F') {
					alert(unescape('Nous%20avons%20d%E9tect%E9%20que%20votre%20pays%20ne%20correspond%20pas%20%E0%20cette%20liste.%20Cliquer%20%22OK%22%20pour%20%EAtre%20r%E9orient%E9.'));
				}
				else {
					alert('We have detected that your country does not correspond to this listing. Click "OK" to be redirected.');
				}
				document.location.href = baseURL + '/video/Live/Competitions/' + CompetitionNameInt(parseInt(competition)) + '/Country=' + CountryValuefromCookie + '/MatchList.html' + suffix;
			}
		}
	}
	else {
		if (option == '1') {						
			if (URL == 'capped') {
				window.open(baseURL + '/video/Live/Competitions/' + CompetitionNameInt(parseInt(competition)) + '/Broadcaster=' + broadcaster + '/Match=' + match + '/BClaunch.html?URL=' + BCHomepage,'Broadcaster');
			}
			else if (URL != '') {
				window.open(baseURL + '/video/Live/Competitions/' + CompetitionNameInt(parseInt(competition)) + '/Broadcaster=' + broadcaster + '/Match=' + match + '/BClaunch.html?URL=' + URL,'Broadcaster');
			}
			else {	
				window.open(BCHomepage,'Broadcaster');								
			}
		}
		else {
			var affiliation = "U";	
			affiliationBC = getArgs().B; 
			if (affiliationBC) {
				//leadid =  CompetitionNameInt(parseInt(competition)) + '_' + broadcaster + '_E';
				affiliation = "E";				
			}
	
			/////****Static campaign*********/////
				_hbSet('cmp','AFC-BC_ClicksOnBuy');
				_hbSet('cmp.c6',broadcaster); 
				_hbSet('cmp.c7', affiliation);
				_hbSet('cmp.c8', match);
				_hbSet('cmp.c9', URL);
				_hbSet('cmp.c10',competition);//9 volte 08/09/08
				_hbSend();
			/////****End Static campaign*********///////
			channel = URL;
			if (price=='0.00') {
				var nodeToselect = '//session[match[@code=' + match + ']]/streams/broadcaster[@id=' + broadcaster + ']';
				//var matchstatus = selectAttr('/applets/uvs/' + CompetitionNameInt(parseInt(competition)) + '/UVSLiveStreamsStatus.xml', nodeToselect, 'status')					
				var req = new evaluateXPath();
				var res = req.createRequest(CompetitionNameInt(parseInt(competition)),"UVSLiveStreamsStatus");
				var matchstatus = req.selectXPath(res,nodeToselect,'status');
				if (matchstatus != 'on') {
					fnOpenWindow(unescape('/video/live/block.html?msg=This stream is no longer available, please try again later' + '&LeadId=' + leadid), 'LiveMatch', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 650, 450, '', '');
					return;
				}
			}	
			//if (country != "audio")
				ChkStreamAuth(URL,affiliate,competition,season,matchday,match,country,item,affiliation,channel,'true',lang,broadcaster);
			//else
			//	BuyStreamAuth(competition,season,matchday,match,country,item,leadid,channel,'true',lang);
		}
	}
}

function showRegions()
{	
	var broadcaster = getArgs().B;
	var suffix = '';
	if (broadcaster) {
		suffix = '?B=' + broadcaster;
	}

	if (GetCookie('geo') == null || GetCookie('geo') == '' || GetCookie('geo') == 'null') { 
		var oXmlDom = zXmlDom.createDocument();
		oXmlDom.async = false;
		oXmlDom.load('/applets/uvs/regions.xml');

		var oXslDom = zXmlDom.createDocument();
		oXslDom.async = false;
		oXslDom.load('/xsl/video/UVS/Live/RegionCheck.xsl');

		var str = zXslt.transformToText(oXmlDom,oXslDom);

		document.getElementById('result').innerHTML=str;
	} 
	else { 
		if (GetCookie('geo') == '' || GetCookie('geo') == '##' || GetCookie('geo') == 'null') { 
			document.location.href='/Video/Live/Competitions/UCL/Country=0/MatchList.html' + suffix; 
		} 
		else { 
			document.location.href='/Video/Live/Competitions/UCL/Country=' + GetCookie('geo') + '/MatchList.html' + suffix; 
		} 
	}
} 
function selectRegion(r,rname)
{
	var broadcaster = getArgs().B;
	var suffix = '';
	if (broadcaster) {
		suffix = '?B=' + broadcaster;
	}
	SetCookie('geo',r, 1, '/', document.location.host, false);
	document.location.replace(GetBaseURL() + '/Video/Live/Competitions/UCL/Country='+ r +'/MatchList.html' + suffix);
}

function MouseOver(picimage)
{
	Picture_Over = eval(picimage +"On.src")
	document[picimage].src = Picture_Over
}
function MouseOut(picimage)
{
	Picture_Out = eval(picimage +"Off.src")
	document[picimage].src = Picture_Out
}

function OpenLiveAudio(season,matchday,lang)
{
	fnOpenWindow(baseURL + '/video/Competitions/UCL/Season='+season+'/Matchday='+matchday+'/LiveAudio.html', 'LiveAudio', 'no', 'no', 'no', 'no', 'no', 'no', 'no', 650, 450, '', '');
}

function ReplaceHTML(imgsrc,title,kind,isfree)
{
	if(title.indexOf("\\'")>-1)
		title.replace("\\'","\'");
	if(title.indexOf("\\\"")>-1)
		title.replace("\\\"","\"");
	if(kind.indexOf("\\'")>-1)
		kind.replace("\\'","\'");
	if(isfree=='true')
		document.getElementById("MediaDetailsToReload").innerHTML="<h1>You are watching:</h1><img src='"+ imgsrc+"' width='52' height='51' alt='' class='MediaThumb' /><h2><em>"+kind+"</em><br />"+ title +"<img src='/ml/images/video/uvs/common/free.gif' border='0' alt='free video'/></h2>";
	else
		document.getElementById("MediaDetailsToReload").innerHTML="<h1>You are watching:</h1><img src='"+ imgsrc+"' width='52' height='51' alt='' class='MediaThumb' /><h2><em>"+kind+"</em><br />"+ title +"</h2>";
	document.getElementById("MediaDetailsToReload").style.textAlign='left';
	document.getElementById("MediaDetailsToReload").style.paddingLeft='0px';
}

  
function isNumeric(value) {
  var numbers="0123456789";
    // value e' una Stringa o un singolo character?
    if(value.length>1) {
      // rimuove segni negativi
      value=Math.abs(value)+"";
      for(j=0;j<value.length;j++) {
        // chiamata isNumeric ricorrentemente per ogni carattere
        number=isNumeric(value.substring(j,j+1));
        if(!number) return number;
      }
      return number;
    }
    else {
      // se x e' un numero return true
      if(numbers.indexOf(value)>=0) return true;
      return false;
    }
  }
  
function isMicrosoftIE()
{
	if(navigator.appName.indexOf('Microsoft')>-1)
		return true;
	return false;
}

function trackEuroExternal(bc)
{
	_hbPageView(bc, '/e/uvs/live/euro/option1/' + bc);
	return false;
}

function replaceTR(match,bc)
{
	var id = "TR" + match + "B" + bc + "SR2";
	var img = "IMG" + match + "B" + bc;
	if ($(img).src.indexOf("plus.gif") > 0)
	{
		$(id).style.visibility='visible';
		$(id).style.display='';
		$(img).src = "/ml/images/video/uvs/ppv/minus.gif";
	}
	else if ($(img).src.indexOf("minus.gif") > 0)
	{
		$(id).style.visibility='hidden';
		$(id).style.display='none';
		$(img).src = "/ml/images/video/uvs/ppv/plus.gif";
	}
}

/*------------------NEW----------------------*/

function mediaItem(accountId,channelId,itemId,returnURL,buyURL,loginURL,errorURL,newWin,newsid,newstitle)
{ //alert(accountId+","+channelId+","+itemId+","+returnURL+","+buyURL+","+loginURL+","+errorURL+","+newWin)
	this.accountId = accountId;
	this.channelId = channelId;
	this.itemId = itemId;
	this.rURL = returnURL;
	this.bURL = buyURL;
	this.lURL = loginURL;
	this.eURL = errorURL;
	this.nWin = newWin;
	this.nwid = newsid;
	this.nwtitle = newstitle;
 
	this.getXml = function(){//<?xml version="1.0" encoding="utf-8"?>
		return ('<Item AccountId="' + this.accountId + '" ChannelId="' + this.channelId + '" ContentId="' + this.itemId + '" ReturnURL="' + this.rURL + '" BuyURL="' + this.bURL + '" LoginURL="' + this.lURL + '" ErrorURL="' + this.eURL + '" newWin="' + this.nWin + '" newsId="' + this.nwid + '" newsTitle="' + this.nwtitle + '"  />'); 
	}
	this.QueryMAN = function(sid,ticket,handler)
	{
 		sendRequest(sid,ticket,this.getXml(),handler);
	}
} 

function mediaItemList()
{
	this.itemsList = new Array();
	
	this.addMediaItem = function(item) 
	{
		this.itemsList[this.itemsList.length] = item;
	}
	
	this.getLength = function() 
	{
		return this.itemsList.length;
	}
	
	this.getXml = function()
	{
		var outerXml = '<root>';
		for (var i=0;i<this.getLength();i++)
		{
			outerXml += this.itemsList[i].getXml();
		}
		outerXml += '</root>';
		 
		return outerXml;
	}
	this.QueryMAN = function(sid,ticket,handler)
	{
		sendRequest(sid,ticket,this.getXml(),handler);
	}
}

function FireFoxXPath()
{
if( document.implementation.hasFeature("XPath", "3.0") ){
	XMLDocument.prototype.selectFxNodes = function(cXPathString, xNode)  {
		if( !xNode ) { xNode = this; } 
		var oNSResolver = this.createNSResolver(this.documentElement)
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
		var aResult = [];
		for( var i = 0; i < aItems.snapshotLength; i++)     {
			aResult[i] =  aItems.snapshotItem(i);
		}    
		return aResult;
	}

	Element.prototype.selectFxNodes = function(cXPathString)  {
		if(this.ownerDocument.selectFxNodes)     {
			return this.ownerDocument.selectFxNodes(cXPathString, this);     }
		else{throw "For XML Elements Only";}
		}
	}

	if( document.implementation.hasFeature("XPath", "3.0") ){
	XMLDocument.prototype.selectFxSingleNode = function(cXPathString, xNode)  {
		if( !xNode ) { xNode = this; } 
		var xItems = this.selectFxNodes(cXPathString, xNode);
		if( xItems.length > 0 )     {
			return xItems[0];
		}
		else     {
			return null;     }
		}
	Element.prototype.selectFxSingleNode = function(cXPathString)  {  
		if(this.ownerDocument.selectFxSingleNode)     {
			return this.ownerDocument.selectFxSingleNode(cXPathString, this);
		}
		else{throw "For XML Elements Only";}
		}
	}
}

function mediaItemsResponse(DOMObject)
{
//------------------------------------------------
//**********Function that expand the XMLDocument and Element objects 
//**********for Mozilla FireFox and Opera v9.0 to enable functions
//**********selectFxSingleNode and selectFxNode
	FireFoxXPath(); 
	
//------------------------------------------------
	
	this.DOMObject = DOMObject;
	
	var agent=navigator.appName;

	if(agent.indexOf("Microsoft")>-1){
		this.GlobalErrorCode = DOMObject.selectSingleNode("/root/@errorcode").value;
		this.GlobalErrorMessage = DOMObject.selectSingleNode("/root/@errormessage").value;
	}
	else{
		this.GlobalErrorMessage = DOMObject.selectFxSingleNode("/root/@errormessage",DOMObject).nodeValue;
		this.GlobalErrorCode = DOMObject.selectFxSingleNode("/root/@errorcode",DOMObject).nodeValue;
	}
	
	if (this.GlobalErrorCode == "0")
	{
		this.Success = true;
	}
	else
	{
		this.Success = false;
	}/*
	this.getPrice = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("price",itemId);
				
		return this.runXpath(xpath);
	}

	this.getDiscountedPrice = function (discountPercentage,itemId)
	{
		itemId = itemId + "";
		var price = this.getPrice(itemId);
		
		var discountedPrice = price * ((100-discountPercentage)/100);
		var discountedPrice = Math.round(100*discountedPrice)/100;
		
		return discountedPrice;
	}*/

	this.isAuthorized = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("authorized",itemId);
		
		return (this.runXpath(xpath) == "true");
	}
	this.getItemErrorCode = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("errorcode",itemId);
				
		return this.runXpath(xpath);
	}/**/

	this.getName = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("name",itemId);
				
		return this.runXpath(xpath);
	}

	this.getEntityID = function (entityId)
	{
		entityId = entityId + "";
		var xpath = this.genXpath("contentId",entityId);
				
		return this.runXpath(xpath);
	}

	this.getReturnURL = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("returnurl",itemId);
				
		return this.runXpath(xpath);
	}

	this.getBuyURL = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("buyurl",itemId);
				
		return this.runXpath(xpath);
	}

	this.getLoginURL = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("loginurl",itemId);
				
		return this.runXpath(xpath);
	}

	this.getErrorURL = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("errorurl",itemId);
				
		return this.runXpath(xpath);
	}

	this.getnewWin = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("newwin",itemId);
				
		return this.runXpath(xpath);
	}
		
	this.getItemErrorMessage = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("errormessage",itemId);
				
		return this.runXpath(xpath);
	}
	/*
	this.getCurrency = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("currency",itemId);
				
		return this.runXpath(xpath);
	}
	
	this.getCurrencySign = function (itemId)
	{
		itemId = itemId + "";
		
		var curr = this.getCurrency(itemId);
		var sign = "";
		switch(curr)
		{
			case "EUR":
				sign = "&euro;";
				break;
			case "USD":
				sign = "$";
				break;
			case "GBP":
				sign = "&pound;";
				break;
			default:
				sign = curr;
		}
		
		return sign;
	}*/
	
	this.getAccountId = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("accountId",itemId);
				
		return this.runXpath(xpath);
	}
	
	this.getChannelId = function (itemId)
	{
		itemId = itemId + "";
		var xpath = this.genXpath("channelId",itemId);
				
		return this.runXpath(xpath);
	}
	
	this.urlToPlay = function()
	{
		var xpath = this.genXpath("urlToPlay");
		return this.runXpath(xpath);
	}
	
	this.newsId = function()
	{
		var xpath = this.genXpath("newsid");
		return this.runXpath(xpath);
	}
	
	this.newsTitle = function()
	{
		var xpath = this.genXpath("newstitle");
		return this.runXpath(xpath);
	}
	
	this.runXpath = function (xpath)
	{
		var result = "";
		var agent=navigator.appName;
		if(agent.indexOf("Microsoft")>-1){
			try
			{
				result = this.DOMObject.selectSingleNode(xpath).value;
			}
			catch(ex)
			{
				result = "";
			}
		}
		else{
			try
			{
				result = this.DOMObject.selectFxSingleNode(xpath).nodeValue;
			}
			catch(ex)
			{
				result = "";
			}
		}
		return result;
	}
	/*
	this.genXpath = function (attribute,itemId)
	{
		var xpath = "";
		itemId = itemId + "";
		if (itemId == "")
		{
			xpath = "/root/item/@" + attribute;
		}
		else
		{
			xpath = "/root/item[@itemId = '" + itemId + "']/@" + attribute;
		}alert(attribute + "," + xpath);
		return xpath;
	}*/
	
	this.genXpath = function (attribute,itemId)
	{
		var xpath = "";
		xpath = "/root/item/@" + attribute;
		return xpath;
	}
}

function sendRequest(sid,ticket,xml, handler)
{
	url = MQSAUrl;
	url += "sid=" + sid + "&ticket=" + ticket;
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			postBody: xml, 
			onComplete: handler
		});
}
function initWMPlayer(testconfig,closewin)
{
	if (agent.indexOf('Microsoft') > -1)
		insertWMPobj('MediaPlayer', PlayerWidth, PlayerHeight, playerVer, false, 'http://video.uefa.com/MultimediaFiles/News/uefa/UEFAGeneral/586118.asx', '40');
	else
		insertWMPobj('MediaPlayer', PlayerWidth, PlayerHeight, playerVer, true, 'http://video.uefa.com/MultimediaFiles/News/uefa/UEFAGeneral/586118.asx', '40');
	var bottomlinks = "<a href=\"#\" onclick=\"window.open('http://support.video.uefa.com/sys/en/syscheck.asp', '_blank','toolbar=yes,location=yes,directories=yes,resizable=yes,scrollbars=yes'); return false;\"><span id=\"FullButton\" class=\"BottomButton\">" + testconfig + "</span></a><a href=\"#\" onclick=\"javascript:window.close();\"><span id=\"LaunchButton\" class=\"BottomButton\">" + closewin + "</span></a>";
	document.getElementById('PlayerButtonsBottom').innerHTML=bottomlinks;
}
function  linkclick(section,comp,lang)
{
	if (section == 'replay')
	{
		$$('div.highlighted').each(function(e){e.removeClassName('highlighted')});
		$$('div.fake').each(function(e){e.addClassName('clickable')});
		$('replay').addClassName('highlighted');
		$('replay').removeClassName('clickable');
		document.location.href = baseURL + "/video/vod/competitions/index.html";
	}
	else if (section == 'live')
	{
		$$('div.highlighted').each(function(e){e.removeClassName('highlighted')});
		$$('div.fake').each(function(e){e.addClassName('clickable')});
		$('live').addClassName('highlighted');
		$('live').removeClassName('clickable');
		if(comp == "")
			document.location.href = baseURL + "/video/live/index.html";
		else
			document.location.href = baseURL + "/video/live/competitions/"+comp+"/index.html";		
	}
	else if (section == 'liveaudio')
	{
		$$('div.highlighted').each(function(e){e.removeClassName('highlighted')});
		$$('div.fake').each(function(e){e.addClassName('clickable')});
		$('liveaudio').addClassName('highlighted');
		$('liveaudio').removeClassName('clickable');
		document.location.href = baseURL + "/video/live/competitions/"+comp+"/audiomatchlist.html";
	}
	else if (section == 'magazine')
	{
		$$('div.highlighted').each(function(e){e.removeClassName('highlighted')});
		$$('div.fake').each(function(e){e.addClassName('clickable')});
		$('magazine').addClassName('highlighted');
		$('magazine').removeClassName('clickable');
		
		if (lang == 'E'){
			document.location.href = "http://www1.uefa.com/magazine/index2.html";
		}
		else
		{
			if(lang == 'I')document.location.href = "http://www1.it.uefa.com/magazine/index2.html";
			if(lang == 'F')document.location.href = "http://www1.fr.uefa.com/magazine/index2.html";
			if(lang == 'D')document.location.href = "http://www1.de.uefa.com/magazine/index2.html";
			if(lang == 'S')document.location.href = "http://www1.es.uefa.com/magazine/index2.html";
			if(lang == 'P')document.location.href = "http://www1.pt.uefa.com/magazine/index2.html";
		}	
	}
}

/**********************Test for replace zxml.js*******************************/
function evaluateXPath()
{
	this.createRequest = function(comp,xmlName){
		url = '/applets/uvs/' + comp + '/' + xmlName + '.xml';
		var ht = this.chooseXmlHttpHandler();
		ht.open("GET",url,false);
		ht.send(null);
		return ht.responseText;
	}
	this.selectXPath = function(xml,node,attribute) {
		FireFoxXPath();

		try{
			var parser=new DOMParser();
			var DOMObject=parser.parseFromString(xml,"text/xml");
			node = DOMObject.selectFxSingleNode(node,DOMObject);		
		}
		catch(e){
			DOMObject = XMLnewDocument();
			DOMObject.async = "false";
			DOMObject.loadXML(xml);
			node = DOMObject.selectSingleNode(node);		
		}
		if (node)
			return node.getAttribute(attribute);
		return false;
	}
	this.chooseXmlHttpHandler = function(){
		var xmlHttp = null;
		if (window.XMLHttpRequest) {
			// If IE7, Mozilla, Safari, and so on: Use native object.
			try{
			xmlHttp = new XMLHttpRequest();
			}
			catch(e){xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');}
		}
		else
		{
			if (window.ActiveXObject) {
				// ...otherwise, use the ActiveX control for IE5.x and IE6.
				xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
			}
		}
		return xmlHttp;
	}
}

function GetGeoCookie(page,qstring) {
	var UVSbaseURL = "";
	if (page == 'hp'){
		UVSbaseURL = baseURL + "/video/index.html";
		redirectUrl = baseURL + "/video/geoindex.html";
	}
	else if (page == 'replay'){
		UVSbaseURL = baseURL + "/video/vod/competitions/index.html" + qstring;		
		if(qstring != ''){
			redirectUrl = baseURL + "/video/vod/competitions/geoindex.html" + qstring;
		}
		else{
			redirectUrl = baseURL + "/video/vod/competitions/geoindex.html" + qstring;
		}
	}
	if (readCookie('geo') == null) {
		document.location.href= _SelfcareGeoCheckBaseURL + '/video/VideoService/GeoCookie.htmx?rUrl=' + UVSbaseURL; 
	} 
	else {
		document.location.href= redirectUrl;
	}
	//if (document.location.search.indexOf('CountryCode=')>-1)document.location.search="";
}

var css_browser_selector = function() {
  var t = this; var ua = navigator.userAgent.toLowerCase(); var is = function(x) { return ua.indexOf(x) != -1; };
  var h = document.getElementsByTagName('html')[0]
  var b = (ua.indexOf("opera/9") > -1) ? 'opera opera9' : (ua.indexOf("opera 8") > -1) ? 'opera opera8' : (ua.indexOf("opera 7") > -1) ? 'opera opera7' : (ua.indexOf("msie 8") > -1) ? 'ie ie8 ie7 ' : (ua.indexOf("msie 7") > -1) ? 'ie ie7' : (ua.indexOf("msie 6") > -1) ? 'ie ie6' : (ua.indexOf("msie 5.5") > -1) ? 'ie ie55' : (ua.indexOf("msie 5.23") > -1) ? 'ie ie523' : (ua.indexOf("msie 5.0") > -1) ? 'ie ie5' : (ua.indexOf("chrome") > -1) ? 'safari chrome' : (ua.indexOf("safari") > -1 && ua.indexOf("version/3.") > -1 && ua.indexOf("version/3.") < ua.indexOf("safari")) ? 'safari safari3' : (ua.indexOf("safari") > -1) ? 'safari safari2' : (ua.indexOf("seamonkey") > -1) ? 'seamonkey gecko' : (ua.indexOf("netscape") > -1) ? 'netscape gecko' : (ua.indexOf("firefox") > -1) ? 'firefox gecko' : (ua.indexOf("gecko") > -1) ? 'gecko' : '', os = (is('x11') || is('linux')) ? ' linux' : is('mac') ? ' mac' : is('win') ? ' win' : '';
  var c = b + os + ' js'; h.className += h.className ? ' ' + c : c;
  t.ver = navigator.appVersion; t.agent = navigator.userAgent; t.mac = ua.indexOf("mac") > -1; t.pc = ua.indexOf("win") > -1; t.opera = ua.indexOf("opera") > -1;
  t.opera9 = ua.indexOf("opera/9") > -1; t.opera8 = ua.indexOf("opera 8") > -1; t.opera7 = ua.indexOf("opera 7") > -1; t.ie8 = (ua.indexOf("msie 8") > -1 && !t.opera) ? 1 : 0; t.ie7 = (ua.indexOf("msie 7") > -1 && !t.opera) ? 1 : 0; t.ie6 = (ua.indexOf("msie 6") > -1 && !t.opera) ? 1 : 0; t.ie55 = (ua.indexOf("msie 5.5") > -1 && !t.opera) ? 1 : 0; t.ie523 = (ua.indexOf("msie 5.23") > -1) ? 1 : 0; t.ie4 = (ua.indexOf("msie 4") > -1) ? 1 : 0; t.ie3 = (ua.indexOf("msie 3") > -1) ? 1 : 0; t.ie5 = (ua.indexOf("msie 5.0") > -1 && !t.ie55 && !t.ie523) ? 1 : 0; t.ns71 = (ua.indexOf("netscape/7.1") > -1) ? 1 : 0; t.safari3 = (ua.indexOf("safari") > -1 && ua.indexOf("version/3.") > -1 && ua.indexOf("version/3.") < ua.indexOf("safari")) ? 1 : 0; t.safari2 = (ua.indexOf("safari") > -1 && ua.indexOf("version/") == -1) ? 1 : 0; t.chrome = (ua.indexOf("chrome") > -1) ? 1 : 0; t.safari = (t.safari2 || t.safari3); t.ie = (t.ie8 || t.ie7 || t.ie55 || t.ie5 || t.ie6 || t.ie523 || t.ie4 || t.ie3); t.gecko = (ua.indexOf("gecko") > -1 & !t.ie) ? 1 : 0; t.ns = (t.ns71); t.ieOld = (t.ie55 || t.ie5 || t.ie523 || t.ie4 || t.ie3); t.ajaxaware = (t.opera || t.ie8 || t.ie7 || t.ie6 || t.safari || t.gecko || t.chrome) ? 1 : 0
} ();

/******************************************************************************/