$(document).ready(function() {  
 
     $(".inner").css('background-color','#f6faf2');
 
    
    $("#reg_form").validate({

   rules: {

     // поле name - обязательное

     

     // для поля email

       email: {

       // заполнение обязательно

        required: true,

       // значение д.б. корректным

        email: true
      },
      name: {
      	required: true,
      	rangelength: [2, 24]
      },      
      pass: {
      	required: true,
      	rangelength: [6, 24]
      },
      passagain: {
      	required: true,
		rangelength: [6, 24],
		equalTo: "#pass"
       
        
     },
     site_rules: {
        required: true
     },
     name: {
        required: true,
        rangelength: [2, 15]
     }
     ,
     surname: {
        required: true,
        rangelength: [2, 15]
     }




   
    },
   
    messages: {

        email: {
    	    required: "Нужно указать email адрес",
    	    email: "Данное поле заполнено некорректно!"
    	      },
        name: {
    	    required: "Нужно указать свое имя",
    	    rangelength: "Данное поле заполнено некорректно!"
    	      },
        pass: {
          	required: "Укажите пароль!",
    		rangelength: "Пароль - от 6 до 24 символов"
          },
        passagain: {
          	required: "Подтвердите пароль!",
    		rangelength: "Пароль - от 6 до 24 символов",
    		equalTo: "Пароли не совпадают"
          },
      site_rules: {
        required: "Это поле обязательно!"
      },
      surname: {
        required: "Нужно указать свою фамилию",
        rangelength: "Данное поле заполнено некорректно!"
     }
   
   

    }
    
    
    });

    
    
     
  

    
    
    
    $('.tooltips').tooltip({
    
    	position: "center right",
    	
    	offset: [-2, 10],
    	
    	effect: "fade",
    	
    	opacity: 0.7
    
    });
    

        

    

        

    

    
    $('#cat_id').change(function () {
    
            var cat_id = $(this).val();
    
            if (cat_id == '0') {
    
                $('#subcat_id').html('');
    
                $('#subcat_id').attr('disabled', true);
    
                return(false);
    
            }
    
            $('#subcat_id').attr('disabled', true);
    
            $('#subcat_id').html('<option>загрузка...</option>');
    
     
            var url = '/ajax/category.php';
    
     
            $.get(
    
                url,
    
                "cat_id=" + cat_id,
    
                function (result) {
    
    
    
                    if (result.type == 'error') {
    
                        alert('error');
    
                        return(false);
    
                    }
    
                    else {
    
                        var options = '';
    
                        $(result.subcats).each(function() {
    
                            options += '<option value="' + $(this).attr('id') + '">' + $(this).attr('title') + '</option>';
    
                        });
    
                        $('#subcat_id').html(options);
    
                        $('#subcat_id').attr('disabled', false);
    
                    }
    
                },
    
                "json"
    
            );
    
        });
    
    
  

  $('#country_id').change(function () {
    
            var country_id = $(this).val();
    
    
            if (country_id == '0') {
    
                $('#city_id').html('');
    
                $('#city_id').attr('disabled', true);
    
                return(false);
    
            }
    
    
            $('#city_id').attr('disabled', true);
    
            $('#city_id').html('<option>загрузка...</option>');
    
            var url = '/ajax/town.php';
    
            $.get(
    
                url,
    
                "country_id=" + country_id,
    
                function (result) {
    
    
                    if (result.type == 'error') {
    
                        alert('error');
    
                        return(false);
    
                    }
    
                    else {
    
                        var options = '';
    
                        $(result.subcats).each(function() {
    
                            options += '<option value="' + $(this).attr('id') + '">' + $(this).attr('title') + '</option>';
    
                        });
    
                        $('#city_id').html(options);
    
                        $('#city_id').attr('disabled', false);
    
                    }
    
                },
    
                "json"
    
            );
    
        });
  
  


  $('#reg-inv').click(function () {$("#reg-display").slideUp("fast");});
  $('#reg-cre').click(function () {$("#reg-display").slideUp("fast");});
  $('#reg-sta').click(function () {$("#reg-display").slideDown("fast");});
  $("input[name='type']").click(
    function () {

       if ($(this).val() == "investor" || $(this).val() == "creditor") {
        $(".startup-cat-tr").hide();
        $(".investor-cat-tr").show();
        
       }
       else {
        $(".startup-cat-tr").show();
        $(".investor-cat-tr").hide();
       } 
        
    }
  
  );  
  
});




