<!--
// Get the HTTP Object
function getHTTPObject(){
	if (window.ActiveXObject) 
		return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest) return new XMLHttpRequest();
	else {
	alert("Your browser does not support AJAX.");
	return null;
	}
}
 
// Change the value of the outputText field
function setCountries(){
	if(httpObject.readyState == 4){
		var combo = document.getElementById('country_id');
		combo.options.length = 0;
		var response = httpObject.responseText;
		var items = response.split(";");
		var count = items.length;
		for (var i=0;i<count;i++){
			var options = items[i].split("-");
			combo.options[i] =
			new Option(options[0],options[1]);
		}
		combo.style.display='inline';
		document.getElementById('city_id').style.display='none';
	}
}
 
function setCities(){
	if(httpObject.readyState == 4){
		var combo = document.getElementById('city_id');
		combo.options.length = 0;
		var response = httpObject.responseText;
		var items = response.split(";");
		var count = items.length;
		for (var i=0;i<count;i++){
			var options = items[i].split("-");
			combo.options[i] =
			new Option(options[0],options[1]);
		}
		combo.style.display='inline';
	}
}

function setStates(){
	if(httpObject.readyState == 4){
		var combo = document.getElementById('state_id');
		combo.options.length = 0;
		var response = httpObject.responseText;
		var items = response.split(";");
		var count = items.length;
		for (var i=0;i<count;i++){
			var options = items[i].split("-");
			combo.options[i] =
			new Option(options[0],options[1]);
		}
		combo.style.display='inline';
	}
}

function getCountries(){
	httpObject = getHTTPObject();
	if (httpObject != null) {
		httpObject.open("GET", "ajax/getCountries.php?continent_id=" +document.getElementById('continent_id').value, true);
		httpObject.onreadystatechange = setCountries;
		httpObject.send(null);
	}
	document.getElementById('country_id').className="select_option";
}

function getCities(){
	//if US, then get the states
	if (document.getElementById('country_id').value=='175') {
		httpObject = getHTTPObject();
		if (httpObject != null) {
			httpObject.open("GET", "ajax/getStates.php?country_id=" + document.getElementById('country_id').value, true);
			httpObject.onreadystatechange = setStates;
			httpObject.send(null);
		}
		document.getElementById('state_id').className="select_option";		
	} else {
		httpObject = getHTTPObject();
		if (httpObject != null) {
			httpObject.open("GET", "ajax/getCities.php?country_id=" + document.getElementById('country_id').value, true);
			httpObject.onreadystatechange = setCities;
			httpObject.send(null);
		}
		document.getElementById('city_id').className="select_option";
	}
}

function getCitiesByState(){
	httpObject = getHTTPObject();
	if (httpObject != null) {
		httpObject.open("GET", "ajax/getCitiesByState.php?state_id=" +document.getElementById('state_id').value, true);
		httpObject.onreadystatechange = setCities;
		httpObject.send(null);
	}
	document.getElementById('city_id').className="select_option";	
}

function hideStateCity(){
	document.getElementById('state_id').style.display='none';
	document.getElementById('city_id').style.display='none';	
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Purpose: Functions to gather the best time to go from the database up to the homepage
// 			Loads a div named bttg with results from the AJAX pull
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getBTTG(type){
	httpObject2 = getHTTPObject();
	if (httpObject2 != null) {
		httpObject2.open("GET", "ajax/getBTTG.php?" + type + "=" +document.getElementById(type).value, true);
		httpObject2.onreadystatechange = displayBTTG;
		httpObject2.send(null);
	}
}

function getBTTGbyMonths(){
	httpObject2 = getHTTPObject();
	if (httpObject2 != null) {
		httpObject2.open("GET", "ajax/getBTTGbyMonths.php?month_id=" +document.getElementById('month_id').value, true);
		httpObject2.onreadystatechange = displayBTTG;
		httpObject2.send(null);
	}
}

function displayBTTG() { 
	if(httpObject2.readyState == 4){
		var BTTG = document.getElementById('BTTG');	
		var response = httpObject2.responseText;
		BTTG.innerHTML = response;
		BTTG.style.display='inline';
	}
}


function gotoCity(){
	window.location = "http://www.besttimetogo.com/view.php?city_id=" + document.getElementById('city_id').value;
}

var httpObject = null;
//-->