﻿document.write('<script type="text/javascript" src="/ajaxpro/Web9eat.Web.UI.Ajax.CpShopCartAjax,Web9eat.Web.UI.ashx"></script>');
document.write('<script type="text/javascript" src="/ajaxpro/Web9eat.Web.UI.Ajax.CompanyAjax,Web9eat.Web.UI.ashx"></script>');
function SetKind(kind)
{
AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+$F('showType')+'&typeId=0&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind='+kind,function(){Init_SelectPrice()});
}

function SetCpType(typeId)
{
AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+$F('showType')+'&typeId='+typeId+'&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind=cp',function(){Init_SelectPrice()});
}

function SetShowType(showType)
{
AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+showType+'&typeId='+$F('typeId')+'&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind='+$F('kind'),function(){Init_SelectPrice()});
}



function HcCheck(chId){


Web9eat.Web.UI.Ajax.CpShopCartAjax.HcAdd(chId,$F('companyId'),$('hcName_'+chId).innerHTML,$('selectPrice_'+chId).value,function(res){

    var result=res.value; 
        if(result!=null){
             AjaxHelper.Updater('Company/Panel_CheckedCpList','CheckedCpList','channel='+$F('channel')+'&companyId='+$F('companyId'));
        }     

    });


}

function HcRemove(chId)
{
Web9eat.Web.UI.Ajax.CpShopCartAjax.HcRemove(chId,$F('companyId'),function(res)
{
    var result=res.value; 

        if(result=="1"){
            AjaxHelper.Updater('Company/Panel_CheckedCpList','CheckedCpList','companyId='+$F('companyId'));
            AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+$F('showType')+'&typeId='+$F('typeId')+'&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind='+$F('kind'),function(){Init_SelectPrice()});

        }
        else if(result=="0"){

            return;
        }
        else{
            alert('操作失败!')
        }
       

    });
}



function HcDecrease(chId)
{
Web9eat.Web.UI.Ajax.CpShopCartAjax.HcDecrease(chId,$F('companyId'),function(res)
{
    var result=res.value; 

        if(result=="1"){
            AjaxHelper.Updater('Company/Panel_CheckedCpList','CheckedCpList','channel='+$F('channel')+'&companyId='+$F('companyId'));
            AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+$F('showType')+'&typeId='+$F('typeId')+'&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind='+$F('kind'),function(){Init_SelectPrice()});

        }
        else if(result=="0"){

            return;
        }
        else{
            alert('操作失败!')
        }
       

    });
}

function HcUp(chId)
{
Web9eat.Web.UI.Ajax.CpShopCartAjax.HcUp(chId,$F('companyId'),function(res)
{
    var result=res.value; 
        if(result=="1"){
            AjaxHelper.Updater('Company/Panel_CheckedCpList','CheckedCpList','channel='+$F('channel')+'&companyId='+$F('companyId'));
            AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+$F('showType')+'&typeId='+$F('typeId')+'&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind='+$F('kind'),function(){Init_SelectPrice()});

        }
        else if(result=="0"){

            return;
        }
        else{
            alert('操作失败!')
                    }       

    });
}





function cpCheck(cpId)
{
if(isloaded==0){Init_SelectPrice();return;}
//alert(comanyId+cpId);
//alert($('selectPrice_'+cpId).value);
//alert($('cpName_'+cpId).innerHTML);
//alert($('li_'+cpId).className);
//alert(this.className);
//Add(string cpId, string companyId, string cpName, string price)
  var li=$('li_'+cpId);
  var link=$('option_'+cpId).getElementsByTagName("a")[0];
  var img=link.getElementsByTagName("img")[0];
  var span=link.getElementsByTagName("span")[0];

if(link.className==''){
Web9eat.Web.UI.Ajax.CpShopCartAjax.Add(cpId,$F('companyId'),$('cpName_'+cpId).innerHTML,$('selectPrice_'+cpId).value,function(res){

    var result=res.value; 
        if(result!=null){

         li.className='selected'
         link.className='selected';
         img.src='/Images/checkSelected.gif';
         span.innerHTML='取 消';
         AjaxHelper.Updater('Company/Panel_CheckedCpList','CheckedCpList','channel='+$F('channel')+'&companyId='+$F('companyId'));

        }
       

    });
}
else 
{
Web9eat.Web.UI.Ajax.CpShopCartAjax.Remove(cpId,$F('companyId'),function(res){

    var result=res.value; 
       
        if(result=="1"){
            li.className=''
            link.className='';
            img.src='/Images/check.gif';
            span.innerHTML='点 菜';
                     AjaxHelper.Updater('Company/Panel_CheckedCpList','CheckedCpList','channel='+$F('channel')+'&companyId='+$F('companyId'));
                    AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+$F('showType')+'&typeId='+$F('typeId')+'&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind='+$F('kind'),function(){Init_SelectPrice()});

            }
       else if(result=="0"){
            return 
           // alert('已经选菜单中，没有移除的项!');
        }
        else{
            alert('操作失败!')
        }
       

    });



}

}

