﻿function myHobby(){
    var myCookie=Cookie.read("display");
    if(myCookie=='hide'){
        document.getElementById('dsp-content').style.display="none";
        document.getElementById('label-dsp-btn').setAttribute('class','label-dsp-btn1');
        document.getElementById('label-dsp-btn').className='label-dsp-btn1';
    }
    else{
        document.getElementById('dsp-content').style.display="block";
        document.getElementById('label-dsp-btn').setAttribute('class','label-dsp-btn');
        document.getElementById('label-dsp-btn').className='label-dsp-btn';
    }
}
function display(){
    if(Cookie.read('display')!=null) Cookie.dispose('display');
    if(document.getElementById('dsp-content').style.display == "none"){
        document.getElementById('dsp-content').style.display="block";
        document.getElementById('label-dsp-btn').setAttribute('class','label-dsp-btn');
        document.getElementById('label-dsp-btn').className='label-dsp-btn';
        Cookie.write('display','show',{duration: 365,path: '/'});
    }
    else{
        document.getElementById('dsp-content').style.display="none";
        document.getElementById('label-dsp-btn').setAttribute('class','label-dsp-btn1');
        document.getElementById('label-dsp-btn').className='label-dsp-btn1';
        Cookie.write('display','hide',{duration: 365,path: '/'});
    }
}
function ContentValidate()
{
    if($('txtContent').value.length==0)
    {
        alert("您还没有填写评论内容！");
        return false;
    }
    var Value=$('txtContent').value;
    if(Value.length<10)
    {
        alert("您的评论小于了10个字！")
        return false;
    }
    if(Value.length>5000)
    {
        alert("您的评论大于了5000个字！");
        return false;
    }
   return true;
}
function getRadioValue(str){
    for (var i = 0; i < document.getElementsByName(str).length; i++){
	    if (document.getElementsByName(str)[i].checked){
		    return document.getElementsByName(str)[i].value;
	    }
    }
    return "";
}
function RadioValidate(sName,sTitle)
{
    var obj=document.getElementsByName(sName);
    for(var i=0;i<obj.length;i++)
    {
        if(obj[i].checked)
        {
            return true;
        }
    }
    alert(sTitle);
    return false;
}
function AvgValidate()
{
    var Value=document.getElementById("txtAvg").value;
    if(!IsNull('txtAvg'))
    {
        alert("您还没有填写人均！");
        return false;
    }
	Value=DBC2SBC(Value).trim();
	document.getElementById("txtAvg").value=Value;
    var Rex=/^[0-9]*$/;
    if(Rex.test(Value))
    {
        return true;
    }
    alert("人均请输入整数");
    return false;
}
function IsNull(sId)
{
    var Value=document.getElementById(sId).value;
    if(Value!="")
    {
        return true;
    }
    return false;
}
function ContentLength()
{
    var val=$('txtContent').value;
    var obj=document.getElementById("leftnum");
    obj.innerHTML=(5000-val.length);
}
function GetMore(cid){
    PostData='cid='+cid+'&t='+Math.random();
    new AjaxReq({
        url: "/adentity/GetMore.aspx",
        method: 'get',
        callType: 'html',
        data: PostData,
        onSuccess: function(data){
            $('cc_'+cid).set('html',this.ajax.response.html);
        }
    }).send();
}
function PostComment(){
    if(!IsNull('adentityId')) {
        alert("无相关餐厅！");
        return false;    
    }
    if(!RadioValidate('rblAppraise','您还没有对餐厅做评价！')){
        return false;
    }
    if(!IsNull('taste')) {
        alert("您还没有为餐厅口味打分呢！");
        return false;    
    }
    if(!IsNull('environment')) {
        alert("您还没有为餐厅环境打分呢！");
        return false;    
    }
    if(!IsNull('service')) {
        alert("您还没有为餐厅服务打分呢！");
        return false;    
    }
    if(!AvgValidate()) return false;
    if(!ContentValidate()) return false;

	Mbox.openLite('<p class="Doing" style="line-height:30px;">正在发表您的评论，请稍候......</p>',280,30);
	
	PostData = 'do=postcomment&ad='+$('adentityId').value
	    +'&ap='+getRadioValue('rblAppraise')
	    +'&ta='+$('taste').value
	    +'&en='+$('environment').value
	    +'&se='+$('service').value
	    +'&av='+$('txtAvg').value
	    +'&di='+$('txtDish').value.cnEncode()
	    +'&pa='+$('txtParking').value.cnEncode()
	    +'&co='+$('txtContent').value.cnEncode()
	    +"&ti="+$('txtTitle').value.cnEncode();
	    
	new AjaxReq({
		url: "/postcomm.aspx",
		method: 'post',
		data: PostData,
		onSuccess: function(data) {
			Mbox.close();
			if(data.code==200){
			    var sDate = new Date();
			    var eDate = new Date();
			    var now = new Date();
			    sDate.setFullYear(2009,11,18);
			    eDate.setFullYear(2010,0,31);
			    if(now>=sDate&&now<=eDate){
                    var html="<div class=\"DialogTitle\"><div class=\"TitleText\">发表评论成功！</div></div>"
                        +"<div class=\"DialogContent\">"
                        +"    <p style=\"text-indent:2em;line-height:24px;font-size:14px;\">即日起至2010年1月31日，您在我们网站发表餐后点评（包括以前吃过没发的），积分将自动翻倍！（非特约商户餐后点评和短信点评除外）</p>"
                        +"</div>"
                        +"<div class=\"DialogButtons\"><button id=\"btnConfirm\" onclick=\"CloseBox('"+data.go+"');\" style=\"width:72px;height:28px;padding:2px 4px;\">关闭</button></div>"
                    Mbox.openLite(html,340,170);
                }
                else{
				    alert(data.msg);
                    window.location.href=data.go;
				}
			}
			else if(data.code==401){
			    //Mbox.openLite('<p class="Doing" style="line-height:30px;">'+data.msg+'</p>',280,30,{closable:true});
			    alert(data.msg);
			}
		}
	}).send();
}

