//alert(window.location + " pathname: " + window.location.pathname + " hostname: " + window.location.hostname + " href: " + window.location.href + " host " + window.location.host );


//alert(window.innerHeight + "   " + window.innerWidth + "   " + window.outerHeight + "   " + window.outerWidth);
var myWidth = 0, myHeight = 0;
window.onbeforeunload = confirmExit;
var meeboVisibility = 0;
var popUp = "";
dw_Tooltip.content_vars = {
            L1: 'Open Chat',
            L2: 'Close Chat'
}

function checkDimension(){
  if(window.name == "popcall"){
      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;
      }
      //alert(document.documentElement.clientHeight + " " + document.documentElement.offsetHeight + " " + document.body.clientHeight + " " + document.body.offsetHeight);
      
      switch (BrowserDetect.browser){
              case "Safari":
                 window.resizeTo("350",window.outerHeight);
              break;
              case "Explorer":
                  //alert(document.body.clientHeight);
                 //window.resizeTo("360",eval(screen.availHeight-document.documentElement.clientHeight-20));
                 window.resizeTo("360","520");
              break;
              case "Firefox":
                  //if (navigator.userAgent.indexOf("Firefox/3.0") != -1)
                    window.resizeTo("358",window.outerHeight);
              break;
              default:
                  window.resizeTo("350","505");
              break;
     }
        
  }
}
  //doResizeTo(-210,0);


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){
        //alert(popWidth + " "+popHeight);
        popUp = popName;
        //popName = popName + Math.round(10*Math.random());
        //alert(popLink + " "+popName);
        //if (BrowserDetect.browser == "Explorer") popHeight = "440";
        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();
        //alert(newWin.location);
}

/*
 * 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){
    //if (meeboVis == 0)
        window.location = link;
}
    
function doResizeTo(x,y) {
    //var x = parseInt(form.resizeToX.value)
    //var y = parseInt(form.resizeToY.value)
    //window.resizeTo(x, y);
    window.resizeBy(x, y);
}


function showMeebo(){
    //alert("popUp vale "+this.name);
    if( this.name == "popcall"){
        toggleHMeebo();
    }
    else{
        popOpen(meebolink, "Meebo","350","420");
        //window.open(meebolink, "meebo", "width=350 , height=420, toolbar=no, location=no ,status=no, menubar=no, scrollbars=no, resizable=no");
        //newWin.focus();         
    }
}

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";
        /*
        $("meeboTooltip").className = "meeboTooltipOpen";
        $("meeboTooltip").innerHTML = "Open Chat";
        */
        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;
        }

        //doResizeTo(210,0);
        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";
                
        /*
        $("meeboTooltip").className = "meeboTooltipClose";
        $("meeboTooltip").innerHTML = "Close Chat";*/
        $("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';
    //$('lower').style.left='14em';
    //$("header").style.display="none";
    $("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(360,550)","1000");
        meeboVisibility = 0;
    }else{
        doResizeTo(360,810);
        setTimeout("Effect.SlideDown('meeBo')","500");
        meeboVisibility = 1;
    }

}

/*
function showMeebo(){
    doResizeTo(360,810);
    setTimeout("Effect.SlideDown('meeBo')","500");
}
*/

function hideMeebo(){

}

function move(){
    try{new Effect.Move('meebo', { x: 150, y: 0});}
    catch(e){
        alert(e.message());
    }
    alert('moove');
}


function setChangeableLanguage(enable){
    //alert(enable);
    if(enable == 1){
        //if (callbutton.value == callTranslation || meeboVisibility == 1)
        $('noFlags').id = "flags";
    }
    else{
        //if (callbutton.value == closeTranslation && meeboVisibility == 0)
          $('flags').id = "noFlags";
    }
}

function confirmExit()
{
    var callbutton = document.getElementById("callbutton");
    //console.log("inside confirm");
    try{
        if(callbutton.value == closeTranslation ){
          //if(confirm("Are you sure to leave without saving data?"))
            //self.close();
          //console.log("inside confirm");
          return "Stai chiudendo la finestra. La chiamata non verrà interrotta. Vuoi comunque chiudere la finestra?";
      }
    }catch(e){
        //alert(e.message);
    }
    
}

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;
      
  //return (ctrlMod && (key in disabled))? false : true;
} 



function getVersion(){
      
      //YAHOO.example.container.panel1.setHeader("Sitòfono 3");
      //YAHOO.example.container.panel1.setBody("Version: "+version);
      //YAHOO.example.container.panel1.setFooter("<i>Powered by Abbeynet</i>");
      //YAHOO.example.container.panel1.render("container");
      //YAHOO.example.container.panel1.show();
      alert("Version: "+version);
}
