/*
	Author		: 	Mukesh Rane
	Email  		: 	r.mukesh@cssaglobal.com
	created		:	Friday - 13-12-2008
*/
	function classCreateExpWindow_MR(){
		var exp_username = exp_username;
		var exp_fromUserId = exp_fromUserId;
		var exp_toUserId = exp_toUserId;
		var exp_isOpen = exp_isOpen;
		var exp_mainDiv = ""; 
		this.createExpWindow_MR=function (exp_username,exp_fromUserId,exp_toUserId,exp_isOpen)
		{	
			//if when user click on username isOpen = 0 and open dyanamic = 1
			this.exp_username = exp_username;			
			this.exp_fromUserId = exp_fromUserId;			
			this.exp_toUserId = exp_toUserId;			
			this.exp_isOpen = exp_isOpen;			
			//--------------------------------------------------------------------------------	
			var exp_countWindowOpen = exp_countHowManyWindowOpen();			
			this.exp_mainDiv = document.createElement("div");
			this.exp_mainDiv.setAttribute("id","chatwindow_" + (this.exp_isOpen == 1?this.exp_fromUserId:this.exp_toUserId));		//	Dynamic
			this.exp_mainDiv.setAttribute("class","window");
			this.exp_mainDiv.className = "window";
			var exp_rightPositionOfWindow = (exp_countWindowOpen * 290);
			_exp_setStyle(this.exp_mainDiv,'margin:0px; padding:2px; position:fixed; text-align:left; visibility:hidden; right:' + exp_rightPositionOfWindow + 'px; bottom:250px; z-index:12; width:280px;');			
			//this.form.appendChild(this.exp_mainDiv);
			//--------------------------------------------------------------------------------
			var exp_titleBar = document.createElement("div");
			this.exp_titleBar = exp_titleBar;
			this.exp_titleBar.setAttribute("class","titleBar");
			this.exp_titleBar.className = "titleBar";				
			this.exp_mainDiv.appendChild(this.exp_titleBar);
		//--------------------------------------------------------------------------------
			var exp_titleBarText = document.createElement("span");
			this.exp_titleBarText = exp_titleBarText;
			this.exp_titleBarText.setAttribute("class","titleBarText");
			this.exp_titleBarText.className = "titleBarText";
			
			this.exp_titleBar.appendChild(this.exp_titleBarText);
				//--------------------------------------------------------------------------------
			var exp_titleBarTextNode = document.createTextNode(this.exp_username);	// Dynamic
			this.exp_titleBarTextNode = exp_titleBarTextNode;

			this.exp_titleBarText.appendChild(this.exp_titleBarTextNode);
			//--------------------------------------------------------------------------------
			var exp_titleBarButtons = document.createElement("img");
			this.exp_titleBarButtons = exp_titleBarButtons;
			this.exp_titleBarButtons.setAttribute("class","titleBarButtons");
			this.exp_titleBarButtons.className = "titleBarButtons";
			this.exp_titleBarButtons.setAttribute("src",SITEROOT + "/js/myajaxchat/images/min.gif");
			this.exp_titleBarButtons.onclick =function(){
					winList["chatwindow_" + (exp_isOpen == 1?exp_fromUserId:exp_toUserId)].minimize();return false;
			}
			this.exp_titleBar.appendChild(this.exp_titleBarButtons);
			
			var exp_titleBarButtons = document.createElement("img");
			this.exp_titleBarButtons = exp_titleBarButtons;
			this.exp_titleBarButtons.setAttribute("class","titleBarButtons");
			this.exp_titleBarButtons.className = "titleBarButtons";
			this.exp_titleBarButtons.setAttribute("src",SITEROOT + "/js/myajaxchat/images/max.gif");
			this.exp_titleBarButtons.onclick =function(){
					winList["chatwindow_" + (exp_isOpen == 1?exp_fromUserId:exp_toUserId)].restore();return false;
			}
			this.exp_titleBar.appendChild(this.exp_titleBarButtons);
			
			var exp_titleBarButtons = document.createElement("img");
			this.exp_titleBarButtons = exp_titleBarButtons;
			this.exp_titleBarButtons.setAttribute("class","titleBarButtons");
			this.exp_titleBarButtons.className = "titleBarButtons";
			this.exp_titleBarButtons.setAttribute("src",SITEROOT + "/js/myajaxchat/images/close.gif");
			this.exp_titleBarButtons.onclick =function()
			{
				winList["chatwindow_" + (exp_isOpen == 1?exp_fromUserId:exp_toUserId)].close();				
				var exp_d_nested = document.getElementById("chatwindow_" + (exp_isOpen == 1?exp_fromUserId:exp_toUserId)); 
				var exp_destroyed = document.body.removeChild(exp_d_nested);
				return false;
			}
			this.exp_titleBar.appendChild(this.exp_titleBarButtons);
				//--------------------------------------------------------------------------------
	
			var exp_clientArea = document.createElement("div");
			this.exp_clientArea = exp_clientArea;
			this.exp_clientArea.setAttribute("class","clientArea");
			this.exp_clientArea.setAttribute("style","height: 300px;");
			this.exp_clientArea.className = "clientArea";
			
			this.exp_mainDiv.appendChild(this.exp_clientArea);
			//--------------------------------------------------------------------------------
			var exp_userChatWindow = document.createElement("div");
			this.exp_userChatWindow = exp_userChatWindow;
			this.exp_userChatWindow.setAttribute("id","userChatWindow_" + (this.exp_isOpen == 1?this.exp_fromUserId:this.exp_toUserId));		//	Dynamic
			this.exp_userChatWindow.setAttribute("style","height:230px; overflow:auto; border:0px solid #000000;");
			this.exp_userChatWindow.className = "userChatWindow";
		
			this.exp_clientArea.appendChild(this.exp_userChatWindow);
			//--------------------------------------------------------------------------------
			var exp_div = document.createElement("div");
			this.exp_div = exp_div;
			this.exp_div.setAttribute("style","height:15px;");
			this.exp_div.setAttribute("id","userChatWindowStatus_" + (this.exp_isOpen == 1?this.exp_fromUserId:this.exp_toUserId));		//	Dynamic
		
			this.exp_clientArea.appendChild(this.exp_div);
			//--------------------------------------------------------------------------------
			var exp_div_1 = document.createElement("div");
			this.exp_div_1 = exp_div_1;
			
			this.exp_clientArea.appendChild(this.exp_div_1);
				//--------------------------------------------------------------------------------
			var exp_chatText = document.createElement("input");
			this.exp_chatText = exp_chatText;
			this.exp_chatText.setAttribute("type","text");
			this.exp_chatText.setAttribute("name","chatText" + (this.exp_isOpen == 1?this.exp_fromUserId:this.exp_toUserId));
			this.exp_chatText.setAttribute("id","chatText_" + (this.exp_isOpen == 1?this.exp_fromUserId:this.exp_toUserId));	//	Dynamic					
			this.exp_chatText.setAttribute("style","width:260px;");
			this.exp_chatText.className = "chatTextBox";

			this.exp_chatText.onkeypress = function(e){
				
				if( !e ) {	if( window.event ) {//Internet Explorer
					e = window.event;	} else {	return;	}}
				if( typeof( e.keyCode ) == 'number'  ) {//DOM
					e = e.keyCode;} else if( typeof( e.which ) == 'number' ) {//NS 4 compatible
					e = e.which;} else if( typeof( e.charCode ) == 'number'  ) {//also NS 6+, Mozilla 0.9+
					e = e.charCode;} else {	//total failure, we have no way of obtaining the key code
				return;}
				
				//doDisplayTypingText_MR(toUserId,fromUserId,username + " typing message...");				
				var exp_charCode;	
				exp_charCode = e;	
				if(exp_charCode == 13) 
					doExpSend_MR((exp_isOpen == 1?exp_toUserId:exp_fromUserId),(exp_isOpen == 1?exp_fromUserId:exp_toUserId),exp_chatText.value);	
			}									

			this.exp_div_1.appendChild(this.exp_chatText);
			//--------------------------------------------------------------------------------
			var exp_div_2 = document.createElement("div");
			this.exp_div_2 = exp_div_2;
			this.exp_div_2.setAttribute("style","padding-top:5px;");
		
			this.exp_clientArea.appendChild(this.exp_div_2);
			//--------------------------------------------------------------------------------
			document.body.appendChild(this.exp_mainDiv);
		}		
	}
	var classCreateExpWindow = new classCreateExpWindow_MR();
	 function _exp_setStyle(element, exp_declaration) 
	{

	   if (exp_declaration.charAt(exp_declaration.length-1)==';')

		 exp_declaration = exp_declaration.slice(0, -1);

	   var exp_k, exp_v;

	   var exp_splitted = exp_declaration.split(';');

	   for (var i=0, exp_len=exp_splitted.length; i<exp_len; i++) {

		  exp_k = exp_rzCC(exp_splitted[i].split(':')[0]);

		  exp_v = exp_splitted[i].split(':')[1];

		if(exp_k || exp_v){
		  eval("element.style."+exp_k+"='"+exp_v+"'");
		}
	   }
	 }
	
	 function exp_rzCC(exp_s)
	{
	   // retrieving-css-styles-via-javascript/
	   for(var exp=/-([a-z])/; 
		   exp.test(exp_s); 
		   exp_s=exp_s.replace(exp,RegExp.$1.toUpperCase()));
	   return exp_s;
	 }
	 
	 function exp_countHowManyWindowOpen()
	{
		var exp_arr = jQuery.makeArray(document.getElementsByTagName("div"));
		var exp_count=0;
		for(i=0;i<exp_arr.length;i++){
			if(exp_arr[i].className == "window"){
				exp_count++;	
			}
		}
		return exp_count;
	 }