//Browser detection to be used site wide
var detect = navigator.userAgent.toLowerCase();
var thestring,place;

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function Random(N) 
	{ return Math.floor( N*Math.random() );	} 

function everyNth(nth)
	{
	  if ( Random(nth+2) > nth )
	    { return true; }
	  else
	    { return false; }
	}

	function popdef()
	{
	  // this determines the probability of the pop-up being served - every tenth in this case
	  if( everyNth(100)  ) 
	  {
	    defwin=window.open("","Glossary","Toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=280,height=290","mainWindow");
	    defwin.document.open();		
	    defwin.document.write("<html><head><title>Survey Popup</title></head><body bgcolor='000000' LINK='red' VLINK='red'>");
		//defwin.document.write(word[0]);
	    defwin.document.write(word[1]);
	    defwin.document.write("</body></html>");
	    defwin.document.close();
	    clearID=defwin.setTimeout("self.close()",15000);
	  }
	}
// to here.................................

// Template.js

var onChangeArray = new Array();
function onChange() {
    for (var i = 0; i < onChangeArray.length; i++) {
        eval(onChangeArray[i]);
    }
}
function addOnChangeHandler(expr) {
    onChangeArray[onChangeArray.length] = expr;
}
var onLoadArray = new Array();
function onLoad() {
    for (var i = 0; i < onLoadArray.length; i++) {
        eval(onLoadArray[i]);

    // called for 5/25 survey 
    // put in "make sure HP handlers"
    popdef();
    }
}
function addOnLoadHandler(expr) {
    onLoadArray[onLoadArray.length] = expr;
}
function silentError() {
    return true;
}
function handleReSize() {
    window.location.reload();
}
function init(verbose) {
    var theAppVersion = parseInt(navigator.appVersion);
    if (theAppVersion < 5) {
         if (navigator.appName == "Netscape") {
                window.onresize = handleReSize;
         }
    }
    if (!verbose) {
        window.onerror = silentError;
    }
}

// Login.js

function launchWindow(url, name, height, width) {
  var str = "height=" + height + ",innerHeight=" + height;
  str += ",width=" + width + ",innerWidth=" + width;
  return window.open(url, name, str);
}

// MediaPopup.js

function rmWin(src,title,brandImage,brandImageLink) 
{
	selectTemplate('RM');
	path += "&src=" + src + "&title=" +title;
	attrs = 'toolbar=0,menubar=0,scrollbars=0,scrolling=no,resizable="no",width=300';
	brand(435,355,brandImage,brandImageLink);
	gallery=window.open(path,newWinName(),attrs);
	gallery.focus();
}

function aviWin(src,title,brandImage,brandImageLink) {
selectTemplate('AVI');
path += "&src=" + src + "&title=" +title;
attrs = 'toolbar=0,menubar=0,scrollbars=0,scrolling=no,resizable="no",width=310';
brand(427,347,brandImage,brandImageLink);
gallery=window.open(path,newWinName(),attrs);
gallery.focus();
}

function movWin(src,title,brandImage,brandImageLink) {
selectTemplate('MOV');
path += "&src=" + src + "&title=" +title;
attrs = 'toolbar=0,menubar=0,scrollbars=0,scrolling=no,resizable="no",width=310';
brand(427,347,brandImage,brandImageLink);
gallery=window.open(path,newWinName(),attrs);
gallery.focus();
}


function raWin(src,title,brandImage,brandImageLink) {
selectTemplate('RA');
path += "&src=" + src + "&title=" +title;
attrs = 'toolbar=0,menubar=0,scrollbars=0,scrolling=no,resizable="no",width=310';
brand(427,347,brandImage,brandImageLink);

gallery=window.open(path,newWinName(),attrs);
gallery.focus();
}

function wavWin(src,title,brandImage,brandImageLink) {
selectTemplate('WAV');
path += "&src=" + src + "&title=" +title;
attrs = 'toolbar=0,menubar=0,scrollbars=0,scrolling=no,resizable="no",width=310';
brand(427,347,brandImage,brandImageLink);
setType('WAV');
gallery=window.open(path,newWinName(),attrs);
gallery.focus();
}

function ipxWin(src,title,brandImage,brandImageLink) {
path = "/media/popup_ipx.jhtml?src=" + src + "&title=" +title;
attrs = 'toolbar=0,menubar=0,scrollbars=0,scrolling=no,resizable="no",width=400';
brand(520,420,brandImage,brandImageLink);
gallery=window.open(path,"graph",attrs);
gallery.focus();
}

function swfWin(src,title,brandImage,brandImageLink) {
path = "/media/popup_swf.jhtml?src=" + src + "&title=" +title;
attrs = 'toolbar=0,menubar=0,scrollbars=0,scrolling=no,resizable="no",width=310';
brand(427,347,brandImage,brandImageLink);
gallery=window.open(path,"graph",attrs);
gallery.focus();
}

function newWindow(url,title) {
  gallery=window.open(url, title, 'scrollbars=no,width=470,height=650,left=0,top=0')
}

function gif_jpg_Win(src,title,brandImage,brandImageLink) {
path = "/media/popup_gif_jpg.jhtml?src=" + src + "&title=" +title;
attrs = 'toolbar=0,menubar=0,scrollbars=0,scrolling=no,resizable="no",width=310';
brand(427,347,brandImage,brandImageLink);
gallery=window.open(path,"graph",attrs);
gallery.focus();
}

function slideshowWin(src,title,brandImage,brandImageLink) {
path = "/media/popup_ss.jhtml?src=" + src + "&title=" +title + "&slidenum=1";
attrs = 'toolbar=0,menubar=0,scrollbars=0,scrolling=no,resizable="no",width=480';
brand(680,600,brandImage,brandImageLink);
gallery=window.open(path,"graph",attrs);
gallery.focus();
}

