function showLoading(){
    if(document.getElementById("userDlgScroll")!=undefined){
        document.getElementById("userDlgScroll").innerHTML="<div id=\"loading\" ><h4>Loading...</h4><img src=\"images/ajax-loader-1.gif\" /></div>";
    }
}
var dMode = false;
var dId = null;
var xOffset = 0;
function dragMode(flag,id){
    dMode = flag;
    dId=id;
    if(!flag){
        xOffset=0;
    }
}
function getNumber(str){
    var st = str.indexOf("px");
    var res=0;
    if(st!=-1){
        res= str.substring(0,st);
    }
    return res;
}
function tryMove(e,id){
    if((dMode)&&(dId==id)){
        var posx = 0;
        var posy = 0;
        if (!e) var e = window.event;
        if (e.pageX || e.pageY) 	{
            posx = e.pageX;
            posy = e.pageY;
        }
        else if (e.clientX || e.clientY) 	{
            posx = e.clientX + document.body.scrollLeft
            + document.documentElement.scrollLeft;
            posy = e.clientY + document.body.scrollTop
            + document.documentElement.scrollTop;
        }
        if(xOffset==0){
            xOffset = posx - getNumber(document.getElementById(id).style.left);
        }
        document.getElementById(id).style.top = (posy-13)+"px";
        //var w = document.getElementById(id).style.width;
        document.getElementById(id).style.left = (posx-xOffset)+"px";      
    }
}
function accept(fId){
    showUserDlg("FriendCenter?task=accept&fId="+fId,"483","400");   
}
function reject(fId){
    showUserDlg("FriendCenter?task=reject&fId="+fId,"483","400");   
}
function showFriendsRequest(){
    showUserDlg("userhome/friendRequests.jsp?s=1","483","400");   
}

var width = "200";
var height = "200";

function showUserDlg(paneContents,w,h){
    width = w;
    height = h;
    AjaxRequest("GET",paneContents+"&ssq="+Math.random(),showUserDlgResult,null);
}
function showUserDlgResult() 
{ 
    if (xmlHttp.readyState==4)
        { 
            var res = xmlHttp.responseText; 
            if(res.indexOf("<!--userDlg-->")!=-1){
                document.getElementById("userDlg").innerHTML= res;
                document.getElementById("userDlg").style.width=width+"px";
                document.getElementById("userDlg").style.height=height+"px";
                document.getElementById("userDlg").style.display="block";
                var w = document.getElementsByTagName('body')[0].clientWidth;
                document.getElementById("userDlg").style.left = ((w-width)/2)+"px";
                document.getElementById("userDlgContent").style.width=(width-20)+"px";
                document.getElementById("userDlgContent").style.height=(height-50)+"px";  
                document.getElementById("userDlgScroll").style.height=(height-220)+"px";  
            }
            
        }
    }
    
    function hideUserWindow(id){
        document.getElementById(id).style.display="none";
    }
    var mWidth = "200";
    var mHeight = "200";
    function showMsgBox(paneContents,w,h){
        mWidth = w;
        mHeight = h;
        AjaxRequest("GET",paneContents,showMsgBoxResult,null);
    }
    function showMsgBoxResult(){
        if (xmlHttp.readyState==4){
            var res = xmlHttp.responseText;
            if(res.indexOf("<div id=\"msgBoxCont\"")!=-1){
                document.getElementById("msgBox").innerHTML= res; 
                document.getElementById("msgBox").style.width=mWidth+"px";
                document.getElementById("msgBox").style.height=mHeight+"px";
                var w = document.getElementsByTagName('body')[0].clientWidth;
                document.getElementById("msgBox").style.left = ((w-width)/2)+"px";
                document.getElementById("msgBox").style.display="block";            
            }
        }
    }
