

// Xay dung ham makeRequest
   function makeRequest(url, parameters, method, id) {
	   	http_request = false;
      	if (window.XMLHttpRequest) { // Mozilla, Safari,...
         	http_request = new XMLHttpRequest();
         	if (http_request.overrideMimeType) {
				// set type accordingly to anticipated content type
				//http_request.overrideMimeType('text/xml');
				http_request.overrideMimeType('text/html');
         	}
      	} else if (window.ActiveXObject) { // IE
         	try {
            	http_request = new ActiveXObject("Msxml2.XMLHTTP");
         	} catch (e) {
            	try {
               		http_request = new ActiveXObject("Microsoft.XMLHTTP");
            	} catch (e) {}
         	}
      	}
      	if (!http_request) {
         	alert('Cannot create XMLHTTP instance');
         	return false;
      	}
		
      	http_request.onreadystatechange = function()  
   	  	{    
			document.getElementById(id).innerHTML = '<div id="soaptissue-testimonials-content2" align="center" style="vertical-align:middle"><image src="images/template/loading.gif"></div>';
       		if (http_request.readyState == 4) {  
		   		if (http_request.status == 200) {  
				   //alert(http_request.responseText);  
				   result = http_request.responseText;  
				   document.getElementById(id).innerHTML = '';
				   
				   document.getElementById(id).innerHTML = result;
       			} else {  
       				alert('There was a problem with the request.');  
       				return false;
       			}  
       		}  
   		} 
		if(method == 'GET')
		{
			http_request.open(method, url + parameters, true);
			http_request.send(null)
		} 
		else{
			http_request.open(method, url , true);
			http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
			http_request.setRequestHeader("Content-length", parameters.length);  
			http_request.setRequestHeader("Connection", "close");  
			http_request.send(parameters);  
			return true;
		}
	}

// Xay dung ham ajaxRequest de khi submit form thi goi ham nay

   function ajaxRequest(url, obj, method, hienthi) {
      var parameters = "";
	  //obj=document.getElementById(idform);
	  if (method=='GET') parameters="?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               parameters += obj.childNodes[i].name + "=" + encodeURIComponent(obj.childNodes[i].value) + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  parameters += obj.childNodes[i].name + "=" + encodeURIComponent(obj.childNodes[i].value) + "&";
               } else {
                  parameters += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  parameters += obj.childNodes[i].name + "=" + encodeURIComponent(obj.childNodes[i].value) + "&";
               }
            }
         }   
		 if (obj.childNodes[i].tagName == "TEXTAREA") {
    			parameters += obj.childNodes[i].name + "=" + encodeURIComponent(obj.childNodes[i].value) + "&";
   		 }

         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            parameters += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         
      }
      makeRequest(url, parameters, method, hienthi);
   }
   
   function loadpage(url, parameters, method, id) {
      	http_request = false;
      	if (window.XMLHttpRequest) { // Mozilla, Safari,...
         	http_request = new XMLHttpRequest();
         	if (http_request.overrideMimeType) {
				// set type accordingly to anticipated content type
				//http_request.overrideMimeType('text/xml');
				http_request.overrideMimeType('text/html');
         	}
      	} else if (window.ActiveXObject) { // IE
         	try {
            	http_request = new ActiveXObject("Msxml2.XMLHTTP");
         	} catch (e) {
            	try {
               		http_request = new ActiveXObject("Microsoft.XMLHTTP");
            	} catch (e) {}
         	}
      	}
      	if (!http_request) {
         	alert('Cannot create XMLHTTP instance');
         	return false;
      	}
      	http_request.onreadystatechange = function()  
   	  	{    
       		document.getElementById(id).innerHTML = '<div align="center" style="vertical-align:middle;margin-top:10px"><image src="images/template/loading.gif"></div>';
			
       		if (http_request.readyState == 4) {  
		   		if (http_request.status == 200) {  
				   //alert(http_request.responseText);  
				   result = http_request.responseText;  
				   document.getElementById(id).innerHTML = '';
				   document.getElementById(id).innerHTML = result;
				   document.getElementById(id).style.display = 'block';
       			} else {  
       				alert('There was a problem with the request.');  
       				return false;
       			}  
       		}  
   		} 
		if(method == 'GET')
		{
			http_request.open(method, url + parameters, true);
			http_request.send(null)
		} 
		else{
			http_request.open(method, url , true);
			http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");  
			http_request.setRequestHeader("Content-length", parameters.length);  
			http_request.setRequestHeader("Connection", "close");  
			http_request.send(parameters);  
			return true;
		}
	}
