function btnHover(btnobj,ishover)
{
  if(btnobj)
  {
    if (ishover)
    {      
     btnobj.setAttribute("class", "app_nav_menu_hover");
    }
    else
    {     
      btnobj.setAttribute("class", "app_nav_menu_normal");
    }
  }
}
var time_out=0;
var timerID;
function htmlwin_create(holderid,contentid,buttonid,w,h)
{
  var holder = document.getElementById(holderid);
  var btn = document.getElementById(buttonid);
  var wrap = document.getElementById('htmlwinwrap');
  if (!wrap)
  {
    //holder.style.display="block";
    var domwindow=document.createElement("div");
    var wrap_h = h+15;
    var wrap_w = w;
    var domwindowdata='<div id="htmlwinwrap" style="width:'+wrap_w+'px;height:'+wrap_h+'px;"><div class="htmlwinhandle" style="width:'+wrap_w+'px;"><a style="cursor:pointer;" onclick="onHtmlwinClose();"><img src="/js/dhtmlwindow/min.gif" border="0"/></a></div><div class="htmlwincontent" style="width:'+w+'px;height:'+h+'px;"><div class="content" id="notifyboxcontent">'+document.getElementById(contentid).innerHTML+'</div></div></div>';    
    domwindow.innerHTML=domwindowdata;
    holder.appendChild(domwindow);
    //btnHover(btn,true);
    wrap = document.getElementById('htmlwinwrap');
    wrap.style.display="none";
  }
}
function htmlwin_toggle(buttonid)
{
  var wrap = document.getElementById('htmlwinwrap');
  var btn = document.getElementById(buttonid);
  if(wrap.style.display=='none'){
      wrap.style.display='block';  
      btnHover(btn,true);    
    }
    else {
      wrap.style.display = 'none';     
      btnHover(btn,false); 
    }
}
function onHtmlwinClose(buttonid)
{
  //var wrap = document.getElementById('htmlwinwrap');
  //if (wrap) wrap.style.display='none';
  show_flash_notify(buttonid);
}
function show_flash_notify(btnid)
{
  if(time_out==0)
  {
    htmlwin_toggle(btnid);
  }
  if(time_out<1)  
  {
     timerID = setTimeout("show_flash_notify()",7000); //3s
  }
  else
  {
    clearTimeout(timerID);
    htmlwin_toggle(btnid);
    time_out=0;
    return;
  }
  time_out++;  
}
function htmlwin_open(holderid,contentid,buttonid,w,h)
{  
  var holder = document.getElementById(holderid);
  var btn = document.getElementById(buttonid);
  var wrap = document.getElementById('htmlwinwrap');
  if (!wrap)
  {
    //holder.style.display="block";
    var domwindow=document.createElement("div");
    var wrap_h = h+15;
    var wrap_w = w;
    var domwindowdata='<div id="htmlwinwrap" style="width:'+wrap_w+'px;height:'+wrap_h+'px;"><div class="htmlwinhandle" style="width:'+wrap_w+'px;"><a style="cursor:pointer;" onclick="onHtmlwinClose(\''+buttonid+'\');"><img src="/js/dhtmlwindow/min.gif" border="0"/></a></div><div class="htmlwincontent" style="width:'+w+'px;height:'+h+'px;"><div class="content" id="notifyboxcontent">'+document.getElementById(contentid).innerHTML+'</div></div></div>';    
    domwindow.innerHTML=domwindowdata;
    holder.appendChild(domwindow);
    btnHover(btn,true);
  }
  else
  {
    if(wrap.style.display=='none'){
      wrap.style.display='block';  
      btnHover(btn,true);    
    }
    else {
      wrap.style.display = 'none';     
      btnHover(btn,false); 
    }
  }
  
}
function remove_from_notify(id)
{
  var ct = document.getElementById('notifyboxcontent');
  var olddiv = document.getElementById(id);
  ct.removeChild(olddiv);  
 
  //window.opener.remove_cookie(id);

}
function printChatline(textwinid) {
  var timeNow = new Date();
  var hours   = timeNow.getHours();
  var minutes = timeNow.getMinutes();
  var textwin = document.getElementById(textwinid);
  textwin.innerHTML += '['+hours+':'+minutes+']';
}

function AppendChat(msg,userto,uid,langid,language,text,domain_cook,portrait)
{
  var ct = document.getElementById('notifyboxcontent');
  var cname = "chatwin" + uid;
  var checkid = document.getElementById(cname);
  var checkchatwin = document.getElementById('textwin'+uid);
  
  if (checkid)
  {    
    show_flash_notify('notify_app');
    return;
  }  
  if (checkchatwin)
  {     
    return;
  }  
  
  var domwindow=document.createElement("div");
 
  domwindow.setAttribute("id", cname);
  msg = eval('"'+msg+'"');
  domwindow.innerHTML='<div class="notify-leftcol"><img src="'+portrait+'" width="32" border="0"/></div><a href="javascript:void(0);" onclick="_openChatwin(\''+userto+'\',\''+uid+'\',\''+langid+'\',\''+language+'\',\''+text+'\',\''+domain_cook+'\',\''+portrait+'\');remove_from_notify(\''+cname+'\');">'+msg+'</a>';
  ct.appendChild(domwindow);
  show_flash_notify();
  
}
function toggle_t_mode(id)
{
  var img = document.getElementById(id); 
  if (!AVIMObj.getMethod())
  {
    //on auto
    AVIMObj.setMethod(0);
    img.src = "/images/vi_typing.png";
  }
  else 
  {
    //off
    AVIMObj.setMethod(-1);
    img.src = "/images/en_typing.png";
  }
  
}
function appCalc(title)
{
  var addr = '/apps/calc/';
  var calc=dhtmlwindow.open('calc', 'iframe', addr, title, "width=265px,height=345px,center=1,resize=0,scrolling=0");	
  calc.onclose=function()
  {  	
  	return 1;	
  }
}
function appCalendar(title)
{
  var addr = '/apps/calendar/';
  var calc=dhtmlwindow.open('calc', 'iframe', addr, title, "width=800px,height=500px,center=1,resize=1,scrolling=1");	
  calc.onclose=function()
  {  	
  	return 1;	
  }
}
