// 路徑設定
rootPath="/";
adminPath=rootPath+"admin/";

// 以下請勿修改
function str_replace(str,org,des) {
  var outStr="";
  while (str.indexOf(org)>=0) {
    outStr+=str.substring(0,str.indexOf(org))+des;
    str=str.substring(str.indexOf(org)+org.length,str.length);
  }
  outStr+=str;
  return outStr;
}

function chgIMG(idx,methods,parentLayer) {
  parentLayer=(parentLayer==null) ? "document.":parentLayer+".doc.";
  if (methods==null) { eval(parentLayer+idx+".src="+idx+"off.src"); }
  else if (methods=="on") { eval(parentLayer+idx+".src = "+idx+"on.src"); }
  else if (methods=="click") { eval(parentLayer+idx+".src = "+idx+"click.src"); }
  else { eval(parentLayer+idx+".src = "+idx+"click.src"); }
}

function addZero(num,digit) {
  num=num+"";
  while (num.length<digit) {
    num="0"+num;
  }
  return num;
}

function str2num(str) {
  str=strSubZero(str);
  if (str.length==0) {str=0;}
  return parseFloat(str);
}

function strSubZero(str) {
  str+="";
  while (str.indexOf("0")==0) {
    str=str.substring(1,str.length);
  }
  if ((str.indexOf(".")==0) || (str=="")) {str="0"+str;}
  return (str);
}

function isNum(str) {
  if (str=="") {return false;}
  str=strSubZero(str);
  num=parseFloat(str);
  if (isNaN(num)) {return false;}
  else {return (str==(num+""));}
}

function isBetween(cpVar,smallVar,largeVar,cpFormat) {
  cpFormat=(cpFormat==null) ? "n":cpFormat;
  switch (cpFormat) {
    case "n": // number
      // no need to change format
      break;
    case "d": // date
      var cpDate,smallDate,largeDate;
      cpDate=cpVar.split(dateSep);
      smallDate=smallVar.split(dateSep);
      largeDate=largeVar.split(dateSep);
      for (var i=0;i<cpDate.length;i++) {
        cpDate[i]=str2num(cpDate[i]);
        smallDate[i]=str2num(smallDate[i]);
        largeDate[i]=str2num(largeDate[i]);
      }
      cpVar=cpDate[0]*366+cpDate[1]*31+cpDate[2];
      smallVar=smallDate[0]*366+smallDate[1]*31+smallDate[2];
      largeVar=largeDate[0]*366+largeDate[1]*31+largeDate[2];
      break;
  }
  if ((cpVar>=smallVar) && (cpVar<=largeVar)) {return true;}
  else {return false;}
}

function writeOptions(itemName,start,end,preset,formName,itemAction,isGet,isDisabled) {
  var str="";
  isGet=(isGet==null) ? false:isGet;
  isDisabled=(isDisabled==null) ? false:isDisabled;
  str+="<select name="+itemName;
  if (itemAction!=null) {str+=' onFocus="'+itemAction+'"';}
  if (isDisabled) {str+=' disabled';}
  str+=">";
  for (var i=start; i<=end; i++) {
    str+="<option value='"+i+"'>"+i+"</option>";
  }
  str+="</select>";
  if (!isGet) {
    document.write(str);
    presetSelect(itemName,preset,formName);
  }
  else {
    formName=(formName!=null) ? ',"'+formName+'"':'';
    return (str+'<script>presetSelect("'+itemName+'","'+preset+'"'+formName+')</script>');
  }
}

function presetSelect(itemName,defaultValue,formName) {
  itemName=(formName==null) ? eval("document.DataInput."+itemName):eval("document."+formName+"."+itemName);
  for (var i=0;i<itemName.length;i++) {
    if (itemName[i].value==defaultValue) {
      itemName[i].selected=true;
      break;
    }
  }
}

function presetRadio(itemName,defaultValue,formName) {
  itemName=(formName==null) ? eval("document.DataInput."+itemName):eval("document."+formName+"."+itemName);
  for (var i=0;i<itemName.length;i++) {
    if (itemName[i].value==defaultValue) {
      itemName[i].checked=true;
      break;
    }
  }
}

function presetCheckbox(itemName,defaultValue,formName) {
  itemName=(formName==null) ? eval("document.DataInput."+itemName):eval("document."+formName+"."+itemName);
  if (itemName.value==defaultValue) {
    itemName.checked=true;
  }
}

function presetDate(form_front,str,formName) {
  docs=(formName==null) ? document.DataInput:eval("document."+formName);
  if (str!="") {
    str=str.split(dateSep);
    eval("docs."+form_front+"year.value="+str[0]);
    eval("docs."+form_front+"month.value="+str[1]);
    eval("docs."+form_front+"day.value="+str[2]);
  }
}

function chkCheckbox(itemName,formName) {
  itemName=(formName==null) ? eval("document.DataInput."+itemName):eval("document."+formName+"."+itemName);
  if (itemName.checked==true) {return true;}
  else {return false;}
}

function chkRadio(itemName,formName) {
  itemName=(formName==null) ? eval("document.DataInput."+itemName):eval("document."+formName+"."+itemName);
  for (var i=0;i<itemName.length;i++) {
    if (itemName[i].checked==true) {
      return true;
      break;
    }
  }

  return false;
}

function chkTXT(itemNameList,formName) {
  itemNameList=itemNameList.split(",");
  for (var i=0;i<itemNameList.length;i++) {
    itemName=(formName==null) ? eval("document.DataInput."+itemNameList[i]):eval("document."+formName+"."+itemNameList[i]);
    if (itemName.value=="") {
      return false;
      break;
    }
  }
  return true;
}

function chkEmail(email) {
  var chkList=new Array("@",".");
  var illegalStr=",/<>;!#$%^&*'\"`?\\";
  if (email.length>0) {
    if (!chkIllegalTXT(email,illegalStr)) {return false;}
    for (var i=0;i<chkList.length;i++) {
      if (email.indexOf(chkList[i])<0) {return false;}
    }
  }
  else {return false;}
  return true;
}

function chkPID(id) {
  var total,str,headStr;
  headStr="ABCDEFGHJKLMNPQRSTUVXYWZIO";

  id=id.toUpperCase();
  if (chkIllegalTXT(id.charAt(0),headStr)) {return false;}
  str=(str2num(headStr.indexOf(id.charAt(0)))+10)+"";
  total=str2num(str.charAt(0))*1+str2num(str.charAt(1))*9;
  for (var i=1;i<9;i++) {
    str=id.charAt(i);
    if (!isNum(str)) {return false;}
    total+=str2num(str)*(9-i);
  }
  total=10-total%10;
  if (total==10) {total=0;}
  if (total!=str2num(id.charAt(i))) {return false;}
  else {return true;}
}

function chkCreditID(id,types) {
  var no,curr,total,str;

  no=id.length;
  total=0;
  for (var i=0;i<no-1;i++) {
    str=id.charAt(i);
    if (!isNum(str)) {return false;}
    curr=str2num(str)*((i%2==0) ? 2:1);
    if (curr>9) {curr-=9;}
    total+=curr;
  }
  total=10-total%10;
  if (total==10) {total=0;}
  if (total!=str2num(id.charAt(i))) {return false;}
  else {return true;}
}

function chkCreditTypes(prefix,types) {
  var creditPrefix=new Array("4","5");
  if (types>creditPrefix.length) {return true;}
  if (prefix!=creditPrefix[types-1]) {return false;}
  else {return true;}
}

