function getClientWidth()  
{  
    return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;  
}  

function getClientHeight()  
{  
    return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;  
}  

function getBodyScrollTop()  
{  
    return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body &&document.body.scrollTop);  
}  

function getBodyScrollLeft()  
{  
    return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);  
}  

function getClientCenterX()  
{  
    return parseInt(getClientWidth()/2)+getBodyScrollLeft();  
}  

function getClientCenterY()  
{  
    return parseInt(getClientHeight()/2)+getBodyScrollTop();  
}


function leavingSiteMSG(href){
    var leavingSite = document.getElementById('leavingSite');
    leavingSite.style.display = 'block';
    leavingSite.innerHTML = '<p>You are now leaving the CostaExchange website</p><div>&nbsp;<a href="javascript:;" onclick="leavingSiteMSGHide(\''+href+'\')"><img src="/image/btn_ok.gif" alt="OK"></a>&nbsp;</div>';
    
    leavingSite.style.left = parseInt((getClientWidth() - $("#leavingSite").width())/2) + getBodyScrollLeft()+'px';
    leavingSite.style.top = parseInt((getClientHeight() - $("#leavingSite").height()) /2) + getBodyScrollTop()+'px';
}
function leavingSiteMSGHide(href){
    var leavingSite = document.getElementById('leavingSite');
    leavingSite.style.display = 'none';
    leavingSite.innerHTML = '';
    
    window.open(href);
}

function leavingSiteInit(){
    var host = location.protocol+'//'+location.host+'/';
    
    img = new Image(); //new img obj
    img.src = '/image/btn_ok.gif';
    
    $("a").each(function(i){ 
            if (this.target == '_blank'){
                if (this.href.indexOf(host) == -1  && this.href.indexOf("mailto:") == -1){
                    this.onclick = new Function('leavingSiteMSG("'+this.href+'")');
                    this.target = '';
                    this.href = 'javascript:;'
                }
            }
    });
}