
//**************************************************************************
//		Copyright  Sybase, Inc. 1998-1999
//						 All Rights reserved.
//
//	Sybase, Inc. ("Sybase") claims copyright in this
//	program and documentation as an unpublished work, versions of
//	which were first licensed on the date indicated in the foregoing
//	notice.  Claim of copyright does not imply waiver of Sybase's
//	other rights.
//
//	 This code is generated by the PowerBuilder HTML DataWindow generator.
//	 It is provided subject to the terms of the Sybase License Agreement
//	 for use as is, without alteration or modification.
//	 Sybase shall have no obligation to provide support or error correction
//	 services with respect to any altered or modified versions of this code.
//
//       ***********************************************************
//       **     DO NOT MODIFY OR ALTER THIS CODE IN ANY WAY       **
//       ***********************************************************
//
//       ***************************************************************
//       ** IMPLEMENTATION DETAILS SUBJECT TO CHANGE WITHOUT NOTICE.  **
//       **            DO NOT RELY ON IMPLEMENTATION!!!!		      **
//       ***************************************************************
//
// Use the public interface only.
//**************************************************************************

// these arrays will be filled with internationalized strings based on the server
var DW_shortDayNames = new Array("Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat");
var DW_longDayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var DW_shortMonthNames = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
var DW_longMonthNames = new Array("January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

// this is dependent on the control panel setting on the server
// it indicates the order of days (this is mm/dd/yyyy)
var DW_PARSEDT_monseq = 0;
var DW_PARSEDT_dayseq = 1;
var DW_PARSEDT_yearseq = 2;

// DWItemStatus
var DW_ITEMSTATUS_NOCHANGE = 0;
var DW_ITEMSTATUS_MODIFIED = 1;
var DW_ITEMSTATUS_NEW = 2;
var DW_ITEMSTATUS_NEW_MODIFIED = 3;

// Added to determine if dates are being processed in client side JavaScript.
var bDateTimeProcessingEnabled = false;

var gMask = "";

// common utility functions

function escapeString( inString )
{
    var index;
    var outString = "";
    var tempChar;

    // force to string type or charAt will fail!
    if (typeof inString != "string")
    	inString = inString.toString();

    var strLength = inString.length;
    for ( index=0; index < strLength; index++ )
        {
        tempChar = inString.charAt( index );
        if (tempChar == "\"" || tempChar == "'")
            outString += "~" + tempChar;
        else if (tempChar == "\r")
            outString += "~r";
        else if (tempChar == "\n")
            outString += "~n";
        else
            outString += tempChar;
        }
    return outString;
}

function convertToRGB( color )
{
	var hexValue = "000000" + eval( color ).toString(16);
	hexValue = hexValue.substr( hexValue.length - 6, 6 );
	hexValue = hexValue.substr( 4, 2 ) + hexValue.substr( 2, 2 ) + hexValue.substr( 0, 2 );
	return hexValue;
}

// default event returns to 0
function _evtDefault (value)
{
    if (value + "" == "undefined")
        return 0;
    return value;
}

// need to double up because of template expander!
function DW_parseIsSpace(theChar)
{
    return /^\s$/.test(theChar);
}

function DW_parseIsDigit(theChar)
{
    return /^\d$/.test(theChar);
}

function DW_parseIsAlpha(theChar)
{
    return /^\w$/.test(theChar) && ! /^\d$/.test(theChar);
}

// auto binding of events expect <controlName>_<eventName>
function HTDW_eventImplemented(sEventName)
{
    // check if we already have one scripted
    if (this[sEventName] == null)
        {
        // check for function with default name
        var testName = this.name + '_' + sEventName;
        if (eval ('typeof ' + testName) == 'function')
            this[sEventName] = eval(testName);
        }

    return this[sEventName] != null;
}

// utility functions
function allowInString (inString, refString)
{
    var index, tempChar;
    var strLength = inString.length;
    for (index=0; index < strLength; index++)
        {
        tempChar= inString.charAt (index);
        if (refString.indexOf (tempChar)==-1)
            return false;
        }
    return true;
}

function DW_Trim(inString)
{
    var indexStart, indexEnd, tempChar, outString;
    var strLength = inString.length;
    // skip leading blanks
    for (indexStart=0; indexStart < strLength; indexStart++)
        {
        tempChar= inString.charAt (indexStart);
        if (tempChar != " ")
            break;
        }
    if (indexStart != strLength)
        {
        // skip trailing blanks
        for (indexEnd=strLength-1; indexEnd > 0; indexEnd--)
            {
            tempChar= inString.charAt (indexEnd);
            if (tempChar != " ")
                break;
            }
        // get all chars in between
        outString = inString.substring(indexStart, indexEnd+1);
        }
    else
        outString = "";
    return outString;
}

function DW_Round(num, decPlaces)
{
	var powTen = Math.pow(10.0,decPlaces);
	num *= powTen;
	if (num >= 0)
	    num = Math.floor(num + 0.5);
	else
	    num = Math.ceil(num - 0.5);

    return num / powTen;
}

function DW_IsNonNegativeNumber(inString, bNilIsNull)
{
	if (arguments.length < 2)
			bNilIsNull = false;
		if (inString == "")
			return bNilIsNull;
		else
		{
			var newString = DW_Trim(inString);
			if (newString == "")
				return false;
			else
			{
				var result = new DW_NumberClass();
				if(DW_parseNumberStringAgainstMask(inString, result, false))
				{
					if (result >= 0)
						return true;
				}

				return false;
			}
		}
}

function DW_IsValidDisplayOrDataValue(inString, bNilIsNull)
{
    if (arguments.length < 2)
        bNilIsNull = false;
    if (inString == "")
        return bNilIsNull;
    else
        {
        var i;
        for(i = 0; i < this.displayValue.length; i++)
            {
            if (inString == this.displayValue[i])
                return true;
            if (inString == this.dataValue[i])
                return true;
            }
        return false;
        }
}

function DW_IsNumber(inString, bNilIsNull)
{
	if (arguments.length < 2)
			bNilIsNull = false;
		if (inString == "")
			return bNilIsNull;
		else
		{
			var newString = DW_Trim(inString);
			if (newString == "")
				return false;
			else
				return DW_parseNumberStringAgainstMask(inString, null, true);
		}
}

// exprContext class
function HTDW_exprContextClass(dataWindow)
{
    this.dw = dataWindow;
    this.row = -1;
    this.currentText = "";
}

// Col0 class
function HTDW_Col0Class(rowId, dwItemStatus)
{
    this.colModified = new Array();
    this.rowId = rowId;
    this.itemStatus = dwItemStatus;
}

// Row class
function HTDW_RowClass(rowId)
{
    var col;

    // column 0 holds special data
    this[0] = new HTDW_Col0Class(rowId, arguments[1]);

    // get data values
    for (col = 1; col < arguments.length - 1; col++)
        {
        this[0].colModified[col] = false;
        this[col] = arguments[col + 1];
        }

    this.numCols = arguments.length - 1;
}

function HTDW_Row_generateChange (rowNum, rowObj)
{
    var col;
    var result;

    if (rowObj[0].itemStatus == DW_ITEMSTATUS_MODIFIED ||
        rowObj[0].itemStatus == DW_ITEMSTATUS_NEW_MODIFIED)
        {
        result = "(ModifyRow " + rowNum + " " + rowObj[0].rowId + " (";
        for (col = 1; col < rowObj.numCols; col++)
            {
            if (rowObj[0].colModified[col])
                {
                if (rowObj[col] == null)
                    result += "(" + col + " 1)";
                else
                    result += "(" + col + " 0 '" + escapeString(rowObj[col]) + "')";
                }
            }
        result += "))";
        }
    else
        result = "";

    return result;
}

function HTDW_Row_dumpRow (rowNum, rowObj)
{
    var col;
    var result;

    result = "Row " + rowNum + "\n" +
             "Modified:" + rowObj[0].itemStatus + "\n" +
             "RowId:" + rowObj[0].rowId + "\n" +
             "NumCols:" + (rowObj.numCols - 1) + "\n";

    for (col = 1; col < rowObj.numCols; col++)
        {
        result += "   Col " + col + " modified:" + rowObj[0].colModified[col] + " '" + rowObj[col] + "'\n";
        }

    // alert (result);

    return result;
}

// set up class functions
HTDW_RowClass.generateChange = HTDW_Row_generateChange;
HTDW_RowClass.dumpRow = HTDW_Row_dumpRow;

function HTDW_ColumnGob(name, colNum, rowInDetail, region, bRequired, bNilIsNull, bFocusRect, formatFunc, getDisplayFormatFunc, getEditFormatFunc, column)
{
    this.name = name;
    this.colNum = colNum;
    this.rowInDetail = rowInDetail;
    this.region = region;
    this.bRequired = bRequired;
    this.bNilIsNull = bNilIsNull;
    this.bFocusRect = bFocusRect;
	this.bUseCodeTable = false;

    this.getDisplayFormat = getDisplayFormatFunc;
    this.getEditFormat = getEditFormatFunc;
    this.format = formatFunc;
    this.column = column;
}

function HTDW_ComputeGob(name, region, computeFunc, formatFunc, getDisplayFormatFunc)
{
    this.name = name;
    this.region = region;

    this.compute = computeFunc;
    this.getDisplayFormat = getDisplayFormatFunc;
    this.format = formatFunc;
}

// Depend classes common function
// DependCompute class
function HTDW_DependComputeUpdate(htmlDw, row, bSkipCurrent)
{
    var gob = this.gob;
    var control = htmlDw.findControl(gob.name, row, gob.region == 0);

    if (control != null && typeof gob.compute == "function")
        {
        // body
        if (gob.region == 0)
            row = row;
        // header
        else if (gob.region == 1)
            row = htmlDw.firstRow;
        // footer or summary
        else if (gob.region == 2 || gob.region == 3)
            row = htmlDw.lastRow;

        var exprCtx = htmlDw.exprCtx;
        exprCtx.row = row;
        exprCtx.currentText = "";

        var value = gob.compute(exprCtx);

        if (control.type == "hidden" || control.type == "password" ||
            control.type == "text" || control.type == "textarea")
            {
            var displayValue;
            if (gob.format != null && gob.getDisplayFormat != null)
                {
                var formatString;
                if (typeof gob.getDisplayFormat == "string")
                    formatString = gob.getDisplayFormat;
                else
                    formatString = gob.getDisplayFormat (exprCtx);
                displayValue = gob.format (formatString, value, control);
                }
            else if (value != null)
                displayValue = value.toString();
            else
                displayValue = "";
            control.value = displayValue;
            }
        }
}

function HTDW_DependCompute(gob)
{
    this.gob = gob;

    this.update = HTDW_DependComputeUpdate;
}

// DependColumn class
function HTDW_DependColumnUpdate(htmlDw, row, bSkipCurrent)
{
    var gob = this.gob;
    var control = htmlDw.findControl(gob.name, row, gob.region == 0);

    // don't mess with the current control if asked not to
    if (control != null &&
            ! (bSkipCurrent && control == htmlDw.currentControl))
        {
        // body
        if (gob.region == 0)
            row = row + gob.rowInDetail;
        // header
        else if (gob.region == 1)
            row = htmlDw.firstRow;
        // footer or summary
        else if (gob.region == 2 || gob.region == 3)
            row = htmlDw.lastRow;

        var value = htmlDw.rows[row][gob.colNum];

        if (control.type == "hidden" || control.type == "password" ||
            control.type == "text" || control.type == "textarea" ||
            control.type == "select-one")
            {
            var displayValue;
            if (gob.format != null && gob.getDisplayFormat != null)
                {
                var exprCtx = htmlDw.exprCtx;
                exprCtx.row = row;
                exprCtx.currentText = "";
                if (typeof gob.getDisplayFormat == "string")
                    formatString = gob.getDisplayFormat;
                else
                    formatString = gob.getDisplayFormat (exprCtx);
                displayValue = gob.format (formatString, value, control);
                }
            else if (value != null)
                displayValue = value.toString();
            else
                displayValue = "";
            control.value = displayValue;
            }
       else if(control.type == "checkbox")
         {
		 if (value != null)
             {
				var displayValue;
				displayValue = value.toString();
				if ( (control.checked==true) &&  (displayValue!=control.value.toString()))
						control.checked=false;
				else if  ((control.checked==false) && (displayValue!=control.value.toString()))
						control.checked=true;

				control.value = displayValue;
		     }
         }

      else if(control.length>1)
     		if(control[0].type="radio")
		        {
				var r;
				for (r=0;r<control.length;r++)
				{
					 displayValue = value.toString();
         				 if(control[r].value==displayValue)
         			 	{
         					control[r].checked=true;
						}

				 }

			}


       }
}

function HTDW_DependColumn(gob)
{
    this.gob = gob;

    this.update = HTDW_DependColumnUpdate;
}

// Column class
function HTDW_Column_addDepend(depend)
{
    if (this.dependents == null)
        this.dependents = new Array();

    this.dependents[this.dependents.length] = depend;
}

function HTDW_Column_updateDependents(htmlDw, row, bSkipCurrent)
{
    if (this.dependents != null)
        {
        for (var i=0; i < this.dependents.length; ++i)
            this.dependents[i].update (htmlDw, row, bSkipCurrent);
        }
}

function HTDW_ColumnClass(colId, name, convertFromStringFunc, typeValidationFunc, itemValidateFunc, validationMessageFunc, computeFunc, displayGobName)
{
    this.colId = colId;
    this.name = name;
    this.dependents = null;

    this.convertFromString = convertFromStringFunc;
    this.validateByType = typeValidationFunc;
    this.validateItem = itemValidateFunc;
    this.validationError = validationMessageFunc;
    this.compute = computeFunc;
    this.displayGobName = displayGobName;

    // interface functions
    this.addDepend = HTDW_Column_addDepend;
    this.updateDependents = HTDW_Column_updateDependents;

    this.displayValue = new Array();
    this.dataValue = new Array()
}

// DataWindow class
function HTDW_findControl(gobName, row, bInBody)
{
    var control = null;
    var controlExists;
    var controlName = gobName;
    var controlObject;

    if (bInBody)
        controlName += "_" + row;

    if (this.dataForm + "" != "undefined")
        {
        controlObject = 'this.dataForm.' + controlName;
        controlExists = eval('typeof ' + controlObject);
        if (controlExists == "object")
            control = eval(controlObject);
        }
    else if (this.navLayerForms[0] + "" != "undefined") // try array of Netscape layered forms
        {
        var rowObj = this.rows[row];
        var index = 0;
        if (bInBody)
            index = row * (rowObj.numCols - 1); // skip over for search
        for( ; index < this.navLayerForms.length; index++)
             {
             if (this.navLayerForms[index].elements[0].name == controlName)
                 {
                 control = this.navLayerForms[index].elements[0];
                 break;
                 }
             }
        }
    else
        control = null;

    return control;
}

function HTDW_itemGainFocus(newRow,newCol,control,gob)
{
    var bRowChanged = false;
	var bReadOnlyControl = false;
	var bNegativeTabIndexControl = false;

    // default arguments
    control.row = newRow;
    control.col = newCol;
    control.gob = gob;

    // if in the middle of trying to force focus back
    // to a control, ignore all other focus stuff
	if (this.forcingBackFocusTo != null)
	    {
	    // check if we have made it back yet
	    if (this.forcingBackFocusTo == control)
	    {
    		this.forcingBackFocusTo = null;
    		this.currentControl = control;
	    }
    	// don't do any other focus related stuff
    	return;
    	}

    // bail if we think that the current control already has focus
    // (Could happen if a button is pressed)
    if (this.currentControl == control &&
		!(this.currentControl.type == "hidden" || this.currentControl.type == "password" ||
		this.currentControl.type == "text" || this.currentControl.type == "textarea"))
        return;

	// check control attri
	if (control.readOnly + "" != "undefined")
		{
		bReadOnlyControl = control.readOnly;
		}
	if (control.tabIndex + "" != "undefined")
		{
		if(control.tabIndex < 0 )
			bNegativeTabIndexControl = true;
		}

	if (bNegativeTabIndexControl)
		{
		control.blur(); //don't allow focus.
		return;
		}

    if (newRow != -1)
        {
        if (newRow != this.currRow)
            {
            bRowChanged = true;


            // row focus changing event
            if (this.eventImplemented("RowFocusChanging"))
                {
                var result = _evtDefault(this.RowFocusChanging (this.currRow+1, newRow+1));
                // if 1 returned, don't allow focus to change (leave focus in last control to have gained focus
                if (result == 1)
                    {
                    this.restoreFocus();
                    // bail out early
                    return;
                    }
                }

            }

        this.currRow = newRow;
        }
    if (newCol != -1)
        this.currCol = newCol;

    this.currentControl = control;

    // update the displayed value to be in editible form
    if (newRow != -1 && newCol != -1 &&
	    (this.currentControl.type == "hidden" || this.currentControl.type == "password" ||
		 this.currentControl.type == "text" ||this.currentControl.type == "textarea"))
        {
        var value = this.rows[newRow][newCol];
        if (gob.format != null)
            {
            var displayValue;

            if (gob.getEditFormat != null)
                {
                var formatString;
                if (typeof gob.getEditFormat == "string")
                    formatString = gob.getEditFormat;
                else
                    {
                    var exprCtx = this.exprCtx;
                    exprCtx.row = control.row;
                    exprCtx.currentText = "";
                    formatString = gob.getEditFormat (exprCtx);
                    }
                displayValue = gob.format (formatString, value, this.currentControl);
                }
            else if (value != null)
                displayValue = value.toString();
            else
                displayValue = "";
            this.currentControl.value = displayValue;
            }
        else if ( value != null )
            {
            // Do not compare against Date/Time if no date fields have been defined
            if (!bDateTimeProcessingEnabled ||
               (value.toString != DW_DatetimeToString &&
                value.toString != DW_DateToString &&
                value.toString != DW_TimeToString))
                this.currentControl.value = value.toString( );
            }
        else
            this.currentControl.value = "";
        }

    // can only programatically change border on IE4
    if (control.gob.bFocusRect && HTDW_DataWindowClass.isIE4)
        {
        this.currentControlBorder = control.style.borderStyle;
        control.style.borderStyle = "dotted";
        }


    // row focus changed event
    if (bRowChanged && this.eventImplemented("RowFocusChanged"))
        this.RowFocusChanged (newRow+1)

    // item focus changed event
    if (newCol != -1 && this.eventImplemented("ItemFocusChanged"))
        this.ItemFocusChanged (newRow+1, this.cols[newCol].name)

}

function HTDW_itemLoseFocus(control)
{
	var bReadOnlyControl = false;
	var bNegativeTabIndexControl = false;

	// check control attri
	if (control.readOnly + "" != "undefined")
		{
		bReadOnlyControl = control.readOnly;
		}
	if (control.tabIndex + "" != "undefined")
		{
		if( control.tabIndex < 0 )
			bNegativeTabIndexControl = true;
		}

	if (bNegativeTabIndexControl)
		{
		return 2;
		}

    // restore border
    // can only programatically change border on IE4
    if (control.gob.bFocusRect && HTDW_DataWindowClass.isIE4 && this.currentControl == control)
        control.style.borderStyle = this.currentControlBorder;

    // don't do validation if in the middle of forcing focus
    // due to validation error (endless loop could happen)
    if (this.forcingBackFocusTo != null)
        return 2;

    if (this.currentControl != control)
        {
        //alert("Focus problem! Control losing focus is not current control!");
        // fake it out
        this.currentControl = control;
        }

	var gob = control.gob;
	if (gob.getEditFormat != null)
	{
		if (typeof gob.getEditFormat == "string")
		gMask = gob.getEditFormat;
		else
		{
			var exprCtx = this.exprCtx;
			exprCtx.row = control.row;
			exprCtx.currentText = "";
			gMask = gob.getEditFormat (exprCtx);
		}

		// code table's edit format is a dummy "CodeTable" format for info.
		if (gob.bUseCodeTable)
			gMask = "";
	}

    if (!control.bChanged)  // check if Change misfired (losing focus beyond frame?)
        {
        var newValue;
        var row = control.row;
        var col = control.col;
        var rowObj = this.rows[row];
        var colObj = this.cols[col];

        if (control.type == "select-one")
            newValue = control.options[control.selectedIndex].value;
        else
            newValue = control.value;

        if (newValue == "")
            {
            if (control.gob.bNilIsNull)
				{
				if (rowObj[col] != null)
					control.bChanged = true;
				}
			else if (rowObj[col] != null && rowObj[col] != "")  // for inserts
				control.bChanged = true;
            }
        else if (colObj.convertFromString != null)
            {
            var convertedValue;
		    if (colObj.convertFromString == parseInt)
			{
				var reg = /,/g;
				var noComma = newValue.replace(reg, "");
				convertedValue = colObj.convertFromString (noComma, 10);
			}
			else
				convertedValue = colObj.convertFromString (newValue);

            if (rowObj[col] != convertedValue)
                control.bChanged = true;
            }
        else
            {
            if (rowObj[col] != newValue)
                control.bChanged = true;
            }
        }

    var result = this.AcceptText();

	gMask = "";

    if (result == 1)
        {
        // reformat the data
        var gob = control.gob;
        var value = this.rows[control.row][gob.colNum];
        if (control.type == "hidden" || control.type == "password" ||
            control.type == "text" || control.type == "textarea")
            {
            if (gob.format != null)
                {
                var displayValue;
                if (gob.getDisplayFormat != null)
                    {
                    var formatString;
                    if (typeof gob.getDisplayFormat == "string")
                        formatString = gob.getDisplayFormat;
                    else
                        {
                        var exprCtx = this.exprCtx;
                        exprCtx.row = control.row;
                        exprCtx.currentText = "";
                        formatString = gob.getDisplayFormat (exprCtx);                        
                        }
                    displayValue = gob.format (formatString, value, this.currentControl);                    
                    }
                else if (value != null)
                    displayValue = value.toString();
                else
                    displayValue = "";
                this.currentControl.value = displayValue;
                }
            else if ( value != null )
                {
                // Do not compare against Date/Time if no date fields have been defined
                if (!bDateTimeProcessingEnabled ||
                    (value.toString != DW_DatetimeToString &&
                     value.toString != DW_DateToString &&
                     value.toString != DW_TimeToString))
                     this.currentControl.value = value.toString( );
                }
            else
                this.currentControl.value = "";
            }
        }

    return result;
}

function HTDW_selectControlContent(control)
{
	var bNegativeTabIndexControl = false;
	if(control != null)
		{
		if (control.tabIndex + "" != "undefined")
			{
			if( control.tabIndex < 0 )
				bNegativeTabIndexControl = true;
			}

		if(!bNegativeTabIndexControl)
			{
			control.select();
			}
		}
}

function HTDW_getChanges()
{
    var changes = "";
    var index, rowObj;
    for (index=0; index < this.rows.length; ++index)
        {
        rowObj = this.rows[index];
        if (rowObj != null)
            {
            HTDW_RowClass.dumpRow (index, rowObj);
            changes += HTDW_RowClass.generateChange (index, rowObj);
            }
        }
    return changes;
}

function HTDW_itemError(row, col, exprCtx, bIsRequired)
{
    var colObj = this.cols[col];
    var result = 0;


    // item error event
    if (this.eventImplemented("ItemError"))
        result = _evtDefault(this.ItemError (row+1, colObj.name, exprCtx.currentText))


    // map unknown results to 0
    if (result != 1 && result != 2 && result != 3)
        result = 0;

    if (result == 0)
        {
        var sMessage;
        if (colObj.validationError != null)
            sMessage = colObj.validationError (exprCtx);
        else if (bIsRequired)
            sMessage = "Value required for item '" + colObj.name + "'.";
        else
            sMessage = "Item '" + exprCtx.currentText + "' does not pass validation test.";

        alert (sMessage);
        }

    return result;
}

function HTDW_restoreFocus()
{
    if (this.currentControl != null)
        {
        var bDocHasFocus = true;
        var bIsDefined = false;

        if ( (document.hasFocus + "" != "undefined") && (this.currentControl.setActive + "" != "undefined") )
            bIsDefined = true;

        if ( bIsDefined )
            {
            bDocHasFocus = document.hasFocus();
            }

        if(bDocHasFocus == false)
            this.currentControl.setActive(); // CR323659
        else
            this.currentControl.focus();
        }
}



function HTDW_setCheckboxValue(control, chkValue, unchkValue)
{
    if (control.checked)
        control.value = chkValue;
    else
        control.value = unchkValue;
}

function HTDW_acceptText()
{
    // nothing to do if no current control
    if (this.currentControl == null)
        return 1;

    var control = this.currentControl;
    var row = control.row;
    var col = control.col;
    var bRequired = control.gob.bRequired;
    var colObj = this.cols[col];
    var bIsValid = true;
    var exprCtx = this.exprCtx;
    var validAction = 2;  // default to accept
    var newValue;
    if (control.type == "select-one")
        newValue = control.options[control.selectedIndex].value;
    else
        newValue = control.value;

    exprCtx.row = row;
    exprCtx.currentText = newValue;

    // check if value required
    if (bRequired && ! control.bChanged)
        {
        if (this.rows[row][col] == null)
            validAction = this.itemError (row, col, exprCtx, true);
        }
    else if (bRequired && control.gob.bNilIsNull && newValue == "")
        validAction = this.itemError (row, col, exprCtx, true);

    if (control.bChanged)
        {
        if (bIsValid && colObj.validateByType != null)
            bIsValid = colObj.validateByType(newValue, control.gob.bNilIsNull);

        if (bIsValid && colObj.validateItem != null)
            bIsValid = colObj.validateItem (exprCtx);


        // item changed event
        if (bIsValid && this.eventImplemented("ItemChanged"))
            {
            validAction = _evtDefault(this.ItemChanged (row+1, colObj.name, newValue));
            // map unknown results to 0
            if (validAction != 1 && validAction != 2)
                validAction = 0;
            // map itemChanged action codes to itemError action codes
            if (validAction == 0) // accept value
                validAction = 2;
            else
                {
                bIsValid = false;
                if (validAction == 1) // reject value, no focus change
                    validAction = 1;
                else // reject value, allow focus change
                    validAction = 3;
                }
            }


        if (! bIsValid)
            validAction = this.itemError (row, col, exprCtx, false);

        if (validAction == 2)
            {

            var rowObj = this.rows[row];
            if (control.gob.bNilIsNull && newValue == "")
                {
                if (rowObj[col] != null)
                    {
                    rowObj[col] = null;
                    if (rowObj[0].itemStatus != DW_ITEMSTATUS_MODIFIED &&
                        rowObj[0].itemStatus != DW_ITEMSTATUS_NEW_MODIFIED) {
                        this.modifiedCount++;
if (this.commitbutton != '') {
	controlObject = 'this.dataForm.' + this.commitbutton
	controlExists = eval('typeof ' + controlObject);
	if (controlExists == "object") {
	  control = eval(controlObject);
	  control.style.visibility = 'visible'
	}
}
		    }
                    rowObj[0].colModified[col] = true;
                    if (rowObj[0].itemStatus == DW_ITEMSTATUS_NOCHANGE)
                        rowObj[0].itemStatus = DW_ITEMSTATUS_MODIFIED;
                    else if (rowObj[0].itemStatus == DW_ITEMSTATUS_NEW)
                        rowObj[0].itemStatus = DW_ITEMSTATUS_NEW_MODIFIED;
                    }
                }
            else if (colObj.convertFromString != null)
                {
				var convertedValue;
				if (colObj.convertFromString == parseInt)
					convertedValue = colObj.convertFromString (newValue, 10);
				else
					convertedValue = colObj.convertFromString (newValue);

                if ('' + rowObj[col] != '' + convertedValue)
                    {
                    rowObj[col] = convertedValue;
                    if (rowObj[0].itemStatus != DW_ITEMSTATUS_MODIFIED &&
                        rowObj[0].itemStatus != DW_ITEMSTATUS_NEW_MODIFIED) {
                        this.modifiedCount++;
if (this.commitbutton != '') {
	controlObject = 'this.dataForm.' + this.commitbutton
	controlExists = eval('typeof ' + controlObject);
	if (controlExists == "object") {
	  control = eval(controlObject);
	  control.style.visibility = 'visible'
	}
}
		    }
                    rowObj[0].colModified[col] = true;
                    if (rowObj[0].itemStatus == DW_ITEMSTATUS_NOCHANGE)
                        rowObj[0].itemStatus = DW_ITEMSTATUS_MODIFIED;
                    else if (rowObj[0].itemStatus == DW_ITEMSTATUS_NEW)
                        rowObj[0].itemStatus = DW_ITEMSTATUS_NEW_MODIFIED;
                    }
                }
            else
                {
                if (rowObj[col] != newValue)
                    {
                    rowObj[col] = newValue;
                    if (rowObj[0].itemStatus != DW_ITEMSTATUS_MODIFIED &&
                        rowObj[0].itemStatus != DW_ITEMSTATUS_NEW_MODIFIED) {
                        this.modifiedCount++;
if (this.commitbutton != '') {
	controlObject = 'this.dataForm.' + this.commitbutton
	controlExists = eval('typeof ' + controlObject);
	if (controlExists == "object") {
	  control = eval(controlObject);
	  control.style.visibility = 'visible'
	}
}		    }
                    rowObj[0].colModified[col] = true;
                    if (rowObj[0].itemStatus == DW_ITEMSTATUS_NOCHANGE)
                        rowObj[0].itemStatus = DW_ITEMSTATUS_MODIFIED;
                    else if (rowObj[0].itemStatus == DW_ITEMSTATUS_NEW)
                        rowObj[0].itemStatus = DW_ITEMSTATUS_NEW_MODIFIED;
                    }

                }
            control.bChanged = false;
            // skip current control
            colObj.updateDependents(this, row, true);
            }
        }

    // force focus back if an error (focus change will happen after we return!)
    if (validAction < 2)
        {
        this.forcingBackFocusTo = control;
        control.focus();
        }

    var result = (validAction < 2) ? -1 : 1;

    return result;
    // this return will only be used if we are not an input form
    return 1;
}


// if false returned, don't allow focus to change or action to happen (leave focus in last control to have gained focus
function HTDW_itemClicked(row, col, objName)
{
    var evtResult = 0;

    // CR228156 - click on DDDW column fires a validation error in IE5.x - Partha
    if (objName.substring(0,12) == 'compute_hand') {
    	dwrows = this.lastRow;
    	for (var i=this.firstRow; i <=dwrows; i++) {
		controlObject = 'this.dataForm.hand' + i;
		control = eval(controlObject);
		control.style.visibility = 'hidden'
		//control.src='none.gif'
	}
    	controlObject = 'this.dataForm.hand' + row;
    	control = eval(controlObject);
	//control.src='apply.gif'
	control.style.visibility = 'visible'
	this.clickedRow = row
	this.currRow = row
    }
    if (this.currentControl != null)
    {
	if ( this.currentControl.type == "select-one" )
	{
	    if ( HTDW_DataWindowClass.isIE4
		&& this.currentControl.gob.bRequired == true
		&& this.currentControl.value == "" )
            	return false ;
	    else
		if (this.AcceptText() != 1)
			return false;

	}
    	else if (this.currentControl.type == "checkbox"
		|| this.currentControl.type == "radio"
		|| this.currentControl.type == "select-multiple" )
	{
        	if (this.AcceptText() != 1)
			return false;
	}
    }

    if (this.eventImplemented("Clicked"))
        evtResult = _evtDefault(this.Clicked (row+1, objName));

    // prevent clicked event from bubbling up in IE4 or higher   mick comment out for bug fix
    //if (HTDW_DataWindowClass.isIE4)
    //    window.event.cancelBubble = true;

    this.clickedRow = row;
    this.clickedCol = col;

    if (col != '-1' && objName != 'datawindow') {
    tmpcontrolObject = 'this.dataForm.hand' + row;
    controlExists = eval('typeof ' + tmpcontrolObject);
    if (controlExists == "object" ) {
         this.clickedRow = row
	 this.currRow = row
         dwrows = this.lastRow;
   	 for (var i=this.firstRow; i <=dwrows; i++) {
		tmpcontrolObject = 'this.dataForm.hand' + i;
		tmpcontrol = eval(tmpcontrolObject);
		tmpcontrol.style.visibility = 'hidden'
	}
	tmpcontrolObject = 'this.dataForm.hand' + row;
    	tmpcontrol = eval(tmpcontrolObject);
    	tmpcontrol.style.visibility = 'visible'
    }
    }

    return evtResult != 1;
}

function HTDW_performAction(action)
{
    this.action = action;
    if (this.b4GLWeb)
	    {
        // cause the surrounding page to be submitted
        psPage.Submit();
		}
	else // deal with it like in 7.0
        {
	   	    var rc = 0;
   	    // OnSubmit can prevent the page from being submitted by returning 1
   	    if (this.eventImplemented("OnSubmit"))
            rc = _evtDefault(this.OnSubmit ());
        if (rc == 0)
            {
       	    this.actionField.value = this.action;
   	        this.contextField.value = this.GetFullContext();
            this.submitForm.submit();
            }
	        }
}

function HTDW_GetFullContext()
{
    var     result = this.context;

    result += "(";
    result += this.getChanges();
    if (this.currRow != -1)
        result += "(row " + this.currRow + ")";
    if (this.sortString != null)
        result += "(sortString '" + escapeString (this.sortString) + "')";
    result += ")";

    return result ;
}

function HTDW_buttonPress(action, row, buttonName)
{
    var evtResult;

    if (this.dwrequired() == -1) return;

    // false from clicked will cancel processing
    if (!this.itemClicked(row, -1, buttonName))
        return;

    // button clicking event
    if (this.eventImplemented("ButtonClicking"))
        {
        evtResult = _evtDefault(this.ButtonClicking (row+1, buttonName));
        // non-zero return will cancel processing
        if (evtResult != 0)
            return;
        }

    // make sure all changes have been recorded
    if (action != "" && this.AcceptText() != 1)
        // cancel processing if AcceptText fails
        return;

    // update start event
    if (action == "Update" && this.eventImplemented("UpdateStart"))
        {
        evtResult = _evtDefault(this.UpdateStart ());
        // a return of 1 will cancel action
        if (evtResult == 1)
            return;
        }
	this.modifiedCount =0;
    if (action == "Print")
	    {
        window.print();
        return;
        }
    // an action of "" is a user defined button which doesn't cause a page reload
    if (action != "")
		this.performAction(action);
    else
        {
        // button clicked event
        if (this.eventImplemented("ButtonClicked"))
            this.ButtonClicked (row+1, buttonName)
        }
}

function HTDW_getColNum(col)
{
    if (typeof col == "string")
        {
        for (var i=1; i< this.cols.length; ++i)
            {
            var colObj = this.cols[i];
            if (colObj.name == col)
                return i;
            }
        }
    else
        return col;

    // if we get here, then we couldn't find it
    return -1;
}

function HTDW_DeletedCount()
{
	return this.deletedCount;
}

function HTDW_DeleteRow(row)
{
	if(this.AcceptText() == 1)
		{
		if (row > 0)
    		this.currRow = row-1;
		this.performAction ("DeleteRow");
		return 1;
		}
	else
		return -1;
}

function HTDW_GetClickedColumn()
{
	return this.clickedCol;
}

function HTDW_GetClickedRow()
{
	return this.clickedRow + 1;
}

function HTDW_GetColumn()
{
	return this.currCol;
}

function HTDW_GetNextModified(startRow)
{
    var nextModified = 0;
    var index, rowObj;

    if (startRow == null)
        return null;

    for (index=startRow-1; index < this.rows.length; ++index)
        {
        rowObj = this.rows[index];
        if (rowObj != null)
            {
            if (rowObj[0].itemStatus == DW_ITEMSTATUS_MODIFIED ||
                rowObj[0].itemStatus == DW_ITEMSTATUS_NEW_MODIFIED)
                {
                nextModified = index+1;
                break;
                }
            }
        }
    return nextModified;
}

function HTDW_GetRow()
{
	return this.currRow + 1;
}

function HTDW_GetItem(row, col)
{
	var result;
	var colNum = this.getColNum(col);
    var rowObj = this.rows[row-1];

	if (colNum == -1 ||
	        (rowObj + "" == "undefined") ||
			rowObj[colNum] + "" == "undefined")
		result = -1;
	else
		result = rowObj[colNum];

	return result;
}

function HTDW_GetItemStatus(row, col)
{
    if (row == null || col == null)
        return null;

    var dwItemStatus = DW_ITEMSTATUS_NOCHANGE;
    var colNum = this.getColNum(col);
    var rowObj = this.rows[row-1];

    if (colNum == -1 ||
            (rowObj + "" == "undefined") ||
            (colNum > 0 && rowObj[colNum] + "" == "undefined"))
        dwItemStatus = -1;
    else if (colNum == 0)
            dwItemStatus = rowObj[0].itemStatus;
    else
        {
        if (rowObj[0].colModified[colNum])
            dwItemStatus = DW_ITEMSTATUS_MODIFIED;
        }

	return dwItemStatus;
}

function HTDW_InsertRow(row)
{
	if(this.AcceptText() == 1)
		{
		this.currRow = row-1;
		this.performAction ("InsertRow");
		return 1;
		}
	else
		return -1;
}

function HTDW_ModifiedCount()
{
    return this.modifiedCount;
}

function HTDW_Retrieve()
{
	if(this.AcceptText() == 1)
		{
		this.performAction ("Retrieve");
		return 1;
		}
	else
		return -1;
}

function HTDW_RowCount()
{
	return this.rowCount;
}

function HTDW_ScrollFirstPage()
{
	if(this.AcceptText() == 1)
		{
		this.performAction ("PageFirst");
		return 1;
		}
	else
		return -1;
}

function HTDW_ScrollLastPage()
{
	if(this.AcceptText() == 1)
		{
		this.performAction ("PageLast");
		return 1;
		}
	else
		return -1;
}

function HTDW_ScrollNextPage()
{
	if(this.AcceptText() == 1)
		{
		this.performAction ("PageNext");
		return 1;
		}
	else
		return -1;
}

function HTDW_ScrollPriorPage()
{
	if(this.AcceptText() == 1)
		{
		this.performAction ("PagePrior");
		return 1;
		}
	else
		return -1;
}

function HTDW_SetItem(row,col,value)
{

	var result;
	var colNum = this.getColNum(col);
    var rowObj = this.rows[row-1];
	if (colNum == -1 ||
	        (rowObj + "" == "undefined") ||
			rowObj[colNum] + "" == "undefined")
		result = -1;
	else
		{
        if (rowObj[colNum] != value)
			{
			rowObj[colNum] = value;
            if (rowObj[0].itemStatus != DW_ITEMSTATUS_MODIFIED &&
                rowObj[0].itemStatus != DW_ITEMSTATUS_NEW_MODIFIED) {
			this.modifiedCount++;
			if (this.commitbutton != '') {
				controlObject = 'this.dataForm.' + this.commitbutton
				controlExists = eval('typeof ' + controlObject);
				if (controlExists == "object") {
				  control = eval(controlObject);
				  control.style.visibility = 'visible'
				}
			}
		}
			rowObj[0].colModified[colNum] = true;
            if (rowObj[0].itemStatus == DW_ITEMSTATUS_NOCHANGE)
                rowObj[0].itemStatus = DW_ITEMSTATUS_MODIFIED;
            else if (rowObj[0].itemStatus == DW_ITEMSTATUS_NEW)
                rowObj[0].itemStatus = DW_ITEMSTATUS_NEW_MODIFIED;
			}

		// update them all
		this.cols[colNum].updateDependents(this, row-1, false);
		result = 1;
		}

	return result;
}

function HTDW_SetColumn(col)
{
    var result = -1;
	var colNum = this.getColNum(col);
    if (colNum != -1)
        {
        var colObj = this.cols[colNum];
        if (typeof colObj != "undefined" && colObj.displayGobName != null)
            {
            var control = this.findControl(colObj.displayGobName, this.currRow, true);
            // if we can't find a control, then we can't set the column
            if (control != null)
                {
                // force focus onto the found control
                // the onFocus event will change the currency variables
                control.focus();
                result = 1;
                }
            }
        }
	return result;
}

function HTDW_SetRow(row)
{
    if(row < this.firstRow + 1) {
    	row = this.firstRow + 1
    }
    var result = -1;
    row -= 1;
    this.currRow = row
    this.clickedRow = row
    //check compute_hand
    controlObject = 'this.dataForm.hand' + row
    controlExists = eval('typeof ' + controlObject);
    if (controlExists == "object") {
      dwrows = this.lastRow;
      for (var i=this.firstRow; i <=dwrows; i++) {
      		controlObject = 'this.dataForm.hand' + i;
      		control = eval(controlObject);
      		control.style.visibility = 'hidden'
      		//control.src='none.gif'
	}
      controlObject = 'this.dataForm.hand' + row
      //control.src='apply.gif'
      control = eval(controlObject);
      control.style.visibility = 'visible'
    }

    var colNum = this.currCol;
    if (colNum != -1)
        {

        var colObj = this.cols[colNum];
        if (typeof colObj != "undefined" && colObj.displayGobName != null)
            {
            var control = this.findControl(colObj.displayGobName, row, true);
            // if we can't find a control, then we can't set the row
            if (control != null)
                {
                // force focus onto the found control,
                // the onFocus event will change the currency variables
                control.focus();
                result = 1;
                }
            }
        }
	return result;
}

function HTDW_SetSort(sortString)
{
	this.sortString = sortString;
	return 1;
}

function HTDW_Sort()
{
	if(this.AcceptText() == 1)
		{
		this.performAction ("Sort");
		return 1;
		}
	else
		return -1;
}

function HTDW_Update()
{
	if(this.AcceptText() == 1)
		{
		this.performAction ("Update");
		return 1;
		}
	else
		return -1;
}

function HTDW_hidecommit(buttname){
		this.commitbutton = buttname
		controlObject = 'this.dataForm.' + this.commitbutton
		controlExists = eval('typeof ' + controlObject);
		if (controlExists != "object") {
			this.commitbutton = buttname + '_0'
			controlObject = 'this.dataForm.' + this.commitbutton
			controlExists = eval('typeof ' + controlObject);
		}
		if (controlExists == "object") {
			control = eval(controlObject);
			control.style.visibility = 'hidden'
		}

}

function HTDW_columnsort(colname){
	ls_current_sort = this.sortString;
	//alert(ls_current_sort.substring(0, colname.length ) + '-' + colname)
	if(colname == ls_current_sort.substring(0, colname.length )) {
		ls_sort = ls_current_sort.substring(ls_current_sort.length-1,ls_current_sort.length);
		if (ls_sort == 'A') {
			this.SetSort(colname + ' D');
			this.submitForm.sort.value = colname + ' D'
		}
		else {
			this.SetSort(colname + ' A');
			this.submitForm.sort.value = colname + ' A'
		}
	}
	else {
		this.SetSort(colname + ' A');
		this.submitForm.sort.value = colname + ' A'
	}

	this.Sort();

};

//////////////////micks functions
function HTDW_dwrequired()  //check required fields
{

	for (var r=0; r <=this.rows.length-1; r++)
	{
		for (var i=1; i <=this.cols.length-1; i++)
		{
			ls_name = this.cols[i].name;
			ll_col = this.cols[i].colId;
			ls_valid = '' + this.gobs[ls_name];
			if (ls_valid != 'undefined'){
				var lb_required = this.gobs[ls_name].bRequired;
				if (lb_required == true) {
					ls_value = '' + this.rows[r][ll_col]
					if ((DW_Trim(ls_value ) == "") || (ls_value  == 'null' )){
						re = /_/g;
						ls_name = ls_name.replace(re, " ");
						ls_first = ls_name.substring(0, 1)
						ls_first = ls_first.toUpperCase( )
						ls_last = ls_name.substring(1,ls_name.length)
						ls_name = ls_first + ls_last
						alert(ls_name + ' must be entered ')
						return(-1)
					}
				}
			}
		}
	}
	return 1
}


function DW_EditKeyPressed(nCase)
{
	if(nCase == 1)
	{
		event.srcElement.value += String.fromCharCode(event.keyCode).toUpperCase();
		event.returnValue = false;
	}
	else if (nCase == 2)
	{
		event.srcElement.value += String.fromCharCode(event.keyCode).toLowerCase();
		event.returnValue = false;
	}
}

function HTDW_DataWindowClass(name, submitForm, actionField, contextField)
{
    // if used in 4GL web, these will not be defined!
    if (arguments.length == 1)
        {
        submitForm = null;
        actionField = null;
        contextField = null;
        }

    this.name = name;
    this.submitForm = submitForm;
    this.actionField = actionField;
    this.contextField = contextField;
    this.sortString = null;
    this.action = "";
    this.commitbutton = "";

    // private functions
    this.buttonPress = HTDW_buttonPress;
	this.performAction = HTDW_performAction;

    this.eventImplemented = HTDW_eventImplemented;
    this.itemClicked = HTDW_itemClicked;

    // public function
    this.GetFullContext = HTDW_GetFullContext;

    this.currRow = -1;
    this.currCol = -1;
    this.forcingBackFocusTo = null;
    this.currentControl = null;
    this.bSingleRow = false;

    this.gobs = new Object();
    this.rows = new Array();
    this.cols = new Array();
    this.navLayerForms = new Array();
    this.exprCtx = new HTDW_exprContextClass(this);

    // private functions
    this.getChanges = HTDW_getChanges;
    this.itemLoseFocus = HTDW_itemLoseFocus;
    this.selectControlContent = HTDW_selectControlContent;
    this.itemError = HTDW_itemError;
    this.itemGainFocus = HTDW_itemGainFocus;
    this.restoreFocus = HTDW_restoreFocus;
    this.findControl = HTDW_findControl;
    this.setCheckboxValue = HTDW_setCheckboxValue;

    // public functions
    this.AcceptText = HTDW_acceptText;

    // private functions
    this.getColNum = HTDW_getColNum;

    // public functions
    this.AcceptText = HTDW_acceptText;
	this.DeletedCount = HTDW_DeletedCount;
	this.DeleteRow = HTDW_DeleteRow;
	this.GetClickedColumn = HTDW_GetClickedColumn;
	this.GetClickedRow = HTDW_GetClickedRow;
	this.GetColumn = HTDW_GetColumn;
	this.GetNextModified = HTDW_GetNextModified;
	this.GetRow = HTDW_GetRow;
	this.GetItem = HTDW_GetItem;
	this.GetItemStatus = HTDW_GetItemStatus;
	this.InsertRow = HTDW_InsertRow;
	this.ModifiedCount = HTDW_ModifiedCount;
	this.Retrieve = HTDW_Retrieve;
	this.RowCount = HTDW_RowCount;
	this.ScrollFirstPage = HTDW_ScrollFirstPage;
	this.ScrollLastPage = HTDW_ScrollLastPage
	this.ScrollNextPage = HTDW_ScrollNextPage
	this.ScrollPriorPage = HTDW_ScrollPriorPage
	this.SetItem = HTDW_SetItem
	this.SetColumn = HTDW_SetColumn
	this.SetRow = HTDW_SetRow
	this.SetSort = HTDW_SetSort
	this.Sort = HTDW_Sort;
	this.Update = HTDW_Update
	this.hidecommit = HTDW_hidecommit; //micks
	this.columnsort = HTDW_columnsort; //micks
	this.dwrequired = HTDW_dwrequired;  //micks
}

// determine the client browser
// this should be used only where ABSOLUTELY necessary
// Generic JavaScript should be used where ever possible
HTDW_DataWindowClass.isNav4 = false;
HTDW_DataWindowClass.isIE4 = false;
if (parseInt(navigator.appVersion) >= 4)
    {
    HTDW_DataWindowClass.isNav4 = (navigator.appName == "Netscape");
    HTDW_DataWindowClass.isIE4 = (navigator.appName.indexOf("Microsoft") != -1);
    }

function DW_ShowCodeTableDisplayValue(formatString, value)
{
    if (value == null)
        return "";
    var result = value.toString();
    var i;
    for (i = 0; i < this.column.displayValue.length; i++)
        if (value.toString() == this.column.dataValue[i])
            {
            result = this.column.displayValue[i];
            i = this.column.displayValue.length;
            }

   return result;
}

// between is inclusive
function DW_Between(val, test1, test2)
{
    if (val == null || test1 == null || test2 == null)
        return false;

    if (test1 <= val && val <= test2)
        return true;
    else
        return false;
}

function DW_BetweenByFunc(val, test1, test2, func)
{
    return func(test1, val) >= 0 && func(val, test2) <= 0;
}

function DW_In(testValue)
{
    var bResult = false;

    for (var i=1; i < arguments.length; i++)
        {
        if (arguments[i] == testValue)
            {
            bResult = true;
            break;
            }
        }
    return bResult;
}

function DW_InByFunc(testValue, func)
{
    var bResult = false;

    for (var i=2; i < arguments.length; i++)
        {
        if (func(arguments[i],testValue) == 0)
            {
            bResult = true;
            break;
            }
        }
    return bResult;
}

pop1 = false;
popup = null;
function popQuiz(){
	if (pop1 == true){
		popup.focus();
		}
	}

function openlookup(as_page){
	popup = window.open(as_page,'_blank','width=650,height=400,top=20,left=20,status=1,resizeable=0,scrollbars=1,location=1');
}

obj_selected="";
chkState='true';

function tabSwap(obj_id, state) {
	vistype1="";
	vistype2="hover";
	vistype3="select";
	if (chkState=='true'){
		if (obj_id != obj_selected) {
			button=document.getElementById(obj_id);
			selected=document.getElementById(obj_selected);
			if ( state=='click') {
				selected.className=(vistype1);
				button.className=(vistype3);
				obj_selected=(obj_id);
				}
			else if ( state=='over') {
				button.className=(vistype2);
				}
			else if ( state=='off') {
				button.className=(vistype1);
				}
			}
		if ( state=='open') {
			obj_selected=(obj_id);
			document.getElementById(obj_selected).className=(vistype3);
			}
		chkState='true';
		}
	}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function Delete_Cookie(name) {
    document.cookie = name + "=;expires=Thu, 01-Jan-1970 00:00:01 GMT";
    return;
}


function toggle(to)
{
	var isNav4 = false;
	var isIE4 = false;
	var isNN6 = false;
	if (document.all) isIE4=true;
	else if (document.layers) isNav4=true;
	else if (document.getElementById) isNN6=true;
	if (isIE4)
	  currentdw = window['dw' + (obj_selected.charAt(2))]
	else if (isNav4)
	  currentdw = eval("document." + 'dw' + (obj_selected.charAt(2)));
	else if (isNN6)
		currentdw = window['dw' + (obj_selected.charAt(2))]
	li_count = currentdw.modifiedCount;
	var tabSave = document.anchors[(obj_selected.charAt(2)-1)].name;
	if (obj_selected.charAt(2) == to.charAt(2))
	{
		li_count = 0;
	}
	retVal = 0;
	if ((li_count > 0) && (ls_autosave == 'A'))
	{
		retVal = 6;
	}
	else if ((li_count > 0) && (ls_autosave == 'P'))
	{
		if (isIE4)
		{
			retVal = makeMsgBox("Change Pages","Do you wish to save changes to "+tabSave+"?",32,3,256,4096);
		}
		else
		{
		  	lb_temp = confirm('Do you wish to save changes to '+tabSave+'?');
		  	if (lb_temp == true)
		  	{
				retVal = 6
			}
			else
			{
			  	retVal = 7
			}
		}
	}
	if (retVal == 2)
	{
		chkState='false';
		return;
	}
	else if(retVal == 6)
	{
		ls_right = to.substring(2,3);
	  	SetCookie ('currenttab', ls_right);
		chkState='true';
		currentdw.performAction("update");
	  	return;
	}
	else if(retVal == 7)
	{
		chkState='true';
	}
	Delete_Cookie('currenttab');
	ls_right = to.substring(2,3);
	SetCookie ('currenttab', ls_right);
	cleartabs( );
	currentdw = eval("document.getElementById('" + to + "')");
	currentdw.style.display = "";
	if ((document.getElementById("header"+obj_selected.charAt(2))!=null) || (document.getElementById("header"+obj_selected.charAt(2))!=undefined))
	{
		document.getElementById("header"+obj_selected.charAt(2)).style.display="none";
		document.getElementById("header"+to.charAt(2)).style.display="block";
	}
}

	function form_query(ls_field, ls_oper, ls_value){
		if (ls_value.indexOf("*", 0) >= 0 && ls_oper=="="){
			ls_out = ls_field + " like ^" + ls_value + "^";
			}
		else if (ls_value.indexOf("*", 0) >= 0  && ls_oper=="<>"){
				ls_out = ls_field + " not like ^" + ls_value + "^";
			}
		else {
			ls_out = ls_field + " " + ls_oper + " ^" + ls_value + "^";
			}
		return ls_out;
		}

	function LoadRM(objID){
		document.getElementById(objID).style.display='none';
	}
	//Removes Objects from View

	function nothing(){
		return;
		}




var targetRedirector=null;

function setRedirector(e)
{
	targetRedirector = "uh-oh";
	if (!e)
	{
		var e = window.top.menu.event;
	}
	var newTarg;	//the object that fired the event
	if (e.target)
	{
		newTarg = e.target;
	}
	else if (e.srcElement)
	{
		newTarg = e.srcElement;
	}
	if (newTarg.nodeType == 3) // defeat Safari bug
	{
		newTarg = newTarg.parentNode;
	}
	var chosenOne=false;
	while (!chosenOne)
	{
		if (newTarg.nodeName=="a" || newTarg.nodeName=="A")
		{
			chosenOne=true;
		}
		else
		{
			newTarg=newTarg.parentNode;
		}
	}
	targetRedirector=newTarg.href;
	targetRedirector=targetRedirector.substring((targetRedirector.lastIndexOf("/")+1),targetRedirector.length);
}

if (window.top.menu!=undefined || window.top.menu!=null)
{
	if (window.top.menu.document.links.length>0)
	{
		for (i=0; i<window.top.menu.document.links.length; i++)
		{
			window.top.menu.document.links[i].onclick = setRedirector;
		}
	}	//registers the click in the main menu
}

function promptSave()
{
	var isNav4 = false;
	var isIE4 = false;
	var isNN6 = false;
	if (document.all) isIE4=true;
	else if (document.layers) isNav4=true;
	else if (document.getElementById) isNN6=true;
	if (obj_selected!="")
	{
		if (isIE4)
		{
			currentdw = window['dw' + (obj_selected.charAt(2))];
		}
		else if (isNav4)
		{
			currentdw = eval("document." + 'dw' + (obj_selected.charAt(2)));
		}
		else if (isNN6)
		{
			currentdw = window['dw' + (obj_selected.charAt(2))];
		}
		li_count = currentdw.modifiedCount;
		var tabSave = document.anchors[obj_selected.charAt(2)-1].name;
		var redirectForm = document.forms["dw"+obj_selected.charAt(2)+"_submitForm"];
		var dataWindowName = "dw"+obj_selected.charAt(2);
	}
	else
	{
		if (isIE4)
		{
			currentdw = window['dw1'];
		}
		else if (isNav4)
		{
			currentdw = eval("document." + 'dw1');
		}
		else if (isNN6)
		{
			currentdw = window['dw1'];
		}
		li_count = currentdw.modifiedCount;
		var tabSave = top.document.title;
		var redirectForm = document.forms["dw1_submitForm"];
		ls_autosave = 'P';
		var dataWindowName = "dw1";
	}
	var retVal = 0;
	if ((li_count > 0) && (ls_autosave == 'A'))
	{
		retVal = 6;
	}
	else if ((li_count > 0) && (ls_autosave == 'P'))
	{
		  	lb_temp = confirm('Do you wish to save changes to '+tabSave+'?');
		  	if (lb_temp == true)
		  	{
				retVal = 6
			}
			else
			{
			  	retVal = 7
			}
	}
	if (retVal == 2)
	{
		chkState='false';
		return;
	}
	else if(retVal == 6)
	{
		if (redirectForm.elements["redirectURL"])
		{
			redirectForm.elements["redirectURL"].value=dataWindowName + "_" + targetRedirector;
		}
		currentdw.performAction("update");
		return;
	}
	else if(retVal == 7)
	{
		chkState='true';
	}
	Delete_Cookie('currenttab');
}

function pageSizeChange(objId)
{
	var pageSizeValue=document.getElementById(objId)[document.getElementById(objId).selectedIndex].value;
	SetCookie('pagesize',pageSizeValue);
	dw1.performAction('undefined');
}



// ###################################### Custom Secondary Filters


function showCookie()
{
	index = document.cookie.indexOf("lookup");
	cookieStart = (document.cookie.indexOf("=", index) + 1);
	cookieEnd = document.cookie.indexOf(";", index);
	if (cookieEnd == -1)
	{
		cookieEnd = document.cookie.length;
	}
	filtVal = document.cookie.substring(cookieStart, cookieEnd);
	if (filtVal.substring(0,6)=="filter" && filtVal != "filter#####")
	{
		filtVal = filtVal.split("#");
		dwfilter_dataForm.filter_field_0.value=(filtVal[1]);
		dwfilter_dataForm.filter_oper_0.value=(filtVal[2]);
		dwfilter_dataForm.filter_value_0.value=(filtVal[3]);
	}
}

function filtPop()
{
	var ls_sql = '';
	var ls_field = dwfilter_dataForm.filter_field_0.value;
	var ls_oper = dwfilter_dataForm.filter_oper_0.value;
	var ls_value = dwfilter_dataForm.filter_value_0.value;
	if ((ls_field != null) && (ls_field != '') && (ls_oper != '') && (ls_oper != null) && (ls_value != null))
	{
		var ls_field2 = form_query(ls_field, ls_oper, ls_value);
		ls_sql = form_query(ls_field, ls_oper, ls_value);
	}
	else
	{
		ls_sql = '';
	}
	v1 = dwfilter_dataForm.filter_field_0.value;
	v2 = dwfilter_dataForm.filter_oper_0.value;
	v3 = dwfilter_dataForm.filter_value_0.value;
	var_all = (v1+'#'+v2+'#'+v3);
	document.cookie="lookup=filter#"+var_all;
	url = document.location.href;
	url = url.substring(0,url.indexOf("?"));
	lslink=(url)+"?second=" + ls_sql + "&sort=" + dw1.sortString;
	document.location.href=lslink;
}


var editFilter=false;
var filteredSet=false;
var initialFilterOpen=true;

var selectedFilter=0;
var filterCount=0;

var currentColour="#ffcc66"; //highlight Selected row colour


function showIndividualFilter()
{
	editFilter=!editFilter; //showIt
	if (editFilter)  //Edit Open
	{
		document.getElementById("filterResults").className="filterEdit";
	}
	else if (filteredSet)
	{
		document.getElementById("filterResults").className="filterApplied";
	}
	else
	{
		document.getElementById("filterResults").className="";
	}
	if (initialFilterOpen) //initialises array
	{
		for (j=0; j<10; j++)
		{
			if (document.getElementById("fieldValue"+j).value!="")
			{
				filteredSet=true;
				filterCount++;
			}
			else if (document.getElementById("column"+j).selectedIndex!=0)
			{
				filteredSet=true;
				filterCount++;
			}
			else if (document.getElementById("operator"+j).selectedIndex!=0)
			{
				filteredSet=true;
				filterCount++;
			}
		}
		if (filterCount==0)
		{
			document.getElementById("fieldValue"+filterCount).value="*";	//load default value
			filterCount++;
		}
		for (count=0; count<filterCount; count++)
		{
			document.getElementById("userFilter"+count).style.display="block";
			currentFilter(count);
		}
		initialFilterOpen=!initialFilterOpen;
	}
	return;
}

function addNewFilter()
{
	if (filterCount<10)
	{
		document.getElementById("fieldValue"+filterCount).value="*";	//load default value
		document.getElementById("userFilter"+filterCount).style.display="block";
		currentFilter(filterCount);
		filterCount++;
	}
	return;
}

function applyFilter()
{
	var filterValues="";
	for (count=0; count<filterCount; count++)
	{
		theCol=document.getElementById("column"+count)[document.getElementById("column"+count).selectedIndex].value;
		theOper=document.getElementById("operator"+count)[document.getElementById("operator"+count).selectedIndex].value;
		theData=document.getElementById("fieldValue"+count).value;
		if ((count+1)<filterCount)
		{
			filterValues=filterValues+form_query(theCol,theOper,theData)+" AND ";
		}
		else
		{
			filterValues=filterValues+form_query(theCol,theOper,theData);
		}
	}
	dw1.submitForm.second.value = filterValues;
	dw1.Sort();
}

function showAllRecords()
{

	Delete_Cookie("lookup");
	dw1.submitForm.second.value = "";
	dw1.Sort();
}

function currentFilter(objId)
{
	if (objId.length>1)
		var newFilter=objId.charAt((objId.length)-1);
	else
		var newFilter=objId;
	newFilter=newFilter*1;
	document.getElementById("userFilter"+selectedFilter).style.background="none";
	document.getElementById("userFilter"+newFilter).style.background=currentColour;
	if (selectedFilter!=newFilter)
	{
		selectedFilter=newFilter;
	}
	if (newFilter==filterCount)
	{
		document.getElementById("column"+newFilter).focus();
	}
	return;
}

function removeSelectedFilter()
{
	if (selectedFilter+1<filterCount)
	{
		var from;
		for (ttCount=selectedFilter; ttCount<filterCount-1; ttCount++)
		{
			from=ttCount+1;
			document.getElementById("column"+ttCount).selectedIndex=document.getElementById("column"+from).selectedIndex;
			document.getElementById("operator"+ttCount).selectedIndex=document.getElementById("operator"+from).selectedIndex;
			document.getElementById("fieldValue"+ttCount).value=document.getElementById("fieldValue"+from).value;
		}
	}
	else
	{
		selectedFilter--;
	}
	filterCount--;
	clearFilter(filterCount);
	if (filterCount==0)
	{
		selectedFilter=0;
		addNewFilter();
	}
	else
	{
		currentFilter(selectedFilter);
	}
	return;
}

function clearFilter(objId)
{
	document.getElementById("column"+objId).selectedIndex=0;
	document.getElementById("operator"+objId).selectedIndex=0;
	document.getElementById("fieldValue"+objId).value="";
	document.getElementById("userFilter"+objId).style.display="none";
	return;
}

function resetFilter()
{
	for (filterCount; filterCount>0; filterCount--)
	{
		clearFilter(filterCount-1);
	}
	filterCount=0;
	selectedFilter=0;
	addNewFilter();
	return;
}


function highlight(obj)
{
	obj.className="hover";
}

function noClass(obj)
{
	obj.className="";
}

// ### Key Events ----


function filterKeyCheck(e)
{
	var code;
	if (!e)
		var e = window.event;
	if (e.keyCode)
		code = e.keyCode;
	else if (e.which)
		code = e.which;
	if (code==13)	//enter asciicode
	{
			applyFilter();
	}
	else if (code==9)	//tab asciicode
	{
		var targ;	//the object that fired the event
		if (e.target)
			targ = e.target;
		else if (e.srcElement)
			targ = e.srcElement;
		if (targ.nodeType == 3) // defeat Safari bug
			targ = targ.parentNode;
		if (targ.id.indexOf('fieldValue')==0 && filterCount==selectedFilter+1)
		{
			addNewFilter();
			targ.focus();	//onkeyup of a tab goes to next field
		}
	}
}

if (document.forms['fform']!=null)
{
	for (i=0; i<document.forms['fform'].elements.length; i++)
	{
		document.forms['fform'].elements[i].onkeydown = filterKeyCheck;
	}
}	//registers the keydown event and associated function if filter form exists
