/*-------------------------------------------------
 *TopNav funciton 
 * Copyright (c) 2007 Allen Dog & Diigo System.
 *------------------------------------------------*/
var TopNav = Class.create();
TopNav.ShowTimeOut = null;
TopNav.hideTimeOut = null;
TopNav.mouseoverHandler =  function(id){
    TopNav.clearTimeHandler();
    TopNav.showTimeOut = setTimeout(function(){TopNav.showContextMenu(id)},50);
}
TopNav.mouseoutHandler = function(){
    TopNav.clearTimeHandler();
    TopNav.hideTimeOut = setTimeout(TopNav.hideContextMenu,200);
}
TopNav.clearTimeHandler = function(){
    clearTimeout(TopNav.showTimeOut);
    clearTimeout(TopNav.hideTimeOut)
}
TopNav.showContextMenu = function(id){
    //IE6 select overlap bug
    if(!$("contextMenuHideIframe")){
        TopNav.hideIframe = new Element('iframe', {id: "contextMenuHideIframe"});
        document.body.appendChild(TopNav.hideIframe);
        TopNav.hideIframe.hide();
    }
    TopNav.hideIframe = $("contextMenuHideIframe");
	
    li = $(id);
    if(TopNav.selected && TopNav.selected != li){
        TopNav.hideContextMenu();
    }
    TopNav.selected = li;
    var toggler = li.down();
    var submenu = toggler.next();
		
    if(!submenu.visible()){		
        toggler.addClassName("flyMenu")
        var p = [0,0]		
    	var p=[toggler.offsetLeft,toggler.offsetTop]
        var left = 0;
        var top = 0;  
        var offsetX = 0;
        left = p[0] + offsetX;
        top = p[1]+toggler.getHeight();
        submenu.setStyle({display: "block", left: left+"px", top:top+"px"});      
        submenu_p = Position.cumulativeOffset(submenu);
        TopNav.hideIframe.setStyle({display: "block",position:'absolute',left: submenu_p[0]+"px", top: submenu_p[1]+"px", width: submenu.getWidth()+"px", height: submenu.getHeight()+"px"});
    }
}
TopNav.hideContextMenu = function(){
    if(TopNav.selected){
        var toggler = TopNav.selected.down();
        var submenu = toggler.next();		
        if(submenu.visible()){
            TopNav.hideIframe.hide();
            submenu.hide();	
            toggler.removeClassName("flyMenu");
        }
        TopNav.selected = null;
    }
}
// JavaScript Document
/* on document mouse up */
window.onmouseupListeners = [];
window.addOnMouseUpListener = function(listener) {
    window.onmouseupListeners[window.onmouseupListeners.length] = listener;
}

function initOnMouseUp() {
    window.document.onmouseup = function() {
        for(var i=0; i<window.onmouseupListeners.length;i++) {
            var func = window.onmouseupListeners[i];
            func.call();
        }
    }
}
/* on document mouse up */


window.globalObjects = [];
window.registerGlobalObject = function(object) {
    window.globalObjects[object.id] = object;
}

String.prototype.trim = function() {
    return this.replace(/^\s*/,"").replace(/\s*$/,"");
}

String.prototype.replaceAll = function(AFindText,ARepText,i){ 
    raRegExp = new RegExp(AFindText,"g"+i); 
    return this.replace(raRegExp,ARepText) 
}

Array.prototype.removeItem = function(index) {
    if(index==0) {
        this.shift();
        return this;
    }else if(index>=this.length || index<0) {
        return this;
    }else {
        return this.slice(0, index).concat(this.slice(index+1, this.length));
    }
}

function switchStyle(s) {
    if (!document.getElementsByTagName) return;
    var el = document.getElementsByTagName("link");
    for (var i = 0; i < el.length; i++ ) {
        if (el[i].getAttribute("rel").indexOf("style") != -1 && el[i].getAttribute("title")) {
            el[i].disabled = true;
            if (el[i].getAttribute("title") == s) el[i].disabled = false;
        }
    }
}
//
function switchBox(editor, switcher){
    new Effect[Element.visible(editor) ? 
            'BlindUp' : 'BlindDown'](editor, {duration: 0.25});
    new Effect[Element.visible(switcher) ? 
            'BlindUp' : 'BlindDown'](switcher, {duration: 0.25}); 
}

function switchBox2(box1, box2){
    new Effect[Element.visible(box1) ? 
            'BlindUp' : 'BlindDown'](box1, {duration: 0.25});
    new Effect[Element.visible(box2) ? 
            'BlindUp' : 'BlindDown'](box2, {duration: 0.25}); 
}

// 
function encodeAdSyntax() {
    var p_what = "";
    // encode tags
    var p_tags = $F('ad_tags').trim();
    if(p_tags!='') {
        p_tags = "tag:("+p_tags+") ";
        p_what += p_tags;
    }
    // encode title
    var p_url = $F('ad_url').trim();
    if(p_url!='') {
        p_url = "url:("+p_url+") ";
        p_what += p_url;
    }
    // encode title
    var p_title = $F('ad_title').trim();
    if(p_title!='') {
        p_title = "title:("+p_title+") ";
        p_what += p_title;
    }
    // encode text
    var p_text = $F('ad_text').trim();
    if(p_text!='') {
        p_text = "text:("+p_text+") ";
        p_what += p_text;
    }
    // encode comments
    var p_comments = $F('ad_comments').trim();
    if(p_comments!='') {
        p_comments = "c:("+p_comments+") ";
        p_what += p_comments;
    }
    // encode highlights
    var p_highlights = $F('ad_highlights').trim();
    if(p_highlights!='') {
        p_highlights = "h:("+p_highlights+") ";
        p_what += p_highlights;
    }
    // encode anywhere
    var p_anywhere = $F('ad_anywhere').trim();
    if(p_anywhere!='') {
        p_anywhere = p_anywhere+" ";
        p_what += p_anywhere;
    }
  
    // encode anywhere 2
    var p_anywhere_2 = $F('ad_anywhere_2').trim();
    if(p_anywhere_2!='') {
        p_anywhere_2 = "\""+p_anywhere_2+"\" ";
        p_what += p_anywhere_2;
    }
  
    // encode nowhere
    var p_nowhere = $F('ad_nowhere').trim();
    if(p_nowhere!='') {
        p_nowhere = "-("+p_nowhere+")"; 
        p_what += p_nowhere;
    }
    return p_what;
}

