function QueryComment(SaleID)
{
	var json = new Array();
	$('#CommentHtml').html('<br /><center><img src="/img/loading.gif" align=absmiddle>&nbsp;Loading...</center><br /><br />');

	$.getJSON(
		AjaxURL+'Mode=SaleComment&Opt=List&SaleID='+SaleID+'&'+GetTime(),
		function(json)
		{
			try
			{
				var Html = ''; var oTpl = ''; var Tpl = $("#CommentTpl").html();
				$.each(json.Data, function(i,item){
					oTpl =  Tpl.replace('#NickName#'   , typeof(item.NickName)=='undefined' ? '' : (typeof(item.CommentURL)=='undefined' ? item.NickName : '<a href="'+item.CommentURL+'" target="_blank">'+item.NickName+'</a>'));
					oTpl = oTpl.replace('#Score#'      , typeof(item.Score)=='undefined'    ? '' : item.Score);
					oTpl = oTpl.replace('#Comment#'    , typeof(item.Comment)=='undefined'  ? '' : item.Comment);

					oTpl = oTpl.replace('#CommentID#'  , typeof(item.CommentID)=='undefined'  ? '' : item.CommentID);
					oTpl = oTpl.replace('#CommentID#'  , typeof(item.CommentID)=='undefined'  ? '' : item.CommentID);
					oTpl = oTpl.replace('#CommentID#'  , typeof(item.CommentID)=='undefined'  ? '' : item.CommentID);
					Html = Html+oTpl;
				});
				$('#CommentHtml').html(Html);
			}
			catch (e)
			{
				$('#CommentHtml').html('No Access');
			}
		}
	);
}

function SubComment()
{
	var Score = $('input[@name=Score][@checked]').val();

	if ($('#NickName').val()=='')
	{
		ShowTempTip("please write your name");
        $("#NickName").focus(); 		
		return false;
	}
	else if(typeof(Score)=='undefined' || Score<1)
	{
		ShowTempTip("please rate！");
        $("#Score").focus(); 		
		return false;
	}
	else if($('#Comment').val()=='')
	{
		ShowTempTip("please write a review");
        $("#Comment").focus(); 		
		return false;
	}
	var PostStr = "SiteID="+$("#SiteID").val()+"&SaleID="+$("#SaleID").val()+"&Score="+Score+"&NickName="+encodeURIComponent($("#NickName").val())+"&Comment="+encodeURIComponent($('#Comment').val());

	if(typeof($('#ValidateCode').val())!='undefined')
	{
		if($('#ValidateCode').val()!='')
		{
			ShowTempTip("please write Code Verification");
			$("#ValidateCode").focus(); 		
			return false;
		}
		else 
			PostStr = PostStr+"&ValidateCode="+$("#ValidateCode").val();
	}
	if($('#CommentURL').val()!='') PostStr = PostStr+"&CommentURL="+encodeURIComponent($("#CommentURL").val());

	$.ajax({
		type: "POST",
		url: AjaxURL+'Mode=SaleComment&Opt=Add',
		dataType: "html",
		data: PostStr,
		error: function(d) {alert(d.name);},
		beforeSend: function(){$("#Comment-Submit").attr('disabled','true');},
		complete:function(){$("#Comment-Submit").removeAttr("disabled");},
		success:
		function(data)
		{
			if(data==1)
			{
				$("#NickName").val('');
				$("#CommentURL").val('');
				$("#Comment").val('');

				QueryComment($("#SaleID").val());
				ShowTempTip("thanks for your review, we will post it ASAP");
			}
			else if(data=='-2')
				ShowTempTip("Code is invalid");
			else
				ShowTempTip("post false");
		}
	});
	return false;
}

$(function()
{
    QueryComment($("#SaleID").val());
});