/******* Common Js for Sohu Personal Protal Park **********/
//	Author: Todd Lee (www.todd-lee.com)
//	Last Update: 2006-09-21
/**********************************************************/
var LoadBar = {
    show:function (text, type) {
        clearTimeout(this.timeout);
        text = text || ('loading...');
        this.build(text);
        if (type == 'ok') {
            Element.addClassName(this.element, 'okBar');
        } else {
            Element.removeClassName(this.element, 'okBar');
        }
        Element.show(this.element);
        this.element.style.right = '0px';
        this.element.style.top = document.documentElement.scrollTop + 30 + 'px';
        this.showStatusBar(text);
    },
    hide:function (delay) {
        if (LoadBar.element) {
            LoadBar.timeout = setTimeout(function () {
                if (LoadBar.element) {
                    Element.hide(LoadBar.element);

                }
                LoadBar.hideStatusBar();

            }, ((delay && !isNaN(delay)) ? delay : 0));

        }
    },
    destroy:function () {
        if (this.element) {
            Element.remove(this.element);
            this.element = null;
        }
    },
    build:function (text) {
        if (this.element) {
            this.element.firstChild.firstChild.alt = text;
            this.element.firstChild.childNodes[1].nodeValue = text;
            return;
        }
        this.element = document.createElement('div');
        Element.addClassName(this.element, 'loadBar');
        this.element.style.zIndex = 1000;
        this.element.style.position = 'absolute';
        Element.hide(this.element);

        var innerDiv = document.createElement('div');
        var img = '/theme/default/images/loading.gif';
        innerDiv.innerHTML = '<img src="' + img + '" alt="text" />' + text;
        this.element.appendChild(innerDiv);
        document.body.appendChild(this.element);
    },
    showStatusBar:function (text) {
        setTimeout(function () {
            window.status = text;
        }, 10);

    },
    hideStatusBar:function () {
        setTimeout(function () {
            window.status = '';

        }, 10);

    },
    loadPage:function () {
        this.show('请稍候，正在下载...');
    }
};

function getPageSize() {
    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if (self.innerHeight) {  // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
    var pageHeight, pageWidth;

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
}

function resizeImage(obj) {
    var pageSize = getPageSize();
    if (obj.width > pageSize.windowWidth * 0.9) {
        obj.resized = true;
        obj.width = pageSize.windowWidth * 0.9;
    }
        obj.alt = "单击这里开新视窗查看";
        obj.onmouseover = function() {
        obj.style.cursor = 'pointer';
    }

}

function getContainer(el, tagName, tagId) {
    if (tagName) {
        var container = el.parentNode;
        if (container.nodeType == 1 && container.tagName.toLowerCase() == tagName && (!tagId || container.getAttribute('id') == tagId)) return container;
        else return getContainer(container, tagName);
    } else {
        var container = el.parentNode;
        if (container.nodeType == 1) return container;
        else return getContainer(container);
    }
}

function getQueryString(p){
    var url=location.search.substring(1);
    var tempStr=p+"=";
    if(url.indexOf(tempStr)==-1)
        return null;
    if(url.indexOf("&")!=-1) {
        var a=url.split("&");
        var i=0;
        for( i=0;i<a.length;i++) {
            if(a[i].indexOf(tempStr)!=-1)
                return a[i].substring(tempStr.length);
        }
    } else
        return url.substring(tempStr.length);
}

function reportError() {
    //Dialog.closeInfo();
    dialog = Dialog.alert("服务器出现未知错误，请重新再试一次！", {windowParameters: {className: "alphacube", width:300, effectOptions:{duration: 0}}, okLabel: '关闭'});
}
function showLoading() {
    LoadBar.show('正在读取，请稍候...');
}
function hideLoading() {
    LoadBar.hide();
}
