
var $Y = YAHOO.util,
$D = $Y.Dom,
$E = $Y.Event,
$  = $D.get,
Ali = YAHOO.namespace("Ali");

function BTN902(o) {
this.ob = typeof(o) == "string" ? YAHOO.util.Dom.get(o) : o;
this.a = YAHOO.util.Dom.getFirstChild(this.ob);
this.text = this.ob.innerHTML.replace(/<[^>]*?>/g, "");
this.charLen = this.text.length;
this.width = 0;
this.disabled = false;
this.callback = null;
this.evtLsner = {};
this.init();
}
BTN902.prototype = {
init: function () {
var bL = document.createElement("b");
bL.className = "btnL";
var bR = document.createElement("b");
bR.className = "btnR";
this.width = this.charLen * 14 + 45;
if (YAHOO.env.ua.ie == 6) this.width += 5;
YAHOO.util.Dom.insertBefore(bL, this.a);
YAHOO.util.Dom.insertBefore(bR, this.a);
YAHOO.util.Dom.setStyle(this.ob, "width", this.width + "px");
YAHOO.util.Event.addListener(this.ob, "mouseover", this.hover, this, true);
YAHOO.util.Event.addListener(this.ob, "mouseout", this.unhover, this, true);
YAHOO.util.Event.addListener(this.a, "focus", function () {
this.blur();
});
this.a.onclick = function () {return false;};
if (YAHOO.util.Dom.hasClass(this.ob, "bo_902btn_disabled"))
this.disable(1);
},
disable: function (flag) {

this.disabled = !!flag;
if (this.disabled) {
YAHOO.util.Dom.addClass(this.ob, "bo_902btn_disabled");
YAHOO.util.Dom.removeClass(this.ob, "bo_902btn_hover");
} else {
YAHOO.util.Dom.removeClass(this.ob, "bo_902btn_disabled");
}
},
hover: function () {
if (this.disabled) return;
YAHOO.util.Dom.addClass(this.ob, "bo_902btn_hover");
},
unhover: function () {
YAHOO.util.Dom.removeClass(this.ob, "bo_902btn_hover");
},
on: function (evtName, f, obj) {
if (!this.evtLsner[evtName]) {
this.evtLsner[evtName] = [];
$E.on(this.ob, evtName, function () {
if (this.disabled) return;
for (var i = 0; i < this.evtLsner[evtName].length; i ++) {
this.evtLsner[evtName][i]();
}
}, this, true);
}
var f2 = obj ? function () {f.call(obj);} : f;
this.evtLsner[evtName].push(f2);
}
};
BTN902.btns = {};
function wp_902btn_init() {
if (typeof(g_btn902s) != "undefined") return;
var btn902s = YAHOO.util.Dom.getElementsByClassName("bo_902btn");
var nm;
for (var i = 0; btn902s[i]; i ++) {
nm = btn902s[i].id || "btn902_" + i;
BTN902.btns[nm] = new BTN902(btn902s[i]);
}
}
$E.onDOMReady(wp_902btn_init);
function PullDownMenu_oj(top, ul, ipt, val) {
this.top = typeof(top) == "string" ? YAHOO.util.Dom.get(top) : top;
this.ul = typeof(ul) == "string" ? YAHOO.util.Dom.get(ul) : ul;
this.ipt = typeof(ipt) == "string" ? YAHOO.util.Dom.get(ipt) : ipt;
this.li = this.ul.getElementsByTagName("li");
this.val = val;
this.tmOut = 0;
this.init();
}
PullDownMenu_oj.prototype = {
init: function () {
var _this = this;
YAHOO.util.Event.on(this.top, "mouseover", this.pullDown, this, true);
YAHOO.util.Event.on(this.top, "mouseout", this.toPullUp, this, true);
YAHOO.util.Event.on(this.ul, "mouseover", this.pullDown, this, true);
YAHOO.util.Event.on(this.ul, "mouseout", this.toPullUp, this, true);
for (var i = 0; this.li[i]; i ++) {
YAHOO.util.Event.on(this.li[i], "mouseover", this._liHover);
YAHOO.util.Event.on(this.li[i], "mouseout", this._liUnHover);
YAHOO.util.Event.on(this.li[i], "click", function () {
_this.select(_this, this);
});
}
},
pullDown: function () {
clearTimeout(this.tmOut);
this.ul.style.display = "block";
},
toPullUp: function () {
var _this = this;
this.tmOut = setTimeout(function () {
_this.pullUp();
}, 500);
},
pullUp: function () {
this.ul.style.display = "none";
},
_liHover: function () {
YAHOO.util.Dom.addClass(this, "hover");
},
_liUnHover: function () {
YAHOO.util.Dom.removeClass(this, "hover");
},
select: function (self, target) {
this.val = target.innerHTML;
this.top.innerHTML = this.val;
this.ipt.value = this.val;
this.pullUp();
}
};
function MsgBox_oj() {
this.html = "";
this.btns = [];
this.btnsWidth = 0;
this.errMsgBox = null;
this.init();
}
MsgBox_oj.prototype = {
init: function () {
var overlay = document.createElement("div");
overlay.className = "msgbox_oj_overlay";
this.overlay = overlay;
document.getElementsByTagName("body")[0].appendChild(this.overlay);
this.wrapper = mkEl("div", {className: "msgbox_oj"});
var innerWrapper = mkEl("div", {className: "msgbox_oj_innerWrapper"});
this.wrapper.appendChild(innerWrapper);
this.topBg = mkEl("div", {className: "msgbox_oj_topBg"});
innerWrapper.appendChild(this.topBg);
var wrapper2 = mkEl("div", {className: "msgbox_oj_inner"});
innerWrapper.appendChild(wrapper2);
var box = mkEl("div", {className: "msgbox_oj_box"});
wrapper2.appendChild(box);
this.wrapper2 = wrapper2;
this.box = box;
var close = mkEl("div", {className: "close"});
this.box.appendChild(close);
$E.on(close, "click", this.hide, this, true);
this.head = document.createElement("h2");
this.box.appendChild(this.head);
this.body = mkEl("div", {className: "msgbox_oj_body"});
this.box.appendChild(this.body);
this.foot = mkEl("div", {className: "msgbox_oj_foot"});
this.box.appendChild(this.foot);
var bottom = mkEl("div", {className: "msgbox_oj_bottom"});
innerWrapper.appendChild(bottom);
this.errMsgBox = mkEl("div", {className: "msgBox_errMsg hidden"});

this.box.insertBefore(this.errMsgBox, this.foot);
document.getElementsByTagName("body")[0].appendChild(this.wrapper);
YAHOO.util.Event.on(window, "scroll", this.center, this, true);
YAHOO.util.Event.on(window, "resize", this.center, this, true);

},
show: function (title, html, btnsAndCallback) {
this.isShow = true;
this.head.innerHTML = title || "tishi";
if (typeof(html) == "string") {
this.body.innerHTML = html|| "none";
} else {
this.body.innerHTML = "";
this.body.appendChild(html);
}
if (!btnsAndCallback) btnsAndCallback = [{text: "yes"}];
for (var i = 0; btnsAndCallback[i]; i ++) {
this.mkBtn(btnsAndCallback[i]);
}
YAHOO.util.Dom.setStyle(this.foot, "padding-left", (378 - this.btnsWidth) / 2 + "px");
YAHOO.util.Dom.setStyle(this.overlay, "width", YAHOO.util.Dom.getDocumentWidth() + "px");
YAHOO.util.Dom.setStyle(this.overlay, "height", YAHOO.util.Dom.getDocumentHeight() + "px");
YAHOO.util.Dom.setStyle(this.overlay, "top", 0);
YAHOO.util.Dom.setStyle(this.overlay, "left", 0);
YAHOO.util.Dom.setStyle(this.overlay, "opacity", 0);
YAHOO.util.Dom.setStyle(this.overlay, "display", "block");
YAHOO.util.Dom.setStyle(this.wrapper, "display", "block");
this.chkBg();
this.center();
//this.animShow.animate();
},
chkBg: function () {
if (!this.isShow) return;
var _this = this;
$D.setStyle(this.topBg, "height", this.wrapper2.offsetHeight + "px");
setTimeout(function () {
_this.chkBg();
}, 50);
},
center: function () {
YAHOO.util.Dom.setStyle(this.wrapper, "left", (YAHOO.util.Dom.getClientWidth() - 422) / 2 + "px");
YAHOO.util.Dom.setStyle(this.wrapper, "top", YAHOO.util.Dom.getDocumentScrollTop() + (YAHOO.util.Dom.getClientHeight() - this.wrapper.offsetHeight) / 2 - 60 + "px");
},
hide: function () {
//this.animHide.animate();
YAHOO.util.Dom.setStyle(this.wrapper, "display", "none");
YAHOO.util.Dom.setStyle(this.overlay, "display", "none");
this.btns = [];
this.btnsWidth = 0;
this.foot.innerHTML = "";
this.isShow = false;
this.errMsgHide();
},
mkBtn: function (btnObj) {
var btn = document.createElement("div");
if (!btnObj.disabled) {
btn.className = "bo_902btn";
} else {
btn.className = "bo_902btn bo_902btn_disabled";
}
var a = document.createElement("a");
a.appendChild(document.createTextNode(btnObj.text || "°´Å¥"));
btn.appendChild(a);
var oBtn = new BTN902(btn);
YAHOO.util.Event.on(btn, "click", function () {
oBtn.callback = btnObj.callback;
var _callback_result = true;
if (!oBtn.disabled && oBtn.callback && typeof(oBtn.callback) == "function") {
_callback_result = oBtn.callback();
}
if (!oBtn.disabled && _callback_result != "__blocked__")
this.hide();
}, this, true);
this.btns.push(oBtn);
this.foot.appendChild(oBtn.ob);
this.btnsWidth += oBtn.width;
},
errMsg: function (msg, msgType) {
if (typeof(msg) != "string") msg = msg + "";
this.errMsgBox.innerHTML = "";
var a = msg.split(","), i, o;
for (i = 0; i < a.length; i ++) {
o = mkEl("div");
this.errMsgBox.appendChild(o);
o.className = msgType || "err";
o.innerHTML = a[i];
}
$D.removeClass(this.errMsgBox, "hidden");
},
errMsgHide: function () {
this.errMsgBox.innerHTML = "";
$D.addClass(this.errMsgBox, "hidden");
}
};
function selectOrder() {
var f = function (ul) {
$D.setStyle(ul, "display", ul.style.display != "block" ? "block" : "none");
$D.setStyle(ul, "display", ul.style.display != "block" ? "block" : "none");
};
$D.getElementsByClassName("selectOrder-wrapper", "div", document.body, function (o) {
$E.on(o, "click", function (e) {
var ul = o.parentNode.getElementsByTagName("ul")[0];
$D.setStyle(ul, "display", ul.style.display != "block" ? "block" : "none");
$E.stopPropagation(e);
var maxHeight = o.className.match(/maxHeight\-(\d+)/);
if (maxHeight) {
maxHeight = parseInt(maxHeight[1]);
if (ul.offsetHeight > maxHeight) {
if (YAHOO.env.ua.ie) {
$D.setStyle(ul, "overflowY", "auto");
} else {
$D.setStyle(ul, "overflow", "auto");
}
$D.setStyle(ul, "height", maxHeight + "px");
setTimeout(function () {
f(ul);
}, 100);
}
}
});
});
$E.on(document, "click", function () {
selectOrder.hide();
});
}
selectOrder.hide = function () {
$D.getElementsByClassName("selectOrder-options", "ul", document.body, function (o) {
$D.setStyle(o, "display", "none");
});
};
function mkTxtEl(txt) {
return document.createTextNode(txt);
}
function mkEl(tagName, p, children) {
var o = document.createElement(tagName);
if (p) {
for (var k in p) {
if (k != "class")
o[k] = p[k];
else
o.className = p[k];
}
}
if (children) {
var a = [];
if (children.constructor != Array)
a.push(children);
else
a = children;
for (var i = 0; i < a.length; i ++) {
try {
o.appendChild(a[i]);
} catch (e) {
}
}
}
return o;
}
function g_imgMaxSize(img, maxWidth, maxHeight, unit) {
if (!img) return [0, 0];
if (typeof(img) == "string") img = $(img);
var w = parseInt(img.width || img.offsetWidth),
h = parseInt(img.height || img.offsetHeight),
u = unit || "px";
if (w <= maxWidth && h <= maxHeight) return [w, h];
if (w == h) {
w = Math.min(maxWidth, maxHeight, w);
h = w;
} else if (w / maxWidth > h / maxHeight) {
h = h * maxWidth / w;
w = maxWidth;
if (!unit) h = Math.floor(h);
} else {
w = w * maxHeight / h;
h = maxHeight;
if (!unit) w = Math.floor(w);
}
$D.setStyle(img, "width", w + u);
$D.setStyle(img, "height", h + u);
return [w, h];
}
var scrollLoader = {
isLoading: false,
c: null,
req: function (method, url, callback, postData) {
if (!postData) postData = {};
if (scrollLoader.isLoading) return;
scrollLoader.isLoading = true;
postData["_input_charset"] = "UTF-8";
postData["_csrf_token"] = _csrf_token;
scrollLoader.c = $Y.Connect.asyncRequest(method, url, {
success: function (r) {
scrollLoader.isLoading = false;
var j = YAHOO.lang.JSON.parse(r.responseText);
if (typeof(callback) == "function") callback(j);
},
failure: function (r) {
scrollLoader.isLoading = false;
}
}, $J.ob2param(postData));
}
};

