// Managing multiple object event
function addEvent(obj, evType, fn, useCapture) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	} else {
		var originalEvent = obj["on" + evType];
		if (typeof obj["on" + evType] != "function") {
			obj["on" + evType] = fn;
		} else {
			obj["on" + evType] = function() {
				originalEvent();
				fn();
			}
		}
	}
}

// Image rollover and rollout functions
function imgOut(image) {
	ext = image.src.substr(image.src.lastIndexOf('.') + 1);
	image.src = image.src.replace(new RegExp('ov.' + ext + '$'), 'on.' + ext);
}

function imgOver(image) {
	ext = image.src.substr(image.src.lastIndexOf('.') + 1);
	image.src = image.src.replace(new RegExp('on.' + ext + '$'), 'ov.' + ext);
}

function imgReplace(imgElementId, imageUrl) {
	image = getObject(imgElementId);
	if (image != null)
		image.src = imageUrl;
}

// Generic image popup window
function imagePopUp(imageURL,imageTitle){
	var defaultWidth  = 400;
	var defaultHeight = 500;
	var autoClose = false;
	var imgWin = openPopUpCenter("about:blank", defaultWidth, defaultHeight, "scrollbars=no");
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(400,500);');
		writeln('width=400-(document.body.clientWidth-document.images[0].width);');
		writeln('height=500-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);');
		writeln('window.moveTo(screen.width/2-width/2, screen.height/2-height/2);}');
		writeln('if (isNN){');       
		writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;');
		writeln('window.moveTo(screen.width/2-window.innerWidth/2, screen.height/2-window.innerHeight/2);}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');
		writeln('</sc'+'ript>');
		if (!autoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
		close();
	}
}

function openPopUpCenter(pageUrl, width, height, feature) {
	feature += ",width=" + width + ",innerWidth=" + width;
	feature += ",height=" + height + ",innerHeight=" + height;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		feature += ",left=" + xc + ",screenX=" + xc;
		feature += ",top=" + yc + ",screenY=" + yc;
	}
	return window.open(pageUrl, "PopPage", feature);
}

function centerWindow() {
	var ns = (navigator.appName == "Netscape") ? true : false;
	iWidth = (ns) ? window.innerWidth : document.body.clientWidth;
	iHeight = (ns) ? window.innerHeight : document.body.clientHeight;
	window.moveTo(screen.width/2-iWidth/2, screen.height/2-iHeight/2);
	self.focus();
}

function getWindowSize() {
	var windowSize = new Object();
	windowSize.width = 0;
	windowSize.height = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		windowSize.width = window.innerWidth;
		windowSize.height = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		windowSize.width = document.documentElement.clientWidth;
		windowSize.height = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		windowSize.width = document.body.clientWidth;
		windowSize.height = document.body.clientHeight;
	}
	return windowSize;
}

function getObjectPosition(obj) {
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent) {
		while (1) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			if (!obj.offsetParent) {
				break;
			}
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
		curtop += obj.y;
	}
	return {x:curleft, y:curtop};
}

function getObjectDimension(obj) {
	return { width:obj.offsetWidth, height:obj.offsetHeight }
}