function chkIllegalTXT(str,illegalStr) {
  for (var i=0;i<str.length;i++) {
    if (illegalStr.indexOf(str.charAt(i))!=-1) {return false;}
  }
  return true;
}

function chkUserPass(formName) {
  if (!chkTXT("username,password",formName)) {alert("對不起，您必須先填入帳號與密碼！");return false;}
  return true;
}

function setReadonly(itemName,isReadonly,formName) {
  itemName=(formName==null) ? eval("document.DataInput."+itemName):eval("document."+formName+"."+itemName);
  itemName.readOnly=isReadonly;
}

function setItemFocus(itemName,msg,formName) {
  alert(msg);
  itemName=(formName==null) ? eval("document.DataInput."+itemName):eval("document."+formName+"."+itemName);
  itemName.focus();
  return false;
}

function clearItem(itemName) {
  if (itemName.value==itemName.defaultValue) {itemName.value="";}
}

function writeInputDate0(itemName,defaultValue,formName,itemAction,isDisabled,isBrowserButton) {
  var actStr;
  if (defaultValue==null) {defaultValue="1970"+dateSep+"1"+dateSep+"1";}
  str=defaultValue.split(dateSep);
  isDisabled=(isDisabled==null) ? false:isDisabled;
  actStr=(itemAction!=null) ? ' onFocus="'+itemAction+'"':'';
  document.write('<input type="text" name="'+itemName+'year" size="4" maxlength="4" value="'+str[0]+'" class="iTextCenter"'+actStr+((isDisabled) ? ' readonly':'')+'>'+dateStrList[0]);
  document.write('<input type="text" name="'+itemName+'month" size="2" maxlength="2" value="'+str[1]+'" class="iTextCenter"'+actStr+((isDisabled) ? ' readonly':'')+'>'+dateStrList[1]);
  document.write('<input type="text" name="'+itemName+'day" size="2" maxlength="2" value="'+str[2]+'" class="iTextCenter"'+actStr+((isDisabled) ? ' readonly':'')+'>'+dateStrList[2]);
  if (isBrowserButton) {document.write('<input type="button" value="瀏覽" onClick="javascript:selectCalendarDate(\''+itemName+'\')">');}
}

function selectCalendarDate(itemName) {
  eval("itemsWin=window.open('"+langPath+"calendar/calendar.php?db=0&org="+itemName+"&time="+getInputDate0(itemName)+"','itemsWin','height=270,width=250,top=200,left=200,scrollbars=no,resizable=no,menubar=no');");
  itemsWin.focus();
}

function writeInputDate(itemName,defaultValue,formName,itemAction) {
  if (defaultValue==null) {defaultValue="1970"+dateSep+"1"+dateSep+"1";}
  str=defaultValue.split(dateSep);
  document.write('西元<input type="text" name="'+itemName+'year" size="4" maxlength="4" value="'+str[0]+'"');
  if (itemAction!=null) {document.write(' onFocus="'+itemAction+'"');}
  document.write(' class="iText">'+dateStrList[0]);
  writeOptions(itemName+"month",1,12,str2num(str[1]),formName,itemAction);
  document.write(dateStrList[1]);
  writeOptions(itemName+"day",1,31,str2num(str[2]),formName,itemAction);
  document.write(dateStrList[2]);
}

function presetDate1(form_front,str,formName) {
  docs=(formName==null) ? document.DataInput:eval("document."+formName);
  if (str!="") {
    str=str.split(dateSep);
    eval("docs."+form_front+"year.value="+str[0]);
    presetSelect(form_front+"month",str2num(str[1]),formName);
    presetSelect(form_front+"day",str2num(str[2]),formName);
  }
}

function writeInputDate2(itemName,defaultValue,formName,itemAction) {
  var yearArray=new Array(3);
  if (defaultValue==null) {defaultValue="1970"+dateSep+"1"+dateSep+"1";}
  str=defaultValue.split(dateSep);
  yearArray[0]=str[0].substring(0,1);
  yearArray[1]=str[0].charAt(2);
  yearArray[2]=str[0].charAt(3);
  document.write('西元');
  writeOptions(itemName+"year_0",19,20,str2num(yearArray[0]),formName,itemAction);
  writeOptions(itemName+"year_1",0,9,str2num(yearArray[1]),formName,itemAction);
  writeOptions(itemName+"year_2",0,9,str2num(yearArray[2]),formName,itemAction);
  document.write(dateStrList[0]);
  writeOptions(itemName+"month",1,12,str2num(str[1]),formName,itemAction);
  document.write(dateStrList[1]);
  writeOptions(itemName+"day",1,31,str2num(str[2]),formName,itemAction);
  document.write(dateStrList[2]);
}

function writeInputDate3(itemName,defaultValue,formName,itemAction,yearRange,isDisabled) {
  if (defaultValue==null) {defaultValue="1970-1-1";}
  isDisabled=(isDisabled==null) ? false:isDisabled;
  yearRange=(yearRange==null) ? "-3,5":yearRange;
  str=defaultValue.split("-");
  yearRange=yearRange.split(",");
  writeOptions(itemName+"year",str2num(str[0])+str2num(yearRange[0]),str2num(str[0])+str2num(yearRange[1]),str2num(str[0]),formName,itemAction,null,isDisabled);
  document.write(dateStrList[0]);
  writeOptions(itemName+"month",1,12,str2num(str[1]),formName,itemAction,null,isDisabled);
  document.write(dateStrList[1]);
  writeOptions(itemName+"day",1,31,str2num(str[2]),formName,itemAction,null,isDisabled);
  document.write(dateStrList[2]);
}

function writeInputTime(itemName,defaultValue,formName) {
  if (defaultValue==null) {defaultValue="00:00:00";}
  str=defaultValue.split(":");
  document.write('<input type="text" name="'+itemName+'hour" size="3" maxlength="2" value="'+str[0]+'" class="iText">'+dateStrList[3]);
  document.write('<input type="text" name="'+itemName+'minute" size="3" maxlength="2" value="'+str[1]+'" class="iText">'+dateStrList[4]);
  document.write('<input type="text" name="'+itemName+'second" size="3" maxlength="2" value="'+str[2]+'" class="iText">'+dateStrList[5]);
}

function writeInputTime2(itemName,defaultValue,formName) {
  if (defaultValue==null) {defaultValue="00:00:00";}
  str=defaultValue.split(":");
  writeOptions(itemName+"hour",0,23,str2num(str[0]),formName);
  document.write(dateStrList[3]);
  writeOptions(itemName+"minute",0,59,str2num(str[1]),formName);
  document.write(dateStrList[4]);
  writeOptions(itemName+"second",0,59,str2num(str[2]),formName);
  document.write(dateStrList[5]);
}

function getInputDate0(itemName,formName) {
  docs=(formName==null) ? document.DataInput:eval("document."+formName);
  itemYear=eval("docs."+itemName+"year");
  itemMonth=eval("docs."+itemName+"month");
  itemDay=eval("docs."+itemName+"day");
  if (!isNum(itemYear.value)) {return false;}
  chk_year=parseInt(itemYear.value);
  chk_year=(chk_year>1800) ? chk_year:chk_year+1911;
  return (chk_year+dateSep+addZero(itemMonth.value,2)+dateSep+addZero(itemDay.value,2));
}

