function get_xmlhttp() //Hàm này để tạo ra đối tượng XMLHTTPRequest ma cac trinh duyet ho tro trong kỷ thụât ajax.
{  
      xml=null;
        try
        {
        	xml=new XMLHttpRequest();
	return xml;
        }
        catch(err)
        {
        	try
		{
			xml=new ActiveXObject("Microsoft.XMLHTTP");
			return xml;
		}

	catch(err1)
		
		{
			try
				{
					xml= new ActiveXObject("Msxml2.XMLHTTP");
			 		return xml;
				}

			catch(err2)

				{
					alert('Browser can not initialize XMLHttpRequest object');
					return xml;
				}

		}

		
        }
       
   return xml;
} 


function process_data(data_gui,url_xuly,id_phantu_bieudien_dulieu) //Hàm này để lấy dữ liệu từ đối tượng XMLHTTP và hiển thị trên trình duyệt.
{
        xmlresult=get_xmlhttp();
	
        if(xmlresult != null)
        {
            url=url_xuly;

            xmlresult.open("POST",url,true);// Dùng kiểu gửi data theo phương thức post để an toàn và gửi nhiều data một lúc.
	
	xmlresult.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;');
            

            xmlresult.onreadystatechange = function ()
                {
                    if (xmlresult.readyState == 4 && xmlresult.status == 200) // Kiểm tra co data tra ve va khong co loi.

                    {
                        
                        document.getElementById(id_phantu_bieudien_dulieu).innerHTML=xmlresult.responseText;//Trình diễn data trả về tại client trên một phần tử như thẻ <div> hay <span>... có id được truyền vào.

		                //escape(data gửi theo url cần mã hóa);---->Ham nay ma hoa cac ky tu va tra ve chuoi theo kieu giong nhu url de gui di cùng url.

                    } 

                }

           xmlresult.send(data_gui);//Hàm gửi data đi.

        }

        else
            alert('Your browser need to support Ajax to use this page best.');

}
time = 0;
url_xuly = "";
data = "";
idphantu = "";
status = false;
requesthttp = 0;


function playorstop_image(state,datasend,urlsend,idpt)
{
    data=datasend;url_xuly=urlsend;idphantu=idpt;status=state;
    if(state == false)
    {
        if(requesthttp != null)
        {
        requesthttp = null;
        }
        window.clearTimeout(time);
    
    }
    else
    {
        
          autoplayimage();  
       
    }
}
function autoplayimage()
{
    
    
        xmlresult=get_xmlhttp();
	
        if(xmlresult != null)
        {
            url=url_xuly;

            xmlresult.open("POST",url,true);// Dùng kiểu gửi data theo phương thức post để an toàn và gửi nhiều data một lúc.
	
	xmlresult.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;');
            

            xmlresult.onreadystatechange = function ()
                {
                    if (xmlresult.readyState == 4 && xmlresult.status == 200) // Kiểm tra co data tra ve va khong co loi.

                    {
                        
                        document.getElementById(idphantu).innerHTML=xmlresult.responseText;//Trình diễn data trả về tại client trên một phần tử như thẻ <div> hay <span>... có id được truyền vào.

		                //escape(data gửi theo url cần mã hóa);---->Ham nay ma hoa cac ky tu va tra ve chuoi theo kieu giong nhu url de gui di cùng url.
		                
		                time = window.setTimeout('autoplayimage()',3000);      

                    } 

                }

           xmlresult.send(data);//Hàm gửi data đi.
           if(requesthttp == 0)
            {
           requesthttp = xmlresult;
            }
           

        }

        else
            alert('Your browser need to support Ajax to use this page best.');
     

}

function an_hien(an,hien)
{
document.getElementById(an).style.display='none';
document.getElementById(hien).style.display='inline';

}