/*
 * GLOBAL VAIRABLES DEFINITION
 */
//var _g_service_data = null;

/*
 * MAIN FUNCTION, PROGRAM ENTRENCE
 */
document.observe('dom:loaded',function(){
    // INIT GLOBAL
    initGlobal();
    // disable part of the page from user interaction.
    if(typeof hzDisableEventDivId != "undefined" && Object.isString(hzDisableEventDivId)){
        disableDivEvent(hzDisableEventDivId);
        //send ajax request, wait notify...
        new Ajax.Request(emailVerifyAjaxUrl+'/?'+loginUid, {
                method:'post',
  		onSuccess: function(response) {
                    //var rText = response.responseText;
                    //alert(rText);
                    //if(rText == "email verify success"){
                        enableDivEvent(hzDisableEventDivId);
                        $("email_verify_tip_div").hide();
                   //}
  		}
	});
    }
    // EVERY PAGE MAY HAVE ONE INIT FUNCTION TO INIT PAGE DISPALY
    if(typeof initFrame != "undefined" && Object.isFunction(initFrame) ){
        initFrame();
    }
    if(typeof initPage != "undefined" && Object.isFunction(initPage) ){
        initPage();
    }
    if(typeof initPage2 != "undefined" && Object.isFunction(initPage2) ){
        initPage2();
    }
    if(typeof initPage3 != "undefined" && Object.isFunction(initPage3) ){
        initPage3();
    }
    if(typeof initPage4 != "undefined" && Object.isFunction(initPage4) ){
        initPage4();
    }
    if(typeof initPage5 != "undefined" && Object.isFunction(initPage5) ){
        initPage5();
    }
    // NOT USED ANYMORE
    if(typeof correctPNG != "undefined" && Object.isFunction(correctPNG) ){
        correctPNG();
    }
    if(typeof setRedirectURL4Login != "undefined" && Object.isFunction(setRedirectURL4Login) ){
        setRedirectURL4Login();
    }
    
});