function getInputDate(itemName,formName) {
  docs=(formName==null) ? document.DataInput:eval("document."+formName);
  itemYear=eval("docs."+itemName+"year");
  itemMonth=eval("docs."+itemName+"month");
  itemDay=eval("docs."+itemName+"day");
  if (!isNum(itemYear.value)) {return false;}
  chk_year=parseInt(itemYear.value);
  chk_year=(chk_year>1800) ? chk_year:chk_year+1911;
  return (chk_year+dateSep+itemMonth[itemMonth.selectedIndex].value+dateSep+itemDay[itemDay.selectedIndex].value);
}

function getInputDate2(itemName,formName) {
  docs=(formName==null) ? document.DataInput:eval("document."+formName);
  itemYear0=eval("docs."+itemName+"year_0");
  itemYear1=eval("docs."+itemName+"year_1");
  itemYear2=eval("docs."+itemName+"year_2");
  itemMonth=eval("docs."+itemName+"month");
  itemDay=eval("docs."+itemName+"day");
  return (itemYear0[itemYear0.selectedIndex].value+itemYear1[itemYear1.selectedIndex].value+itemYear2[itemYear2.selectedIndex].value+dateSep+addZero(itemMonth[itemMonth.selectedIndex].value,2)+dateSep+addZero(itemDay[itemDay.selectedIndex].value,2));
}

function getInputDate3(itemName,formName) {
  docs=(formName==null) ? document.DataInput:eval("document."+formName);
  itemYear=eval("docs."+itemName+"year");
  itemMonth=eval("docs."+itemName+"month");
  itemDay=eval("docs."+itemName+"day");
  return (itemYear[itemYear.selectedIndex].value+"-"+addZero(itemMonth[itemMonth.selectedIndex].value,2)+"-"+addZero(itemDay[itemDay.selectedIndex].value,2));
}

function getInputTime(itemName,formName) {
  var timePart=new Array(3);
  var timeLength=new Array(100,60,60);
  docs=(formName==null) ? document.DataInput:eval("document."+formName);
  timePart[0]=eval("docs."+itemName+"hour.value");
  timePart[1]=eval("docs."+itemName+"minute.value");
  timePart[2]=eval("docs."+itemName+"second.value");
  for (var i=0;i<timeLength.length;i++) {
    if (!isNum(timePart[i])) {return false;}
    else {
      if (str2num(timePart[i])>=timeLength[i]) {return false;}
    }
  }
  return (addZero(timePart[0],2)+":"+addZero(timePart[1],2)+":"+addZero(timePart[2],2));
}

function getInputTime3(itemName,formName) {
  if (formName==null) {
    itemHour=eval("document.DataInput."+itemName+"hour");
    itemMinute=eval("document.DataInput."+itemName+"minute");
    itemSecond=eval("document.DataInput."+itemName+"second");
  }
  else {
    itemYear=eval("document."+formName+"."+itemName+"hour");
    itemMonth=eval("document."+formName+"."+itemName+"minute");
    itemDay=eval("document."+formName+"."+itemName+"second");
  }
  return (addZero(itemHour[itemHour.selectedIndex].value,2)+":"+addZero(itemMinute[itemMinute.selectedIndex].value,2)+":"+addZero(itemSecond[itemSecond.selectedIndex].value,2));
}

function getSelect(itemName,formName) {
  itemName=(formName==null) ? eval("document.DataInput."+itemName):eval("document."+formName+"."+itemName);
  return (itemName[itemName.selectedIndex].value);
}

function getRadio(itemName,formName) {
  itemName=(formName==null) ? eval("document.DataInput."+itemName):eval("document."+formName+"."+itemName);
  if (typeof itemName.length=="number") {
    for (var i=0;i<itemName.length;i++) {
      if (itemName[i].checked==true) {
        return (itemName[i].value);
      }
    }
  }
  else {
    if (itemName.checked==true) {
      return (itemName.value);
    }
  }
  return "";
}

function getFilename(fileStr,dirStr) {
  dirStr=(dirStr==null) ? "\\":dirStr;
  if (fileStr=="") {return "";}
  else {return fileStr.substring(fileStr.lastIndexOf(dirStr)+1,fileStr.length);}
}

function getFilenameExt(fileStr) {
  if (fileStr=="") {return "";}
  else {return fileStr.substring(fileStr.lastIndexOf("."),fileStr.length);}
}

function getCurrency(num,digit) {
  var no,max,str="",isDigit;
  isDigit=(digit==null) ? false:true;
  num=num+"";
  num=num.split(".");
  if (num.length==2) {
    if (isDigit) {num[1]=addZero(num[1],digit);}
    str="."+num[1];
  }
  max=num[0].length;
  no=Math.ceil(max/3);
  for (var i=0;i<no;i++) {
    if (i!=0) {str=","+str;}
    str=num[0].substring(max-3,max)+str;
    max-=3;
  }
  return str;
}

function closeMe(winName) {
  winName=(winName==null) ? "self":winName;
  eval(winName+".close()");
}

function goBack() {
  document.write('<p>[<a href="javascript:history.go(-1)">'+miscStrList[3]+'</a>]');
}

// *
function writeSearchList() {
  var str="";
  str+='<select name="db" size="1" class="t3">';
  str+='<option value="">'+miscStrList[5]+miscStrList[6]+'</option>';
  for (var i=0;i<(productGroupList[0].length/5);i++) {
    str+='<option value="'+productGroupList[0][i*5]+'">'+productGroupList[0][i*5+1]+'</option>';
  }
  str+='</select>';
  document.write(str);
}

function writeTopNavMenu() {
  var str='';
  for (var i=0;i<2;i++) {
    if (i!=0) {str+='<td><img src="'+rootPath+'pic/empty.gif" width="11" height="1"></td>';}
    str+='<td><a href="'+unsslPath+'product/index.php?db='+productGroupList[0][i*5]+'">'+productGroupList[0][i*5+1]+'</a></td>';
  }
  document.write(str);
}

function writeMenu(groups) {
  var str='',strTmp='',listStr,mainGroups,counts;
  groups=(groups==null) ? 0:groups;

  listStr=getProductGroupRelativeList(groups);
  mainGroups=getMainProductGroupID(groups);
  level=0;
  str=getMenuLinks(listStr,mainGroups,level);
  str='<table width="204" border="0" cellspacing="0" cellpadding="0" name="菜色提供表格"><tr><td bgcolor="EFF0F0" width="11" height="10"><img src="'+langPath+'graphics/left-menu01.gif" width="11" height="10"></td><td bgcolor="#EFF0F0"><img src="'+rootPath+'pic/empty.gif" width="1" height="1"></td><td bgcolor="#EFF0F0" width="11" height="10"><img src="'+langPath+'graphics/left-menu02.gif" width="11" height="10"></td></tr><tr><td bgcolor="#EFF0F0">&nbsp;</td><td bgcolor="#EFF0F0"><img src="'+langPath+'graphics/menu.gif" title="烤肉菜色提供" width="181" height="64"><br><table width="100%" border="0" cellspacing="1" cellpadding="1">'+str+'</table></td><td bgcolor="#EFF0F0">&nbsp;</td></tr><tr><td width="11" height="10"><img src="'+langPath+'graphics/left-menu03.gif" width="11" height="10"></td><td bgcolor="#EFF0F0"><img src="'+rootPath+'pic/empty.gif" width="1" height="1"></td><td width="11" height="10"><img src="'+langPath+'graphics/left-menu04.gif" width="11" height="10"></td></tr></table>';

  document.write(str);
}

