
var reRemoveWWW = /^www\./
var strHostname = location.hostname.replace(reRemoveWWW, "");
var never = new Date();
never.setTime(never.getTime() + (365*24*60*60*1000));

function getCookieVal (offset) {
	var cookieValue = document.cookie;
	var endstr = cookieValue.indexOf (";", offset);

	if (endstr == -1) {
		endstr = cookieValue.length;
	}
	
	if (cookieValue.length > 0 && cookieValue.charAt(offset) == '"' && cookieValue.charAt(endstr-1) == '"') {
		offset++;
		endstr--;
	}
		
	return unescape(cookieValue.substring(offset, endstr));
}

function GetCookie (name) {  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
		}  
	return null;
}

function SetCookie(name, value) {
  var argv = SetCookie.arguments;
  var expires = (typeof argv[2] != "undefined") ? argv[2] : null;
  var path = (typeof argv[3] != "undefined") ? argv[3] : null;
  var domain = (typeof argv[4] != "undefined") ? argv[4] : null;
  var secure = (typeof argv[5] != "undefined") ? argv[5] : false;
  document.cookie = name + "=" + value +
    ((expires == null) ? ""         : ("; expires=" + expires.toGMTString())) +
    ((path == null)    ? "; path=/" : ("; path=" + path)) +
    ((domain == null)  ? ""         : ("; domain=" + domain)) +
    ((secure == true)  ? "; secure" : "");
}
function DeleteCookie(name) {
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function GetChip(cookiename, name) {
  var cookie=GetCookie(cookiename)
    if (cookie != null){
    var arg=name+"=";
    var alen=arg.length;
    var i = cookie.indexOf(arg);
      if (i>=0) {
        var j = cookie.indexOf("&", i);
        if (j>=0) {
          return cookie.substring(i+alen,j)
        } else {
        return cookie.slice(i+alen);
      }
    } else return null
  } else return null
}
function SetChip(cookiename, name, value){
   var argv = SetChip.arguments;
   var argc = SetChip.arguments.length;
   var expires = (argc > 2) ? argv[3] : never;
   var cookie=GetCookie(cookiename);
   var arg=name+"=";
   if (cookie==null) cookie = "";
   var i = cookie.indexOf(arg);
   var trail ="";
   if (i>=0) {
     var j = cookie.indexOf("&", i);
     if (j>=0) trail=cookie.slice(j);
     SetCookie(cookiename, cookie.substring(0,i)+arg+value+trail, expires, '/', strHostname);
   } else {
     SetCookie(cookiename, cookie+'&'+arg+value, expires, '/', strHostname);
   }
}
function DeleteChip(cookiename, name){
  var cookie=GetCookie(cookiename);
  if (cookie != null) {
    var arg=name+"=";
    var i = cookie.indexOf(arg);
    var trail ="";
    if (i>=0) {
      var j = cookie.indexOf("&", i);
      if (j>=0) {
        trail=cookie.slice(j+1);
        SetCookie(cookiename, cookie.substring(0,i)+trail, never);
        return 1;
      } else {
        SetCookie(cookiename, cookie.substring(0,i-1), never);
          return 1;
        }
    } else return null
  } else return null
}

function arrayAddElement(theArray,theValue) {
  for (var i = 0;i < theArray.length;i++) {
    if (theArray[i][0] == theValue[0]) {
      alert("You have already added this item.\nUnable to add again.");
      return;
    }
  }
  theArray[theArray.length] = theValue;
}
function arrayDeleteElement(theArray,theValue) {
  var j = 0;
  var k = 0;
  for (var i = 0;i < theArray.length;i++) {
    if (theArray[i][0] != theValue) {
      theArray[j] = theArray[i];
      j++;
    } else {
      k++;
    }
  }
  theArray.length = theArray.length - k;
}
function arrayMoveElementUp(theArray,theValue) {
  for (var i = 0;i < theArray.length;i++) {
    if (theArray[i][0] == theValue) {
      if (i > 0) {
        var pos = i - 1;
        var juggle = theArray[pos];
        theArray[pos] = theArray[i];
        theArray[i] = juggle;
      }
    }
  }
}
function arrayMoveElementDown(theArray,theValue) {
  for (var i = 0;i < theArray.length;i++) {
    if (theArray[i][0] == theValue) {
      var pos = i + 1;
      if (pos < theArray.length) {
        var juggle = theArray[pos];
        theArray[pos] = theArray[i];
        theArray[i] = juggle;
        break;
      }
    }
  }
}

var DocDom, DocLay, DocAll
if (typeof document.getElementById != "undefined") {DocDom = true;} else {DocDom = false;}
if (typeof document.layers != "undefined") {DocLay = true;} else {DocLay = false;}
if (typeof document.all != "undefined") {DocAll = true;} else {DocAll = false;}
function getRef(id) {
    if (DocLay) {return document.layers['NS_' + id];}
    if (DocDom) {return document.getElementById(id);}
    if (DocAll) {return document.all[id];}
    return false;
}
function dynWrite(id, strToWrite) {
  if (DocLay) {
    var x = getRef(id).document;
    x.open('text/html');
    x.write(strToWrite);
    x.close();
    getRef(id).moveTo(document.anchors['pos_'+id].x,document.anchors['pos_'+id].y);
    return false;
  }
  if ((DocDom) || (DocAll)) {
    getRef(id).innerHTML=strToWrite;
    return false;
  }
  return false;
}

var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav6up = (is_nav && (is_major >= 5));
var is_opera = (agt.indexOf("opera") != -1);
function MM_preloadImages() { //v3.0
  var d=document; if (d.images) {
    if (!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for (i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0) {
        d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
      }
  }
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if (!d) d=document;if ((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if (!(x=d[n])&&d.all) x=d.all[n];for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for (i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if (!x && d.getElementById) x=d.getElementById(n);return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; for (i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null) {
    x.src=a[i+2];
  }
}
function imgCache() {
  
  if (is_nav6up || is_opera) {
    MM_preloadImages(arguments);
  } else if (document.images)  {
    var args = arguments, d = document;
    d.imgarray = new Array();
    var imgcount = d.imgarray.length;
    for (i = 0; i < args.length; i++) {
      d.imgarray[imgcount] = new Image;
      d.imgarray[imgcount++].src = args[i];
    }
  }
}
function imgSwap() {
  var args = arguments;
  if (typeof args[0] == "string") {
    if (is_nav6up || is_opera) {
      MM_swapImage(args[0],'',args[1],1);
    } else if (document.images)  {
      var imgstr = "document."+args[0];
      var obj = eval (imgstr);
      if (obj) {
        obj.src = args[1];
        args[0].src = args[1];
      }  
    }
  }
}

var qs = new Array();
var querystring = unescape(document.location.search);

if (querystring != "") {
  var varArray = querystring.substring(querystring.lastIndexOf("?")+1 ,querystring.length).split("&");
} else {
  var varArray = Array();
}

for (var ii = 0; ii < varArray.length; ii++) {
  
  if (varArray[ii] != "") {
    
    var varValueArray = varArray[ii].split("=");
    
    if (varValueArray.length == 1) {
      varValueArray[1] = '';
    }
    
    if (typeof qs[varValueArray[0]] != "undefined" && varValueArray[0] != "") {
      
      if (typeof qs[varValueArray[0]] == "object") {
        
        qs[varValueArray[0]].push(varValueArray[1]);
      } else {
        
        var valueArray = new Array(qs[varValueArray[0]],varValueArray[1]);
        qs[varValueArray[0]] = valueArray;
      }
    } else {
      
      qs[varValueArray[0]] = varValueArray[1];
    }
  }
}

function nullFunc() {return false;}


function changeOnClick(item,functionType,functionName) {
  
  item = 'javascript:nullFunc(\''+ functionType + '\',' + item + ');';
  
  for (var i = 0; i < document.links.length; i++) {
    
    if (document.links[i].href == item) {
      
      eval('document.links[' + i + '].onclick = ' + functionName + ';');
    }
  }
}

function getNumber(thisArgs) {
  thisArgs = thisArgs.substring(thisArgs.indexOf('(') + 1,thisArgs.indexOf(')'));
  return thisArgs.substring(thisArgs.indexOf(',') + 1);
}

function moveUp(e) {
  var thisNumber = getNumber(this.href);
  eval('arrayMoveElementUp(' + inView + ',' + View[thisNumber][0] + ');updateView();');
  return false;
}


function moveDown(e) {
  var thisNumber = getNumber(this.href);
  eval('arrayMoveElementDown(' + inView + ',' + View[thisNumber][0] + ');updateView();');
  return false;
}

function clipDelete(e) {
  var thisNumber = getNumber(this.href);
  eval('arrayDeleteElement(' + inView + ',' + View[thisNumber][0] + ');if(offSet > 0){offSet--;}updateView();');
  return false;
}

function clipAddFave(e) {
  var thisNumber = getNumber(this.href);
  arrayAddElement(Fave,View[thisNumber]);
  return false;
}

function reelPlay(e) {
  eval('playReel(' + inView + ');');
  return false;
}
function reelPlayRedirection(e) {
  eval('playReelRedirection(' + inView + ');');
  return false;
}


function reelDelete(e) {
  eval('clearReel(' + inView + ');');
  return false;
}

function reelScrollDown(e) {
  offSet++;
  updateView();
  return false;
}

function reelScrollUp(e) {
  offSet--;
  updateView();
  return false;
}

function addToReel(clipData) {
  if (inView == "Fave") {
    arrayAddElement(Fave,clipData);
    updateView();
  } else if (inView == "Reel") {
    arrayAddElement(Reel,clipData);
    updateView();
  }
}








var Reel = new Array();
var Fave = new Array();
var View = new Array();

var inView = 'Reel';
var viewSize = 4;
var offSet = 0;


var i;



var stringReel = GetCookie('ptvReel');
var stringFave = GetCookie('ptvFave');


if (stringReel != null) {
  var stringReelArray;
  eval('stringReelArray = [' + stringReel + '];');
  for (var i=0;i<stringReelArray.length-1;) {
    Reel[Reel.length] = new Array(stringReelArray[i],unescape(stringReelArray[i+1]),stringReelArray[i+2],unescape(stringReelArray[i+3]),unescape(stringReelArray[i+4]),unescape(stringReelArray[i+5]));
    i = i + 6;
  }
}

if (stringFave != null) {
  var stringFaveArray;
  eval('stringFaveArray = [' + stringFave + '];');
  for (var i=0;i<stringFaveArray.length-1;) {
    Fave[Fave.length] = new Array(stringFaveArray[i],unescape(stringFaveArray[i+1]),stringFaveArray[i+2],unescape(stringFaveArray[i+3]),unescape(stringFaveArray[i+4]),unescape(stringFaveArray[i+5]));
  i = i + 6;
  }   
}


function clearReel(theArray) {
  theArray.length = 0;
  setTimeout("updateView()",1);
}


function playReel(theArray) {
  //Creates the url to make the XMLHttpRequest to get the asx file to
  //play the clips and all the extra information about them to be
  //displayed next to the media player.
  var url = 'loadXMLDoc("' + XMLHttPRequestServletUrl + 'play.xml?type=8&clipList=';
  //The value of the parameter "clipList" will be the list of clip identifiers
  //in the array, separated by commas.
  for (var i=0;i<theArray.length-1;i++) {
    url = url + theArray[i][0] + ","; 
  }
  url = url + theArray[theArray.length-1][0] + '")';
  //Make the XMLHttpRequest.
  eval(url);
  //Send the user to the top of the document where the media player is.
  document.location.href = '#top';
  
  return true;
}

function playReelRedirection(theArray) {
  
  var clipList = "";
  var detailId = 0;
  for (var i=0;i<theArray.length-1;i++) {
    clipList = clipList + theArray[i][0] + ",";
    detailId = detailId + ((i+1) *  theArray[i][0]);
  }  
  clipList = clipList + theArray[theArray.length-1][0];
  detailId = detailId + ((theArray.length) * theArray[theArray.length-1][0]);
  
  var url = mediaPlayerPageUrl + 
           '~' + detailId +             
           ',00.html' + 
           '?seasonId=' + selectedSeason +
           '&teamId=' + selectedTeam +
           '&playerId=' + selectedPlayer +
           '&opponentId=' + selectedOpponent +
           '&competitionId=' + selectedCompetition +
           '&incidentId=' + selectedIncident +
           '&clipsXpage=' + clipsXpage +
           '&page=' + page + 
           '&clipList=' + clipList;
  document.location.href = url;
  
  return true;
}


function launchHelp() {
  window.open('reelHelp.asp','reelHelp','height=350,width=450,scrollbars=yes');
  return false;
}

function viewReel() {
  inView = 'Reel';
  offSet = 0;
  setTimeout("imgSwap('tabCurrentReel',reelImages['viewCurrentReelOn'].src)",1);
  setTimeout("imgSwap('tabFavouritesReel',reelImages['viewFavouritesReelOff'].src)",1);
  setTimeout("updateView()",1);
  return false;
}

function viewFave() {
  inView = 'Fave';
  offSet = 0;
  setTimeout("imgSwap('tabFavouritesReel',reelImages['viewFavouritesReelOn'].src)",1);
  setTimeout("imgSwap('tabCurrentReel',reelImages['viewCurrentReelOff'].src)",1);
  setTimeout("updateView()",1);
  return false;
}

function viewInView() {
  if (typeof qs['inView'] != "undefined") {
    inView = qs['inView'];
    if (qs['inView'] != 'Reel' && qs['inView'] != 'Fave') {
      qs['inView'] = 'Reel';
    }
    eval ('view' + qs['inView'] + '()');
    return false;
  } else {
    viewReel();
    return false;
  }
}

function updateView() {
  
  if (Reel.length != 0) {
    var cookieValue = '';
    for (var i=0; i<Reel.length-1; i++) {
      cookieValue = cookieValue + Reel[i][0] + ',"' + escape(Reel[i][1]) + '",' + Reel[i][2] + ',"' + escape(Reel[i][3]) + '","' + escape(Reel[i][4]) + '",' + Reel[i][5] + ',';
    }
    cookieValue = cookieValue + Reel[Reel.length-1][0] + ',"' + escape(Reel[Reel.length-1][1]) + '",' + Reel[Reel.length-1][2] + ',"' + escape(Reel[Reel.length-1][3]) + '","' + escape(Reel[Reel.length-1][4]) + '",' + Reel[Reel.length-1][5] ;
    SetCookie('ptvReel',cookieValue);
  } else {
    SetCookie('ptvReel',"");
  }
  
  if (Fave.length != 0) {
    var cookieValue = '';
    for (var i=0; i<Fave.length-1; i++) {
      cookieValue = cookieValue + Fave[i][0] + ',"' + escape(Fave[i][1]) + '",' + Fave[i][2] + ',"' + escape(Fave[i][3]) + '","' + escape(Fave[i][4]) + '",' + Fave[i][5] + ',';
    } 
    cookieValue = cookieValue + Fave[Fave.length-1][0] + ',"' + escape(Fave[Fave.length-1][1]) + '",' + Fave[Fave.length-1][2] + ',"' + escape(Fave[Fave.length-1][3]) + '","' + escape(Fave[Fave.length-1][4]) + '",' + Fave[Fave.length-1][5] ;
    SetCookie('ptvFave',cookieValue,never);
  } else {
    SetCookie('ptvFave',"",never);
  }
 
  
  View.length = 0;
  
  eval('var j = 0;for (i = offSet;i<' + inView + '.length;i++) {if (j < viewSize) {View[j] = ' + inView + '[i];j++}}');
  
  for (i = 0;i < View.length;i++) {
    //
    // Put the new keyframe in place
    //
    eval("imgSwap('clipKeyFrame" + i + "','" + View[i][1] + "');");
    
    if (typeof document.images != "undefined") {
      eval('document.images.clipKeyFrame' + i + '.alt = "Clip ID : ' + View[i][0] + '";');
    }
    //
    // If we are on the current reel, allow add to favourites
    //
    if (inView == 'Reel') {
      eval("imgSwap('clipAddFave" + i + "',reelImages['addClipToFavourites'].src);");
      changeOnClick(i,'clipAddFave','clipAddFave');
      
      if (typeof document.images != "undefined") {
        eval('document.images.clipAddFave' + i + '.alt = "Add Clip To Favourites";');
      }
    } else {
      eval("imgSwap('clipAddFave" + i + "',reelImages['blankButton'].src);");
      changeOnClick(i,'clipAddFave','nullFunc');
      if (typeof document.images != "undefined") {
        eval('document.images.clipAddFave' + i + '.alt = "";');
      }
    }
    
    if (View.length == 1) {
      eval("imgSwap('clipMoveUp" + i + "',reelImages['blankButton'].src);");
      changeOnClick(i,'moveUp','nullFunc');
      eval("imgSwap('clipMoveDown" + i + "',reelImages['blankButton'].src);");
      changeOnClick(i,'moveDown','nullFunc');
      if (typeof document.images != "undefined") {
        eval("imgSwap('clipMoveUp" + i + "',reelImages['blankMoveUpButton'].src);");
        eval('document.images.clipMoveUp' + i + '.alt = "";');
        eval("imgSwap('clipMoveDown" + i + "',reelImages['blankMoveDownButton'].src);");
        eval('document.images.clipMoveDown' + i + '.alt = "";');
        
      }
    } else {
      
      
      eval("imgSwap('clipMoveUp" + i + "',reelImages['moveClipUp'].src);");
      changeOnClick(i,'moveUp','moveUp');
      eval("imgSwap('clipMoveDown" + i + "',reelImages['moveClipDown'].src);");
      changeOnClick(i,'moveDown','moveDown');
      if (typeof document.images != "undefined") {
        eval('document.images.clipMoveUp' + i + '.alt = "Move Clip Up";');
        eval('document.images.clipMoveDown' + i + '.alt = "Move Clip Down";');
      }
    }
    eval("imgSwap('clipDelete" + i + "',reelImages['deleteClip'].src);");
    changeOnClick(i,'clipDelete','clipDelete');
    if (typeof document.images != "undefined") {
      eval('document.images.clipDelete' + i + '.alt = "Delete This Clip";');
    }
  }
  
  for (i = View.length;i < viewSize;i++) {
    eval("imgSwap('clipKeyFrame" + i + "',reelImages['clipFrameBlank'].src);");
    eval("imgSwap('clipAddFave" + i + "',reelImages['blankButton'].src);");
    changeOnClick(i,'clipAddFave','nullFunc');
    eval("imgSwap('clipMoveUp" + i + "',reelImages['blankButton'].src);");
    changeOnClick(i,'moveUp','nullFunc');
   eval("imgSwap('clipMoveDown" + i + "',reelImages['blankButton'].src);");
    changeOnClick(i,'moveDown','nullFunc');
    eval("imgSwap('clipDelete" + i + "',reelImages['blankButton'].src);");
    changeOnClick(i,'clipDelete','nullFunc');
    if (typeof document.images != "undefined") {
      eval('document.images.clipKeyFrame' + i + '.alt = "";');
      eval('document.images.clipAddFave' + i + '.alt = "";');
      eval('document.images.clipMoveUp' + i + '.alt = "";');
      eval('document.images.clipMoveDown' + i + '.alt = "";');
      eval('document.images.clipDelete' + i + '.alt = "";');
    }
  }
  
  if (offSet > 0 && View.length != 0) {
    imgSwap('reelScrollUp',reelImages['scrollReelUp'].src);
    changeOnClick(1,'reelScrollUp','reelScrollUp');
  } else {
    imgSwap('reelScrollUp',reelImages['scrollReelUp'].src);
    changeOnClick(1,'reelScrollUp','nullFunc');
  }
  
  if (eval('offSet < ' + inView + '.length - viewSize')) {
    imgSwap('reelScrollDown',reelImages['scrollReelDown'].src);
    changeOnClick(1,'reelScrollDown','reelScrollDown');
  } else {
    imgSwap('reelScrollDown',reelImages['scrollReelDown'].src);
    changeOnClick(1,'reelScrollDown','nullFunc');
  }
  
  if (View.length != 0) {
    imgSwap('reelPlay',reelImages['playReel'].src);
    if (window.mediaPlayer && window.mediaPlayer != null && window.mediaPlayer != undefined) {
      changeOnClick(1,'reelPlay','reelPlay');
    } else {  
      changeOnClick(1,'reelPlay','reelPlayRedirection');
    }  
    changeOnClick(2,'reelPlay','reelPlayRedirection');

    imgSwap('reelDelete',reelImages['cleerReel'].src);
    changeOnClick(1,'reelDelete','reelDelete');
  } else {
    imgSwap('reelPlay',reelImages['playReel'].src);
    changeOnClick(1,'reelPlay','nullFunc');
    changeOnClick(2,'reelPlay','nullFunc');
    imgSwap('reelDelete',reelImages['cleerReel'].src);
    changeOnClick(1,'reelDelete','nullFunc');
  }
  
  var showCount = eval(inView + '.length');
  if (showCount == 1) {
    showCount = "1 clip";
  } else {
    showCount = showCount + " clips";
  }
  showCount = '<table width="100%" cellspacing="20" cellpadding="20" border="0"><tr><td><font face="Verdana, Arial, Helvetica" color="#FFFFFF" size="1"><span class="countReel">You have ' + showCount + ' in your reel.</span><font></td></tr></table>';
  dynWrite('divViewCount',showCount);
  
  return false;
}

<!-- PTV Cache: persloche06/tomcatvip Sat, 22 May 2010 06:29:37 GMT / 86400 (0) -->