// Creates & returns an ajax object
function newAjaxObject()
{
	var xmlhttp = null;
	
	try
	{
		// Mozilla, Opera, Safari, Konqueror and everything else uses this method
		xmlhttp = new XMLHttpRequest();
	}
	catch(e)
	{
		try
		{
			// IE lower than 6 implements Msxml lib (only 5.xx versions,
			// versions below 5.0 does not support asynchronous queries
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				// For IE 6 and later
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e)
			{
				// No asynchronous support provided by this browser...
				alert("Your browser doesn't support Ajax Requests\n\nTherefore, certain features may not be available to you.")
			}
		}
	}
	return xmlhttp;
}

// Init some new ajax objects
var ajax = newAjaxObject(); // this is globally used
var ajaxBusy = false;

// Makes a query using the ajax object ajaxObj to the page serverPage
// using GET or POST (sendMethod) and puts the response into the div with the id divID
// If the POST method is prefered, the params to be sent must be given as a string of this form:
// field1=value1&field2=value2&field3=value3 (etc.)
function makequery( ajaxObj, serverPage, divID, sendMethod, params )
{
	// Get the container's handler
	var div = document.getElementById( divID );
	
	if( ajaxBusy )
	{
		ajaxObj.onreadystatechange = function() {}
		ajaxObj.abort();
	}
	
	if( ajaxObj )
	{
		if( sendMethod == "GET" )
		{
			ajaxObj.open( "GET", serverPage, true );
			ajaxBusy = true;
			ajaxObj.onreadystatechange = function()
			{
				if( ajaxObj.readyState == 4 && ajaxObj.status == 200 )
				{
					div.innerHTML = ajaxObj.responseText;
				}
				ajaxBusy = false;
			}
			ajax.send( null );
		}
		else if( sendMethod == "POST" )
		{
			ajaxObj.open( "POST", serverPage, true );
			ajaxBusy = true;
			ajaxObj.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" );
			ajaxObj.onreadystatechange = function()
			{
				if( ajaxObj.readyState == 4 && ajaxObj.status == 200 )
				{
					div.innerHTML = ajaxObj.responseText;
				}
				ajaxBusy = false;
			}
			ajaxObj.send( params );
		}
		else
		{
			// No other valid known methods for passing the data...
			alert( "Invalid or no method passed to the function!" );
			return;
		}
	}
}

function updateServicii( obj )
{
	obiect('sLoading').style.display = 'block';
	var selected = obj.options[obj.selectedIndex].value;
	for (o=3;o<=9;o++) 
	{
		if (obiect('o'+o)) obiect('o'+o).style.display = 'none';
	}
	if (obiect('o'+selected)) obiect('o'+selected).style.display = 'block';
	makequery( ajax, mainWebsiteURL+'pages/servicii.php?s=' + selected, 'servicii', "GET" );
}