function getMenuLinks(listStr,mainGroups,level) {
  if (level>2) {return "";} //防止過多層
  var rowStyleList=new Array(
  //level0
  '', //header
  '', //footer
  '<tr><td width="9">%ARROW%</td><td width="195"><a href="%URL%">%GROUPNAME%</a></td></tr>',//link string
  //level1
  '',
  '',
  '<tr><td>&nbsp;</td><td><a href="%URL%">%GROUPNAME%</a></td></tr>',
  //level2
  '<tr><td>&nbsp;</td><td><table width="100%" border="0" cellspacing="1" cellpadding="2">',
  '</td></tr></table>',
  '<tr><td>&nbsp;</td><td>&nbsp;&nbsp;&nbsp;<a href="%URL%">%GROUPNAME%</a></td></tr>');
  var counts,str='',tempStr='',listStr_org,tempListIdx;
  var imgStr='<img src="'+langPath+'graphics/triangle.gif" width="9" height="9">';
  var sepImg='<tr><td colspan="2"><img src="'+langPath+'graphics/dot-line.gif" width="197" height="3"></td></tr>';

// show all
  listStr=getProductGroupRelativeList(mainGroups);

  listStr_org=listStr;
  listStr=listStr.split(",");
  tempListIdx=searchValue("productIdxList",listStr[level],"0,2,4");

//  if ((tempListIdx==0) || ((tempListIdx>0) && (searchValue("productIdxList",listStr[level],"0,2,4")>0))) {
if ((tempListIdx==0) || (tempListIdx>0)) {
    counts=productGroupList[tempListIdx].length;
//    str+=rowStyleList[level*3];
    for (var i=0;i<counts;i++) {
      if (productGroupList[tempListIdx][i*5+4]==1) {
        curr_URL=unsslPath+'product/index.php?db='+productGroupList[tempListIdx][i*5];
        curr_Group=productGroupList[tempListIdx][i*5+1];
        tempStr=str_replace(str_replace(rowStyleList[level*3+2],"%GROUPNAME%",curr_Group),"%URL%",curr_URL);

        // 主項目箭頭
        //if ((level==0) && (productGroupList[tempListIdx][i*5]==mainGroups)) {
        if (level==0) {
          tempStr=str_replace(tempStr,"%ARROW%",imgStr);
          // 分隔線
          if (i!=0) {tempStr=sepImg+tempStr;}
        }
        else {tempStr=str_replace(tempStr,"%ARROW%",'&nbsp;');}        

        // 子項目
//        if ((productGroupList[tempListIdx][i*5]==listStr[level+1]) && (productGroupList[tempListIdx][i*5+2]==1) && (productGroupList[tempListIdx][i*5+4]==1)) {
//        if ((mainGroups!=0) && ((level==0) || (level==1)) && (productGroupList[tempListIdx][i*5+2]==1) && (productGroupList[tempListIdx][i*5+4]==1)) {
        if (((level==0) || (level==1)) && (productGroupList[tempListIdx][i*5+2]==1) && (productGroupList[tempListIdx][i*5+4]==1)) {
//          tempStr+=getMenuLinks(listStr_org,mainGroups,level+1);
          tempStr+=getMenuLinks(listStr_org,productGroupList[tempListIdx][i*5],level+1);
        }

        // 選擇的類別放置於第一項
//        if ((productGroupList[tempListIdx][i*5]==listStr[level+1]) && (level!=2)) {str=tempStr+str;}
//        else {str+=tempStr;}
        str+=tempStr;
      }
    }
//    str+=rowStyleList[level*3+1];
  }

  return (str);
}

// ----- misc effect -----
function writePicBlock(picFile,picAlign,picDesc,picTitle,size,picLink,border,isNewBrowser,misc,lyrName) {
  var alignList=new Array("center","left","right");
  if (picDesc==null) {picDesc="";}
  picTitle=(picTitle==null) ? picDesc:picTitle;
  picAlign=(picAlign==null) ? 0:picAlign;
  border=(border==null) ? 0:border;
  isNewBrowser=(isNewBrowser==null) ? false:isNewBrowser;
  isFlash=(getFilenameExt(picFile)==".swf");
  picSize="";
  if (!((size==null) || (size==","))) {
    size=size.split(",");
    if (size[0]!="") {picSize=' width="'+size[0]+'"';}
    if (size[1]!="") {picSize+=' height="'+size[1]+'"';}
  }
  str="";
  if (picFile=="") {return true;}
  if (picDesc!="") {
    str+='<table border="0" cellspacing="2" cellpadding="2" align="'+alignList[picAlign]+'"><tr><td><div class="divCenter">';
  }
  if ((picLink!=null) && (picLink!="")) {
    str+='<a href="'+picLink+'"';
    if (isNewBrowser) {str+=' target="_blank"';}
    str+='>';
  }
  if (!isFlash) {
    str+='<img src="'+rootPath+picFile+'" border="'+border+'"'+picSize;
    if (misc!=null) {str+=misc;}
  }
  else {
    str+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"'+picSize+'><param name="movie" value="'+rootPath+picFile+'"><param name="quality" value="high"><PARAM NAME="wmode" VALUE="transparent"><PARAM NAME="PLAY" VALUE="true"><PARAM NAME="LOOP" VALUE="true"><embed src="'+rootPath+picFile+'" quality="high" PLAY="true" LOOP="true" WMODE="transparent" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"'+picSize+'></embed></object';
  }
  if (picDesc=="") {
    if (!isFlash) {
      if (picTitle!="") {str+=' title="'+picTitle+'" title="'+picTitle+'"';}
      str+=' align="'+alignList[picAlign]+'"';
    }
    str+='>';
    if ((picLink!=null) && (picLink!="")) {str+='</a>';}
  }
  else {
    str+='>';
    if ((picLink!=null) && (picLink!="")) {str+='</a>';}
    str+='</div></td></tr><tr><td class="colDBlue">'+miscStrList[4]+picDesc+'</td></tr></table>';
  }
  if ((lyrName!=null) && (isFlash) && (!isIE)) {
    str='<table border="0" cellspacing="0" cellpadding="0"'+((picAlign==0) ? ' align="center"':'')+'><tr><td><img src="'+rootPath+'pic/empty.gif" height="'+size[1]+'" width="1"></td><td><div id="'+lyrName+'" style="display: ">'+str+'</div></td></tr></table>';
    isFlashLyr=true;
  }
  else if (isFlash) {
    str='<table border="0" cellspacing="0" cellpadding="0" align="'+alignList[picAlign]+'"><tr><td>'+str+'</td></tr></table>';
  }

  if (picAlign==0) {str='<div class="divCenter">'+str+'</div>';}

  document.write(str);
}


function isPicFile(str) {
  str=getFilenameExt(str);
  for (var i=0;i<mediaExtList.length;i++) {
    if (mediaExtList[i]==str) {return true;}
  }
  return false;
}

function viewAttachFile(str) {
  if (isPicFile(str)) {viewPic(str);}
  else {location.href=str;}
}

function viewPic(str) {
  eval("previewWin=window.open(str,'previewWin','height=500,width=650,top=20,left=30,scrollbars=yes,resizable=yes,menubar=no');");
  previewWin.focus();
}

function viewFlash(filename,size) {
  size=size.split(",");
  eval("previewWin=window.open('demo.php?file='+filename,'previewWin','width="+size[0]+",height="+size[1]+",top=20,left=30,scrollbars=no,resizable=no,menubar=no');");
  previewWin.focus();
}

