var is_ff = (navigator.userAgent.toUpperCase().indexOf("FIREFOX") > -1)? true:false
var is_ie  = (document.all)? true:false
var aol = (navigator.userAgent.toUpperCase().indexOf("AOL") > -1)? true:false
var mac = (navigator.userAgent.toUpperCase().indexOf("MAC") > -1)? true:false

var undef;

function popup(popupurl,winName,w,h,params) {
   // Build parameter list manually.  This lets us override individual defaults as needed.

	var paramList = "";
	if (params == undef) {
		params = "";
	}
	
	params = params.toLowerCase();
	
	// Centering the Popup
	if (params.indexOf("centered=yes") != -1)
		{
			t = Math.round((screen.height - h) / 2);
			l = Math.round((screen.width - w) / 2);
		}
	else
		{
			t = 35;
			l = 130;
		}

	if (params.indexOf("menubar=yes") != -1) {
	} else {
		paramList = paramList + ",menubar=no";
	}
	
	if(aol) // aol anti-spyware tools deduct from our viewable area
		{
		h = h + 45;
		}
	

	// For Mozilla Popups that don't need extra sapce
	if (params.indexOf("scrollbars=yes") != -1) {
	    // default
		paramList = paramList + ",scrollbars=yes";
	    // IE needs extra space to allow for the phantom scrollbar, or we'll get horizontal scrollbars too.
	    // IE 6.x needs 4px more than IE 5.x, but IE 5.x's width needs vary a lot.  So, we'll set all
	    // IE browsers to use the wider IE 6.x size.
		if (is_ie && !aol)
		{
			w = w + 17;
		}
		else if(is_ff)
		{
			w = w + 19;
		}
		else
		{
			if(aol)
				w = w + 21;
			else
				w = w + 16;
		}
	} else if (params.indexOf("mozscroll=auto") != -1 && !is_ie) {
		w = w;
	} else {
		paramList = paramList + ",scrollbars=no";
	}
	
	if (params.indexOf("resizable=yes") != -1) {
		paramList = paramList + ",resizable=yes";
	} else {
	    // default
		paramList = paramList + ",resizable=no";
	}
	
	if ((params.indexOf("toolbar=yes") != -1) || (params.indexOf("toolbars=yes") != -1)) {
		paramList = paramList + ",toolbar=yes";
	} else {
	    // default
		paramList = paramList + ",toolbar=no";
	}
	
	if ((params.indexOf("location=yes") != -1) || (params.indexOf("location=yes") != -1)) {
		paramList = paramList + ",location=yes";
	} else {
	    // default
		paramList = paramList + ",location=no";
	}
	
	if ((params.indexOf("status=yes") != -1)) {
		paramList = paramList + ",status=yes";
	} else {
	    // default
		paramList = paramList + ",status=no";
	}
	
	if ((params.indexOf("top=") != -1) || (params.indexOf("left=") != -1)) {
		paramArray = params.split(",");
		for (i=0; i<paramArray.length; i++) {
			if (paramArray[i].indexOf("top=") != -1) {
				pEles = paramArray[i].split("=");
				t = pEles[1];
			}
			if (paramArray[i].indexOf("left=") != -1) {
				pEles = paramArray[i].split("=");
				l = pEles[1];
			}
		}
	}

	//alert(paramList);
	return window.open(popupurl,winName,"top=" + t + ",left=" + l + ",width=" + w + ",height=" + h + paramList);
}

var newwindow = '';

function popupClip(pcUrl, pcW, pcH, pcTxtTitle, pcTxtAgency, pcTxtDisclaimer) {

	// Construct URL for Popup
	var finalUrl = 'popup.html?mediafile=' + pcUrl + '&mediafileWidth=' + pcW + '&mediafileHeight=' + pcH + '&title=' + pcTxtTitle + '&agency=' + pcTxtAgency;
	
	// Optional Disclaimer
	if (pcTxtDisclaimer.length > 0)
		{
		finalUrl += '&disclaimer=' + pcTxtDisclaimer;
		}
	// alert(finalUrl);

	// Popup Behavior
	if (!newwindow.closed && newwindow.location) // If Window exists and has location then Refresh
		{
		newwindow.location.href = finalUrl;
		}
	else // If window does not exist, create new
		{
		newwindow=popup(finalUrl,'popupClip',270,240,'centered=yes');
		}
	if (window.focus) {newwindow.focus()} // If main site is in focus, set focus to popup
}