function updateChatRequests(){
	$('#newRequests').load('inc/chatrequests.php');
	$('#newRequestsOpt').load('inc/chatrequestsOpt.php');
	setTimeout("updateChatRequests()",3000);
}

var ended = false;


/*function EvalSound() {
  var thissound=document.getElementById('newMessage');
  thissound.Play();
}


*/


function moveDiv(){

		var objDiv = document.getElementById("chatprint");
		$("#chatprint").attr({ scrollTop: $("#chatprint").attr("scrollHeight") });
		
}

function updateChat(){ 
		
		if(ended == true) 
			setTimeout("updateUsermsg()",3000);
		
		if(ended != true){

		if($("#currentChat").val() != ""){
			
			//$("#chatprint").load('inc/chat.php?id='+$("#currentChat").val());	
			//$("#chatDetails").load('inc/chatdetails.php?id='+$("#currentChat").val());	
			
			$.ajax({
			type: "GET",
			url: "inc/chat.php",
			data: "id="+ $("#currentChat").val(),
			success: function(response){
				//alert(response);
             				var newchat =response.indexOf('==**==');

				if(newchat != "-1")
				{
						var output=response.split("==**==");
						//alert(output[0]);
						if(output[1] == "NEW") 
						{ //alert("NEW");
							//newMessageSound();
							EvalSound();
							var data = output[0];

          					document.getElementById("chatprint").innerHTML=output[0];
						}
						//alert(output[1]);
				}
				else {
					 document.getElementById("chatprint").innerHTML=response;
				}
				//alert(newchat[1]);

			 document.getElementById("chatprint").scrollTop=200000;
			 document.getElementById("chatprint").style.border="1px solid #bbbbbb";

			}
			});
			
			$.ajax({
			type: "GET",
			url: "inc/chatdetails.php",
			data: "id="+ $("#currentChat").val(),
			success: function(response){
             document.getElementById("chatDetails").innerHTML=response;
			 
			}
			});
			
		
		document.getElementById("chatprint").scrollTop=200000;
		}
	}
	setTimeout("updateChat()",3000);

	
}
function messageWind() {
	if($("#currentChat").val() != ""){
			$("#messageArea").load('inc/messagearea.php?id='+$("#currentChat").val());
			
	}
setTimeout("moveDiv()",3000);
}
function ipDetails() {
    if($("#currentChat").val() != ""){
            $("#ipdet").load('inc/messagearea.php?id='+$("#currentChat").val());
            
    }

}


function updateUsermsg()
{
		
		$.ajax({
			type: "GET",
			url: "inc/chat.php",
			data: "id="+ $("#currentChat").val(),
			success: function(response){
				
				var newchat =response.indexOf('==**==');

				if(newchat != "-1")
				{
						var output=response.split("==**==");
						//alert(output[0]);
						if(output[1] == "NEW") 
						{ //alert("NEW");
							//newMessageSound();
							EvalSound();
							var data = output[0];

          					document.getElementById("chatprint").innerHTML=output[0];
						}
						//alert(output[1]);
				}
				else {
					 document.getElementById("chatprint").innerHTML=response;
				}
				//alert(newchat[1]);
				
            
    		 document.getElementById("chatprint").style.border="1px solid #bbbbbb";

			}
			});
		
			 document.getElementById("chatprint").scrollTop=200000;
		
}

function newMessageSound() {
	
  var thissound = eval("document.newMessage");
  thissound.Play();
  
}

function EvalSound() {
/*  var thissound=document.getElementById('newMessage');
  thissound.Play();*/
document.getElementById("newMessage").innerHTML="<embed src='chatmsg.wav' hidden=true autostart=true loop=false>";
}

function newRequests() {

   /*var thissound=document.getElementById('newRequest');
 // var thissound = eval("document.newRequest");
    thissound.Play();
  */
  
  document.getElementById("newRequest").innerHTML="<embed src='newrequest.wav' hidden=true autostart=true loop=false>";
}


function noend(){
	ended = false;
}

function support(support_ticket){
	$("#currentChat").val(support_ticket);
	$("#messageArea").load('inc/messagearea.php?id='+support_ticket);
	$("#chatprint").load('inc/chat.php?id='+support_ticket);	
    $("#ipdet").load('inc/ipdetails.php?id='+support_ticket);    
	$("#chatDetails").load('inc/chatdetails.php?id='+support_ticket);	
    
	document.getElementById("chatprint").style.border="1px solid #bbbbbb";

}