function searchValue(listName,values,para) {
  para=(para==null) ? "0,1,2":para;
  para=para.split(",");
  eval("var localListName="+listName);
  for (var i=0;i<3;i++) {
    para[i]=str2num(para[i]);
  }
  for (var i=0;i<(localListName.length/para[2]);i++) {
    if (localListName[i*para[2]+para[0]]==values) {return localListName[i*para[2]+para[1]]; break;}
  }
  return "";
}

function searchValueIdx(listName,values,para) {
  para=(para==null) ? "0,2":para;
  para=para.split(",");
  eval("var localListName="+listName);
  for (var i=0;i<2;i++) {
    para[i]=str2num(para[i]);
  }
  for (var i=0;i<(localListName.length/para[1]);i++) {
    if (localListName[i*para[1]+para[0]]==values) {return i; break;}
  }
  return -1;
}

function getDateStringx(thisDate) {
  var thisDateArray;
  thisDateArray=thisDate.split("-");
  return (thisDateArray[0]+dateStrList[0]+str2num(thisDateArray[1])+dateStrList[1]+str2num(thisDateArray[2])+dateStrList[2]);
}

function archiveUrlGo(itemName,script_link,act) {
  act=(act==null) ? "list":act;
  location.href=script_link+"?act="+act+"&gp="+itemName[itemName.selectedIndex].value;
}

function quickSearch(form) {
  docs=form;
  if (docs.keyword.value=="") {alert(miscStrList[0]);return false;}
  else {return true;}
}

function searchKeyword(formName) {
  docs=(formName==null) ? document.DataInput:eval("document."+formName);
  location.href=docs.searchRef.value+"&keyword="+docs.keyword.value;
}

function checkAdvSearchValue(form) {
//  if (form.keyword.value=="") {alert(miscStrList[0]);return false;}
  return true;
}

function writeNewPageNavBar(db,order,page,totalPage,size,script_link,keyword,misc,width,pageSize) {
  if (size==0) {return true;}
  pageSize=(pageSize==null) ? 10:pageSize;
  currSection=Math.ceil(page/10)-1;
  str="";
  misc=(misc==null) ? "":misc;
  str="";
  str+='<table '+width+' border="0" cellspacing="0" cellpadding="3"><tr>';
  str+='<td><div class="divCenter">&nbsp;'; //+getPageTotalStr(page,totalPage,size)+'';
  if (keyword!="") {misc+="&keyword="+keyword;}
  if (page!=1) {str+='<a href="'+script_link+'?db='+db+'&page='+(page-1)+'&order='+order+misc+'">'+pageBarStrList[5]+'</a>&nbsp;&nbsp;';}
  if (currSection!=0) {str+='<a href="'+script_link+'?db='+db+'&page='+(currSection*10)+'&order='+order+misc+'">&lt;&lt;</a>&nbsp;';}
  for (var i=0;i<10;i++) {
    currPage=currSection*10+i+1;
    if (currPage>totalPage) {break;}
    if (i!=0) {str+=pageBarStrList[4];}
    if (currPage!=page) {str+='<a href="'+script_link+'?db='+db+'&page='+currPage+'&order='+order+misc+'">'+currPage+'</a>';}
    else {str+='<span class="colDRed">'+currPage+'</span>';}
  }
  if (currSection<(Math.ceil(totalPage/10)-1)) {str+='&nbsp;<a href="'+script_link+'?db='+db+'&page='+((currSection+1)*10+1)+'&order='+order+misc+'">&gt;&gt;</a>';}
  if (page!=totalPage) {str+='&nbsp;&nbsp;<a href="'+script_link+'?db='+db+'&page='+(page+1)+'&order='+order+misc+'">'+pageBarStrList[6]+'</a>';}
  str+='&nbsp;</div></td></tr></table>';
  document.writeln(str);
}

function writePageNavBar2(db,order,page,totalPage,size,script_link,keyword,misc,width) {
//  if (size==0) {return true;}
  currSection=Math.ceil(page/10)-1;
  var cellTag=pageBarStrList[4], pgcellTag="&nbsp;";
  misc=(misc==null) ? "":misc;
  str="";
  str+='<table'+width+' border="0" class="bgWhite" cellspacing="0" cellpadding="3"><tr>';
  if (keyword!="") {misc+="&keyword="+keyword;}
  str+='<td class="colDBlue"><div class="divCenter">';
  if (currSection!=0) {str+='<a href="'+script_link+'?db='+db+'&page='+(currSection*10)+'&order='+order+misc+'">&lt;&lt;</a>'+pgcellTag;}
  for (var i=0;i<10;i++) {
    currPage=currSection*10+i+1;
    if (currPage>totalPage) {break;}
    else {
      if (i!=0) {str+=cellTag;}
    }
    if (currPage!=page) {str+='<a href="'+script_link+'?db='+db+'&page='+currPage+'&order='+order+misc+'"><span class="chrULine">'+currPage+'</span></a>';}
    else {str+='<span class="colRed">'+currPage+'</span>';}
  }
  if (currSection<(Math.ceil(totalPage/10)-1)) {str+=pgcellTag+'<a href="'+script_link+'?db='+db+'&page='+((currSection+1)*10+1)+'&order='+order+misc+'">&gt;&gt;</a>';}
  str+='</div></td>';
  str+='</tr></table>';
  document.writeln(str);
}

function getPageTotalStr(page,totalPage,size) {
  var startNo,endNo,str;
  str="";
  startNo=(page-1)*10+1;
  endNo=(page==totalPage) ? size:(page*10);
  return (pageBarStrList[1]+size+pageBarStrList[2]+page+pageBarStrList[3]);
}

function writeNew2PageNavBar(db,order,page,totalPage,size,script_link,keyword,misc,width) {
  var pageSize=10;
  if (size==0) {return true;}
  currSection=Math.ceil(page/10)-1;
  str="";
  misc=(misc==null) ? "":misc;
  str="";
  str+='<table '+width+' border="0" cellspacing="0" cellpadding="0"><tr bgcolor="#ddeedd">';
  str+='<td class="p3">&nbsp;'+getTotalSizeStr(size,keyword)+',&nbsp;'+pageBarStrList[4]+": ";
  if (keyword!="") {misc+="&keyword="+keyword;}
  if (currSection!=0) {str+='<a href="'+script_link+'?db='+db+'&page='+(currSection*10)+'&order='+order+misc+'">&lt;&lt;</a> ';}
  for (var i=0;i<pageSize;i++) {
    currPage=currSection*10+i+1;
    if (currPage>totalPage) {break;}
    if (currPage!=page) {str+='<a href="'+script_link+'?db='+db+'&page='+currPage+'&order='+order+misc+'">'+currPage+'</a> ';}
    else {str+='<span class="itemRed">-'+currPage+'-</span> ';}
  }
  if (currSection<(Math.ceil(totalPage/10)-1)) {str+='<a href="'+script_link+'?db='+db+'&page='+((currSection+1)*10+1)+'&order='+order+misc+'">&gt;&gt;</a>';}
  str+='</td>';
  str+='<td class="p3"><div class="divRight">'+getPageTotal2Str(page,totalPage);
  str+='&nbsp;</div></td></tr></table>';
  document.writeln(str);
}

function getTotalSizeStr(size,keyword) {
  var str;
  str=((langID!=0) ? '共 '+size+' 項資料':(size+((size>1) ? ' Entries':' Entry')));
  if (keyword!="") {
    str+=((langID!=0) ? '與 「<span class="colRed">'+keyword+'</span>」 有關':' about "<span class="colRed">'+keyword+'</span>"');
  }
  return str;
}

