function reload(){   
  var rndval = new Date().getTime();
  document.getElementById('capcha').innerHTML = '<img src="/kcaptcha/kcaptcha_view.php?f='+rndval+'" width="120" height="50" border="0" alt="" /><br/><a href="javascript:void();" onclick="reload(); return false;" class="reloadcapcha">Обновить картинку</a>';
}
$(document).ready(function(){
  $("form").keypress(function (e) {
    var thisID = $(this).attr("id");
    if ((e.which == 17)&&(e.which == 13)||(e.which == 13)) {
      $(this).submit();
    }
  });

  
  $("#regist").click(function(event){ event.preventDefault();});
  $("#regist").click(function(){
    var errorVal = "поле обязательно для заполнения";
    var starArr = new Array;
    var starLenght;
    var k = 0;
    star = $(".inhold .star");
    starLenght = $(star).length;
    for (i=0; i<starLenght; i++ ){
      idInput = $(star[i]).parent().attr("for");
      valInput = $("#"+idInput).val();
      if ((valInput=="")||(valInput==errorVal)){
        k++;
        $("#"+idInput).addClass("star2").val(errorVal);
      }
    }

    if (k==0){    
      $('#form').submit();
    }else{
      formInpuVal();
    }
  });

  function formInpuVal(){
    var asInitVals = new Array();
    $("#form input").each( function (i) {
        asInitVals[i] = this.value;
        
      });
    
    $("#form input").focus( function () {
        if ( this.className == "star2" ){
          this.className = "";
          this.value = "";
        }
      });
    $("#form input").blur( function (i) {
          thisValue = str = jQuery.trim(this.value);
        if (thisValue == "" ){
          this.className = "star2";
          this.value = asInitVals[$("#form input").index(this)];
        }
      });
  }
  
  $("#subscribe").click(function(event){ event.preventDefault();});
  $('#subscribe').click(function(){
     var message = '';
     var email = $('#subscribe_email').val();
     if(email==''){
       message = 'Поле пустое';
     }
     if (!/^([\w-~_]+\.)*[\w-~_]+@([\w-_]+\.){1,3}\w{2,4}$/.test(email)) {
       message = 'Поле Email имеет неверный формат';
     }
     if(message!=''){
       $('.err').text(message);
     }
     else{
       $.post('/index/subscribe/',{email: email},function(message){
         $('.err').css("color","blue");
         $('.err').text(message);
       });
     }
     
     $('#subscribe_email').val('');
  });  
})

