/* ==================================================== *
 * TITLE   : COMMON JAVASCRIPT   |  common.js    
 		
		contents taken from crutchfield.com common.js 11.27.2007 - OM
 
 *
 * ==================================================== */

/* ==================================================== *
 * EXTERNAL POPUP
 * ==================================================== */

var poppedWin = null;

/**
 * Call like this: ...onclick="return !NewWindow(this.href, {'height': 600, 'scrollable': 'no'})"...
 * @return  true if popup succeeded
 */
function NewWindow(url)
{
	//retrofit for old calls
	if(arguments.length === 5)
	{
		opts =
		{
			'winLabel': arguments[1],
			'width': arguments[2],
			'height': arguments[3],
			'scrollable': arguments[4]
		};
	}
	else if(arguments.length === 2)
	{
		opts = arguments[1];
	}
	else
	{
		opts = {};
	}

	var winLabel = opts['winLabel'] || "CrutchfieldPopup";
	var width = opts['width'] || 400;
	var height = opts['height'] || 450;
	var scrollable = opts['scrollable'] || 'yes';
	var resizable = opts['resizable'] || 'yes';
	var stripped = opts['stripped'] || 'no'; // 'yes', 'no', or 'almost'

	var leftPosition = (screen.width) ? (screen.width-width)/2 : 0;
	var topPosition = (screen.height) ? (screen.height-height)/2 : 0;
	var chromeSettings = (stripped === 'yes' ? ',toolbar=no,location=no,directories=no,status=no,menubar=no' : stripped === 'almost' ? ',toolbar=no,location=yes,directories=no,status=no,menubar=no' : '');

	settings = 'height='+height+',width='+width+',top='+topPosition+',left='+leftPosition+',scrollbars='+scrollable+',resizable='+resizable + chromeSettings;
	poppedWin = window.open(url, winLabel, settings);

	if(poppedWin)
		poppedWin.focus();//just in case we are replacing a backgrounded popup

	return !!poppedWin;// so we can say onclick="return !NewWindow(...)"
}



/**
 * Call like this: ...onclick="return !loadInParent(this.href, true)"...
 * @return  true if popup succeeded
 */
function loadInParent(url, closeSelf)
{
	if(self.opener)
	{
		self.opener.location = url;
		if(closeSelf)
			self.close();
		return true;
	}
	else // on the slight chance that this is called from a non-popup, open link normally
	{
		return false;
	}
}





