﻿window.addEvent('domready', function() {
    var pass = $$('input[id$=vPassword]');
   if ( pass && pass.length > 0 ) pass[0].addEvent('keypress', Login.bind(this) ); 
});

function Login(e) {
   var e = new Event(e);
   if ( e.code==13 && typeof( CommitLogin ) == 'function' ) {
        CommitLogin();
        return false;
   }
}

var RecoverPassword = {
    Show: function(type) {
        // type: 1 =seekers; 2 = employers;
        this.Type = type;

        var e = '';
        switch (type) {
            case 1: e = $$('input:text[id$=vEmail]')[0].value;
                break;
            case 2: e = $$('input:text[id$=vEmail]')[0].value;
                break;
        }

        myAlert.prompt(EmailRecoveryInsertEmail, e, { textBoxBtnOk: btnRecover, textBoxBtnCancel: btnCancel, onComplete: function(returnvalue) {
            if (!returnvalue)
                return;

            returnvalue = Trim(returnvalue);
            if (!isValidEmail(returnvalue)) {
                myAlert.error(EmailMustBeVaild);
                return;
            }

            RecoverPassword.Email = returnvalue;
            RecoverPassword.Send();
        }
        });
    },
    Send: function() {

        var jsonRequest = new Request.JSON({ url: "../Handlers/RecoverPassword.ashx", onComplete: function(RecoveryDetails) {
            if (RecoveryDetails != null) {
                if (RecoveryDetails.Status)
                    myAlert.info(EmailSentSuccess.replace('[email]', RecoverPassword.Email));
                else
                    myAlert.alert(EmailDoesntExists);
            }
            else
                myAlert.error(errorOccured);
        }
        }).post({ 'Email': RecoverPassword.Email, 'Type': RecoverPassword.Type });
    }
}

function isValidEmail( strEmail )
{
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return ( filter.test( strEmail ) )
}