/**
 * Copyright Estudio Nemo S.R.L
 * @author Equipo Desarrollo MPH
 */

(function(){

	loadScripts(new Array(), function() {

		var validationOptions = {

			rules : [
			   "required,PRICESURFER_USER_EMAIL," + $.i18n._("MESSAGE_REQUIRED_USERNAME"),
			   "required,PRICESURFER_PASSWORD," + $.i18n._("MESSAGE_REQUIRED_PASSWORD") /* ,
			   "valid_email,PRICESURFER_USER_EMAIL," + $.i18n._("MESSAGE_INVALID_EMAIL") */
			],

			displayType: 'alert-all',
			errorFieldClass: 'error',
			errorTextIntro : $.i18n._("MESSAGE_INVALID_FORM")
		}

		$("#login-form").RSV( validationOptions ).removeAttr("onsubmit");

		$("#PRICESURFER_USER_EMAIL").focus();

		$('#PRICESURFER_USER_EMAIL, #PRICESURFER_PASSWORD').keydown(function(e){

			var
				$target = $(e.target),
				pressedOnUsername = ( $target.attr("id") == "PRICESURFER_USER_EMAIL"),
				pressedOnPassword = ( $target.attr("id") == "PRICESURFER_PASSWORD");

	        if ( e.keyCode == 13 && pressedOnPassword ) {
	            $(this).parents('form').submit();
	            return false;
	        }
	    });

		// -- Chequeo de errores
		if ( $("#error").find("*").length > 0 ) {
			$("#error").show();
		};

		// --
		$("#btn-login-register").click(function(e){

			var
				$this = $(this),
				url = $this.attr("href"),
				options = { content : "about:blank", width : 800, height: 600, title : $.i18n._("ACCOUNT_CREATION_REQUEST"), content : url};

			$.mph.openDialog( options );

			return false;
		});

		$("#btn-login-remember").click(function(e){

			var
				$this = $(this),
				url = $this.attr("href"),
				options = { content : "about:blank", width : 800, height: 600, title : $.i18n._("PASSWORD_RESET_REQUEST"), content : url };

			$.mph.openDialog( options );

			return false;
		});

	})
})();