function decodeAdSyntax(whatID) {
    var p_what = $F(whatID).trim();
    // decode tags
    var re = new RegExp(/tags?:\([^\)]*\)/i);
    var t_match_a = p_what.match(re);
    if(t_match_a) {
        var t_match_str = t_match_a[0];
        p_what = p_what.replace(t_match_str,'');
        var p_tags = t_match_str.substring(t_match_str.indexOf(':(')+2, t_match_str.length-1);
        $('ad_tags').value = p_tags.trim();
    }else {
        $('ad_tags').value = "";    
    }
  
    // decode title
    var re = new RegExp(/titles?:\([^\)]*\)/i);
    var t_match_a = p_what.match(re);
    if(t_match_a) {
        var t_match_str = t_match_a[0];
        p_what = p_what.replace(t_match_str,'');
        var p_title = t_match_str.substring(t_match_str.indexOf(':(')+2, t_match_str.length-1);
        $('ad_title').value = p_title.trim();
    }else {
        $('ad_title').value = "";    
    }
  
    // decode text
    var re = new RegExp(/text?:\([^\)]*\)/i);
    var t_match_a = p_what.match(re);
    if(t_match_a) {
        var t_match_str = t_match_a[0];
        p_what = p_what.replace(t_match_str,'');
        var p_text = t_match_str.substring(t_match_str.indexOf(':(')+2, t_match_str.length-1);
        $('ad_text').value = p_text.trim();
    }else {
        $('ad_text').value = "";    
    }
  
    // decode url
    var re = new RegExp(/url:\([^\)]*\)/i);
    var t_match_a = p_what.match(re);
    if(t_match_a) {
        var t_match_str = t_match_a[0];
        p_what = p_what.replace(t_match_str,'');
        var p_url = t_match_str.substring(t_match_str.indexOf(':(')+2, t_match_str.length-1);
        $('ad_url').value = p_url.trim();
    }else {
        $('ad_url').value = "";    
    }
  
    // decode comments
    var re = new RegExp(/c:\([^\)]*\)/i);
    var t_match_a = p_what.match(re);
    if(t_match_a) {
        var t_match_str = t_match_a[0];
        p_what = p_what.replace(t_match_str,'');
        var p_comments = t_match_str.substring(t_match_str.indexOf(':(')+2, t_match_str.length-1);
        $('ad_comments').value = p_comments.trim();
    }else {
        $('ad_comments').value = "";    
    }
  
    // decode highlights
    var re = new RegExp(/h:\([^\)]*\)/i);
    var t_match_a = p_what.match(re);
    if(t_match_a) {
        var t_match_str = t_match_a[0];
        p_what = p_what.replace(t_match_str,'');
        var p_highlights = t_match_str.substring(t_match_str.indexOf(':(')+2, t_match_str.length-1);
        $('ad_highlights').value = p_highlights.trim();
    }else {
        $('ad_highlights').value = "";    
    }
  
    // decode nowhere
    var re = new RegExp(/\-\([^\)]*\)/i);
    var t_match_a = p_what.match(re);
    if(t_match_a) {
        var t_match_str = t_match_a[0];
        p_what = p_what.replace(t_match_str,'');
        var p_nowhere = t_match_str.substring(t_match_str.indexOf('-(')+2, t_match_str.length-1);
        $('ad_nowhere').value = p_nowhere.trim();
    }else {
        $('ad_nowhere').value = "";    
    }
  
    // decode phrase
    var re = new RegExp(/\"[^\"]*\"/i);
    var t_match_a = p_what.match(re);
    if(t_match_a) {
        var t_match_str = t_match_a[0];
        p_what = p_what.replace(t_match_str,'');
        var p_anywhere_2 = t_match_str.substring(t_match_str.indexOf('"')+1, t_match_str.length-1);
        $('ad_anywhere_2').value = p_anywhere_2.trim();
    }else {
        $('ad_anywhere_2').value = "";    
    }
  
    // decode anywhere
    var t_match_str = p_what.trim();
    $('ad_anywhere').value = t_match_str;

}
/*search box*/



function calculateOffest(field, attr) {
    var offset = 0;
    while(field) {
        offset += field[attr]; 
        field = field.offsetParent;
    }
    return offset;
} 

/*function setAdSearchBoxOffsets(adSearchBox) {
    var whatFiled = $("f_t_name");
    var end = whatFiled.offsetWidth;
    var left = calculateOffest(whatFiled, "offsetLeft");
    var top = calculateOffest(whatFiled, "offsetTop") + whatFiled.offsetHeight;
    adSearchBox.style.left = left-6 + "px";
    adSearchBox.style.top = top-47 + "px";
}

function check_who() {
    var whoList = $("who_list");
    if(whoList.style.display=="") {
      whoList.style.display = "none" ;
    }else { 
      setWhoListOffsets(whoList);            
      whoList.style.display = "";
    }
}

function fill_who(id, u_name) {
  $(id).value = u_name;
  check_who();
} */

function displayAvatar(size, avatar) {
    for(var i=0; i<avatar.length; i++) {
        if(avatar[i].offsetWidth>avatar[i].offsetHeight) {
            avatar[i].style.width = size+"px";
        }else if(avatar[i].offsetWidth<avatar[i].offsetHeight) {     
            avatar[i].style.height = size+"px";
        }else {
            avatar[i].style.width = size+"px";
        }
        avatar[i].style.visibility = "visible";              
    }
}
function initSideBarBoxSwitchAble() {
    var index = 0;
    var header = $("sideBarBoxTitle_"+index);
    var eocMark = $("eocMark_"+index);
    var content = $("sideBarBoxContent_"+index);
    while(header) {
        header.onclick = switchSideBarBox;
        if(content.style.display=="") {
            eocMark.className += " expand";
        }else {
            eocMark.className += " collapse";
        }
        index++;
        header = $("sideBarBoxTitle_"+index);
        eocMark = $("eocMark_"+index);
        content = $("sideBarBoxContent_"+index);
    }
}


function switchSideBarBox() {
    var index = this.id.split("_")[1];
    var content = $("sideBarBoxContent_"+index);
    new Effect[Element.visible(content) ? 
            'BlindUp' : 'BlindDown'](content, {duration: 0.25});
    var eocMark = $("eocMark_"+index);
    if(content.style.display=="") {
        eocMark.className = eocMark.className.replace("expand", "collapse");
    }else {
        eocMark.className = eocMark.className.replace("collapse", "expand");
    }
}
function findAvatar(elmentID){
    var avatar = $(elmentID).getElementsByTagName("img")[0];
    return avatar;
}

