function userMUnSelect(row){

}	

function userMSelect(row){

}	
function ps_isSelected(row) {
	if (row.className == "listCellSelected")
		return true;
	if (row.className == "listCellSelection")
		return true;
	return false;
}


function ps_multiSelectOverOutHandler(ev) {
	// Standard cross-browser event code
	ev = ev || event;
	var target = ev.target || ev.srcElement;
	if (target.nodeName == "IMG")
	{
		target = target.parentNode;
	}	
	if (target.nodeName == "NOBR")
	{
		target = target.parentNode;
	}
	if (target.nodeName != "TD") return;
		
	if (ev.type == "mouseover")
	{
		if (!ps_isSelected(target.parentNode))
		{
			target.parentNode.className = "listCellHighlight";
		};	
	}
	else
	{
		if (!ps_isSelected(target.parentNode))
		{
			target.parentNode.className = "listCell";
		};
	};
	
	// stop bubbling, IE event model
	ev.cancelBubble = true; 
	// stop bubbling, W3C event model
	if (ev.stopPropagation) ev.stopPropagation();
}

function ps_multiSelectItem(row) {		
	var keyTd = row.firstChild;
	while (keyTd.nodeName=='#text')	keyTd = keyTd.nextSibling;	
	var sel = keyTd.firstChild
	while (sel.nodeName=='#text')	sel = sel.nextSibling;
	
	if (ps_isSelected(row))
	{
		// change the class to highlight because the mouse is over this item
		row.className = "listCellHighlight";		
		sel.value = '';
		userMUnSelect(row);	
		
	}
	else
	{
		// select the item
		row.className = "listCellSelection";
		sel.value = '2';
		userMSelect(row);	
	}
	
	return true;
}

function ps_clickItem(row) {
	
	var keyTd = row.firstChild;
	//If white space preserved by Mozilla
	while (keyTd.nodeName=='#text')	keyTd = keyTd.nextSibling;	
	var sel = keyTd.firstChild;
	while (sel.nodeName=='#text')	sel = sel.nextSibling;
	//Select the row
	row.className = "listCellSelection";
	sel.value = '2';
	sel = sel.nextSibling;
	while (sel.nodeName=='#text')	sel = sel.nextSibling;
	if (sel == null) return true;
	sel.click();
	return true;
}


function ps_multiSelectClickHandler(ev) {
	ev = ev || event;
	var target = ev.target || ev.srcElement;
	if (target.nodeName == "IMG")
	{
		target = target.parentNode;
	}	
	if (target.nodeName == "NOBR")
	{
		target = target.parentNode;
	}
	if (target.nodeName != "TD") return;
	var tableObject = target.parentNode;
	tableObject = tableObject.parentNode;
	tableObject = tableObject.parentNode;
	ps_unselectSelection(tableObject, 1);
	ps_multiSelectItem(target.parentNode);
	
	// stop bubbling, IE event model
	ev.cancelBubble = true; 
	// stop bubbling, W3C event model
	if (ev.stopPropagation) ev.stopPropagation();
}

function ps_clickHandler(ev) {
	ev = ev || event;
	var target = ev.target || ev.srcElement;
	if (target.nodeName == "IMG")
	{
		target = target.parentNode;
	}	
	if (target.nodeName == "NOBR")
	{
		target = target.parentNode;
	}

	if (target.nodeName != "TD") return;
	//if (event.ctrlKey == true)
	if (ev.ctrlKey == true)
		{
		var tableObject = target.parentNode;
		tableObject = tableObject.parentNode;
		tableObject = tableObject.parentNode;
		ps_unselectSelection(tableObject, 1);
		ps_multiSelectItem(target.parentNode);
		}
	else
		{
		var tableObject = target.parentNode;
		tableObject = tableObject.parentNode;
		tableObject = tableObject.parentNode;
		ps_unselectSelection(tableObject, 0);
		ps_clickItem(target.parentNode);
		}
	
	// stop bubbling, IE event model
	ev.cancelBubble = true; 
	// stop bubbling, W3C event model
	if (ev.stopPropagation) ev.stopPropagation();
}

function ps_multiSelectItems(tableObject) {
	// itertate through all rows in the tableObject
	var row = tableObject.firstChild;
	// skip TBODY
	while (row.nodeName != "TBODY") 
	{
		row = row.nextSibling;
		if (row == null) break;
	}
	
	//if (row.nodeName == "TBODY") 
	row = row.firstChild;
	while (row.nodeName != "TR")
	{	
		row = row.nextSibling;
		if (row == null) break;
	}
	
	while (row != null)
	{
		//alert('WHILE ROW')
		
		var keyTd = row.firstChild;		
		while (keyTd.nodeName=='#text')	keyTd = keyTd.nextSibling;	
		var sel = keyTd.firstChild;
		while (sel.nodeName=='#text')	sel = sel.nextSibling;
		if (sel.value =="1")
			{
			row.className = "listCellSelected";
			}
		else if (sel.value =="2")
			{
			row.className = "listCellSelection";
			}
		else	{
			row.className = "listCell";
			}

		// advance to the next row
		row = row.nextSibling;
		if (row == null) break;
		while (row.nodeName != "TR")
		{
			row = row.nextSibling;
			if (row == null) break;
		}
	}	
}

function ps_unselectSelection(tableObject, newVal) {
	// itertate through all rows in the tableObject
	var row = tableObject.firstChild;
	// skip TBODY
	while (row.nodeName != "TBODY") 
	{
		row = row.nextSibling;
		if (row == null) break;
	}
	
	//if (row.nodeName == "TBODY") 
	row = row.firstChild;
	while (row.nodeName != "TR")
	{	
		row = row.nextSibling;
		if (row == null) break;
	}
	
	while (row != null)
	{
		
		
		var keyTd = row.firstChild;		
		while (keyTd.nodeName=='#text')	keyTd = keyTd.nextSibling;	
		var sel = keyTd.firstChild;
		while (sel.nodeName=='#text')	sel = sel.nextSibling;
		//SEL IS null on Firefox
		if (sel != null)
		{
		//alert('WHILE ROW' + sel.value)
			if (sel.value =="2")
				{
				//alert('GOT A 2');
				if (newVal == 1)
					{
					row.className = "listCellSelected";
					sel.value ='1';
					}
				else
					{
					row.className = "listCell";
					sel.value ='0';
					}
	
				}
			else	{
				//row.className = "listCell";
				}
		}
		// advance to the next row
		row = row.nextSibling;
		if (row == null) break;
		while (row.nodeName != "TR")
		{
			row = row.nextSibling;
			if (row == null) break;
		}
	}	
}


function ps_unselectMultiSelection(tableObject) {
	// itertate through all rows in the tableObject
	var row = tableObject.firstChild;
	// skip TBODY
	while (row.nodeName != "TBODY") 
	{
		row = row.nextSibling;
		if (row == null) break;
	}
	
	//if (row.nodeName == "TBODY") 
	row = row.firstChild;
	while (row.nodeName != "TR")
	{	
		row = row.nextSibling;
		if (row == null) break;
	}
	
	while (row != null)
	{
		
		
		var keyTd = row.firstChild;		
		while (keyTd.nodeName=='#text')	keyTd = keyTd.nextSibling;	
		var sel = keyTd.firstChild;
		while (sel.nodeName=='#text')	sel = sel.nextSibling;
		if (sel.value =="1")
				{
				row.className = "listCell";
				sel.value ='0';
				}

		// advance to the next row
		row = row.nextSibling;
		if (row == null) break;
		while (row.nodeName != "TR")
		{
			row = row.nextSibling;
			if (row == null) break;
		}
	}	
}



