// JScript 文件
var old;
function AlterType(arg,obj)
{
 old=obj.parentElement.innerHTML;
 var object=admin_renewcook_aspx.GetTypes();
 if(object.value!="")
 {
  var data=object.value.split("|");
  var txt="<select id=\"selevtType\"><option value=-1 >请选择</option>";
  for(i=0;i<data.length-1;i++)
  {
  var temp=data[i].split(",");
  txt=txt+"<option value="+temp[0]+" >"+temp[1]+"</option>";
  }
  txt=txt+"</select>";
 }
 obj.parentElement.innerHTML=txt+"<a href=# onclick=\"subAlterType('"+arg+"')\" >确认</a> <a onclick=\"Recover(this)\" >返回</a>";
}
function loadType()
{
 if(document.getElementById("itemTypeLists").options.length<1)
 {
 var object=admin_renewcook_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);
 }
 }
 }
}
function Recover(obj)
{
 obj.parentElement.innerHTML=old;
}

function subAlterType(arg)
{
 if(document.getElementById("selevtType").value!=-1)
 {
  var object=admin_renewcook_aspx.AlterType(arg,document.getElementById("selevtType").value);
  if(object.value==1)
   alert("修改成功");
  
 }
}
function DeleteItem(id,obj)
{
 
 if(confirm("您确实要删除这个菜?"))
 {
  if(admin_renewcook_aspx.DeleteItem(id)==1)
  { 
   alert("删除成功");
   obj.parentNode.parentNode.style.display="none";
  }
 }
}

function Preview()
{
 var txt=document.getElementById("ctl00_ContentPlaceHolder1_itemPicUrl").value;
 var i=txt.lastIndexOf("\\");
 var picName=txt.substring(i+1);
 i=picName.lastIndexOf(".");
 txt=picName.substring(i+1).toLowerCase();
 if(txt=="jpg"||txt=="gif"||txt=="png")
 {
 document.getElementById("iType").value=txt;
 document.getElementById("itemPic").style.display="block";
 document.getElementById("itemPic").height=160;
 document.getElementById("itemPic").width=210.
 document.getElementById("itemPic").src=document.getElementById("ctl00_ContentPlaceHolder1_itemPicUrl").value;
 document.getElementById("ctl00_ContentPlaceHolder1_itemPicUrl").setAttribute("verify",true);
 document.getElementById("ctl00_ContentPlaceHolder1_itemPicUrl").setAttribute("state",true);
 }
 else
 {
  alert("格式错误");document.getElementById("ctl00_ContentPlaceHolder1_itemPicUrl").setAttribute("verify",false);
 }
}
function ShowItems()
{
 document.getElementById("nifty").style.display="block";
 document.getElementById("Div2").style.display="none";
}
function AddItems()
{
  document.getElementById("itemName").value="";
  document.getElementById("itemPic").src="";
  document.getElementById("itemPic").style.display="none";
  document.getElementById("itemPrice").value="";
  document.getElementById("context").value="";
  document.getElementById("nifty").style.display="none";
  document.getElementById("Div2").style.display="block";
}
function EditItem(id)
{
 loadType();
 AddItems();
 var object=admin_renewcook_aspx.GetItem(id);
 if(object.value!="")
 {
  data=object.value.split("*");
  document.getElementById("itemName").value=data[0];
  document.getElementById("itemTypeLists").value=data[4];
  document.getElementById("itemPic").src="../"+data[2];
  document.getElementById("itemPic").style.display="block";
  document.getElementById("itemPic").height=160;
  document.getElementById("itemPic").width=210.
  document.getElementById("itemPrice").value=data[1];
  document.getElementById("context").value=data[3];
  document.getElementById("ctl00_ContentPlaceHolder1_itemPicUrl").setAttribute("verify",false);
  document.getElementById("ctl00_ContentPlaceHolder1_itemPicUrl").setAttribute("state",false);
  var txt = document.createElement("input"); 
  txt.name = "itemId";
  txt.id = "itemId"
  txt.type = "hidden"; 
  txt.value = id;
  document.forms[0].appendChild(txt);
  var txt1 = document.createElement("input");
  txt1.name = "itemOldPic";
  txt1.id = "itemOldPic"
  txt1.type = "hidden"; 
  txt1.value = data[2].substring(data[2].lastIndexOf("/")+1);
  document.forms[0].appendChild(txt1);
  document.forms[0].action=document.forms[0].action+"&Edit=0";
 }
}
function Verify_UnBlank(value)
{
  var myReg = /^\s*$/;
  if(myReg.test(value)) return true;
  return false;
}
function CheckForm()
{
 if(Verify_UnBlank(document.getElementById("itemName").value))
 {
  alert("1");
  return false;
 }
 
 if(Verify_UnBlank(document.getElementById("itemPrice").value))
 {
  alert("2");
  return false;
 }
 
 if(document.getElementById("itemPic").state==false)
 {
  if(document.getElementById("itemPic").verify!=true)
   {
     alert("照片非法");
     return false;
   }
   
 }
 else
 {
  if(document.getElementById("itemPic").verify!=true)
   {
     alert("照片非法");
     return false;
   }
 }
 
}