$(document).ready(function(){


  //$("#ApplicationTime").datepicker();
  var cur_load = 0;
  
  $.datepicker.setDefaults($.datepicker.regional['ru']);
  $('#ApplicationTime').datepicker();
  $('#ActionTime').datepicker();

  
  if($('#colorpicker').attr('id')) {    
    $('#colorpicker').farbtastic('#TagColor');
  }

  $('#ApplicationTag').selectbox();


  $(".row div").hover(
    function() {
      $(this).css('background', 'url(/img/bgday.png)');      
    },
    function() {
      if($(this).attr('class') == 'curdayclass')
        $(this).css('background', 'url(/img/curbgday.png)');
      else
        $(this).css('background', 'none');
    }
  );

  $(".row div").click(
    function() {
      if($(this).attr('id') != "") {
        window.location.href="/pages/all_actions/"+$(this).attr('id');
      }      
    }
  );
    
//      if ($("#dayActions").is(":hidden")) {
//        cur_load = "";
//      }
//
//      if (!$("#dayActions").is(":hidden")) {
//        $("#dayActions").slideUp('slow');
//      }
//
//      if(cur_load != $(this).attr('id')) {
//        cur_load = $(this).attr('id');
//        $("#dayActions").load("/actions/day_actions/"+$(this).attr('id'),
//          function(data) {
//            if(data != '<div id="day_actions"></div>')
//              $("#dayActions").slideDown('slow')
//          }
//        );
//      }


  $("#calPrev").click(function() {
    $(this).parent().children('div').each(function(){
      if($(this).attr('class') == "calendar") {
        
       if($(this).prev().attr('class') == 'calendar hide') {
         $(this).attr('class', 'calendar hide');
         $(this).prev().attr('class', 'calendar');
       }
      }
    })
  });

  $("#calNext").click(function() {
    var i = 0;    
    $(this).parent().children('div').each(function(){
      if($(this).attr('class') == "calendar" && i == 0) {
       if($(this).next().attr('class') == 'calendar hide') {
         $(this).attr('class', 'calendar hide');
         $(this).next().attr('class', 'calendar');
         i = 1;
       }
      }
    })
  });

  $(".day_action").live('mouseover', function(){
    $(this).attr('id', 'sel_action')
  });

  $(".day_action").live('mouseout', function(){
    $(this).attr('id', '')
  });

  $(".inputText").click(function() {
    $(this).val('');
  });


  $(".inputText:odd").parent().css('display','none');
  $(".inputText:odd").val('  ');


  $("#ApplicationAddForm").submit(function() {
    var ret = 0;

    $(".inputText").each(function(){
      if($(this).val() == "") {        
        ret = 1;
      }
    });
    
    if(ret == 0) {
      return true;
    } else {
      alert('Чтобы сообщение успешно отправилось, необходимо заполнить все поля');
      return false;
    }
  });

  $("#PageContactsForm").submit(function() {
    var ret = 0;

    $(".inputText").each(function(){
      if($(this).val() == "") {
        ret = 1;
      }
    });

    if(ret == 0) {
      return true;
    } else {
      alert('Чтобы сообщение успешно отправилось, необходимо заполнить все поля');
      return false;
    }
  });

  $("#datapicer").datepicker({    
    onSelect: function(dateText) { window.location.href = "/admin/pages/action_text/"+dateText; }
  });

		$('textarea').tinymce({
			// Location of TinyMCE script
			script_url : '/js/tiny_mce/tiny_mce.js',

			// General options
			theme : "advanced",
			plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "bullist,numlist,|,link,unlink,|,insertdate,inserttime,preview,|,forecolor,backcolor",
			theme_advanced_buttons3 : "",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,

			// Example content CSS (should be your site CSS)
			content_css : "css/content.css",

			// Drop lists for link/image/media/template dialogs
			template_external_list_url : "lists/template_list.js",
			external_link_list_url : "lists/link_list.js",
			external_image_list_url : "lists/image_list.js",
			media_external_list_url : "lists/media_list.js",

			// Replace values for the template plugin
			template_replace_values : {
				username : "Some User",
				staffid : "991234"
			}
		});

});