function getPageTotal2Str(page,totalPage) {
  return ((langID!=0) ? "第 "+page+" 頁（共 "+totalPage+" 頁）":"Page "+page+" of <b>"+totalPage+"</b>");
}

function writeRealname(id) {
  document.write(searchValue("adminInfoList",id));
}

function writeDepartment(id) {
  document.write(searchValue("departmentList",id));
}

function getTimeString(thisTime) {
  var thisTimeArray;
  thisTimeArray=thisTime.split(":");
  if (timeType==1) {
    thisTimeArray[0]=str2num(thisTimeArray[0]);
    if (thisTimeArray[0]>=12) {
      timePeriod="pm";
      thisTimeArray[0]-=12;
    }
    else {
      timePeriod="am";
    }
    if (thisTimeArray[0]==0) {thisTimeArray[0]+=12;}
    return thisTimeArray[0]+":"+thisTimeArray[1]+" "+timePeriod;
  }
  else {return thisTimeArray[0]+":"+thisTimeArray[1];}
}

//dFormat=0,1->no week; 2->w/ week string
function getDateString(thisDate,dFormat) {
  var thisDateArray;
  dFormat=((dFormat==null) || (dFormat=="")) ? 0:str2num(dFormat);
  thisDateArray=thisDate.split("-");
  for (var i=0;i<thisDateArray.length;i++) {
    thisDateArray[i]=str2num(thisDateArray[i]);
  }
  var showDateObj=new Date();
  showDateObj.setYear(thisDateArray[0]);
  showDateObj.setMonth(thisDateArray[1]-1);
  showDateObj.setDate(thisDateArray[2]);
  weekStr=(dFormat>=2) ? weekdayList[showDateObj.getDay()*2+langID]:"";

  if (langID!=0) {
    if (weekStr!="") {weekStr="（"+weekStr+"）";}
    if ((dFormat==null) || (dFormat==0)) {return thisDateArray[0]+"年"+thisDateArray[1]+"月"+thisDateArray[2]+"日"+weekStr;}
    else {
      if (dFormat!=3) {return "民國"+(thisDateArray[0]-1911)+"年"+thisDateArray[1]+"月"+thisDateArray[2]+"日"+weekStr;}
      else {return thisDateArray[0]+"年"+thisDateArray[1]+"月"+thisDateArray[2]+"日"+weekStr;}
    }
  }
  else {
    if ((dFormat==null) || (dFormat==0)) {return thisDate;}
    else {
      if (weekStr!="") {weekStr+=", ";}
      if (dFormat!=3) {
        dayTest=str2num(thisDateArray[2]);
        if (dayTest<=3) {thisDateArray[2]+=numberOrderList[thisDateArray[2]-1];}
        else if ((isBetween(dayTest,21,23)) || (dayTest==31)) {thisDateArray[2]+=numberOrderList[(dayTest%10)-1];}
        else {thisDateArray[2]+="th";}
      }
      return ((dFormat==3) ? "":weekStr)+((dFormat==3) ? monthList[(thisDateArray[1]-1)*2].substring(0,3):monthList[(thisDateArray[1]-1)*2])+" "+thisDateArray[2]+" "+thisDateArray[0];
    }
  }
}

function writeCopyright() {
  str="";
  str+='<table width="95%" border="0" cellspacing="0" cellpadding="0"><tr bgcolor="E7F6FE"><td>';
  str+='<div align="center" class="t2">&copy;2004 BBQTaiwan 台灣烤肉網</div></td></tr></table>';
  document.write(str);
}

function winTellFriend(urlStr) {
  eval("tellWin=window.open(langPath+'tellfriend/form.php?url='+escape(urlStr),'tellWin','width=480,height=500,left=10,top=10,scrollbars=no,resizable=yes,menubar=no');");
  tellWin.focus();
}

function writeMiscList(tagname,defaultValue,arrayname,isNullItem,actions,para,nullItemText,formName) {
  docs=(formName==null) ? document.DataInput:eval("document."+formName);
  arrayname=(arrayname==null) ? tagname+"List":arrayname;
  isNullItem=(isNullItem==null) ? true:isNullItem;
  para=(para==null) ? "0,1,2":para;
  para=para.split(",");
  for (var i=0;i<3;i++) {
    para[i]=str2num(para[i]);
  }
  eval("var curr_JSmenu="+arrayname);
  str='<select name="'+tagname+'"';
  if (actions!=null) {str+=' onChange="'+actions+'"';}
  str+='>';
  if (isNullItem) {
    str+='<option value="">'+((nullItemText!=null) ? nullItemText:miscStrList[3])+'</option>';
  }

  for (var i=0;i<(curr_JSmenu.length/para[2]);i++) {
    str+='<option value="'+curr_JSmenu[i*para[2]+para[0]]+'">'+curr_JSmenu[i*para[2]+para[1]]+'</option>';
  }
  str+='</select>';
  document.write(str);
  presetSelect(tagname,defaultValue,formName);
}

function writeRadioList(tagname,defaultValue,arrayname,actions,para,formName) {
  docs=(formName==null) ? document.DataInput:eval("document."+formName);
  arrayname=(arrayname==null) ? tagname+"List":arrayname;
  para=(para==null) ? "0,1,2":para;
  para=para.split(",");
  str="";
  for (var i=0;i<3;i++) {
    para[i]=str2num(para[i]);
  }
  eval("var curr_JSmenu="+arrayname);

  for (var i=0;i<(curr_JSmenu.length/para[2]);i++) {
    str+='<input type="radio" name="'+tagname+'"';
    if (actions!=null) {str+=' onClick="'+actions+'"';}
    str+=' value="'+curr_JSmenu[i*para[2]+para[0]]+'">'+curr_JSmenu[i*para[2]+para[1]]+'<br>';
  }
  document.write(str);
  presetRadio(tagname,defaultValue,formName);
}

isIE=(navigator.appName=="Microsoft Internet Explorer");

var dateSep="-";
var daysOfMonthList=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var numberOrderList=new Array("st","nd","rd","th");
var weekdayList=new Array("Sunday","日","Monday","一","Tuesday","二","Wednesday","三","Thursday","四","Friday","五","Saturday","六");
var monthList=new Array("January","一月","February","二月","March","三月","April","四月","May","五月","June","六月","July","七月","August","八月","September","九月","Octorber","十月","November","十一月","December","十二月");
var mediaExtList=new Array(".gif",".jpg",".jpeg",".png",".doc",".pdf",".htm",".html",".swf");
var fileExtList=new Array(".gif",".jpg",".jpeg",".png",".doc",".htm",".html",".pdf",".zip",".txt",".xls",".ppt");
var booleanStatus=new Array(false,true);
text4NCRate=0.6;
langID=(typeof langID=="number") ? langID:0;

// *
function writeHeaderHight() {
  document.write('<img src="'+rootPath+'pic/empty.gif" width="1" height="'+((isIE) ? '65':'64')+'">');
}

function writeSearchInput(keyword,textLength) {
  textLength=(isIE) ? textLength:Math.round(textLength*text4NCRate);
  document.write('<input type="text" style="background-color: #FFFFFF; border: #224C77 1px solid; color: #224C77" name="keyword" size="'+textLength+'" class="iText" value="'+keyword+'">');
}

