// JScript 文件
function itemsList(id)
{
 
}
var itemMoney=0.0;
var itemCount=0;
function PreView(obj,arg)
{
  var tableobj=document.getElementById("menuItems");
  var rowobj;
  var cell;
  if(arg==1)
  {
  if(itemCount%2!=0)
  {
    rowobj=tableobj.insertRow(tableobj.rows.length);
    cell=rowobj.insertCell(rowobj.cells.length);
  }
  else
  {
    cell=tableobj.rows[itemCount/2-1].insertCell(tableobj.rows[itemCount/2-1].cells.length);
  }
  cell.innerHTML=obj.parentElement.innerText+"<input name=itemMenuList type=checkbox value="+obj.value+" disabled=true >";
  }
  else
  {
   for(i=0;i<tableobj.rows.length;i++)
   {
    rowobj=tableobj.rows(i);
    for(x=0;x<rowobj.cells.length;x++)
    {
     
     var temp1=rowobj.cells(x).innerHTML.indexOf("value=");
     var temp2=rowobj.cells(x).innerHTML.substr(temp1);
     var temp=temp2.indexOf(" ");
     var txt=rowobj.cells(x).innerHTML.substr(temp1+6,temp-6);
     if(obj.value==txt)
       rowobj.deleteCell(x);
    }
   }
  }
  
}
function subAddMenu()
{
 var arg="";
 var list=document.getElementsByName("itemMenuList");
 for(i=0;i<list.length;i++)
 {
  arg=arg+list[i].value+",";
 }
 var obj=admin_menumange_aspx.AddMenu(arg,document.getElementById("menuName").value,document.getElementById("menuMark").value);
 if(obj.value>0)
  alert("添加成功");
 
}
function $(v) { return(document.getElementById(v)); }
function $S(v) { return($(v).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function isset(v) { return((typeof(v)=='undefined' || v.length==0)?false:true); }
function XYwin(v) { var z=agent('msie')?Array(document.body.clientHeight,document.body.clientWidth):Array(window.innerHeight,window.innerWidth); return(isset(v)?z[v]:z); }

function sexyTOG() { document.onclick=function(){ $S('sexyBG').display='none'; $S('sexyBOX').display='none'; document.onclick=function(){}; subAddMenu();};}
function sexyTOG1() { document.onclick=function(){ $S('sexyBG').display='none'; $S('sexyBOX').display='none'; document.onclick=function(){}; subEditMenu();};}
function sexyBOX1(b) {
$S('sexyBG').height=XYwin(0)+'px'; 
$S('sexyBG').display='block'; 
$('sexyBOX').innerHTML="<div class=\"sexyT\">菜单名称:<input type=text id=\"menuName\"><\/div>备注:<textarea  id=\"menuMark\" ></textarea><div class=\"sexyX\" onMouseMove=\"setTimeout('sexyTOG()',1);\" onMouseOut=\"setTimeout('document.onclick=function(){}',1);\" style=\"cursor:pointer;\">(确认)"+"<\/div>"; 
$S('sexyBOX').left=Math.round((XYwin(1)-b)/2)+'px'; 
$S('sexyBOX').width=b+'px'; 
$S('sexyBOX').display='block'; }
function sexyBOX(b,id) {
var obj=admin_menumange_aspx.GetMenuInfo(id);
var data=obj.value.split("*");
$S('sexyBG').height=XYwin(0)+'px'; 
$S('sexyBG').display='block'; 
$('sexyBOX').innerHTML="<div class=\"sexyT\"><input type=hidden id=\"menuId\" value='"+id+"'>菜单名称:<input type=text id=\"menuName\" value='"+data[0]+"' ><\/div>备注:<textarea  id=\"menuMark\" >"+data[1]+"</textarea><div class=\"sexyX\" onMouseMove=\"setTimeout('sexyTOG1()',1);\" onMouseOut=\"setTimeout('document.onclick=function(){}',1);\" style=\"cursor:pointer;\">(确认)"+"<\/div>"; 
$S('sexyBOX').left=Math.round((XYwin(1)-b)/2)+'px'; 
$S('sexyBOX').width=b+'px'; 
$S('sexyBOX').display='block'; }
window.onload=function(){
document.body.innerHTML="<div id=\"sexyBG\"></div><div id=\"sexyBOX\"></div>"+document.body.innerHTML;
}
function DeleteTableRow() 
{ 
var tableobj=document.getElementById("itemList");
if(tableobj.rows.length>0)
{
var m=tableobj.rows.length;
for(i=0;i<m;i++)
  tableobj.deleteRow(0);
}
}

function StateShow(obj)
{
 var tableobj=document.getElementById("itemList");
 if(obj.checked)
 {
  itemMoney=itemMoney+parseFloat(obj.money);
  itemCount=itemCount+1;
  PreView(obj,1);
 }
 else
 {
  itemMoney=itemMoney-parseFloat(obj.money);
  itemCount=itemCount-1;
  PreView(obj,-1);
 }

 arrayOb[document.getElementById("itemTypeLists").selectedIndex]=tableobj.innerHTML;
 document.getElementById("state").innerHTML="您总共点了"+itemCount+"个菜  当前面值:"+itemMoney;
}
function LoadItems()
{
 var tableobj=document.getElementById("itemList");
 if(arrayOb[document.getElementById("itemTypeLists").selectedIndex]==null)
 {
 var obj=admin_menumange_aspx.GetItems(document.getElementById("itemTypeLists").value);
 if(obj.value!="")
 {
 DeleteTableRow();
 var data=obj.value.split("|");
 q=0;
 var rowobj;
 var cell;
 for(i=0;i<data.length-1;i++)
 {
  oneItem=data[i].split(",");
  if(q%2==0)
  {
  rowobj=tableobj.insertRow(tableobj.rows.length);
  cell=rowobj.insertCell(rowobj.cells.length);
  }
  else
  {
   cell=rowobj.insertCell(rowobj.cells.length);
  }
  cell.innerHTML=oneItem[0]+"<input type=checkbox  value="+oneItem[1]+" money="+oneItem[4]+"  onpropertyChange=\"StateShow(this)\" >";
  q=q+1;
 }
 }
 }
 else
 { 
  tableobj.outerHTML="<table width=100% id=\"itemList\" border=\"0\">"+arrayOb[document.getElementById("itemTypeLists").selectedIndex].toString()+"</table>";
  }
}
var arrayObj; 　
function LoadType()
{
 if(document.getElementById("itemTypeLists").options.length<1)
 {
 var object=admin_menumange_aspx.GetTypes();
 if(object.value!="")
 {
 var data=object.value.split("|");
 for(i=0;i<data.length-1;i++)
 {
  var temp=data[i].split(",");
  var TemOption=new Option(temp[1],temp[0]);
  document.getElementById("itemTypeLists").options.add(TemOption);
 }
 arrayOb=new Array(i);
 }
 }
}
function ShowMenu()
{
 document.getElementById("nifty").style.display="block";
 document.getElementById("Div2").style.display="none";
}
function MakeMenu()
{
  document.getElementById("nifty").style.display="block";
  document.getElementById("Div2").style.display="block";
}
function EditMeun(id)
{
 document.getElementById("changeMenun").innerHTML="修改菜单";
 Init_Items();
 var countmoney=0;
 var obj=admin_menumange_aspx.GetMenu(id);
 if(obj.value!="")
 {
 var data=obj.value.split("|");
 var tableobj=document.getElementById("menuItems");
 var count=0;
 var rowobj;
 var cell;
 for(i=0;i<data.length-1;i++)
 {
  //alert(data[i]);
  var temp=data[i].split("*");
  if(count%2==0)
  {
   rowobj=tableobj.insertRow(tableobj.rows.length);
  }
  cell=rowobj.insertCell(rowobj.cells.length);
  //alert(temp[2]);
  cell.innerHTML=temp[0]+"<input type=checkbox name=itemMenuList value='"+temp[2]+"' money='"+temp[1]+"' checked onpropertyChange=\"AlterStateShow(this)\" >";
  count=count+1;
  countmoney=countmoney+parseFloat(temp[1]);
 }
 itemMoney=countmoney;
 itemCount=count;
 }
 document.getElementById("sure").onclick=new Function("sexyBOX('500','"+id+"')");
}
function subEditMenu()
{
 var arg="";
 var list=document.getElementsByName("itemMenuList");
 for(i=0;i<list.length;i++)
 {
  arg=arg+list[i].value+",";
 }
 var obj=admin_menumange_aspx.EditMenu(document.getElementById("menuId").value,arg,document.getElementById("menuName").value,document.getElementById("menuMark").value);
 if(obj.value>0)
  alert("修改成功");
  
}
function AlterStateShow(obj)
{
 var tableobj=document.getElementById("menuItems");
 if(!obj.checked)
 {
  itemMoney=itemMoney-parseFloat(obj.money);
  itemCount=itemCount-1;
  tableobj.rows[obj.parentElement.parentElement.rowIndex].deleteCell(obj.parentElement.cellIndex);
  document.getElementById("state").innerHTML="您总共点了"+itemCount+"个菜  当前面值:"+itemMoney;
 }
}

function Init_Items()
{
 var tableobj=document.getElementById("menuItems");
 if(tableobj.rows.length>0)
 {
 var m=tableobj.rows.length;
 for(i=0;i<m;i++)
  tableobj.deleteRow(0);
 }
 itemMoney=0;
 itemCount=0;
 ShowMenu();
}