var Try_js = {
    these_js: function () {
        var returnValue;
        for (var i = 0; i < arguments.length; i++) {
            var lambda = arguments[i];
            try {
                returnValue = lambda();
                break;
            } catch (e) {}
        }
        return returnValue;
    }
};
var _type = function (obj) {
    if (obj.htmlElement) return 'element';
    var type = typeof obj;
    if (type == 'object' && obj.nodeName) {
        switch (obj.nodeType) {
        case 1:
            return 'element';
        case 3:
            return (/\S/).test(obj.nodeValue) ? 'textnode' : 'whitespace';
        }
    }
    if (type == 'object' || type == 'function') {
        switch (obj.constructor) {
        case Array:
            return 'array';
        case RegExp:
            return 'regexp';
        case Class_js:
            return 'class';
        }
        if (typeof obj.length == 'number') {
            if (obj.item) return 'collection';
            if (obj.callee) return 'arguments';
        }
    }
    return type;
};
var _merge = function () {
    var mix = {};
    for (var i = 0; i < arguments.length; i++) {
        for (var property in arguments[i]) {
            var ap = arguments[i][property];
            var mp = mix[property];
            if (mp && _type(ap) == 'object' && _type(mp) == 'object') mix[property] = _merge(mp, ap);
            else mix[property] = ap;
        }
    }
    return mix;
};
var _extend_js = function () {
    var args = arguments;
    if (!args[1]) args = [this, args[0]];
    for (var property in args[1]) args[0][property] = args[1][property];
    return args[0];
};
var _native = function () {
    for (var i = 0, l = arguments.length; i < l; i++) {
        arguments[i].extend_js = function (props) {
            for (var prop in props) {
                if (!this.prototype[prop]) this.prototype[prop] = props[prop];
                if (!this[prop]) this[prop] = _native.generic(prop);
            }
        };
    }
};
_native.generic = function (prop) {
    return function (bind) {
        return this.prototype[prop].apply(bind, Array.prototype.slice.call(arguments, 1));
    };
};
var Class_js = function (properties) {
    var klass_ja = function () {
        return (arguments[0] !== null && this.initialize && _type(this.initialize) == 'function') ? this.initialize.apply(this, arguments) : this;
    };
    _extend_js(klass_ja, this);
    klass_ja.prototype = properties;
    klass_ja.constructor = Class_js;
    return klass_ja;
};
Class_js.prototype = {
    extend_js: function (properties) {
        var proto = new this(null);
        for (var property in properties) {
            var pp = proto[property];
            proto[property] = Class_js.Merge(pp, properties[property]);
        }
        return new Class_js(proto);
    },
    implement: function () {
        for (var i = 0, l = arguments.length; i < l; i++) _extend_js(this.prototype, arguments[i]);
    }
};
Class_js.empty = function () {};
Class_js.Merge = function (previous, current) {
    if (previous && previous != current) {
        var type = _type(current);
        if (type != _type(previous)) return current;
        switch (type) {
        case 'function':
            var merged = function () {
                this.parent = arguments.callee.parent;
                return current.apply(this, arguments);
            };
            merged.parent = previous;
            return merged;
        case 'object':
            return _merge(previous, current);
        }
    }
    return current;
};
var Events = new Class_js({
    addEvent: function (type, fn) {
        if (fn != Class_js.empty) {
            this.$events = this.$events || {};
            this.$events[type] = this.$events[type] || [];
            this.$events[type].include_js(fn);
        }
        return this;
    },
    fireEvent_js: function (type, args, delay) {
        if (this.$events && this.$events[type]) {
            this.$events[type].each(function (fn) {
                fn.create({
                    'bind': this,
                    'delay': delay,
                    'arguments': args
                })();
            }, this);
        }
        return this;
    },
    removeEvent: function (type, fn) {
        if (this.$events && this.$events[type]) this.$events[type].remove(fn);
        return this;
    }
});
var Options = new Class_js({
    setOptions: function () {
        this.options = _merge.apply(null, [this.options].extend_js(arguments));
        if (this.addEvent) {
            for (var option in this.options) {
                if (_type(this.options[option] == 'function') && (/^on[A-Z]/).test(option)) this.addEvent(option, this.options[option]);
            }
        }
        return this;
    }
});
document.getElementsByClassName_js = function (className, root) {
    var children = (root ? root : document).getElementsByTagName('*') || (root ? root : document).all;
    var elements_js = new Array();
    for (var i = 0; i < children.length; i++) {
        var child = children[i];
        var classNames = child.className.split(' ');
        for (var j = 0; j < classNames.length; j++) {
            if (classNames[j] == className) {
                elements_js.push(child);
                break;
            }
        }
    }
    return elements_js;
};
var Element = {
    hasClass: function (klass_ja) {
        return String(this.className).indexOf(klass_ja) !== - 1;
    },
    addClass: function (klass_ja) {
        this.className += ' ' + klass_ja;
        return this;
    },
    removeClass: function (klass_ja) {
        var expr = new RegExp(' ?' + klass_ja);
        this.className = this.className.replace(expr, '');
        return this;
    },
    replaceClass: function (klass_ja1, klass_ja2) {
        this.className = this.className.replace(klass_ja1, klass_ja2);
        return this;
    },
    getValue_js: function () {
        if (!this.tagName) return false;
        switch (this.tagName.toLowerCase()) {
        case 'select':
            var values = [];
            $$$A(this.options).each(function (option) {
                if (option.selected) values.push(option.value || option.text);
            });
            return (this.multiple) ? values : values[0];
        case 'input':
            if (!(this.checked && ['checkbox', 'radio'].contains(this.type)) && !['hidden', 'text', 'password'].contains(this.type)) break;
        case 'textarea':
            return this.value;
        }
        return false;
    }
};

