$(document).ready(function() {
  var prop = document.getElementById("month_list");

  $(document).click(function() {
    $('#month_list').hide();
    $('#year_list').hide();
  });
  $('.vibor_month').click(function(event) {
    $('#year_list').hide();
    $('#month_list').toggle();
    if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;
  });
  $('#fast_search').click(function() {
    $(this).removeClass('search_act');
    $('#big_search').addClass('search_act');
    $('.search_cont').show();
    $('.search_cont2').hide();
  });
  $('#big_search').click(function() {
    $(this).removeClass('search_act');
    $('#fast_search').addClass('search_act');
    $('.search_cont').hide();
    $('.search_cont2').show();
  });

  $('.vibor_year').click(function(event) {
    $('#month_list').hide();
    $('#year_list').toggle();
    if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;
  });
  $('#year_list a').click(function() {
    var propDate = $(this).text();
    $('#year').text(propDate);

    var y = $(this).attr('rel');
    $("#vibor_year01").val(y);
    var m = $('#vibor_month01').val();
    $.ajax({
      url: "/search/calendar.php",
      data: {
        month: m,
        year: y
      },
      dataType: 'html',
      cache: false,
      success: function(text)
      {
        $("#calendar1").html(text);
      },
      beforeSend: function()
      {
        $("#calendar1").html("<div id='load_calendar'><img src='images/load_cal.gif' alt='' /></div>");
      }
    });
  });
	
});
function ocentrovka(offset_w) {
  if (typeof offset_w == "undefined")
    offset_w = 208;
  _width = window.innerWidth || document.documentElement.clientWidth;
  _width1 = $('body').innerWidth();
  _height = document.body.clientHeight;
  _height2 = window.innerHeight || document.documentElement.clientHeight;
  pos_width = ((_width1/2)-offset_w);
  pos_height = 250;
}

function add_friends_conf() {
  ocentrovka(208);
  $(".add_friends_cont2").css({
    'left':pos_width+"px",
    'top':pos_height+"px"
  });
  $(".add_friends_cont2").show();
  $("table.friends_list").remove();
}
/*function popUp() {
  $('.login').toggle();
  $('.authiriz').toggle();
  ocentrovka(150);
  $('.login').css({
    'width':_width1+"px",
    'height':_height+"px"
  });
  $('.authiriz').css({
    'width':_width1+"px",
    'height':_height+"px"
  });
  $('.auth').css({
    'left':pos_width+"px",
    'top':pos_height+"px"
  });

  if ($("#log").val())
    $("#pass").focus();
  else
    $("#log").focus();
}
$(window).resize(function() {
  ocentrovka(150);
  $('.authiriz').css({
    'width':_width1+"px",
    'height':_height+"px"
  });
  $('.login').css({
    'width':_width1+"px",
    'height':_height+"px"
  });
  $('.auth').css({
    'left':pos_width+"px",
    'top':pos_height+"px"
  });
});*/

window.onkeyup = function(event) {
  if (event.keyCode=="27")
  {
    $('.login').hide();
    $('.authiriz').hide();
  }
}


function ImageCountInc(id_im)
{
  $.ajax({
    url: "/Scripts/imagecounterinc.php",
    type: "POST",
    data: {
      id_im:id_im
    },
    dataType : 'html',
    cache : false,
    success: function(html){
    },
    beforeSend: function() {
    }
  });
  return true;
}
function my_calendar(url,months,rel) {
  var propText = months;
  $('#month').text(propText);

  var m = rel;
  $("#vibor_month01").val(m);
  var y = $('#vibor_year01').val();
  $.ajax({
    url: url,
    data: {
      month: m,
      year: y
    },
    dataType: 'html',
    cache: false,
    success: function(text)
    {
      $("#calendar1").html(text);
    },
    beforeSend: function()
    {
      $("#calendar1").html("<div id='load_calendar'><img src='/images/load_cal.gif' alt='' /></div>");
    }
  });
}
function show_mess_full(id) {
  $.ajax({
    url:"/Scripts/show_mess_full.php",
    type: "POST",
    data: {
      id:id
    },
    dataType: 'html',
    cache: false,
    success:function(messages) {
      ocentrovka(208);
      $("#send_mess").html(messages);
      $("#send_mess").css({
        'left':pos_width+"px",
        'top':pos_height+"px"
      });
      $("#send_mess").toggle();
    },
    beforeSend: function() {
    }
  });
}
function send_mess_ajax(uid, mid)
{               
  $.ajax({
    url: "/Scripts/message_form.php",
    type: "POST",
    data: {
      UID:uid,
      MID:mid
    },
    dataType : 'html',
    cache : false,
    success: function(html)
    {
      ocentrovka(208);
      $("#send_mess").html(html);
      $("#send_mess").css({
        'left':pos_width+"px",
        'top':pos_height+"px"
      });
      $("#send_mess").toggle();
    },
    beforeSend: function() {
    }
  });
}
function send_mess2_ajax() {
  ocentrovka(208);
  $("#send_mess2_ajax").css({
    'left':pos_width+"px",
    'top':pos_height+"px"
  });
  $("#send_mess2_ajax").toggle();
}

function confirmPos(id,offset){
 if (typeof offset == "undefined")
    offset_w = 150;
  _width = window.innerWidth || document.documentElement.clientWidth;
  _height = window.innerHeight || document.documentElement.clientHeight;
  pos_width = ((_width/2)-208);
  pos_height = ((_height/2)-offset);
  $(".carcas").css('position','static');
  $('#'+id).css({
    'left':pos_width+"px",
    'top':pos_height+"px"
  });
  $(window).resize(function() {
    _width = window.innerWidth || document.documentElement.clientWidth;
    _height = window.innerHeight || document.documentElement.clientHeight;
    pos_width = ((_width/2)-208);
    pos_height = ((_height/2)-offset);
    $('#'+id).css({
      'left':pos_width+"px",
      'top':pos_height+"px"
    });
  });
}

function del_mess(link) {
	ocentrovka(200);
	$("#del_mess").css({'left':pos_width,'top':pos_height});
	$("#del_mess").toggle();
	$(".add_frinput tr td a[rel=ok_send]").attr("href",link);
}
$(window).resize(function() {
	 ocentrovka(200);
	$("#del_mess").css({'left':pos_width,'top':pos_height});
	$(".add_friends_cont").css({'left':pos_width,'top':pos_height});
	$("#add_friends_conf").css({'left':pos_width,'top':pos_height});
});	


var shown='';

function windowopen(url, w, h){
	if( shown=='' || shown.closed) {
		shown=window.open(url, 'windowopen', 'toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,resizable=0,width='+w+',height='+h+',top=150,left=150');
	} else {
		shown.close();
		shown=window.open(url, 'windowopen', 'toolbar=0,scrollbars=0,location=0,directories=0,status=0,menubar=0,resizable=0,width='+w+',height='+h);
	} 
}
