function downloadTemplate()
{
	$( 'processing_bar' ).setStyle( { height: $('tmpld_main').getHeight() } )
	$( 'tmpld_main' ).hide();
	$( 'processing_bar' ).show();
	
	var formid = 'download_form';
	var url = linkprefix+'/controller/joomla_templates/download.ajax.php';
	$( formid ).action = url;
	$( formid ).request( {
		asynchronous: false,
		parameters: { 
			tid: template_id
		},
		onSuccess: function( transport ) {
			var res = transport.responseText;
			res = trim( res );
			if( res.length > 0 )
			{
				if( res == 'OK' )
				{
					$('download_email').update( $( 'email' ).value );
					$('box').update( $( 'download_sent' ).innerHTML );
				}	
				else if( res.match( /^Error:/ ) )
				{
					closePreview();
					alert( res );
				}			
				else if( res.isJSON() )
				{
					$( 'processing_bar' ).hide();
					$( 'tmpld_main' ).show();
					var errors = res.evalJSON();
					showErrors( errors );
				}
			}
		}
	});
	
	$( formid ).action = '';
}

function toggleConfirmCheckbox()
{
	var aid = "confirm_check";
		
	if( $( aid ).hasClassName( 'checkbox_off' ) )
	{
		checkOn( aid );
		enableButton();
	}
	else
	{
		checkOff( aid );
		disableButton();
	}
}

function checkOn( aid )
{
	if( $( aid ) )
	{
		$( aid ).removeClassName( 'checkbox_off' );
		$( aid ).addClassName( 'checkbox_on' );
	}
}

function checkOff( aid )
{
	if( $( aid ) )
	{
		$( aid ).removeClassName( 'checkbox_on' );
		$( aid ).addClassName( 'checkbox_off' );
	}
}

function enableButton()
{
	$( 'button_off' ).hide();
	$( 'button_on' ).show();
}

function disableButton()
{
	$( 'button_on' ).hide();
	$( 'button_off' ).show();
}
