	function toggleLayer(whichLayer)
{

var theInput = document.search.elements[whichLayer];

if (document.getElementById)
{
// this is the way the standards work
var style2 = document.getElementById(whichLayer).style;
if (style2.display == "block"){
style2.display = "none";
theInput.value = 0;
}
else {
		 style2.display ="block";
		 theInput.value = 1;
}
}
else if (document.all)
{
// this is the way old msie versions work
var style2 = document.all[whichLayer].style;
if (style2.display == "block"){
style2.display = "none";
theInput.value = 0;
}
else {
		 style2.display ="block";
		 theInput.value = 1;
}
}
else if (document.layers)
{
// this is the way nn4 works
var style2 = document.layers[whichLayer].style;
if (style2.display == "block"){
style2.display = "none";
theInput.value = 0;
}
else {
		 style2.display ="block";
		 theInput.value = 1;
}
}
}

function setHiddenVals(){
		var layerArray = new Array("interests", "education", "lifestyle", "career", "current_studies");
		var tot = layerArray.length;
		var whichLayer = null;
		var theInput = null;
		for (i = 0; i < tot; i++){
		   whichLayer = layerArray[i];
			 theInput = document.search.elements[whichLayer];
			 if (document.getElementById){
// this is the way the standards work
	 				 if (document.getElementById(whichLayer) != null){
					   if (document.getElementById(whichLayer).style.display == "block"){
						 		theInput.value = 1;
						 }
						 else {
		 				   theInput.value = 0;
						 }
					}
				}
			 else if (document.all){
// this is the way old msie versions work
	 			if (document.all[whichLayer] != null){
				   if (document.all[whichLayer].style.display == "block"){
					   theInput.value = 1;
					}
					else {
							 theInput.value = 0;
					}
				}
			}
			else if (document.layers){
// this is the way nn4 works
	 			if( document.layers[whichLayer] != null){
						if (document.layers[whichLayer].style.display == "block"){
							 theInput.value = 1;
				}
				else {
		 				 theInput.value = 0;
				}
			}
		 }
		}//for
}//function

function setGroupVal(){
		if (document.search.groups == 0){
			 document.search.groups.value =1;
			 }
	 else {
	 			document.search.groups.value = 0;
				}
}
function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}
var editing = false;
var http = createRequestObject(); 

var currentCity;

function getCitiesFromState(state_ab, currCity){
	var country = '';

if (document.getElementById('country') == null){
	country = 'USA';
}
else {
	country = document.getElementById('country').value;
}

if (country == 'USA' || country == ''){
currentCity = currCity;
		http.open('get', 'index.php?page_id=101&tbl=9&trm='+ state_ab);

		
			http.onreadystatechange = handleCityStateData; 
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	http.send(null);
}
}
function Trim(inString) {
  var retVal = "";
  var start = 0;
  while ((start < inString.length) && (inString.charAt(start) == ' ')) {
    ++start;
  }
  var end = inString.length;
  while ((end > 0) && (inString.charAt(end - 1) == ' ')) {
    --end;
  }
  retVal = inString.substring(start, end);
  return retVal;
}


/* Function called to handle the list that was returned from the internal_request.php file.. */
function handleCityStateData(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
//			alert ("currcity is "+currentCity);
	var xmlDoc = http.responseXML.documentElement;
	var results = xmlDoc.getElementsByTagName('result');
	var citySel = document.getElementById(currentCity);
  for (i = 0; i < results.length; i++) {
			var cityNode = results[i].getElementsByTagName('city')[0];
			var cityText = cityNode.firstChild.data;
			citySel.options[i+1] = new Option(cityText, cityText);
			}
	 citySel.disabled = false;
	 if (editing){
	 		citySel.options[i] = new Option('{/literal}{$group.city_loc}', '{$group.city_loc}', true, true);{literal}
					editing = false;

		}
	var country = document.getElementById('country');
	country.options[1].selected = true;
	}
}