var AtSignAutoComplete = {
    inputTextArea : null,
    textDiv : null,
    atWhoDiv : null,
    atWhoSignalSpan : null,
    atWhoKeySpan : null,
    atWhoTextSpan : null,
    atSignKey : "",
    atKeySIndex : 0,
    atWhoUl : null,
    displayAtWhoDiv : false,
    arrowKeyType : false,
    //处理文本中的@regex标记：“向前”读取离文本光标最近的@regex标记
    processAtSign : function(text, caretPos) {
        var atRegex = /@[\w\u4e00-\u9fa5]+/g;
        var length = text.length;
        var subLength = length < caretPos ? length : caretPos;
        var processText = text.substring(0,subLength);
        var matchArray = processText.match(atRegex);
        if(matchArray ==null) {
            return false;
        } else {
            //读取最后一个匹配
            var atSignKey = matchArray[matchArray.length -1];
            var atKey = atSignKey.substring(atSignKey.indexOf("@")+1);
            var atSignKeySIndex = processText.lastIndexOf(atSignKey);
            var atSignKeyEIndex = atSignKeySIndex + atSignKey.length;
            if(atSignKeyEIndex < caretPos) {
                return false;
            }
            var beforeAtSignStr = processText.substring(0, atSignKeySIndex);
            //将回车替换为html换行符
            beforeAtSignStr = beforeAtSignStr.replace("\n","<br/>")
            beforeAtSignStr = beforeAtSignStr.replace(/\s/g,"<span style='white-space:pre-wrap;font-size:14px;'>&nbsp;</span>")
            AtSignAutoComplete.atWhoTextSpan.innerHTML = beforeAtSignStr;
            AtSignAutoComplete.atWhoKeySpan.innerHTML = atKey;
            AtSignAutoComplete.atSignKey = atSignKey;
            AtSignAutoComplete.atKeySIndex = atSignKeySIndex + 1;
            if(!AtSignAutoComplete.arrowKeyType){
                AtSignAutoComplete.sendQuery(atKey);
            }
            return true;
        }
    },
    processTextAreaEvent:function(event) {
        var e = window.event || event;
        var eventEle = e.srcElement || e.target;
        var value = eventEle.value;
        if(e.type == "keydown") {
            if(AtSignAutoComplete.displayAtWhoDiv) {
                //如果此时正在选择条目中，那么处理文本域中的特殊按键事件
                var keycode = e.keyCode || e.which;
                var highlightItem = AtSignAutoComplete.getHighLightItem();
                switch(keycode){
                    //回车
                    case 13:
                        if(highlightItem != null) {
                            var text = highlightItem.innerHTML;
                            AtSignAutoComplete.insertSelectAtWhoValue(text);
                        }
                        AtSignAutoComplete.arrowKeyType = false;
                        return false;
                    //左箭头
                    case 37:
                        AtSignAutoComplete.arrowKeyType = true;
                        return false;
                    //上箭头
                    case 38:
                        var previousItem = highlightItem.previous("li");
                        if(previousItem != undefined) {
                            AtSignAutoComplete.removeAllHighLightClass();
                            previousItem.setAttribute("id","highlightACL");
                        }
                        AtSignAutoComplete.arrowKeyType = true;
                        return false;
                    //右箭头
                    case 39:
                        AtSignAutoComplete.arrowKeyType = true;
                        return false;
                    //下箭头
                    case 40:
                        var nextItem = highlightItem.next("li");
                        if(nextItem == undefined) {
                            nextItem = $(AtSignAutoComplete.atWhoUl).firstDescendant();
                        }
                        if(nextItem != undefined){
                            AtSignAutoComplete.removeAllHighLightClass();
                            nextItem.setAttribute("id","highlightACL");
                        }
                        AtSignAutoComplete.arrowKeyType = true;
                        return false;
                    default:
                        AtSignAutoComplete.arrowKeyType = false;
                }
            } else {
                AtSignAutoComplete.arrowKeyType = false;
            }
        } else {
            if(value.indexOf("@")!=-1){
                var caretPos = Position_HZ.getCaretPosition(eventEle);
                var result = AtSignAutoComplete.processAtSign(value,caretPos);
                if(!result) {
                    AtSignAutoComplete.hideAtWhoDiv();
                }
            }
        }
        
    },
    processAtWhoDivEvent : function() {
        var refNameItems = $(AtSignAutoComplete.atWhoUl).select("li");
        refNameItems.each(function(refNameItem,index){
            refNameItem.observe("mouseover",function(event){
                AtSignAutoComplete.removeAllHighLightClass();
                var item = event.element();
                item.setAttribute("id","highlightACL");
            });
            refNameItem.observe("click",function(event){
                var item = event.element();
                var text = item.innerHTML;
                AtSignAutoComplete.insertSelectAtWhoValue(text);
            });
        });
    },
    //删除所有选项的高亮类名
    removeAllHighLightClass : function(){
        var refNameItems = $(AtSignAutoComplete.atWhoUl).select("li");
        refNameItems.each(function(refNameSItem,index){
            refNameSItem.removeAttribute("id");
        });
    },
    //获得此时高亮显示的选项
    getHighLightItem : function(){ 
        return $(AtSignAutoComplete.atWhoUl).select("#highlightACL")[0];
    }, 
    //选择选项后，将其内容插入到文本框中
    insertSelectAtWhoValue : function(text) {
        var textAreaValue = AtSignAutoComplete.inputTextArea.value;
        AtSignAutoComplete.inputTextArea.value = textAreaValue.substring(0,AtSignAutoComplete.atKeySIndex) + text+" " + textAreaValue.substring(AtSignAutoComplete.atKeySIndex + AtSignAutoComplete.atSignKey.length - 1);
        AtSignAutoComplete.hideAtWhoDiv();
        Position_HZ.setCaretPosition(AtSignAutoComplete.inputTextArea, AtSignAutoComplete.inputTextArea.value.length);
    },
    //定位引称选择DIV
    positionAtWhoDiv:function() {
        var atWhoDivLeft = Position_HZ.getLeft(AtSignAutoComplete.atWhoSignalSpan);
        var atWhoDivHeight = Position_HZ.getTop(AtSignAutoComplete.atWhoSignalSpan) + AtSignAutoComplete.atWhoSignalSpan.offsetHeight;
        AtSignAutoComplete.atWhoDiv.style.left = atWhoDivLeft + "px";
        AtSignAutoComplete.atWhoDiv.style.top = atWhoDivHeight + "px";
        AtSignAutoComplete.showAtWhoDiv();
    },
    positionTextDiv:function(event) {
        var e = window.event || event;
        if(e.type == "focus") {
            var textDivId = AtSignAutoComplete.inputTextArea.getAttribute("id");
            if(textDivId=="microblogContent"){
                Microblog.mblogFocus('我在忙些什么...');
            } else if(textDivId=="question_content"){
                Focus.hideStr(AtSignAutoComplete.inputTextArea, '我想知道...');
            }
        }
        AtSignAutoComplete.textDiv.style.height = AtSignAutoComplete.inputTextArea.clientHeight + "px";
        AtSignAutoComplete.textDiv.style.width = AtSignAutoComplete.inputTextArea.clientWidth + "px";
        //设置padding
        AtSignAutoComplete.textDiv.style.paddingTop = HzElement.getStyle(AtSignAutoComplete.inputTextArea, "padding-top");
        AtSignAutoComplete.textDiv.style.paddingLeft = HzElement.getStyle(AtSignAutoComplete.inputTextArea, "padding-left");
        AtSignAutoComplete.textDiv.style.paddingRight = HzElement.getStyle(AtSignAutoComplete.inputTextArea, "padding-right");
        AtSignAutoComplete.textDiv.style.paddingBottom = HzElement.getStyle(AtSignAutoComplete.inputTextArea, "padding-bottom");
        
        AtSignAutoComplete.textDiv.style.left = Position_HZ.getLeft(AtSignAutoComplete.inputTextArea) + "px";
        AtSignAutoComplete.textDiv.style.top = Position_HZ.getTop(AtSignAutoComplete.inputTextArea) + "px";
    },
    //初始化元素和绑定事件处理函数
    init : function(elInputId, elContainerId) {
        //Init Element
        AtSignAutoComplete.inputTextArea = document.getElementById(elInputId);
        AtSignAutoComplete.atWhoDiv =  document.getElementById(elContainerId);
        AtSignAutoComplete.textDiv = document.getElementById("textDiv");
        AtSignAutoComplete.atWhoSignalSpan = document.getElementById("atWhoSignalSpan");
        AtSignAutoComplete.atWhoKeySpan = document.getElementById("atWhoKeySpan");
        AtSignAutoComplete.atWhoTextSpan = document.getElementById("atWhoTextSpan");
        AtSignAutoComplete.atWhoKeyInput = document.getElementById("atWhoKeyInput");
        AtSignAutoComplete.positionTextDiv();
        //处理inputTextArea事件
        this.inputTextArea.onkeyup = AtSignAutoComplete.processTextAreaEvent;
        this.inputTextArea.onfocus = AtSignAutoComplete.positionTextDiv;
        this.inputTextArea.onkeydown = AtSignAutoComplete.processTextAreaEvent;
        this.inputTextArea.onclick = AtSignAutoComplete.processTextAreaEvent;
        //设置atWhoDiv内容
        if(AtSignAutoComplete.atWhoDiv.getElementsByTagName("ul").length==0) {
            //创建ul
            AtSignAutoComplete.atWhoUl = HzElement.createElement("ul");
            //创建标题div
            AtSignAutoComplete.atWhoDiv.appendChild(HzElement.createElement("div", "想用@提到谁？", "autoCompleteTitle"));
            AtSignAutoComplete.atWhoDiv.appendChild(AtSignAutoComplete.atWhoUl);
        } else {
            AtSignAutoComplete.atWhoUl = AtSignAutoComplete.atWhoDiv.getElementsByTagName("ul")[0];
        } 
       
        
    },
    showAtWhoDiv : function() {
        AtSignAutoComplete.atWhoDiv.style.display = "block";
        AtSignAutoComplete.displayAtWhoDiv = true;
    },
    hideAtWhoDiv : function(){
        AtSignAutoComplete.atWhoDiv.style.display = "none";
        AtSignAutoComplete.displayAtWhoDiv = false;
    },
    sendQuery : function(keyword) {
        new Ajax.Request("/Profile3.do?action=QUERY_REFNAME", {
            parameters:{
                keyword : keyword
            },
            requestHeaders : {
                Accept: 'application/json'
            }, 
            onCreate : function(){
            },
            onSuccess : function(transport){
                var json = transport.responseText.evalJSON(true);
                if(json.RETURN){
                    $(AtSignAutoComplete.atWhoUl).update("");
                    var refNames = json.refNames;
                    if(refNames.length < 1){
                        //无相应结果
                        AtSignAutoComplete.atWhoUl.appendChild(
                            HzElement.createElement("li", AtSignAutoComplete.atSignKey.substring(1), "highlightACL","highlightACL")
                            );
                    } else {
                        refNames.each(function(refName,index){
                            if(index == 0) {
                                AtSignAutoComplete.atWhoUl.appendChild(
                                    HzElement.createElement("li", refName, "highlightACL","highlightACL")
                                    );
                            } else {
                                AtSignAutoComplete.atWhoUl.appendChild(HzElement.createElement("li", refName)); 
                            }
                        });
                    }
                    AtSignAutoComplete.processAtWhoDivEvent();
                    AtSignAutoComplete.positionAtWhoDiv();
                }else{
            }
            }.bind(this),
            onComplete : function(){
            }
        })
    }
}

