﻿

function GetAjaxObj()
{
	var xmlhttp = false;
	try {
		// IE 
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
	} catch (e) {
		try {
			// Old IE
	    	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	  	} catch (E) {
			try {
				// For Mozilla, Firefox, Safari, Opera, and Netscape:
				 xmlhttp=new XMLHttpRequest();
			}catch(e){
	    		xmlhttp = false;
			}
	   }
	}
	return xmlhttp;
}


function checkReadyState(obj){
	if(obj.readyState == 4)
	{
		if(obj.status == 200)  
		{
			return true;
		}else{
			alert("Problem retrieving XML data");
		}
	}
	else
	{
		return false
	}
}



function AjaxUpdateContent( updateObjID , URL , scriptOnUnload){
	var ObjID = document.getElementById(updateObjID);
	var stateReturn;
	
	var xmlhttp = GetAjaxObj(); 
	if(!xmlhttp)
	{
		document.write ("Script Not support");
		return;
	}
	
	try 
	{
		xmlhttp.open("GET", URL ,true); 
		
		xmlhttp.onreadystatechange = function() {
			  state = checkReadyState(xmlhttp);
			  if (state== true) 
			  {
					ObjID.innerHTML = xmlhttp.responseText;
					
					if(scriptOnUnload != undefined)
					{
						eval(scriptOnUnload);
					}
			  }else{
					ObjID.innerHTML ="Loading....";
			  }
		 }
		 
 	    xmlhttp.send(null) // Sends the request.
	}
	catch(e) 
	{
		document.writeln(e+"<br>");
		document.writeln ("XmlHttp undefined");
		return;
	}	
}




/*****************************************************************
*
* function for use ajax
*
*****************************************************************/

function getMainContent(cate, val){
		AjaxUpdateContent('mainContainer', "getMain.php?id="+val+"&cate="+cate);
}