// JavaScript Document

$(document).ready(function () {
	$('.sl_d').toggle(
	function () {
		$('.otherCityBlInp02').show(); //.slideDown("fast");
	},
	function () {
		$('.otherCityBlInp02').hide(); //.slideUp("fast");
	});

	$('.sl_d02').toggle(
	function () {
		$('.searchBlInp02').slideDown("fast");
	},
	function () {
		$('.searchBlInp02').slideUp("fast");
	});

	$('.sl_d03').toggle(
	function () {
		$('.otherCityInput02').slideDown("fast");
	},
	function () {
		$('.otherCityInput02').slideUp("fast");
	});

	$('a.selectLi2').click(function () {
		var elemtext = $(this).text();
		$("#inpSearch input").val(elemtext);
		$(".searchBlInp01 span").text(elemtext);
		$('.searchBlInp02').slideUp("fast");
		return false;
	});

	$('a.selectLi3').click(function () {
		var elemtext = $(this).text();
		$(".otherCity span").text(elemtext);
		$('.otherCityInput02').slideUp("fast");
		return false;
	});

	$("a[rel='adr']").click(function () {
		var pageHeight = $("body").outerHeight();
		var pageWidth = $("body").outerWidth();
		var msgLeft = (pageWidth - 970) / 2 + 300;
		$("#mess_overlay").css("width", pageWidth + "px").css("height", pageHeight + "px").fadeIn("fast");
		$(".popUp").css("left", msgLeft + "px").fadeIn("fast").find(".popUpBl").fadeIn("normal");
		return false;
	});

	$("#mess_overlay").click(function () {
		$(this).fadeOut("fast");
		$(".popUp").fadeOut("fast").find(".popUpBl").fadeOut("fast");
	});

	$("a.close").click(function () {
		$("#mess_overlay").fadeOut("fast");
		$(".popUp").fadeOut("fast").find(".popUpBl").fadeOut("fast");
		return false;
	});

	if ($("#cal_cent").html() != null) {
		$("#cal_cent").datepicker({
			showOtherMonths: true,
			selectOtherMonths: true,
			selectWeek: true,
			closeOnSelect: true,
			highlightWeek: true,
			rangeSelect: true,
			gotoCurrent: true,
			defaultDate: getCurDate(),
			dateFormat: 'dd.mm.yy',
			onSelect: function (date, instance) { goToDate(date); },
			minDate: getMinDate(),
			maxDate: getMaxDate(),
			onChangeMonthYear: function (year, month, inst) { setTimeout(function () { initCalDots(year, month, inst); }, 200); },
			beforeShowDay: function (date) { return beforeShowDay(date); }
		});

		$("#cal_top02 a").click(function (e) {
			e.preventDefault();
			$("#calendar").show();
		});

		$("#cal_top01 a").click(function (e) {
			e.preventDefault();
			$("#calendar").hide();
		});

		initCalDots();
	}

	$(".grid tr").mouseover(function () {
		$(this).addClass("contBl01Cur");
	});

	$(".grid tr").mouseout(function () {
		$(this).removeClass("contBl01Cur");
	});

	$("input:submit").addClass("pointers");
	$("input:button").addClass("pointers");

	$("#addressBlock input").change(function () {
		$("#saveAsAdr").show();
	});
	$("#addressBlock select").change(function () {
		$("#saveAsAdr").show();
	});
	$("#customerBlock input").change(function () {
		$("#saveAsAdr").show();
	});

	$("input[name='isMain']:radio").click(function () {
		$("input[name='isMain']:radio:checked").attr("checked", "");
		$(this).attr("checked", "checked");
	});	
});
function onHref(n) {
	id = window.open("", "_blank");
	id.location.href = n;
}