function writeBrandStoryList() {
 var str,no,order;
  order=brandSortList.split("*/");
  order=order[1].split(",");
  no=order.length;
  str='<select name="brandSelect" size="1" onChange="location.href=unsslPath+\'product/story.php?db=\'+this[this.selectedIndex].value"><option value="" selected="true">品牌故事</option>';
  for (var i=0;i<no;i++) {
    order[i]=str2num(order[i]);
    str+='<option value="'+order[i]+'">'+searchValue("brandStoryList",order[i],"0,1,2")+'</option>';
  }
  str+='</select>';

  document.write(str);
}

// download/index.asp
function getFilesizeStr(filesize) {
  filesize=Math.round(filesize/1024);
  unitStr=(filesize>=1024) ? "MB":"KB"
  if (filesize>=1024) {filesize=Math.round(filesize*10/1024)/10;}
  return (filesize+unitStr);
}

function getFileExtStr(fileExt) {
  var str;
  str="."+fileExt;
  for (var i=0;i<fileExtList.length;i++) {
    if (fileExtList[i]==str) {return fileExtStrList[i*2+1];}
  }
  return fileExt.toUpperCase();
}

function goDownloadDetail(id,link) {
  link=(link==null) ? langPath+'download/view.php?id='+id:link;
  eval("viewWin=window.open(link,'viewWin','scrollbars=yes,resizable=yes,width=350,height=325,left=30,top=100');");
  viewWin.focus();
}

// contact/index.php
function checkContactForm(isAdmin) {
  docs=document.DataInput;
  if (!isAdmin) {docs.action="save_contact.php";}
  if (!chkTXT("title,email,comment0")) {alert("對不起，標記 * 的項目必須填寫！");return false;}
  if ((chkTXT("email")) && (!chkEmail(docs.email.value))) {alert("對不起，您的電子郵件信箱錯誤，請再檢查一次！");return false;}
  if (getRadio("types")=="")  {alert("對不起，您必須選擇您的建議類別（如商品意見、付費問題...），\n請再檢查一次！");return false;}

  docs.submit();
//  return true;
}

// product/*
function writeProductSitemapPosition(groups,id,isAdmin) {
  var str,listStr,groupStr,productStr,tempListIdx,productUrlPrefix,tmpId;
  str="";
  isAdmin=(isAdmin==null) ? false:isAdmin;
  if (isAdmin) {
    productUrlPrefix=adminPath+'product/groups/list.php';
  }
  else {
    productUrlPrefix=langPath+'product/index.php';
  }
//  groupStr=' &gt;&gt; <span class="colRed">%GroupName%</span>';
  groupStr=' &gt;&gt; %GroupName%';
  groupLinkStr=' &gt;&gt; <a href="'+productUrlPrefix+'?db=%GroupID%">%GroupName%</a>';
  productStr=' &gt;&gt; <a href="'+productUrlPrefix+'">商品介紹</a>';
  listStr=getProductGroupRelativeList(groups);
  listStr=listStr.split(",");
  if (listStr.length>1) {
    for (var i=1;i<listStr.length;i++) {
      listStr[i]=str2num(listStr[i]);
      tempListIdx=searchValue("productIdxList",listStr[i],"0,1,4");
      tmpId=((i==listStr.length-1) ? id:1);
      if ((isAdmin) && (searchValue("productGroupList["+tempListIdx+"]",listStr[i],"0,3,5")==1)) {tmpId=1;}
      isShowGroup=(!isAdmin) ? (searchValue("productGroupList["+tempListIdx+"]",listStr[i],"0,2,5")==1):true;
      str+=getColorGroupText(searchValue("productGroupList["+tempListIdx+"]",listStr[i],"0,1,5"),groupStr,listStr[i],tmpId,isShowGroup,isAdmin)
    }
  }
  if (isAdmin==false) {
    if (groups==0) {str=getColorGroupText("商品介紹",groupStr,0,0,false,isAdmin);}
    else {str=productStr+str;}
    document.write('<span class="p3">目前所在位置：<a href="'+langPath+'">首頁</a>'+str+'</span>');
  }
  else {return str;}
}

function getColorGroupText(groupsName,groupStr,groups,id,isShowGroup,isAdmin) {
  var str="",groupLinkLocalStr;
  groupLinkLocalStr=groupLinkStr;
  if (!isShowGroup) {groupLinkLocalStr=str_replace(groupLinkLocalStr,"index.php","index.php");}
  if (id==0) {
    if (isAdmin) {groupLinkLocalStr=' &gt;&gt; <a href="'+adminPath+'product/list.php?db=%GroupID%">%GroupName%</a>';}
    else {groupLinkLocalStr=groupStr;}
  }
  groupsName=str_replace(str_replace(groupLinkLocalStr,"%GroupName%",groupsName),"%GroupID%",groups);
  return (groupsName);
}

function writeProductGroupImg(groups) {
  var title,img,link,str='';
  if (groups==null) {return;}
  title=searchValue("productGroupDescriptionList",groups,"0,1,5");
  img=searchValue("productGroupDescriptionList",groups,"0,2,5");
  if (img!="") {
    link=searchValue("productGroupDescriptionList",groups,"0,4,5");
    if (link!="") {str+='<a href="'+link+'">';}
    str+='<img src="'+rootPath+'media/'+lang+'/product/'+img+'" border="0" title="'+title+'">';
    if (link!="") {str+='</a>';}
  }
  else {str='<span class="titleBlack">'+title+'</span>';}
  document.write('<p>'+str);
}

// product/index.php
function getDateStr(showtime,dType) {
  var str;
  showtime=showtime.split("-");
  for (var i=0;i<showtime.length;i++) {showtime[i]=str2num(showtime[i]);}
  switch (dType) {
    case "s":
      str=(langID!=0) ? showtime[1]+"月"+showtime[2]+"日":monthList[(showtime[1]-1)*2+langID].substring(0,3)+" "+showtime[2];
      break;
    case "l":
      str=(langID!=0) ? showtime[0]+"年"+showtime[1]+"月"+showtime[2]+"日":monthList[(showtime[1]-1)*2+langID]+" "+showtime[2]+", "+showtime[0];
      break;
  }
  return str;
}

function checkProductSearchValue(form) {
  var temp;
  if (form.price_high.value!="") {
    if (!isNum(form.price_high.value)) {alert("對不起，價錢必須輸入數字！");return false;}
    if (form.price_low.value=="") {alert("對不起，價錢區間必須輸入！");return false;}
  }
  if (form.price_low.value!="") {
    if (!isNum(form.price_low.value)) {alert("對不起，價錢必須輸入數字！");return false;}
    if (form.price_high.value=="") {alert("對不起，價錢區間必須輸入！");return false;}
  }
  if ((form.price_high.value!="") && (form.price_low.value!="")) {
    if (str2num(form.price_low.value)>str2num(form.price_high.value)) {
      temp=form.price_low.value;
      form.price_low.value=form.price_high.value;
      form.price_high.value=temp;
    }
  }
  return true;
}

function writeProductSearchList(db) {
  var str,no;
  str='<select name="db" size="1"><option value="" selected="true">所有商品類別</option>';
  no=productGroupList[0].length/5;
  for (var i=0;i<no;i++) {
    if (productGroupList[0][i*5+4]==1) {
      str+='<option value="'+productGroupList[0][i*5]+'">'+productGroupList[0][i*5+1]+'</option>';
    }
  }
  str+='</select>';

  document.write(str);
  presetSelect("db",db,"productSearch")
}

