//-------------for in=article page & in=upload page--------
	function showOpt(objThis, strID, strID2, boolS) {
	  var str1 = "&#9654;", str2 = "&#9664;";
	  if(boolS==true) { str1 = "&#9700;", str2 = "&#9699;"; };
    var opt = $id(strID).style;
    if(opt.display == "none") {
      opt.display = ""; objThis.innerHTML = str2;
      if(strID2) $id(strID2).style.display = "none";
    } else {
      opt.display = "none"; objThis.innerHTML = str1;
      if(strID2) $id(strID2).style.display = "";
    }
  }

  function getTimeStr(intT) {
    var theDate = new Date(), arr = ["getFullYear", "getMonth", "getDate", "getHours", "getMinutes", "getSeconds"], arr2 = [];
    for(var i=0; i<arr.length; i++) {
      arr2[i] = theDate[arr[i]]();
      if(arr[i]=="getMonth") arr2[i] += 1;
      if(arr2[i]<10) arr2[i] = "0" + arr2[i];
    }
    arr = arr2.splice(3, arr2.length).join(":");
    arr2 = arr2.join("-");
    if(intT==1) return arr2;
    if(intT==2) return arr;
    return arr2 + " " + arr;
  }

  function setCurrentTime(strName) {
    $name(strName)[0].value = getTimeStr();
  }

  function ajaxTempArticle(objForm, strFlag, objThis) {
    if(strFlag=="save") ajax.query("?in=article&ajax=save", null, objForm);
    if(strFlag=="load") {
      if(confirm("Are you sure?")) {
        ajax.query("?in=article&ajax=load", objForm);
        objThis.disabled = true;
      }
    }
  }

  function autoSaveContent(objThis) {
    autoSaveContent.time = 5 * 60 * 1000; //5 seconds
    autoSaveContent.showSaveTime = function() {
      document.getElementById("showSaveTimeBox").innerHTML = getTimeStr(2) + " Saved.";
    }
    if(objThis.checked==true) {
      autoSaveContent.form = objThis.form;
      this.interval = window.setInterval("ajaxTempArticle(autoSaveContent.form, 'save');autoSaveContent.showSaveTime();", autoSaveContent.time);
    } else {
      clearInterval(this.interval);
      this.interval = null, this.form = null;
    }
  }

  function selectAllCheckbox(objThis, strName) {
  	objThis = objThis.checked;
  	strName = $name(strName);
    for(var i=0; i<strName.length; i++) strName[i].checked = objThis;
  }

  function checkArticleFrom(objForm) {
    var arr = [{check: objForm["log_title"].value.length<1, err : $lang["title_fail"]},
    	         {check: objForm["cat_id"].value=="0", err : $lang["category_fail"]},
    	         {check: objForm["log_content"].value.length<1, err : $lang["content_fail"]}
    	        ], str = "";
    for(var i=0; i<arr.length; i++) if(arr[i].check) str += "* " + arr[i].err + "\n";
    if(str.length>0) { alert(str); return false; }
    var re = /^ {2,2}/, con = objForm["log_content"].value;
    if(re.test(con)) objForm["log_content"].value = con.replace(re, "\u3000");
    return true;
  }
//-------------for in=category page--------------------
	function showCatChild(objThis, strName) {
		var objName;
		objThis = objThis.parentNode;
		for(var obj=objThis.nextSibling; obj!=null; obj=obj.nextSibling) {
			if(obj.nodeName.toLowerCase()!="tr") continue;
	 		objName = obj.getAttribute("name");
	 		if(strName=="all") {
  		  obj.style.display = "";
	 	  } else if(objName==strName) {
	 	  	obj.style.display = (obj.style.display=="none") ? "" : "none";
	    }
    }
  }
//-------------for in=template page------------------------
  function showSkinFileOption(strSelectName, strThisValue, objItem) {
    var opt = $name(strSelectName)[0];
    var arr = objItem[strThisValue];
    if(!opt || !arr) return;
    opt.length = 0;
    for(var i=0; i<arr.length; i++) opt.options[opt.length] = new Option(arr[i], arr[i]);
  }

  function showPreview(objThis, strMod) {
    objThis = objThis.form;
    var tar = objThis.getAttribute("target"), act = objThis.getAttribute("action");
    objThis.setAttribute("target", "_blank"); objThis.setAttribute("action", "./default.asp?prev=" + strMod);
    objThis.submit();
    objThis.setAttribute("target", tar); objThis.setAttribute("action", act);
  }
//-------------for in=upload page------------------------
  function getSelectOptionText(obj) {
    this.arr = [];
    for(var i=0; i<obj.length; i++) if(obj[i].selected) this.arr.push(obj[i].text);
    this.arr.splice(0, this.arr.length - 1);
    return this.arr[0] || "";
  }

  function showFileOnChange(objThis, strID, strURL) {
    var strValue = (objThis.type.indexOf("select")!=-1) ? getSelectOptionText(objThis.options) : objThis.value, obj = $id(strID);
    if(!obj || !strValue) return;
    strURL = strURL ? (strURL + strValue.replace(/ \(\S+?\)/g, "")) : strValue;
    strValue = (strValue = strURL.split(/\./g))[strValue.length - 1];
    var ubbType = ubb.getFileTypeByName(strValue);
    obj.innerHTML = ubbType ? ubb.getObjStrByType(ubbType, strURL, obj.clientWidth, obj.clientHeight) : strValue;
  }

  function insertFileToUBB(objSelect) {
    if(!objSelect) return;
    var oURL = [], opt, str, re = / \((\S+?)\)$/g;
    for(var i=0; i<objSelect.length; i++) {
      opt = objSelect.options[i];
      if(opt.selected) {
        opt = opt.text;
        if(opt.match(re)) {
          str = "[album=" + RegExp.$1.replace(/\*/g, ",").replace(/k/ig, "") + "][" + opt.replace(re, "") + "][\/album=" + getTimeStr(1) + "]";
        } else {
          str = opt.split(/\./g);
          str = ubb.getFileTypeByName(str[str.length - 1]);
          if(!str || str=="") str = "[file][" + opt + "][/file]";
            else if(str=="doc" || str=="zip" || str=="exe") str = "[file=" + str + "][" + opt + "][/file]";
            else if(str=="img") str = "[img][" + opt + "][/img]";
          else str = "[media][" + opt + "][/media]";
        }
        oURL[oURL.length] = str;
      }
    }
    oURL = oURL.join("\n");
    parent.ubb.insert(oURL);
  }