
// styles for popups. add new ones as you need. each
// array holds: [STYLES,TARGET] (and target is optional)
//
var popupLinkConfig = new Array;
popupLinkConfig['emailFriend'] = new Array( 'width=500,height=540,scrollbars=yes');
popupLinkConfig['themePop'] = new Array( 'width=550,height=500,scrollbars=yes');
popupLinkConfig['pageFlipper'] = new Array( 'width=545,height=532,scrollbars=no');
popupLinkConfig['unboundPrivacy'] = new Array( 'width=510,height=450,scrollbars=yes');
popupLinkConfig['unboundVideo'] = new Array( 'width=560,height=460,scrollbars=no');
popupLinkConfig['unboundAudio'] = new Array( 'width=560,height=460,scrollbars=no');
popupLinkConfig['userManage'] = new Array( 'width=680,height=680,scrollbars=yes,resizable=yes');


//	-	-	-	-	-	-	-	-
// 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.firstOpen = true;
		anc.isopen = false;
		
		anc.togglePopper = function() {		// you can call this manually
			this.isopen = !this.isopen;
			if ( this.firstOpen) {
				// tracking pixel when the user opens, 1st time only
				var pth=window.location.pathname, trkImg=new Image();
				if ( pth.substr(pth.length-1,1) == '/' ) pth=pth+'default.asp'
				trkImg.src = rootDir() + '_track/popopen.asp?page=' + pth + '~'+this.id;
				this.firstOpen = false;
			}
			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} );