function $$$(el) {
    var type = _type(el);
    if (type == 'string') {
        var elem = document.getElementById(el);
    }
    else var elem = el;
    try {
        if (elem.htmlElement) return elem;
        _extend_js(elem, Element);
        elem.htmlElement = true;
    } catch (e) {}
    return elem;
};
_native(Function, Array, String, Number);
Function.extend_js({
    create: function (options) {
        var fn = this;
        options = _merge({
            'bind': fn,
            'event': false,
            'arguments': null,
            'delay': false,
            'periodical': false,
            'attempt': false
        }, options);
        if ( !! options.arguments && _type(options.arguments) != 'array') options.arguments = [options.arguments];
        return function (event) {
            var args;
            if (options.event) {
                event = event || window.event;
                args = [(options.event === true) ? event : new options.event(event)];
                if (options.arguments) args.extend_js(options.arguments);
            }
            else args = options.arguments || arguments;
            var returns = function () {
                return fn.apply(options.bind || fn, args);
            };
            if (options.delay) return setTimeout(returns, options.delay);
            if (options.periodical) return setInterval(returns, options.periodical);
            if (options.attempt) try {
                return returns();
            } catch (err) {
                return false;
            };
            return returns();
        };
    },
    bind: function (bind, args) {
        return this.create({
            'bind': bind,
            'arguments': args
        });
    },
    bindAsEventListener: function (bind, args) {
        return this.create({
            'bind': bind,
            'event': true,
            'arguments': args
        });
    },
    delay: function (delay, bind, args) {
        return this.create({
            'delay': delay,
            'bind': bind,
            'arguments': args
        })();
    },
    periodical: function (interval, bind, args) {
        return this.create({
            'periodical': interval,
            'bind': bind,
            'arguments': args
        })();
    }
});
Array.extend_js({
    forEach: function (fn, bind) {
        for (var i = 0, j = this.length; i < j; i++) fn.call(bind, this[i], i, this);
    },
    filter: function (fn, bind) {
        var results = [];
        for (var i = 0, j = this.length; i < j; i++) {
            if (fn.call(bind, this[i], i, this)) results.push(this[i]);
        }
        return results;
    },
    map: function (fn, bind) {
        var results = [];
        for (var i = 0, j = this.length; i < j; i++) results[i] = fn.call(bind, this[i], i, this);
        return results;
    },
    every: function (fn, bind) {
        for (var i = 0, j = this.length; i < j; i++) {
            if (!fn.call(bind, this[i], i, this)) return false;
        }
        return true;
    },
    some: function (fn, bind) {
        for (var i = 0, j = this.length; i < j; i++) {
            if (fn.call(bind, this[i], i, this)) return true;
        }
        return false;
    },
    indexOf: function (item, from) {
        var len = this.length;
        for (var i = (from < 0) ? Math.max(0, len + from) : from || 0; i < len; i++) {
            if (this[i] === item) return i;
        }
        return -1;
    },
    remove: function (item) {
        var i = 0;
        var len = this.length;
        while (i < len) {
            if (this[i] === item) {
                this.splice(i, 1);
                len--;
            } else {
                i++;
            }
        }
        return this;
    },
    copy: function (start, length) {
        start = start || 0;
        if (start < 0) start = this.length + start;
        length = length || (this.length - start);
        var newArray = [];
        for (var i = 0; i < length; i++) newArray[i] = this[start++];
        return newArray;
    },
    contains: function (item, from) {
        return this.indexOf(item, from) != - 1;
    },
    include_js: function (item) {
        if (!this.contains(item)) this.push(item);
        return this;
    },
    extend_js: function (array) {
        for (var i = 0, j = array.length; i < j; i++) this.push(array[i]);
        return this;
    },
    merge: function (array) {
        for (var i = 0, l = array.length; i < l; i++) this.include_js(array[i]);
        return this;
    }
});
Array.prototype.each = Array.prototype.forEach;
Array.each = Array.forEach;

