function moveDiv2center(oDiv){
    var oContentDiv = document.getElementById('content_div');
	if (!oContentDiv)
	{
		oContentDiv = document.getElementById('content_div1');
	}
    var aScreenDimensions = getPageSize();
    if(window.pageYOffset){
        var iScrollTop = window.pageYOffset;
    }else{
        var iScrollTop = document.documentElement.scrollTop;
    }
    if(window.pageXOffset){
        var iScrollLeft = window.pageXOffset;
    }else{
        var iScrollLeft = document.documentElement.scrollLeft;
    }
    oDiv.style.top     = Math.round(iScrollTop + aScreenDimensions[3]/2 - (oContentDiv.style.height.replace('px','')/2)) + "px";
    oDiv.style.left = Math.round(iScrollLeft + aScreenDimensions[2]/2 - (oContentDiv.style.width.replace('px','')/2)) + "px";

}


function getPageSize(){
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        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
        if(document.documentElement.clientWidth){
            windowWidth = document.documentElement.clientWidth;
        } else {
            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;
    }
    // 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 = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
    return arrayPageSize;
}

function ShadowCLS(){
    this.fOpacity             = 0.6;
    this.fCurrentOpacity     = 0;
    this.Style                 = null;
    this.bProcessMode        = 0;
    this.iClickCounter        = 0;
    this.move_shadow = function(){
        if(document.getElementById("shadow_div") && document.getElementById("shadow_div").style.display == "block"){
            var oShadowStyle = document.getElementById("shadow_div").style;
            if(window.pageXOffset){
                var iScrollLeft = window.pageXOffset;
            }else{
                var iScrollLeft = document.documentElement.scrollLeftp;
            }
            oShadowStyle.left     = iScrollLeft + 'px';
        }
    }
    this.getPageSize = function(){
        var xScroll, yScroll;
        if (window.innerHeight && window.scrollMaxY) {
            xScroll = window.innerWidth + window.scrollMaxX;
            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
            if(document.documentElement.clientWidth){
                windowWidth = document.documentElement.clientWidth;
            } else {
                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;
        }
        // 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 = xScroll;
        } else {
            pageWidth = windowWidth;
        }
        arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
        return arrayPageSize;
    }
    this.openShadowLayer = function (){
        if(this.Style == null){
            if(document.getElementById("shadow_div")){
                this.Style     = document.getElementById("shadow_div").style;
                if(document.getElementById("shadow_div").filters){
                    this.fOpDisplayStap = this.fOpacity;
                    this.fOpHideStap    = this.fOpacity;
                }else{
                    this.fOpDisplayStap = this.fOpacity/10;
                    this.fOpHideStap    = this.fOpacity/5;
                }
            }
        }
        if(this.Style){
            this.bProcessMode         = 1;
            var aScreenDimensions     = this.getPageSize();
            if(window.pageXOffset){
                var iScrollLeft = window.pageXOffset;
            }else{
                var iScrollLeft = document.documentElement.scrollLeft;
            }
            this.Style.left     = iScrollLeft + 'px';
            this.Style.backgroundColor     = "#000000";
             if(document.getElementById("shadow_div").filters){
                 document.getElementById("shadow_div").filters.alpha.opacity = 0;
             }else{
                 this.Style.opacity        = 0;
            }
            this.Style.display = "block";
            if(aScreenDimensions[1] > 1000){
                this.Style.height     = aScreenDimensions[1] + 'px';
            }else{
                this.Style.height     = '1000px';
            }
            changeShadowOpacity();
        }
    }
    this.closeShadowLayer = function(){
        if(this.Style){
            this.bProcessMode = 0;
            changeShadowOpacity();
        }
    }
    this.click = function(){
        if(this.iClickCounter >= 5 || main_div == null){
            this.iClickCounter = 0;
            this.closeShadowLayer();
        }else{
            this.iClickCounter++;
        }
    }
}

function changeShadowOpacity(){
    if(oShadow.bProcessMode){
        if(oShadow.fOpacity > oShadow.fCurrentOpacity){
            oShadow.fCurrentOpacity     += oShadow.fOpDisplayStap;
            setTimeout("changeShadowOpacity(1);",10);
        }else{
            oShadow.fCurrentOpacity        = oShadow.fOpacity;
        }
    }else{
        if(oShadow.fCurrentOpacity > 0){
            oShadow.fCurrentOpacity     -= oShadow.fOpHideStap;
            setTimeout("changeShadowOpacity(0);",10);
        }else{
            oShadow.fCurrentOpacity    = 0;
            oShadow.Style.display     = 'none';
        }
    }
     if(document.getElementById("shadow_div").filters){
         document.getElementById("shadow_div").filters.alpha.opacity = oShadow.fCurrentOpacity*100;
     }else{
        oShadow.Style.opacity         = oShadow.fCurrentOpacity;
    }
    //oShadowStyle.MozOpacity         = fCurrentOpacity;
    //oShadowStyle.KhtmlOpacity     = fCurrentOpacity;
}



function showSignUp(){
    oShadow.openShadowLayer();
    var oDiv = document.getElementById("back_div");
    moveDiv2center(oDiv);
    oDiv.style.display="block";
    document.getElementById("content_div").style.display="block";
}

function closeDiv(){
    var oDiv = document.getElementById("back_div");
	if (!oDiv)
	{
		oDiv = document.getElementById("back_div1");
	}
    var oContent = document.getElementById("content_div");
	if (!oContent)
	{
		oContent = document.getElementById("content_div1");
	}
    
    oDiv.style.top=0;
    oDiv.style.left=0;
    oDiv.style.display="none";
    oContent.style.display="none";
    oShadow.closeShadowLayer();
}

