﻿//
//	This class represent the page the user is viewing. It's the controller on
//	the client-side of the view.
//
ContactPage = function()
{
	Unyk.Web.UI.Page.call(this);
};

YAHOO.lang.extend(ContactPage, Unyk.Web.UI.Page, 
{
	//*************************************************************************
	//
	//	Fields
	//
	//*************************************************************************
	_defaultForm : "frmContactUs",



	//*************************************************************************
	//
	//	Events
	//
	//*************************************************************************
	
	//
	//	Handles the Page Load event.
	//
	Page_Load : function(e, args)
	{
		// Assign the default form to post back to.
		this.Form = this._defaultForm;

		// Init all the page listeners.
		this.InitListeners();

		// Close the window if from a popup
		if (PageLewt.IsWindowAutoClosed)
		{
			alert(PageLewt.Texts.MessageSent);
			window.close();
		}

		if (PageLewt.IsAutoRedirected)
		{
			alert(PageLewt.Texts.MessageSent);
			document.location = "/";
		}

		if($("cboSubject").value == 17)
		{
			if (Dom.hasClass("rowModel", "hid-model"))
				Dom.removeClass($("rowModel"), "hid-model");

			if (Dom.hasClass("rowOption", "hid-model"))
				Dom.removeClass($("rowOption"), "hid-model");
		}
	},

	//
	//	Handles the btnSend Click event.
	//
	btnSend_Click : function(e, args)
	{
		Event.preventDefault(e);
		
		var errorMsg = this.ValidateInputs();
		if (errorMsg == "")
		{
			this.__doPostBack("btnSend", "");
		}
		else
		{
			alert(errorMsg);
		}
	},


	//
	//
	//
	cboSubject_Change : function(e, args)
	{
		Event.preventDefault(e);
		
		var sender = Event.getTarget(e);
		
		if (sender.value == 17)
		{
			if (Dom.hasClass("rowModel", "hid-model"))
				Dom.removeClass("rowModel", "hid-model");

			if (Dom.hasClass("rowOption", "hid-model"))
				Dom.removeClass($("rowOption"), "hid-model");
		}
		else
		{
			if (!Dom.hasClass("rowModel", "hid-model"))
				Dom.addClass("rowModel", "hid-model");

			if (!Dom.hasClass("rowOption", "hid-model"))
				Dom.addClass($("rowOption"), "hid-model");
		}
	},


	//
	//	Handles the btnSend Click event.
	//
	txtMessage_KeyUp : function(e, args)
	{
		var stat = EnsureMaxLength($("txtMessage"), 1800);

		$("lblRemaining").innerHTML = stat.Remaining;
	},


	//
	//
	//
	txtModel_Focus : function(e, args)
	{
		Event.preventDefault(e);
		
		var sender = Event.getTarget(e);
		
		if(sender.value == PageLewt.Texts.ModelEx)
			sender.value = "";
	},

	//*************************************************************************
	//
	//	Private API
	//
	//*************************************************************************

	//
	//	...
	//
	InitListeners : function()
	{
		Event.on("btnSend", "click", this.btnSend_Click, null, this);
		Event.on("txtMessage", "keyup", this.txtMessage_KeyUp, null, this);
		Event.on("cboSubject", "change", this.cboSubject_Change, null, this);
		Event.on("txtModel", "focus", this.txtModel_Focus, null, this);
	},


	//
	//	...
	//
	ValidateInputs : function()
	{
		var errorMsg = "";
		var emailRegex = /^[a-z0-9]+[a-z0-9\._-]*@[a-z0-9]+[a-z0-9\._-]*\.+[a-z]{2,4}$/i;


		if (!emailRegex.test($("txtEmail").value))
			errorMsg = PageLewt.Texts.InvalidEmailAddress;

		if ($("cboSubject").value == 0)
			errorMsg = PageLewt.Texts.MustChooseSubject;

		if ($("txtMessage").value == "")
			errorMsg = PageLewt.Texts.MustEnterMessage;



		return errorMsg;
	}

	
});

// Create the JS object defined above
ContactPage = new ContactPage();


//
//	This is the js implementation of the .asp page's Page Methods.
//	
//
PageMethods = function()
{
	Unyk.Web.PageMethodsProxy.call(this);
};

YAHOO.lang.extend(PageMethods, Unyk.Web.PageMethodsProxy, 
{
	// Not Used right now //
});

PageMethods = new PageMethods();
PageMethods.Path = "/Help/Contact.asp";