function CloseBox(url){
    Mbox.close();
    window.location.href=url;
}

function GetReply(cid,rid){
    var flag=$('Reply_'+cid).style.display=='none'?true:false;
    if(flag){
        $('Reply_'+cid).style.display="";
        PostData='do=GetReply&cid='+cid+'&rid='+rid+'&t='+Math.random();
        new AjaxReq({
            url: "/adentity/DoReply.aspx",
            method: 'get',
            callType: 'html',
            data: PostData,
            onSuccess: function(data){
                $('Reply_'+cid).set('html',this.ajax.response.html);
            }
        }).send();
    }else{
        $('Reply_'+cid).style.display="none";
    }
}
function PostReply(cid){
    var co=$('txtReplyContent_'+cid).value;
    if(co.length<5)
    {
        alert("您的回复太短了！")
        return false;
    }
    if(co.length>500)
    {
        alert("您的回复太长了！");
        return false;
    }

	Mbox.openLite('<p class="Doing" style="line-height:30px;padding-left:5px;">正在提交你的回复，请稍候......</p>',280,30);

    PostData='do=PostReply&cid='+cid+"&co="+$('txtReplyContent_'+cid).value.cnEncode()+'&t='+Math.random();
    new AjaxReq({
        url: "/adentity/DoReply.aspx",
        method: 'post',
        data: PostData,
        callType: 'html',
        onSuccess: function(data){
            Mbox.close();
            $('Reply_'+cid).set('html',this.ajax.response.html);
			var val = $('RC_'+cid).innerHTML;
            $('RC_'+cid).set('html',Number(val)+1);
        }
    }).send();
}
function SendFlower(cid)
{
	Mbox.openLite('<p class="Doing" style="line-height:30px;padding-left:5px;">正在献花，请稍候......</p>',220,30);
	PostData = "id=" + cid +"&userful=1&t="+Math.random();
	new AjaxReq({
        url: "/AJAX_Comment.aspx",
        method: 'post',
        data: PostData,
        callType: 'html',
        onSuccess: function(data){
			Mbox.close();
            $('Flower_'+cid).set('html',this.ajax.response.html);
        }
    }).send();
}

