﻿function downloadContent(params) {
	var content =	'<div id="pressdownloadpopup" class="popcontainer">' +
						'<div class="maincontent clearfix">' +
							'<div class="whitebg small">' +
								'<span class="eightteen">Download requirements</span>' +
								'<span class="fourteen">Some of the requested information is intended for journalists only.</span>' +
							'</div>' +
							'<div class="confirm">' +
								'<span>Please confirm that you are<br />a member of the media.</span>' +
								'<ul class="buttonlist">' +
									'<li><a href="#" onclick="openLink(\''+params.href+'\'); return false;"><img src="/corporate/images/news/journalist_yes.gif" alt="Yes" /></a></li>' +
									'<li><a href="#" onclick="denyAccess(); return false;"><img src="/corporate/images/news/journalist_no.gif" alt="No" /></a></li>' +
								'</ul>' +
							'</div>' +
							'<div class="deny">' +
								'<span class="important" style="width: 240px;"><strong>We are sorry,</strong> you may not<br/> access this content.</span>' +
								'<ul class="buttonlist">' +
									'<li><a href="#" onclick="lightbox.lb_hide(); return false;"><img src="/corporate/images/news/journalist_close.gif" alt="Close" /></a></li>' +
								'</ul>' +
							'</div>' +
						'</div>' +
					'</div>';
	return content;
}
function openLink(href) { 
	lightbox.lb_hide(); 
	newWindow = window.open(href, "PDF", "width=900,height=600,left=100,top=200");
	newWindow.focus();
	document.cookie='journalist-approved=true;path=/corporate/';
}
function denyAccess(href) {
	$('#pressdownloadpopup div.confirm').each(function () { $(this).css("display","none") });
	$('#pressdownloadpopup div.deny').each(function () { $(this).css("display","block"); });
	Cookie.erase('journalist-approved');
}
function initPressDownloads() {
	$('a.pressdownload').click( function() {		
		var href = $(this).attr('href');		
		if(Cookie.get('journalist-approved') != 'true'&&$(this).attr('href').indexOf('pdf')>-1)
		{
			lightbox.create({type:'callback', callback : downloadContent, href : href});
		}
		else
		{
			newWindow = window.open( href, "PDF", "width=900,height=600,left=100,top=200");
			newWindow.focus();
		}
		return false;		
	});
}

$(document).ready(function(){
	initPressDownloads();
});