
function CFDeleteSelectedRow(pDso,pStatusField, pSelectField) {
	var oRecordset ;
	var lRecCount ;
	var lNumDeleted;
	
	lNumDeleted = 0 ;
	oRecordset = pDso.recordset ;	
	lRecCount = oRecordset.recordcount;
	
	for (var i=1; i<=lRecCount ; i++) {
			oRecordset.absoluteposition = i ;
			if (oRecordset.fields(pSelectField).value == -1) {
				lValue = oRecordset.fields(pStatusField).value ;
				if (lValue == "M" || lValue == "U") {
					oRecordset.fields(pStatusField).value = "D" ;
					lNumDeleted = lNumDeleted + 1 ;
				} else {
					if (lValue == "D") {
						lNumDeleted = lNumDeleted + 1 ;
					}
					if (lValue == "N") {
						oRecordset.fields(pStatusField).value = "X" ;
					}
				}
			}
	}
	
	return lNumDeleted ;
}

function CFCountSelectedRow(pDso, pSelectField) {
	var oRecordset ;
	var lRecCount ;
	var lNumSelected;
	
	lNumSelected = 0 ;
	oRecordset = pDso.recordset ;	
	lRecCount = oRecordset.recordcount;
	
	for (var i=1; i<=lRecCount ; i++) {
		oRecordset.absoluteposition = i ;
		if (oRecordset.fields(pSelectField).value == -1) {
			lNumSelected = lNumSelected + 1 ;
		}
	}
	
	return lNumSelected ;
}



function CFMarkDeletedOnly(pDso,pStatusField) {
	var oRecordset ;
	var lRecCount ;
	var lNumDeleted;
	
	lNumDeleted = 0 ;
	oRecordset = pDso.recordset ;	
	lRecCount = oRecordset.recordcount;
	
	for (var i=1; i<=lRecCount ; i++) {
		oRecordset.absoluteposition = i ;
		lValue = oRecordset.fields(pStatusField).value ;
		if (lValue == "M" || lValue == "N") {
			oRecordset.fields(pStatusField).value = "U" ;
		}
	}
	
	return lNumDeleted ;
}


function CFCheckUncheckAll(pDso, pField) {
	var oRecordset;
	var lRecCount;
	var lrecfield;
	var lnewvalue;
	
	oRecordset = pDso.recordset ;
	
	lRecCount = oRecordset.recordcount;
	
	if (lRecCount > 0) {
		oRecordset.movefirst();
		if (oRecordset.fields(pField).value == "") {
			lnewvalue = "-1";
		} else {
			lnewvalue = "";
		}
	
		for (var i=1; i<=lRecCount ; i++) {
			oRecordset.absoluteposition = i;
			oRecordset.fields(pField).value = lnewvalue ;
		}
	}
}

function CFAddRow(pTable, pDso) {

	var oRecordset ;
	var lAddRow ;
	
	oRecordset = pDso.recordset ;
	lAddRow = true ;
	
	if (oRecordset.recordcount == 1) {
		oRecordset.movefirst();
		if (oRecordset.fields("CFSTATUS") == "S") {
			pTable.all["CFBody"].style.display = "" ;
			pTable.all["CFHeaderNoRow"].style.display = "none";
			lAddRow = false ;
		}
	}
	
	if (lAddRow) {
		oRecordset.addnew() ;
	}
	oRecordset.fields("CFSTATUS").value = "N" ;
}

function CFDestroyAllRows(pTable, pDso) {

	var oRecordset ;
	var index ;
	var lRecordCount ;
	var lExecDestroy ;
	
	lExecDestroy = true ;
	
	oRecordset = pDso.recordset ;
	lRecordCount = oRecordset.recordcount ;
	
	if (lRecordCount == 1) {
		if (oRecordset.fields("CFSTATUS") == "S") {
			lExecDestroy = false ;
		}
	}
	
	if (lExecDestroy) {
	
		for (index=1; index<=lRecordCount; index++) {
			oRecordset.movefirst();
			oRecordset.Delete();
		}
		
		oRecordset.addnew() ;
		oRecordset.fields("CFSTATUS").value = "S" ;
		pTable.all["CFBody"].style.display = "none" ;
		pTable.all["CFHeaderNoRow"].style.display = "";
	}
}

