function Pdf_Generator(){

	/**
	 *	Private variables
	 **/
	var data = new Object ();
	
	var contactForm = dojo.byId ( "pdf_generator_contact_form" );
	var emailField = dojo.byId ( "pdf_generator_email" );
	var emailSendButton = dojo.byId ( "pdf_generator_email_send" );
	var successMessage = dojo.byId ( "pdf_generator_success_message" );
	var loadingMessage = dojo.byId ( "pdf_generator_loading" );
	var courseSeason = dojo.byId('id_school_demonstrator_select_course_season');
	var all_preise = dojo.byId('id_school_info_all_prices_include_simple');
//	var schulmaterial = document.getElementById('id_school_facts_prices').getElementsByTagName('td');
	
	function validateEmail(email) 
	{ 
		var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 
	 	return email.match(re) 
	}
	
	function updateData()
	{

		var today = new Date();
		data [ "time" ] = today.toTimeString();
		data [ "accommodation_id" ] = a_price_calculator.accommodation_form.id;
		data [ "course_id" ] = a_price_calculator.course.id;
		data [ "school_id" ] = a_price_calculator.school.id;
		data [ "transfer_id" ] = a_price_calculator.transfer.id;		
		data [ "currency_id" ] = a_money_exchange.locale_currency.id;
		data [ "exchange_rate" ] = a_price_calculator.span_exchange_rate.innerHTML;
		
		data [ "acc_duration" ] = a_price_calculator.accommodation_weeks;
		data [ "course_duration" ] = a_price_calculator.course_weeks;
		data [ "season" ] = courseSeason.innerHTML;
		
		data [ "accommodation_inscription_fee" ] = a_price_calculator.span_accommodation_inscription_fee_amount.innerHTML;
		data [ "accommodation_price" ] = a_price_calculator.span_accommodation_price_amount.innerHTML;
		
		data [ "course_exam_fee" ] = a_price_calculator.span_course_exam_fee_amount.innerHTML;
		data [ "course_inscription_fee" ] = a_price_calculator.span_course_inscription_fee_amount.innerHTML;
		data [ "course_price" ] = a_price_calculator.span_course_price_amount.innerHTML;
		
		data [ "exchange_rate" ] = a_price_calculator.span_exchange_rate.innerHTML;
		
		data [ "school_material_fee" ] = a_price_calculator.span_school_material_fee_amount.innerHTML;
		
		data [ "total_price" ] = a_price_calculator.span_total_price.innerHTML;
		data [ "total_price_school_curency" ] = a_price_calculator.span_total_price_school_curr.innerHTML;
		
		data [ "transfer_price" ] = a_price_calculator.span_transfer.innerHTML;
		data [ "all_preise" ] = all_preise.innerHTML;

		data [ "course_start" ] = a_price_calculator.course_start;
	
		data [ "accommodation_weeks" ] = a_price_calculator.accommodation_weeks;
		data [ "course_weeks" ] = a_price_calculator.course_weeks; 

	}
	
	function enable ( aNode )
	{
		aNode.style.display = '';
	}
	
	function disable ( aNode )
	{
		aNode.style.display = 'none';
	}
	
	function post_to_url(path, params, method) 
	{
	    method = method || "post"; // Set method to post by default, if not specified.
	
	    // The rest of this code assumes you are not using a library.
	    // It can be made less wordy if you use one.
	    var form = document.createElement("form");
	    form.setAttribute("method", method);
	    form.setAttribute("action", path);
	
	    for(var key in params) {
	        var hiddenField = document.createElement("input");
	        hiddenField.setAttribute("type", "hidden");
	        hiddenField.setAttribute("name", key);
	        hiddenField.setAttribute("value", params[key]);
	
	        form.appendChild(hiddenField);
	    }
	
	    document.body.appendChild(form);    // Not entirely sure if this is necessary
	    form.submit();
	}

	
	this.viewPdf = function ()
	{
		try {
			updateData();
			
			post_to_url ( "/pdf/view/", data, "POST" )
		} 
		catch (error) {
			console.error(error);
			return false;
		}
	}
	
	this.sendPdf = function ()
	{
		try
		{
			var email = emailField.value;
			console.log ( email );
			if ( validateEmail ( email ) )
			{
				data[ "email" ] = email;
			}
			else
			{
				alert ( gettext ("Bitte eine gültige Email-Adresse angeben." ) );
				throw gettext ( "Ungültige Email-Adresse." );
			}

			updateData ();
			
		
			enable ( loadingMessage );
				
			disable ( contactForm );		
			
			var url = "/pdf/create/";
			var handleAs = "json-comment-optional";
			
			var handle = function ( aData, aArgs )
			{
				if (typeof aData == "error") 
				{
					console.warn("error!", aArgs);
				}
				
				// we hide the contact form
				
				
				// and we show a success message
				enable ( successMessage );
				
				disable ( loadingMessage );
				
			}
			
			
//			dojoWrapper.ajaxRequestPost ( url, data, agent, handleAs );
			dojo.xhrPost ( 
			{
				url:url, content:data, handle: handle, handleAs:handleAs 
			} );
		}
		catch ( error )
		{
			console.error ( error );
			return false;
		}
		
	}
	
	this.enableContactForm = function ()
	{
		// make the contact form visible
		disable ( successMessage );
		enable ( contactForm );	
		
	}
	
	
}