function doExcellent(){
    var lasturi=location.pathname+'?&Page=1&o='+($('order').value)+"&e="+($('cbIsExcellent').checked?1:0);
    location.href=lasturi;
}
function doMobile(){
    var lasturi=location.pathname+'?&Page=1&o='+($('order').value)+"&m="+($('cbIsMobile').checked?1:0);
    location.href=lasturi;
}
function doOrder(){
    var lasturi=location.pathname+'?&Page=1&o='+($('order').value)+"&m="+($('cbIsMobile').checked?1:0)+"&e="+($('cbIsExcellent').checked?1:0);
    location.href=lasturi;
}
function ResTipContentLength()
{
    var val=document.getElementById("txtContent").value;
    var obj=document.getElementById("leftnum");
    obj.innerHTML=(2000-val.length);
}
function PostResTip(aid){
    var ti=$('txtTitle').value;
    var co=$('txtContent').value;
    if(aid==""||aid.length==0){
        alert("无对应的餐厅！");
	return false;
    }
    if(ti==""||ti=="输入您的攻略标题"||ti.length==0){
    	alert("攻略标题不能为空！");
	return false;
    }
    if(ti.length>30){
    	alert("攻略标题太长了！");
	return false;
    }
    if(co==""||co=="在这儿写您的攻略正文"||ti.length==0){
	alert("攻略正文不能为空！");
	return false;
    }
    if(co.length<10)
    {
        alert("攻略内容不能少于10个字符！");
        return false;
    }
    if(co.length>2000)
    {
        alert("攻略内容不能多于2000个字符！");
        return false;
    }

	Mbox.openLite('<p class="Doing" style="line-height:30px;padding-left:5px;">正在提交你的攻略，请稍候......</p>',280,30);

    PostData='do=postrestip&aid='+aid+'&co='+co.cnEncode()+'&ti='+ti.cnEncode()+'&t='+Math.random();
    new AjaxReq({
		url: "/postcomm.aspx",
		method: 'post',
		data: PostData,
		onSuccess: function(data) {
			Mbox.close();
			if(data.code==200){
				alert(data.msg);
			    window.location.href=data.go;
			}
			else if(data.code==401){
			    alert(data.msg);
			}
		}
	}).send();
}
function ShowReport(cid,type){
    var html="<div class=\"DialogTitle\"><div class=\"TitleText\">评论举报</div></div>"
    +"<div class=\"DialogContent\">"
    +"    <input id=\"Rid\" type=\"hidden\" value='" + cid + "' />"
    +"    <input id=\"RType\" type=\"hidden\" value='" + type + "' />"
    +"    <textarea id=\"RContent\" cols=\"15\" rows=\"8\" style='width:99%;'></textarea>"
    +"</div>"
    +"<div class=\"DialogButtons\"><button id=\"confirmTip\" onclick=\"return DoReport();\" style=\"padding:2px 4px;\">提交举报信息</button></div>"
    Mbox.openLite(html,340,230,{closable:true});
}
function DoReport(){
    var cnt = ($('RContent').value+'').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
    var rid = $('Rid').value;
    var tid = $('RType').value
    if(cnt=='请输入举报原因'){
        $('RContent').focus();
        return false;
    }
    if(cnt.length<2){
        alert('举报原因不能小于2个字符');
        $('RContent').focus();
        return false;  
    }
    PostData = "id=" + rid +"&report=1&typeId=" + tid + "&title="+escape(cnt);
    new AjaxReq({
        url: '/AJAX_Comment.aspx',
        method: 'post',
        callType: 'html',
        data: PostData,
        onSuccess: function(data) {
            Mbox.close();
            $('Report_' + rid).set('html',this.ajax.response.html);
        }
    }).send();
}
function NoLoginFav(){
	alert('您好,只有登录后才能使用收藏功能!');
	return false;
}
function doDisplayFav(id,typeid){
    var gdata="id="+id+"&type="+typeid+"&r="+Math.random();
    var idReg=/^\d+$/;
    if(!idReg.test(id))
    {
        GetBankContent('/Members/myFavorites.aspx',gdata,'JfavBar');
    }
    else
    {
        GetBankContent('/Members/myFavorites.aspx',gdata,'JfavBar'+id);
    }
}
function doAddFav(varst,typeid){
    var gdata="ajax=1&resid="+varst+"&typeid="+typeid;
    var idReg=/^\d+$/;
    if(!idReg.test(varst))
    GetBankContent('/Members/myFavorites.aspx',gdata,'JfavBar');
    else
    GetBankContent('/Members/myFavorites.aspx',gdata,'JfavBar'+varst);
}

function GetBankContent(sUrl,sPara,obj){
    $(obj).set('html','<img src="/image/loading.gif"/>');
    PostData = sPara;
    new AjaxReq({
        url: sUrl,
        method: 'post',
        callType: 'html',
        data: PostData,
        onSuccess: function(data) {
            $(obj).set('html',this.ajax.response.html);
        }
    }).send();
}

function ShowErrorReport(resid){
    var html="<div class=\"DialogTitle\"><div class=\"TitleText\">报告餐厅错误信息</div></div>"
    +"<div class=\"DialogContent\">"
    +"    <input id=\"ErrorRes\" type=\"hidden\" value='" + resid + "' />"
    +"    <input id=\"ErrorType\" type=\"hidden\" value=\"error\" />"
    +"    <textarea id=\"ErrorContent\" cols=\"15\" rows=\"8\" style='width:99%;'></textarea>"
    +"</div>"
    +"<div class=\"DialogButtons\"><button id=\"confirmTip\" onclick=\"return DoErrorReport();\" style=\"padding:2px 4px;\">提交错误报告</button></div>"
    Mbox.openLite(html,340,230,{closable:true});
}
function DoErrorReport(){
    var cnt = ($('ErrorContent').value+'').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
    var rid = $('ErrorRes').value;
    var tid = $('ErrorType').value;
    if(cnt=='请输入报错原因'){
        $('ErrorContent').focus();
        return false;
    }
    if(cnt.length<2){
        alert('报错原因不能小于2个字符');
        $('ErrorContent').focus();
        return false;  
    }
    PostData = "id=" + rid +"&report=1&typeId=" + tid + "&title="+escape(cnt);
    new AjaxReq({
        url: '/AJAX_Comment.aspx',
        method: 'post',
        callType: 'html',
        data: PostData,
        onSuccess: function(data) {
            Mbox.close();
	        if($('SysReportError_' + rid)){
		        $('SysReportError_' + rid).set('html',this.ajax.response.html);
	        }
	        if($('lnk-report1')){
		        $('lnk-report1').set('html',this.ajax.response.html);
	        }
        }
    }).send();
}