function writeBrandSearchList(db) {
  var str,no,order;
  order=brandSortList.split("*/");
  order=order[0].split(",");
  no=order.length;
  str='<select name="db" size="1"><option value="" selected="true">所有品牌</option>';
  for (var i=0;i<no;i++) {
    order[i]=str2num(order[i]);
    if (searchValue("productBrandList",order[i],"0,3,4")==1) {
      str+='<option value="'+order[i]+'">'+searchValue("productBrandList",order[i],"0,1,4")+'</option>';
    }
  }
  str+='</select>';

  document.write(str);
  presetSelect("db",db,"productSearch")
}

// product/ask.php
function checkProduckAskForm() {
  docs=document.DataInput;
  if (!chkTXT("title,email")) {alert("對不起，『姓名』與『E-Mail』必須填寫！");return false;}
  if (!chkEmail(docs.email.value)) {alert("對不起，您的 E-Mail 錯誤，請再檢查一次！");return false;}

  if (confirm('我們會在收到您的資料後儘速回覆您，謝謝！')) {docs.action="ask_save.php";docs.submit();}
}

// 
function writeProductGroupLabel(groups,arrayname,para) {
  document.write(getProductGroupLabel(groups,arrayname,para));
}

function getProductGroupLabel(groups) {
  var str,idx;
  idx=(groups<=0) ? 0:searchValue("productIdxList",groups,"0,1,4");
  str=searchValue("productGroupList["+idx+"]",groups,"0,1,5");

  return (str);
}

function getMainProductGroupID(db) { // 取得商品主類別id
  idx=db;
  while (db!=0) {
    db=searchValue("productIdxList",db,"0,3,4");
    if (db!=0) {idx=db;}
  }
  return (idx);
}

function getProductGroupParent(idx,level_shift) {
  for (var i=0;i<level_shift;i++) {
    idx=searchValue("productIdxList",idx,"0,3,4");
  }
  return (idx);
}

function getProductGroupRelativeList(idx) {
  var listStr=idx+"";
  while (idx>0) {
    idx=searchValue("productIdxList",idx,"0,3,4");
    listStr=idx+","+listStr;
  }
  return (listStr);
}

// newsletter/edit.php
function preset_newsletter_edit(isAdmin) {
  isAdmin=(isAdmin==null) ? false:isAdmin;
  docs=document.DataInput;
  if (docs.title.value=="") {alert("對不起，「電子郵件信箱」為必須填寫之欄位！");return false;}
  if (!chkEmail(docs.title.value)) {alert("對不起，您的電子郵件信箱填寫錯誤，請您再檢查一次！");return false;}
  mailserver=docs.title.value.split("@");
  docs.mailserver.value=mailserver[1].toLowerCase();

  if (isAdmin) {
    return true;
  }
  else {
    docs.action=langPath+"newsletter/save.php";
    docs.submit();
  }
}

function newsletter_check(docs) {
  docs=(docs==null) ? document.DataInput:docs;
  if ((preset_newsletter_edit(true)) && (confirm('資料即將儲存，請按「確定」繼續...'))) {
    docs.action=langPath+"newsletter/save.php";
    docs.submit();
  }
}

// member/form.php
function writeInterestCheckList(defaultValue) {
  var str="";
  for (var i=0;i<(interestList.length/2);i++) {
    str+='<input type="checkbox" name="interest'+(i+1)+'" value="'+interestList[i*2+1]+'">'+interestList[i*2+1]+'<br>';
  }
  document.write(str);

  if (defaultValue=="") {return;}
  defaultValue=defaultValue.split(",");
  for (var i=0;i<defaultValue.length;i++) {
    eval('document.DataInput.interest'+defaultValue[i]+'.checked=true');
  }
}

function writeMemberNO(member_type,idx) {
  document.write(writeMemberNOHead(member_type)+addZero(idx,memberTypePrefix[member_type*2+1]));
}

function writeMemberNOHead(member_type) {
  return memberTypePrefix[member_type*2];
}

function getZipCode(tagname) {
  zipWin=window.open(langPath+'member/location.php?tagname='+tagname,'zipWin','directories=no,location=no,menubar=no,toolbar=no,scrollbars=no,height=170,width=250,left=100,top=100');
  zipWin.focus();
}

// cart/order_detail.php
function writeOrderStatus(idx) {
  document.write(getOrderStatus(idx));
}

function getOrderStatus(idx) {
  for (i=0;i<orderProcessStatus.length/3;i++) {
    if (orderProcessStatus[i*3]==idx) {
      return '<span class="'+orderProcessStatus[i*3+2]+'">'+orderProcessStatus[i*3+1]+'</span>';
    }
  }
}

// service/supplier.php
function preset_supplier_edit() {
  docs=document.DataInput;
  if (!chkTXT("SUPCONTACTOR2,SUPTEL")) {alert("對不起，「聯絡人」與「電話」為必須填寫之欄位！");return false;}
  if (chkTXT("SUPEMAIL")) {
    if (!chkEmail(docs.SUPEMAIL.value)) {alert("對不起，您的電子郵件信箱填寫錯誤，請您再檢查一次！");return false;}
  }
  if (confirm('我們會在收到您的資料後，儘速與您聯絡，謝謝！')) {docs.action="sp_send.php";docs.submit();}

//  return true;
}

// product/view.php
function writeFreeShippingFee(price) {
  if ((price>=shippingPriceList[1]) && (price!=0)) {document.write("（免運費）");}
}

function checkProductFAQForm(isAdmin) {
  if (!isAdmin) {docs=document.faqForm2;formName="faqForm2";}
  else {docs=document.DataInput;formName="DataInput";}
  if (!chkTXT("title,email,comment0",formName)) {alert("對不起，標記 * 的項目必須填寫！");return false;}
  if ((chkTXT("email",formName)) && (!chkEmail(docs.email.value))) {alert("對不起，您的電子郵件信箱錯誤，請再檢查一次！");return false;}

  if (!isAdmin) {docs.action="save_faq.php";docs.submit();}
  else {return true;}
}

// product/list_option.php,admin/product/options/*
function addSubproductGroupList() {
  currLength=productGroupList[0].length/5;
  for (var i=0;i<3;i++) {
    currLength+=i;
    productGroupList[0][currLength*5]=subproductTypeList[i*2];
    productGroupList[0][currLength*5+1]=subproductTypeList[i*2+1];
    productGroupList[0][currLength*5+2]=0;
    productGroupList[0][currLength*5+3]=0;
    productGroupList[0][currLength*5+4]=0;
  }
}

// product/vote/index.php
function check_product_vote() {
  if (!chkRadio("vote_stars")) {alert("對不起，您必須先選擇一個評等，再按下投票鍵！");return false;}

  return true;
}

// index.php
function winPopup() {
  window.open(rootPath+"media/"+lang+"/banner/popup.htm","popup","height=10,width=10,top=20,left=20,scrollbars=no,resizable=no,menubar=no");
}

// faq/*
function writeGroupLabel(groups,arrayname,para) {
  document.write(getGroupLabel(groups,arrayname,para));
}

function getGroupLabel(groups,arrayname,para) {
  var str,groupStr,productStr,no,itemName;
  arrayname=(arrayname==null) ? "productGroupList":arrayname;
  para=(para==null) ? "0,1,5":para;
  paraList=para.split(",");
  no=str2num(paraList[2]);
  itemName=eval(arrayname);
  str="";
  str=searchValue(arrayname+"[0]",groups,para);
  if (str=="") {
    for (var i=0;i<(itemName[0].length/no);i++) {
      if (itemName[0][i*no+3]==1) {
        str=searchValue(arrayname+"["+(i+1)+"]",groups,para);
        if (str!="") {break;}
      }
    }
  }
  return (str);
}
