//***********************************************
// D I S C L A I M E R  J S
//
// USAGE
//
// To be included as an external JS file on a page
// e.g. <script type="text/javascript" src="http://disney.go.com/features/javascript/disclaimer.js"></script>
// The script will start automatically on page load.
//
// The disclaimer can be called from Flash using:
//	on(rollOver){
//		gURL = "http://www.disney.com";
//		getURL("javascript:flashDisclaimer('"+gURL+"');");
//	}
//
// DESCRIPTION
//
// Dynamically adds rollover disclaimer to any
// links referencing a server outside the go domain
//
// FUNCTIONS
//
// addLoadEvent(), disclaimOutsideLinks(), createDisclaimerDiv(), showDHTMLDisclaimer(evt),
// flashDisclaimer(gURL), hideDisclaimer()
//
// Originally written by Mitchell Cichocki 	10/31/2005 	(mitchell.cichocki@dig.com)
// Modified - 11/22/2005
// Modified - 12/02/2005
// Modified - 12/19/2005
// Modified - 04/25/2006
//***********************************************
// G L O B A L  S E T T I N G S
//***********************************************
// disclaimer image location
var disclaimerImage = "http://disney.go.com/features/global/images/pop.gif";
// disclaimer image dimensions
var disclaimerImageWidth = "218";
var disclaimerImageHeight = "130";
// z-index of disclaimer, override on page if necessary
var disclaimerzIndex = "30";
// open in new window defaults to true, override with false to open in parent
var openInNewWin = true;
// init vars to default value
var flashDisclaim = false;
var clickThru = null;
// init ua to current browser
var ua = navigator.userAgent.toLowerCase();
// init mouse offset
var mouseOffset = 10;
var detectAnch = false;

