$(document).ready(function(){
  $(".validation_err_name_img").hide();
  $(".validation_err_educ_img").hide();
  $("#tester_reg").dialog({
  	autoOpen: false,
    modal: true,
    width:350,
    resizable: false,
    draggable: false,
    buttons: {
      "Atcelt": function() {
        $(this).dialog("close");
      },
      "Turpināt": function() {
          var t_name = $('#tester_name').val();
          var t_educ = $('#tester_education').val();
          var nameRegex = /^[a-z\_\ ]{1,28}$/i;
          var educRegec = /^[0-9]{1,4}$/i;
          var err = false;
          if(!nameRegex.test(t_name))
          {
            $(".validation_err_name_img").show();
            err = true;
          }
          else $(".validation_err_name_img").hide();
          if(!educRegec.test(t_educ))
          {
            $(".validation_err_educ_img").show();
            err = true;
          }
          else $(".validation_err_educ_img").hide();
          if(!err)
          {
            $(".content").html('<table style="font-size:11px;" border=0 cellspacing=0 cellpadding=0><tr><td><img width=18 src="images/ajax-loader.gif" /></td><td style="padding-bottom:4px;">&nbsp;Notiek ielāde...</td></tr></table>');
            $(this).dialog("close");
            $.get("async.php",{page: 'start_test', tester_name: $('#tester_name').val(), tester_live: $('#tester_live').val(), tester_occupation: $('#tester_occupation').val(), tester_education: $('#tester_education').val()}, function(data){
                if(data.search("registred") == '-1')
                {
                    $(this).dialog("close");
                }
                else
                {
                    $.get("phpScripts/tabs.php", function(data){
                      $(".content").html(data);
                    });
                }
            });
          }
      }
    }
  });

  $(".start_testing").click(function(){
        $('#tester_name').attr("value","");
        $('#tester_education').attr("value","");
        $(".validation_err_name_img").hide();
        $(".validation_err_educ_img").hide();
        $("#tester_reg").dialog("open");
  });

  });