// mazda NGW general javascript
// global pdfLink
var pdfLink; // string
var followLink; //string

// generic popup window allowing size to be set
function openWindow (url, winName, w, h, properties) { 
    properties = properties || "resizable"
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+','+ properties;
	newWindow = window.open(url,winName,settings);
	if(url.indexOf("://") == -1) newWindow.focus();
	top.newWindow = true;
	return false;
}

// full screen popup window
function launchFullScreen(url, winName, properties) {
	properties = properties || "resizable"
	LeftPostion = 0;
	TopPosition = 0;
	settings = properties;
	newWindow = window.open(url,winName,settings);
	newWindow.moveTo(0,0);
	newWindow.resizeTo(screen.availWidth,screen.availHeight);
	newWindow.focus();
}	

/*Show Overlay Option 3 brochure request*/
function ShowOverlay(followLinkSent,pdfLinkSent)
{
	//Ajax call to sever // determine whether a cookie has been set 
	pdfLink = pdfLinkSent;
	followLink = followLinkSent;
	Methods.RequestBrochureLinkCheck(linkCallBack);
}

function linkCallBack(res)
{
	if(res.value == false)
	{
		//display Overlay
		document.getElementById("panelFormDetails").style.visibility='visible';
		document.getElementById("content").style.visibility='hidden';
		document.getElementById("NextFirst").className = 'FormBox';
		//push links
		document.getElementById("FormControl_pdfLinkForm").value = pdfLink;
		document.getElementById("FormControl_followLinkForm").value = followLink;
	}
	else if(res.value == true)
	{
		// popup pdf && redirect link
		window.open(pdfLink);
		window.location=followLink;
	}
}

function promoTitleReplace(DisplayName)
{
	if (DisplayName.match('0% APR'))
	{
		return DisplayName.replace(/0% APR/, '<span style="FONT-SIZE: 150%">0% APR</span>');
	}
	
	return DisplayName;
}
