var myWidth = 0, myHeight = 0;
window.onbeforeunload = confirmExit;
window.onunload = function onUnload(){
    closeCall();
};
var meeboVisibility = 0;
var popUp = "";
dw_Tooltip.content_vars = {
            L1: 'Open Chat',
            L2: 'Close Chat'
};

function getGuiVisitorCookie(){
    var vi = ReadCookie("SitofonoVisitor");
    if(vi != null && vi != "")
        return (vi.length > 127 ? vi.substring(0, 127) : vi);
    return null;
}

var vcookie = getGuiVisitorCookie();
if(vcookie != null){
    SetCookie("SitofonoVisitor", vcookie, 360);
}
    
function checkWinDimension(popWidth, popHeight){
    if(window.name == "popcall" || window.name == "minipop"){
        if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
        //var ste = document.documentElement.offsetHeight;
        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
        }

        if(myWidth < popWidth)
            myWidth = popWidth;
        if(myHeight < popHeight)
            myHeight = popHeight;
        resizeTo(myWidth, myHeight);
    }
}

function checkDimension(){
  var popWidth = 380;
  var popHeight = 480;
  if(window.name == "popcall" || window.name == "minipop"){
    resizeTo(popWidth, popHeight);
  }
}

function privacyOpen(popLink,popName,popWidth,popHeight){
        var privacyWin = window.open(popLink, popName,'width='+popWidth+',height='+popHeight+', toolbar=0,location=0, status=0, menubar=0,scrollbars=1,resizable=1');
}
    
function popOpen(popLink,popName,popWidth,popHeight){
        popUp = popName;
        var newWin = window.open(popLink, popName,'width='+popWidth+'px,height='+popHeight+'px, toolbar=no, location=no ,status=yes, menubar=no, scrollbars=no, directories=no, resizable=no');
        newWin.focus();
}

/*
 * Not Used
 **/
function winOpen(popLink){
        var newWin = window.open(popLink,'_blank','width='+screen.width+',height='+screen.height+', toolbar=1, location=0, status=1, menubar=1, scrollbars=auto, directories=1, resizable=1');
}
// 

function changeLanguage(link){
    var thirdPartyCallButton = document.getElementById("callbutton");
    if(thirdPartyCallButton == undefined || thirdPartyCallButton != undefined && thirdPartyCallButton.value != closeTranslation && meeboVisibility == 0)
             parent.self.location.href = link;
}
 


function ChangeLang(meeboVis, link){
    window.location = link;
}
    
function doResizeTo(x,y) {
    window.resizeBy(x, y);
}


function showMeebo(){
    if( this.name == "popcall"){
        toggleHMeebo();
    }
    else{
        popOpen(meebolink, "Meebo","350","420");
    }
}

function toggleHMeebo(){
    
    if(meeboVisibility == 1){
        try{
            if ($("callbutton").className == "call" ){
                
              setChangeableLanguage(1);
        }
        }catch(e){
            //alert(e.message()
        }
        
        try{
            if ( g_callID == "")
              setChangeableLanguage(1);
        }catch(e){
            //alert(e.message()
        }
        $("lower").style.position="static";
        $("lower").style.dispaly="none";
        $("header").position="static";
        $("header").style.visibility = "hidden";
        $("bookmark").style.position="static";
        $("footerright").style.position="static";
        $("foot").style.width="330px";
        $("header").style.width="330px";

        Effect.SlideLeft('meeBo');
        setTimeout("deanimation()", "1000");
        $("buttonClose").id = "buttonOpen";
        $("buttonOpen").className = "showTip L1";
        meeboVisibility = 0;
    }else{
        try{
          setChangeableLanguage(0);
        }catch(e){
            //alert(e.message()
        }
        switch (BrowserDetect.browser){
            case "Safari":
               doResizeTo(230,0);
            break;
            
         
            default:
                doResizeTo(210,0);
            break;
        }

        setTimeout("animation();","500");
        $("lower").style.display="none";
        $("foot").style.width="540px";
        $("bookmark").style.position="relative";
        $("bookmark").style.left="8em";
        $("footerright").style.position="relative";
        $("footerright").style.left="17em";
        $("header").style.display="block";
        $("header").style.visibility = "hidden";
        $("header").style.width="540px";
        $("meeBo").className = "meeboClose";
        $("buttonOpen").id = "buttonClose";
        $("buttonClose").className = "showTip L2";
                
        $("wrapper").style.marginLeft="10px";
        meeboVisibility = 1;
    }
}

function deanimation(){
    doResizeTo(-210,0);
    $('header').style.visibility = 'visible';
    Effect.Appear('lower', {duration: 3.0});
}      

function animation(){
    Effect.SlideRight('meeBo');
    $('lower').style.position='relative';
    $('lower').style.top='-20em';
    $("header").style.visibility="visible";

    Effect.Appear('lower', {duration: 2.0});
    Effect.Appear('header', {duration: 2.0});
}

function toggleVMeebo(){
    if(meeboVisibility == 1){
        Effect.SlideUp('meeBo');
        setTimeout("doResizeTo(380,480)","1000");
        meeboVisibility = 0;
    }else{
        doResizeTo(360,810);
        setTimeout("Effect.SlideDown('meeBo')","500");
        meeboVisibility = 1;
    }

}

function hideMeebo(){

}

function move(){
    try{new Effect.Move('meebo', {x: 150, y: 0});}
    catch(e){
        alert(e.message());
    }
    alert('moove');
}


function setChangeableLanguage(enable){
    if(enable == 1){
        $('noFlags').id = "flags";
    }
    else{
          $('flags').id = "noFlags";
    }
}

function confirmExit(){
    var callbutton = document.getElementById("callbutton");
    if(callbutton.value == closeTranslation || ((window.location.pathname).indexOf("/web") != -1 && g_callID != undefined && g_callID != "")){
        if (navigator.userAgent.toString().toLowerCase().indexOf("safari") != -1
            && navigator.userAgent.toString().toLowerCase().indexOf("chrome") == -1){
            return undefined;
        }
        return confirmExitString;
    }
    return undefined;
}

function showVersion(evt) {
  var disabled = {q:0};
  var ctrlMod = (window.event)? window.event.ctrlKey : evt.ctrlKey;
  var key = (window.event)? window.event.keyCode : evt.which;
  key = String.fromCharCode(key).toLowerCase();
  if (ctrlMod && (key in disabled)){
      getVersion();
      return false;
  }
  else
      return true;
}

function getVersion(){
      alert("Version: "+version);
}