function getTreeHeight(){
var o = document.getElementById("main_tree") || document.getElementById("tree1");
if (!o) return;
var treeheight = o.offsetHeight;
var o2 = document.getElementById("main_right");
if (!o2) return;
var old_height = o2.offsetHeight;
o2.style.height = "auto";
var main_right = o2.offsetHeight;
if (treeheight > main_right){
o2.style.height=o.offsetHeight+"px";
document.getElementById("main_body").style.height=o.offsetHeight+28+"px";
}else{
document.getElementById("main_body").style.height=o2.offsetHeight+28+"px";
}
}
var _csrf_token;
$E.onDOMReady(function () {
var tmp = $D.getElementsBy(function (o) {
return o.getAttribute("name") == "_csrf_token";
}, "input");
_csrf_token = tmp[0] ? tmp[0].value : "";

var _resizeForCustomImg_maxCount = 100,
reSizeForCustomImg = function (img) {
var w = img.width || img.offsetWidth;
if (w > 700) {
$D.setStyle(img, "width", "700px");
} else if (w == 0) {
if (_resizeForCustomImg_maxCount <= 0) return;
_resizeForCustomImg_maxCount --;
setTimeout(function () {
_resizeForCustomImg(img);
}, 500);
}
};
if (YAHOO.env.ua.ie == 6) {
var imgs1 = YAHOO.util.Selector.query("#customHtml img"),
w, i;
for (i = 0; i < imgs1.length; i ++) {
reSizeForCustomImg(imgs1[i]);
}
}
/* end of  */
});
(function () {
var oj = function (p) {
return (new oj.cls(p));
};
oj.$ = function (p) { return document.getElementById(p); };
oj.cls = function (p) {
this.items = [];
if (typeof(p) == "string") {
this.items.push(oj.$(p));
} else if (typeof(p) == "object" && typeof(p.length) == "number") {
for (var i = 0, l = p.length; i < l; i ++)
this.items.push(p[i]);
} else if (typeof(p) == "object") {
for (var k in p)
this.items.push(p[k]);
} else {
this.items.push(p);
}
};
oj.cls.prototype = {
each: function (f, callback) {
var args = [];
for (var i = 2, l = arguments.length; i < l; i ++)
args.push(arguments[i]);
for (i = 0, l = this.items.length; i < l; i ++)
f.apply(this.items[i], args);
if (typeof(callback) == "function") callback();
return this;
}
}
oj.ajaxForm = function (el, params) {

var f = function () {};
this.elForm = typeof(el) == "string" ? $(el) : el;
if (!this.elForm) return;
this.action = this.elForm.getAttribute("action") || "";
this.method = this.elForm.getAttribute("method") || "POST";
this.elBtns = params.btnSubmit ? oj(params.btnSubmit) : null;
this.enabled = true;
this.tradSubmit = params.tradSubmit;
this.ipts = {
_csrf_token: _csrf_token,
_input_charset: "UTF-8"
};
this.before = typeof(params.before) == "function" ? params.before : f;
this.success = typeof(params.success) == "function" ? params.success : f;
this.failure = typeof(params.failure) == "function" ? params.failure : f;
var _this = this;
if (typeof(this.elForm.onsubmit) == "function") {
f = this.elForm.onsubmit;
}
this.elForm.onsubmit = function () {
f();
_this.submit();
return false;
};
this.initBtn(params.evtSubmit);
};
oj.ajaxForm.prototype = {
addBtn: function (o, evtSubmit) {
if (this.elBtns) {
this.elBtns.items.push($(o));
} else {
this.elBtns = oj(o) || null;
}
this.initBtn(evtSubmit);
},
initBtn: function (evtSubmit) {
var _this = this;
if (this.elBtns != null) {
this.elBtns.each(function () {
if (this.tagName && this.tagName.toLowerCase() == "a") this.onclick = $J.ffun;
$E.on(this, evtSubmit || "click", _this.submit, _this, true);
});
}
},
getValues: function () {
var _this = this;
oj(this.elForm.childNodes).each(function () {
if (this.nodeType != 1) return;
var tagName = (this.tagName || "").toLowerCase(),
attrName = this.getAttribute("name");
if (attrName == null) return;
if (tagName == "input" || tagName == "textarea") {
_this.ipts[attrName] = this.value || "";
}
});
},
setValues: function () {
for (k in this.ipts) {
if (this.elForm[k]) {
this.elForm[k].value = this.ipts[k];
} else {
this.elForm.appendChild(mkEl("input", {type: "hidden", name: k, value: this.ipts[k]}));
}
}
},
submit: function () {
if (!this.enabled) return;
var reqUrl = this.action, _this = this;
this.getValues();
if (this.before() === false) return;
if (this.tradSubmit) {

this.setValues();
this.elForm.submit();
return;
}
if (this.method == "GET") reqUrl = oj.urlQuery(reqUrl, this.ipts);
this.enabled = false;
$Y.Connect.asyncRequest(this.method,
reqUrl, {
success: function (r) {
_this.enabled = true;
_this.success.call(_this, r);
},
failure: function (r) {
_this.enabled = true;
_this.failure.call(_this, r);
}
}, oj.ob2param(this.ipts, true));
}
};
oj.ob2param = function (ob, urlEncode) {
var a = [], k;
if (!urlEncode)
for (k in ob)
a.push(k + "=" + ob[k]);
else
for (k in ob)
a.push(k + "=" + encodeURIComponent(ob[k]));
return a.join("&");
};
oj.ob2str = function (p) {
if (typeof(p) == "undefined") return "\"undefined\"";
var s = "", k, i;
if (p.constructor == Array) {

for (i = 0; i < p.length; i ++) {
s += "," + oj.ob2str(p[i]);
}
s = s.substring(1);
s = "[" + s + "]";
} else if (typeof(p) == "object") {

for (k in p) {
s += ",\"" + k + "\":" + oj.ob2str(p[k]);
}
s = s.substring(1);
s = "{" + s + "}";
} else {

s = "\"" + p.toString() + "\"";
}
return s;
};
oj.urlQuery = function (url, obQuery) {

return url.indexOf("?") == -1 ? url + "?" + oj.ob2param(obQuery) :
url + "&" + oj.ob2param(obQuery);
};
oj.cookie = function (k, v, expDT) {
if (arguments.length == 1) {	//get
v = document.cookie.match("(?:^|;)\\s*" + k + "=([^;]*)");
return v ? unescape(v[1]) : "";
} else {	//set
}
};
oj.Anim = function (attrs, frames, interval, callback) {
this.attrs = attrs;
this.frames = frames;
this.itvl = interval;
this.playing = false;
this.callback = typeof(callback) == "function" ? callback : oj.ffun;
};
oj.Anim.prototype = {
animate: function () {
if (this.frames <= 0) {
this.playing = false;
this.callback();
return;
}
this.playing = true;
var _this = this, v0, step;
for (var i = 0, j; i < this.attrs.length; i ++) {
v0 = this.attrs[i].get();
step = (this.attrs[i].to - v0) / this.frames;
this.attrs[i].set(v0 + step);
}
this.frames --;
setTimeout(function () {_this.animate();}, this.itvl);
},
play: function () {
if (this.playing) return;
this.animate();
}
};
oj.trim = function (s) {
return s.replace(/^\s+/, "").replace(/\s+$/, "");
};
oj.htmlEncode = function (s) {
return mkEl("div", null, mkTxtEl(s)).innerHTML;
};
//oj Array Class
oj.A = function (a) {
return new oj._A(a);
};
oj._A = function (a) {
this.a = [];
for (var i = 0, l = a.length; i < l; i ++) {
this.a.push(a[i]);
}
};
oj._A.prototype = {
has: function (v, strict) {
var i, l;
if (!strict) {
for (i = 0, l = this.a.length; i < l; i ++) {
if (v == this.a[i]) return true;
}
} else {
for (i = 0, l = this.a.length; i < l; i ++) {
if (v === this.a[i]) return true;
}
}
return false;
},
remove: function (v) {
for (var a = [], i = 0, l = this.a.length; i < l; i ++) {
if (v != this.a[i]) a.push(this.a[i]);
}
this.a = a;
return this;
}
};

oj.strLeft = function (s, n, ellStr) {
//return s.slice(0, n - s.slice(0, n).replace(/[\x00-\xff]/g, "").length);
for (var i = 0, l = s.length, c, m = 0, str = ""; i < n && i < l && m < n; i ++) {
c = s.substr(i, 1);
if (!c.match(/[\x00-\xff]/))
m += 2;
else
m ++;
str += c;
}
return str + (ellStr && str.length < l ? ellStr : "");
};
oj.ffun = function () {if (this.blur) this.blur();return false;};
$J = oj;
})();