function makeStringFromSelect(selectCtrl) {
	var i;
	var j = 0;
	var outlist = "";

	for (i = 0; i < selectCtrl.options.length; i++) {
		if (j > 0) {
			outlist = outlist + ", ";
		}

		outlist = outlist + selectCtrl.options[i].value;
		j++;
	}
	return outlist;
}

function addItems(fromCtrl, toCtrl) {
	var i;
	var j;
	var itemexists;
	var nextitem;

	// step through all items in fromCtrl
	for (i = 0; i < fromCtrl.options.length; i++) {
		if (fromCtrl.options[i].selected) {
			// search toCtrl to see if duplicate
			j = 0;
			itemexists = false;
			while ((j < toCtrl.options.length) && (!(itemexists))) {
				if (toCtrl.options[j].value == fromCtrl.options[i].value) {
					itemexists = true;
					alert(fromCtrl.options[i].value + " found!");
				}
				j++;
			}
			if (!(itemexists)) {
				// add the item
				nextitem = toCtrl.options.length;
				toCtrl.options[nextitem] = new Option(fromCtrl.options[i].text);
				toCtrl.options[nextitem].value = fromCtrl.options[i].value;
			}
		}
	}
}

function removeItems(fromCtrl) {
	var i = 0;
	var j;
	var k = 0;

	while (i < (fromCtrl.options.length - k)) {
		if (fromCtrl.options[i].selected) {
			// remove the item
			for (j = i; j < (fromCtrl.options.length - 1); j++) {
				fromCtrl.options[j].text = fromCtrl.options[j+1].text;
				fromCtrl.options[j].value = fromCtrl.options[j+1].value;
				fromCtrl.options[j].selected = fromCtrl.options[j+1].selected;
			}
			k++;
		} else {
			i++;
		}
	}
	for (i = 0; i < k; i++) {
		fromCtrl.options[fromCtrl.options.length - 1] = null;
	}
}

var old_city;
var old_state;

function modifyCityState(state_id, city_id, country_id, zip_code_id, zip_code_dist_id){
	country = document.getElementById(country_id).value;
	if (country != "USA" && country != ""){
		document.getElementById(state_id).style.display = 'none';
		document.getElementById(city_id).style.display = 'none';
		if (zip_code_dist_id != '' && zip_code_id != ''){			
			document.getElementById(zip_code_dist_id).disabled = true;
			document.getElementById(zip_code_dist_id).options[0].selected = true;
			document.getElementById(zip_code_id).value = "";
			document.getElementById(zip_code_id).disabled = true;
		}
		document.getElementById(city_id+2).style.display = 'block';
		document.getElementById(state_id+2).style.display = 'block';
		if (old_city != null){
			document.getElementById(city_id+2).value = old_city;
			document.getElementById(state_id+2).value = old_state;
		}
		old_city = document.getElementById(city_id).value;
		old_state = document.getElementById(state_id).value;
		document.getElementById(state_id).value = "";
		document.getElementById(city_id).value = "";
		document.getElementById(state_id+"_lbl").innerHTML = "State/Province:";
	}
	else {
		document.getElementById(state_id+2).style.display = 'none';
		document.getElementById(city_id+2).style.display = 'none';
		document.getElementById(city_id).style.display = 'block';
		document.getElementById(state_id).style.display = 'block';
		if (zip_code_dist_id != '' && zip_code_id != ''){	
			document.getElementById(zip_code_dist_id).disabled = false;
			document.getElementById(zip_code_id).disabled = false;
		}
		if (old_city != null){
			document.getElementById(city_id).value = old_city;
			document.getElementById(state_id).value = old_state;
		}
		old_city = document.getElementById(city_id+2).value;
		old_state = document.getElementById(state_id+2).value;
		document.getElementById(state_id+2).value = "";
		document.getElementById(city_id+2).value = "";
		document.getElementById(state_id+"_lbl").innerHTML = "State:";	
	}
}
