﻿ jQuery.noConflict();
jQuery(document).ready(function($){

		var name = $("#name"),
			email = $("#email"),
			password = $("#password"),
			allFields = $([]).add(name).add(email).add(password),
			tips = $("#validateTips");

		function updateTips(t) {
			tips.text(t).effect("highlight",{},1500);
		}

		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("Длина  " + n + " должна быть "+min+" до "+max+".");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}

		$("#dialog").dialog({
			bgiframe: true,
			autoOpen: false,
			height: 250,
            width: 466,
			modal: true,
            resizable: false,
			buttons: {
				'Войти': function() {
	//				var bValid = true;
	//				allFields.removeClass('ui-state-error');

	//				bValid = bValid && checkLength(name,"username",3,16);
	//	  		bValid = bValid && checkLength(password,"password",5,16);

	//				bValid = bValid && checkRegexp(name,/^[a-z]([0-9a-z_])+$/i,"Логин должен содержать a-z, 0-9, пробел, начинаться с буквы.");
	//	  		bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Пароль должен содержать только : a-z 0-9");

				if (true) {

                        $("form:personcab").submit();
                        $(this).dialog('close');
					}



				},

				'Отмена': function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});



		$('#create-user').click(function() {
			$('#dialog').dialog('open');
		})

     $("h4.mitem").click( function() {
       var id = $(this).attr("id");
       var htmlStr = $("div#_"+id);
       htmlStr.slideToggle("fast");
      });

	});