function $$$A(array) {
    return Array.copy(array);
};
String.extend_js({
    trim: function () {
        return this.replace(/^ *(.*?) *$/, '$1');
    },
    isEmpty: function () {
        return this.trim().length < 1;
    },
    evalScripts: function () {
        try {
            var script, scripts;
            scripts = [];
            var regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;
            while ((script = regexp.exec(this))) scripts.push(script[1]);
            scripts = scripts.join('\n');
            if (scripts)(window.execScript) ? window.execScript(scripts) : window.setTimeout(scripts, 0);
        } catch (e) {}
    }
});
new
function () {
    var b = navigator.userAgent.toLowerCase();
    browser = {
        safari: /webkit/.test(b),
        opera: /opera/.test(b),
        msie: /msie/.test(b) && !/opera/.test(b),
        mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
    };
};
var Event_js = {
    KEY_BACKSPACE: 8,
    KEY_TAB: 9,
    KEY_RETURN: 13,
    KEY_ESC: 27,
    KEY_LEFT: 37,
    KEY_UP: 38,
    KEY_RIGHT: 39,
    KEY_DOWN: 40,
    KEY_DELETE: 46,
    element: function (event) {
        return event.target || event.srcElement;
    },
    isLeftClick: function (event) {
        return (((event.which) && (event.which == 1)) || ((event.button) && (event.button == 1)));
    },
    pointerX: function (event) {
        return event.pageX || (event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft));
    },
    pointerY: function (event) {
        return event.pageY || (event.clientY + (document.documentElement.scrollTop || document.body.scrollTop));
    },
    stop: function (event) {
        if (event.preventDefault) {
            event.preventDefault();
            event.stopPropagation();
        } else {
            event.returnValue = false;
        }
    },
    findElement: function (event, tagName) {
        var element = Event_js.element(event);
        while (element.parentNode && (!element.tagName || (element.tagName.toUpperCase() != tagName.toUpperCase())))
        element = element.parentNode;
        return element;
    },
    observers: false,
    _observeAndCache: function (element, name, observer, useCapture) {
        if (!this.observers) this.observers = [];
        if (element.addEventListener) {
            this.observers.push([element, name, observer, useCapture]);
            element.addEventListener(name, observer, useCapture);
        } else if (element.attachEvent) {
            this.observers.push([element, name, observer, useCapture]);
            element.attachEvent('on' + name, observer);
        }
    },
    unloadCache: function () {
        if (!Event_js.observers) return;
        for (var i = 0; i < Event_js.observers.length; i++) {
            Event_js.stopObserving.apply(this, Event_js.observers[i]);
            Event_js.observers[i][0] = null;
        }
        Event_js.observers = false;
    },
    observe: function (element, name, observer, useCapture) {
        var element = $$$(element);
        useCapture = useCapture || false;
        if (name == 'keypress' && ((navigator.appVersion.indexOf('AppleWebKit') > 0) || element.attachEvent)) name = 'keydown';
        this._observeAndCache(element, name, observer, useCapture);
    },
    stopObserving: function (element, name, observer, useCapture) {
        var element = $$$(element);
        useCapture = useCapture || false;
        if (name == 'keypress' && ((navigator.appVersion.indexOf('AppleWebKit') > 0) || element.detachEvent)) name = 'keydown';
        if (element.removeEventListener) {
            element.removeEventListener(name, observer, useCapture);
        } else if (element.detachEvent) {
            element.detachEvent('on' + name, observer);
        }
    },
    isReady: false,
    readyList: [],
    onReady: function (fn) {
        Event_js.readyList.push(fn);
    },
    ready: function () {
        if (!Event_js.isReady) {
            Event_js.isReady = true;
            if (Event_js.readyList) {
                Event_js.readyList.each(function (f) {
                    f.apply(document);
                });
                Event_js.readyList = null;
            }
            if (browser.mozilla || browser.opera) document.removeEventListener("DOMContentLoaded", Event_js.ready, false);
        }
    }
};
new
function () {
    if (browser.mozilla || browser.opera) document.addEventListener("DOMContentLoaded", Event_js.ready, false);
    else if (browser.msie) {
        document.write("<scr" + "ipt id=__ie_init defer=true " + "src=//:><\/script>");
        var script = document.getElementById("__ie_init");
        if (script) script.onreadystatechange = function () {
            if (this.readyState != "complete") return;
            this.parentNode.removeChild(this);
            Event_js.ready();
        };
        script = null;
    } else if (browser.safari) var safariTimer = setInterval(function () {
        if (document.readyState == "loaded" || document.readyState == "complete") {
            clearInterval(safariTimer);
            safariTimer = null;
            Event_js.ready();
        }
    }, 10);
    else Event_js.observe(window, "load", Event_js.ready);
}
var XHR = new Class_js({
    options: {
        method: 'post',
        async: true,
        onRequest: Class_js.empty,
        onSuccess: Class_js.empty,
        onFailure: Class_js.empty,
        urlEncoded: true,
        encoding: 'utf-8',
        autoCancel: false,
        headers: {}
    },
    setTransport: function () {
        this.transport_js = Try_js.these_js(function () {
            return new ActiveXObject('Msxml2.XMLHTTP')
        }, function () {
            return new ActiveXObject('Microsoft.XMLHTTP')
        }, function () {
            return new XMLHttpRequest()
        }) || false;
        return this;
    },
    initialize: function (options) {
        this.setTransport().setOptions(options);
        this.options.isSuccess = this.options.isSuccess || this.isSuccess;
        this.headers = {};
        if (this.options.urlEncoded && this.options.method == 'post') {
            var encoding = (this.options.encoding) ? '; charset=' + this.options.encoding : '';
            this.setHeader('Content-type', 'application/x-www-form-urlencoded' + encoding);
        }
        if (this.options.initialize) this.options.initialize.call(this);
    },
    onStateChange: function () {
        if (this.transport_js.readyState != 4 || !this.running) return;
        this.running = false;
        var status = 0;
        try {
            status = this.transport_js.status;
        } catch (e) {};
        if (this.options.isSuccess.call(this, status)) this.onSuccess();
        else this.onFailure();
        this.transport_js.onreadystatechange = Class_js.empty;
    },
    isSuccess: function (status) {
        return ((status >= 200) && (status < 300));
    },
    onSuccess: function () {
        this.response = {
            'text': this.transport_js.responseText,
            'xml': this.transport_js.responseXML
        };
        this.fireEvent_js('onSuccess', [this.response.text, this.response.xml]);
    },
    onFailure: function () {
        this.fireEvent_js('onFailure', this.transport_js);
    },
    setHeader: function (name, value) {
        this.headers[name] = value;
        return this;
    },
    send: function (url, data) {
        if (this.options.autoCancel) this.cancel();
        else if (this.running) return this;
		this.running = true;
        if (data && this.options.method == 'get') {
            url = url + (url.contains('?') ? '&' : '?') + data;
            data = null;
        }
		this.transport_js.open(this.options.method.toUpperCase(), url, this.options.async);
        this.transport_js.onreadystatechange = this.onStateChange.bind(this);
		
        if ((this.options.method == 'post') && this.transport_js.overrideMimeType) this.setHeader('Connection', 'close');
		_extend_js(this.headers, this.options.headers);
        for (var type in this.headers)
        try {
            this.transport_js.setRequestHeader(type, this.headers[type]);
        } catch (e) {};

		this.fireEvent_js('onRequest');

		this.transport_js.send(data || null);


		return this;
    },
    cancel: function () {
        if (!this.running) return this;
        this.running = false;
        this.transport_js.abort();
        this.transport_js.onreadystatechange = Class_js.empty;
        this.setTransport();
        this.fireEvent_js('onCancel');
        return this;
    }
});
XHR.implement(new Events, new Options);
var Ajax_js = XHR.extend_js({
    options: {
        data: null,
        update: null,
        onComplete: Class_js.empty,
        evalScripts: false,
        evalResponse: false
    },
    initialize: function (url, options) {
        this.addEvent('onSuccess', this.onComplete);
        this.setOptions(options);
        this.options.data = this.options.data || this.options.postBody;
        if (!['post', 'get'].contains(this.options.method)) {
            this._method = '_method=' + this.options.method;
            this.options.method = 'post';
        }
        this.parent();
        this.setHeader('X-Requested-With', 'XMLHttpRequest');
        this.setHeader('Accept', 'text/javascript, text/html, application/xml, text/xml, */*');
        this.url = url;
    },
    onComplete: function () {
        if (this.options.update) $$$(this.options.update).innerHTML = this.response.text;
        if (this.options.evalScripts || this.options.evalResponse) this.evalScripts();
        this.fireEvent_js('onComplete', [this.response.text, this.response.xml], 20);
    },
    request: function (data) {
        data = data || this.options.data;
		if (this._method) data = (data) ? [this._method, data].join('&') : this._method;
		return this.send(this.url, data);
    },
    evalScripts: function () {
        try {
            var script, scripts;
            if (this.options.evalResponse || (/(ecma|java)script/).test(this.getHeader('Content-type'))) scripts = this.response.text;
            else {
                scripts = [];
                var regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;
                while ((script = regexp.exec(this.response.text))) scripts.push(script[1]);
                scripts = scripts.join('\n');
            }
            if (scripts)(window.execScript) ? window.execScript(scripts) : window.setTimeout(scripts, 0);
        } catch (e) {}
    },
    getHeader: function (name) {
        try {
            return this.transport_js.getResponseHeader(name);
        } catch (e) {};
        return null;
    }
});
var Effect = {};
Effect.Base = new Class_js({
    options: {
        transitions: function (pos) {
            return (-Math.cos(pos * Math.PI) / 2) + 0.5;
        },
        duration: 1,
        fps: 10,
        onStart: Class_js.empty,
        onUpdate: Class_js.empty,
        onEnd: Class_js.empty
    },
    initialize: function (options) {
        this.setOptions(options);
        this.startOn = new Date().getTime();
        this.finishOn = this.startOn + (this.options.duration * 1000);
        this.fireEvent_js('onStart');
        this.timer = this.loop.periodical(this.options.fps, this);
    },
    loop: function () {
        var timePos = new Date().getTime();
        if (timePos >= this.finishOn) {
            this.fireEvent_js('onEnd');
            clearInterval(this.timer);
            return;
        }
        var pos = (timePos - this.startOn) / (this.finishOn - this.startOn);
        pos = this.options.transitions(pos);
        this.fireEvent_js('onUpdate', [pos]);
    }
});
Effect.Base.implement(new Events, new Options);

