function Is3() {
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && 
    ((agent.indexOf('spoofer')==-1) && 
    (agent.indexOf('compatible') == -1)));
    this.ns4 = (this.ns && (this.major < 5));
}

var is = new Is3();

if (is.ns4) {
    window.location = "http://www.canucks.com/upgrade/index.asp";
}


// Form validation for global Search function
function searchCheck(search){
 if((search.elements['searchbox'].value=='') || (search.elements['searchbox'].value=='Search')){
  alert('Please enter a search query');
  search.elements['searchbox'].focus();
 } else {
 search.submit();
 }
}

// resize fix for ns4
var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}


// quick browser tests
var ns4 = (document.layers) ? true : false;
var ie4 = (document.all && !document.getElementById) ? true : false;
var ie5 = (document.all && document.getElementById) ? true : false;
var ns6 = (!document.all && document.getElementById) ? true : false;

function show(sw,obj) {
	// show/hide the divisions
	if (sw && (ie4 || ie5) ) document.all[obj].style.visibility = 'visible';
	if (!sw && (ie4 || ie5) ) document.all[obj].style.visibility = 'hidden';
	if (sw && ns4) document.layers[obj].visibility = 'visible';
	if (!sw && ns4) document.layers[obj].visibility = 'hidden';
	if (sw && ns6) document.getElementById(obj).style.visibility = 'visible';
	if (!sw && ns6) document.getElementById(obj).style.visibility = 'hidden';
}

function openGameDetail(game_id) {
	var t = 0;
	var l = 0;
	var w = 0;
	var	h = 0;
	var sizex = 539;
	var sizey = 268;

	if (screen) {
		w = screen.width;
		h = screen.height;
		l = (w - sizex) / 2;
		t = (h - sizey) / 2;
	}

	gameWin = gameWin = window.open('/schedule/game_popup.asp?GameID=' + game_id, 'gameWindow', 'top='+t+',left='+l+',height='+sizey+',width='+sizex);
	gameWin.focus();
}

//various popups
function popUpWin (windowURL,windowName,windowWidth,windowHeight) {
	var windowTop = 0;
	var windowLeft = 0;
	var w,h;
	
	if (screen) {
		w = screen.width;
		h = screen.height;
		if (w > 1024) w = 1024;
		if (h > 768) h = 768;
		windowLeft = (w - windowWidth) / 2;
		windowTop = (h - windowHeight) / 2;
	}
	
	newWindow = window.open(windowURL,windowName, 'status,top='+windowTop+',left='+windowLeft+',height='+windowHeight+',width='+windowWidth +',statusbar=no,scrollbars=no');
	newWindow.focus();
}

//various popups
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function popUpWinCustom (windowURL,windowName,windowWidth,windowHeight,windowLeft,windowTop) {
		
	newWindow = window.open(windowURL,windowName, 'status,top='+windowTop+',left='+windowLeft+',height='+windowHeight+',width='+windowWidth +',statusbar=no,scrollbars=no');
	newWindow.focus();
}


function popupLink (myLocation) {
	if (window.opener.closed) window.open(myLocation,'happyWindow');
	else window.opener.document.location = myLocation;
	self.close();
}

function popupExtLink (myLocation) {
	window.open(myLocation,'happyWindow');
	self.close();
}

