// JavaScript Document

function cl_xmlHttpObject () 
	  {  
          var xml_http_object;       
  
          try{ 
              	xml_http_object = new XMLHttpRequest();  
				
          	 }catch(e)
			 {
          		try { 
                  		xml_http_object = new ActiveXObject("Msxml2.XMLHTTP");
						
						
              		}
					catch(e)
					{ 
                  		try {
                      			xml_http_object = new ActiveXObject("Microsoft.XMLHTTP");
  
                  } catch(e) { 
                      //alert("ERROR: Your browser does not support AJAX.");
                      return false; 
                  }

              }
 
          }    

          return xml_http_object;      
 
      }

function popitup_chat(url) {
	newwindow=window.open(url,'name','height=350,width=500');
	if (window.focus) {newwindow.focus()}
	return false;
}

function display_message(Text)
	{
		var display_in_div = document.getElementById("massage");
		document.getElementById('massage').innerHTML=Text;
	}

function SendChat()
	{   			
       
		var userid = document.frmlist.userid.value
		var message = document.getElementById("messagetext").value;		
		var senderID = document.frmlist.senderID.value;	
		//alert(usertype);
		//alert(userid);
		//alert(message);
		//alert(senderID);
		
		var xmlhttp1 = new cl_xmlHttpObject();				
		xmlhttp1.open("GET","send_chat.php?userid="+userid+"&message="+message+"&senderID="+senderID,true);
        xmlhttp1.onreadystatechange = function()
    	{
    		 if (xmlhttp1.readyState <4) {
 
                     //document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								display_message(xmlhttp1.responseText);
								//display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};

    xmlhttp1.send(null);
	}
	
	
	
	function EditUserInfo_chat(id)
	{  alert('hi');
	   clear_message();		
       	var id= id;
		var xmlhttp1 = new cl_xmlHttpObject();	
		if(id)
		{
		var mode ='Edit';		
		xmlhttp1.open("GET","register.php?id="+id+"&mode="+mode,true);
		}else
		{
			var mode ='Add';					
			xmlhttp1.open("GET","register.php?mode="+mode,true);
		}
        xmlhttp1.onreadystatechange = function()
    	{
    		 if (xmlhttp1.readyState <4) {
 
                     document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								//clear_message();
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};

    xmlhttp1.send(null);
    }