function pageSize() {
    var d = document;
    return [(d.compatMode == 'BackCompat' ? d.body : d.documentElement).scrollWidth, d.documentElement.scrollHeight];
}

function setStyle_js(elm, property) {
    var type = _type(property);
    if (type == 'object') {
        for (var prop in property) {
            $$$(elm).style[prop] = property[prop];
        }
    }
}
var ShadowLayer = new Class_js({
    options: {
        element: 'shadowWindow',
        parent: null
    },
    initialize: function (options) {
        this.setOptions(options);
        this.element = $$$(this.options.element);
        this.status = 'idle';
        setStyle_js(this.element, {
            'visibility': 'hidden'
        });
        with(this.element.style) {
            if (typeof(filter) != 'undefined') {
                filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/shadow.png,sizingMethod='scale')";
            } else {
                backgroundImage = 'url(images/shadow.png)';
            }
        }
    },
    pageShadow: function (flg) {
        if ($$$('PageShadowLayer') && flg) setStyle_js($$$('PageShadowLayer'), {
            'display': 'block'
        });
        else if (!$$$('PageShadowLayer')) {
            var lay = document.createElement('DIV');
            var size = pageSize();
            with(lay) {
                id = 'PageShadowLayer';
                style.position = 'absolute';
                style.zIndex = 998;
                style.left = '0px';
                style.top = '0px';
                style.width = size[0] + 'px';
                style.height = size[1] + 'px';
                if (typeof(style.filter) != 'undefined') {
                    style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/shadow.png,sizingMethod='scale')";
                } else {
                    style.backgroundImage = 'url(images/shadow.png)';
                }
            }
            if (browser.msie) {
                var iframe = document.createElement('IFRAME');
                lay.appendChild(iframe);
                lay.className += 'select-free';
            }
            document.body.appendChild(lay);
        }
        setStyle_js($$$('PageShadowLayer'), {
            'display': flg ? 'block' : 'none'
        });
    },
    getParentSize: function () {
        var parent = this.element.parent;
        if (!parent) {
            do {
                parent = this.element.parentNode;
                if (parent.tagName == 'DIV') break;
            } while (parent.tagName != 'BODY');
            this.options.parent = parent;
        }
        return [parent.offsetWidth, parent.offsetHeight];
    },
    show: function (callback) {
        if (this.status != 'idle') return false;
        callback = callback || Class_js.empty;
        var size = this.getParentSize();
        setStyle_js(this.element, {
            'visibility': 'visible',
            'width': size[0] + 'px',
            'height': size[1] + 'px'
        });
        callback();
    },
    hide: function () {
        if (this.status != 'idle') return false;
        this.status = 'idle';
        setStyle_js(this.element, {
            'visibility': 'hidden'
        });
    }
});
ShadowLayer.implement(new Options);
var eWindow = new Class_js({
    options: {
        element: 'WindowLayer',
        table: 'WindowTable',
        title: 'windowTitle',
        body: 'windowContent',
        close: 'windowClose',
        imgpath: 'images/zwindow/'
    },
    initialize: function (options) {
        this.setOptions(options);
        this.element = $$$(this.options.element);
        var self = this,
            close = $$$(this.options.close);
        Event_js.observe(this.options.close, 'mouseover', (function () {
            this.src = self.options.imgpath + 'close_over.gif';
        }).bind(close));
        Event_js.observe(this.options.close, 'mouseout', (function () {
            this.src = self.options.imgpath + 'close_normal.gif';
        }).bind(close));
        Event_js.observe(this.options.close, 'mousedown', (function () {
            this.src = self.options.imgpath + 'close_down.gif';
        }).bind(close));
        Event_js.observe(this.options.close, 'click', this.hide.bindAsEventListener(this));
        setStyle_js($$$(this.options.close), {
            'cursor': 'pointer'
        });
    },
    setSize: function (size) {
        var size = pageSize();
        setStyle_js(this.element, {
            'width': size[0] + 'px'
        });
        return this;
    },
    show: function () {
        this.setSize();
        setStyle_js(this.element, {
            'display': 'block'
        });
        if (Shadow) Shadow.show();
    },
    setWidth: function (w) {
        if (!w) return this;
        setStyle_js(this.options.table, {
            'width': w + 'px'
        });
        return this;
    },
    hide: function () {
        this.setTitle('').setBody('');
        setStyle_js(this.element, {
            'display': 'none'
        });
        if (Shadow) Shadow.hide();
        this.fireEvent_js('onHide');
    },
    setTitle: function (text) {
        $$$(this.options.title).innerHTML = text;
        return this;
    },
    setBody: function (text) {
        $$$(this.options.body).innerHTML = text;
        return this;
    }
});
eWindow.implement(new Events, new Options);
var includedFiles = new Array();

