﻿
var im_cid = 0;
var site = "http://im2.tw128.com/";
var showChatIcon = true;
var isEnglishAccept = false;
var B2B_UserName = "";

function writehtml()
{  
  // var showChatIcon = true;
   if (arguments.length > 0)
   {
      showChatIcon = arguments[0];
   }
   var showChatIconValue = 1;
   var Iwidth=0;
   var Iheight=0;
   if (showChatIcon == false) 
   {
      showChatIconValue = 0;
      Iwidth = 0;
      Iheight = 0;
   }
   var queryString = "referrer=" + document.referrer;
   var re = /&/g;
       queryString = queryString.replace(re,'***!@****');
       queryString += "&url=" + document.location.href.replace(re,'***!@****');
       queryString += "&title=" + document.title;
       queryString += "&cid=" + im_cid;
       queryString += "&showChatIcon=" + showChatIconValue;
   if (im_cid == 2)
       queryString += "&B2B_UserName=" + B2B_UserName;
   var url = site + "Test.htm?" + queryString;
   url = encodeURI(url);
   //var iframe = document.createElement("iframe");
   //iframe.
   document.write("<iframe id='chatIconIframe'  width='" + Iwidth + "' height='" + Iheight + "' ALLOWTRANSPARENCY='true' FRAMEBORDER='0' SCROLLING='NO' SRC=\"" + url + "\"></iframe>");
   if (showChatIcon == false && displayAcceptWindow == false) return;
   if (isEnglishAccept)
   {
      showEnglishAcceptWin();
      return;
   }
   document.write("<script" +" type='text/javascript' src='" + site + "/writeaccept.aspx?CID="+ im_cid + "&showChatIcon=" + showChatIconValue + "'  charset='gb2312'></" + "script> ");
}


function hideAcceptWindow()
{
   var d = document.getElementById('Dialogbox1122');
   if (d)
    d.style.visibility = 'hidden';
}

var isOpenChatWindow = false;
var displayAcceptWindow = true;

function showAcceptWindow()
{

    var d = document.getElementById('Dialogbox1122');
    if (isOpenChatWindow == true) return;
    if (displayAcceptWindow == false) return;

    window.attachEvent( "onscroll", moveAcceptWindow);
    window.attachEvent( "onresize", moveAcceptWindow);
    
    if (d)
    {            

      //d.style.top=(document.body.scrollTop+(document.body.clientHeight-d.offsetHeight)/2)+"px";
      //d.style.left=(document.body.scrollLeft+(document.body.clientWidth-d.offsetWidth)/2)+"px";
     
      d.style.visibility = 'visible';

      moveAcceptWindow();
    }
}

var showflash = true;
var ImHotelId = 0;
var tform = null;
function OpenChatWindow()
{

        isOpenChatWindow = true;
        hideAcceptWindow();
        var tUrl = site + "CallerChat.aspx?CID=" + im_cid + "&title=" + document.title;
        tUrl = encodeURI(tUrl);
        
        if ( tform == null || tform.closed)
        {
          if (showflash) 
          {
             tUrl += "&showflash=true&hotelId=" + ImHotelId;
             tform = window.open(tUrl, 'IsOpenWin' ,'height='+screen.availHeight+',   width='+screen.availWidth+',   top=0,   left=0,   toolbar=no,   menubar=no,   scrollbars=yes,   resizable=yes,   location=no,   status=yes');  
          }
          else
          {
             tform = window.open(tUrl, 'IsOpenWin','height=430,width=604,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no');
          }
       }
       
      tform.focus();
}

