


$(document).ready(function(){


//centering popup
function centerPopup(){
var viewport={o:function(){if(self.innerHeight){this.pageYOffset=self.pageYOffset;this.pageXOffset=self.pageXOffset;this.innerHeight=self.innerHeight;this.innerWidth=self.innerWidth;}else if(document.documentElement&&document.documentElement.clientHeight){this.pageYOffset=document.documentElement.scrollTop;this.pageXOffset=document.documentElement.scrollLeft;this.innerHeight=document.documentElement.clientHeight;this.innerWidth=document.documentElement.clientWidth;}else if(document.body){this.pageYOffset=document.body.scrollTop;this.pageXOffset=document.body.scrollLeft;this.innerHeight=document.body.clientHeight;this.innerWidth=document.body.clientWidth;}
return this;},init:function(el){$(el).css("left",Math.round(viewport.o().innerWidth/2)+viewport.o().pageXOffset-Math.round($(el).width()/2));$(el).css("top",Math.round(viewport.o().innerHeight/2)+viewport.o().pageYOffset-Math.round($(el).height()/2));}};
viewport.init(".pop_up");
}



	$('.b_dl').click(function(){
		link = $(this).attr('id');
		$('#LINK').val(link);
		
		if($.cookie('PBP-BROCHURE-COOKIE'))
		{
			openDownload(link)
		}
		else
		{
			$('.pop_up').load('brochures-download-popup.php')
			$('.pop_up').fadeIn('normal');		
			centerPopup();
		}
		
		return false;
	});
	$('#RESET').live('click',function(){
		$('.pop_up input').each(function(){
			id = $(this).attr('id');
			if ( id !== "RESET" && id !== "SUBMIT" ) 
			{
				$(this).val("");
			}
		});
	});
	
	$('#SUBMIT').live('click',function(){
		var link = $('#LINK').val()
		var first_name = $('#ID_FIRSTNAME').val();
		var last_name = $('#ID_LASTNAME').val();
		var company = $('#ID_COMPANY').val();
		var contact_number = $('#ID_CONTACT_NUMBER').val();
		var email = $('#ID_EMAIL').val();
		var newsletter_signup = $('#ID_NEWSLETTER').val();
		params = 'SUBMIT=1&ID_FIRSTNAME=' + first_name + '&ID_LASTNAME=' + last_name + '&ID_COMPANY=' + company + '&ID_CONTACT_NUMBER=' + contact_number + '&ID_EMAIL=' + email + '&ID_NEWSLETTER=' + newsletter_signup;
		
		$('.pop_up').load('brochures-download-popup.php?',params,function(){
			if ( $("table tr td.error").text() == "" )
			{
				$.cookie('PBP-BROCHURE-COOKIE', '1', { expires: 365});
				$('.pop_up').fadeOut('normal');
				openDownload(link)
			}				
		});
		//centerPopup();
	});
	
	function openDownload(link)
	{
		//open('download-file.php?f='+link);
		// $.get('download-file.php?f='+link);
		window.location = 'download-file.php?f='+link;
		//return false;
	}
	
	$('.close').live('click',function(){
		$('.pop_up').fadeOut('normal');
	});
});