/**
* Assign the view handler
*/

viewHandler = UploadPage;

/**
* Creates a new object with methods used by the Upload page
*
* @author				Matt Gifford
* @copyright			2008 Timeshifting Interactive Limited
*/
function UploadPage()
	{
	// Step 1. Define Properties

	var _instance = this;
	var _tooltips = [];



	// Step 2. Define Public Methods

	/**
	* Sets up the initial page state and event handlers
	*/
	this.init = function()
		{
		// Call generic page init method
		this.base.init.call(this);
		}

	
	/**
	* Handles the UI update on a video upload
	*/
	this.processVideoUpload = function()
		{
		// 1. Validate the form

		// Clear any existing status message
		document.getElementById('videoFormMessage').className = 'hidden';

		// Check the form fields
		var inputs = document.getElementById('videoForm').getElementsByTagName('input');

		// Check filename
		if (inputs[0].value.length < 4)
			{
			document.getElementById('videoFormMessage').firstChild.nodeValue = 'Please select a video to upload';
			document.getElementById('videoFormMessage').className = 'error';
			return;
			}

		// Check the title
		if (inputs[1].value.length < 4)
			{
			document.getElementById('videoFormMessage').firstChild.nodeValue = 'Please enter a title for this video';
			document.getElementById('videoFormMessage').className = 'error';
			return;
			}


		// 2. Upload the content

		// Set the uploading state on the video form
		document.getElementById('videoForm').className = 'uploading';

		// Display the uploading message
		document.getElementById('videoUploading').className = '';

		// Hide the upload photo form
		if (document.getElementById('imageForm'))
			{
			document.getElementById('imageForm').className = 'hidden';
			}

		// Submit the form
		document.getElementById('videoForm').submit();
		}


	/**
	* Handles the UI update on a photo upload
	*/
	this.processPhotoUpload = function()
		{
		// 1. Validate the form

		// Clear any existing status message
		document.getElementById('imageFormMessage').className = 'hidden';

		// Check the form fields
		var inputs = document.getElementById('imageForm').getElementsByTagName('input');

		// Check filename
		if (inputs[0].value.length < 4)
			{
			document.getElementById('imageFormMessage').firstChild.nodeValue = 'Please select a photo to upload';
			document.getElementById('imageFormMessage').className = 'error';
			return;
			}

		// Check the title
		if (inputs[1].value.length < 4)
			{
			document.getElementById('imageFormMessage').firstChild.nodeValue = 'Please enter a title for this photo';
			document.getElementById('imageFormMessage').className = 'error';
			return;
			}


		// 2. Upload the content

		// Set the uploading state on the photo form
		document.getElementById('imageForm').className = 'uploading';

		// Display the uploading message
		document.getElementById('imageUploading').className = '';

		// Hide the upload video form
		if (document.getElementById('videoForm'))
			{
			document.getElementById('videoForm').className = 'hidden';
			}

		// Submit the form
		document.getElementById('imageForm').submit();
		}


	/**
	* Toggles the display of an about page module
	*
	* @param		obj			The button clicked
	*/
	this.toggleModule = function(obj)
		{
		// Find the module div
		var module = obj.parentNode.parentNode;

		// Toggle the state
		if (module.className.indexOf('expanded') != -1)
			{
			module.className = module.className.replace(/\s?expanded/g, '') + ' collapsed';
			var body = module.getElementsByTagName('div')[1];
			body.className += ' hidden';
			}
		else
			{
			module.className = module.className.replace(/\s?collapsed/g, '') + ' expanded';
			var body = module.getElementsByTagName('div')[1];
			body.className = body.className.replace(/\s?hidden/g, '');
			}
		}


	/**
	* Reloads the page on login, so the upload forms are displayed
	*/
	this.onAccountLogin = function()
		{
		window.location.reload();
		}


	/**
	* Redirects to homepage on logout
	*/
	this.onAccountLogout = function()
		{
		window.location = '/';
		}
	}