//***********************************************
// A D D  L O A D  E V E N T
//
// Adds a new event to the page onLoad while
// retaining any existing onLoad events
//***********************************************
function addLoadEvent(func) {
	// save existing onload events
  var oldonload = window.onload;
  // check for existing onload events
  if (typeof window.onload != 'function') {
		// set func to onload
    window.onload = func;
  } else {
		// append func to existing events
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
//***********************************************
// D I S C L A I M  O U T S I D E  L I N K S
//
// Adds the disclaimer to any outside links
//***********************************************
function detectAnchors(){
	detectAnch = true;
	disclaimOutsideLinks();
}
function disclaimOutsideLinks(){
	if(detectAnch == true){
		// collect all anchor tags
		var anchorTags = document.getElementsByTagName("a");
		// loop through anchor tag array
		for(x = 0; x < anchorTags.length; x++){
			// filter only tags containing '.com'
			if(anchorTags[x].href.indexOf(".com") != -1){
				// create search expression 
				domainRE = new RegExp("....com","g");
				// apply expression to anchor tag array
				results = anchorTags[x].href.match(domainRE);
				// loop through anchor tag array and check for non 'go' domains
				for(var j =0; j < results.length; j++){
					// if outside domain is found, add the disclaimer
					if(results[j] != ".go.com"){
						anchorTags[x].onmouseover = showDHTMLDisclaimer;
					}
				}
			}
			if(anchorTags[x].href.indexOf(".org") != -1){
				anchorTags[x].onmouseover = showDHTMLDisclaimer;
			}
		}
	}
	//if(ua.indexOf('mac') != -1 && ua.indexOf('msie') != -1){
		// collect all embed tags
		var embedTags = document.getElementsByTagName("embed");
		// loop through object tag array and add onmousemove
		for(x=0; x< embedTags.length; x++){
			embedTags[x].onmousemove = showDHTMLDisclaimerFlash;
		}
	//} else {
		// collect all object tags
		var objectTags = document.getElementsByTagName("object");
		// loop through object tag array and add onmousemove
		for(x=0; x< objectTags.length; x++){
			objectTags[x].onmousemove = showDHTMLDisclaimerFlash;
		}
	//}
}
//***********************************************
// C R E A T E  D I S C L A I M E R  D I V
//
// creates a new div tag and writes the disclaimer
// graphic into it
//***********************************************
function createDisclaimerDiv(){
	// find body
	var bodyElem = document.getElementsByTagName("body");
	// create empty div
	var dID = document.createElement('div');
	// set id and styles
	dID.setAttribute('id','disclaimerDiv');
	dID.style.position = "absolute";
	dID.style.left = "0px";
	dID.style.top = "0px";
	dID.style.width = disclaimerImageWidth+"px";
	dID.style.height = disclaimerImageHeight+"px";
	dID.style.zIndex = disclaimerzIndex;
	dID.style.visibility = "hidden"
	// write image and anchor tags to disclaimerDiv
	dID.innerHTML = '<a id="dAnchor" href="" target="_blank"><img id="discImage" src="'+disclaimerImage+'" width="'+disclaimerImageWidth+'" height="'+disclaimerImageHeight+'" border=0></a>';
	// append disclaimerDiv to page body
	bodyElem[0].appendChild(dID);
	// return reference to disclaimerDiv
	return dID;
}
//***********************************************
// H T M L  S H O W  D I S C L A I M E R
//
// displays disclaimer centered on mouse pointer
//***********************************************
function showDHTMLDisclaimer(evt){
	// filter event for IE and DOM compatibility
	evt = (evt) ? evt : ((event) ? event : null);
	// check for disclaimerDiv
	var dID = document.getElementById("disclaimerDiv");
	// if disclaimerDiv does not exist, build it
	if(!dID){
		dID = createDisclaimerDiv();
	}
	// position disclaimerDiv - mac ie doesn't like documentElement
	if(ua.indexOf('msie') != -1 && ua.indexOf('mac') != -1){
		dID.style.left = evt.clientX+document.body.scrollLeft-(String(dID.style.width).slice(0,-2)/mouseOffset)+"px";
		dID.style.top = evt.clientY+document.body.scrollTop-(String(dID.style.height).slice(0,-2)/mouseOffset)+"px";
	} else {
		dID.style.left = evt.clientX+document.documentElement.scrollLeft-(String(dID.style.width).slice(0,-2)/mouseOffset)+"px";
		dID.style.top = evt.clientY+document.documentElement.scrollTop-(String(dID.style.height).slice(0,-2)/mouseOffset)+"px";
	}
	// find the anchor tag
	var dAnchor = document.getElementById("dAnchor");
	// set disclaimer click thru to original element's
	if(this.href){
		dAnchor.href = this.href;
	} else {
		dAnchor.href = clickThru;
	}
	if(openInNewWin == true){
		dAnchor.target = "_blank";
	} else {
		dAnchor.target = "_parent";
	}
	// hide after click
	dAnchor.onclick = hideDisclaimer;
	// hide on roll out
	dAnchor.onmouseout = hideDisclaimer;
	// make disclaimerDiv visible
	dID.style.visibility = "visible";
}
//***********************************************
// F L A S H  S H O W  D I S C L A I M E R
//
// displays disclaimer when called from flash
//
//***********************************************
function showDHTMLDisclaimerFlash(evt){
	if(typeof flashDisclaim != "undefined"){
		if(flashDisclaim == true){
			showDHTMLDisclaimer(evt)
		}
	}
}
function flashDisclaimer(gURL){
		flashDisclaim = true;
		clickThru = gURL;
}
	
//***********************************************
// H I D E  D I S C L A I M E R
//
// hides the disclaimer
//***********************************************
function hideDisclaimer(){
	// find the body element
	var bodyElem = document.getElementsByTagName("body");
	// find the disclaimerDiv
	var dID = document.getElementById("disclaimerDiv");
	if(dID){
		// hide the disclaimer 
		dID.style.visibility = "hidden";
		dID.style.left = "0px";
		dID.style.top = "0px";
	}
	flashDisclaim = false;
}
// S T A R T  S C R I P T
addLoadEvent(disclaimOutsideLinks);