function initSidebarAvatar() {
    //var avatar = findAvatar("userInfos");
    //displayAvatar(96, [$("avatar")]);
}

/* cookie */
function getCookieDomain() {
    return D_DOMAIN;
}
function Cookie(document, name, hours, path, domain, secure) {
    this.$document = document;
    this.$name = name;
    if(hours)
        this.$expiration = new Date((new Date).getTime() + hours*3600000);
    else this.$expiration = null;
    if(path) this.$path = path; else this.$path = null;
    if(domain) this.$domain = domain; else this.$domain = null;
    if(secure) this.$secure = secure; else this.$secure = null;  
}

Cookie.prototype.store = function() {
    var cookieval = "";
    for(var prop in this) {
        if((prop.charAt(0) =='$' ) || ((typeof this[prop]) == 'function' ))
            continue;
        if(cookieval != "") cookieval += '|';
        cookieval += prop + ':' + escape(this[prop]);
    }
  
    var cookie = this.$name + '=' + cookieval;
    if(this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString();
    if(this.$path) cookie += '; path=' + this.$path;
    if(this.$domain) cookie += '; domain=' + this.$domain;
    if(this.$secure) cookie += '; secure';
    this.$document.cookie = cookie;
}

Cookie.prototype.load = function() {
    var allcookies = this.$document.cookie;
    if(allcookies == '') return false;
  
    var start = allcookies.indexOf(this.$name + '=');
    if(start==-1) return false;
    start += this.$name.length + 1;
    var end = allcookies.indexOf(';', start);
    if(end==-1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);
  
    var a = cookieval.split('|');
    for(var i=0; i<a.length; i++){
        a[i] = a[i].split(':');
    }
  
    for(var i=0; i<a.length; i++) {
        this[a[i][0]] = unescape(a[i][1]);
    }
  
    return true
}

Cookie.prototype.remove = function() {
    var cookie;
    cookie = this.$name + '=';
    if(this.$path) cookie += '; path=' + this.$path;
    if(this.$domain) cookie += '; domain=' + this.$domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
    this.$document.cookie = cookie;
}
/* cookie */

function report() {
    var w = window.open("/report/index", null, "width=380,height=500, left=0, top=0, status=no,resizable=no");
}

function getInstallURL(aEvent) {

    // The event target might be the link itself or one of its children
    var target = aEvent.target;
    while (target && !target.href)
        target = target.parentNode;

    return target && target.href;
}


function install( aEvent, extName, iconURL, extHash) {
    if (aEvent.altKey || !window.InstallTrigger)
        return true;

    var url = getInstallURL(aEvent);

    if (url) {

        var params = new Array();

        params[extName] = {
            URL: url,
            IconURL: iconURL,
            toString: function () { return this.URL; }
        };
        // Only add the Hash param if it exists.
        //
        // We optionally add this to params[] because installTrigger
        // will still try to compare a null hash as long as the var is set.
        if (extHash) {
            params[extName].Hash = extHash;
        }

        InstallTrigger.install(params);

        return false;
    }
    return true;
}

function flashNotice2(content, noticerID, className, duration) {
    if(typeof(noticerID)=="undefined") noticerID = "tailNoticer";
    if(typeof(className)=="undefined") className = "tailNoticer";
    if(typeof(duration)=="undefined") duration = DURATION_1;
    var noticer = $(noticerID);
    if(noticer) {
        noticer.style.display = "";
        noticer.innerHTML = content;
        noticer.className = className;
        noticer.onclick = quickFadeFlashNoticer;
        setTimeout("new Effect.Fade('"+noticerID+"')",duration);
    }
}

function hideNotice2(noticerID) {
    if(typeof(noticerID)=="undefined") noticerID = "tailNoticer";
    var noticer = $(noticerID);
    if(noticer) noticer.style.display = "none";
}

function quickFadeFlashNoticer() {
    setTimeout("new Effect.Fade('"+this.id+"')",DURATION_2);
}
function showCentralNoticer(content, noticerID) {
    if(typeof(noticerID)=='undefined') noticerID = "centralNoticer";
    if(typeof(content)=='undefined') content = "Processing...";
    var noticerBox = $(noticerID+"_box");
    var noticerContent = $(noticerID+"_content");
    if(!noticerBox) {
        noticerBox = document.createElement("div");
        noticerBox.className = "centralNoticerBox";
        noticerBox.id = noticerID+"_box";
        noticerContent = document.createElement("div");
        noticerContent.id = noticerID+"_content";
        noticerContent.className = "centralNoticerContent";
        noticerBox.appendChild(noticerContent);
        document.body.appendChild(noticerBox);
    }
    //TODO
    noticerContent.innerHTML = content;
    var width = document.body.offsetWidth;
    var left = width/2 - $(noticerID+"_box").getWidth()/2;
    noticerBox.show();
    noticerBox.setStyle({"left":left+"px", "top":0});
  
}
function updateCentralNoticer(content, noticerID) {
    if(typeof(noticerID)=='undefined') noticerID = "centralNoticer";
    var noticerBox = $(noticerID+"_content");
    noticerBox.innerHTML = content;
}
function hideCentralNoticer(delay) {
    if(typeof(noticerID)=='undefined') noticerID = "centralNoticer";
    if(typeof(delay)=='undefined') delay = 1;
    delay = delay*1000;
    $(noticerID+"_box").style.display="none";
}

function EasySignin(id){
    if(!$(id+"_switcher")) {
        this.valid = false;
        return false;
    }
    this.valid = true;
    this.id = id;
    this.enableEasySignin = function() {
        var switcher = $(this.id+"_switcher");
        switcher.onclick = this.switchEasySignin;
        return false;
    }
  
    this.disableEasySignin = function() {
        var switcher = $(this.id+"_switcher");
        switcher.onclick = null;
        return true;
    }
  
    this.switchEasySignin = function() {
        var id = this.id.split("_")[0];
        var box = $(id+"_box");
        if(box.style.display=="") {
            box.style.display="none";
        }else {
            var switcher = $(id+"_switcher");
            var end = switcher.offsetWidth;
            var left = calculateOffest(switcher, "offsetLeft");
            var top = calculateOffest(switcher, "offsetTop") + switcher.offsetHeight;
            box.style.left = left-30 + "px";
            box.style.top = top + "px";
            box.style.display=""
            $(id+"_username").focus();
        }
        return false;
    }
  
    this.initEasySinginBox = function() {
        var id = this.id;
        var box = document.createElement("div");
        box.style.display = "none";
        box.id = id+"_box";
        box.className = "signinBox";
        var top = document.createElement("div");
        top.className = "top";
        var closer = document.createElement("img");
        closer.id = id+"_closer";
        closer.src="/images/v2/closer.gif";
        closer.onclick = this.switchEasySignin;
        top.appendChild(closer);
        var content = document.createElement("div");
        content.className = id+"_content";
        var form = document.createElement("form");
        form.method = "post";
        form.action = "/user_mana2/login";
        var referInfo = document.createElement("input");
        referInfo.name = "referInfo";
        referInfo.value = self.location;
        referInfo.type = "hidden";
        form.appendChild(referInfo);
        var label = document.createElement("label");
        label.innerHTML = DIS_1;
        var input = document.createElement("input");
        input.type = "text";
        input.id= id+"_username";
        input.name = "username";
        input.className = "inputTxt";
        form.appendChild(label);
        form.appendChild(input);
        label = document.createElement("label");
        label.innerHTML = DIS_2;
        input = document.createElement("input");
        input.type = "password";
        input.id= id+"_password";
        input.name = "password";
        input.className = "inputTxt";
        form.appendChild(label);
        form.appendChild(input);
        input = document.createElement("input");
        input.type = "submit";
        input.value = DIS_3;
        input.id = id+"_submit";
        input.className = "diigoBtn";
        form.appendChild(input);
        content.appendChild(form);
        box.appendChild(top);
        box.appendChild(content);
        var bottom = document.createElement("div");
        bottom.className = "bottom";
        box.appendChild(bottom);
        document.body.appendChild(box);
    }
    return true;
}

function Validator(){
    this.isEmail =  /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    this.isEmail2 =  /^.+<\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*>$/;
    this.isTags = /^[^%&]+$/;
    this.isTag = /^[^%&\s]*$/; 
    this.isUsername = /^[a-zA-Z]([0-9a-zA-Z\-_]{5,15})$/;
    this.isUrl = /^https?:\/\/.+$/;
    this.IsEmail = function (email) {
        re = this.isEmail;
        return (re.test(email.trim()));
    };
    this.IsEmail2 = function (email) {
        re = this.isEmail2;
        return (re.test(email.trim()));
    };
    this.IsTags = function (tags) {
        re = this.isTags;
        return (re.test(tags));
    };
    this.IsTag = function (tag) {
        re = this.isTag;
        return (re.test(tag));
    };
    this.IsUsername = function (username) {
        re = this.isUsername;
        return (re.test(username.trim()));
    };
    this.IsPwd = function (pwd) {
        if(pwd.length>=6 && pwd.length<=32) {
            return true;
        }else {
            return false;
        }
    };
    this.IsRealname = function(realname) {
        if(realname.length>=1 && realname.length<=64) {
            return true;
        }else {
            return false;
        }
    }
    this.IsTitle = function(title) {
        if(title.length<=255) {
            return true;
        }else {
            return false;
        }
    }
    this.IsSignature = function(signature) {
        if(signature.length<=255){
            return true
        }else {
            return false;
        }
    }
    this.IsUrl = function(url) {
        re = this.isUrl;
        return (re.test(url))
    }
};

function appendTip(tipperID, content, position) {
    var tipper = $(tipperID);
    tipper.content = content;
    tipper.tipPosition = position;
    tipper.onmouseover = showFloatTip;
    tipper.onmouseout = hideFloatTip;
}

function showFloatTip() {
    var floatTipID = "floatTip";
    var floatTip = getFloatTip(floatTipID);
    floatTip.innerHTML = "<p>"+this.content+"</p>";
    setFloatTipOffsets(this, floatTip, this.tipPosition);
    floatTip.style.display = "block";
}
function hideFloatTip() {
    var floatTipID = "floatTip";
    var floatTip = getFloatTip(floatTipID);
    floatTip.style.display = "none";
}
function getFloatTip(floatTipID) {
    var floatTip = $(floatTipID);
    return floatTip ? floatTip : createFloatTip(floatTipID);
}
function createFloatTip(floatTipID) {
    var box = document.createElement("div");
    box.id = floatTipID;
    box.className = box.id;
    box.style.display = "none";
    document.body.appendChild(box);
    return box;
}
function setFloatTipOffsets(tipper, floatTip, position) {
    var width = tipper.offsetWidth;
    var height = tipper.offsetHeight;
    var margin = 2;
    var left;
    var top;
    switch(position) {
        case "top": {
                left = calculateOffest(tipper, "offsetLeft");
                bottom = calculateOffest(tipper, "offsetTop")+margin;
                floatTip.style.left = left + "px";
                floatTip.style.bottom = bottom + "px";
            }break;
        case "right": {
                left = calculateOffest(tipper, "offsetLeft")+width+margin;
                top = calculateOffest(tipper, "offsetTop");
                floatTip.style.left = left + "px";
                floatTip.style.top = top + "px";
            }break;
        case "bottom": {
                left = calculateOffest(tipper, "offsetLeft");
                top = calculateOffest(tipper, "offsetTop")+height+margin;
                floatTip.style.left = left + "px";
                floatTip.style.top = top + "px";
            }break;
        case "left": {
                right = calculateOffest(tipper, "offsetLeft")+margin;
                top = calculateOffest(tipper, "offsetTop")+height;
                floatTip.style.right = right + "px";
                floatTip.style.top = top + "px";
            }break;
    }
}

// size: small, medium, big
function loading(loaderID, size) {
    if(typeof(size)=="undefined") size = "small";
    var loader = $(loaderID);
    loader.innerHTML = "<img src=\"/images/v2/loading_"+size+".gif\" alt=\"loading...\" />";
    loader.style.display = "";
}
function loadComplete(loaderID) {
    var loader = $(loaderID);
    loader.innerHTML = "";
    loader.style.display = "none";
}

function authFailed(){
    self.location = "/sign-out";
}

//function getElementsByClassName(oElm, strTagName, strClassName){
//    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
//    var arrReturnElements = new Array();
//    strClassName = strClassName.replace(/\-/g, "\\-");
//    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
//    var oElement;
//    for(var i=0; i<arrElements.length; i++){
//        oElement = arrElements[i];      
//        if(oRegExp.test(oElement.className)){
//            arrReturnElements.push(oElement);
//        }   
//    }
//    return (arrReturnElements)
//}
function doSearch(searchType, ad) {
    if(typeof(searchType)=="undefined") searchType="T";
    var reAll = new RegExp(/^all$/i);
    var reMy = new RegExp(/^my$/i);
    var scope = $F("dSearchScope").trim();
    var keyword = $F("dSearchKeyword").trim();
    var url;
    if(searchType=="T") {
        if(scope=="" || scope.match(reAll)) {
            if(keyword==_GLOBAL_VAR['keywordTip']) return false;
            url = "/tag/"+keyword;
        }else if(scope.match(reMy)){
            if(keyword==_GLOBAL_VAR['keywordTip'])
                url = "/user/"+_GLOBAL_VAR['my_name'];
            else
                url = "/user/"+_GLOBAL_VAR['my_name']+"/"+keyword;
        }else {
            if(keyword==_GLOBAL_VAR['keywordTip'])
                url = "/user/"+scope;
            else
                url = "/user/"+scope+"/"+keyword;
        }
    }else if(searchType=="F") {
        if(keyword==_GLOBAL_VAR['keywordTip'])
            url = "/search/ad="+ad+"&who="+scope+"&what=";
        else
            url = "/search/ad="+ad+"&who="+scope+"&what="+keyword;
    }else {
        return false;
    }
    self.location = url;
    return false;
}
function doFSearch(type) {
    if(typeof(type)=="undefined") type="all";
    var ad = 0;
    if(type=="my") {
        $("dSearchScope").value = "My";
    }else if(type=="all") {
        $("dSearchScope").value = "All";
    }else if(type=="ad") {
        ad = 1;
    }
    doSearch("F", ad);
}

function fillScope(scope) {
    $("dSearchScope").value = scope;
    switchScopeList();
  
}
function switchScopeList() {
    var scopeList = $("scopeList");
    if(scopeList.style.display=="none") {
        scopeList.style.display = ""
        setScopeListOffsets(scopeList);
    }else {
        scopeList.style.display = "none";
    }
    return false;
}

function setScopeListOffsets(scopeList) {
    var who = $("dSearchScope");
    var end = who.offsetWidth;
    var left = calculateOffest(who, "offsetLeft");
    var top = calculateOffest(who, "offsetTop") + who.offsetHeight;
    scopeList.style.left = left + "px";
    scopeList.style.top = top + "px";
}
function blurKeyword() {
    var keyword = $("dSearchKeyword");
    if(keyword.value.trim()=="") {
        keyword.value = _GLOBAL_VAR['keywordTip'];
    }
}
function focusKeyword() {
    var keyword = $("dSearchKeyword");
    if(keyword.value.trim()==_GLOBAL_VAR['keywordTip']) {
        keyword.value = ""
    }
}

function setCaretPos(ele, pos) {
    if(ele.createTextRange) {
        /* Create a TextRange, set the internal pointer to
a specified position and show the cursor at this
position
         */
        var range = ele.createTextRange();
        range.move("character", pos);
        range.select();
    } else if(ele.selectionStart >= 0) {
        /* Gecko is a little bit shorter on that. Simply
focus the element and set the selection to a
specified position
         */
        ele.focus();
        ele.setSelectionRange(pos, pos);
    }
}

function loadCusData() {
    var domain = getCookieDomain();
    var cusData = new Cookie(document, "cus_data", 240, '/', domain);
    cusData.load();
    return cusData;
}

function switchSearchMoreList() {
    var list = $("searchMore");
    if(list.style.display=="none") {
        list.style.display = ""
        setSearchMoreOffsets(list);
    }else {
        list.style.display = "none";
    }
    return false;
}

function setSearchMoreOffsets(list) {
    var switcher = $("searchMoreLink");
    var end = switcher.offsetWidth;
    var left = calculateOffest(switcher, "offsetLeft");
    var top = calculateOffest(switcher, "offsetTop") + switcher.offsetHeight;
    list.style.left = left-75 + "px";
    list.style.top = top+3 + "px";
}

function flagAsSpammer(flagID,user_name) {
    if(!confirm("Flag "+user_name+" As Spammer?")){
        return;
    }
    if(flagID == 0){
        $("report_spam").hide();
        $("alert").update("Spam reported. To reduce spam, you can change your <a href='/setting'>settings</a> so only your friends can send you  messages").show();
        return;
    }
    var url = BOOKMARK_HOST + "/spam_mana/mark_spammer?spammer_id="+flagID;
    CrossSubDomainAjax.request(url, 
    {asynchronous:true, 
        evalScripts:false, 
        onComplete:function(request){
            if(request.status=="200") {
                $("report_spam").hide();
                $("alert").update("Spam reported. To reduce spam, you can change your <a href='/setting'>settings</a> so only your friends can send you  messages").show();
            }else {
                //alert(request.status);
            }
        }
    }); 
    return false;
}

/* common load user's group */
function cLoadUserGroups() {
    var url = "/group_mana/load_groups2?u_name="+_GLOBAL_VAR['username'];
    new Ajax.Request(url, 
    {asynchronous:true, 
        evalScripts:false,  
        onComplete:function(request){
            if(request.status=="200") {
                var groups = request.responseText.evalJSON();
                var groupsUL = $("groupsUL");
                if(!groupsUL) return false;
                if(groups.length>0) {
                    for(var i=0; i<groups.length; i++) {
                        var li = document.createElement("li");
                        li.innerHTML = "<a href=\""+GROUP_HOST+"/groups/"+groups[i]['g_name']+"\">"+groups[i]['display_name']+"</a>";
                        li.id = "group_"+i;
                        groupsUL.appendChild(li);
                    }
                    $("groupCount").innerHTML = groups.length;
                    $("groupList").style.display = "";
                }else {
                    //renderNoGroups();
                }
            }else if(request.status=="400") {
            }else {
            }}}); 
}

/* load recommend user */
function cLoadRecommendUsersByUser() {
    var username = _GLOBAL_VAR['username'];
    var url="/recommend/user_by_user?username="+username;
    new Ajax.Request(url, 
    {asynchronous:true, 
        evalScripts:false, 
        onComplete:function(request){
            if(request.status=="200") {
                $("recommendUserHolder").innerHTML = request.responseText;
                if($F("rUserCount")>0) $("rUserList").style.display = "";
            }}}); 
}
/* load recommend user */

/*-------------------------------------------------
 *  markUserStatus
 *------------------------------------------------*/
function markUserStatus() {
    var usernameEls = $("box").select('.dUserName');
    var usernames = [];
    usernameEls.each(function(u) {
        usernames.push(u.getAttribute("username")||"")
    });    
    var url="/talk/check_user_status";
    var params = "json_infos="+usernames.toJSON();
    new Ajax.Request(url, 
    {asynchronous:true, 
        evalScripts:false,
        method:'get', 
        onComplete:function(request){checkUserStatusCompleted(request, usernameEls)},
        parameters:params
    }); 
}

function checkUserStatusCompleted(request, usernameEls) {
    if(request.status=="200") {
        var status = request.responseText.evalJSON();
        usernameEls.each(function(u) {
            var username = u.getAttribute("username") || "";
            var s = status[username];
            doMarkUserStatus(u, username, s);
        });
    }
}
function doMarkUserStatus(el, username, status) {
    try{
    //var title = el.up().getAttribute("title");
    if(status==1) {
        el.style.background = "url(/images/online_status.gif) no-repeat scroll left -27px";
        //el.up().setAttribute("title",title+" online");
    }else {
        el.style.background = "url(/images/online_status.gif) no-repeat scroll left top";
        //el.up().setAttribute("title",title+" offline");
    }
    el.style.paddingLeft = "11px";
    el.style.width = "37px";
    }catch(e) {}
}

//function doMarkUserStatus(el, username, status) {
//    try{
//        if(status==1) {
//            el.style.background = "url(/images/online_status.gif) no-repeat scroll left -27px";
//        }else {
//            el.style.background = "url(/images/online_status.gif) no-repeat scroll left top";
//        }
//        el.style.paddingLeft = "11px";
//        el.style.width = "37px";
//    }catch(e) {}
//}

/*-------------------------------------------------
 * doTopSearch
 *------------------------------------------------*/
function doTopSearch() {
    var form = $("topSearchForm");
    var scope = form.scope.value;
    var what = form.what.value;
    switch(scope) {
        case "diigo": {
                self.location = BOOKMARK_HOST+"/search/fulltext?what="+encodeURIComponent(what);
            }break;
        case "groups": {
                self.location = GROUP_HOST+"/group_mana/search_groups?keywords="+encodeURIComponent(what);
            }break;
        case "people": {
                self.location = BOOKMARK_HOST+"/people/search?query="+encodeURIComponent(what);
            }break;
        case "messages": {
            }break;
        case "web":{
                self.location = "http://www.google.com/search?hl=en&q="+encodeURIComponent(what);
            }break;
    }
} 
 
/*-------------------------------------------------
 * Context Menu
 * Copyright (c) 2007 Allen Dog & Diigo Inc.
 *  leinte 2007-11-5
 * options:
 *     eventType:
 *                click -- onclick event
 *                mouseover  --  mouseover event
 *     background-color
 *     color:      font color
 *     togglerClass:  class name of toggler
 *------------------------------------------------*/
var ContextMenu = Class.create({
    initialize: function(scope, options) {
        var eventType = options.eventType || "click";
        // IE6 select overlap bug
        if(!ContextMenu.hideIframe && !$("contextMenuHideIframe")) {
            ContextMenu.hideIframe = new Element('iframe', {
                id: "contextMenuHideIframe"
            });
            document.body.appendChild(ContextMenu.hideIframe);
            ContextMenu.hideIframe.hide();
        }

        $(scope).select(".contextMenu").each(function(li){
            var toggler = li.down();
            var submenu = toggler.next();
            if(options.submenuId){
                submenu = $(options.submenuId)
            }
            if(eventType == "click"){
                toggler.onclick = function(){
                    toggler.blur();
                    ContextMenu.clearTimeHandler();
                    if(!submenu.visible()){
                        ContextMenu.showContextMenu(li,options);
                        Event.observe(document,"mousedown",ContextMenu.onclick);
                    }else{
                        ContextMenu.onclick();
                    }
                    return false;
                }
            }else if(eventType == "mouseover"){
                li.onmouseover = function(event){
                    ContextMenu.clearTimeHandler()
                    ContextMenu.showTimeOut = setTimeout(function(){
                        ContextMenu.showContextMenu(li,options)
                    },50)
                }
                li.select(".subMenu")[0].select("a").each(function(aEl){
                    aEl.onmouseover = function(){
                        ContextMenu.clearTimeHandler();
                    }
                    aEl.onmouseout = function(){
                        ContextMenu.clearTimeHandler();
                        ContextMenu.hideTimeOut = setTimeout(ContextMenu.hideContextMenu,500);
                    }
                });
            }
        })
    }
});

ContextMenu.showTimeOut = null;
ContextMenu.hideTimeOut = null;
ContextMenu.selected = null;
ContextMenu.selected_submenu = null;
ContextMenu.options = null;
ContextMenu.onclick = function(event){
    ContextMenu.clearTimeHandler();
    ContextMenu.hideTimeOut = setTimeout(ContextMenu.hideContextMenu,200)
    Event.stopObserving(document,"mousedown",ContextMenu.onclick);
}
ContextMenu.clearTimeHandler = function(){
    if(ContextMenu.showTimeOut){
        clearTimeout(ContextMenu.showTimeOut);
    }
    if(ContextMenu.hideTimeOut){
        clearTimeout(ContextMenu.hideTimeOut)
    }
}
ContextMenu.showContextMenu = function(li,options){
    if(ContextMenu.selected && ContextMenu.selected != li){
        ContextMenu.hideContextMenu();
    }
    ContextMenu.options = options;
    ContextMenu.selected = li;
    var toggler = ContextMenu.selected;
    var submenu = toggler.down().next();
    if(options.submenuId){
        submenu = $(options.submenuId)
    }
    if(submenu && !submenu.visible()){
        if(options.togglerClass){
            toggler.addClassName(options.togglerClass)
        }
        ContextMenu.selected_submenu = submenu;
        var p = Position.cumulativeOffset(toggler);
        var left = p[0]
        var top = p[1]+toggler.getHeight();
        var offsetX = options.offsetX || 0;
        var offsetY = options.offsetY || 0;
        if(submenu.getWidth()+p[0]+30>document.body.offsetWidth){
            left = p[0]-(submenu.getWidth()-toggler.getWidth());
        }else {
            left = p[0] + offsetX;
            if(options.align == "right"){
                left = p[0] + toggler.getWidth() - submenu.getWidth();
            }
        }
        document.body.appendChild(submenu);
        if(options.className){
            submenu.addClassName(options.className);
        }
        submenu.setStyle({
            display: "block",
            left: left+"px",
            top:top+"px"
        });
        ContextMenu.hideIframe.setStyle({
            display: "block",
            postion:'absolute',
            border:0,
            frameborder:'no',
            left: left+"px",
            top: top+"px",
            width: submenu.getWidth()+"px",
            height: submenu.getHeight()+"px"
        });
    }
}
ContextMenu.hideContextMenu = function(){
    if(ContextMenu.selected){
        var toggler = ContextMenu.selected.down();
        var submenu = ContextMenu.selected_submenu//toggler.next();
        if(ContextMenu.options.submenuId){
            submenu = $(ContextMenu.options.submenuId)
        }
        if(submenu.visible()){
            ContextMenu.hideIframe.hide();
            submenu.hide();
            if(ContextMenu.options.togglerClass){
                toggler.removeClassName(ContextMenu.options.togglerClass)
            }
            ContextMenu.selected.appendChild(submenu)
        }
        ContextMenu.selected = null;
    }
}

/*-------------------------------------------------
 * Browser version
 * Copyright (c) 2007 leinte & Diigo System.
 *------------------------------------------------*/
var BrowserVersion={
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/),
    getIEVersion: function(){
    	var rv = null;
    	if (navigator.appName == 'Microsoft Internet Explorer'){
            var ua = navigator.userAgent;
            var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
            if (re.exec(ua) != null)
                rv = parseFloat( RegExp.$1 );
        }
        return rv	
    },
    isIE6:  function(){
    	var version = BrowserVersion.getIEVersion();
    	return version && BrowserVersion.getIEVersion() <= 6} 
}

