function CalendarActivate(){
	var datesYear = new Array();
	var datesMonth = new Array();
		for (year in eventsObj) {
			for(month in eventsObj[year]) {
				datesYear.push(month + '-' + year);
			}
		}
	var startDate = '1-' + datesYear.shift();
	var endDate = '31-' + datesYear.pop();
	
	//alert('1');
	if (dateInNew == null){
		$(".jcalendar").jcalendar({startDate:startDate, endDate:endDate});
	}else{
		$(".jcalendar").jcalendar({startDate:startDate, endDate:endDate, dateIn:dateInNew});
	}
}


$(document).ready(function() {
	CalendarActivate();
});


function MainCalendar(){
	//alert($("#cities").val());
	
	$.ajax({
	   type: "GET",
	   url: "/schedule/",
	   data: "city="+$("#cities").val()+"&main_calendar=1",
	   success: function(msg){
			$("#test_cont").html(msg);
			CalendarActivate();
	   }
	 });	
}

function GoToTraining(path){
	path+='/city'+$("#cities").val()+'/';
	document.location=path;
}

function EventGo(d, w){
	$(".jsp").removeClass("jsp");
	$(w).parent().addClass("jsp");
	$(".jsp2").css({ backgroundColor:"transparent", color:"#000" });
	//if ($(w).parent.hasClass != "jsp") $(".today > a").css({ backgroundColor:"transparent", color:"#000" });

	$.ajax({
	   type: "GET",
	   url: d,
	   data: "sched=1",
	   success: function(msg){
		   //alert(msg);
		    $("#test_cont").html(msg);
	   }
	 });
}


function openPopup(url,name,width,height) {
	var popupWin = top[name];
	
		popupWin = window.open(url, name, 'width=' + width + ',height=' + height + ',status=yes,menubar=no,resizable=no,scrollbars=no, left=' + String((screen.width-width)/2) + ',top=' + String((screen.height-height)/2));
	
	popupWin.focus();
}

function closePopup(url) {
	if (opener) {
		if (opener.closed) window.open(url, "");
		self.close();
		return false;
	}
	return true;
}

$(document).ready(
	function(){
		$(".enter").click(
			function(){
				if ($("#tabform").css("display") == "block"){
					$("#tabform").css("display", "none");
					return false;
				}
				$("#tabform").css("display", "block");
				return false;
			}
		);

		$(".fclose").click(
			function(){
				$("#tabform").css("display", "none");
				return false;
			}
		);
	}
);

function Participate(tid, uid){
	if (uid==0){
		alert('Запись на тренинги доступна только зарегистрированным пользователям');
		return false;
	}
	$.ajax({
	   type: "GET",
	   url: '/',
	   data: "ajax=1&participate="+tid+"&uid="+uid,
	   success: function(msg){
		   alert('Ваша заявка отправлена!');
	   }
	 });
}

function Participate2(tid){
	$.ajax({
	   type: "GET",
	   url: '/',
	   data: "ajax=1&participate="+tid+"&uid=0&name="+$("#id_name").val()+"&descr="+$("#id_descr").val(),
	   success: function(msg){
		   alert('Ваша заявка отправлена!');
		   $('#connect').toggle();
	   }
	 });
}


function UpdateTotalPrice(gid, o){
	var cnt = $(o).val();
	$.ajax({
	   type: "GET",
	   url: '/',
	   data: "ajax=1&update_total_price="+gid+"&cnt="+cnt,
	   success: function(msg){
		   //alert(msg);
		   $("#total_price").html(msg);
	   }
	 });
}

function RemoveFromBasket(gid, o){
	$.ajax({
	   type: "GET",
	   url: '/',
	   data: "ajax=1&remove_from_basket="+gid,
	   success: function(msg){
		   //alert(msg);
		   $("#total_price").html(msg);
		   $(o).parent().parent().remove();
	   }
	 });
}