function addfriend(login,name)
{
    
    var z = [], xx = new xAjax;
    z['login'] = login;
    xx.AJAXPostData('/dynamic/user/user/add_friend.ajax', z);
    xx.fShow = function ()
    {
        alert("Your request was sent to "+name);
        document.location.href = document.location.href;
    }
}

var oShadow = new ShadowCLS;

function showPresents(){
    oShadow.openShadowLayer('content_div1');
    var oDiv = document.getElementById("back_div1");
    moveDiv2center(oDiv);
    oDiv.style.display="block";
    document.getElementById("content_div1").style.display="block";
}

function showAddStars(){
    oShadow.openShadowLayer('content_div1');
    var oDiv = document.getElementById("star_div");
    moveDiv2centerNew(oDiv,"star_div");
    oDiv.style.display="block";
    document.getElementById("content_div1").style.display="block";    
    
}

function moveDiv(name,evt){
    var oDiv = document.getElementById(name);
    if(window.pageYOffset){
        var iScrollTop = window.pageYOffset;
    }else{
        var iScrollTop = document.documentElement.scrollTop;
    }
    if(window.pageXOffset){
        var iScrollLeft = window.pageXOffset;
    }else{
        var iScrollLeft = document.documentElement.scrollLeft;
    }
    var x=0, y=0;
    if (document.all) {//IE
        x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
        y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
        x += window.event.clientX;
        y += window.event.clientY;

    } else {//Good Browsers
        x = evt.pageX;
        y = evt.pageY;
    }
    
    
    iScrollLeft = 240;
    iScrollTop = 270;
    oDiv.style.left = (x - iScrollLeft) + "px";
    oDiv.style.top = (y - iScrollTop) + "px";

} 

function showInfoDiv(evt,name,age,location,avatar,rating){
    var info_div = document.getElementById("user_info_div");
    if (info_div.style.display == "block") 
    {
        return false;   
    }
    moveDiv("user_info_div",evt);
    $("#user_name").html(name); 
    $("#user_age").html(age);
    $("#user_location").html(location);
    $("#user_rating").html(rating);
    $("#user_avatar").html("<img src='"+avatar+"' />");
    info_div.style.display = "block";    
}

function hideUserInfoDiv(){
    //alert('a');
    var info_div = document.getElementById("user_info_div");
    info_div.style.display = "none";
    info_div.style.top = 0;
    info_div.style.left = 0;
}

function showInfoDiv2(evt,name,avatar,message){
    var info_div = document.getElementById("user_info_div2");

//    moveDiv("user_info_div2",evt);

	info_div.style.display = "block";
	setPosition(info_div, getBounds(evt));
    $("#user_name2").html(name); 
	if (message != '')
	{
		$("#um2").css('display', '');
		$("#user_message").html(message);
	}
	else
	{
		$("#um2").css('display', 'none');
	}
	
    
    $("#user_avatar2").html("<img src='"+avatar+"' />");
    
}

function hideUserInfoDiv2(){
    var info_div = document.getElementById("user_info_div2");
    info_div.style.display = "none";
}

function showHelpDiv(evt){
    oShadow.openShadowLayer();
    var oDiv = document.getElementById("help_info_div");
    moveDiv2center(oDiv);
    oDiv.style.display="block";
    document.getElementById("help_info_div").style.display="block";
    
   // moveDiv("help_info_div",evt);
   // $("#help_info_div").show();
}

function showAddCredits(){
    oShadow.openShadowLayer();
    var oDiv = document.getElementById("payment_div");
    moveDiv2centerNew(oDiv,"content_d");
    oDiv.style.display="block";
    document.getElementById("payment_div").style.display="block";        
}


function closePayment(){
   
}

function moveDiv2centerNew(oDiv,content_d){
    var oContentDiv = document.getElementById(content_d);
    var aScreenDimensions = getPageSize();
    if(window.pageYOffset){
        var iScrollTop = window.pageYOffset;
    }else{
        var iScrollTop = document.documentElement.scrollTop;
    }
    if(window.pageXOffset){
        var iScrollLeft = window.pageXOffset;
    }else{
        var iScrollLeft = document.documentElement.scrollLeft;
    }
    oDiv.style.top     = Math.round(iScrollTop + aScreenDimensions[3]/2 - (oContentDiv.style.height.replace('px','')/2)) + "px";
    oDiv.style.left = Math.round(iScrollLeft + aScreenDimensions[2]/2 - (oContentDiv.style.width.replace('px','')/2)) + "px";

}

/// Universal functions

function showLayer(odiv){
    oShadow.openShadowLayer();
    var oDiv = document.getElementById(odiv);
    centerDiv(oDiv);
    oDiv.style.display="block";
}

function closeLayer(odiv){
    oShadow.closeShadowLayer();
    var oDiv = document.getElementById(odiv);
    oDiv.style.top = 0;
    oDiv.style.left = 0;
    oDiv.style.display = 'none';
}

function centerDiv(oDiv){
    var aScreenDimensions = getPageSize();
    if(window.pageYOffset){
        var iScrollTop = window.pageYOffset;
    }else{
        var iScrollTop = document.documentElement.scrollTop;
    }
    if(window.pageXOffset){
        var iScrollLeft = window.pageXOffset;
    }else{
        var iScrollLeft = document.documentElement.scrollLeft;
    }
    oDiv.style.top     = Math.round(iScrollTop + aScreenDimensions[3]/2 - (oDiv.style.height.replace('px','')/2)) + "px";
    oDiv.style.left = Math.round(iScrollLeft + aScreenDimensions[2]/2 - (oDiv.style.width.replace('px','')/2)) + "px";

}