/*--------------------------
 * get message count
 *-------------------------*/
function getMessageCount() {
    var url = "/normal_message/get_message_count";
    new Ajax.Request(url, 
    {asynchronous:true, 
        evalScripts:false,
        method:"get",
        onComplete:function(request){
            if(request.status=="200") {
                $("messageCount").innerHTML = "("+request.responseText+")";
            }
        }}); 
    return false;
}

function getTextSize(text, el){
    el.innerHTML = text.escapeHTML().replace(/ /g, '&nbsp;');
    return el.offsetWidth;
}

function accSelectDoChange(el){
    switch(el.value) {
        case "allFriends":{
                $(_GLOBAL_VAR["bACCID"]).hide();
                _GLOBAL_VAR[_GLOBAL_VAR["bACCID"]+"_instance"].hideTipInBox();
                return false;
            }break;
        case "someone":{
                if(_GLOBAL_VAR[_GLOBAL_VAR["bACCID"]+"_instance"]){
                    _GLOBAL_VAR[_GLOBAL_VAR["bACCID"]+"_instance"].recBox.reset();
                }else{
                    _GLOBAL_VAR[_GLOBAL_VAR["bACCID"]+"_instance"] = new ACContact({rec:$(_GLOBAL_VAR["bACCID"]), contacts:_contacts});
                }
                $(_GLOBAL_VAR["bACCID"]).show();
                _GLOBAL_VAR[_GLOBAL_VAR["bACCID"]+"_instance"].showTipInBox();
                return false;
            }break;
        case "myself":{
            $(_GLOBAL_VAR["bACCID"]).hide();
            _GLOBAL_VAR[_GLOBAL_VAR["bACCID"]+"_instance"].hideTipInBox();
            return false;
        }break;
        default:{$(_GLOBAL_VAR["bACCID"]).hide();return false;}break;
    }
}

