/*
	Author		: 	Mukesh Rane
	Email  		: 	r.mukesh@cssaglobal.com
	created		:	Friday - 13-12-2008
*/

	//	------------------------	declear all file path --------------------------
	var saveFilePath;
	this.saveFilePath = SITEROOT + "/myajaxchat/save.php";

	var displayChatMessageFilePath;
	this.displayChatMessageFilePath = SITEROOT + "/myajaxchat/displayMessages.php";

	var checkMessageSendFilePath;
	this.checkMessageSendFilePath = SITEROOT + "/myajaxchat/checkMessageSend.php";
	
	//var displayTypingTextMessageFilePath;
	//this.displayTypingTextMessageFilePath = SITEROOT + "/myajaxchat/checktypingmessage.php";

	//	-----------------------		declear all global veriable	-------------------
	var fromUserId;
	var toUserId;
	this.fromUserId = fromUserId;
	this.toUserId = toUserId;

//	-----------------------		function for min max chat user list window	-------------------
	
	function chatPlusMinus_MR(id,rootimagepath){
		if(document.getElementById(id).style.display == 'none'){
			$("#" + id).fadeIn("slow");
			document.getElementById('MyAjaxChatPlusMinus').src = rootimagepath + 'plusMinus2.gif';
		}else{
			$("#" + id).fadeOut("slow");
			document.getElementById('MyAjaxChatPlusMinus').src = rootimagepath + 'plusMinus1.gif';
		}
	}

	//	-----------------------		function for open chat  window	-------------------

	function openChatWindow_MR(username,fromUserId,toUserId){
		this.fromUserId = fromUserId;
		this.toUserId = toUserId;
		
		classCreateWindow.createWindow_MR(username,fromUserId,toUserId,0);
		var userChatWindowId = document.getElementById("chatwindow_" + this.toUserId);
		
		if(userChatWindowId.style.visibility == "hidden"){
			winInit();
			if (winList["chatwindow_" + this.toUserId]) {	
				winList["chatwindow_" + this.toUserId].open();
				doDisplayMessages_MR(fromUserId,toUserId);
				//doDisplayTypingText_MR(fromUserId,toUserId,"");
				document.getElementById("chatText_" + this.toUserId).focus();
				return false;
			}
		}
		
	}

	//	-----------------------		function for send message  window	-------------------

	function doSend_MR(fromUserId,toUserId,chatText){
		var toUserId	=	(toUserId?toUserId:0);
		var fromUserId	=	(fromUserId?fromUserId:0);
		var chatText 	=	chatText;
		
		if(chatText.length > 0 && toUserId > 0){
			ajax.sendrequest("POST",this.saveFilePath, { chatText : chatText , toUserId:toUserId,fromUserId:fromUserId}, "isDoSend_MR", "");
	
			if(document.getElementById("chatText_" + toUserId)){
				document.getElementById("chatText_" + toUserId).value = "";
			}else{
				document.getElementById("chatText_" + fromUserId).value = "";
			}
		}
		
	}
	
	function isDoSend_MR(msg){
		if(msg.success == 1){
			doDisplayMessages_MR(msg.fromUserId,msg.toUserId);
		}
	}

	//	-----------------------		function for display message to user	-------------------
	
	function doDisplayMessages_MR(fromUserId,toUserId){
		var toUserId = (toUserId?toUserId:0);
		var fromUserId = (fromUserId?fromUserId:0);
	
		var userChatWindowId = (document.getElementById("userChatWindow_" + toUserId)?document.getElementById("userChatWindow_" + toUserId):document.getElementById("userChatWindow_" + fromUserId));
	
		if(userChatWindowId){
			ajax.sendrequest("GET",this.displayChatMessageFilePath, {toUserId:toUserId,fromUserId:fromUserId,r:parseInt(Math.random()*99999999)}, "",userChatWindowId);
			return 1;
		}
	}
	
	function chat_CheckForOnLinkMessage_MR(){
	
		var flag = 1;
		ajax.sendrequest("GET",this.checkMessageSendFilePath, {flag:flag,r:parseInt(Math.random()*99999999)}, "isChat_CheckForOnLinkMessage_MR", "");
		
		var userChatWindowId = (document.getElementById("userChatWindow_" + this.toUserId)?document.getElementById("userChatWindow_" + this.toUserId):document.getElementById("userChatWindow_" + this.fromUserId));
	
		if(userChatWindowId){
			var objDiv = userChatWindowId;
			objDiv.scrollTop = objDiv.scrollHeight;	
		}
	}
	
	function isChat_CheckForOnLinkMessage_MR(msg){ 
		if(msg.to_user_id && msg.from_user_id && msg.success == 1 && !document.getElementById("chatwindow_" + msg.from_user_id)){
			classCreateWindow.createWindow_MR(msg.from_user_name,msg.from_user_id,msg.to_user_id,1);
			winInit();
			
			var userChatWindowId = document.getElementById("chatwindow_" + msg.from_user_id);
			if(userChatWindowId){
				if(userChatWindowId.style.visibility == "hidden" && msg.success == 1){
					///sound
					if (winList["chatwindow_" + msg.from_user_id]) winList["chatwindow_" + msg.from_user_id].open();
					doDisplayMessages_MR(msg.from_user_id,msg.to_user_id);
				}
			}
		}else{
			doDisplayMessages_MR(msg.from_user_id,msg.to_user_id);
		}
		
		this.fromUserId = (msg.from_user_id?msg.from_user_id:this.fromUserId);
		this.toUserId = (msg.toUserId?msg.toUserId:this.toUserId);
		
		window.setTimeout(chat_CheckForOnLinkMessage_MR, 3000, true); 
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/*
	
//	-----------------------		function for min max chat user list window	-------------------
	
	function chatPlusMinus_MR(id,rootimagepath){
		if(document.getElementById(id).style.display == 'none'){
			$("#" + id).fadeIn("slow");
			document.getElementById('MyAjaxChatPlusMinus').src = rootimagepath + 'plusMinus2.gif';
		}else{
			$("#" + id).fadeOut("slow");
			document.getElementById('MyAjaxChatPlusMinus').src = rootimagepath + 'plusMinus1.gif';
		}
	}

	//	-----------------------		function for open chat  window	-------------------

	function openChatWindow_MR(username,fromUserId,toUserId){
		this.fromUserId = fromUserId;
		this.toUserId = toUserId;
		
		classCreateWindow.createWindow_MR(username,fromUserId,toUserId,0);
		var userChatWindowId = document.getElementById("chatwindow_" + this.toUserId);
		
		if(userChatWindowId.style.visibility == "hidden"){
			winInit();
			if (winList["chatwindow_" + this.toUserId]) {	
				winList["chatwindow_" + this.toUserId].open();
				doDisplayMessages_MR(fromUserId,toUserId);
				//doDisplayTypingText_MR(fromUserId,toUserId,"");
				document.getElementById("chatText_" + this.toUserId).focus();
				return false;
			}
		}
		
	}

	//	-----------------------		function for send message  window	-------------------

	function doSend_MR(fromUserId,toUserId,chatText){
		var toUserId	=	(toUserId?toUserId:0);
		var fromUserId	=	(fromUserId?fromUserId:0);
		var chatText 	=	chatText;
		
		if(chatText.length > 0 && toUserId > 0){
			ajax.sendrequest("POST",this.saveFilePath, { chatText : chatText , toUserId:toUserId,fromUserId:fromUserId}, "isDoSend_MR", "");
	
			if(document.getElementById("chatText_" + toUserId)){
				document.getElementById("chatText_" + toUserId).value = "";
			}else{
				document.getElementById("chatText_" + fromUserId).value = "";
			}
		}
		
	}
	
	function isDoSend_MR(msg){
		if(msg.success == 1){
			doDisplayMessages_MR(msg.fromUserId,msg.toUserId);
		}
	}
	
	//	-----------------------		function for display message to user	-------------------
	
	function doDisplayMessages_MR(fromUserId,toUserId){
		var toUserId = (toUserId?toUserId:0);
		var fromUserId = (fromUserId?fromUserId:0);
	
		var userChatWindowId = (document.getElementById("userChatWindow_" + toUserId)?document.getElementById("userChatWindow_" + toUserId):document.getElementById("userChatWindow_" + fromUserId));
	
		if(userChatWindowId){
			ajax.showIndicator = userChatWindowId;
			ajax.sendrequest("GET",this.displayChatMessageFilePath, {toUserId:toUserId,fromUserId:fromUserId}, "",userChatWindowId);
			return 1;
		}
	}
	
	function doDisplayTypingText_MR(fromUserId,toUserId,text){
		var toUserId = (toUserId?toUserId:0);
		var fromUserId = (fromUserId?fromUserId:0);
		var text  = text || "";
		if(toUserId > 0){

			//var userChatWindowId = (document.getElementById("userChatWindowStatus_" + toUserId)?document.getElementById("userChatWindowStatus_" + toUserId):document.getElementById("userChatWindowStatus_" + fromUserId));
			var userChatWindowId = (document.getElementById("userChatWindowStatus_" + toUserId));

			//if(userChatWindowId){
				ajax.sendrequest("GET",this.displayTypingTextMessageFilePath, {toUserId:toUserId,fromUserId:fromUserId,text:text}, "",userChatWindowId);
				//return 1;
			//}
		}
	}
	

	function chat_CheckForOnLinkMessage_MR(){
		var flag = 1;
		ajax.sendrequest("POST",this.checkMessageSendFilePath, {flag:flag}, "isChat_CheckForOnLinkMessage_MR", "");
		
		var userChatWindowId = (document.getElementById("userChatWindow_" + this.toUserId)?document.getElementById("userChatWindow_" + this.toUserId):document.getElementById("userChatWindow_" + this.fromUserId));
	
		if(userChatWindowId){
			var objDiv = userChatWindowId;
			objDiv.scrollTop = objDiv.scrollHeight;	
		}
	}
	
	function isChat_CheckForOnLinkMessage_MR(msg){
		if(msg.to_user_id && msg.from_user_id && msg.success == 1 && !document.getElementById("chatwindow_" + msg.from_user_id)){
			classCreateWindow.createWindow_MR(msg.from_user_name,msg.from_user_id,msg.to_user_id,1);
			winInit();
			
			var userChatWindowId = document.getElementById("chatwindow_" + msg.from_user_id);
			if(userChatWindowId){
				if(userChatWindowId.style.visibility == "hidden" && msg.success == 1){
					///sound
					if (winList["chatwindow_" + msg.from_user_id]) winList["chatwindow_" + msg.from_user_id].open();
					doDisplayMessages_MR(msg.from_user_id,msg.to_user_id);
					//doDisplayTypingText_MR(msg.to_user_id,msg.from_user_id,"");
				}
			}
		}else{
			doDisplayMessages_MR(msg.from_user_id,msg.to_user_id);
			//doDisplayTypingText_MR(msg.to_user_id,msg.from_user_id,"");
		}
		
		this.fromUserId = (msg.from_user_id?msg.from_user_id:this.fromUserId);
		this.toUserId = (msg.toUserId?msg.toUserId:this.toUserId);
		
		window.setTimeout(chat_CheckForOnLinkMessage_MR, 2000, true);
	}
	
	*/
	
	