function include_js(file, callback) {
    includedFiles.push(file);
    ajaxReq('js/?f=' + file, {
        method: 'get'
    }, callback);
}

function include_once(file, callback) {
    if (includedFiles.indexOf(file) === - 1) {
        include_js(file, callback);
        return true;
    }
    return false;
}

function getLoadingHTML(element) {
    return '<table class="loading_progress" cellpadding="0" cellspacing="0" border="0" width="100%" dir="rtl"><tr><td><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td  align="center"><img src="../images/motools/loadingAnimation.gif" /></td></tr><tr><td align="CENTER"><b style="color:#fff; font-family:tahoma; font-size:12px;">در حال بارگذاری، لطفا منتظر بمانید...</b></td></tr></table></td></tr></table>';
}

function ajaxReq(url, options, callback, fx) {
    var req = function () {
        options = options || {};
        options.evalScripts = true;
		if (options.update && options.preload) $$$(options.update).innerHTML = getLoadingHTML(options.update);
		var ajax_rr = new Ajax_js(url, options);

		
        ajax_rr.addEvent('onComplete', function (r) {
            if (options.update && ($$$(options.update).id == 'home_page')) w='#'; //window.location = '#';
            if (fx) Shadow.hide();
            (callback || Class_js.empty)(r);
        });


		ajax_rr.addEvent('onFailure', function (r) {
            if (fx) Shadow.hide();
        });
				
        ajax_rr.request();
    }
    fx ? Shadow.show(req) : req();
}

