function show_fumodal(message) {

	$.fumodal({	
		width:300,
		height:130,
		style:true,
		content: '<p style="text-align: center; margin-top: 15px; font-size: 12px;">' + message + '</p>',
		title:'<b>Newsletter</b>'
	});

}

function show_fumodal2(message, filelink) {

	var link_line = '';
	if (filelink != '') {
		link_line = '<a href="' + filelink + '">Click here</a> to download the selected file.';
	}

	$.fumodal({	
		width:300,
		height:170,
		style:true,
		content: '<p style="text-align: center; margin-top: 15px; font-size: 12px;">' + message + '<br /><br />' + link_line + '</p>',
		title:'<b>Newsletter</b>'
	});

}

function add_newsletter_js(email, name, company_name, modal_type, downloads_verification) {

	if (modal_type == 'fumodal') {
		$.fumodal({	
			width:200,
			height:100,
			style:true,
			content: '<p style="text-align: center; margin-top: 15px; font-size: 12px;">Sending ... Please wait.</p>',
			title:'<b>Alert</b>'
		});				
	} 	

	$.post(base_url + "chimp/add_subscriber", {email: email, name: name, company_name: company_name}, function(result) {

		result = json(result);
		var message = "";
		var download_possible = false;
		
		if (result["mesg"] == 'ok') {
			if (result["code"] == false) {
				message = "You have already signed for our newsletter.";
			} else {
				message = "You have been added to our newsletter.";
			}
			$.fumodal_close();
			download_possible = true;	
			
		}
		if (result["mesg"] == 'fill_all') {
			message = "Please fill in all fields marked with an asterisk and check if they are correct.";
		}		
		
		if (modal_type == 'fumodal') {
		
			$.fumodal_close();			
			setTimeout("show_fumodal('" + message + "');", 1000);							
			
		} 
		if (modal_type == 'from_fumodal') {
		
			if (downloads_verification != -1) {
			
				$.post(base_url + "ajax/load_downloads", {file_id: downloads_verification}, function(filelink) {				
					$.fumodal_close();			
					if (filelink != 'bad_data') {
						if (download_possible == false) {
							filelink = '';
						}
						setTimeout("show_fumodal2('" + message + "', '" + filelink + "');", 1000);									
					}
				});				
				
			} else {					
				$("#modal_info_paragraph").html(message);
			}
			
		}
		
				
	});
	
}

$(function() {

	$("a.popup_newsletter").click(function() {
		$.fumodal({	
			width:400,
			height:310,
			style:true,
			data: {file_id: -1},
			url: base_url + "ajax/popup_newsletter",
			title:'<b>Join Newsletter</b>'
		});				
		
		return false;		
	});

	$("a.popup_newsletter_download").click(function() {
		var file_id = $(this).attr('id').substr(5);
		$.fumodal({	
			width:400,
			height:310,
			style:true,
			data: {file_id: file_id},
			url: base_url + "ajax/popup_newsletter",
			title:'<b>Join Newsletter</b>'
		});				
		
		return false;		
	});

});	