function stopEventPropagation(event){
    var elt = $(Event.element(event)).up('.hzEnableWhenEmailNotVirified');
    if(elt != "undefined" && elt !=null){
        return;
    }
    Event.stop(event);
    alert('您的邮箱还没有验证，部分功能无法使用。请您验证您的邮箱。');
}

function disableDivEvent(divId){
    Event.observe(divId, 'click', stopEventPropagation);
    Event.observe(divId, 'dbclick', stopEventPropagation);
    Event.observe(divId, 'mousedown', stopEventPropagation);
    Event.observe(divId, 'mouseup', stopEventPropagation);
    //Event.observe(divId, 'keydown', stopEventPropagation);
    Event.observe(divId, 'keypress', stopEventPropagation);
    Event.observe(divId, 'keyup', stopEventPropagation);
}
            
function enableDivEvent(divId){
    Event.stopObserving(divId);
}

function setRedirectURL4Login(){
    var cookie_name = "hzRedirectURL4Login";
    if(typeof hzRedirectURL4Login != "undefined"){
        if(hzRedirectURL4Login){
            // if hzRedirectURL4Login == true, SAVE URL FOR REDIRECT
            var cookie_value = document.URL;
            var cookie_string = cookie_name + "=" + escape ( cookie_value )+ "; path=/";
            document.cookie = cookie_string;
        }else{
    // if hzRedirectURL4Login == false, do nothing,
    // example: login page, do not save or delete this cookie, just keep anything untouched.
    }
    }else{
        // DEL COOKIE
        document.cookie = cookie_name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +"; path=/";
    }
}

