$(document).ready(function(){	
						   
	 $('.star').rating({
	  callback: function(value, link){

		modd = $(this).parent().attr('id');
		ctrl = $(this).attr('name');
		
	   if (value>0) { 
			
			$(this).rating('readOnly', true);
			$(this).parent().append('<a href="javascript:void();" class="dellink" onclick="cancelvote(\''+modd+'\');"><div class="rating-cancel"></div>Вы можете удалить свою оценку</a>');
			$('.'+modd).load('/index.php?go=Comment&in=rate', { modd : modd, value:value});
	   }
	   
	  }
	 });
	
});

function add_file(){ if ($("#files .item").length<5) $('#new_el').clone(true).attr("id", "").show().appendTo('#files'); 	}

function comm_check() { if (length($('#comm_text').val())>0) alert('Bingo!');	 }

function comment() { 
	
	$('div.postlink').toggle();
	$('div.postform').toggle();
	
}

function commkarma(plid, com_id, karma) { $('#rate'+com_id).load('/index.php?go=Comment&in=karma', { plid:plid, id:com_id, point:karma}); }

function checkballs() {
	
	var count=0; balls=0;
	for (i=0; i<=4; i=i+1) { if ($('#rating-select_'+i+' option:selected"').val()>0) {count++; balls+=eval($('#rating-select_'+i+' option:selected"').val()); }}
	if (count==5) { $('#submit').removeAttr('disabled'); }
	
}

function changeMainRateHint(a){
	
	var d=document.getElementById("MainRateHint");
	var c=d.getElementsByTagName("DIV");
	for(var b=0;b<c.length;b++){if(c[b].id=="rating-label_0"+a.value){c[b].style.display="block"}else{c[b].style.display="none"}}
}

function syncLabel(c){
	
	var b=document.getElementById(c);
	var a=b.parentNode.parentNode.getElementsByTagName("LABEL");
	document.getElementById(b.htmlFor).checked=true;for(i=0;i<a.length;i++){setClass(a[i],"inset",a[i]!=b)}

}

var ltIE7=false;
/*@cc_on @if (@_jscript_version < 5.7) ltIE7 = true @end @*/

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


	function initRates(){
		
		$('*[id ^= "rating-select_"]').each(function(){
													 
			var c=$(this);
			var e=c.attr("id").split("rating-select_")[1];
			c.css("display","none");
			var f=$("#rating-stars_"+e+"");
			f.css("display","block");
			var d=$("#rating-stars_"+e+" .b-rating__star").css("cursor","pointer");
			d.click(function(){
				rate=d.index(this)+1;
				c.find("option").removeAttr("selected");
				c.find("option[value = "+rate+"]").attr("selected","selected");
				$(this).prevAll().andSelf().addClass("b-rating__star-my");
				$(this).nextAll().removeClass("b-rating__star-my");
				checkballs();
				return false
			});
			
			d.hover(function(){
				$(this).prevAll().andSelf().addClass("b-rating__star-my-hover");
				$(this).nextAll().addClass("b-rating__star-hover")
				
			},function(){d.removeClass("b-rating__star-hover b-rating__star-my-hover")})});
		
		var a=$("#rating-stars_0 .b-rating__star");
		var b=$('span[id ^= "rating-label_0"]');
		a.click(function(){

			rate=a.index(this)+1;
			b.removeClass("visible");
			$("#rating-label_0"+rate+"").addClass("visible");
			return false
		});
		
		a.hover(function(){
			
			rate=a.index(this)+1;
			b.addClass("hover-hidden");
			$("#rating-label_0"+rate+"").removeClass("hover-hidden");
			$("#rating-label_0"+rate+"").addClass("hover-visible")},function(){
				
				$('span[id ^= "rating-label_0"]').removeClass("hover-hidden hover-visible")
				
			})
		}

function spaceclean(str) { return str.replace(/^\s+|\s+$/g, ''); }

function checkreg() {
	var mail = $('#mail').val();
	var email = $('#email').val();
	var password = $('#password').val();
	var emlcheck = $('#email_check').val();
	var password2 = $('#password2').val();
	var utown = $('select[@name=uname] option:selected').val();
	var fname = $('#fname').val();
	var lname = $('#lname').val();
	if ((email!=='') && (password!=='') && (utown>0) && (password==password2) && (emlcheck!=='') && (spaceclean(fname)!=='')) { $('#reg_but').show(); $('#reginfo').hide(); }
	else {  $('#reg_but').hide();  $('#reginfo').show(); 	}
}

function checkmail() { var email = $('#email').val(); $('#email_info').load("/index.php?go=Users&in=checkmail", { email:email } ); }

function cancelvote(what, ctrl) {
	
	$("div."+ctrl).load('/index.php?go=Comment&in=ratedel', { modd:ctrl});
	
}

function loadflt() {
	var cat = $('#cat_id').val();
	$('#flt').load('/index.php?go=Home&in=loadflt', { cat: cat} );
}

function vote_star(event_id, point, mod){ $("#vote"+event_id).load("/index.php?go=Star", { answer_id:event_id, point: point, mod:mod } ); }

function showgmap(){
	var a = $('#maplink');
	if (a.val() == 'Показать объекты на карте') { $('#maplink').val('Спрятать карту'); } 
	else {$('#maplink').val('Показать объекты на карте'); }
	$("#map").toggle("slide"); 
}

//function hmenuload(id) { $('#submenuplace').load('/index.php?go=Home&in=submenuload', { id: id} ); }

//function hmenuload(id) { $('#submenuplace').load('/index.php?go=Home&in=submenuload', { id: id} ); }

