﻿/*based jquery. created by wanlei - (http://www.wanlei.net) - v2009.06.07.2 */
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 getCookie(key) { var items = document.cookie.split("; "); for (var i = 0; i < items.length; i++) { var kv = items[i].split("="); if (key == kv[0]) {if (kv[1] != undefined) return decodeURIComponent(kv[1]); } } return ""; }
function setCookie(key, value) { date = new Date(); document.cookie = key + "=" + encodeURIComponent(value) + ";path=/;expires=Fri, 31 Dec 2020 23:59:59 GMT;"; }
function delCookie(key){document.cookie = key + "=" + encodeURIComponent("") + "; 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 getId(eid) { return document.getElementById(eid); }
function Q2B(s) { var i; var r = ''; for (i = 0; i < s.length; i++) { code = s.charCodeAt(i); if (code >= 65281 && code < 65373) { r += String.fromCharCode(s.charCodeAt(i) - 65248); } else { r += s.charAt(i); } } return r; }
function isElement(element, tagname) { return element.tagName.toLowerCase() == tagname;}
function initScript(){getBrowser();}
initScript();

/*string ext*/
String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }
String.prototype.ftrim = function() { return this.replace(/(\ )/g, ""); }
String.prototype.ltrim = function(){return this.replace(/(^\s*)/g, "");}
String.prototype.rtrim = function() { return this.replace(/(\s*$)/g, ""); }
String.prototype.startswith = function(value){return this.indexOf(value)==0;}

/*validate*/
function validateEmail(s) { var str = Q2B(s); var patn = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$/; if (patn.test(str)) return 1; return 0; }
function validateMobile(s) { var str = Q2B(s); var patn = /^13\d{9}$/; if (patn.test(str)) return 1; return 0; }

function buildQSInContainer(containerID)
{
   var result = "";var container = getId(containerID);
   var length = isElement(container, "form") ? container.elements.length : container.childNodes.length;
   for (i = 0; i < length; i++)
   {
      var item = isElement(container,"form") ? container.elements[i] : container.childNodes[i];
      if (item.type == "text" || item.type == "password" || item.type == "hidden" || item.type == "textarea" || item.type == "select-one")
      {
         if (item.name != "") result += item.name + "=" + encodeURIComponent(item.value).replace(/\+/g, '%2B') + "&";
         else if (item.id != "") result += item.id + "=" + encodeURIComponent(item.value).replace(/\+/g, '%2B') + "&";
      }
   }
   return result;
}

function cleanInContainer(containerID) { var container = getId(containerID); for (i = 0; i < container.childNodes.length; i++) { var item = container.childNodes[i]; if (item.type == "text" || item.type == "password" || item.type == "hidden" || item.type == "textarea") item.value = ""; } }
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; } }
function getChecked(elementName) { return $("input:checkbox[name=\"" + elementName + "\"]:checked").serialize(); }

/*icon*/
var accept_icon = "<img class=\"img_pre\"  src=\"/r/i/accept.gif\" style=\"position:relative;top:3px;\">";
var error_icon = "<img class=\"img_pre\"  src=\"/r/i/error.gif\" style=\"position:relative;top:3px;\">";
var loading_icon = "<img class=\"img_pre\" src=\"/r/i/loading.gif\" style=\"position:relative;top:3px;\">";

/*ajax begin*/
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);this._xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");this._xmlhttp.setRequestHeader("Cache-Control", "no-cache"); 
   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.ashx?cmd=' + encodeURI(cmd) + '&r=' + Math.random(), method, data); }

function ajaxPost(cmd,container, extData, info, activation, loading,reset)
{
   var poststr;
   if (container != "") poststr = buildQSInContainer(container) + "&" + extData; else poststr = extData;
   if (activation != null) activation.attr("disabled", "disabled");
   info.html(loading);
   ajaxExe(function(status, statusText, responseText, responseHTML)
   {
      if (status == 200 && responseText != "")
      {
         eval(responseText);
         if (result.success != "1") { info.html(error_icon + result.message); if (activation != null) activation.removeAttr("disabled"); }
         else { info.html(accept_icon + result.message); if (reset) { cleanInContainer(container); activation.removeAttr("disabled"); } }
      }
   }, cmd, 'POST', poststr);
}

function ajaxPostCallback(cmd, container, extData, info, activation, loading, successCallback, failedCallback)
{
   var poststr;
   if (container != "") poststr = buildQSInContainer(container) + "&" + extData; else poststr = extData;
   if (activation != null) activation.attr("disabled", "disabled");
   if(info!=null) info.html(loading);
   ajaxExe(function(status, statusText, responseText, responseHTML)
   {
      if (status == 200 && responseText != "")
      {
         eval(responseText);
         if (result.success != "1") { if (failedCallback != null) failedCallback(result); }
         else { if (successCallback != null) successCallback(result); }
      }
   }, cmd, 'POST', poststr);
}

/*ajax end*/

function searchChengYu(isInner)
{
   var key = $("#ck").val().ftrim();
   if (key != '' && key != '成语搜索'){var url = '/dict/chengyu/' + encodeURI(key) + '/';if (window.open == null || isInner) location.href = url; else window.open(url); }
   else { alert('请输入您要搜索的成语!'); }
}
function searchSuoXie(isInner)
{
   var key = $("#sk").val().ftrim();
   if (key != '' && key != '缩写词搜索') { var url = '/dict/suoxie/' + encodeURI(key) + '/'; if (window.open == null) location.href = url; else window.open(url); }
   else { alert('请输入您要搜索的缩写词!'); }
}