function ajaxload(element, url, callback) {
    ajaxReq(url + '&ty=a', {
        update: element,
        preload: true,
        method: 'get'
    }, callback);
}

function ajaxPost(element, url, body) {
    ajaxReq(url + '&ty=a', {
        update: element,
        data: body,
        method: body ? 'post' : 'get',
        preload: true
    });
}

function winAjaxLoad(url, title, width, body, callback) {
    if (!zWindow) return false;
    zWindow.addEvent('onHide', function () {});
    ajaxReq(url + '&ty=a', {
        data: body,
        method: body ? 'post' : 'get'
    }, function (r) {
        zWindow.setTitle(title).setBody(r).setWidth(width).show();
//        window.location = '#';
    });
}

function homepageLoad_(title, zp, callback) {
    $$$('other_homepage_modules').style.display = 'none';
    $$$('home_page_div').style.display = '';
    try {
        elm = $$$('home_page');
    } catch (e) {}
    ajaxload(elm, zp, callback);
    if (title && !title.isEmpty()) $$$('home_page_header').innerHTML = title;
//    window.location = '#';
}

function homepageLoad(title, zp, callback) {
    $$$('other_homepage_modules').style.display = 'none';
    $$$('home_page_div').style.display = '';	
    try {
        elm = $$$('home_page');
    } catch (e) {}
    ajaxReq(zp + (zp.indexOf('?') == - 1 ? '?' : '&') + 'ty=a', {
        update: elm,
        preload: true,
        method: 'get'
    }, function () {
        initPageLink();
        if (callback) callback();
    });
    if (title && !title.isEmpty()) $$$('home_page_header').innerHTML = title;
//    window.location = '#';
		var myelement = $j("#home_page_div");
		var myoffset = myelement.offset();
		window.scrollTo(0,myoffset.top)		
}

