var req = null;



function InitXMLHttpRequest() {

	// Make a new XMLHttp object

	if (window.XMLHttpRequest) {

		req = new XMLHttpRequest();

	} else if (window.ActiveXObject) {

		req = new ActiveXObject("Microsoft.XMLHTTP");

	}

}









function SelectCountry(section, destination) {

	InitXMLHttpRequest();

	// Load the result from the response page

	if (req) {

		req.onreadystatechange = function() {

			if (req.readyState == 4) {

				destination.innerHTML = req.responseText;

			} else {

				destination.innerHTML = "Loading data...";

			}

		}

		req.open("GET", "location2.php?sec=" + section + "&sel=country", true);

		req.send(null);

	} else {

		destination.innerHTML = 'Browser unable to create XMLHttp Object';

	}

}



function SelectRegion(section, id_country, destination, destination2, text, text2) {



	InitXMLHttpRequest();

	if (id_country != '') {

		if (req) {

			req.onreadystatechange = function() {

				if (req.readyState == 4) {

					destination.innerHTML = req.responseText;

				} else {

					

					if(section=='qsi') destination.innerHTML = "<select id='region' name='region' class=\"text\"><option>"+text+"</option></select>";

					else if(section=='qsa') destination.innerHTML = "<select id='region' name='region' class=\"text2\"><option>"+text+"</option></select>";

					 else if(section=='acc' || section=='ch_e_v') destination.innerHTML = "<select id='region' name='region' class=\"text_slim\"><option>"+text+"</option></select>";

					else destination.innerHTML = "<select id='region' name='region' style=\"width:150px;\"><option>"+text+"</option></select>";


				}

			}

			req.open("GET", "location2.php?sec=" + section + "&sel=region&id_country=" + id_country, true);

			req.send(null);

		} else {

			destination.innerHTML = 'Browser unable to create XMLHttp Object';

		}

	} else {

		req.open('GET', 'location2.php?sec=' + section + '&sel=region', false);

	    req.send(null);

    	destination.innerHTML = req.responseText;

	}

	

    if(section=='qsi') destination2.innerHTML = "<select id='city' name='city' class=\"text\"><option>"+text2+"</option></select>";

	 else if(section=='qsa') destination2.innerHTML = "<select id='city' name='city' class=\"text2\"><option>"+text2+"</option></select>";

	  else if(section=='acc' || section=='ch_e_v') destination2.innerHTML = "<select id='city' name='city' class=\"text_slim\"><option>"+text2+"</option></select>";

	else destination2.innerHTML = "<select id='city' name='city' style=\"width:150px;\"><option>"+text2+"</option></select>";

}



function SelectRegion2(section, id_country, destination, destination2, text, text2, destination3) {


	InitXMLHttpRequest();

	if (id_country != '') {

		if (req) {

			req.onreadystatechange = function() {

				if (req.readyState == 4) {

					destination.innerHTML = req.responseText;

				} else {

					destination.innerHTML = "<select id='region' style=\"width:150px;\"><option>"+text+"</option></select>";

				}

			}

			req.open("GET", "location2.php?sec=" + section + "&sel=region2&id_country=" + id_country, true);

			req.send(null);

		} else {

			destination.innerHTML = 'Browser unable to create XMLHttp Object';

		}

	} else {

		req.open('GET', 'location2.php?sec=' + section + '&sel=region', false);

	    req.send(null);

    	destination.innerHTML = req.responseText;

	}

    destination2.innerHTML = "<select id='city' style=\"width:150px;\"><option>"+text2+"</option></select>";

    if ((section == 'rnte') || (section == 'rmte')){

    	destination3.innerHTML = "";

    }

}





function SelectCity(section, id_region, destination, text){

	InitXMLHttpRequest();

    if (id_region != '') {

		// Load the result from the response page

	    if (req){

			req.onreadystatechange = function() {

				if (req.readyState == 4) {

					destination.innerHTML = req.responseText;

				} else {

					

					if(section=='qsi') destination.innerHTML = "<select id='city' class=\"text\"><option>"+text+"</option></select>";

					else if(section=='qsa') destination.innerHTML = "<select id='city' class=\"text2\"><option>"+text+"</option></select>";

					else if(section=='acc' || section=='ch_e_v')  destination.innerHTML = "<select id='city' class=\"text_slim\"><option>"+text+"</option></select>";

					else destination.innerHTML = "<select id='city' class=\"text_slim\"><option>"+text+"</option></select>";

				}

			}

	       req.open('GET', 'location2.php?sec=' + section + '&sel=city&id_region=' + id_region, true);

	       req.send(null);

	    }

	    else{

	       destination.innerHTML = 'Browser unable to create XMLHttp Object';

	    }

    }

    else {

    	req.open('GET', 'location2.php?sec=' + section + '&sel=city', false);

		req.send(null);

    	destination.innerHTML = req.responseText;

    }

}



function SelectCity2(section, id_region, destination, text, destination2){

	InitXMLHttpRequest();

    if (id_region != '') {

		// Load the result from the response page

	    if (req){

			req.onreadystatechange = function() {

				if (req.readyState == 4) {

					destination.innerHTML = req.responseText;

				} else {

					destination.innerHTML = "<select id='city' class=\"text_slim\"><option>"+text+"</option></select>";

				}

			}

	       req.open('GET', 'location2.php?sec=' + section + '&sel=city2&id_region=' + id_region, true);

	       req.send(null);

	    }

	    else{

	       destination.innerHTML = 'Browser unable to create XMLHttp Object';

	    }

    }

    else {

    	req.open('GET', 'location2.php?sec=' + section + '&sel=city2', false);

		req.send(null);

    	destination.innerHTML = req.responseText;

    }

    if ((section == 'rnte') || (section == 'rmte')){

    	destination2.innerHTML = "";

    }

}



function ShowSubways(section, city_id, destination, text, text2){

	if ((section == 'rnte') || (section == 'rmte')){

		if ((city_id=='3159_4312_4400') || (city_id=='3159_4925_4962')){

			InitXMLHttpRequest();

			if (req){

				req.onreadystatechange = function() {

					if (req.readyState == 4) {

						destination.innerHTML = req.responseText;

					} else {

						destination.innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" height=\"25\"><tr><td height=\"27\" width=\"100\">" + text2 + ":&nbsp;</td><td><select style=\"width:150px;\"><option>" + text +"</option></select></td></tr></table>";

					}

				}

		       req.open('GET', 'location2.php?sec=' + section + '&sel=subway&id_city=' + city_id, true);

		       req.send(null);

		    }

		    else{

		       destination.innerHTML = 'Browser unable to create XMLHttp Object';

		    }

		} else {

			destination.innerHTML = '';

		}

	} else {

		destination.innerHTML = '';

	}

}

function ViewDetails(id,destination){
	if(destination.style.display == "block"){
		destination.style.display = "none";
	} else {
		destination.style.display = "block";
		InitXMLHttpRequest();
		// Load the result from the response page
		// ** As far a I know firefox will only load a requment on the SAME domain!!
		if (req) {

			req.onreadystatechange = function() {

					if (req.readyState == 4)
					{
						destination.innerHTML = req.responseText;
					}
				}
			req.open("GET", "etraining_details.php?id=" + id, false);
		    	req.send(null);
		} else {
			destination.innerHTML = 'Browser unable to create XMLHttp Object';
		}
		destination.innerHTML = req.responseText;
	}
}