//--------delete this visit record--------------------------------
function delete_visit(id){
    //if(!confirm(ALE_43)) return false ;
    showCentralNoticer("delete your visit record");
    new Ajax.Request("/normal_message/delete_visit_record",{method:'post',
        parameters:{vid:id},
        onSuccess:function(transport){
            hideCentralNoticer();
            $("record_"+id).remove();                                  
        },
        onFailure:function(){
            hideCentralNoticer();
        },
        onException:function(){
            hideCentralNoticer();
        }
    }
)
}

function flashNotice(content, noticerID, duration) {
    if(typeof(noticerID)=="undefined") noticerID = "noticeBar";
    if(typeof(duration)=="undefined") duration = 10000;
    var noticer = $(noticerID);
    if(noticer) {
        noticer.style.display = "";
        setTimeout("$('"+noticerID+"').hide()",duration);
        var c = noticer.getElementsByClassName('contentb')[0];
        c.innerHTML = content;
    }
}

/*
 * calculate body dimension
 * keep the left position between min and max
 * args:
 * left: element's left position
 * width: element's width
 */
function fixLeft(left, width){
    var maxP = Element.getDimensions(document.body);
    if((left+width) >= maxP.width){
        left = maxP.width-width;
    }else if(left<0){
        left = 0;
    }
    return left;
}
/*
 * calculate body dimension
 * keep the top position between min and max
 * args:
 * top: element's top position
 * height: element's height
 */
