var newWindow = null;
var extUrl = "";
var extType = "";
var extScrWidth = "";
var extScrHeight = "";
var winXPos = 160;
var winYPos = 90;
var custom_text = "";

function writeImage(){
  /* cview removal fix */
}

function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}

function setWindowSize() {
	if (parseInt(navigator.appVersion) > 3){
		if ((navigator.appName=="Microsoft Internet Explorer")&&document.body) {
			winXPos = (document.body.offsetWidth / 2) - 185;
			winYPos = (document.body.offsetHeight / 2) - 160;
		}
		else if (navigator.appName=="Netscape") {
			winXPos = (window.innerWidth / 2) - 185;
			winYPos = (window.innerHeight / 2) - 160;
		}
	}
}

function findPopUps() {
	var popups = document.getElementsByTagName("a");
	for (i=0;i<popups.length;i++) {
		if (popups[i].rel.indexOf("popup")!=-1) {
			// Attach popup behaviour
			popups[i].onclick = doPopUp;
		}
	}
}

function doPopUp(e) {
	// Set defaults - if nothing in rel attrib, these will be used
	var t = "standard";
	var w = "800";
	var h = "600";
	var x = "";

	// Look for parameters
	attribs = this.rel.split(" ");
	if (attribs.length > 3) {
		if (attribs[1]!=null) {t = attribs[1];}
		if (attribs[2]!=null) {w = attribs[2];}
		if (attribs[3]!=null) {h = attribs[3];}
		if (attribs[4]!=null) {x = attribs[4];}
	} else if (this.rel.indexOf("standard") > -1) {
		t = "standard";
	} else if (this.rel.indexOf("console") > -1) {
		t = "console";
	} else if (this.rel.indexOf("fullscreen") > -1) {
		t = "console";
	} else if (this.rel.indexOf("external") > -1) {
		x = "external";
	} else if (this.rel.indexOf("external-custom") > -1) {
		x = "external-custom";
	}

	if ((x == "external") || (x == "external-custom")) {
		// Call the 3rd party disclaimer DHTML
		extUrl = this.href;
		extType = t;
		extScrWidth = w;
		extScrHeight = h;
		display3PD(x);
	} else {
		// Call the popup script
		popUpWin(this.href,t,w,h);
	}

	// Cancel the default link action if pop-up activated
	if (window.event) {
		window.event.returnValue = false;
		window.event.cancelBubble = true;
	} else if (e) {
		e.stopPropagation();
		e.preventDefault();
	}
}

function popUpWin(url, type, scrWidth, scrHeight) {
	var tools="";
	var winNameGen=new Date();
	var winName=winNameGen.getTime();
	type = type.toLowerCase();

	closeWindow();
	
	if (type == "fullscreen") {
		scrWidth = screen.availWidth;
		scrHeight = screen.availHeight;
	}
	
	if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+scrWidth+",height="+scrHeight+",top=0,left=0";
	if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+scrWidth+",height="+scrHeight+",left=0,top=0";
	
	newWindow = window.open(url, winName, tools);
	newWindow.focus();
}

function launchPopup() {
	hide3PD();
	popUpWin(extUrl,extType,extScrWidth,extScrHeight);
}

function closeWindow() {
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function display3PD(x) {
	setWindowSize();
	
	var popup_text = 'The link to this third party website is provided for your information and convenience. The operator of this site is not affiliated with NAB and NAB is not responsible for the content of this site. NAB will not be liable for any loss or damage resulting from your use of any aspect of this site and all such use is solely at your risk. In particular, NAB, its related companies and businesses and personnel do not guarantee that any file or program available for download and/or execution from or via this site is free of computer viruses or other conditions which could damage or interfere with data, hardware or software with which it might be used.';

	if (window.popup_text_custom == undefined) {
		var popup_text_custom = "Please define the variable <code>popup_text_custom</code> before this script is loaded in the page source.";
	}

	var popup_html = '<div style="z-index: 500; position: fixed; _position: absolute; top: '+winYPos+'; left: '+winXPos+';" tabindex="-1" id="disc_container" class="disc_container"><a href="javascript:hide3PD()" id="close"><img src="/vgnmedia/images/buttons/btn_closediv.gif" border="0" /></a><h1>Disclaimer</h1><p>' + popup_text + '</p><ul><li id="decline"><a href="javascript:hide3PD()"><img border="0" alt="Decline" src="/vgnmedia/images/buttons/btn_decline.gif"/></a></li><li id="accept"><a href="javascript:launchPopup()"><img border="0" alt="Accept" src="/vgnmedia/images/buttons/btn2_accept.gif"/></a></li></ul></div>'; 

	var popup_html_custom = '<div style="z-index: 500; position: fixed; _position: absolute; top: '+winYPos+'; left: '+winXPos+';" tabindex="-1" id="disc_container" class="disc_container"><a href="javascript:hide3PD()" id="close"><img src="/vgnmedia/images/buttons/btn_closediv.gif" border="0" /></a><h1>Disclaimer</h1><p>' + popup_text_custom + '</p><ul><li id="decline"><a href="javascript:hide3PD()"><img border="0" alt="Decline" src="/vgnmedia/images/buttons/btn_decline.gif"/></a></li><li id="accept"><a href="javascript:launchPopup()"><img border="0" alt="Accept" src="/vgnmedia/images/buttons/btn2_accept.gif"/></a></li></ul></div>'; 
	
	if (x == "external") {
		$("#third_party_disclaimer").empty().append(popup_html).show();
	}
	if (x == "external-custom") {
		$("#third_party_disclaimer").empty().append(popup_html_custom).show();
	}
}

function hide3PD() {
	$("#third_party_disclaimer").hide();
}

addEvent(window, 'load', findPopUps, false);
if ((document.location).toString().indexOf("iblogout") == -1) {
	document.write('<div id="third_party_disclaimer"></div>');
}
