// ac.js
// Loading...
// ajax.js
var ac_ajax_debug = true;
function ac_ajax_request_object() {
var hreq;
try {
hreq = new XMLHttpRequest();
} catch (e) {
hreq = null;
}
return hreq;
}
function ac_ajax_init() {
}
function ac_ajax_call_url(url, post, cb) {
var hreq = ac_ajax_request_object();
if (hreq !== null) {
hreq.onreadystatechange = function() {
try {
ac_ajax_handle(hreq, cb);
} catch (e) {}
};
var method = ( post === null ? 'GET' : 'POST' );
var postType = typeof(post);
if ( post !== null ) {
if ( postType == 'array' || postType == 'object' ) {
var postArr = new Array();
for ( var i in post ) {
var postType = typeof(post[i]);
if ( postType == 'array' || postType == 'object' ) {
for ( var j in post[i] ) {
if ( typeof(post[i][j]) != 'function' ) {
postArr.push(i + '[' + ( j == 'undefined' ? '' : j ) + ']=' + encodeURIComponent(post[i][j]));
}
}
} else if ( postType != 'function' ) {
postArr.push(i + '=' + encodeURIComponent(post[i]));
}
}
post = postArr.join('&');
}
}
hreq.open(method, url, true);
hreq.setRequestHeader("X-XSRF-TOKEN", getCSRFToken());
if ( post !== null ) {
hreq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}
hreq.send(post);
}
}
function ac_ajax_proxy_call_url(base, url, post, cb) {
if (post !== null)
ac_ajax_call_url(base + "/ac_global/functions/ajax_proxy.php?post=1&url=" + ac_b64_encode(url), post, cb);
else
ac_ajax_call_url(base + "/ac_global/functions/ajax_proxy.php?url=" + ac_b64_encode(url), post, cb);
}
function ac_ajax_proxy_call_cb(base, url, func, cb) {
if (url.match(/\?/))
url = url + "&f=" + func;
else
url = url + "?f=" + func;
url += "&rand=" + ac_b64_encode(Math.random().toString());
if (arguments.length > 3) {
for (var i = 4; i < arguments.length; i++)
url += "&p[]=" + encodeURIComponent(arguments[i]);
}
ac_ajax_proxy_call_url(base, url, null, cb);
}
function ac_ajax_call(url, func) {
if (arguments.length < 3)
ac_ajax_call_cb(ac_str_url(url), func, null);
else {
ac_ajax_call_cb(ac_str_url(url), func, null, ac_ary_last(arguments, 2));
}
}
function ac_ajax_call_cb(url, func, cb) {
if (func) {
if (url.match(/\?/))
url = url + "&f=" + func;
else
url = url + "?f=" + func;
}
url += "&rand=" + ac_b64_encode(Math.random().toString());
if (arguments.length > 3) {
for (var i = 3; i < arguments.length; i++)
url += "&p[]=" + encodeURIComponent(arguments[i]);
}
if ( cb === null ) cb = function(){};
ac_ajax_call_url(url, null, cb);
}
function ac_ajax_post_cb(url, func, cb, post) {
if (func) {
if (url.match(/\?/))
url = url + "&f=" + func;
else
url = url + "?f=" + func;
}
url += "&rand=" + ac_b64_encode(Math.random().toString());
if ( cb === null ) cb = function(){};
ac_ajax_call_url(url, post, cb);
}
function ac_ajax_handle(hreq, cb) {
if (hreq !== null) {
if (hreq.readyState == 4) {
if (hreq.status == 200) {
try {
var xml = hreq.responseXML;
if (xml !== null && xml.documentElement !== null) {
if (cb === null)
cb = eval("cb_" + xml.documentElement.nodeName);
if (typeof cb == "function")
cb(xml.documentElement, hreq.responseText);
} else {
if ( hreq.responseText != '' ) {
if (typeof ac_ajax_handle_text == 'function')
ac_ajax_handle_text(hreq.responseText);
}
}
/*
var rootNode = ( xml !== null ? xml.documentElement : null );
if (cb === null && rootNode) {
cb = eval("cb_" + rootNode.nodeName);
}
if (typeof cb == "function")
cb(rootNode, hreq.responseText);
*/
} catch (e) {
alert(e);
}
}
}
}
}
function ac_ajax_cb(cbf) {
return function(xml, text) {
window.t_xml = xml;
window.t_text = text;
var ary = ac_dom_read_node(xml, null);
window.t_ary = ary;
cbf(ary);
}
}
// dom.js
function ac_dom_compstyle(elem) {
if (document.defaultView && document.defaultView.getComputedStyle)
return document.defaultView.getComputedStyle(elem);
else if (elem.currentStyle)
return elem.currentStyle;
else
return null;
}
function ac_dom_showif(id, cond) {
if (cond)
$(id).show();
else
$(id).hide();
}
function ac_dom_hideif(id, cond) {
if (cond)
$(id).hide();
else
$(id).show();
}
function ac_dom_read(tag, filter) {
return ac_dom_read_node(document.getElementsByTagName(tag).Items(0), filter);
}
function ac_dom_read_node(node, filter) {
if (typeof(filter) != 'function') filter = null;
var ary = new Array();
var cnode = null;
if ( !node ) return null;
for (var i = 0; i < node.childNodes.length; i++) {
cnode = node.childNodes[i];
switch (cnode.nodeType) {
case 3: // TEXT_NODE
ary["__text"] = cnode.nodeValue;
break;
case 4: // CDATA_SECTION_NODE
ary["__cdata"] = cnode.nodeValue;
break;
case 1: // ELEMENT_NODE
if (ac_dom_isnull(cnode.firstChild)) {
var idx = cnode.nodeName.toLowerCase();
if (ary[idx] === undefined || (typeof(ary[idx]) != "string" && typeof(ary[idx]) != "array" && typeof(ary[idx]) != "object"))
ary[idx] = "";
else {
if (typeof(ary[idx]) == "string") {
var tmp = ary[idx];
ary[idx] = new Array();
ary[idx].push(tmp);
}
ary[idx].push("");
}
} else if (ac_dom_istext(cnode.firstChild)) {
var idx = cnode.nodeName.toLowerCase();
var nodedata = ( cnode.textContent !== undefined ? cnode.textContent : cnode.firstChild.nodeValue );
nodedata = nodedata.replace(/__--acenc:endcdata--__/, "]]>", nodedata);
if (nodedata.match(/^-?[0-9]+$/) && !nodedata.match(/0+[0-9]+$/))
nodedata = parseInt(nodedata, 10);
if (ary[idx] === undefined || (typeof(ary[idx]) != "string" && typeof(ary[idx]) != "array" && typeof(ary[idx]) != "object"))
ary[idx] = (filter === null) ? nodedata : filter(nodedata);
else {
if (typeof(ary[idx]) == "string") {
var tmp = ary[idx];
ary[idx] = new Array();
ary[idx].push(tmp);
} else if (typeof(ary[idx]) != "array" && typeof(ary[idx]) != "object") {
alert(typeof(ary[idx]));
//continue;
}
ary[idx].push((filter === null) ? nodedata : filter(nodedata));
}
} else {
var idx = cnode.nodeName.toLowerCase();
if (ary[idx] === undefined || (typeof(ary[idx]) != "string" && typeof(ary[idx]) != "array" && typeof(ary[idx]) != "object")) {
ary[idx] = new Array();
}
ary[idx].push(ac_dom_read_node(cnode, filter));
}
break;
default:
break;
}
}
return ary;
}
function ac_dom_istext(node) {
return node.nodeType == 3 || node.nodeType == 4; // TEXT_NODE || CDATA_SECTION_NODE
}
function ac_dom_isnull(node) {
return node === null;
}
function ac_dom_toggle_display(id, val) {
var disp = $(id).style.display;
if (disp != "none")
$(id).style.display = "none";
else
$(id).style.display = ( typeof val == "undefined" ? "" : val );
}
/*
function ac_dom_toggle_display(id, val) {
var node = document.getElementById(id);
if (val.match(/table(-row|-cell)?/) && navigator.userAgent.match(/MSIE [567]/))
val = "block";
if (node !== null)
node.style.display = (node.style.display == val) ? "none" : val;
}
*/
function ac_dom_display_block(id) {
$(id).style.display = "block";
}
function ac_dom_display_inlineblock(id) {
$(id).style.display = "inline-block";
}
function ac_dom_display_none(id) {
$(id).style.display = "none";
}
function ac_dom_toggle_class(id, className1, className2) {
var node = document.getElementById(id);
if ( !node ) return;
node.className = ( node.className == className1 ? className2 : className1 );
}
// We don't recurse to the child nodes here; this function itself is a
// shallow foreach.
function ac_dom_foreach_node(node, fun) {
while (node !== null) {
fun(node);
node = node.nextSibling;
}
}
// The idea here is to take an HTML collection and walk through it, as
// opposed to an actual node. (You would use foreach_item, for example,
// with the result of a call to document.getElementsByTagName().)
function ac_dom_foreach_item(coll, fun) {
for (var i = 0; i < coll.length; i++)
fun(coll[i]);
}
function ac_dom_foreach_child(obj, fun) {
for (var i = 0; i < obj.childNodes.length; i++)
fun(obj.childNodes[i]);
}
// Useful for removing all children at once, which isn't a standard
// DOM function but does come up from time to time.
function ac_dom_remove_children(node) {
var filter = null;
if (arguments.length > 1) {
// they passed a filter function
filter = arguments[1];
}
for (var i = node.childNodes.length - 1; i >= 0; i--) {
if (typeof filter != "function")
node.removeChild(node.childNodes[i]);
else if (filter(node.childNodes[i]))
node.removeChild(node.childNodes[i]);
}
}
function ac_dom_append_childtext(node, text) {
node.appendChild(document.createTextNode(text));
}
// Create a new