var popup = {};

function doPopup(url, name, width, height, winparams) {
	if (!width) width = screen.availWidth;
	if (!height) height = screen.availHeight;
	if (!name) name = 'popup';
	if (!url) return;

	leftX = (screen.availWidth - width) / 2;
	topY = (screen.availHeight - height) / 2;
	if (leftX < 0) leftX = 0;
	if (topY < 0) topY = 0;
	if (window.opera) topY = 2 * topY / 3;

	if (!(name in popup) || popup[name].closed) {
		popup[name] = window.open(url, name, 'width=' + width + ',height=' + height +
				',left=' + leftX + ',top=' + topY + (winparams?','+winparams:''));
	}
	if (window.focus) popup[name].focus();
	if (popup[name].opener == null) popup[name].opener = self;
	return popup[name];
}

function extLink(sWin, type, image, id) {
    switch (sWin) {
		case "signup":
            doPopup("/f150raptor/signup/", sWin, 800, 650, "scrollbars=1,resizable=1");
			break;
        case "tellafriend":
            doPopup("/f150raptor/tellafriend/", sWin, 500, 650, "scrollbars=1,resizable=1");
			break;
		case "share":
            doPopup("/f150raptor/share/?type="+type+"&image="+image+"&id="+id, sWin, 500, 650, "scrollbars=1,resizable=1");
			break;
		case 'build':
			doPopup('http://www.forddirect.fordvehicles.com/FordVehicles.jsp?intcmp=&target=config&partner=&sModel=2009F-150&sBrand=Ford&sZip=', sWin, 800, 600, 'scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes');
			break;
		case 'dealer':
			doPopup('http://www.fordvehicles.com/dealerships/locate/', sWin, 800, 600, 'scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes');
			break;
		case 'search':
			doPopup('http://www.fordvehicles.com/asp/util/gateway.asp?App=DealerInventory&nModelId=0&Parameter1=undefined', sWin, 800, 600, 'scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes');
			break;
		case 'privacy':
			doPopup('/help/privacy/', sWin, 800, 600, 'scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes');
			break;
		case 'home':
			doPopup('/', sWin, 800, 600, 'scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes');
			break;
		case 'ford':
			doPopup('http://www.ford.com/', sWin, 970, 738, 'scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes');
			break;
		case 'disclaimer':
			doPopup('/f150raptor/disclaimer/', 'disclaim', 400, 400, 'scrollbars=yes,resizable=yes');
			break;
		case 'score':
			doPopup('http://www.score-international.com/', sWin, 980, 738, 'scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes');
			break;
		case 'bitd':
			doPopup('http://www.bitd.com/main/', sWin, 980, 738, 'scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes');
			break;
    }
}

String.prototype.startsWith = function (s) {
	return this.substr(0, s.length) === s;
}

function launchExLink($url) {
	if (confirm("You are linking to a non-Ford Web site. Your browsing and interaction are subject to the rules and policies of that site. Please read over the site's rules and policies before proceeding.")) {
		sendLinkEventNew('referral:exit', 'referral:'+$url);
		doPopup($url, 'offroad', 980, 738, 'scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes');
	}
}