function fixTop(top, height){
    var maxP = Element.getDimensions(document.body);
    if((top+height) >= maxP.height){
        top = maxP.height-height;
    }else if(top<0){
        top = 0;
    }
    return top;
}

/*-------------------------------------------------
 * Pop Window
 * Copyright (c) 2007 Allen Dog & Diigo System.
 *------------------------------------------------*/
var PopWindow = Class.create({
    initialize: function(options) {
        if(PopWindow.instance){
            PopWindow.instance.hide();
        }
        if($("diigoPopWindow")){
            $("diigoPopWindow").remove();
        }
        PopWindow.instance = this;
        this.selectX = 0;
        this.selectY = 0;
        this.offsetX = options.left || 0;
        this.offsetY = options.top || 0;
        this.width = options.width || 400;
        titleWord = options.title || "";
        this.root = options.root || document;
        this.optEnabled = options.optEnabled || false;
        this.dragEnabled = false;
        if(typeof(this.root)=="string" && !this.root.blank()){
            this.root = $(this.root);
        }
        this.window  = new Element("div", {
            id:"diigoPopWindow"
        });
        var inner = new Element("div", {
            id:"diigoPopWindowInner"
        });
        this.title = new Element("h3", {
            id:"wTitle"
        });
        this.title.innerHTML = titleWord;
        this.closeLink = new Element("a", {
            id:"wCloseLink",
            href:"javascript:void(0);",
            title:"Close Window"
        });
        this.closeLink.innerHTML = "<img src='/images/close_icon.gif' alt='close' />";
        this.closeLink.onclick = PopWindow.instance.doCancel.bind(this);
        inner.appendChild(this.closeLink);
        inner.appendChild(this.title);
        this.content = new Element("div", {
            id:"wContent"
        });
        inner.appendChild(this.content);
        this.noticer = new Element("div", {
            id:"wNoticer"
        }).hide();
        inner.appendChild(this.noticer);
        if(this.optEnabled) {
            this.submitBtn = new Element("input", {
                type: "button",
                id:"wSubmit",
                value:"Submit"
            });
            this.submitBtn.onclick = PopWindow.instance.doSubmit.bind(this);
            this.cancelBtn = new Element("input", {
                type: "button",
                id:"wCancel",
                value:"Cancel"
            });
            this.cancelBtn.onclick = PopWindow.instance.doCancel.bind(this);
            this.opt = new Element("div", {
                id:"wOptions"
            });
            this.opt.appendChild(this.submitBtn);
            this.opt.appendChild(this.cancelBtn);
            inner.appendChild(this.opt);
        }
        this.window.appendChild(inner);
        var left = 0; var top = 0;
        if(this.root!=document) {
            var p = Position.cumulativeOffset(this.root);
            left = p[0];
            top = p[1];
        }

        this.window.setStyle({
            left: fixLeft(left+this.offsetX, this.width+15)+"px",
            top: fixTop(top+this.offsetY, this.window.getHeight()+15)+"px",
            zIndex: 10009,
            width: this.width+"px"
        });
        document.body.appendChild(this.window);
        // object embed overlap bug
        if(!PopWindow.shadow) {
            PopWindow.shadow = new Element("div", {
                id: "popWindowShadow"
            });
            PopWindow.hideIframe = new Element('iframe', {
                id: "popWindowHideIframe",
                width:"100%",
                height:"100%"
            });
            PopWindow.shadow.appendChild(PopWindow.hideIframe);
            PopWindow.hideIframe.setAttribute("frameBorder", "0");
            PopWindow.hideIframe.setAttribute("marginheight", "0");
            PopWindow.hideIframe.setAttribute("marginwidth", "0");
            PopWindow.hideIframe.setAttribute("scrolling", "no");
            document.body.appendChild(PopWindow.shadow);
        }
        PopWindow.shadow.setStyle({
            left: fixLeft(left+this.offsetX, this.width+15)+"px",
            top: fixTop(top+this.offsetY, this.window.getHeight()+15)+"px",
            zIndex: 10008,
            width: this.width+10+"px",
            height: this.window.getHeight()+"px"
        });
        PopWindow.shadow.show();
        if(!BrowserVersion.IE || BrowserVersion.getIEVersion()>=8){
            // movable
            document.onmousedown = this.selectmouse.bind(this);
            document.onmouseup=function(){
                this.dragEnabled=false;

            }.bind(this);
            $("wTitle").setStyle({
                "cursor":"move"
            });
        }
    },
    movemouse : function(e) {
        if(this.dragEnabled) {
            var l = !BrowserVersion.IE ? (this.offsetX + e.clientX - this.selectX) : (this.offsetX + event.clientX - this.selectX);
            var t = !BrowserVersion.IE ? (this.offsetY + e.clientY - this.selectY) : (this.offsetY + event.clientY - this.selectY);
            if(l<=0){
                l=0;
            }
            if(t<=0){
                t=0;
            }
            var maxP = Element.getDimensions(document.body);
            if((l+this.window.getWidth()) >= maxP.width){
                l = maxP.width-this.window.getWidth();
            }
            if((t+this.window.getHeight()) >= maxP.height){
                t = maxP.height-this.window.getHeight();
            }
            this.window.setStyle({
                left : l+'px',
                top : t+'px'
            });
            PopWindow.shadow.setStyle({
                left : l+'px',
                top : t+'px'
            });
            return false;
        }

    },
    selectmouse : function(e) {
        var fobj       = !BrowserVersion.IE ? e.target : event.srcElement;
        if(fobj.id=="wTitle") {
            this.dragEnabled = true;
            var p = Position.cumulativeOffset(this.window);
            this.offsetX = p[0];
            this.offsetY = p[1];
            this.selectX = !BrowserVersion.IE ? e.clientX : event.clientX;
            this.selectY = !BrowserVersion.IE ? e.clientY : event.clientY;
            document.onmousemove=this.movemouse.bind(this);
            return false;
        }
    },
    show : function(options) {
        if(typeof(options)!="undefined"){
            this.offsetX = options.left || this.offsetX;
            this.offsetY = options.top || this.offsetY;
            this.root = options.root || this.root;
            if(typeof(this.root)=="string" && !this.root.blank()){
                this.root = $(this.root);
            }
            var left = 0; var top = 0;
            if(this.root!=document) {
                var p = this.root.cumulativeOffset();left = p[0];top = p[1];
            }
        }
        this.window.setStyle({
            left: fixLeft(left+this.offsetX, this.width+15)+"px",
            top: fixTop(top+this.offsetY, this.window.getHeight()+15)+"px",
            zIndex: 999,
            width: this.width+"px"
        });
        this.window.show();
        PopWindow.shadow.setStyle({
            left: fixLeft(left+this.offsetX, this.width+15)+"px",
            top: fixTop(top+this.offsetY, this.window.getHeight()+15)+"px",
            zIndex: 998,
            width: this.width+10+"px",
            height: this.window.getHeight()+"px"
        });
        PopWindow.shadow.show();
        this.content.show();
        this.noticer.hide();
        this.title.show();
        this.closeLink.show();
        if(this.optEnabled) {
            this.opt.show();
        }
    },
    hide : function() {
        this.window.hide();
        PopWindow.shadow.hide();
    },
    updateContent : function(html) {
        this.content.innerHTML=html;this.reCalShadowRange();
    },
    appendNode : function(el) {
        if(el){
            this.content.appendChild(el);this.reCalShadowRange();
        }
    },
    doSubmit : function() {
        this.submit();
    },
    doCancel : function() {
        this.hide();
        try{
            this.cancel();
        }catch(e){}
    },
    reCalShadowRange : function() {
        PopWindow.shadow.setStyle({
            height:this.window.getHeight()+"px"
        });
    },
    onLoading : function(msg) {
        msg = msg || "processing...";
        this.noticer.innerHTML = msg;
        this.noticer.className = "wLoading";
        this.noticer.show();
        this.content.hide();
        this.opt.hide();
        this.reCalShadowRange();
    },
    onComplete : function(args) {
        if(args.status=="200"){
            this.noticer.className = "wSuccess";
            msg = args.msg || "done!";
            this.noticer.innerHTML = msg;
        }else {
            this.noticer.className = "wFailed";
            msg = args.msg || "failed!";
            this.noticer.innerHTML = msg;
        }
        this.noticer.show();
        this.opt.hide();
        this.content.hide();
        this.title.hide();
        setTimeout("PopWindow.instance.hide()", 1000);
    }
});
