﻿function myHobby(){
    var myCookie=Cookie.read("display");
    if(myCookie=='hide'){
        document.getElementById('dsp-content').style.display="none";
        document.getElementById('label-dsp-btn').setAttribute('class','viewBtn02');
        document.getElementById('label-dsp-btn').className='viewBtn02';
    }
    else{
        document.getElementById('dsp-content').style.display="block";
        document.getElementById('label-dsp-btn').setAttribute('class','viewBtn01');
        document.getElementById('label-dsp-btn').className='viewBtn01';
    }
}
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','viewBtn01');
        document.getElementById('label-dsp-btn').className='viewBtn01';
        Cookie.write('display','show',{duration: 365,path: '/'});
    }
    else{
        document.getElementById('dsp-content').style.display="none";
        document.getElementById('label-dsp-btn').setAttribute('class','viewBtn02');
        document.getElementById('label-dsp-btn').className='viewBtn02';
        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(resid,cid){
    PostData='resid='+resid+'&step=4&cid='+cid+'&t='+Math.random();
    new AjaxReq({
        url: "/adentity/docomment.aspx",
        anysc: false,
        method: 'get',
        callType: 'html',
        data: PostData,
        onSuccess: function(data){
            $('cc_'+cid).innerHTML=this.ajax.response.html;
        }
    }).send();
}
function PostComment(){
    if(!IsNull('adentityId')) {
        alert("无相关餐厅！");
        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;
    if(!RadioValidate('rblAppraise','您还没有对餐厅做评价！')){
        return false;
    }
	var aid=$('adentityId').value;
	PostData = 'do=postcomment&ad='+$('adentityId').value
	    +'&ap='+getRadioValue('rblAppraise')
	    +'&tb='+getRadioValue('rblBackAgain')
	    +'&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();
    $('btnPost').innerHTML="正在发表您的评论，请稍候......";
	new AjaxReq({
		url: "/postcomm.aspx",
		method: 'post',
		data: PostData,
		onSuccess: function(data) {
			if(data.code==200){
				showStep2(aid,data.msg);
			}
			else if(data.code==401){
			    alert(data.msg);
			    $('btnPost').innerHTML="<input id=\"btnPost\" type=\"button\" class=\"longBtn\" value=\"提交\" onclick=\"PostComment();return false;\" /></span>";
			}
		}
	}).send();
}
function showStep1(resid){
	new AjaxReq({
		url: "/adentity/docomment.aspx",
		async:false,
		method: 'get',
		callType: 'html',
		data: 'resid='+resid+'&step=1&k='+Math.random(),
		onSuccess: function(data) {
            Mbox.openLite(this.ajax.response.html,619,'auto',{closable:true});
		}
	}).send();
}
function showStep2(resid,commentid){
	new AjaxReq({
		url: "/adentity/docomment.aspx",
		async:false,
		method: 'get',
		callType: 'html',
		data: 'resid='+resid+'&cid='+commentid+'&step=2&k='+Math.random(),
		onSuccess: function(data) {
            Mbox.openLite(this.ajax.response.html,719,'auto',{closable:true});
		}
	}).send();
}
function showUpload(resid,commentid){
	new AjaxReq({
		url: "/adentity/docomment.aspx",
		async:true,
		method: 'get',
		callType: 'html',
		data: 'resid='+resid+'&cid='+commentid+'&step=3&k='+Math.random(),
		onSuccess: function(data) {
            Mbox.openLite(this.ajax.response.html,719,'auto',{closable:true});
		}
	}).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 ShowReplyEditor(id,cid){
    PostData='do=ShowEditor&cid='+cid+'&id='+id+'&t='+Math.random();
    new AjaxReq({
        url: "/adentity/DoReply.aspx",
        method: 'get',
        async:true,
        callType: 'html',
        data: PostData,
        onSuccess: function(data){
        	var html=this.ajax.response.html;
			//if(html===''){
        		Mbox.openLite(html,320,120);
        	//}
        }
    }).send();
}
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 UpdateReply(id,cid){
    var co=$('txtReply').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=SaveReply&id='+id+'&cid='+cid+'&co='+co.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);
        }
    }).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();
			alert(this.ajax.response.html);
            $('Flower_'+cid).set('html',this.ajax.response.html);
        }
    }).send();
}
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,'auto',{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,'auto',{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();
}
function setStars(n,t,o){
    var target = document.getElementById(t);
    var obj = document.getElementById(o);
    target.value = n;
    switch(n){
        case 1:
            obj.style.backgroundPosition = '-80px top';
            break;
        case 2:
            obj.style.backgroundPosition = '-60px top';
            break;
        case 4:
            obj.style.backgroundPosition = '-20px top';
            break;
        case 5:
            obj.style.backgroundPosition = '0px top';
            break;
        case 3:
        default:
            obj.style.backgroundPosition = '-40px top';
            break;
    }
}

function showSendMobile(resid,type){
	new AjaxReq({
		url: "/adentity/docommon.aspx",
		async:true,
		method: 'get',
		callType: 'html',
		data: 'resid='+resid+'&type=' + type + '&k='+Math.random(),
		onSuccess: function(data) {
		    //alert(this.ajax.response.html);
            Mbox.openLite(this.ajax.response.html,450,'auto',{closable:true});
		}
	}).send();
}
//发送停车场信息的短信
function SendMobileMsg(resid,type,code,mobile,content)
{
	new AjaxReq({
		url: "/adentity/docommon.aspx",
		async:true,
		method: 'post',
		callType: 'html',
		data: 'resid='+resid+'&mobile=' + mobile + '&code='+ code + '&content=' + content + '&type=' + type + '&k='+Math.random(),
		 onSuccess: function(data) {
		 	 var result = this.ajax.response.html;
		        if(result==="1"){
		        	alert("发送成功");
		            Mbox.close();
		        }
		        else{
		           	alert(result);
		        }
		    }
	}).send();    
}

function DoResCanBook(resid,type){
	new AjaxReq({
		url: "/adentity/docommon.aspx",
		async:true,
		method: 'get',
		callType: 'html',
		data: 'resid='+resid+'&type=' + type + '&k='+Math.random(),
		onSuccess: function(data) {
		    //alert(this.ajax.response.html);
            Mbox.openLite(this.ajax.response.html,562,'auto',{closable:true});
            
		}
	}).send();
}

function ShowNewForm(action,width,height){
		new AjaxReq({
		url: "/members/douser.aspx",
		async:true,
		method: 'post',
		callType: 'html',
		data: 'do=' + action + '&k='+Math.random(),
		 onSuccess: function(data) {
		 	 Mbox.openLite(this.ajax.response.html,width,height,{closable:true});
		    }
	}).send();
}