// This function is for stripping leading and trailing spaces
String.prototype.trim = function () {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
//This function is for stripping trailing spaces
String.prototype.Rtrim = function() {
    return this.replace(/([\s]*$)/g,"");
};

Object.extend(String.prototype, {
    templateDecode: function() {
        var decoded = this.replace(/#%7B([a-zA-Z0-9_-]+)%7D/gi, "#{$1}");
        return decoded;
    }
});

function initGlobal(){
// LOAD HEADER
//    HeaderFooter.setHeaderMenuSelection();
}

// PRE_DEFINED PAGE INIT FUNCTION FOR EVERY PAGE.
//function initPage(){
//	alert("initPage");
//	return null;
//}

/**
* HEADER FOOTER FUNCTIONS
*/
var HeaderFooter = {
    // HIGLLIGHT MENU IF THE URL MATCHES
    setHeaderMenuSelection: function(){
        
        // GET CURRENT PAGE STRING FROM URL
        var currentPage = document.location.pathname;
        //        var lastIdx = currentPage.lastIndexOf('/')+1;

        //        currentPage = currentPage.substring(lastIdx).strip();
        currentPage = currentPage.strip();
        var subCurrentPage = currentPage;
        
        if(currentPage.include("network")){
            currentPage = "network";
            subCurrentPage = currentPage + "_null";
        }else if(currentPage.include("profile1") || currentPage.startsWith("upload") || currentPage.startsWith("link")){
            currentPage = "network";
            subCurrentPage = "profile1";
        }else if(currentPage.include("profile2")){
            currentPage = "network";
            subCurrentPage = "profile2";
        }else if(currentPage.include("profile.jsp") || currentPage.startsWith("slide_list_other")){
            currentPage = "network";
            subCurrentPage = currentPage + "_null";
        }else if(currentPage.include("inner_invite")){
            currentPage = "mail";
            subCurrentPage = currentPage + "_null";
        }else if(currentPage.include("invitation")){
            currentPage = "network";
            subCurrentPage = "invitation";
        //        }else if(currentPage.include("slide_list_pub") || currentPage.include("slide_list_search")){
        }else if(currentPage.include("slides")){
            currentPage = "slides";
            subCurrentPage = currentPage + "_null";
        //        }else if(currentPage.include("slide_list_mybookmark")){
        //            currentPage = "slide_list_pub";
        //            subCurrentPage = "slide_list_mybookmark";
        //        }else if(currentPage.include("slide_list_my.")){
        //            currentPage = "slide_list_pub";
        //            subCurrentPage = "slide_list_my.";
        //        }else if(currentPage.include("slide_upload")){
        //            currentPage = "slide_list_pub";
        //            subCurrentPage = "slide_upload";
        }else if(currentPage.include("groups")){
            currentPage = "groups";
            subCurrentPage = currentPage + "_null";
        }else if(currentPage.include("events")){
            currentPage = "events";
            subCurrentPage = currentPage + "_null";
        }
        
        // IF ROOT
        if(currentPage.length<2){
            currentPage = "/";
        }
        // GET MATCHED ELEMENT
        if($('menu') == null){
            return;
        }
        //        var aSelectedPage = $('frame_sidebar').select('dt');
        //        var subaSelectedPage = $('frame_sidebar').select('dd');

        var aSelectedPage = $("HeaderMenu1").select("li");
        var subaSelectedPage = $("HeaderMenu2").select("li");

        for(var i=0;i<aSelectedPage.size();i++){
            var tmp = aSelectedPage[i];
            
            if(tmp.innerHTML.include(currentPage)){
                // SET ID=CURRENT, WILL HIGH LIGHT MENU
                tmp.setAttribute('id', 'selected');
            }else{
                // REMOVE ALL OTHER ID, IF PRE-SET
                tmp.removeAttribute('id');
            }
        }
        
        for(i=0;i<subaSelectedPage.size();i++){
            var subTmp = subaSelectedPage[i];

            if(subTmp.innerHTML.include(subCurrentPage)){
                // SET ID=CURRENT, WILL HIGH LIGHT MENU
                subTmp.setAttribute('id', 'selected');
            }else{
                // REMOVE ALL OTHER ID, IF PRE-SET
                subTmp.removeAttribute('id');
            }
        }
    }
}


var BackGray = Class.create({
    initialize: function(){
        this.body = document.body;
        this.midDivId = "mid_div";
        this.body_width = (this.body.scrollLeft + this.body.scrollWidth > window.screen.availWidth) ? window.screen.availWidth : this.body.scrollLeft + this.body.scrollWidth;
        this.body_height = (this.body.scrollTop + this.body.scrollHeight < window.screen.availHeight) ? window.screen.availHeight : this.body.scrollTop + this.body.scrollHeight;
    },
    
    _createTopDiv : function(topDivId, template){
        var DivTop = document.createElement("div");
        with(DivTop.style)
        {
            display = "none";
            zIndex = 3;
            position = "absolute";
            border = "0px"; 
            }
        DivTop.id = topDivId;
        DivTop.innerHTML = template;
        this.body.appendChild(DivTop);
        
    },
    _createMidDiv : function(midDivId){
        var DivMid = document.createElement("div");
        
        with(DivMid.style)
        {
            display = "none";
            zIndex = 2;
            position = "absolute";
            top = 0;
            left = 0;
            if(location.href.include("home")){
                height = "150%";
            }else if(location.href.include("profile")){
                height = "120%";
            }else{
                height = "100%";
            }
            width = "100%";
            border = "0px";
            backgroundColor = "#000000";
        
            
            }
        DivMid.id = this.midDivId;
        this.body.appendChild(DivMid);
    },
    _center : function(element){
        //xinjun change
        //$(element).style.position ="absolute";
        $(element).style.top = "25%";
        $(element).style.left = "50%";
        //$(element).style.width = "50%";
        //$(element).style.height ="100%";
        if($(element) != null) {
    //            /*
    //            if(typeof window.innerHeight != 'undefined') {
    //                $(element).style.top =
    //                    Math.round(document.viewport.getScrollOffsets().top +
    //                    ((window.innerHeight - $(element).clientHeight) + 100)/2)+'px';
    //                $(element).style.left =
    //                    Math.round(document.viewport.getScrollOffsets().left +
    //                    ((window.innerWidth))/2)+'px';
    //            } else {
    //                $(element).style.top =
    //                    Math.round(document.body.scrollTop +
    //                    (($$('body')[0].clientHeight - $(element).clientHeight))/2)+'px';
    //                $(element).style.left =
    //                    Math.round(document.body.scrollLeft +
    //                    (($$('body')[0].clientWidth))/2)+'px';
    //            }//*/
    }
    },
    action : function(topDivId, template){
        var trans = 75;
        if(Prototype.Browser.IE)
            trans = 35;
        
        this._createTopDiv(topDivId, template);
        this._createMidDiv(this.midDivId);
   
        with(this.body.style){
            width = this.body_width;
            height = this.body_height;
            }

        with($(this.midDivId).style){
            display ="";
            height = this.body_height;
            width = "100%";
            
            if(Prototype.Browser.IE){
                filter = " Alpha(Opacity="+trans+")";
            }else{
                opacity = trans/250;
            }
            }
        with($(topDivId).style){
            display = "";
            }
        this._center(topDivId);
    },
    closeTopDiv : function(topDivId){
        with(this.body.style){
            overflow = "auto";
            }
        with($(this.midDivId).style){
            display = "none";
            }
                
        with($(topDivId).style){
            display = "none"; 
            }
    }
});

var Popup = Class.create({
    initialize : function(inputElement, tip){
        this._showPopup(inputElement, tip);
        this._hidePopup(inputElement);
    },
    _showPopup : function(inputElement, tip){
        inputElement.observe("focus", function(){
            if($(inputElement.id +"_span") != null){
                $(inputElement.id +"_span").remove();
            }
            //            var div = new Element("div", {"class" : "tishi"});
            //            var subDiv = new Element("div", {"class" : "tishibottom"});
            //            div.appendChild(subDiv);
            //            subDiv.insert({"after" : tip});
            //            var span = new Element('span', {"id" : inputElement.id + "_span", "style" : "position:absolute"});
            //            span.appendChild(div);
            //            inputElement.insert({"after" : span});
            var popHTML ='<div class="tishileft"></div>' + 
            '<div class="rounded">' +
            '<h2></h2>' +
            '<div class="main"></div>' +
            '<div class="footer"><p></p></div>' +
            '</div>';
            var div = new Element("span", {
                "id" : inputElement.id + "_span",
                "class" : "tishi"
            }).update(popHTML);
            var tipDiv = div.select('[class="main"]')[0];
            tipDiv.width = "500px";
            tipDiv.update(tip);
            inputElement.insert({
                "after" : div
            });
        })
    },
    _hidePopup : function(inputElement){
        inputElement.observe("blur", function(){
            if($(inputElement.id +"_span") != null){
                $(inputElement.id +"_span").remove();
            }
        }),
        inputElement.observe("keypress", function(){
            if($(inputElement.id +"_span") != null){
                $(inputElement.id +"_span").remove();
            }
        })
    }
});

var PopupForButton = Class.create({
    initialize : function(inputElement, tip){
        this._showPopup(inputElement, tip);
        this._hidePopup(inputElement);
    },
    _showPopup : function(inputElement, tip){
        inputElement.observe("mousemove", function(){
            if($(inputElement.id +"_span") != null){
                $(inputElement.id +"_span").remove();
            }
            var popHTML ='<div class="tishileft"></div>' +
            '<div class="rounded">' +
            '<h2></h2>' +
            '<div class="main"></div>' +
            '<div class="footer"><p></p></div>' +
            '</div>';
            var div = new Element("span", {
                "id" : inputElement.id + "_span",
                "class" : "tishi"
            }).update(popHTML);
            var tipDiv = div.select('[class="main"]')[0];
            tipDiv.width = "500px";
            tipDiv.update(tip);
            inputElement.insert({
                "after" : div
            });
        })
    },
    _hidePopup : function(inputElement){
        inputElement.observe("mouseout", function(){
            if($(inputElement.id +"_span") != null){
                $(inputElement.id +"_span").remove();
            }
        }),
        inputElement.observe("keypress", function(){
            if($(inputElement.id +"_span") != null){
                $(inputElement.id +"_span").remove();
            }
        })
    }
});

function correctPNG()
{
    if (Prototype.Browser.IE) {
        for(var i=0; i<document.images.length; i++)
        {
            var img = document.images[i];
            var imgName = img.src.toUpperCase();
            if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
            {
                var imgID = (img.id) ? "id='" + img.id + "' " : "";
                var imgClass = (img.className) ? "class='" + img.className + "' " : "";
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
                var imgStyle = "display:inline-block;" + img.style.cssText;
                if (img.align == "left") imgStyle = "float:left;" + imgStyle;
                if (img.align == "right") imgStyle = "float:right;" + imgStyle;
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
                var strNewHTML = "<span "+ imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src='" + img.src + "', sizingMethod='scale');\"></span>";
                img.outerHTML = strNewHTML;
                i = i-1;
            }
        }
    }
}

function isAllNumberStr(str){
    if(/^\d+$/.test(str)){
        return true;
    }else{
        return false;
    }
}

var Paging = {
    pagination: function(page){
        $("page_num").value = page;
        $("search_form").submit();
    },
    paginationById : function(page, formId, pageNumFieldId) {
        $(pageNumFieldId).value = page;
        $(formId).submit();
    }
}

function setBackground(actType, e){
    if(actType == "over"){
        e.style.background = "#F3F7FC";
    }else{
        e.style.background = "#FFFFFF";
    }
}

function compareTwoDateIsEqual(bDate,eDate){  
    if(bDate.getTime() == eDate.getTime()){
        return true;
    }else{
        return false;
    }
}

function focusHide(e,str){
    if(e.value.indexOf(str) != -1){
        e.value = "";
        e.style.color="#000";
    }
}

function focusShow(e,str){
    if(e.value == ""){
        e.style.color="#999";
        e.value = str;
    }
}
