/***********************************
 * Dependencias
 *
 * prototype.js
 * YAHOO
 ***********************************/

var pageHomeViewClass = Class.create();

pageHomeViewClass.prototype = {
	/**************************
	 * Attributes
	 **************************/
	Event: YAHOO.util.Event,
	Env: YAHOO.env,
	innovacFrom: null,
	innovacTo: null,
	month: 0,

	/**************************
	 * Constructor
	 **************************/
	initialize: function() {
		this.createCalendars();
		var myDate=new Date();
		this.month = myDate.getMonth()+1;
		this.addEvents();
	},

	/**************************
	 * Public Methods
	 **************************/
	addEvents: function() 
	{
		this.Event.addListener("submitButton", "click", this.submitForm, this, true);
		this.Event.addListener("innovacFromAction", "click", this.innovacFrom.oCalendar.selectEvent.subscribe(this.changeInnovacSelectedDate, this), this, true);
		this.Event.addListener("innovacToAction", "click", this.innovacTo.oCalendar.selectEvent.subscribe(this.changeInnovacSelectedDate, this), this, true);
		
	},
	
	createCalendars: function() 
	{
		// Calendar From
		this.innovacFrom = new yuiCalendarClass("innovacDateFrom", "innovacFromAction", "innovacFromAction");
		// Calendar To
		this.innovacTo = new yuiCalendarClass("innovacDateTo", "innovacToAction", "innovacToAction");
		
		var myDate=new Date();
		myDate.setDate(myDate.getDate()+1);
		this.innovacFrom.setDate(myDate);
		this.innovacTo.setDate(myDate);
	},
	
	changeInnovacSelectedDate: function(type, args, me) 
	{

	},
	
	submitForm: function()
	{
		if (this.isValidForm())
			$("customizedTripForm").submit();
	},
	
	isValidForm: function()
	{
		var ok = true;

		var name = $("name");
	    if (name.value == null || name.value.replace(" ", "").length == 0)
	    {
	    	name.addClassName('error_input');
	    	ok = false;
	    } else 
	    	name.removeClassName('error_input');

	    var email = $("email");
	    if (email.value == null || email.value.replace(" ", "").length == 0)
	    {
	    	email.addClassName('error_input');
	    	ok = false;
	    } else 
	    	email.removeClassName('error_input');

	    return ok;
	}
}


var homeView = null;

Event.observe(window, 'load', initHomeView, false);

function initHomeView()
{
	homeView = new pageHomeViewClass();
}