function Remove(cpId)
{
Web9eat.Web.UI.Ajax.CpShopCartAjax.Remove(cpId,$F('companyId'),function(res)
{
    var result=res.value; 

        if(result=="1"){
            AjaxHelper.Updater('Company/Panel_CheckedCpList','CheckedCpList','channel='+$F('channel')+'&companyId='+$F('companyId'));
            AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+$F('showType')+'&typeId='+$F('typeId')+'&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind='+$F('kind'),function(){Init_SelectPrice()});

        }
        else if(result=="0"){

            return;
        }
        else{
            alert('操作失败!')
        }
       

    });
}



function Decrease(cpId)
{
Web9eat.Web.UI.Ajax.CpShopCartAjax.Decrease(cpId,$F('companyId'),function(res)
{
    var result=res.value; 

        if(result=="1"){
            AjaxHelper.Updater('Company/Panel_CheckedCpList','CheckedCpList','channel='+$F('channel')+'&companyId='+$F('companyId'));
            AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+$F('showType')+'&typeId='+$F('typeId')+'&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind='+$F('kind'),function(){Init_SelectPrice()});

        }
        else if(result=="0"){

            return;
        }
        else{
            alert('操作失败!')
        }
       

    });
}

function Up(cpId)
{
Web9eat.Web.UI.Ajax.CpShopCartAjax.Up(cpId,$F('companyId'),function(res)
{
    var result=res.value; 
        if(result=="1"){
            AjaxHelper.Updater('Company/Panel_CheckedCpList','CheckedCpList','channel='+$F('channel')+'&companyId='+$F('companyId'));
            AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+$F('showType')+'&typeId='+$F('typeId')+'&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind='+$F('kind'),function(){Init_SelectPrice()});

        }
        else if(result=="0"){

            return;
        }
        else{
            alert('操作失败!')
        }
       

    });
}

function Clear()
{
Web9eat.Web.UI.Ajax.CpShopCartAjax.Clear($F('companyId'),function(res)
{
    var result=res.value; 

        if(result=="1"){
            AjaxHelper.Updater('Company/Panel_CheckedCpList','CheckedCpList','channel='+$F('channel')+'&companyId='+$F('companyId'));
            AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+$F('showType')+'&typeId='+$F('typeId')+'&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind='+$F('kind'),function(){Init_SelectPrice()});

        }
        else if(result=="0"){

            return;
        }
        else{
            alert('操作失败!')
        }
       

    });
}

function tcCheck(chId)
{
Web9eat.Web.UI.Ajax.CpShopCartAjax.AddTc(chId,$F('companyId'),function(res)
{
    var result=res.value; 

        if(result=="1"){
            AjaxHelper.Updater('Company/Panel_CheckedCpList','CheckedCpList','channel='+$F('channel')+'&companyId='+$F('companyId'));
            AjaxHelper.Updater('Company/Panel_CpList','CpListBody','channel='+$F('channel')+'&companyId='+$F('companyId')+'&showType='+$F('showType')+'&typeId='+$F('typeId')+'&tcId='+$F('tcId')+'&hcId='+$F('hcId')+'&cpId='+$F('cpId')+'&kind='+$F('kind'),function(){Init_SelectPrice()});

        }
        else if(result=="0"){
          alert('暂无预设的菜!')
            return;
        }
        else{
            alert('操作失败!')
        }
       

    });
}

