// JavaScript Document




var msgsys = {
	
	win: {},
	countries:false,
	basicUrl: 'http://www.scouting-team.com/',
	league_options:false,
	url_send: '/index.php?/talk/send',
	url_sendall: '/index.php?/talk/sendtoall',
	url_get: '/index.php?/talk/get',
	url_getDeleted: '/index.php?/talk/getdeleted',
	
	w: 460,
	h: 460,
	history:false,
	msg:false,
	to_id:false,
	from_id:false,
	user_id: 0,
	
	


	
	_get: function (from_id,delflag)
	{ 	
		  this.from_id  = from_id;
		  var url;
		  if(!delflag)
		  url = this.url_get ;
		  else
		  url = this.url_getDeleted ;
		
		
		//alert(this.from_id);
		
		  new Ajax.Request( url  , { method: 'post',
	  	  parameters: { msg: this.msg  ,  id :  this.from_id  } ,
	      onSuccess: function(transport) {
			  
		
			 msgsys.setEditWin(msgsys.from_id  ,  transport.responseText );
		   },
	      onFailure: function(){ alert("Error : Could not  conntect to server."); return false; }
		});
		  
		 
		return true;
	
	} ,


	massend: function(to_id) 	
	{
		
		 
		 
	 	  Windows.closeAll();
		  this.msg =  $F('msg');
		  this.to_id =  to_id ;	

		  new Ajax.Request(this.url_sendall  , { method: 'post',
	  	  parameters: { msg: this.msg  ,  id :  this.to_id  } ,
		  onSuccess: function(transport) {
				 var response = transport.responseText ;// ||  "no response from server";
				alert("Message was successfully send!\n\n" +  response  );
    	   },
	      onFailure: function(){ alert("Error : Could not  conntect to server."); return false; }
		});
				  
	
	} ,
	
	
	
	
	create_Win2: function(to_id,name)
	{
	
	this.h =  260; 
	var id  = to_id ;
	Windows.closeAll();
	if (this.win['edituser_'+id] == undefined)
	{
		this.win['edituser_'+id] = new Window({className: "mac_os_x", title: "Send message to  " + name , 
		draggable:true ,
		width:this.w, height:this.h, destroyOnClose: false, resizable: false, recenterAuto:false});
		this.win['edituser_'+id].getContent().innerHTML= "<div class=\"loading\">Loading</div>";
	}
	
 
 	this.win['edituser_'+id].getContent().innerHTML= 
	    '<div  id="msg_win"   >' 
	    +	 '<div class="title">&nbsp;</div>' 
        +     '<div class="clear"></div>' 
        +	 '<label >Message:</label>'
        +     '<div class="ditem" ><textarea id="msg" rows="10" cols="50" name="msg" ></textarea></div>'
        +     '<div class="clear"></div>'
 	    +     '<div>'
	    +     '<label ></label><button type="button"  class="submit" '
        +	 ' onclick="javascript:msgsys.massend(\'' +  to_id  + '\');" >Send message</button>'
        +     '</div>'
        +     '<div class="clear"></div>'
	    +     '</div>';
  
	
	this.win['edituser_'+id].showCenter();
	

	}
	
	,
	
	
	send: function(to_id) 	
	{
	 	  Windows.closeAll();
		
		  this.msg =  $F('msg');
		  this.to_id =  to_id ;	
			
		  new Ajax.Request(this.url_send  , { method: 'post',
	  	  parameters: { msg: this.msg  ,  id :  this.to_id  } ,
	//	  requestHeaders: ['Content-Type','application/x-www-form-urlencoded; charset=UTF-8'],
	      onSuccess: function(transport) {
				 var response = transport.responseText; // ||  "no response text";
 				 alert("Message was successfully send!\n\n"    );
				  
    	   },
	      onFailure: function(){ alert("Error : Could not  conntect to server."); return false; }
		});
				  
	
	},
	
	
	update: function(to_id) 
	{
	 	  Windows.closeAll();
		  
		
		
		  this.msg =  $F('msg');
		  this.to_id =  to_id ;	
		  
			
		  new Ajax.Request(this.url_send  , { method: 'post',
	  	  parameters: { msg: this.msg  ,  id :  this.to_id  } ,
		  requestHeaders: ['Content-Type','application/x-www-form-urlencoded; charset=UTF-8'],
	      onSuccess: function(transport) {
		//		 var response = transport.responseText ||  "no response text";
    			 alert("Message was successfully send!\n\n");

				 
    	   },
	      onFailure: function(){ alert("Error : Could not  conntect to server."); return false; }
		});
				  
	
	},
	
	
		
	setEditWin: function(id,msg)
	{
		
		
	
	Windows.closeAll();	
	if (this.win['edituser_'+id] == undefined )
	{
		this.win['edituser_'+id] = new Window({className: "mac_os_x", title: "Send message ", 
		draggable:true ,
		width:this.w, height:this.h, destroyOnClose: false, resizable: false, recenterAuto:false});
		this.win['edituser_'+id].getContent().innerHTML= "<div class=\"loading\">Loading</div>";
	}
	
 	
			
	
	
 	this.win['edituser_'+id].getContent().innerHTML = 
	    '<div  id="msg_win"   >' 
	    +	  '<div class="title">&nbsp;</div>' 
        +     '<div class="clear"></div>' 
		
        +	 '<label > </label>'
        +     '<div style="margin: 20px 0px 20px 10px;">'
		+     'You can\'t send messege from here.'
		+     'Go to new <a href="'+this.basicUrl+'home/connector/buffer/'+this.user_id+'">new messenger system</a>'
		+     '</div>'
        +     '<div class="clear"></div>'
 	    +     '<div>'
	
		+     '<div>'
		+	  '<label >History:</label>'
        +     '<div class="ditem" ><textarea id="msg" rows="10" cols="50" name="msg" >' +
		msg + '</textarea></div>'
        +     '<div class="clear"></div>'
 	
	    +     '</div>';
  
		this.win['edituser_'+id].showCenter();
		
	} ,
	
	edit_Win: function(from_id,delflag, user_id)
	{
		this.user_id = user_id;
		this._get(from_id,delflag);
	} 
	
	,create_Win: function(id,to_id,name)
	{
	
	this.h =  260; 
	
	Windows.closeAll();
	if (this.win['edituser_'+id] == undefined)
	{
		this.win['edituser_'+id] = new Window({className: "mac_os_x", title: "Send message to  " + name , 
		draggable:true ,
		width:this.w, height:this.h, destroyOnClose: false, resizable: false, recenterAuto:false});
		this.win['edituser_'+id].getContent().innerHTML= "<div class=\"loading\">Loading</div>";
	}
	
 
 	this.win['edituser_'+id].getContent().innerHTML= 
	    '<div  id="msg_win"   >' 
	    +	 '<div class="title">&nbsp;</div>' 
        +     '<div class="clear"></div>' 
        +	 '<label >Message:</label>'
        +     '<div class="ditem" ><textarea id="msg" rows="10" cols="50" name="msg" ></textarea></div>'
        +     '<div class="clear"></div>'
 	    +     '<div>'
	    +     '<label ></label><button type="button"  class="submit" '
        +	 ' onclick="javascript:msgsys.send(\'' +  to_id  + '\');" >Send message</button>'
        +     '</div>'
        +     '<div class="clear"></div>'
	    +     '</div>';
  
	
	this.win['edituser_'+id].showCenter();
	

	}
	
	
} 