$(document).ready(function()
{
	/* 物品图片播放器 */
	$('#body .goods_image_box .goods_image a').click(function()
	{
		$('#body .goods_image_box .image_box .preview a img').attr('src',_web_attachments_path+'album/'+$(this).attr('previewImage'));
		$('#body .goods_image_box .image_box .preview a').attr('href',_web_attachments_path+'album/'+$(this).attr('srcImage'))
	});
	
	/* 检查评论 */
	$('#s_comment').blur(function()
	{
		if($(this).val().length<=0)
		{
			$('#s_comment_msg').attr('class','failed');
			$('#s_comment_msg').html('请填写评论');
			return false;
		}
		else if($(this).val().length>500)
		{
			$('#s_comment_msg').attr('class','failed');
			$('#s_comment_msg').html('最多500个字');
			return false;
		}
		else
		{
			$('#s_comment_msg').attr('class','succeed');
			$('#s_comment_msg').html('&nbsp;&nbsp;&nbsp;');
		}
	});
	
	/* 发表评论 */
	$('#goods_comment_form').submit(function()
	{
		if($('#s_comment').val().length<=0)
		{
			return false;
		}
		
		var options={
	
			type: "POST",
					
			url: _web_path+"space/postGoodsComment/"+$('#s_space_member_id').val(),
					
			dataType: 'json',
					
			timeout: 0,
	
			beforeSend: function()
			{
				$('#s_submit_msg').empty();
				$.blockUI('<img src="'+_web_image_path+'busy.gif" />',{border: '0', padding: '10px', width: '0px'});
			},
				
			complete: function()
			{
				$.unblockUI();
			},
				
			error: function(request, settings)
			{
				$('#s_submit_msg').attr('class','failed');
				$('#s_submit_msg').html(_ajaxError);
			},
					
			success: function(msg)
			{
				if(msg.status!=1)
				{
					$.unblockUI();
					
					$('#'+msg.component+'_msg').attr('class','failed');
					$('#'+msg.component+'_msg').html(msg.message);
					
				}
				else
				{
					self.location.reload();
				}
			}
		};
	
		$(this).ajaxSubmit(options);
			
		return false;
	});
	
	/* 检查留言标题 */
	$('#s_title').blur(function()
	{
		if($(this).val().length<=0)
		{
			$('#s_title_msg').attr('class','failed');
			$('#s_title_msg').html('请填写主题');
			return false;
		}
		else if($(this).val().length>100)
		{
			$('#s_title_msg').attr('class','failed');
			$('#s_title_msg').html('最多100个字');
			return false;
		}
		else
		{
			$('#s_title_msg').attr('class','succeed');
			$('#s_title_msg').html('&nbsp;&nbsp;&nbsp;');
		}
	});
	
	/* 检查留言 */
	$('#s_message').blur(function()
	{
		if($(this).val().length<=0)
		{
			$('#s_message_msg').attr('class','failed');
			$('#s_message_msg').html('请填写正文');
			return false;
		}
		else if($(this).val().length>500)
		{
			$('#s_message_msg').attr('class','failed');
			$('#s_message_msg').html('最多500个字');
			return false;
		}
		else
		{
			$('#s_message_msg').attr('class','succeed');
			$('#s_message_msg').html('&nbsp;&nbsp;&nbsp;');
		}
	});
	
	/* 发表评论 */
	$('#send_message_form').submit(function()
	{
		if($('#s_message').val().length<=0)
		{
			return false;
		}
		
		var options={
	
			type: "POST",
					
			url: _web_path+"space/postSendMessage/"+$('#s_space_member_id').val(),
					
			dataType: 'json',
					
			timeout: 0,
	
			beforeSend: function()
			{
				$('#s_submit_msg').empty();
				$.blockUI('<img src="'+_web_image_path+'busy.gif" />',{border: '0', padding: '10px', width: '0px'});
			},
				
			complete: function()
			{
				$.unblockUI();
			},
				
			error: function(request, settings)
			{
				$('#s_submit_msg').attr('class','failed');
				$('#s_submit_msg').html(_ajaxError);
			},
					
			success: function(msg)
			{
				if(msg.status!=1)
				{
					$.unblockUI();
					
					$('#'+msg.component+'_msg').attr('class','failed');
					$('#'+msg.component+'_msg').html(msg.message);
					
				}
				else
				{
					self.location.href= _web_path+"space/sendMessageSucceed/"+$('#s_space_member_id').val()
				}
			}
		};
	
		$(this).ajaxSubmit(options);
			
		return false;
	});
});