 document.onkeydown = NavigateThrough;
 function NavigateThrough (event)
 {
    if (!document.getElementById) return;
    if (window.event) event = window.event;
    if (event.ctrlKey)
    {
       var link = null;
       var href = null;
       switch (event.keyCode ? event.keyCode : event.which ? event.which : null)
       {
          case 0x25:
             link = $(".prev").attr('id');
             break;
          case 0x27:
             link = $(".next").attr('id');
             break;     
       }
       if (link) 
          document.location = link;
    }
 }

 
 $(document).ready(function(){

    $("#slider").easySlider({
       continuous: true 
    });
				
    var flg_show=true;				
    //Code for example B
    $("a.buttonBslidedown").click(function(){
       if (flg_show) {
          $("div.allphones").find("div#additionalphones:hidden").slideDown("slow");
          flg_show=false;
       }
       else{
          $("div.allphones").find("div#additionalphones:visible").slideUp("slow");
          flg_show=true;						
       } 
       return false;
    }); 		  					  

    $("a[rel='lightbox']").colorbox();
    $("a.gallery").colorbox();

    $('.AjNews').live('click',function(){
       $('.overlay2').removeClass('hidden');
       $("#aj_calendar").load('/_ajax/calendar.php', {url: this.id}, function(){
          $('.overlay2').addClass('hidden');
       });
    });                                   

    $('.AjPress').live('click',function(){
       $('.overlay2').removeClass('hidden');
       $("#aj_calendar").load('/_ajax/PressCalendar.php', {url: this.id}, function(){
          $('.overlay2').addClass('hidden');
       });
    });                                   

    $('.AjRepertoire').live('click',function(){
       $('.overlay2').removeClass('hidden');
       $("#aj_calendar").load('/_ajax/RepertoireCalendar.php', {url: this.id}, function(){
          $('.overlay2').addClass('hidden');
       });
    });                                   


  $.validator.addMethod('validName', function (value) {
      var result = true;
      var iChars = "!@#$%^&*()+=[]\\\';,./{}|\":<>?";
      for (var i = 0; i < value.length; i++) {
          if (iChars.indexOf(value.charAt(i)) != -1) {
              return false;
          }
      }
      return result;
  }, '');

  var options = { 
    target: "#output",
    url: '/_ajax/online.php',
    timeout: 5000, 
    beforeSubmit: function() {
	$('.overlay').removeClass('hidden');
    },
    success: function() {
        $('#aj_image').load('/_ajax/captcha.php',{},function(){$('.overlay').addClass('hidden');});        
    }
  };

  $("#form_name").validate({
     submitHandler: function(form) {
  	    $(form).ajaxSubmit(options);
    },  
    focusInvalid: false,
    focusCleanup: true,
    rules: {
      name: {
         required: true,
         validName: true,
         minlength: 4,
         maxlength: 25
      },
      captcha_word: {
         required: true,
      },        
      email: {
           required: true,
           email: true
      },
    },
    messages: {
      name: {
        required: "Введите имя контактного лица",
        validName: "Символы !@#$%^&*()+=[]\\\';,./{}|\":<>? запрещены.",
        minlength: "Минимум 4 символа ",
        maxlength: "Максимум 25 символов ",
      },
      captcha_word: {
        required: "Введите символы на картинке",
      },
      email: {
        required: "Введите адрес ящика",
        email: "Введите корректный адрес"
      },
    },
    errorPlacement: function(error, element) {
        error.appendTo( element.parent().parent().find("label[for='" + element.attr("name") + "']").find("span") );
    },

  });


 });

 function voicePanel() {

  //форма голосования
  var voiceOptions = { 
    target: "#pollPanel",
    url: '/_ajax/voice.php',
    timeout: 5000, 
    beforeSubmit: function() {
	$('.voicePanel2').removeClass('hidden');
    },
    success: function() {
        $('.voicePanel2').addClass('hidden');
    }
  };

  $("#voiceForm").validate({
     submitHandler: function(form) {
  	    $(form).ajaxSubmit(voiceOptions);
    },  
    focusInvalid: false,
    focusCleanup: true,
    rules: {
      gotheatre: {
         required: true,
      },
    },
    messages: {
      gotheatre: {
        required: "Выберите вариант ответа",
      },
    },
    errorPlacement: function(error, element) {
        error.appendTo( element.parent().parent().parent().find("#voiceError"));
    }
  });

 }


 function viewVoice(id) {
    $('.voiceAll'+id).removeClass('hidden');
    $('#poll'+id).load('/_ajax/voiceAll.php', {section: id}, function(){
       $('.voiceAll'+id).addClass('hidden');
    });
 }

 function viewVoicePanel(id) {
    $('.voicePanel2').removeClass('hidden');
    $('#pollPanel').load('/_ajax/voiceAllPanel.php', {section: id}, function(){
       $('.voicePanel2').addClass('hidden');
    });
 }

 function addVoicePanel(id) {
    $('.voicePanel2').removeClass('hidden');
    $('#pollPanel').load('/_ajax/voiceAddPanel.php', {section: id}, function(){
       $('.voicePanel2').addClass('hidden');
    });
 }

 function addVoice(id) {
    $('.voiceAll'+id).removeClass('hidden');
    $('#poll'+id).load('/_ajax/voiceAdd.php', {section: id}, function(){
       $('.voiceAll'+id).addClass('hidden');
    });
 }

 function voiceList(id) { 
  //форма голосования
  var voiceOptions2 = { 
    target: "#poll"+id,
    url: '/_ajax/voiceAll.php',
    timeout: 5000, 
    beforeSubmit: function() {
	$('.voiceAll'+id).removeClass('hidden');
    },
    success: function() {
        $('.voiceAll'+id).addClass('hidden');
    }
  };

  $("#form"+id).validate({
     submitHandler: function(form) {
  	    $(form).ajaxSubmit(voiceOptions2);
    },  
    focusInvalid: false,
    focusCleanup: true,
    rules: {
      gotheatre: {
         required: true,
      },
    },
    messages: {
      gotheatre: {
        required: "Выберите вариант ответа",
      },
    },
    errorPlacement: function(error, element) {
        error.appendTo( element.parent().parent().find("#voiceError"+id));
    }, 
  }); 
 }
