﻿/*created by wanlei - (http://wanlei.net) - v0.009.2009.02.15 */
var isIE = 0, isFirefox = 0, isSafari = 0, isCamino = 0, isMozilla = 0;
function getBrowser() { if ((navigator.userAgent.indexOf("MSIE")) > 0) return isIE = 1; if ((navigator.userAgent.indexOf("Firefox")) > 0) return isFirefox = 2; if ((navigator.userAgent.indexOf("Safari")) > 0) return isSafari = 3; if ((navigator.userAgent.indexOf("Camino")) > 0) return isCamino = 4; if ((navigator.userAgent.indexOf("Gecko/")) > 0) return isMozilla = 5; return 0; }
function setHomePage(item, link) { item.style.behavior = 'url(#default#homepage)'; item.setHomePage(link); }
function addBookmark(title, url) { if (isIE) { window.external.AddFavorite(url, title); } else if (window.sidebar) { window.sidebar.addPanel(title, url, ""); } else { return true; } }
function hideElement(itemid, browser) { if (browser == getBrowser()) { var item = document.getElementById(itemid); item.style.display = "none"; } }
function showDate(itemid) { var today = new Date(); var d = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]; document.getElementById(itemid).innerHTML = (today.getFullYear() + "." + (today.getMonth() + 1) + "." + today.getDate() + "&nbsp;&nbsp;" + d[today.getDay()]); }
function set_value(ename, evalue) { if (evalue == null) evalue = ""; document.getElementById(ename).value = evalue; }
function get_value(ename) { return document.getElementById(ename).value; }
function getCookie(key) { var items = document.cookie.split("; "); for (var i = 0; i < items.length; i++) { var kv = items[i].split("="); if (key == kv[0]) return unescape(kv[1]); } return null; }
function setCookie(key, value) { date = new Date(); document.cookie = key + "=" + escape(value) + "; expires=Fri, 31 Dec 2010 23:59:59 GMT;"; }
function delCookie(key) { document.cookie = key + "=" + escape("") + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;"; }
function syncHeight(src, target) { var sh = $(src).attr("clientHeight"); var th = $(target).attr("clientHeight"); if (sh > th) $(target).css("height", sh + "px"); else $(src).css("height", th + "px"); }
function setCopy(txt) { try { if (window.clipboardData) { window.clipboardData.setData("Text", txt); } } catch (e) { } }
function focusElement(eid) { try { if (isIE) document.getElementById(eid).focus(); } catch (e) { } }
function initScript() { getBrowser(); }
initScript();

/*ajax*/
function GetXMLHttpRequest() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if (window.ActiveXObject) { var msxmls = new Array('Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'); for (var i = 0; i < msxmls.length; i++) { try { return new ActiveXObject(msxmls[i]); } catch (e) { } } } throw new Error("Could not instantiate XMLHttpRequest"); }
function AjaxCore() { this._xmlhttp = GetXMLHttpRequest(); }
function AjaxCore_loading() { }
function AjaxCore_loaded() { }
function AjaxCore_interactive() { }
function AjaxCore_complete(status, statusText, responseText, responseHTML) { }
function AjaxCore_call(url, method, senddata)
{
   var instance = this;
   this._xmlhttp.open(method, url, true); //maybe can change the method.
   this._xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   this._xmlhttp.setRequestHeader("Cache-Control", "no-cache"); //TODO:增加选项控制
   this._xmlhttp.onreadystatechange = function() { switch (instance._xmlhttp.readyState) { case 1: instance.loading(); break; case 2: instance.loaded(); break; case 3: instance.interactive(); break; case 4: instance.complete(instance._xmlhttp.status, instance._xmlhttp.statusText, instance._xmlhttp.responseText, instance._xmlhttp.responseXML); break; } }
   this._xmlhttp.send(senddata);
}
AjaxCore.prototype.loading = AjaxCore_loading;
AjaxCore.prototype.loaded = AjaxCore_loaded;
AjaxCore.prototype.interactive = AjaxCore_interactive;
AjaxCore.prototype.complete = AjaxCore_complete;
AjaxCore.prototype.call = AjaxCore_call;
function ajaxExe(handler, cmd, method, data) { var ajax = new AjaxCore(); ajax.complete = handler; ajax.call('/ajax.aspx?cmd=' + encodeURI(cmd) + '&r=' + Math.random(), method, data); } //2009.9.3 增加随机数和中文编码.to v0.004
/*ajax end*/

//2008.6.14 bug fix:url encode.增加escape编码参数。
function buildQSInForm(form)
{
   var result = "";
   var theForm = document.getElementById(form);
   for (i = 0; i < theForm.elements.length; i++)
   {
      var item = theForm.elements[i];
      if (item.type == "text" || item.type == "password" || item.type == "hidden" || item.type == "textarea" || item.type == "select-one" || (item.type == "radio" && item.checked))
      {
      
         if (item.name != "")
            result += item.name + "=" + escape(item.value).replace(/\+/g, '%2B') + "&";
         else if (item.id != "")
            result += item.id + "=" + escape(item.value).replace(/\+/g, '%2B') + "&";
      }
   }
   return result;
}

function tabPage(tabs) { var t = tabs.split(','); document.getElementById(t[0]).className = "current"; document.getElementById(t[0] + "view").style.display = ""; for (i = 1; i < t.length; i++) { document.getElementById(t[i]).className = "normal"; document.getElementById(t[i] + "view").style.display = "none"; } }
function doCheck(checked) { var inputs = document.getElementsByTagName("input"); for (i = 0; i < inputs.length; i++) { var item = inputs[i]; if (item.type == "checkbox") item.checked = checked; } }

//clipboard action
/* copy code */
function setCopy(text)
{
   if (window.clipboardData)
   {
      window.clipboardData.setData("Text", text)
   }
}

/*for chinalivedoor.com*/
function dictSearch(keyName, dictType, open)
{
   var keyValue = document.getElementById(keyName).value;

   if (keyValue != '' && keyValue != '成语搜索')
   {
      var url = '/dict/search/' + encodeURI(keyValue) + '/';
      if (window.open == null) document.URL = url;
      else window.open(url);
   }
   else
   {
      alert('请输入您要搜索的成语!');
   }
}