function ajaxConnect(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

// used in top search bar
function getCities(val, language){
	var url = "/inc/scripts/getCities.php";
	var params = "head_country=" + val + "&language=" + language,

	ajax=ajaxConnect();
	ajax.open("POST", url, true);
	
	//Send the proper header information along with the request
	ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajax.setRequestHeader("Content-length", params.length);
	ajax.setRequestHeader("Connection", "close");
	
	ajax.onreadystatechange = function() {//Call a function when the state changes.
		if (ajax.readyState==4 && ajax.status == 200) {

			if(language == "en")
			{
				var select_city = "Select City";
				var select_subject = "Select Subject";
			}
			else
			{
				var select_city = "Selecciona ciudad";
				var select_subject = "Selecciona Programa";
			}

			var msgSplit = ajax.responseText; 
			
			var obj = document.getElementById('head_city');
			obj.options.length = 0;
			obj.options[obj.options.length] = new Option(select_city,'');
			eval(msgSplit);	// Executing the response from Ajax as Javascript code	
			
			var obj_sub = document.getElementById('head_subj');
			obj_sub.options.length = 0;
			obj_sub.options[obj_sub.options.length] = new Option(select_subject,'');

	 	}
	}
	ajax.send(params);
}

// used in search_schools_abroad.php
function getCities2(val, language){
	var url = "/inc/scripts/getCities.php";
	var params = "head_country=" + val + "&language=" + language,

	ajax=ajaxConnect();
	ajax.open("POST", url, true);
	
	//Send the proper header information along with the request
	ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajax.setRequestHeader("Content-length", params.length);
	ajax.setRequestHeader("Connection", "close");
	
	ajax.onreadystatechange = function() {//Call a function when the state changes.
		if (ajax.readyState==4 && ajax.status == 200) {

			if(language == "en")
			{
				var all_cities = "All Cities";
			}
			else
			{
				var all_cities = "Todas las ciudades";
			}

			var msgSplit = ajax.responseText; 
			
			var obj = document.getElementById('city2');
			obj.options.length = 0;
			obj.options[obj.options.length] = new Option(all_cities,'');
			eval(msgSplit);	// Executing the response from Ajax as Javascript code	
			
	 	}
	}
	ajax.send(params);
}

// used in list_your_school.php, register.php
function getRegion(val, language, selectID){
	var url = "/inc/scripts/getRegion.php";
	var params = "country=" + val + "&language=" + language,

	ajax=ajaxConnect();
	ajax.open("POST", url, true);
	
	//Send the proper header information along with the request
	ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajax.setRequestHeader("Content-length", params.length);
	ajax.setRequestHeader("Connection", "close");
	
	ajax.onreadystatechange = function() {//Call a function when the state changes.
		if (ajax.readyState==4 && ajax.status == 200) {

			var msgSplit = ajax.responseText; 
			
			var obj = document.getElementById(selectID);
			obj.options.length = 0;
			eval(msgSplit);	// Executing the response from Ajax as Javascript code	
			
	 	}
	}
	ajax.send(params);
}

// used in top search bar
function getSubjs(val, language){
	var url = "/inc/scripts/getSubjects.php";
	var params = "head_country=" + document.getElementById('head_country').value + "&head_city=" + val + "&language=" + language,

	ajax=ajaxConnect();
	ajax.open("POST", url, true);
	
	//Send the proper header information along with the request
	ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ajax.setRequestHeader("Content-length", params.length);
	ajax.setRequestHeader("Connection", "close");

	ajax.onreadystatechange = function() {//Call a function when the state changes.
		if (ajax.readyState==4 && ajax.status == 200) {

			if(language == "en")
			{
				var select_subject = "Select Subject";
			}
			else
			{
				var select_subject = "Selecciona Programa";
			}

			var msgSplit = ajax.responseText; 
			
			var obj = document.getElementById('head_subj');
			obj.options.length = 0;
			obj.options[obj.options.length] = new Option(select_subject,'');
			eval(msgSplit);	// Executing the response from Ajax as Javascript code	
	 	}
	}
	ajax.send(params);
}