﻿		var lastNotify = new Date();
	
       
	function SetTypingNotification() 
    {
		//Get text control
		// THIS WILL CRASH
        //var txt1 = $get("message");
       
        //Call server side method
        ///Flipmind.LiveChat.Services.ChatWebService.SetTypingNotification(getCookie('chatId'), txt1.value, OnSetTypingNotificationComplete);
    }
    
    function OnSetTypingNotificationComplete(result,methodName)
    {
    } 

var theInputBox;

    function CallSendMsg(inputBoxId) 
    {
    theInputBox = inputBoxId;
        //Get text control
        var txt1 = $get(inputBoxId);

        //Call server side function
        Flipmind.LiveChat.Services.ChatWebService.SendMsg(txt1.value,getCookie('chatId'),OnCallSendMsgComplete);
    }
    
    function OnCallSendMsgComplete(result,methodName)
    {
        //Get text control
        var txt1 = $get(theInputBox);
        //delete text in message
        txt1.value='';
        //focus
        txt1.focus();
    }
    
    function getCookie(c_name)
    {
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=")
      if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1 
        c_end=document.cookie.indexOf(";",c_start)
        if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end))
        } 
      }
    return ""
    }
    
    
////////////////////
	var lastCheck = new Date();
		 
		function scrollDiv()
		{
			var d;
			if ((d = document.getElementById('chat')) && ('undefined' != typeof d.scrollTop))
			{
				//d.scrollTop = 0;
				d.scrollTop = 5000;
			}
			
			window.setTimeout("scrollDiv()", 950);
			
			var now = new Date();
			var elapse = now.getSeconds() - lastCheck.getSeconds();
			var sameMinute = now.getMinutes - lastCheck.getMinutes();
			if( sameMinute != 0 || elapse >= 2 )
			{
				// Check for typing notification
				Flipmind.LiveChat.Services.ChatWebService.CheckTypingNotification(getCookie('chatId'), OnCheckTypingNotificationComplete);
				
				lastCheck = new Date();
			}
		}
		
		function OnCheckTypingNotificationComplete(result, methodName)
		{
			if( result != '' )
			{
				var v = document.getElementById('typingNotification');
				if( v != null && v != 'undefined' ) 
					v.innerText = result; 
			}
		}
		
		function initControls()
		{
		  //var txtMessage = document.getElementById("message");
		  //if (txtMessage != null){
        //txtMessage.onkeypress = function () { checkEnter(event); };
      //}
      //var sendButton = document.getElementById("sendMessage");
		  //if (sendButton != null){
//        sendButton.onclick = function () { CallSendMsg(); };
  //    }
      //var requestChatButton = document.getElementById("RequestChat");
		  //if (requestChatButton != null){
        //requestChatButton.onclick = function () { RequestChat(); };
      //}
		}
		
		function RequestChat(requestName, requestEmail){
		  // Check for typing notification
		  Flipmind.LiveChat.Services.ChatWebService.RequestChat(requestEmail, requestName, completeCallBack, failCallBack);
		}
		
		function completeCallBack(result){
		  document.getElementById('RequestTemplateContainerDiv').style.display = 'none';
		  document.getElementById('ChattingTemplateContainerDiv').style.display = 'block';
		}
		
		function failCallBack(result){
		  alert('fail to request');
		}