// Hint popup
function prepareHints() {
	var windowSize = getWindowSize();
	var hasHint = false;
	
	var triggerList = [
		{tagName:"input", displayEvent:"focus", hideEvent:"blur"},
		{tagName:"select", displayEvent:"focus", hideEvent:"blur"},
		{tagName:"textarea", displayEvent:"focus", hideEvent:"blur"},
		{tagName:"img", displayEvent:"mouseover", hideEvent:"mouseout"},
		{tagName:"a", displayEvent:"mouseover", hideEvent:"mouseout"}
	];
	
	for(var i = 0; i < triggerList.length; i++) {
		var trigger = triggerList[i];
		var triggerElements = document.getElementsByTagName(trigger.tagName);
		for (var j = 0; j < triggerElements.length; j++){
			var triggerObj = triggerElements[j];
			var hintElements = triggerObj.parentNode.getElementsByTagName("span");
			for (var k = 0; k < hintElements.length; k++) {
				if (hintElements[k].className == "hint") {
					var hintObj = hintElements[k];
					// Add pointer
					var pointer = document.createElement("span");
					pointer.className = "hint_pointer";
					pointer.innerHTML = " ";
					hintObj.appendChild(pointer);
					
					// Check the position of the hint, make sure it's not over the window size, otherwise set to show the hint on the top
					hintObj.style.display = "inline";
					var hintPosition = getObjectPosition(hintObj);
					var hintDimension = getObjectDimension(hintObj);
					hintObj.style.display = "none";
					if (hintPosition.x + hintDimension.width > windowSize.width) {
						hintObj.className = "hint_offset";
						hintObj.style.marginTop = -(hintDimension.height + 12) + "px";
						hintObj.style.marginLeft = -(hintDimension.width + -10) + "px";
						pointer.style.top = hintDimension.height - 2 + "px";
						pointer.style.left = hintDimension.width - 30 + "px";
					}
	
					// Add the event
					triggerObj.hintObj = hintObj;
					addEvent(triggerObj, trigger.displayEvent, function(eventObj) {
						var thisObj = eventObj["srcElement"] ? eventObj["srcElement"] : eventObj["target"];
						thisObj.hintObj.style.display = "inline";
						
						// Fix for hover overlapping in IE 6 using i-frame
						var iframe = getObject("hint_mask");
						iframe.style.display = "block";
						iframe.style.width = thisObj.hintObj.offsetWidth;
						iframe.style.height = thisObj.hintObj.offsetHeight;
						iframe.style.left = thisObj.hintObj.offsetLeft;
						iframe.style.top = thisObj.hintObj.offsetTop;

					}, false);
					addEvent(triggerObj, trigger.hideEvent, function(eventObj) {
						var thisObj = eventObj["srcElement"] ? eventObj["srcElement"] : eventObj["target"];
						thisObj.hintObj.style.display = "none";
						
						var iframe = getObject("hint_mask");
						iframe.style.display = "none";
						
					}, false);
					
					hasHint = true;
				}
			}
		}
	}
	
	if (hasHint) {
		// Fix for hover overlapping in IE 6 using i-frame
		var hintMask = document.createElement("iframe");
		hintMask.id = "hint_mask";
		hintMask.scrolling = "no";
		hintMask.frameborder = "0";
		hintMask.width = "0";
		hintMask.height = "0";
		document.body.appendChild(hintMask);
	}
}
addEvent(window, "load", prepareHints, false);

function getObject(elmID) {
	if (document.getElementById) { elmID = document.getElementById(elmID); }
	else if (document.all) { elmID = document.all[elmID]; }
	else if (document.layers) { elmID = this._getLayer(elmID); }
	else if (document.forms) {
		if(document.forms[elmID]) { elmID = document.forms[elmID]; }
		else {
			for(var i=0; i<document.forms.length; i++) {
				if(document.forms[i][elmID]) {
					elmID = document.forms[i][elmID];
					break;
				}
			}
		}
	} else { elmID = null; }
	return elmID;
}

function startWith(strCheck, pattern) {
	return strCheck.indexOf(pattern) === 0;
}

function endWith(strCheck, pattern) {
	var d = strCheck.length - pattern.length;
	return d >= 0 && strCheck.lastIndexOf(pattern) === d;
}

function pad(strText, l, s, t) {
	return s || (s = " "), (l -= strText.length) > 0 ? (s = new Array(Math.ceil(l / s.length) + 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2)) + strText + s.substr(0, l - t) : strText;
}

var urlAddress = "http://www.anzstadium.com.au/"; 
var pageName = "ANZ Stadium"; 
function addToFavorites() 
{ 
 if (document.all)
    {
      document.body.style.behavior='url(#default#homepage)';
			document.body.setHomePage(urlAddress);
    }
    else if (window.sidebar)
    {
			if(window.netscape)
			{
         try
				 {  
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
         }  
         catch(e)  
         {  
					alert("This action was aviod by your browser,if you want to enable,please enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true");  
         }
			} 
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',urlAddress);
		} 
}

function playVideo(videoName, filePath, videoSizeW, videoSizeH) {
	var videoPlayerPath = "/Media/Video/VideoPlayer.htm?VideoName=" + videoName + "&Path=" + filePath + "&Width=" + videoSizeW + "&Height=" + videoSizeH;
	openPopUpCenter(videoPlayerPath, videoSizeW, parseInt(videoSizeH) + 20, "scrollbars=no");
}