var timeSetInterval;
var tmpChatMsg;

function enterChatHome(e) {

    if( e.keyCode==13){
        addhomeChat();
	}

}

function addhomeChat(){
    if($('#txtChat').val()!=''&& chkWhiteSpace($('#txtChat').val())==true){
        $('#txtChat').attr("disabled",true);
        var txtChat = $('#txtChat').val();
        $.ajax({
            url:'modules/chat/chatHomeSub.php',
            cache: false,
            data:{'chatTxt':txtChat},
            type:'POST',
            success:function(data){
                if(data == 1){                    
                    $('#txtChat').val('');
                    $('#txtChat').removeAttr("disabled").focus();
                    getChatMsg();
                }else if(data == -50){
                    sessionTimeout();
                }else{
                    alert(data);
                }
            }

		});

    }//E-if
    
}//E-func


function getChatMsg(){
	setTimeout("innitChatMsg()",2000);
	timeSetInterval = setInterval("innitChatMsg()",5000); //setTime Reload function innitChat() 5 second

}

function innitChatMsg(){
	$.ajax({
        url:'modules/chat/chatHome.php',
        cache: false,
        success:function(data){
            showChatMsg(data);
        }
	});
}

function scrollTop(){
	try{ 
		/*document.getElementById('chatMsg').scrollTop =100000;*/
		document.getElementById('chatMsg').scrollTop=2000;
        
	}catch(e){
		;
	}
}

function showChatMsg(data){
	try{
		var msgChat = data;
		if(msgChat != tmpChatMsg){
			tmpChatMsg = msgChat;
			$('#chatMsg').empty().append(msgChat);
			setTimeout("scrollTop()",1500);
		}
	}catch(e){
		;
	}
}
