var win = null;
var baseURL;
window.onerror = null;
baseURL = window.location.protocol + "//" + window.location.hostname + "/";


// NEW WINDOW
function newWindow(mypage, myname, w, h, scroll) {
	closePopWin();
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',noresize';
	win = window.open(mypage, myname, winprops);
	//if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

// CLOSE POPUP
function closePopWin()  {
	if(win != null) {
		if(!win.closed) {
			win.close();
			win = null;
		} else {
			win = null;
		}
	}
}

// GET OBJECT BY ID.. OLDER METHOD
function getObject(id) {
	var object = null;
	if( document.layers ) object = document.layers[id];
	else if( document.all ) object = document.all[id];
	else if( document.getElementById )  object = document.getElementById(id);
	return object;
}

// GOOGLE ANALYTICS
if (typeof(_gat) == "object") { 
	//var pageTracker = _gat._getTracker("UA-5192063-3");
	var pageTracker = _gat._getTracker("UA-5192063-2");
	pageTracker._initData(); 
	pageTracker._trackPageview(); 
}

function analyticTrack( address ){ 
	pageTracker._trackPageview( address );	
	//getObject('google_tracking_debug').innerHTML = '<!-- [' + address + '] -->'; 
}

// SPOTLIGHT
function spotlight(src) {
	var axel = Math.random()+"";
	var a = axel * 1000000000000000000;
	//var url = src + a + '?';
//	alert(a)
	var url = src + a + "?";
	var spotpix = new Image();
	spotpix.src = url;
	//getObject('spotlight_pixel').innerHTML = '<img src=' + url + ' />';
}


// ESTERA CALL BACK
function launchEstera(id) {
	webVoicePop("Template=" + id );
}

function buildYourOwn() {
	newWindow("http://www.porsche.com/all/usa/startcc/default.htm?t=&screen=1280x800", 'build', 980, 700)
}

function launchDealer(zip,model) {
	//Car Model MUST be sent with a first letter being Capitalized | country codes: canada, usa
	//var url = "http://admin.porschedealer.com/PD_launchpad/index_" + countryCode + ".php?zip=" + zip + "&model=" + model;
	var url = "http://ican.porschedealer.com/index.php?zip=" + zip + "&model=" + model;
	newWindow(url, 'dealer', 870, 792, 1);
}

function launchPDF(lname,fname,email,zip,model,opt) {
	var url = "http://98.129.68.50/popup.aspx?cartype="+model+"&fname="+fname+"&lname="+lname+"&zip="+zip+"&email="+email+"&optin="+opt;
	newWindow(url, 'hardcopy', 640, 792, 1);
}

function testDrive(){
	// test drive?
}