function Show(Id,type,relationId){
var arrPageScroll=getPageScroll();
WinDialog(955,500)
//alert(arrPageScroll[1])
if(parseInt(arrPageScroll[1])<45){
$('dialog').style.top=(45-parseInt(arrPageScroll[1]));
}
else{
$('dialog').style.top=parseInt(arrPageScroll[1]+10);
}

var htmlStr='<table width="100%" height="500" border="0" cellpadding="0" cellspacing="0">';
  htmlStr+='<tr>';
  htmlStr+='<td width="265" align="left" valign="top" style="border:1px solid #FFBC7B">';
  htmlStr+='<div style="background-color:#FFF8EE;height:25px;line-height:25px;padding-left:10px; align-text:left;font-weight:bold;color:#FF8A00; border-bottom:1px solid #FFBC7B" >菜谱列表</div>';
  htmlStr+='<div id="LeftCpList" style="overflow-y:scroll;SCROLLBAR-FACE-COLOR: #ffffff; PADDING-BOTTOM: 0px; SCROLLBAR-HIGHLIGHT-COLOR: #ffffff; OVERFLOW: auto; SCROLLBAR-SHADOW-COLOR: #919192; SCROLLBAR-3DLIGHT-COLOR: #ffffff; SCROLLBAR-ARROW-COLOR: #919192; SCROLLBAR-TRACK-COLOR: #ffffff; SCROLLBAR-DARKSHADOW-COLOR: #ffffff; " ><span id="loading" >正在加载...</div></div>';
  htmlStr+='</td>';
  htmlStr+='<td width="10">&nbsp;</td>';
  htmlStr+='<td align="left" valign="top" style="border:1px solid #FFBC7B" >';
  htmlStr+='<div style="background-color:#FFF8EE;height:25px;line-height:25px;padding-left:10px; border-bottom:1px solid #FFBC7B" ><span style="font-weight:bold;color:#FF8A00; float:left;width:620px; ">菜谱详细</span> <span style="float;right;"><a href="javascript:void(0)" onclick="CloseDialog()" >关 闭</a></span></div>';
  htmlStr+='<div id="CpDetail" ><span id="loading" >正在加载...</div></div>';
  htmlStr+='</td>';
  htmlStr+='</tr>';
  htmlStr+='</table>';
$('dialog').innerHTML=htmlStr;
SetView(Id,type,relationId);

}

function SetView(Id,type,relationId){
var e;
try{
 AjaxHelper.Updater('Company/Panel_LeftCpList','LeftCpList','channel='+$F('channel')+'&companyId='+$F('companyId')+'&Id='+Id+'&type='+type+'&relationId='+relationId);
 AjaxHelper.Updater('Company/Panel_CpDetail','CpDetail','channel='+$F('channel')+'&Id='+Id+'&type='+type+'&relationId='+relationId);
}
catch(e){

}
}

//&d_Data='+$F('txtd_Data')+'&d_Time1='+$F('ddd_Time1')+'&d_Room='+$F('txtd_Room')+'&d_Rs='+$F('txtd_Rs')+'&d_Name='+$F('txtd_Name')+'&d_Tel='+$F('txtd_Tel')+'&d_Mome='+$F('txtd_Mome')+'&radRoomType='+radRoomType)
function eat_Yuding(obj,companyId,isdc)
{
obj.disabled=true;  
Web9eat.Web.UI.Ajax.CpShopCartAjax.EatYuding(companyId,isdc,function(res){
 var result=res.value; 
    if(result=="1"){

       alert('您的预订已经提交成功，网站客服人员会立即与您确认,并帮您预订!');
       location.reload();
    }
    else if(result=="2" ){
    alert('您的预订和在线点菜已经提交成功，网站客服人员会立即与您确认,并帮您预订!')
       location.reload();
    }
    else if(result=="-1"){
    ShowLoginWin(function(){eat_Yuding(obj,companyId,isdc);});
    }
    else{
    alert('提交失败');
    }
});


}

