// global var for window creation
var newWin = null;
function openWin(url,windowName,settings,reUse) { 
	// open a new window given a pre-defined name
	//var settings = '';
	// pre-defined window names
	//if (windowName == 'feedback') {settings = 'height=450,width=450,scrollbars=0';}
	//if (windowName == 'legend') {settings = 'height=450,width=250,scrollbars=0';}
	//if (windowName == 'tree') {settings = 'height=450,width=300,scrollbars=1';}
	//if (windowName == 'admin') {settings = 'height=450,width=450,resizable=1,scrollbars=1,directories=0,menubar=0,status=0,toolbar=0';}
	if (reUse == 'true') {
		//If tree then don't reload window, only check if already open;
		if (newWin && newWin.open && !newWin.closed)
		{
			//window is already open, don't refresh simply set focus
			//alert('tree already open');
			//BUG:every reload of the parent window allows with to run again BUT works if run twice from  same page
			newWin.focus();
		}
		else {newWin = window.open(url, windowName, settings); }
	}
	// default ALL windows will open
	else {newWin = window.open(url, windowName, settings); }
	newWin.focus(); 
}
function toggleDisplay(field,caption) {
	// toggle display of target object
	thingy = document.getElementById(field);
	mode = (thingy.style.display == 'none') ? '' : 'none'; 
	thingy.style.display = mode;
	//caption trigger text
	if (caption != null) {
		var new_caption = (mode == 'none') ? '[+]' : '[-]';
		caption.innerHTML = new_caption;
	}
}
function toggleCollumn(field) {
	// toggle display for multiple cells
	cells = document.getElementsByName(field);
	if (cells.length > 0) {			
		mode = (cells[1].style.display == 'none') ? '' : 'none'; 
		for(j = 0; j < cells.length; j++) cells[j].style.display = mode;
	}
}
function toggleCheckbox(field, isChecked) {
	// toggle checked for multiple checkboxes
	boxes = document.getElementsByName(field);
	if (boxes.length > 0) {	
		for(j = 0; j < boxes.length; j++) boxes[j].checked = isChecked;
	}
}
function toggleSelect(field,index,fieldcount)
{ 
	// toggle selectedIndex for single or multiple select boxes
	// use 1 not 0 for first field & N
	// usage: onChange="toggleSelect('contenttype_id',this.selectedIndex,#form.rowcount#);
	if(fieldcount <= 0)	{
		//fsingle field 
		//ex: field.selectedIndex
		combo = document.getElementById(temp);
		combo.selectedIndex = index; 
	} else { 
		//multiple unique fields expected 
		//ex: fieldN.selectedindex
		for(j = 1; j <= fieldcount; j++) {
			temp = '' + field + j;
			combo = document.getElementById(temp);
			combo.selectedIndex = index;
		}
	}
}
function toggleCombo(field, isSelected)
{	
	// toggle multiple options selected for single combo
	// assume field array
	combo = document.getElementById(field);
	if (combo.options.length > 0) {
		for(j = 0; j < combo.options.length; j++) combo.options[j].selected = isSelected;
	}
}
function changeCombo(field, IndexNum)
{
	// set option as selected in single combo box
	combo = document.getElementById(field);
	combo.selectedIndex = IndexNum;
}
function showPanel(tab, pos)
{
	// show:hide tab given position within array
  	var selectedTab = null;
	//shift to 0 array start
	pos = pos - 1;
	
	// get tabs array
	tabSet = document.getElementsByName('tabs');
	if (tabSet.length > 0) {			
		// set all tabs to regular
		for(i = 0; i < tabSet.length; i++)
		{
		tabSet[i].style.backgroundColor = '';
		tabSet[i].style.paddingTop = '';
		tabSet[i].style.paddingBottom = '';
		}
		// set POS tab to highlight
		tabSet[pos].style.backgroundColor = 'white'
		tabSet[pos].style.paddingTop = '6px'
	}

	// show:hide tab given position within array
	panelSet = document.getElementsByName('panels');
	if (panelSet.length > 0) {			
		// set all panels to hide
		for(j = 0; j < panelSet.length; j++) panelSet[j].style.display = 'none';
		// set POS panel to show
		panelSet[pos].style.display = '';
	}
	return false;
}
function limitText(limitField, limitCount, limitNum) {
	thisfield = document.getElementById(limitField);
	thisfieldcount = document.getElementById(limitCount);
	if (thisfield.value.length > limitNum) {
		thisfield.value = thisfield.value.substring(0, limitNum);
	} else {
		thisfieldcount.value = limitNum - thisfield.value.length;
	}
}
var preClick ;
var orgClass ;
function changeTR(e,backColor) {
	//if (window.event) e = window.event; 
	//var srcEl = e.srcElement? e.srcElement : e.target;
	 
	if(typeof(preClick)!='undefined') {
	preClick.className=orgClass; 
	} 
	var clicked = event.srcElement;
	clicked = clicked.parentElement;
	orgClass = clicked.className;
	clicked.className = backColor;
	preClick = clicked; 
}
function fixCR(str)
	{
	var str2 = str.replace(new RegExp('\n\n\n', 'g')," ");
	return str;
}
function EscapeNoScript(field) {
	//my technique to write a tags content back to itself 
	//works fine when noscript not used
	//addresses ie activex click to activate issue
	oField = document.getElementById(field);
	oField.innerHTML = oField.innerHTML.replace(/noscript/gi,'div');
	return true;
}