// LegacyPopup.js

function basicwrapsmall(slideshow) {
    path = "/wrappers/theater/wrappers/" + slideshow + ".html"; 
    gallery=window.open(path,"graph",'toolbar=0,menubar=0,scrollbars=0,SCROLLING=NO,resizable=no,width=270,height=392')
} 

function basicwraplarge(slideshow) {
    path = "/wrappers/theater/wrappers/" + slideshow + ".html"; 
    gallery=window.open(path,"graph",'toolbar=0,menubar=0,scrollbars=0,SCROLLING=NO,resizable=no,width=330,height=420,left=5,top=30')
} 

function nbatvwrapsmall(slideshow) {
    path = "/wrappers/nbatv/wrappers/" + slideshow + ".html"; 
    gallery=window.open(path,"graph",'toolbar=0,menubar=0,scrollbars=0,SCROLLING=NO,resizable=no,width=215,height=300')
} 

function nbatvwraplarge(slideshow) {
    path = "/wrappers/nbatv/wrappers/" + slideshow + ".html"; 
    gallery=window.open(path,"graph",'toolbar=0,menubar=0,scrollbars=0,SCROLLING=NO,resizable=no,width=310,height=400,left=5,top=30')
}

function allstarwrapsmall(slideshow) {
    path = "/wrappers/allstar2000/theater/wrappers/" + slideshow + ".html"; 
    gallery=window.open(path,"graph",'toolbar=0,menubar=0,scrollbars=0,SCROLLING=NO,resizable=no,width=270,height=370')
} 

function allstarwraplarge(slideshow) {
    path = "/wrappers/allstar2000/theater/wrappers/" + slideshow + ".html"; 
    gallery=window.open(path,"graph",'toolbar=0,menubar=0,scrollbars=0,SCROLLING=NO,resizable=no,width=330,height=420,left=5,top=30')
}

function courtsidewrap(slideshow) {
    path = "/wrappers/theater/courtside/wrappers/" + slideshow + ".html"; 
    gallery=window.open(path,"graph",'toolbar=0,menubar=0,scrollbars=0,SCROLLING=NO,resizable=no,width=270,height=392')
} 

function usabsmall(slideshow) {
    path = "/wrappers/usab/theater/wrappers/" + slideshow + ".html"; 
    gallery=window.open(path,"graph",'toolbar=0,menubar=0,scrollbars=0,SCROLLING=NO,resizable="no",width=270,height=392')
} 

function usablarge(slideshow) {
    path = "/wrappers/usab/theater/wrappers/" + slideshow + ".html"; 
    gallery=window.open(path,"graph",'toolbar=0,menubar=0,scrollbars=0,SCROLLING=NO,resizable="no",width=330,height=420')
}

function open_window(url) {
    var path = url;
    if( url.search(/^http:/) == -1 ) {
        path = "/popups/" + url;
    } else {
        var nbaDomain = new RegExp("/^http:\/\/www.nba.com\/([.*]*)/");
        var result = url.match(nbaDomain);
        if( result != null ) {
            path = "/popups/" + result[1];
        } else {
            path = url;
        }
    }
    mywin=window.open(path,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=yes,width=600,height=600');
}

function open_window_ex(url, title, height, width) {
    var path = url;
    if( url.search(/^http:/) == -1 ) {
        path = "/popups/" + url;
    } else {
        var nbaDomain = new RegExp("/^http:\/\/www.nba.com\/([.*]*)/");
        var result = url.match(nbaDomain);
        if( result != null ) {
            path = "/popups/" + result[1];
        } else {
            path = url;
        }
    }
    var opts = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes';
    opts += ',width=' + width;
    opts += ',height=' + height;
    mywin=window.open(path,title,opts);
}

function open_win(url, title, height, width) {
    var path = url;
    var opts = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes';
    opts += ',width=' + width;
    opts += ',height=' + height;
    mywin=window.open(path,title,opts);
}
/*
	Functions & vars needed to launch popup video
	call compatible with old digitas stuff
	dependent on vidPopup.html, and vidPlay.js
	Sample Call:
	
	<a class="aLMediaLinkFeature" href="?nav=ArticleList#top" onclick="rmWin(escape('http://play.rbn.com/?url=nba/nba/g2demand/Nets/kidd_071101_240x180.rm&amp;proto=rtsp'),escape('ISDN+'),'/logos/wrappers/dotcomtv01.gif','');return false;">ISDN+</a>
*/
var jsPath = '/';
var gallery = null;

//Reason: Real player on ie will explode if re-opened in same window
function newWinName()
{
	return('vidWin' +(new Date).valueOf());
}
function brand(bSize,noBSize,brandImage,brandImageLink) {
   if (brandImage != '') {
       path += "&brandImage="+brandImage;
       if (brandImageLink != '') {
	   path += "&brandImageLink="+brandImageLink;
       }
       attrs += ",height="+bSize;
   } else {
       attrs += ",height="+noBSize;
   }
}

function selectTemplate(clipType)
{
	//create a string in the form of jsPath/vidPopup_browser_clipType.html
	path = jsPath + 'vidPopup_';
	if((clipType == 'RA') || (clipType=='RM'))
	{
		path+= 'rn.html'
	}else
	{
		path+= 'ms.html'
	}
	path+= '?clipType=' + clipType;
}
	
// Array and function necessary for ads to show up in netscape
	var ads = new Array();
	function ad(site, page, position, size){
		this.site = site;
		this.page = page;
		this.pos = position;
		this.sz = size;
		}
		
//Get Cookie Functions
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.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;
}