//餐饮预订
function yudingConfirm(companyId){

var d_Data=$F('txtd_Data');

if(d_Data!=''){
if(!isDate(d_Data)){
alert('时间格式出错！');return;
}
else{
//var date1=(new Date().getYear())+'-'+(new Date().getMonth()+1)+'-'+(new Date().getDate())
var date=new Date();

var day=date.getFullYear()+'-'+parseInt(date.getMonth()+1)+'-'+date.getDate();

var date1=addDate("4",parseInt($F('txtC_advanceDate')),date);
var date2=d_Data;


if(getDateDiff(day,date2)<0){
alert('预订日期必须大于当前日期！');return;
}
else{
    if($F('txtC_advanceDate')!="0"){
        if(!compareDate(date1,date2)){
        alert('预订天数必须在'+$F('txtC_advanceDate')+'天内！');
        return;
        }
    }
    date=new Date();    
     var minutesAll1=parseInt(date.getHours()*60)+parseInt(date.getMinutes());
     var ddd_Time1=$F('ddd_Time1');
     var hours=$F('ddd_Time1').split(':')[0];
    var minutes=$F('ddd_Time1').split(':')[1];   
      var minutesAll2=parseInt(hours)*60+parseInt(minutes);
         var last_hours=$F('txtC_latestTime').split(':')[0];
      var last_minutes=$F('txtC_latestTime').split(':')[1];
      minutesAll3=parseInt(last_hours)*60+parseInt(last_minutes);
      
  if(getDateDiff(date.getFullYear()+'-'+parseInt(date.getMonth()+1)+'-'+date.getDate(),d_Data)==0)//当天
  {
       
          
                     
           
         
       
         if(minutesAll1>minutesAll2)
        {        
             alert('预订时间必需大于当前时间！');return;
        }
        if($F('txtC_advanceTime')!="0")//时间
        {
       
               if((minutesAll1+parseInt($F('txtC_advanceTime')))>minutesAll2)
               {       
               alert('您必需提前'+$F('txtC_advanceTime')+'分钟预订！');return;
               }
        }
        
        
          
    }

      if(minutesAll3>0&&minutesAll2>minutesAll3){
        alert('该商家最晚预订时间是'+last_hours+":"+last_minutes+'，超过该时间，不能提供预订！');return;      
      }
      

}

}

}
else{
alert('请填写预订时间！');$('txtd_Data').focus();return;
}


if($F('txtd_Room')==''){alert('请输入桌数！');$('txtd_Room').focus();return}
if($F('txtd_Rs')==''){alert('请输入就餐人数！');$('txtd_Rs').focus();return}
var arr_radRoomType=document.getElementsByName("radHotelId");
var radRoomType="";
for (var i = 0; i < arr_radRoomType.length; i++) 
{
if(arr_radRoomType[i].checked){
radRoomType=arr_radRoomType[i].value;
break; 
}
}

if(radRoomType==""){alert('请选择包厢类型！');return;}

if($F('txtd_Name')==''){alert('请输入联系人姓名！');$('txtd_Name').focus();return}
if($F('txtd_Tel')=='')
{
 alert('请输入联系电话！');$('txtd_Tel').focus();return
}
else{
    var tel=$F('txtd_Tel');
    if(tel.length==11){
        if(tel.substring(0,2)!='13'&&tel.substring(0,2)!='18'&&tel.substring(0,2)!='15'){
            alert('手机号码输入不正确');$('txtd_Tel').focus();return;
        }
    }
    else if(tel.length!=8&&tel.length!=7){
      alert('电话号码输入不正确');$('txtd_Tel').focus();return;
    }
}

  
Web9eat.Web.UI.Ajax.CpShopCartAjax.SaveYuding(companyId,$F('txtd_Data'),$F('ddd_Time1'),$F('txtd_Room'),$F('txtd_Rs'),radRoomType,$F('txtd_Tel'),$F('txtd_Name'),$F('txtd_Mome'),function(res)
{
    var result=res.value; 

       if(result!=null){

            WinMessage("预订信息确认", '', 400,200);
             AjaxHelper.Updater('Company/Panel_YudingConfirm','dialogbody','companyId='+companyId+'&d_Data='+$F('txtd_Data')+'&d_Time1='+$F('ddd_Time1')+'&d_Room='+$F('txtd_Room')+'&d_Rs='+$F('txtd_Rs')+'&d_Name='+$F('txtd_Name')+'&d_Tel='+$F('txtd_Tel')+'&d_Mome='+$F('txtd_Mome')+'&radRoomType='+radRoomType);
        }
        else{
            alert('操作失败');
        }
    });


}
