
function showLocationOptions(country_id) {
	var out = '<table>';
	if (country_id == 1 || country_id == 226 || country_id == 227) {
		out += '<tr valign=top><td class=form_table_right>ZIP:</td><td class=form_table_left><input type=text SIZE=6 MAXLENGTH=12 name=zip id=zip class=form_table  onChange="getCityState(window.document.joinForm.zip.value);"></td></tr>';
		out += '<tr valign=top><td class=form_table_right>City:</td><td class=form_table_left><span ID=city></span></td></tr>';
		out += '<tr valign=top><td class=form_table_right>State:</td><td class=form_table_left><span ID=state></span></td></tr>';
		out += '<INPUT TYPE="hidden" NAME="city" VALUE=""><INPUT TYPE="hidden" NAME="state" VALUE=""><INPUT TYPE="hidden" NAME="lat" VALUE=""><INPUT TYPE="hidden" NAME="lon" VALUE="">';
	} else if (country_id == 39) {
		out += '<tr valign=top><td class=form_table_right>City</td><td class=form_table_left><input type=text SIZE=15 MAXLENGTH=36 name=city ID=city class=form_table></td></tr>';
		out += '<tr valign=top><td class=form_table_right>Province</td><td class=form_table_left><input type=text SIZE=2 MAXLENGTH=2 name=state ID=state class=form_table></td></tr>';
	} else {
		out += '<tr valign=top><td class=form_table_right>City</td><td class=form_table_left><input type=text SIZE=15 MAXLENGTH=36 name=city ID=city class=form_table></td></tr>';
	}
	out += '</table>';
	document.getElementById("locationOptions").innerHTML = out;
}

function dateDropdown(month,day) {
	var days = 31;
	if (month == 2) {
		days = 29;
	} else if (month == 4 || month == 6 || month == 9 || month == 11) {
		days = 30;
	}
	var out = '<select name="birth_date" class="profile_dropdown"><option value="">Day';
	for (a = 1; a <= days; a++) {
		out += '<option value='+a+''
		if (a == day) { out +=' SELECTED'; }
		out += '>'+a+'';
	}
	out += '</select>';
	document.getElementById('dateDropdown').innerHTML = out;
}

function getCityState(zip) {
	if (zip) {
		var poststr ='zip='+zip ;
		window.document.joinForm.zip.value = zip;
		makeZipRequest('/includes/zipcode.php', poststr);
	}
}

function makeZipRequest(url, parameters) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
      
	http_request.onreadystatechange = zipContents;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function zipContents() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			//alert(http_request.responseText);
			result = http_request.responseText;
			var parts = result.split('|');
			document.getElementById('city').innerHTML = parts[0];
			document.getElementById('state').innerHTML = parts[1];
			window.document.joinForm.city.value = parts[0];
			window.document.joinForm.state.value = parts[1];
			window.document.joinForm.lat.value = parts[2];
			window.document.joinForm.lon.value = parts[3];
		} else {
			alert('There was a problem with the request.');
		}
	}
}