function openPlayer(theURL) {

	var W = 703;
	var H = 535;
	var windowX = Math.ceil( (window.screen.width  - W) / 2 );
	var windowY = Math.ceil( (window.screen.height - H) / 2 );

	s = ",width="+W+",height="+H;

	if (document.all) {
	   var playerWin = window.open(theURL, "playerWin", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0"+s, true);
	} else {
		var playerWin = window.open("/player/noie.html","Sorry...","width=300,height=200,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0",true);
	}
//	}
	playerWin.focus();
}

function openTicketForm(theURL) {

	var W = 385;
	var H = 370;
	var windowX = Math.ceil( (window.screen.width  - W) / 2 );
	var windowY = Math.ceil( (window.screen.height - H) / 2 );

	s = ",width="+W+",height="+H;

	if (document.all) {
	   var playerWin = window.open(theURL, "playerWin", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0"+s, true);
	} else {
		var playerWin = window.open(theURL, "playerWin", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0"+s, true);
	}
//	}
	playerWin.focus();
}
function openPPVContest(theURL) {

	var W = 385;
	var H = 560;
	var windowX = Math.ceil( (window.screen.width  - W) / 2 );
	var windowY = Math.ceil( (window.screen.height - H) / 2 );

	s = ",width="+W+",height="+H;

	if (document.all) {
	   var playerWin = window.open(theURL, "playerWin", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0"+s, true);
	} else {
		var playerWin = window.open(theURL, "playerWin", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0"+s, true);
	}
//	}
	playerWin.focus();
}

// feedback function
function ResponsetekPopUp (url, name, width, height) {
	settings = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+width+",height="+height;
	MyNewWindow=window.open(""+url,name,settings);
}

// BobbleHead Popup

function Is() {
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.ns2 = (this.ns && (this.major == 3));
    this.ns3 = (this.ns && (this.major == 3));
    this.ns4 = (this.ns && (this.major >= 4));
    this.ns406 = (this.ns && (this.minor == 4.06));
    this.ns407 = (this.ns && (this.minor == 4.07));
    this.ns408 = (this.ns && (this.minor == 4.08));
    this.ns45 = (this.ns && (this.minor == 4.5));
    this.ie   = (agent.indexOf("msie") != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major >= 4));
    this.op3 = (agent.indexOf("opera") != -1);
}

var is = new Is();
var bigWindow = null;

function newWindow(url, name, width, height)
{
      if(is.ns4 || is.ie4) {
        var buffer = (is.ns406 || is.ns407 || is.ns408) ? 30 : 48;
        if(screen.height <= 768) {
            var window_width = screen.width-12;
            var window_height = screen.height-buffer;
        } else {
            var window_width = 1024-12;
            var window_height = 768-buffer;
		}
        var window_top = 50;
        var window_left = window_width / 2 - 400;
    }
  
  var openStr = "WIDTH=" + width + ",HEIGHT=" + height + ",toolbar=no,scrollbars=no,noresize,resizable=no,resize=no,status=no,top=" + window_top + ",left=" + window_left + "";
  var version = parseInt(navigator.appVersion.substring(0,1));
  var navType = navigator.appName;

  newWin = window.open(url, name, openStr);

  if ( navType == "Netscape" && version >= 3 ) 
  {  newWin.focus(); }
  else if ( navType == "Microsoft Internet Explorer" && version >= 3 )
  {  setTimeout('newWin.focus();', 250); }
}

function getexpirydate( nodays){
 var UTCstring;
 Today = new Date();
 nomilli=Date.parse(Today);
 Today.setTime(nomilli+nodays*24*60*60*1000);
 UTCstring = Today.toUTCString();
 return UTCstring;
}

function setCookie(value) {  
 document.cookie = "canucksTicker=" + value + ";EXPIRES=" + getexpirydate(10) + ";path=/";
}

function getCookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function resetTickerState() {
 if (getCookie("canucksTicker") == 'show') turnTickerOn();
}

function turnTickerOn() {
 show(true,'tickerOn'); 
 show(true,'tickerClose'); 
 show(true,'tickerLeft'); 
 show(false,'tickerOff'); 
 show(false,'tickerOpen'); 
 show(false,'tickerLeftOff'); 
 populate();
 setCookie('show');
}

function turnTickerOff() {
 show(true,'tickerOff'); 
 show(true,'tickerOpen'); 
 show(true,'tickerLeftOff');  
 show(false,'tickerOn'); 
 show(false,'tickerClose'); 
 show(false,'tickerLeft'); 
 clearInterval(lefttime);
 setCookie('hide');
}



 function mOvr(src,clrOver)
	{
		if (!src.contains(event.fromElement))
		{
			src.style.cursor = 'hand';
			src.bgColor = clrOver;
		}
	}
	function mOut(src,clrIn)
	{
		if (!src.contains(event.toElement))
		{
			src.style.cursor = 'default';
			src.bgColor = clrIn;
		}
	}
	function mClk(src)
	{
		if(event.srcElement.tagName=='TD')
		{
			src.children.tags('A')[0].click();
		}
	}
	
	var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

/* center current pop up window */
function centerMe() {

	if (parseInt(navigator.appVersion)>3) {
		
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}

		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
	 	}
	}

	w = screen.width;
	h = screen.height;
	moveTo = ( (w - winW) / 2, (h - winH) / 2 );
}

BrowserDetect.init();
	
