	function clear(box){
		//box = document.getElementById(c);
		len = box.length;
		for (n = 0; n <= (len - 1); n++){
			box.remove(0);
		}
		try {
			box.add(new Option("Please select an option", "0"), null);
		}catch(ex) {
			box.add(new Option("Please select an option", "0"));
		}
	}

	function createRequestObject() {
		var req; 
		if(window.XMLHttpRequest){ 
			// Firefox, Safari, Opera... 
			req = new XMLHttpRequest(); 
		} else if(window.ActiveXObject) { 
			// Internet Explorer 5+ 
			req = new ActiveXObject("Microsoft.XMLHTTP"); 
		} else { 
			// There is an error creating the object, 
			// just as an old browser is being used. 
			alert('Problem creating the XMLHttpRequest object'); 
		}
		return req; 
	} 

	// Make the XMLHttpRequest object 
	var http = createRequestObject(); 

	//Do over AJAX	
	function subcats(sub) { 
		clear(document.getElementById('subcat'));
		req = 'cat=' + sub;
		// Open PHP script for requests 
		http.open('get', 'suggest.php?'+req); 
		http.onreadystatechange =HandleResponseSubcat; 
		http.send(null); 
	} 
	function HandleResponseSubcat() { 
		testbox = document.getElementById('subcat');
		if(http.readyState == 4 && http.status == 200){ 
			// Text returned FROM the PHP script 
			var response = http.responseText; 
			if(response) { 
				newtestsarray = response.split(":");
				len = newtestsarray.length - 2;
				//alert(len);
				for (n = 0; n <= len; n += 2){
					if (n >= 0){
						try {
							testbox.add(new Option(newtestsarray[n + 1], newtestsarray[n]), null);
						}catch(ex) {
							testbox.add(new Option(newtestsarray[n + 1], newtestsarray[n]));
						}
					}
				}

			} 
		} 
	} 
	function cities(sub) { 
		clear(document.getElementById('city'));
		req = 'city=' + sub;
		// Open PHP script for requests 
		http.open('get', 'suggest.php?'+req); 
		http.onreadystatechange =HandleResponseCities; 
		http.send(null); 
	} 
	function HandleResponseCities() { 
		testbox = document.getElementById('city');
		if(http.readyState == 4 && http.status == 200){ 
			// Text returned FROM the PHP script 
			var response = http.responseText; 
			if(response) { 
				newtestsarray = response.split(":");
				len = newtestsarray.length - 2;
				//alert(len);
				for (n = 0; n <= len; n += 2){
					if (n >= 0){
						//alert(n);
						//alert(test[newtestsarray[n]]);
						try {
							testbox.add(new Option(newtestsarray[n + 1], newtestsarray[n]), null);
						}catch(ex) {
							testbox.add(new Option(newtestsarray[n + 1], newtestsarray[n]));
						}
					}
				}

			} 
		} 
	} 
