function init_locations_list ( ) {
	var temp_obj = document.getElementById( 'countries_select' );
	var temp_size = countries_options.length;
	var parentnode_outerhtml = temp_obj.parentNode.innerHTML;
	var parentnode_outerhtml_end = parentnode_outerhtml.substring ( (parentnode_outerhtml.indexOf ( '>' )+1),parentnode_outerhtml.length );
	parentnode_outerhtml = parentnode_outerhtml.substring ( 0, parentnode_outerhtml.indexOf ( '>' )+1 );
	var temp_insertion_string = parentnode_outerhtml;
	for ( var temp_i=0; temp_i<temp_size; temp_i++ ) {
		temp_insertion_string += "<option value=\"" + countries_options[temp_i]['id'].toString() + "\" >"+ countries_options[temp_i]['value'].toString() + "</option>";
	}
	temp_insertion_string += parentnode_outerhtml_end;
	var par_node = temp_obj.parentNode;
	par_node.innerHTML = temp_insertion_string;
	return true;
}

function populate_regions ( param_obj ) {
	var selectedItem = param_obj.options[param_obj.selectedIndex].value;
	if ( selectedItem < 1 ) {
		return false;
	}
	var temp_obj = document.getElementById ( 'regions_select' );
	temp_obj.innerHTML = "";
	var temp_size = regions_options.length;
	var parentnode_outerhtml = temp_obj.parentNode.innerHTML;
	var parentnode_outerhtml_end = parentnode_outerhtml.substring ( (parentnode_outerhtml.indexOf ( '>' )+1), parentnode_outerhtml.length );
	parentnode_outerhtml = parentnode_outerhtml.substring ( 0, parentnode_outerhtml.indexOf ( '>' )+1 );
	var temp_insertion_string = parentnode_outerhtml;
	for ( var temp_i=0; temp_i<temp_size; temp_i++ ) {
		if ( regions_options[temp_i]['pnode'] == selectedItem ) {
			temp_insertion_string += "<option value=\"" + regions_options[temp_i]['id'].toString() + "\" >" + regions_options[temp_i]['value'].toString() + "</option>";
		}
	}
	temp_insertion_string += parentnode_outerhtml_end;
	var par_node = temp_obj.parentNode;
	par_node.innerHTML = temp_insertion_string;
	var temp_obj = document.getElementById ( 'areas_select' );
	temp_obj.innerHTML = "";
	var temp_obj = document.getElementById ( 'text_location_region' );
	if ( temp_obj && temp_obj != null ) {
		temp_obj.innerHTML = "Click here if you wish to refine your search";
	}
	var temp_obj = document.getElementById ( 'text_location_area' );
	if ( temp_obj && temp_obj != null ) {
		temp_obj.innerHTML = "";
	}
	if ( false === turn_on_button ) {
		turn_on_button = true;
		var temp_obj = document.getElementById ( 'add_loc_button' );
		if ( temp_obj && temp_obj != null ) {
			temp_obj.src = "/images/add_loc.jpg";
		}
	}
	return true;
}

function populate_areas ( param_obj ) {
	var selectedItem = param_obj.options[param_obj.selectedIndex].value;
	if ( selectedItem < 1 ) {
		return false;
	}
	var temp_obj = document.getElementById('areas_select');
	temp_obj.innerHTML = "";
	var temp_size = area_options.length;
	var parentnode_outerhtml = temp_obj.parentNode.innerHTML;
	var parentnode_outerhtml_end = parentnode_outerhtml.substring ( (parentnode_outerhtml.indexOf ( '>' )+1), parentnode_outerhtml.length );
	parentnode_outerhtml = parentnode_outerhtml.substring ( 0, parentnode_outerhtml.indexOf ( '>' )+1 );
	var temp_insertion_string = parentnode_outerhtml;
	for ( var temp_i=0; temp_i<temp_size; temp_i++ ) {
		if ( area_options[temp_i]['pnode'] == selectedItem ) {
			temp_insertion_string += "<option value=\"" + area_options[temp_i]['id'].toString() + "\">" + area_options[temp_i]['value'].toString() + "</option>";
		}
	}
	temp_insertion_string += parentnode_outerhtml_end;
	var par_node = temp_obj.parentNode;
	par_node.innerHTML = temp_insertion_string;
	var temp_obj = document.getElementById ( 'text_location_area' );
	if ( temp_obj && temp_obj != null ) {
	        temp_obj.innerHTML = "Click here if you wish to refine your search further";
	}
}


function add_location_to_submitResults ( ) {
	if ( false !== turn_on_button ) {
		// variables
		var temp_obj = document.getElementById('countries_select');
		var temp_outputText = "";
		var temp_outputValue = 0;
		var temp_outputType = "";
		var temp_outputResult = "";
		//
		temp_outputText += temp_obj.options[temp_obj.selectedIndex].text;
		temp_outputValue = temp_obj.options[temp_obj.selectedIndex].value;
		temp_outputType = "country";
		temp_obj = document.getElementById('regions_select');
		if ( temp_obj.selectedIndex >= 0 ) {
			temp_outputText += " >> " + temp_obj.options[temp_obj.selectedIndex].text;
			temp_outputValue = temp_obj.options[temp_obj.selectedIndex].value;
			temp_outputType = "region";
			temp_obj = document.getElementById('areas_select');
			if ( temp_obj.selectedIndex >= 0 ) {
				temp_outputText += " >> " + temp_obj.options[temp_obj.selectedIndex].text;
				temp_outputValue = temp_obj.options[temp_obj.selectedIndex].value;
				temp_outputType = "area";
			}
		}
		//
		temp_outputResult += "<span id=\"submitLocation-" + temp_outputValue.toString() + "-" + temp_outputType + "\" style=\"float: left; clear: both;\">\n";
		temp_outputResult +=    temp_outputText;
		temp_outputResult +=    "&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#\" onclick=\"return remove_location_from_submitResults ( '" + temp_outputValue.toString() + "', '" + temp_outputType + "' );\">[x]</a>\n";
		temp_outputResult +=    "<input type=\"hidden\" name=\"locations[]\" value=\"" + temp_outputValue.toString() + "-" + temp_outputType + "\" >\n";
		temp_outputResult += "</span>";
		temp_obj = document.getElementById('locations_to_submit_textVersion');
		temp_obj.innerHTML += temp_outputResult;
	}
	return false;
}

function remove_location_from_submitResults ( param_value, param_type ) {
	var parentNode = document.getElementById ( 'locations_to_submit_textVersion' );
	var childNode = document.getElementById ( 'submitLocation-' +  param_value.toString() + "-" + param_type );
	parentNode.removeChild ( childNode );
	return false;
}
