var url="loader.php";
//Create http object
function ajaxCreateHTTP(){
	try{
		xmlhttp	= window.XMLHttpRequest ? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e){
		//Browser doesn't support ajax
		xmlhttp	= false;
	}
	return xmlhttp;
}
function SendQuery(request,method,callbackFunction)
{
	// Init Object
	req = ajaxCreateHTTP();
	
	if ( (req!=null) )
	{		
		req.onreadystatechange = function()
								{
								// only if req shows "complete"
									if (req.readyState == 4)
								    {
							        // only if "OK"
										if (req.status == 200)
										{
											// Process
											eval(callbackFunction);
										}
									}
								};
		
		request += "&rand="+Math.random()*100;
		
		// Use POST or GET method , default is GET
					
		req.open("GET",url+"?"+request, true);
		req.send(null);
	}
}
/*===================================*/
//Load url and get content
function ajaxLoadURL(the_url, the_method, post_vars, div_output, waiting_type, output_type){
	//Create http object
	var xmlhttp	= ajaxCreateHTTP();
	if ( !xmlhttp ){
		return false;
	}

	//Handle status changes
	xmlhttp.onreadystatechange	= function(){
		ajaxHandleResponse(div_output, waiting_type, output_type);
	}

	//Prevent caching
	the_date	= new Date();
	randCode	= the_date.getTime() +"_"+ (Math.round(Math.random() * 100));
	the_url		+= (the_url.indexOf('?') != -1) ? '&ajaxRand='+ randCode : '?ajaxRand='+ randCode;

	//Open takes in the HTTP method and url.
	xmlhttp.open(the_method, the_url);

	//Send the request.
	//If this is a POST request we would have sent post variables: send("name=aleem&gender=male)
	//Moz is fine with just send(); but IE expects a value here, hence we do send(null);
	if ( the_method == 'POST' ){
		xmlhttp.send(post_vars);
	}
	else{
		xmlhttp.send(null);
	}
	return true;
}

function ajaxHandleResponse(div_output, waiting_type, output_type){
	//If the readyState code is 4 (Completed) and http status is 200 (OK) we go ahead and get the responseText
	if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)){
		if (output_type == 1){
			//Call js function
			if (xmlhttp.responseText != ""){
				eval(xmlhttp.responseText);
			}
		}
		else{
			//Display result
			if ( div_output != "" ){
				document.getElementById(div_output).innerHTML	= xmlhttp.responseText;
			}
		}
	}
	else{
		switch (waiting_type){
			case 1:
					//Display waiting text in div_output
					document.getElementById(div_output).innerHTML	= "Loading.....";
					break;
			case 2:
					//Display waiting text at the right top of page
					break;
			default:
					//Not display waiting screen
		}
	}
}
//===================================================
function ProcessCatagory()
	{
		var c=req.responseXML.getElementsByTagName('category').length;			
		var Opts = new Array();
		Opts[i] 	  = new Option;
		Opts[i].value = '';
		Opts[i].text  = '--Select--';
		document.getElementById('sub_cat').length=0;	
		if(c>0)
		{
			var id,name;
			Opts = new Array();
			
			for(var i=0; i<c; i++)	
			{
				with(req.responseXML.getElementsByTagName('category').item(i))
				{
					Opts[i] 	  = new Option;
					Opts[i].value = req.responseXML.getElementsByTagName('id')[i].firstChild.data;//getAttribute('id');
					Opts[i].text  = req.responseXML.getElementsByTagName('fname')[i].firstChild.data;//getAttribute('fname');
				}
			}
			
			for(i=0;i<Opts.length;i++)
			{
				document.getElementById('sub_cat').options[i] = Opts[i];
			}
		}else{
			Opts[i].value = '0';
			Opts[i].text  = 'Not available';
		}
		//zone_level = 1;		
	}
	
	function LoadCategory(value)
	{
		//if(new_level>1)zone_level = new_level;
		
		if(value!=0)
		{
			request = "mod=services&act=psub&pid="+value;		
			SendQuery(request,'GET',"ProcessCatagory()",1);
		}
	}		
	
//===================================================
function ProcessType()
	{
		var c=req.responseXML.getElementsByTagName('category').length;			

		var Opts = new Array();
		Opts[i] 	  = new Option;
		Opts[i].value = '';
		Opts[i].text  = '--Select--';
		document.getElementById('type_id').length=0;
		if(c>0)
		{
			var id,name;
			Opts = new Array();
			
			for(var i=0; i<c; i++)	
			{
				with(req.responseXML.getElementsByTagName('category').item(i))
				{
					Opts[i] 	  = new Option;
					Opts[i].value = req.responseXML.getElementsByTagName('id')[i].firstChild.data;//getAttribute('id');
					Opts[i].text  = req.responseXML.getElementsByTagName('fname')[i].firstChild.data;//getAttribute('fname');
					if(old_type)if(Opts[i].value==old_type)Opts[i].selected = true;
				}
			}		
			
		}else{
			var Opts = new Array();
			Opts[0] 	  = new Option;	
			Opts[0].value = '0';
			Opts[0].text  = 'Not available';
		}
		for(i=0;i<Opts.length;i++)
			{
				document.getElementById('type_id').options[i] = Opts[i];
			}
		//zone_level = 1;		
	}
	
	function LoadType(value)
	{
		//if(new_level>1)zone_level = new_level;
		
		
			request = "mod=services&act=type&pid="+value;		
			SendQuery(request,'GET',"ProcessType()",1);
		
	}		