/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

/* Function called to get the product categories list */
function getState(country_id){
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	http.open('get', 'intermediate.php?mode=state&country_id='+country_id);
	/* Define a function to call once a response has been received. This will be our
		handleProduct function that we define below. */
	http.onreadystatechange = handleProducts; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleProducts(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		
		document.getElementById('divloc').innerHTML = response;
		//document.getElementById('div1').innerHTML = response;

	}
}

/* Function called to get the product categories list */
function getJobs(catid,subid)
{	
	http.open('get', 'intermediate.php?mode=province&country_id=' + catid + '&subcatid=' + subid);
	http.onreadystatechange = handleProducts; 
	http.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleProducts()
{
	if(http.readyState == 4)
	{ 
		var response = http.responseText;
		document.getElementById('divcat').innerHTML = response;
	}
}

function getcity(proid,subid)
{
	
	http.open('get', 'intermediate.php?province_id=' + proid );
	http.onreadystatechange = handlecity; 
	http.send(null);
}
function handlecity()
{
	/*if(http.readyState != 4) 
	{
		document.getElementById('divcat1').innerHTML = "Loading...";
	}*/
	if(http.readyState == 4)
	{ 
		var response = http.responseText;
		document.getElementById('divcat1').innerHTML = '';
		var s2 = new SWFObject("flvplayer.swf","playlist","240","205","7");
		s2.addParam("allowfullscreen","true");
		s2.addVariable("backcolor","0x000000");
		s2.addVariable("frontcolor","0xCCCCCC");
		s2.addVariable("lightcolor","0xFF0000");
		s2.write("divcat1");
	}
}

function getarea(cityid,subid)
{
	
	http.open('get', 'intermediate.php?mode=area&city_id=' + cityid + '&subcatid=' + subid);
	http.onreadystatechange = handlearea; 
	http.send(null);
}
function handlearea()
{
	
	if(http.readyState == 4)
	{ 
		var response = http.responseText;
			
		document.getElementById('divcat2').innerHTML = '';
		var s2 = new SWFObject("flvplayer.swf","playlist","450","370","7");

		s2.addParam("allowfullscreen","true");
		s2.addVariable("file","images/BMW2.flv");
		s2.addVariable("backcolor","0x000000");
		s2.addVariable("frontcolor","0xCCCCCC");
		s2.addVariable("lightcolor","0xFF0000");
		s2.write("player2");
	}
}