function doFormSubmit(id, url, body) {
		var myelement = $j("#home_page_div");
		var myoffset = myelement.offset();
		window.scrollTo(0,myoffset.top)		
	
    ajaxReq(url + (url.indexOf('?') == - 1 ? '?' : '&') + 'ty=a', {
        update: id,
        data: body,
        method: body ? 'post' : 'get',
        preload: true
    });
}

function dolittleFormSubmit(id, url, body) {
    ajaxlittleReq(url + (url.indexOf('?') == - 1 ? '?' : '&') + 'ty=a', {
        update: id,
        data: body,
        method: body ? 'post' : 'get',
        preload: true
    });
}

function getlittleLoadingHTML(element) {
    return '<img src="images/indicator_red.gif" /><b style="font-size:10px;padding-left:5px;">Loading . . . ,Please wait</b>';
}

function ajaxlittleReq(url, options, callback, fx) {
    var req = function () {
        options = options || {};
        options.evalScripts = true;
		if (options.update && options.preload) $$$(options.update).innerHTML = getlittleLoadingHTML(options.update);
		var ajax_rr = new Ajax_js(url, options);

		
        ajax_rr.addEvent('onComplete', function (r) {
            if (options.update && ($$$(options.update).id == 'home_page')) w='#'; //window.location = '#';
            if (fx) Shadow.hide();
            (callback || Class_js.empty)(r);
        });


		ajax_rr.addEvent('onFailure', function (r) {
            if (fx) Shadow.hide();
        });
				
        ajax_rr.request();
    }
    fx ? Shadow.show(req) : req();
}



function doFormSubmit_bytitle(id, title, url, body) {
    $$$('other_homepage_modules').style.display = 'none';
    $$$('home_page_div').style.display = '';
    ajaxReq(url + (url.indexOf('?') == - 1 ? '?' : '&') + 'ty=a', {
        update: id,
        data: body,
        method: body ? 'post' : 'get',
        preload: true
    });
    $$$('home_page_header').innerHTML = title;
//    window.location = '#';
}

function backToHomepage() {
    if (!window.location.href.match(new RegExp('^.*\/(index\.php)?(#.*)?$'))) {
        window.location = 'index.php';
        return true;
    }
    $$$('other_homepage_modules').style.display = '';
    $$$('home_page_div').style.display = 'none';	
		$j.post("/backend.php", {"currenturl": ""});
		var myelement = $j("#home_page_div");
		var myoffset = myelement.offset();
		window.scrollTo(0,myoffset.top)		
		
		
}
var currentPage = new Array();

function changePage(page, group, fix_height) {
    try {
        if (parseInt($$$('section_' + page).style.height) != (fix_height || 0)) hideSection(page, false, fix_height);
        else showSection(page);
    } catch (e) {
        return false;
    }
}

function showSection(page, not1st) {
    var section = $$$('section_' + page);
    with(section) {
        if (!not1st) {
            style.display = '';
        }
        style.height = offsetHeight + Math.ceil((scrollHeight - offsetHeight) / 8) + 'px';
        if (offsetHeight < scrollHeight) {
            if (section.hideTimer) {
                clearTimeout(section.hideTimer);
                section.hideTimer = 0;
            }
            section.showTimer = setTimeout('showSection("' + page + '", true);', 20);
        } else {
            section.showTimer = 0;
            style.overflow = 'visible';
        }
    }
}

