$(function() {	
	
	$('#big_map').hide();
		   
	$("#authImg").click(function() {
		$(this).attr("src", "{DOMAIN}{ROOT}?m=tool.valid&token=" + Math.round(Math.random() * 10000));
	});
	
	$("#cmsbtnv1").click(function(){
		var environmental = $('#environmental_point').attr('value');
		var service = $('#service_point').attr('value');
		var sound = $('#sound_point').attr('value');
		var title = $('#title').attr('value');
		var content = $('#content').attr('value');
		var code = $('#code').attr('value');
		var ktvId = $('#ktvId').attr('value');
		var data = $("#my_form").serialize();
		
		if(service == 0 || sound == 0 || environmental == 0)
		{
			alert('请对这家KTV进行评分');
			return;	
		}

		if(content == '')
		{
			alert('请输入定评内容！');	
			return;
		}

		
	/*	if(code == '')
		{
			alert('请输入验证码');
			return;
		}*/
		
		if(memberId == 0)
		{
			alert('请先登录再评论！');
			return;
		}
	
		$.ajax({
			type:'POST',
			url:root + '?m=ktv.addcomment&ktvId='+ktvId+'&environmental='+environmental+'&service='+service+'&sound='+sound+'&memberId='+memberId,
			data:data,
			success: function (data) {	

				if(data == '')
				{
					alert('评论成功');
					location.reload();
				}
				else
				{
					alert(data);
				}
			},
			cache: false
		});
		
	});
	
	var environmental_point = 0;
	$('.environmental').each(function() {
 		$(this).click(function(){
			var count = $(this).attr('sid');
			 environmental_point = 0;
		
			
			if( $(this).attr('src') ==  root + 'theme/simple/images/ktv/star2.gif')
			{
					$(this).attr('src' , root + 'theme/simple/images/ktv/star1.gif');
					environmental_point += 0.5;
					
					$('#environmental_point').attr('value' , environmental_point);
					
					return;
			}
			
		

			$('.environmental').attr('src' , root + 'theme/simple/images/ktv/star3.gif');
			
				environmental_point = 0;
			
			for(var i = 1;i<=count; i++)
			{
				if(i == count)
				{
					
					environmental_point += 0.5;
					$('#environmental_' + i).attr('src' , root + 'theme/simple/images/ktv/star2.gif');
				}else
				{
					environmental_point += 1;
					$('#environmental_' + i).attr('src' , root + 'theme/simple/images/ktv/star1.gif');	
				}
			}
			
			$('#environmental_point').attr('value' , environmental_point);
			
		});
	});
	
	var sound_point = 0;
	$('.sound').each(function() {
 		$(this).click(function(){
			
			var count = $(this).attr('sid');
			
			
			if( $(this).attr('src') ==  root + 'theme/simple/images/ktv/star2.gif')
			{
				sound_point += 0.5;
				$(this).attr('src' , root + 'theme/simple/images/ktv/star1.gif');	
				$('#sound_point').attr('value' , sound_point);
				return;
			}

			$('.sound').attr('src' , root + 'theme/simple/images/ktv/star3.gif');
			sound_point = 0;
			for(var i = 1;i<=count; i++)
			{
				if(i == count)
				{
					sound_point += 0.5;
					$('#sound_' + i).attr('src' , root + 'theme/simple/images/ktv/star2.gif');
				}else
				{
					sound_point += 1;
					$('#sound_' + i).attr('src' , root + 'theme/simple/images/ktv/star1.gif');	
				}
			}
			$('#sound_point').attr('value' , sound_point);
		});
	});
		
		
	var service_point = 0;	
	$('.service').each(function() {
								
 		$(this).click(function(){
			var count = $(this).attr('sid');
			
			if( $(this).attr('src') ==  root + 'theme/simple/images/ktv/star2.gif')
			{
					service_point += 0.5;
					$(this).attr('src' , root + 'theme/simple/images/ktv/star1.gif');	
					$('#service_point').attr('value' , service_point);
					return;
			}

			$('.service').attr('src' , root + 'theme/simple/images/ktv/star3.gif');
			
			service_point = 0;	
			for(var i = 1;i<=count; i++)
			{
				if(i == count)
				{
					service_point += 0.5;
					$('#service_' + i).attr('src' , root + 'theme/simple/images/ktv/star2.gif');
					
				}else
				{
					service_point += 1;
					$('#service_' + i).attr('src' , root + 'theme/simple/images/ktv/star1.gif');	
				}
			}
			
			$('#service_point').attr('value' , service_point);
		});
	});

	var page = 1;

	$('#comment_more').click(function(){
		page++;
		
		var ktvId = $('#ktvId').attr('value');
		
		$.post( root + '?m=ktv.getComment', {ktvId:ktvId , index:page , size:5}, function(data) {
		//	var ary = eval("(" + data + ")");	
		
		if(data == 1)
		{
			alert('已经全部加载完毕！');
			return;
		}
		
		var str = '';
			for(var a in data)
			{
				str += ' <dl><dt><p class="img"><img src="'+ root +data[a]['member_head'] + '"  width="48" height="48" onerror="this.src='+ root +'/upload/ktv/nopic.jpg"></p></dt><dd><div class="cmtstop"><div class="cmtscontent"><p class="spacing"></p><p class="p1">环境：<strong>'+ data[a]['environmental'] +'</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;服务：<strong>'+ data[a]['service'] +'</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;音效：<strong>'+ data[a]['sound'] +'</strong></p><p class="spacing5"></p><div class="desc"><span>"'+ data[a]['member_name'] +'"：</span>	"'+ data[a]['content'] +'"</div><p class="spacing5"></p></div></div><div class="cmtsfoot"></div></dd></dl><p class="spacing"></p>';
			}
		
		
		$('#cmtslist2').append(str);
			
		}, "json");
			
	})

});

var id_index = 0;
function img_change(id , src)
{


	if(id_index == id)
	{
		return;
	}


	id_index = id;
	
	var url = root + 'Compression.php?img=' + src + '&width=585&height=500';

	$('#big_img').attr('src' , url)
	$('.iimgt').fadeout(500);
	
	
	$('#phone_' + id).fadeIn(500);
}