function OpenLYWindow()
 {
    var  width = 578;
    var  height = 438;
    var  tUrl = site + "LY/CallerLY.aspx?CID=" + im_cid + "&url=" + document.location.href;
    var  t = window.open(tUrl, 'IsOpenWin','height=' + height + ',width=' + width + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no');
    t.focus();
 }

var divX = 0;
 var divY = 0;
 
 function handleonmouseover()
 {
     var oEvent = event;
     var d = document.getElementById('Dialogbox1122');
     if (d)
     {
         divX = oEvent.clientX - d.offsetLeft;
         divY = oEvent.clientY - d.offsetTop;
         
         document.body.attachEvent ( "on" + "mousemove", DivMousemove);
         document.body.attachEvent ( "on" + "mouseup", DivMouseup);
     }
 }
 
 function DivMousemove()
 {
     var oEvent = event;
     var d = document.getElementById('Dialogbox1122');
     if (d)
     {
        d.style.left = oEvent.clientX - divX;
        d.style.top = oEvent.clientY - divY;
     }
 }
 
 function DivMouseup()
 {
     document.body.detachEvent ( "on" + "mousemove", DivMousemove);
     document.body.detachEvent ( "on" + "mouseup", DivMouseup);
 }
 
 function moveAcceptWindow()
 {
    if (displayAcceptWindow == false || isOpenChatWindow == true) return;
    var d = document.getElementById('Dialogbox1122');
    if (d)
      {
        //d.style.top=(document.body.scrollTop+(document.body.clientHeight-d.offsetHeight)/2)+"px";
        //d.style.left=(document.body.scrollLeft+(document.body.clientWidth-d.offsetWidth)/2)+"px";
        var documentTop = document.documentElement.scrollTop || document.body.scrollTop;
        var documentLeft = document.documentElement.scrollLeft  || document.body.scrollLeft ;
        
        var docHeight = document.documentElement.offsetHeight|| document.body.offsetHeight;
        var docWidth = document.documentElement.offsetWidth || document.body.offsetWidth;

        d.style.top= docHeight / 2 - d.offsetHeight / 2 + documentTop;
        d.style.left= (documentLeft+(docWidth-d.offsetWidth)/2);
      }

 }
 

setTimeout("showAcceptWindow()",5000);

function showEnglishAcceptWin()
{
   var tStr = "<div id='Dialogbox1122' style='position:absolute; visibility:hidden; text-align:center; top:200px; cursor:move;'  onmousedown='handleonmouseover()'> " +
             "<table width='440' border='0' cellspacing='0' cellpadding='0'>" +
             "<tr>" +
             "<td><table width='100%' border='0' cellspacing='0' cellpadding='0'>" +
             "<tr>" +
             "<td width='3%'><img src='$site$/images/box_03.gif' width='15' height='36' /></td>"+
             "<td width='68%' align='left' background='$site$/images/box_04.gif' style=' padding-top:5px; color:#FFFFFF; font-size:14px;'><b>Invitation</b></td>" +
             "<td width='14%'><img src='$site$/images/box_06_En.gif' width='182' height='36' border='0' /></td>" +
             "<td width='15%'><img src='$site$/images/box_07.gif' width='11' height='36' /></td>" +
             "</tr>" +
             "</table></td>" +
             "</tr>"+
             "<tr>" +
             "<td><table width='440' height='124' border='0' cellpadding='0' cellspacing='0'>" +
             "<tr>"+
             "<td background='$site$/images/box_09.gif'><table width='100%' height='51' border='0' cellpadding='0' cellspacing='0' >"+
             "<tr>" +
             "<td height='30' align='left' style='padding-left:140px; font-size: 10pt;'>Welcome to Room Reservation !</td>"+
             "</tr>" +
             "<tr>" +
             "<td height='30'  style='padding-right:30px; font-size: 12px; text-align:right;'>Would you like to talk with customer service?</td>" +
             "</tr>" +
             "<tr>" +
             "<td height='30' valign='bottom' style='padding-left:150px;'><table width='200' border='0' align='right' cellpadding='0' cellspacing='0'>" +
             "<tr>" +
             "<td width='88'><img src='$site$/images/box_01_En.gif' style='cursor: hand;'  width='64' height='21' onclick='javascript: hideAcceptWindow();OpenChatWindow(); '></td> " +
             "<td width='112'><img src='$site$/images/box_02_En.gif' style='cursor: hand;'  width='64' height='21' onclick='javascript: hideAcceptWindow(); '/></td>" +
             "</tr>" +
             "</table></td>" +
             "</tr>" +
             "</table></td>" +
             "</tr>" +
             "</table></td>" +
             "</tr>" +
             "</table>" +
             "</div>";
      var tER = /\$site\$/g;
      tStr = tStr.replace(tER, "http://im2.tw128.com/template/Style1/inviteBox");
      document.write(tStr);
}