/**
 * $Id: PreSignUp.js 244 2011-10-01 21:11:33Z manuel_jasso $
 */
/*global YUI */

YUI().use("caliso-cookie", "caliso-json", "node",
function (Y)
{
    var lang = Y.Lang;
    var caliso = Y.namespace("caliso");
    var formsText, theForm;

    function validateForm()
    {
        if (!caliso.cookieTest(formsText.DisabledCookiesAlert, false)) {
            return false;
        }

        var nodeUserID = theForm.one("input[name=UserID]");
        if (lang.trim(nodeUserID.get("value")) === "") {
            alert(formsText.EnterIDAlert);
            nodeUserID.focus();
            return false;
        }

        var nodePassword = theForm.one("input[name=Password]");
        if (lang.trim(nodePassword.get("value")) === "") {
            alert(formsText.EnterPasswordValueAlert);
            nodePassword.focus();
            return false;
        }

        var nodeInvoice = theForm.one("input[name=Invoice]");
        if (lang.trim(nodeInvoice.get("value")) === "") {
            alert(formsText.EnterInvoiceValueAlert);
            nodeInvoice.focus();
            return false;
        }
        return true;
    }

    Y.on("domready", function ()
    {
        theForm = Y.one("form[name=theForm]");
        formsText = caliso.getJSON("#formsText");

        theForm.one("#submitBtn").on("click", function (e) {
            if (validateForm(theForm)) {
                theForm.submit();
            }
        });

        caliso.cookieTest(formsText.DisabledCookiesAlert, true);
    });

});

