
// styles for popups. add new ones as you need. each
// array holds: [STYLES,TARGET] (and target is optional)
//
var popupLinkConfig = new Array;
popupLinkConfig['video'] = new Array( 'width=500,height=550,scrollbars=no','videoPop');

//	-	-	-	-	-	-	-	-
// DO NOT EDIT BELOW THIS LINE
//	-	-	-	-	-	-	-	-


	//	-	-	-	-	-	POP OPEN	-	-	-	-	-
	//
	// you can set this.preProcess & .postProcess to insert your own functionality into the anchor
	// if preProcess returns true, we DO NOT continue toggling
	//
	function setupOnePopopen( anc) {
		anc.isopen = false;
		
		anc.togglePopper = function() {		// you can call this manually
			this.isopen = !this.isopen;
			toggleVis(this.id+'Pop');		// open the div

			if ( this.isopen )	// swap classes
				replaceClass(this,'popopen','popclosed');
			else
				replaceClass(this,'popclosed','popopen');
		};
		togglePopFunction = function(e) {
			if ( this.preProcess && this.preProcess( !this.isopen))	// preprocessing fnc can terminate this operation
				return false;
			this.togglePopper();
			if ( this.postProcess) this.postProcess( this.isopen);
			cancelEvent(e,false);
			return false;
		};
		addEvent(anc,'click',togglePopFunction,true);
	}

	//	-	-	-	-	-	POPUP WINDOWS	-	-	-	-	-	
	//
	
		// using this directly is discouraged, but allowed (it's needed for FORM actions)
		function doPopup( href, tgt, opts) {
			var w = window.open(href,tgt,opts);
			w.focus();
			try {
				window[tgt] = w;
				w.objectName = tgt;	// fails in IE when w is HTTPS
			}
			catch(xx) {}
		}
		// called from the popup window to the parent. pass in:
		//		[pwin] = the window itself
		//		[closePopup] = boolean, to close the popup
		//		[andGoWhere] = href to redirect to (in the parent) - or blank to force a page-refresh
		//
		function redirectTo(pwin,closePopup,andGoWhere) {
			if (closePopup) {
				try {
					var nm = (pwin.objectName ? pwin.objectName : 'popupWin');
					if ( window[nm] != null) window[nm] = null;
					pwin.objectName = null;
				} catch(xx) {}
				pwin.close();
			}
			if (andGoWhere)
				location.href=andGoWhere;
			else
				window.location.reload(true);
		}
		// use this function from the popup window
		function parentRedir(closePopup,addr) {
			if(window.opener) window.opener.redirectTo(window,closePopup,addr);
		}
	
	function setupOnePopupWin( anc) {
		var	cls = getCls(anc),
			sty = stripMultiCls( cls.substring(8 + cls.indexOf('popupWin'))), sizes, styleArray, scrb, spc;

		// popupWin-STYLE (from array above)
		if (sty.substring(0,1) == '-') {
			styleArray = popupLinkConfig[sty.substring(1)];
			if ( styleArray) {
				var target = styleArray[1] ? styleArray[1] : 'popupWin',
					opts = styleArray[0],
					popFunc1 = function(e) {
						doPopup(this.href,target,opts);
						cancelEvent(e,false);
						return false;
					};
				addEvent( anc, 'click', popFunc1, true);
			}
		}
		// popupWin400x300 (no scrolls) popupWin400x300xS (with scrolls)
		else {
			sizes = sty.split('x');
			if (sizes.length>2) scrb=',scrollbars=yes';
			var popFunc2 = function(e) {
				var opts = 'width='+sizes[0]+',height='+sizes[1]+scrb;
				doPopup(this.href,'popupWin',opts);
				cancelEvent(e,false);
				return false;
			};
			addEvent( anc, 'click', popFunc2, true);
		}
	}
	
	function setupOneParentRedirect( anc) {
		var parClick = function(e) { parentRedir(true,this.href); cancelEvent(e,false); return false; };
		addEvent( anc, 'click', parClick, true);
	}


	//	-	-	-	-	-	OFF-SITE LINKS	-	-	-	-	-	
	//
	function setupOneOffsiteLink( anc) {
		anc.target = "_blank";
		anc.setAttribute("title", "Offsite link: " + anc.href);
		
		if ( classContains(anc, "offsite"))	// exact match only
			anc.innerHTML += '<img src="../uimages/bullets/offsite-link.gif" width="13" height="7" class="offsite">';
		
		var offsiteFnc = function(e) {
			var trkImg=new Image(), url=this.href.replace(/[\?&]/g, '^');	// get rid of ? and & in the URL
			trkImg.src = rootDir() + '_track/offsite-link.asp?url=' + url;
			return true;	// let the HREF do its normal thing
		};
		addEvent( anc, 'click', offsiteFnc, true);
	}


//	-	-	-	-	-	-	-	-	-	-	-	-	-	-	-	

registerAnchorType( {cls:"popopen",			apply:setupOnePopopen} );
registerAnchorType( {clsPartial:"popupWin",	apply:setupOnePopupWin} );
registerAnchorType( {clsPartial:"offsite",	apply:setupOneOffsiteLink} );
registerAnchorType( {clsPartial:"parentRedirect", apply:setupOneParentRedirect} );
