	function openPopup(pagePath,iWidth,iHeight,forPrint,useUnique,keepOpen){
			var iWinWidth = (iWidth) ? parseInt(iWidth) : 455;
			var iWinHeight = (iHeight) ? parseInt(iHeight) : 380;
			
			pagePath = String(pagePath).toLowerCase();
			// if other arguments exist, the first after url overwrites width of window
			
						
			var iAvailWidth = screen.availWidth;
			var iAvailHeight = screen.availHeight;
			if (iAvailWidth < iWinWidth) iWinWidth = iAvailWidth;
			if (iAvailHeight < iWinHeight) iWinHeight = iAvailHeight;
			// also center position of window
			var iLeft = (iAvailWidth - iWinWidth)/2;
			var iTop = (iAvailHeight - iWinHeight)/2;
			
			// make a function to generate window name unique or non unique as requested
			// close or do not close opened windows
			// add window to global least level array in opened windows stack
						
			var newWinName = (useUnique) ? getWindowName() : 'newWindow'; 
			
			var GlobalArray = (!keepOpen) ?  getGlobalArray() : new Array();
			
			if (forPrint)
				GlobalArray[GlobalArray.length] = window.open(pagePath,newWinName,'width='+ iWinWidth +',left='+ iLeft +',top='+ iTop +',height='+ iWinHeight +',toolbar=0,status=0,menubar=1,resizable=1,scrollbars=1');
			else
				GlobalArray[GlobalArray.length] = window.open(pagePath,newWinName,'width='+ iWinWidth +',left='+ iLeft +',top='+ iTop +',height='+ iWinHeight +',toolbar=0,status=0,menubar=0,resizable=0,scrollbars=1');
				
			
			GlobalArray[GlobalArray.length-1].focus();	
			
			
			if (event)
			{
				event.cancelBubble = true;
				event.returnValue = false;			
			}
			
		}
	
	function openModal(pagePath,iWidth,iHeight,isModal){
			var iWinWidth = (iWidth) ? parseInt(iWidth) : 455;
			var iWinHeight = (iHeight) ? parseInt(iHeight) : 380;
			
			pagePath = String(pagePath).toLowerCase();
			
			var iAvailWidth = screen.availWidth;
			var iAvailHeight = screen.availHeight;
			if (iAvailWidth < iWinWidth) iWinWidth = iAvailWidth;
			if (iAvailHeight < iWinHeight) iWinHeight = iAvailHeight;
			/*
			// also center position of window
			var iLeft = (iAvailWidth - iWinWidth)/2;
			var iTop = (iAvailHeight - iWinHeight)/2;
			*/
			// open either a modal or modless dialog according to isModal
						
			var modalReturn;
				
			if (isModal)
				modalReturn = showModalDialog(pagePath,window,'dialogHeight:'+ iWinHeight+ 'px;dialogWidth:'+ iWinWidth+'px ;center: yes ;resizable: no ;scroll: no;status:no');
			else
				showModelessDialog(pagePath,window,'dialogHeight:'+ iWinHeight+ 'px;dialogWidth:'+ iWinWidth+'px ;center: yes ;resizable: no ;scroll: no;help:no; status:no;');
				
			
			if (event)
			{
				event.cancelBubble = true;
				event.returnValue = false;			
			}
			
		}
		
		
	var newWin = new Array();
	function getGlobalArray(){
		if (window.opener)
			return window.opener.getGlobalArray();
		else
			return newWin;
	}
	function getWindowName(){
		// keep searching for a new unique ID
		
		var newID = window.document.uniqueID;
		if (window.newID){
			newID = window.document.body.uniqueID;
		}
		return newID;
	}
	
	function unloadPopup(){
										  
		// loop thru all opened windows and close only if this is the main window
		if (!window.opener){
			var i = 0;
			var newWinX;
			
			for (i=0; i<newWin.length; i++){
				
				if (window.newWin[i])
					if (!window.newWin[i].closed)
						window.newWin[i].close();
				newWin[i] = null;
			
			}
		}
				
		
	}
	var onLoadFocus = false; // set this to true in individual documents
	window.onunload = unloadPopup;
	window.onload = loadPage;
	var loadBodyFunc;
	
	function loadPage(){
			
		// anything else?, handle here
		if (loadBodyFunc){
			eval(loadBodyFunc);
		}
		
		var pageHash = window.location.hash;
		if (pageHash != "") return;
		
		// focus on first field
		focusDefault();
		
			
	}
	function focusDefault(){
		if (!onLoadFocus) return;
		
		var elemForm = document.forms[0];
		
		if (elemForm){	
			var i;
			var count = elemForm.elements.length;
			for (i=0; i<count; i++){
				var elem = elemForm.elements[i];
				if ((elem.type == 'text' || elem.type == 'password') && (elem.disabled == false)){
					
					try{
						elem.focus();
					}catch(e){
						
					}
					break;
				} 
			}
		}
	}


function checkEnableByField(fieldID, blnChecked){
	var fieldObj = document.getElementById(fieldID);
	if (fieldObj){

		fieldObj.disabled = blnChecked;
		fieldObj.updateState();

	}
}

function insertSelected(blockID, fieldID){
	var blockObj = document.getElementById(blockID);
	if (blockObj){
		var fieldObj = document.getElementById(fieldID);
		if (fieldObj)
			fieldObj.innerText += blockObj.innerText + '\n \n ';
	}
}
/*
function insertSelectedByField(groupName, fieldID){
	// search for radio group, get selected item, read insertID attribute, search for obj, populate innerhtml in fieldid
	// in the future, if the html editor is going to be used, fieldID is the hiddeninput fieldid associated
	var radioObj = document.getElementsByName(groupName);
	
	if (radioObj){
		for (i =0; i< radioObj.length; i++){
			if (radioObj[i].checked){
				var divObj = document.getElementById(radioObj[i].getAttribute("insertid"));
				if (divObj){ 
					var fieldObj = document.getElementById(fieldID);
					fieldObj.innerText = divObj.innerText;
					
				}
				break;
			}
		}
	}
	
}
*/

// ORDER ROWS
var gRow;
function move(rowElem, dir){
	// if dir = 1, move row to the lower one
	var replaceElem = (dir == 1) ? rowElem.nextSibling : rowElem.previousSibling;
	
	// swap
	if (replaceElem){
		// check the attribute of replaceElem and make sure its part of the ordering system
		if (replaceElem.include == "no") return false;
	
		var retRow = rowElem.swapNode(replaceElem);
		orderRow(replaceElem);
		orderRow(retRow);
		return retRow;
	}else
		return false;
	
}
function sendRowParent(dir,elem){
	// look in the parent hie. for the ROW element to send
	//var elem = event.srcElement;
	var rowElem = findRowParent(elem);
	// if gRow, clear its style
	if (gRow){
		gRow.style.backgroundColor  = '';
	}
	gRow = move(rowElem, dir);
	if (gRow){
		gRow.style.backgroundColor = '#DDE8F9';
	}
		
}
function orderRow(rowElem){
	// find the hidden input in the third cell and change value
	var index = rowElem.rowIndex +1;
	rowElem.cells[0].children[1].value = index;

}
function findRowParent(obj){
	if (obj.parentElement.tagName == 'TR')
		return obj.parentElement;
	else
		parentElem = findRowParent(obj.parentElement);
		
	return parentElem;
}



