var xmlHttp;

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
	  // Internet Explorer
	  try {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	  catch (e){
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	}
	return xmlHttp;
}



function tampil(content)
{
	alert('as');
	document.getElementById('input_cari_perkara').value = 'tes';
}



// getXMLDocument('tes.php?get=value', tampil, id_loading)
function getXMLDocument(url, callback, id_loading)
{
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
 	{
		alert ("Your browser does not support AJAX!");
		return;
	}

	xmlHttp.onreadystatechange = function()
	{
		if (typeof(id_loading) != 'undefined')
		{
			if (xmlHttp.readyState==1)
			{
				document.getElementById(id_loading).style.display = '';
			}
		}
		
		if (xmlHttp.readyState==4)
		{
			if (xmlHttp.status == 200)
			{
				if (typeof(id_loading) != "undefined")
				{
					document.getElementById(id_loading).style.display = 'none';
				}
				callback(xmlHttp.responseText);
			}
			else if (xmlHttp.status == 0)
			{
				//alert('Tidak bisa sambung ke server, silakan cek koneksi Anda.');
			}
			else if (xmlHttp.status == 404)
			{
				//alert('Error: URL '+url+' tidak ada.');
			}
		}
	}
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}

function postXMLDocument(url, contents, callback, id_loading)
{
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
 	{
		alert ("Your browser does not support AJAX!");
		return;
	}

	xmlHttp.onreadystatechange = function()
	{
		if (typeof(id_loading) != "undefined")
		{
			if (xmlHttp.readyState==1)
			{
				document.getElementById(id_loading).style.display = '';
			}
		}
		
		if (xmlHttp.readyState==4)
		{
			if (xmlHttp.status == 200)
			{
				if (typeof(id_loading) != "undefined")
				{
					document.getElementById(id_loading).style.display = 'none';
				}
				callback(xmlHttp.responseText);
			}
			else if (xmlHttp.status == 0)
			{
				//alert('Tidak bisa sambung ke server, silakan cek koneksi Anda.');
			}
			else if (xmlHttp.status == 404)
			{
				//alert('Error: URL '+url+' tidak ada.');
			}
		}
	}
	
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", contents.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(contents);

}

function loadingText(text, id_loading)
{
	var defText = text;
	
	if (text == defText)
	{
		text += '.';
	}
	else if (text == text+'.')
	{
		text += '..';
	}
	else if (text == text+'..')
	{
		text += '...';
	}
	else if (text == text+'...')
	{
		text.replace(/.../, '');
	}
	
	document.getElementById(id_loading).innerHTML = text;
	setTimeout(loadingText(text, id_loading), 100);
}


