// JavaScript Document
function showhidePopUpLayer(layerName,show) {
  if (document.getElementById) {
    obj = document.getElementById(layerName);
  } else if (document.all) {
    obj = document.all.item(layerName);
  } else {
    obj = null;
  }
  if (obj==null) return;
  obj.style.visibility = show ? 'visible' : 'hidden';
  obj.style.display = show ? 'block' : 'none';
}
function showPopupWindow(winURL) {
	self.name = "main"; // names current window as "main"
	OpenWindow = window.open(winURL, "remote", "toolbar=0,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width=500,height=500,top=100,left=110");
	OpenWindow.focus();
}

function showHideDivElements(parentDivId, idStartsWith, showId, tabValueHiddenFieldId) {
	var parent;
	if (document.getElementById) {
		parent = document.getElementById(parentDivId);
		tabValueField = document.getElementById(tabValueHiddenFieldId);
	} 
	else if (document.all) {
		parent = document.all.item(parentDivId);
		tabValueField = document.all.item(tabValueHiddenFieldId);
	} 
	else {
		return;
	}

	var divs = parent.getElementsByTagName("div");
	for (i = 0; i < divs.length; i++) {
		obj = divs[i];
		len = idStartsWith.length;
		if (obj.id.substring(len, 0).toLowerCase() == idStartsWith) {
			if (obj.id == showId) {
				obj.style.visibility = 'visible';
				obj.style.display = 'block';
				if (tabValueField != null) {
					index = obj.id.substring(idStartsWith.length, obj.id.length);
					tabValueField.value = index;
				}
			}
			else {
				obj.style.visibility = 'hidden';
				obj.style.display = 'none';
			}
		}
	}
}

function selectThisTab(listName,obj) {
	if (document.getElementById) {
		tabs = document.getElementById(listName);
		obj = document.getElementById(obj);
	} else if (document.all) {
		tabs = document.all.item(listName);
		obj = document.all.item(obj);
	} else {
		tabs = null;
		obj = null;
	}
	if (tabs==null) return;
	var tabList = tabs.getElementsByTagName("a");
	for (i = 0; i < tabList.length; i++) {
    tabList[i].className = "";
  }
  obj.className = "selected";
}

/* Counts how many checkboxes are selected */
function GetSelectedCount(className) {
    var count = 0;

    //Finds all state checkboxes and adds their value to the array
    jQuery('.' + className + ' input').each(
		function(box) {
		    if (this.checked) {
		        count += 1;
		    }
		}
	);

    return count;
}

/*
Removes a location from the page
*/       
function removeLocationRow(id) {
    var rowId = 'tr_' + id;
    var row = document.getElementById('tr_' + id);
    if (row != null) {
        var rows = new Array();
        rows.push(row);
        // Need to get all the rows that the location spans
        var rowSpan = jQuery('#' + rowId + " > td:first").attr('rowspan');
        if (rowSpan != null) {
            for (var i = 0; i < rowSpan - 1; i++) {
                var nextRow = jQuery(row).next()[0];                
                rows.push(nextRow);
                row = nextRow;
            }
        }
        jQuery(rows).fadeOut('fast');
    }
    deselectCheckbox(id);
}

function deselectCheckbox(id) {
    var checkboxSelector = "#cb_" + id + " input";
    jQuery(checkboxSelector).each(
		function() {
		    this.checked = false;
		}
	);
}