function GetRowCount(pDso) {
	var oRecordset ;
	var lRecCount ;
	
	oRecordset = pDso.recordset ;	
	lRecCount = oRecordset.recordcount;

	return lRecCount ;
}

function GetFormValue(pForm, pField, pIndex) {	
	if (document.forms[pForm].item(pField,pIndex).type == "checkbox") {
		return document.forms[pForm].item(pField,pIndex).checked;
	} else {
		return document.forms[pForm].item(pField,pIndex).value ;
	}	
}

function CFShowEmptyRow(pTable, pDso) {
	var oRecordset ;
	oRecordset = pDso.recordset ;
	if (oRecordset.recordcount == 1) {
		if (oRecordset.fields("CFSTATUS") == "S") {
			pTable.all["CFBody"].style.display = "none" ;
			pTable.all["CFHeaderNoRow"].style.display = "";
		}
	}
}


function CFHighlightRowForDelete(pField, pAffectedRow) {

	var lRowObj      // Row object
	var lFound;      // Found deleted Row
	var lStop;       // Stop iteration
	var lValue;      // Delete or Undelete
	var lCount;      // Max iteration count
	var lTagName     // TagName
	var i, j         // Index
	var lCurAffected // Current affected row
	var lCurTable    // Current table
	var lCurObj      // Current parent obj (may be TR or TABLE)
	var lCurIndex    // Current row index inside table
	var	lRowLength   // Row number inside table
	
	lValue = pField.checked;
	
	lFound = false ;
	lStop = false ;
	
	lRowObj = pField ;
	lCount = 0
	
	if (typeof(pAffectedRow) == 'undefined') {
		pAffectedRow = 1
	}
	
	if (pAffectedRow == null) {
		pAffectedRow = 1
	}
	
	while (!lStop)
	{
		if (lRowObj.tagName.toLowerCase() == 'tr' 
		    && lRowObj.parentElement.tagName.toLowerCase() == 'tbody') {
			lStop = true ;
		    lFound = true ;
		}
		
		if (lRowObj.tagName.toLowerCase() == 'table') { lStop = true ; }
		
		lCount = lCount + 1;
		if (lCount == 10) { lStop = true ; }
		
		if ((!lStop)&&(!lFound)) { lRowObj = lRowObj.parentElement; }
	}
	
	if (lFound) {
	
		lCurAffected = 1 ;
		while (lCurAffected <= pAffectedRow) {
			
			for (i=0; i<lRowObj.cells.length; i++)
			{		
				for (j=0 ; j<lRowObj.cells(i).all.length; j++) {			
					lType = '' ;
					lTagName = '' ;
					
					try { lType = lRowObj.cells(i).all(j).type } catch (e) {}
					try { lTagName = lRowObj.cells(i).all(j).tagName } catch (e) {}
					
					if (lType == 'text') {
						if (lValue) {
							lRowObj.cells(i).all(j).style.textDecorationLineThrough = true ;
						} else {
							lRowObj.cells(i).all(j).style.textDecorationLineThrough = false ;
						}
					}
					if ((lTagName == 'SPAN') || (lTagName == 'TEXTAREA') || (lTagName == 'SELECT')) {
						if (lValue) {
							lRowObj.cells(i).all(j).style.textDecorationLineThrough = true ;
						} else {
							lRowObj.cells(i).all(j).style.textDecorationLineThrough = false ;
						}
					}		
				}		
			}
			
			lCurAffected++ ;
			if (lCurAffected <= pAffectedRow) {
			
				lCurTable = null ;
				lCurObj = lRowObj ;
				lCurIndex = lRowObj.rowIndex ;
				lRowLength = 0 ;
				if (lRowObj.parentElement.tagName.toLowerCase() == 'tbody') {
					lCurObj = lRowObj.parentElement ;
				} 
				if (lCurObj.parentElement.tagName.toLowerCase() == 'table') {
					lCurTable = lCurObj.parentElement ;
				}
				
				if (lCurTable != null) {
					lRowLength = lCurTable.rows.length ;
					if (lRowLength >= lCurIndex + 1) {
						lRowObj = lCurTable.rows(lCurIndex + 1) ;
					} else {
						lCurAffected = pAffectedRow + 1 ; // Set an exit condition
					}
				} else {
					lCurAffected = pAffectedRow + 1 ; // Set an exit condition
				}
				
			}
			
		}
		
	}
	
}

