//Based on function at http://www.netlobo.com/div_hiding.html

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

function showLayerInline(whichLayer) {
	if (!whichLayer) {
		return;
	}
	
    var style2;
    if (document.getElementById) {
        // this is the way the standards work
        style2 = document.getElementById(whichLayer).style;
    }
    else if (document.all) {
        // this is the way old msie versions work
        style2 = document.all[whichLayer].style;
    }
    else if (document.layers) {
        // this is the way nn4 works
        style2 = document.layers[whichLayer].style;
    }
    style2.display = "inline";
}

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

function setLayerDisabled(whichLayer, myCheckbox) {
    if (myCheckbox.checked) {
        showLayer(whichLayer);
    } else {
        hideLayer(whichLayer);
    }
}

function showPrint(element) {
	var cur;
    if (document.getElementById) {
        // this is the way the standards work
		cur = document.getElementById(element).getAttribute("class");
		// if (cur == "") DO SOMETHING FOR IE!!!
		var x = cur.gsub(" print_hidden", "");
		document.getElementById(element).setAttribute("class", x);
		var f = document.getElementById(element).getAttribute("class");
    }
    else if (document.all) {
        // this is the way old msie versions work
		cur = document.all[element].getAttribute("className");
		document.all[element].setAttribute("className", cur.gsub(" print_hidden", ""));
    }
    else if (document.layers) {
        // this is the way nn4 works
		cur = document.layers[element].getAttribute("class");
		document.layers[element].setAttribute("class", cur.gsub(" print_hidden", ""))
    }
}

function hidePrint(element) {
	var cur;
    if (document.getElementById) {
        // this is the way the standards work
		cur = document.getElementById(element).getAttribute("class");
		// if (cur == "") DO SOMETHING FOR IE!!!
		document.getElementById(element).setAttribute("class", cur + " print_hidden");
    }
    else if (document.all) {
        // this is the way old msie versions work
		cur = document.all[element].getAttribute("className");
		document.all[element].setAttribute("className", cur + " print_hidden");
    }
    else if (document.layers) {
        // this is the way nn4 works
		cur = document.layers[element].getAttribute("class");
		document.layers[element].setAttribute("class", cur + " print_hidden")
    }	
}

function setPrintVisible(checkbox, element) {
	if (checkbox.checked) {
		showPrint(element);
	} else {
		hidePrint(element);
	}
}

function populateCities(o, counties) {
	// Determine the selected index, and display the correct county div as a result.

	var selectedIdx = o.selectedIndex;
	
	for (var i = 0; i < counties.length; i++) {
		if (i == selectedIdx) {
			showLayerInline(counties[i]);
		} else {
			hideLayer(counties[i]);
		}
	}
}

function initializeCities(elementId, counties) {
	if (document.getElementById) {
        // this is the way the standards work
        populateCities(document.getElementById(elementId), counties);
    }
    else if (document.all) {
        // this is the way old msie versions work
        populateCities(document.all[elementId], counties);
    }
    else if (document.layers) {
        // this is the way nn4 works
        populateCities(document.layers[elementId], counties);
    }
}

function populateLocalities(o, firstIndex) {
	// Determine the selected index, and display the correct locality div as a result.
	var localities = new Array();
	localities[0] = 'atlanta_locality_selects';
	localities[1] = 'minneapolis_locality_selects';

	var residences = new Array();
	residences[0] = 'atlanta_locality_residence';
	residences[1] = 'minneapolis_locality_residence';
	
//	var selectedVal = o.options[o.selectedIndex].value;
	var selectedIdx = o.selectedIndex;
	
	for (var i = 0; i < localities.length; i++) {
		if (i == selectedIdx) {
			showLayerInline(localities[i]);
//			showLayerInline(residences[i]);
		} else {
			hideLayer(localities[i]);
//			hideLayer(residences[i]);			
		}
	}
}

function initializeLocalities(elementId, firstIndex) {
	if (document.getElementById) {
        // this is the way the standards work
        populateLocalities(document.getElementById(elementId), firstIndex);
    }
    else if (document.all) {
        // this is the way old msie versions work
        populateLocalities(document.all[elementId], firstIndex);
    }
    else if (document.layers) {
        // this is the way nn4 works
        populateLocalities(document.layers[elementId], firstIndex);
    }
}