function hideSection(page, not1st, fix_height) {
    fix_height = fix_height || 0;
    var section = $$$('section_' + page);
    if (section.style.display == 'none') {
        return;
    }
    var tmph = section.offsetHeight;
    if (!not1st) {
        section.style.overflow = 'hidden';
    }
    section.style.height = section.offsetHeight - Math.ceil(section.offsetHeight / 8) + 'px';
    if (browser == 'gecko' && document.documentElement.scrollHeight - (document.documentElement.scrollTop + document.documentElement.clientHeight) < section.offsetHeight) {
        document.documentElement.scrollTop -= (tmph - section.offsetHeight);
    }
    if (section.offsetHeight > fix_height) {
        if (section.showTimer) {
            clearTimeout(section.showTimer);
            section.showTimer = 0;
        }
        section.hideTimer = setTimeout('hideSection("' + page + '", true, ' + fix_height + ');', 20);
    } else {
        section.hideTimer = 0;
        section.style.height = fix_height + 'px';
    }
}
var customer_num = 0;

function scrollCustomer(pos) {
    $$$('fix_news_box').scrollTop = $$$('fix_news_box').scrollTop + 1;
    if (pos > $$$('fix_news_box').scrollTop) setTimeout('scrollCustomer(' + pos + ');', 10);
    else setTimeout(nextCustomer, 3000);
}

function nextCustomer() {
    customer_num++;
    if (customer_num == $$$('fix_news_table').rows.length) {
        customer_num = 1;
        $$$('fix_news_box').scrollTop = 0;
    }
    scrollCustomer($$$('fix_news_table').rows[customer_num].offsetTop);
}

function checkMail(email) {
    return !!email.match(new RegExp('^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$', 'i'));
}

function show_message(msg, elm) {
    alert(msg);
    try {
        if (elm.focus && _type(elm.focus) == 'function') elm.focus();
    } catch (e) {}
}

function getOffset(obj, attr) {
    var offset = 0;
    while (obj) {
        offset += obj['offset' + attr];
        obj = obj.offsetParent;
    }
    return offset;
}

function getDirection(obj) {
    var dir = 'ltr';
    while (obj) {
        if (obj.style.direction != '') return obj.style.direction.toLowerCase();
        if (obj.dir != '') return obj.dir.toLowerCase();
        obj = obj.parentNode;
    }
    return dir;
}

function initPageLink(className, root) {
    document.getElementsByClassName_js(className || 'ajax_link', root || $$$('home_page_div')).each(function (link) {
        if (link._addLinkEvent) return;
        link._addLinkEvent = true;
        Event_js.observe(link, 'click', function (e) {
            Event_js.stop(e);
            var location = link.getAttribute('href');
            var linkTitle = link.getAttribute('title') || link.text || link.innerText || 'none';
            if (location.length > 1) homepageLoad(linkTitle, location);
        });
    });
}

function inviteFriend() {
    var emails = $$$('friend_emails');
    var mail = $$$('member_email');
    var name = $$$('member_name');
    try {
        var comSp = emails.value.split(",");
    } catch (e) {
        var comSp = [];
    }
    var insertEmails = [];
    for (var i = 0; i < comSp.length; i++) {
        try {
            insertEmails = insertEmails.concat(String(comSp[i]).split("\n"));
        } catch (e) {
            continue;
        }
    }
    var postEmail = [];
    for (var i = 0; i < insertEmails.length; i++) {
        insertEmails[i] = String(insertEmails[i]).replace(/^\s+/, '').replace(/\s+$/, '');
        if (insertEmails[i].length < 1) {
            insertEmails.splice(i, 1);
            continue;
        }
        postEmail.push('mail[]=' + insertEmails[i]);
    }
    var rg = [{
        border: '1px solid green'
    },
    {
        border: '1px solid red'
    }];
    if (name.value == '') {
        setStyle_js(name, rg[1]);
        name.focus();
        return false;
    } else setStyle_js(name, rg[0]);
    if (mail.value == '') {
        setStyle_js(mail, rg[1]);
        mail.focus();
        return false;
    } else setStyle_js(mail, rg[0]);
    if (!postEmail.length) {
        setStyle_js(emails, rg[1]);
        emails.focus();
        return false;
    } else setStyle_js(emails, rg[0]);
    postEmail.push('name[]=' + name.value);
    postEmail.push('email[]=' + mail.value);
    ajaxPost($$$('send2F'), inite_location, postEmail.join('&'));
}
var zWindow, Shadow, domReady;

function onPageLoad() {
    domReady = true;
    Shadow = new ShadowLayer;
    zWindow = new eWindow;
    try {
        if ($$$('fix_news_table').rows.length > 1) {
            $$$('fix_news_table').insertRow($$$('fix_news_table').rows.length).insertCell(0).innerHTML = $$$('fix_news_table').rows[0].cells[0].innerHTML + '<br />&nbsp;';
            setTimeout(nextCustomer, 3000);
        }
    } catch (e) {}
    initPageLink(null, document);
}
Event_js.onReady(onPageLoad);
