/*jslint browser: true, cap: false, glovar: true, passfail: false, undef: false, white: false */
/*global SONGHAY YAHOO */

SONGHAY.ui.Index.dataFormAlert = function(type,args)
{
    if(args.length){}else { return; }

    if(args.length > 1)
    {
        SONGHAY.ui.Index.dataFormAlertFocus = args[1];

        SONGHAY.ui.Dom.alert(SONGHAY.ui.Index.applicationTitle,
            args[0],SONGHAY.ui.Index.dataFormAlertProcedure);
    }
    else
    {
        SONGHAY.ui.Dom.alert(SONGHAY.ui.Index.applicationTitle,
            args[0],SONGHAY.ui.Index.dataFormAlertProcedure);
    }
};

SONGHAY.ui.Index.dataFormAlertFocus = null;

SONGHAY.ui.Index.dataFormAlertProcedure = function()
{
    if(this.hide) { this.hide(); }

    if(SONGHAY.ui.Index.dataFormAlertFocus && SONGHAY.ui.Index.dataFormAlertFocus.focus)
    {
        SONGHAY.ui.Index.dataFormAlertFocus.focus();
    }
};

SONGHAY.ui.dataFormPost = function(e)
{
    YAHOO.util.Event.stopEvent(e);

    var o = YAHOO.util.Event.getTarget(e);

    if(o && o.id && o.form) {} else { return false; }

    if(o.id=='MailerPageSubmitButton')
    {
        if(SONGHAY.ui.DataValidation.isNotComplete(o.form.realname,'Your Name')) { return false; }
        if(!SONGHAY.ui.DataValidation.isEmailValid(o.form.id,o.form.email)) { return false; }
        o.form.submit();
    }

    return true;
};

SONGHAY.ui.DataValidation.onMessage.subscribe(SONGHAY.ui.Index.dataFormAlert);