function loadex(id, cat) { $('#exnavi').load("/index.php?go=Report&in=loadex", { id:id, cat:cat } ); }
function load_exinfo(id, sid) { $('#exinfo').load("/index.php?go=Place&in=load_tabs", { id:id, sid:sid } ); }
function load_report(id) { $('#report').load("/index.php?go=Home&in=report",{id:id}, function(data) { $("#carusel").carousel({direction:"vertical"});});}

function load_rep(rep_id, img_id) { 

	$('#rep_area').html('<center><br><br><br><br><img src="/images/loading-thickbox.gif"></center>');
	$('#rep_area').load("/index.php?go=Report&in=load_info", { id:rep_id, imgidx:img_id } );
	document.href='/reports/'+rep_id+'/'+img_id+'.html';
	$(window).load(function () { $('#report_image').imgNotes(); });	
	//$('#report_image').imgNotes();
}

function load_repnav(rep_id, img_id, num) {
	$('#rep_area').html('<center><br><br><br><br><img src="/images/loading-thickbox.gif"></center>');
	$("div.scrollable").scrollable().click(num);
	$('#rep_area').load("/index.php?go=Report&in=load_info", { id:rep_id, imgidx:img_id } );	
	$(window).load(function () { $('#report_image').imgNotes(); });	
}

function preload(images) {
    if (typeof document.body == "undefined") return;
    try {
        var div = document.createElement("div");
        var s = div.style;
        s.position = "absolute";
        s.top = s.left = 0;
        s.visibility = "hidden";
        document.body.appendChild(div);
        div.innerHTML = "<img src=\"" + images.join("\" /><img src=\"") + "\" />";
    } catch(e) {
        // Error. Do nothing.
    }
}


function load_repnav_j(rep_id, img_id, num, img1, img2){
	preload([
		img1,
		img2
	]);
	$("div.scrollable").scrollable().click(num);
	$('#rep_area').load("/index.php?go=Report&in=load_info", { id:rep_id, imgidx:img_id } );	
	$(window).load(function () { $('#report_image').imgNotes(); });	
}

function load_rep_j(rep_id, img_id, img1, img2, img3) {
	preload([
		img1,
		'/images/reports/'+img2,
		'/images/reports/'+img3
	]);	
	$('#rep_area').load("/index.php?go=Report&in=load_info", { id:rep_id, imgidx:img_id } );
	document.href='/reports/'+rep_id+'/'+img_id+'.html';
	$(window).load(function () { $('#report_image').imgNotes(); });	
}

function delquest(id) { 

	if (confirm("Действительно хотите удалить этот вопрос?")) 	{ $('#que'+id).load("/index.php?go=Personal&in=delquest", { id:id} ); }
	
}

function event_in(evid) { $('#ev_in').load("/index.php?go=Event&in=event_in", { evid:evid} );  }

function load_limage(sec, image, id, town) { 

	$('div.events_onefirst').attr('class', 'events_one');
	$('#evnt'+id).attr('class', 'events_onefirst');
	$('#limage'+sec).html('<a href="/events/'+id+'.html"><img src="/images/events/'+town+'/'+image+'" border=0 class="events_images"></a>');
	
}

function load_calend(page, cat) { $("#calendar").load("/index.php?go=Home&in=calendar_load", { page:page, cat:cat} ); }

function add_place() { $("#adr0").show(); }
function vote(place_id, point){ $("#vote"+place_id).load("/index.php?go=Place&in=vote", { answer_id:place_id, point: point } ); }
function vote_report(report_id, point){ $("#vote"+report_id).load("/index.php?go=Report&in=vote", { answer_id:report_id, point: point } ); }
function vote_event(event_id, point){ $("#vote"+event_id).load("/index.php?go=Event&in=vote", { answer_id:event_id, point: point } ); }
function formcancel(id) { $('#adr'+id).hide(); }
function add_comment() { $('#comment_place').toggle(); }
function cancel_comment() { $('#comment_place').hide(); }
function question() { $('#question').toggle(); }
function questansw(id) { $('#questansw'+id).toggle(); }
function trailer() { $('#trailer').toggle(); }
function report(img) { $('#report').css('background-image', "url('"+img+"')"); }
function calend_reload(cat_id, week_id) { $("#calendar").load("/index.php?go=Home&in=calendar_load", { cat:cat_id, week:week_id} ); }
function show_form (id) { $('#adr'+id).show(); }
function favremove(good_id) { $("#member_catalog").load("/index.php?go=Members&in=favdelcat", { id:good_id }); }

function toggle_form (id) {
	var a = $('#button'+id);
	if (a.val()=='Показать') { $('#adr'+id).show(); $('#button'+id).val('Убрать'); } 
	else  { $('#adr'+id).hide(); $('#button'+id).val('Показать'); }
}

function formdel(id) { $('#status'+id).load('/index.php?go=Members&in=del_adr', {id:id}); $('#add_place'+id).empty(); }

function formsave (form_id) { var str = $("#adres"+form_id).serialize(); $.post("/index.php?go=Members&in=save_adr", str, function(data) { $("#adresses_place").html(data); }); }

function showmap(){
     var a = $('#showmap');
     if (a.val() == 'Показать карту') { $("#YMAP").show("slide"); $('#showmap').val('Спрятать карту'); } 
	 else { $("#YMAP").hide("slide"); $('#showmap').val('Показать карту'); }
}

function favorite(good_id){
     var a = $('#fav'+good_id);
     if (a.val() == 'Добавить в личный каталог') {
          $("#favoperation").load("/index.php?go=Place&in=favadd", { id:good_id });
          $("#fav"+good_id).val('Удалить из личного каталога');
     } else { 
          $("#favoperation").load("/index.php?go=Place&in=favdel", { id:good_id });
          $("#fav"+good_id).val('Добавить в личный каталог');
     }
}
