

//**************************************************************************

//		Copyright  Sybase, Inc. 1998-2006

//						 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", "February", "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;



// DWPagingMethod

var DW_PAGING_POSTBACK = 0;

var DW_PAGING_CALLBACK = 1;

var DW_PAGING_XMLCLIENTSIDE = 2;



// 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 && this.autoEventBind == true)

        {

        // check for function with default name

        var testName = this.name + '_' + sEventName;

        if (eval ('typeof ' + testName) == 'function')

            this[sEventName] = eval(testName);

        }



    return this[sEventName] != null;

}

// bind the event with the givent function name instead of above <controlName>_<eventName>

function HTDW_AddEventImplementation(sEventName, sEventFunctionName)

{

    if (eval ('typeof ' + sEventFunctionName) == 'function')

        this[sEventName] = eval(sEventFunctionName);

}



// 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_ChangeDecimalCharAndGroupCharToStd(inString)

{

   if(DW_decimalChar != ',')

   {

   	return inString;

   }

   	

   var outString = "";

   var index;

   for(index = 0;index < inString.length;index++)

   {

   	if(inString.charAt (index) == DW_decimalChar)

   	{

   	      outString += ".";

   	}

   	else if(inString.charAt (index) == DW_thousandsChar)

   	{

   		outString += ",";

   	}

   	else

   	{

	   	outString += inString.charAt (index);

	}

   }

   return outString;

}

function DW_ChangeDecimalCharAndGroupCharToCurrent(inString)

{

   if(DW_decimalChar != ',')

   {

   	return inString;

   }

   	

   var outString = "";

   var index;

   for(index = 0;index < inString.length;index++)

   {

   	if(inString.charAt (index) == '.')

   	{

   	      outString += DW_decimalChar;

   	}

   	else if(inString.charAt (index) == ',')

   	{

   		outString += DW_thousandsChar;

   	}

   	else

   	{

	   	outString += inString.charAt (index);

	}

   }

   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();	

				var newString = DW_ChangeDecimalCharAndGroupCharToStd(inString);

				if(DW_parseNumberStringAgainstMask(newString, result, false)) 	

				{													

					if (result.number >= 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			

			{

				newString = DW_ChangeDecimalCharAndGroupCharToStd(newString)

				return DW_parseNumberStringAgainstMask(newString, 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, pagingMode)

{

    var col;

    var result;



    if (pagingMode == DW_PAGING_XMLCLIENTSIDE &&

        (rowObj[0].itemStatus == DW_ITEMSTATUS_NEW ||

         rowObj[0].itemStatus == DW_ITEMSTATUS_NEW_MODIFIED))

        {

        result = "(InsertRow " + rowNum + " (";

        for (col = 1; col < rowObj.numCols; col++)

            {

            if (rowObj[col] == null)

                result += "(" + col + " 1)";

            else

                result += "(" + col + " 0 '" + escapeString(rowObj[col]) + "')";

            }

        result += "))";

        }

    else 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_generateQuery (rowNum, rowObj)

{

    var col;

    var result;



    if (rowObj[0].itemStatus == DW_ITEMSTATUS_MODIFIED ||

        rowObj[0].itemStatus == DW_ITEMSTATUS_NEW_MODIFIED)

        {

        result = "(Query " + 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_generateQuerySort (rowNum, rowObj)

{

    var col;

    var result;



    if (rowObj[0].itemStatus == DW_ITEMSTATUS_MODIFIED ||

        rowObj[0].itemStatus == DW_ITEMSTATUS_NEW_MODIFIED)

        {

        result = "(QuerySort " + 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.generateQuery = HTDW_Row_generateQuery;

HTDW_RowClass.generateQuerySort = HTDW_Row_generateQuerySort;



HTDW_RowClass.dumpRow = HTDW_Row_dumpRow;



function HTDW_ColumnGob(name, colNum, rowInDetail, region, bRequired, bNilIsNull, bFocusRect, bDDCalendar,

						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.bDDCalendar = bDDCalendar;

	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 && !(bSkipCurrent && control[r] == htmlDw.currentControl))

         			 	{

         					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(controlExists + "" == "undefined")

            {

            controlName = this.name + "_" + controlName;

            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") && !this.bSuppressItemGainFocusCallback)

                {

                var result ;

                if(this.autoEventBind)

                    result = _evtDefault(this.RowFocusChanging (this.currRow+1, newRow+1));

               else

                    result = _evtDefault(this.RowFocusChanging (this, 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;

        this.actionRow = 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];

        var formatString = null;

        var displayValue;

        if (gob.format != null)

        {

            if (gob.getEditFormat != null)

                {

                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)

            {

               if((typeof value == "date" || typeof value == "number" ) 

               && gob.getDisplayFormat != null)

              {

                displayValue = gob.format (gob.getDisplayFormat, value, this.currentControl);

              }

              else

              {

                displayValue = value.toString();

              }

                

            }

            else

                displayValue = "";



            if (this.currentControl.value != displayValue)

            {

                this.currentControl.value = displayValue;

                this.currentControl.bChanged = true;

            }

        }

        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))

                {

                displayValue = value.toString();

                if (this.currentControl.value != displayValue)

                    this.currentControl.value = displayValue;

                }

            }

        else

            this.currentControl.value = "";



        // if Date or Datetime field, render dropdown calendar

        if (gob.bDDCalendar && document.getElementById(this.name + '_calFrame') != null)

            DW_NewCalendar(this, value, formatString);

        }



    // can only programatically change border on IE4

    if (control.gob.bFocusRect && HTDW_DataWindowClass.isIE4)

        {

        this.currentControlBorder = control.style.borderStyle;

        control.style.borderStyle = "dotted";

        }

        

    // show row focus indicator

    this.showRowFocusIndicator(this.currRow, true);



	



	if(this.bSuppressItemGainFocusCallback)

	{

		this.bSuppressItemGainFocusCallback = false;

		return;

	} 

    // row focus changed event

    if (bRowChanged && this.eventImplemented("RowFocusChanged"))

        {

        if(this.autoEventBind)

            this.RowFocusChanged (newRow+1)

        else

            this.RowFocusChanged (this, newRow+1)

        }

    // item focus changed event

    if (newCol != -1 && this.eventImplemented("ItemFocusChanged"))

        {

        if(this.autoEventBind)

           this.ItemFocusChanged (newRow+1, this.cols[newCol].name)

        else

            this.ItemFocusChanged (this, newRow+1, this.cols[newCol].name)

        }

	

}



function HTDW_itemLoseFocus(control)

{



	this.nOutOfFocusRow = control.row;

	this.nOutOfFocusCol = control.col;

 // CLIENTEVENTS

	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;

    // to avoid repeated acceptText. For example, calling acceptText diretly might cause itemerror and

    // itemerror might cause alert msg box. then current control will lose focus asynchronously, where

    // acceptText will be called again.

    if (this.acceptControl == control)

        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 = null;

		    if (colObj.convertFromString == parseInt)

			{

				var reg = /,/g;

				var noComma = newValue.replace(reg, "");

				convertedValue = colObj.convertFromString (noComma, 10);

			}

			else

				convertedValue = colObj.convertFromString (newValue);



            if (convertedValue != null)

                {

                if (bDateTimeProcessingEnabled &&

                    (colObj.convertFromString == DW_DateParse ||

                     colObj.convertFromString == DW_DatetimeParse ||

                     colObj.convertFromString == DW_TimeParse))

                       {// it is datetime, use equals instead of ==

                       if(rowObj[col] == null || !rowObj[col].equals(convertedValue))

                         control.bChanged = true;

                       }

                else 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 && value != 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 = "";

            }

            

		if (this.pagingMode == DW_PAGING_XMLCLIENTSIDE)

			{

			var xmlRenderer = this.xmlRenderer;

			if ((xmlRenderer) && (xmlRenderer.bMozilla))

				{

				var detailList = xmlRenderer.dwXML.getElementsByTagName("detail");

				var cellNode = detailList[control.row].firstChild;                    

				while (cellNode)

					{

					if (cellNode.nodeName == xmlRenderer.divName + "_" + gob.name)

						{

						cellNode.textContent = this.currentControl.value;

						break;

						}

					cellNode = cellNode.nextSibling;

					}

				}

			}

        }

        

    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 = "";



	if( this.bIsSlaveSharedDataWindow )

		return changes;



    var index, rowObj;

    for (index=0; index < this.rows.length; ++index)

        {

        rowObj = this.rows[index];

        if (rowObj != null)

            {

            if(this.dumpRow + "" != "undefined" && this.dumpRow == true)

                HTDW_RowClass.dumpRow (index, rowObj);



		if(this.bIsQueryMode==false)



	            changes += HTDW_RowClass.generateChange (index, rowObj, this.pagingMode);



		else if(this.bIsQuerySort && index==0 )

	            changes += HTDW_RowClass.generateQuerySort (index, rowObj);

		else

	            changes += HTDW_RowClass.generateQuery (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"))

        {   

        if(this.autoEventBind)

            result = _evtDefault(this.ItemError (row+1, colObj.name, exprCtx.currentText));

        else

             result = _evtDefault(this.ItemError (this, 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_positionComboBox(control, cB)

{

	var cP = cB.offsetParent;

	var eL = 0;

	var eT = 0;



	for(var obj = control; obj && obj != cP; obj = obj.offsetParent)

	{

	    eL += obj.offsetLeft;

	    eT += obj.offsetTop;

	    if (obj.offsetParent && obj.offsetParent != cP)

		{

			eL -= obj.offsetParent.scrollLeft;

			eT -= obj.offsetParent.scrollTop;

		}

	}



	var eW = control.offsetWidth;

	var dW = cB.style.pixelWidth;

	var sL = cP.scrollLeft;



	if (eL + dW > cP.clientWidth + sL)

	    eL -= (dW - eW);



	var eH = control.offsetHeight;

	var dH = cB.style.pixelHeight;

	var sT = cP.scrollTop;

	if (eT - dH >= sT && eT + eH + dH > cP.clientHeight + sT)

	    eT -= dH;

	else

	    eT += eH;

	cB.style.left = eL;

	cB.style.top = eT;

}



// Dropdown DataWindow

// Configurable parameters

var DDDW_SelectRowColor = "blue"; // background color of selected row

var DDDW_SelectTextColor = "white"; // text color of selected row

// end Configurable parameters



function HTDW_addDDDWOptions(dddw, aOptions)

{

	var i;

	if (dddw.options.length < aOptions.length)

	{

		var selection = dddw.options[0];

		for (i = 0; i < aOptions.length; i++)

		{

			if (aOptions[i][0] != selection.text)

			{

				var oOption = document.createElement("option");

				dddw.options.add(oOption, i);

				oOption.innerText = aOptions[i][0];

				oOption.value = aOptions[i][1];

			}

		}

	}

}



function HTDW_removeDDDWOptions(dddw)

{

	if (dddw.selectedIndex < 0)

		dddw.selectedIndex = 0;

	var selection = dddw.options[dddw.selectedIndex];

	dddw.options.length = 0;

	dddw.options[0] = selection;

}



function HTDW_overrideDDDWSelect(dddwSelect, newCol, dddwName)

{

	var dddw = document.getElementById(this.name + "_" + dddwName + "_dddw");



	if (dddwSelect == document.elementFromPoint(window.event.clientX, window.event.clientY))

	{

		if (this.currentControl != null)

		{

			if (newCol == this.currentControl.col)

				dddw.blur();

		}

		return false;

	}

	return true;

}



function HTDW_setDDDWVisible(dddwName, bVisible, newRow, newCol, control, aOptions)

{

	var dddw = document.getElementById(this.name + "_" + dddwName + "_dddw");

	var dddwF = document.getElementById(this.name + "_" + dddwName + "_frame");

	if (dddw==null||dddwF==null) return;

	var i;



	if (bVisible)

	{

		// display DDDW

		dddw.style.display = "block";

		this.positionComboBox(control, dddw);

		// display frame

		dddwF.style.width = dddw.offsetWidth;

		dddwF.style.height = dddw.offsetHeight;

		dddwF.style.top = dddw.style.top;

		dddwF.style.left = dddw.style.left;

		dddwF.style.zIndex = dddw.style.zIndex - 1;

		dddwF.style.display = "block";

		dddw.row = newRow;

		dddw.col = newCol;

		dddw.textbox = control;

		dddw.selectedRow = -1;

		var selection = control.options[0];

		if (selection.text != "")

		{

			for (i = 0; i < aOptions.length; i++)

			{

				if (aOptions[i][0] == selection.text)

				{

					dddw.selectedRow = i;

					break;

				}

			}

		}

		this.itemGainFocus(newRow,newCol,control,this.gobs[dddwName]);

		dddw.focus();

	}

	else

	{

		// hide

		dddw.style.display = "none";

		dddwF.style.display = "none";



		// deselect row after hiding

		var gob = dddw.textbox.gob;

		var rowElement = gob.dddw_selectedRowElement;

		if (rowElement != null)

		{

			rowElement.style.backgroundColor = gob.dddw_bgColors[0];

			rowElement.style.color = gob.dddw_txtColors[0];

			for(i = 0; i < rowElement.all.length; i++)

			{

				rowElement.all(i).style.backgroundColor = gob.dddw_bgColors[i+1];

				rowElement.all(i).style.color = gob.dddw_txtColors[i+1];

			}

			gob.dddw_selectedRowElement = null;

		}

	}

}



function HTDW_scrollDDDW(dddwControl, dddwObj)

{

	var row = dddwControl.selectedRow;

	var i;



	if (row < 0)

	{

		// scroll to top

		dddwControl.scrollTop = 0;

		return;

	}

	var rowElementId = dddwObj + "_detail_" + row.toString();

	var rowElement = dddwControl.all[rowElementId];

	var oneRowElement = null;

	if (rowElement.length + "" != "undefined")

		oneRowElement = rowElement[0];

	else

		oneRowElement = rowElement;



	// scroll

	dddwControl.scrollTop = oneRowElement.offsetTop;



	// save row element

	var gob = dddwControl.textbox.gob;

	gob.dddw_selectedRowElement = oneRowElement;



	// select row

	gob.dddw_bgColors[0] = oneRowElement.style.backgroundColor;

	gob.dddw_txtColors[0] = oneRowElement.style.color;

	oneRowElement.style.backgroundColor = DDDW_SelectRowColor;

	oneRowElement.style.color = DDDW_SelectTextColor;

	for(i = 0; i < oneRowElement.all.length; i++)

	{

		gob.dddw_bgColors[i+1] = oneRowElement.all(i).style.backgroundColor;

		gob.dddw_txtColors[i+1] = oneRowElement.all(i).style.color;

		oneRowElement.all(i).style.backgroundColor = DDDW_SelectRowColor;

		oneRowElement.all(i).style.color = DDDW_SelectTextColor;

	}

}



function HTDW_setDDDWItem(dddwGobName, dddwObjName, row, aOptions)

{

	var dddw = document.getElementById(this.name + "_" + dddwGobName + "_dddw");

	var gob = dddw.textbox.gob;

	var rowElement = gob.dddw_selectedRowElement;

	var i;



	// deselect old row

	if (rowElement != null)

	{

		rowElement.style.backgroundColor = gob.dddw_bgColors[0];

		rowElement.style.color = gob.dddw_txtColors[0];

		for(i = 0; i < rowElement.all.length; i++)

		{

			rowElement.all(i).style.backgroundColor = gob.dddw_bgColors[i+1];

			rowElement.all(i).style.color = gob.dddw_txtColors[i+1];

		}

	}



	// get new selection

	var rowElementId = dddwObjName + "_detail_" + row.toString();

	rowElement = dddw.all[rowElementId];

	var oneRowElement = null;

	if (rowElement.length + "" != "undefined")

		oneRowElement = rowElement[0];

	else

		oneRowElement = rowElement;



	// save row

	gob.dddw_selectedRowElement = oneRowElement;



	// select row

	gob.dddw_bgColors[0] = oneRowElement.style.backgroundColor;

	gob.dddw_txtColors[0] = oneRowElement.style.color;

	oneRowElement.style.backgroundColor = DDDW_SelectRowColor;

	oneRowElement.style.color = DDDW_SelectTextColor;

	for(i = 0; i < oneRowElement.all.length; i++)

	{

		gob.dddw_bgColors[i+1] = oneRowElement.all(i).style.backgroundColor;

		gob.dddw_txtColors[i+1] = oneRowElement.all(i).style.color;

		oneRowElement.all(i).style.backgroundColor = DDDW_SelectRowColor;

		oneRowElement.all(i).style.color = DDDW_SelectTextColor;

	}



	// set item

	var selectedValue = aOptions[row];

	dddw.textbox.options.length = 0;

	var oOption = document.createElement("option");

	dddw.textbox.options.add(oOption);

	oOption.innerText = selectedValue[0];

	oOption.value = selectedValue[1];



	dddw.textbox.bChanged = true;

	this.AcceptText();

	// wait a moment so new SelectRow can be seen

	window.setTimeout(this.name + ".setDDDWVisible('" + dddwGobName + "',false)", 200);

}



alphas = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

digits = "0123456789";



function isalpha(c) 

{ 

	return alphas.indexOf(c) >= 0; 

}



function isdigit(c) 

{ 

	return digits.indexOf(c) != -1;

} 



function isalnum(c)

{

	return isalpha(c)||isdigit(c);

}



function DWQRY_isropkey(text)

{

	var temp=text.toLocaleUpperCase();

	if(temp=="AND" || temp=="OR")

		return true;

	else 

		return false;

}



function DWQRY_isopkey(text)

{

	if(text=="=" || text=="<" || text==">" || text=="<>" || text=="<=" || text == ">=" )

		return true;

	else 

		return false;

}



function DWQRY_FindFirstNonNumericalPos(inString)

{

    var index, tempChar="", tempPrevChar="";

    var strLength = inString.length;

    var foundExpForm = false;

    var foundDecimalForm = false;

    

    for (index=0; index < strLength; index++)

    {

		tempPrevChar=tempChar;

        tempChar= inString.charAt (index);

        if(tempChar=="E" || tempChar=="e")

        {

			if(foundExpForm)

				return index;

			else if(tempPrevChar=="")

				return index;

			else if(!isdigit(tempPrevChar))

				return index;

			else 

				foundExpForm = true;

		}

		else if(tempChar==".")

		{

			if(foundDecimalForm||foundExpForm)

				return index;

			else

				foundDecimalForm = true;

		}

		else if(tempChar=="+" || tempChar=="-")

		{

			if(tempPrevChar!="")

				if(tempPrevChar!="E" && tempPrevChar!="e")

					return index;

		}

		else if(!isdigit(tempChar))

		{

			return index;

		}

		

	}

	return index;

}



function DWQRY_FindFirstNonStringPos(inString)

{

    var index, tempChar="";

    var strLength = inString.length;

    

    for (index=0; index < strLength; index++)

    {

        tempChar= inString.charAt (index);

        if(!isalnum(tempChar) && tempChar!="_" && tempChar!="#" && tempChar!="$")

			return index;

	}

	return index;

}



function DWQRYTokenizer_gettoken()

{

	this.buffer = DW_LeftTrim(this.buffer);

	

	if(this.buffer=="")

	{

		this.curtoktype="END";

		this.curtok="";	

		this.buffer="";	

	}

	else if(this.buffer.substr(0,1)=="(" )

	{

		this.curtoktype="OPAREN";

		this.curtok="(";

		this.buffer=this.buffer.substr(1);

	}

	else if(this.buffer.substr(0,1)==")" )

	{

		this.curtoktype="CPAREN";

		this.curtok=")";

		this.buffer=this.buffer.substr(1);

	}

	else if(this.buffer.substr(0,2)=="<="  )

	{

		this.curtoktype="SPECIAL";

		this.curtok="<=";

		this.buffer=this.buffer.substr(2);

	}

	else if(this.buffer.substr(0,2)==">="  )

	{

		this.curtoktype="SPECIAL";

		this.curtok=">=";

		this.buffer=this.buffer.substr(2);

	}

	else if(this.buffer.substr(0,2)=="<>"  )

	{

		this.curtoktype="SPECIAL";

		this.curtok="<>";

		this.buffer=this.buffer.substr(2);

	}

	else if(this.buffer.substr(0,1)=="<"  )

	{

		this.curtoktype="SPECIAL";

		this.curtok="<";

		this.buffer=this.buffer.substr(1);

	}

	else if(this.buffer.substr(0,1)==">"  )

	{

		this.curtoktype="SPECIAL";

		this.curtok=">";

		this.buffer=this.buffer.substr(1);

	}

	else if(this.buffer.substr(0,1)=="="  )

	{

		this.curtoktype="SPECIAL";

		this.curtok="=";

		this.buffer=this.buffer.substr(1);

	}

	else if(this.buffer.substr(0,1)=="\"" && (this.buffer.indexOf("\"",1)>=1) )

	{

		var newpos=this.buffer.indexOf("\"",1);

		this.curtoktype="DQUOTE";

		this.curtok=this.buffer.substring(1,newpos);

		this.buffer=this.buffer.substr(newpos+1);	

	}

	else if(isdigit(this.buffer.substr(0,1)))

	{

		var newpos=DWQRY_FindFirstNonNumericalPos(this.buffer);

		this.curtoktype="NUMBER";

		this.curtok=this.buffer.substring(0,newpos);	

		this.buffer=this.buffer.substr(newpos);	

	}

	else if(this.buffer.substr(0,1)==".")

	{

		var newpos=DWQRY_FindFirstNonNumericalPos(this.buffer);

		this.curtoktype="NUMBER";

		this.curtok=this.buffer.substring(0,newpos);	

		this.buffer=this.buffer.substr(newpos);	

	}

	else if(this.buffer.substr(0,1)=="+")

	{

		var newpos=DWQRY_FindFirstNonNumericalPos(this.buffer);

		this.curtoktype="NUMBER";

		this.curtok=this.buffer.substring(0,newpos);	

		this.buffer=this.buffer.substr(newpos);	

	}

	else if(this.buffer.substr(0,1)=="-")

	{

		var newpos=DWQRY_FindFirstNonNumericalPos(this.buffer);

		this.curtoktype="NUMBER";

		this.curtok=this.buffer.substring(0,newpos);	

		this.buffer=this.buffer.substr(newpos);	

	}

	else if(this.buffer.substr(0,1)==",")

	{

		this.curtoktype="SPECIAL";

		this.curtok=",";

		this.buffer=this.buffer.substr(1);

	}

	else if(isalpha(this.buffer.substr(0,1)))

	{

		var newpos=DWQRY_FindFirstNonStringPos(this.buffer);

		this.curtoktype="NAME";

		this.curtok=this.buffer.substring(0,newpos);	

		this.buffer=this.buffer.substr(newpos);	

	}

	else

	{

		this.curtoktype = "SPECIAL";

		this.curtok=this.buffer.substring(0,1);	

		this.buffer=this.buffer.substr(1);			

	}

}



function DWQRYTokenizer_token(tokentype)

{

	if(this.curtok=="")

	{

		this.gettoken();

	}

	if(this.curtoktype==tokentype)

	{

		var temp = this.curtok;

		this.curtok = "";

		return temp;

	}

	else

	{

		return "";

	}

}



function DWQRYTokenizer_checktoken(tokentype)

{

	if(this.curtok=="")

	{

		this.gettoken();

	}

	if(this.curtoktype==tokentype)

	{

		this.curtok = "";

		return true;

	}

	else

	{

		return false;

	}

}



function DWQRYTokenizer(text)

{

	this.buffer=text.toLocaleUpperCase();

	this.curtok="";

	this.curtoktype="";

	

	this.checktoken=DWQRYTokenizer_checktoken;

	this.token=DWQRYTokenizer_token;

	this.gettoken=DWQRYTokenizer_gettoken;

}



function HTDW_validateQueryCriterion(text,columnType,curRow,curCol)

{

	var tokenizer=new DWQRYTokenizer(text);

	var word = tokenizer.token("NAME");

	var word1 = "";

	var bOp = false;

	var bHavePart = false;

	var bIn = false;

	

	if(word!="")

	{

		if(DWQRY_isropkey(word))

		{

			var index, index2, rowObj;

			var bFoundNonEmptyCell=false;



			rowObj = this.rows[curRow];

			for(index=curCol-1;index>=1;--index)

				if(rowObj[index]!=null&&rowObj[index]!="")

				{

					bFoundNonEmptyCell=true;					

					break;

				}

					

			if(!bFoundNonEmptyCell)

			{

				var topCheckedRow = 0;

				if(this.bIsQuerySort)

					topCheckedRow = 1;					

				for (index=curRow-1; index>=topCheckedRow ; --index)

				{

					rowObj = this.rows[index];

					for(index2=1; index2<rowObj.numCols;++index2)

					{

						if(rowObj[index2]!=null&&rowObj[index2]!="")

						{

							bFoundNonEmptyCell=true;					

							break;

						}

					}

				}

			}



			if(!bFoundNonEmptyCell)

				return false;



			word = tokenizer.token("NAME");		

			word = word.toLocaleUpperCase();	

			

			if(word!="")

			{

				if(word == "LIKE")

				{

					bOp = true;

				}

				

				if(word == "NOT")

				{

					word1 = tokenizer.token("NAME");		

					word1 = word.toLocaleUpperCase();	

					

					if(word1=="LIKE")

					{

						bOp = true;

					}

					else

					{

						bHavePart = true;

					}

				}

				else

				if(word=="IN")

				{

					bOp=true;

					bIn=true;

				}

				else

				{

					bHavePart=true;

				}	

			}

		}

		else

		if(word == "LIKE")

		{

			bOp = true;

		}

		else

		if(word == "NOT")

		{

			word1 = tokenizer.token("NAME");		

			word1 = word.toLocaleUpperCase();	

					

			if(word1=="LIKE")

			{

				bOp = true;

			}

			else

			{

				bHavePart = true;

			}

		}

		else

		if(word=="IN")

		{

			bOp=true;

			bIn=true;

		}

		else

		{

			bHavePart=true;

		}	

	}

	if(word=="" && !bOp)

	{

		word = tokenizer.token("SPECIAL");

		if(word!="")

		{

			if(DWQRY_isopkey(word))

			{

				bOp=true;

			}

			else if(word=="+" || word=="-")

			{

				++this.curpos;

			}

			else

			{

				return false;

			}

		}

	}

	//if(!bOp)

	//{

	//}

	if(bIn)

	{

		if(!tokenizer.checktoken("OPAREN"))

		{

			return false;

		}

		while(1)

		{

			if(columnType=="NUMBER")

			{

				word = tokenizer.token("NUMBER");

				if(word=="")

					return false;

			}

			else

			{

				word = tokenizer.token("NAME");

				if(word=="")

					word = tokenizer.token("DQUOTE");

				if(word=="")

					return false;

					

			}

			word = tokenizer.token("SPECIAL");

			if(word!="")

			{

				if(word!=",")

				{

					return false;

				}

			}

			else

			{

				if(!tokenizer.checktoken("CPAREN"))

					return false;

				break;

				

			}

		}

		if(tokenizer.checktoken("END"))

		{

			return true;

		} 

		else

		{

			return false;

		}

	}

	if(bHavePart)

	{

		if(columnType=="NUMBER")

		{

			return false;

		}

		else

		{

			return true;

		}

	}

	if(columnType=="NUMBER")

	{

		word = tokenizer.token("NUMBER");

		if(word!="")

		{

			if(tokenizer.checktoken("END"))

			{

				return true;

			} 

			else

			{

				return false;

			}

		}

	}

	word = tokenizer.token("DQUOTE");

	if(word!="")

	{

		if(tokenizer.checktoken("END"))

		{

			return true;

		} 

		else

		{

			return false;

		}

	}

	return true;

}







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;

    var oldValue=exprCtx.currentText;



    var gob = control.gob;

    if (gob.getEditFormat != null)

    {

      if (typeof gob.getEditFormat == "string")

        gMask = gob.getEditFormat;

      else

      {

        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 = "";

    }

    else  

      gMask = "";

    if (control.type == "select-one")

    {

        newValue = control.options[control.selectedIndex].value;

        if(oldValue==newValue)

			return 1;

    }

    else

        newValue = control.value;



    // to avoid accepttext is called recursively since we might fire event below and there accepttext might be called again in dw .net and pb .net

    if (this.acceptControl == control)

        return 1;

    this.acceptControl = control;		

    exprCtx.row = row;

    exprCtx.currentText = newValue;



    if (this.pagingMode == DW_PAGING_XMLCLIENTSIDE)

		{

        var xmlRenderer = this.xmlRenderer;

        if ((xmlRenderer) && (!xmlRenderer.bMozilla))

			{	

            var detailList = xmlRenderer.dwXML.getElementsByTagName("detail");

            var cellNode = detailList.item(control.row / xmlRenderer.dw.rowsPerDetail  | 0).firstChild;

            while (cellNode)

				{

                if (cellNode.nodeName == xmlRenderer.divName + "_" + gob.name)

					{

                    var currentValue = DW_Trim(this.currentControl.value);

                    var nodeText = DW_Trim(cellNode.text);

                    if (nodeText != currentValue)

						{

                        cellNode.text = this.currentControl.value;

                        

                        if ((control.bChanged != false) && (control.bChanged != true))

                            control.bChanged = true;

						}

                    break;

					}

                cellNode = cellNode.nextSibling;

				}

			}

		}



    // 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)

        {

        var dataValue  = newValue;

        if (bIsValid && colObj.validateByType != null)



		

		if(this.bIsQueryMode && !this.bIsQuerySort)

		{

			var colType="";

			if(colObj.validateByType==DW_IsNumber)

				colType=="NUMBER"

			if(colObj.validateByType==DW_IsNonNegativeNumber)

				colType=="NUMBER"

			bIsValid = this.ValidateQueryCriterion(newValue,colType,row,col);

		}

		else if(this.bIsQueryMode && this.bIsQuerySort && row>= 1)

		{

			var colType="";

			if(colObj.validateByType==DW_IsNumber)

				colType=="NUMBER"

			if(colObj.validateByType==DW_IsNonNegativeNumber)

				colType=="NUMBER"

			bIsValid = this.ValidateQueryCriterion(newValue,colType,row,col);

		}

		else if(this.bIsQueryMode && this.bIsQuerySort )

			bIsValid = true;

		else



	            bIsValid = colObj.validateByType(newValue, control.gob.bNilIsNull);



        if (bIsValid && colObj.validateItem != null)



		if(!this.bIsQueryMode)



	            bIsValid = colObj.validateItem (exprCtx);



       if (!(control.gob.bNilIsNull && newValue == "") && colObj.convertFromString != null)

           {// get the data value instead of value with format.

           var tempDataValue;

           if (colObj.convertFromString == parseInt)

               tempDataValue = colObj.convertFromString (newValue, 10);

           else

               tempDataValue = colObj.convertFromString (newValue);

           if (tempDataValue != null)

               dataValue = tempDataValue.toString();

           }

		

        // item changed event

        if (bIsValid && this.eventImplemented("ItemChanged"))

            {

            if(this.autoEventBind)

                validAction = _evtDefault(this.ItemChanged (row+1, colObj.name, this.bDwDotNet ? dataValue : newValue));

            else

                validAction = _evtDefault(this.ItemChanged (this, row+1, colObj.name, this.bDwDotNet ? dataValue : 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(this.bIsQueryMode)

		{

			if (rowObj[col] != newValue)

                 	{

				rowObj[col] = newValue;

				if (rowObj[0].itemStatus != DW_ITEMSTATUS_MODIFIED && rowObj[0].itemStatus != DW_ITEMSTATUS_NEW_MODIFIED)

					this.modifiedCount++;	    

				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 (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++;

                    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++;	    

                    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++;	    

                    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);           

            

            this.refreshSharedDataWindows(row,col);

            

            }

        }



    // 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;

    this.acceptControl = null; // clear the acceptControl before return.

    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, bandID)

{

    var evtResult = 0;



    // CR228156 - click on DDDW column fires a validation error in IE5.x - Partha

    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.bDwDotNet && (bandID == 1 || bandID == 2 || bandID == 3))

        row = -1;

    if (this.eventImplemented("Clicked"))

        {

        if(this.autoEventBind)

            evtResult = _evtDefault(this.Clicked (row+1, objName));

        else

             evtResult = _evtDefault(this.Clicked (this, row+1, objName));

        }



    // prevent clicked event from bubbling up in IE4 or higher

    if (HTDW_DataWindowClass.isIE4)

        window.event.cancelBubble = true;



    this.clickedRow = row;

    this.clickedCol = col;

    

    if (row > -1)

        this.showRowFocusIndicator(row, true);



    return evtResult != 1;

}



function HTDW_itemDoubleClicked(row, col, objName, bandID)

{

    var evtResult = 0;

         

    if(this.bDwDotNet && (bandID == 1 || bandID == 2 || bandID == 3))

        row = -1;

    if (this.eventImplemented("DoubleClicked"))

        {

        if(this.autoEventBind)

            evtResult = _evtDefault(this.DoubleClicked (row+1, objName));

        else

             evtResult = _evtDefault(this.DoubleClicked (this, row+1, objName));

        }



    // prevent clicked event from bubbling up in IE4 or higher

    if (HTDW_DataWindowClass.isIE4)

        window.event.cancelBubble = true;



    this.clickedRow = row;

    this.clickedCol = col;

    

    return evtResult != 1;

}



function HTDW_itemRButtonDown(row, col, objName, bandID)

{

	if(window.event.button!=2)

		return;

		

    var evtResult = 0;

         

    if(this.bDwDotNet && (bandID == 1 || bandID == 2 || bandID == 3))

        row = -1;

    if (this.eventImplemented("RButtonDown"))

        {

        if(this.autoEventBind)

            evtResult = _evtDefault(this.RButtonDown (row+1, objName));

        else

             evtResult = _evtDefault(this.RButtonDown (this, row+1, objName));

        }



    // prevent clicked event from bubbling up in IE4 or higher

    if (HTDW_DataWindowClass.isIE4)

        window.event.cancelBubble = true;



    this.clickedRow = row;

    this.clickedCol = col;

    

    return evtResult != 1;

}





function HTDW_htmlCallbackHandler(eventResult, dwObj)

{

    var sindex, eindex, htmlindex, i;

    var stylestr, htmlstr, tempstr, beginscripts, endscripts, rslt;

    var divSTag, divETag, styleSTag, styleETag, scriptSTag, scriptETag;

    var scriptEle, dwContainerEle;

    

    rslt = eventResult;

    divSTag = "<" + "DIV";

    divETag = "<" + "/DIV>";

    styleSTag = "<" + "STYLE";

    styleETag = "<" + "/STYLE>";

    scriptSTag = "<" + "SCRIPT";

    scriptETag = "<" + "/SCRIPT>";

    // extract the style sheet from rslt;

    sindex = rslt.indexOf(styleSTag + " ID=\"" + dwObj.name + "_stylesheet" + "\"");

    if(sindex < 0)

        sindex = rslt.indexOf(styleSTag.toLowerCase() + " id=\"" + dwObj.name + "_stylesheet" + "\"");

    sindex = rslt.indexOf(">", sindex) + 1;

    eindex = rslt.indexOf(styleETag, sindex);

    if(eindex < 0)

        eindex = rslt.indexOf(styleETag.toLowerCase(), sindex);

    stylestr = rslt.substring(sindex, eindex);

    

    htmlindex = rslt.indexOf(divSTag + " ID=\"" + dwObj.name + "\"", eindex);

    if(htmlindex < 0)

        htmlindex = rslt.indexOf(divSTag.toLowerCase() + " id=\"" + dwObj.name + "\"", eindex);

    // extract the begin javascript from rslt;

    sindex = rslt.indexOf(scriptSTag, eindex);

    if(sindex < 0)

        sindex = rslt.indexOf(scriptSTag.toLowerCase(), eindex);

    beginscripts = new Array();

    i = 0;

    while(sindex > 0 && sindex < htmlindex)

    {

        sindex = rslt.indexOf(">", sindex) + 1;

        // can not use complete script end tag here, which might cause error.

        eindex = rslt.indexOf(scriptETag, sindex);

        if(eindex < 0)

            eindex = rslt.indexOf(scriptETag.toLowerCase(), sindex);

        tempstr = rslt.substring(sindex, eindex);

        beginscripts[i] = tempstr;

        i++;

        sindex = rslt.indexOf(scriptSTag, eindex);

        if(sindex < 0)

            sindex = rslt.indexOf(scriptSTag.toLowerCase(), eindex);

    }

    // extract the datawindow display contents from rslt;

    sindex = rslt.indexOf(">", htmlindex) + 1;

    eindex = rslt.lastIndexOf(divETag);

    if(eindex < 0)

        eindex = rslt.lastIndexOf(divETag.toLowerCase());

    htmlstr = rslt.substring(sindex, eindex);

    

    // extract the end javascript from rslt;

    sindex = rslt.indexOf(scriptSTag, eindex);

    if(sindex < 0)

        sindex = rslt.indexOf(scriptSTag.toLowerCase(), eindex);

    endscripts = new Array();

    i = 0;

    while(sindex > 0)

    {

        sindex = rslt.indexOf(">", sindex) + 1;

        // can not use complete script end tag here, which might cause error.

        eindex = rslt.indexOf(scriptETag, sindex);

        if(eindex < 0)

            eindex = rslt.indexOf(scriptETag.toLowerCase(), sindex);

        tempstr = rslt.substring(sindex, eindex);

        endscripts[i] = tempstr;

        i++;

        sindex = rslt.indexOf(scriptSTag, eindex);

        if(sindex < 0)

            sindex = rslt.indexOf(scriptSTag.toLowerCase(), eindex);

    }

    

    // start the update result to dom

    // update styleshee

    if(HTDW_DataWindowClass.isIE4) // for IE

    {

        // in IE, styleElement.innerHTML is readonly

        var styleSheet, styleSheeId;

        styleSheeId = dwObj.name + "_stylesheet";

        for(var i = 0; i < document.styleSheets.length; i++)

        {

            styleSheet = document.styleSheets[i];

            if(styleSheet.owningElement.id == styleSheeId)

            {

                styleSheet.cssText = stylestr;// refresh the stylesheet.

                break;

            }

        }

    }

    else

    {

        var styleEle = document.getElementById(dwObj.name + "_stylesheet");        

        styleEle.innerHTML = stylestr;// refresh the stylesheet.

    }

    // update begin script    

    dwContainerEle = document.getElementById(dwObj.name);

    

    for(i=0; i<beginscripts.length; i++)

    {

        temp = beginscripts[i];

        scriptEle = document.getElementById(dwObj.name + "_bscript" + i.toString());

        if(scriptEle)

        {

            if(HTDW_DataWindowClass.isIE4) // for IE

            {

                scriptEle.text = temp;

                continue;

            }            

            scriptEle.parentNode.removeChild(scriptEle);// need to remove and readd

        }

        scriptEle = document.createElement("script");

        scriptEle.id = dwObj.name + "_bscript" + i.toString();

        scriptEle.type = "text/javascript";

        scriptEle.defer = true;

        if(HTDW_DataWindowClass.isIE4) // for IE

            scriptEle.text = temp;

        else

            scriptEle.innerHTML = temp;

        dwContainerEle.parentNode.insertBefore(scriptEle, dwContainerEle);

    }

    // update html content

    dwContainerEle.innerHTML = htmlstr;

    // update end script

    for(i=0; i<endscripts.length; i++)

    {

        temp = endscripts[i];

        scriptEle = document.getElementById(dwObj.name + "_escript" + i.toString());

        if(scriptEle)

        {

            if(HTDW_DataWindowClass.isIE4) // for IE

            {

                scriptEle.text = temp;

                continue;

            }            

            scriptEle.parentNode.removeChild(scriptEle);// need to remove and readd

        }

        scriptEle = document.createElement("script");

        scriptEle.id = dwObj.name + "_escript" + i.toString();

        scriptEle.type = "text/javascript";

        scriptEle.defer = true;

        if(HTDW_DataWindowClass.isIE4) // for IE

            scriptEle.text = temp;

        else

            scriptEle.innerHTML = temp;

        dwContainerEle.parentNode.appendChild(scriptEle);

    }

}

function HTDW_xhtmlCallbackHandler(eventResult, dwObj)

{

    var sindex, eindex, temp, rslt, bDelay;

    var dwContainerEle, scriptEle, scriptParent, linkEle, newLinkEle;

    var linkhref, linkhref1, htmlstr, rowscripts;    

    var linkSTag, divSTag, divETag, scriptSTag, scriptETag;    

    

    rslt = eventResult;

    dwContainerEle = document.getElementById(dwObj.name);

    linkSTag = "<" + "link";

    divSTag = "<" + "div";

    divETag = "<" + "/div" + ">";

    scriptSTag = "<" + "script";

    scriptETag = "<" + "/script" + ">";

    

    // stylesheet

    sindex = rslt.indexOf(linkSTag + " id=\"" + dwObj.name + "_stylesheet\"");

    sindex = rslt.indexOf("href=\"", sindex) + 6;

    eindex = rslt.indexOf("\"", sindex);

    linkhref = rslt.substring(sindex, eindex);

    

    // styleshee1 not always there

    sindex = rslt.indexOf(divSTag + " id=\"" + dwObj.name + "\"", eindex);

    temp = sindex;

    linkhref1 = rslt.substring(0, sindex);

    sindex = linkhref1.indexOf(linkSTag + " id=\"" + dwObj.name + "_stylesheet1\"");

    if (sindex >= 0)

    {

        sindex = linkhref1.indexOf("href=\"", sindex) + 6;

        eindex = linkhref1.indexOf("\"", sindex);

        linkhref1 = linkhref1.substring(sindex, eindex);    

    }

    else

        linkhref1 = null;

    

    // html

    sindex = temp;

    sindex = rslt.indexOf(">", sindex) + 1;   

    eindex = rslt.lastIndexOf(divETag); //skip the xhtml doc's div end tag

    eindex = rslt.lastIndexOf(divETag, eindex); // this our container div tag

    htmlstr = rslt.substring(sindex, eindex);

    

    // rowscript

    sindex = rslt.lastIndexOf(scriptSTag + " id=\"" + dwObj.name + "_rowscript\"");

    sindex = rslt.indexOf(">", sindex) + 1;

    eindex = rslt.indexOf(scriptETag, sindex);

    rowscripts = rslt.substring(sindex, eindex);

    

    // update stylesheet

    bDelay = false;

    dwObj.linkReadyStateChangeCount = 0;

    linkEle = document.getElementById(dwObj.name + "_stylesheet");

    newLinkEle = document.getElementById(linkEle.id + "_new"); //new link for buffer so that old style can be kept temporarily.

    if(newLinkEle == null)

    {

        newLinkEle = linkEle.cloneNode(true);

        newLinkEle.id = linkEle.id + "_new";

        linkEle.parentNode.insertBefore(newLinkEle, linkEle);

    }

    newLinkEle.href = linkhref; //set the new stylesheet

    if(newLinkEle.readyState + "" != "undefined" &&  newLinkEle.readyState != "complete")

    {

        newLinkEle.dwObj = dwObj;

        newLinkEle.dwObjHtml = htmlstr;

        newLinkEle.onreadystatechange = HTDW_xhtmlLinkReadyStateChange;

        bDelay = true;

        dwObj.linkReadyStateChangeCount++;

    }

    else

    {

        linkEle.href = linkhref; //set the new stylesheet

        newLinkEle.dwObj = null;

        newLinkEle.dwObjHtml = null;

        newLinkEle.onreadystatechange = null;

    }

    if(linkhref1)

    {

        var linkEle1 = document.getElementById(dwObj.name + "_stylesheet1");

        if(linkEle1 == null)

        {

            linkEle1 = document.getElementById(dwObj.name + "_stylesheet").cloneNode(true);

            linkEle1.id = dwObj.name + "_stylesheet1";

            linkEle1.href = linkhref1;

            linkEle.parentNode.insertBefore(linkEle1, linkEle);

            if(linkEle1.readyState + "" != "undefined" &&  linkEle1.readyState != "complete")

            {

                linkEle1.dwObj = dwObj;

                linkEle1.dwObjHtml = htmlstr;

                linkEle1.onreadystatechange = HTDW_xhtmlLinkReadyStateChange;

                bDelay = true;

                dwObj.linkReadyStateChangeCount++;

            }

        }

        else

        {

            newLinkEle = document.getElementById(linkEle1.id + "_new"); //new link for buffer

            if(newLinkEle == null)

            {

                newLinkEle = linkEle1.cloneNode(true);

                newLinkEle.id = linkEle1.id + "_new";

                linkEle1.parentNode.insertBefore(newLinkEle, linkEle1);

            }

            newLinkEle.href = linkhref1;//set the new stylesheet

            if(newLinkEle.readyState + "" != "undefined" &&  newLinkEle.readyState != "complete")

            {

                newLinkEle.dwObj = dwObj;

                newLinkEle.dwObjHtml = htmlstr;

                newLinkEle.onreadystatechange = HTDW_xhtmlLinkReadyStateChange;

                bDelay = true;

                dwObj.linkReadyStateChangeCount++;

            }

            else

            {

                linkEle1.href = linkhref1; //set the new stylesheet

                newLinkEle.dwObj = null;

                newLinkEle.dwObjHtml = null;

                newLinkEle.onreadystatechange = null;

            }           

        }

    }



    // update html content

    if(!bDelay)

        dwContainerEle.innerHTML = htmlstr;



    // update rows script

    eval(rowscripts);

}



function HTDW_xhtmlLinkReadyStateChange()

{

    if(this.readyState == "complete")

    {

        this.dwObj.linkReadyStateChangeCount--;

        var timerId = window.setTimeout("HTDW_xhtmlLinkTimerCallback('" + this.id + "')", 5);

        this.timerId = timerId;

    }

}

function HTDW_xhtmlLinkTimerCallback(linkId)

{

    var linkEle, mainLinkEle, dwObj;

    linkEle = document.getElementById(linkId);

    dwObj = linkEle.dwObj;

    mainLinkEle = document.getElementById(linkId.substring(0, linkId.length - 4)); // remove "_new"

    window.clearTimeout(linkEle.timerId);

    mainLinkEle.href = linkEle.href; // set the main link href to the buffer one.

    if(dwObj.linkReadyStateChangeCount <= 0)

    { // update continer's innerHtml after stylsheet is ready.

        var savedIndicatorRow = -1;

        if(dwObj.bHasRowFocusIndicator && dwObj.indicatorRow != -1)

        {

            savedIndicatorRow = dwObj.indicatorRow;

            dwObj.showRowFocusIndicator(dwObj.indicatorRow, false);

        }



        var dwContainerEle = document.getElementById(dwObj.name);

        dwContainerEle.innerHTML = linkEle.dwObjHtml;



        if(dwObj.bHasRowFocusIndicator && savedIndicatorRow != -1)

           dwObj.showRowFocusIndicator(savedIndicatorRow, true);

    }

    linkEle.dwObjHtml = null;

}



function HTDW_PreCallbackArgClass(eventResult)

{

    this.eventResult = eventResult;

    this.resultModified = false;

}

function HTDW_callbackHandler(eventResult, context)

{

    var dwObj = context;

    var savedIndicatorRow = -1;

    var fRow, controlEle;

    if(dwObj == null)

        return;



    if(dwObj.onprecallback)

    {// give a chance for inheritor or wrapper (like .net dw) to check or modify its customized 

     // eventResult before passing it into our dw.

        var arg = new HTDW_PreCallbackArgClass(eventResult);

        dwObj.onprecallback(dwObj, arg);

        if(arg.resultModified) // check whether onprecallback returns the modified eventResult

            eventResult = arg.eventResult;

    }

    if(dwObj.rows)

        dwObj.rows.length = 0; //reset the rows.

    if(dwObj.rowInfos)

        dwObj.rowInfos.length = 0; //reset the rowInfos.

    if(dwObj.bHasRowFocusIndicator && dwObj.indicatorRow != -1)

    {

        savedIndicatorRow = dwObj.indicatorRow;

        dwObj.showRowFocusIndicator(dwObj.indicatorRow, false);

    }

    fRow = dwObj.firstRow;

    if(dwObj.renderFormat == 0) // html

        HTDW_htmlCallbackHandler(eventResult, dwObj);

    else if(dwObj.renderFormat == 1) // xhtml

        HTDW_xhtmlCallbackHandler(eventResult, dwObj);

    else // xml

        XMLDW_TransformCallbackPage(eventResult, dwObj);



    if(dwObj.currentControl)

        dwObj.currentControl = null; // clear the current control.

    if(dwObj.bHasRowFocusIndicator && savedIndicatorRow != -1)

        dwObj.showRowFocusIndicator(savedIndicatorRow, true);

    if(fRow != dwObj.firstRow && dwObj.action && (dwObj.action == "PageNext" || dwObj.action == "PagePrior" || 

       dwObj.action == "PageFirst" || dwObj.action == "PageLast" || dwObj.action.toUpperCase().indexOf("PAGETO") == 0))

    {

        controlEle = null;

        if(document.getElementById + "" != "undefined")

            controlEle = document.getElementById(dwObj.dwControlId);

        if(controlEle != null && controlEle.scrollTop + "" != "undefined")

            controlEle.scrollTop = 0;

    }

}

function HTDW_performAction(action)

{

    this.action = action;

	if ((this.pagingMode == DW_PAGING_XMLCLIENTSIDE) &&

		(action == "PageNext" ||

		 action == "PagePrior" ||

		 action == "PageFirst" ||

		 action == "PageLast"))

	{

		this.xmlRenderer.transformClientSidePage( action );

	}

	else if (this.pagingMode == DW_PAGING_XMLCLIENTSIDE &&

		action == "InsertRow")

	{

		this.xmlRenderer.insertClientSide( );

	}

	else if (this.pagingMode == DW_PAGING_XMLCLIENTSIDE &&

		action == "AppendRow")

	{

		this.actionRow = this.rows.length;

		this.xmlRenderer.insertClientSide( );

	}

	else if (this.pagingMode == DW_PAGING_XMLCLIENTSIDE &&

		action == "DeleteRow")

	{

		this.xmlRenderer.deleteClientSide( );

	}

	else if (this.b4GLWeb)

    {

		if ((this.pagingMode == DW_PAGING_CALLBACK) && (this.callback + "" != "undefined"))

			this.callback( HTDW_callbackHandler, action );

		else

        // cause the surrounding page to be submitted

		if (this.submit + "" != "undefined") //Asp.Net

			this.submit();

		else

        	psPage.Submit(); //Jsp Target

	}

	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"))

   	        {

   	        if(this.autoEventBind)

                               rc = _evtDefault(this.OnSubmit ());

   	        else

   	            rc = _evtDefault(this.OnSubmit (this));

                           }

        if (rc == 0)

            {

       	    this.actionField.value = this.action;

   	        this.contextField.value = this.GetFullContext();

            this.submitForm.submit();

            }

	    }

}



function HTDW_GetFullContext()

{

    var     result = this.context;



    if (result.indexOf("((DeleteRow") < 0)

	    result += "(";

    result += this.getChanges();

    if (this.actionRow != -1)

        result += "(row " + this.actionRow + ")";

    if (this.currRow != -1 && this.bDwDotNet)

        result += "(currentrow " + this.currRow + ")";

    if (this.currCol != -1 && this.bDwDotNet)

        result += "(currentcol " + this.currCol + ")";

    if (this.sortString != null)

        result += "(sortString '" + escapeString (this.sortString) + "')";

    var rowSelectedChanges = this.getRowSelectedChanges();

    if (rowSelectedChanges != null && rowSelectedChanges != "")

        result += rowSelectedChanges;

    result += ")";



    return result ;

}



function HTDW_getRowHtmlElement(row)

{

    if (row < 1)

        return null;

    var dwElement, rowElement, oneElement;

    var rowElementId;

    var count = 0;

    if (document.getElementById + "" != "undefined")

        {

        dwElement = document.getElementById(this.name + "_datawindow");

        if (dwElement == null)

            return null;

        rowElementId = this.name + "_detail_" + (row-1).toString();

        rowElement = null;

        if (HTDW_DataWindowClass.isIE4)

            rowElement = dwElement.all[rowElementId];

        else

            {

            var temp = document.getElementById(rowElementId);

            var tempArray = new Array();

            if (temp == null)

                return null;

            tempArray[0] = temp;

            count++;

            while (temp.nextSibling != null)

                {// find out all the following row elements. This cound happen in our tabular render.

                if (temp.nextSibling.id + "" != "undefined" && temp.nextSibling.id  != null && temp.nextSibling.id == rowElementId)

                    {                      

                    tempArray[count] = temp.nextSibling;

                    count++;

                    temp = temp.nextSibling;

                    }

                else

                    break;

                }

            if (tempArray.length > 1)

                rowElement = tempArray;

            else

                rowElement = temp;

            }       

        return rowElement;

        }

    return null;

}



function HTDW_showRowFocusIndicator(row, bShow)

{

    // show row focus indicator

    if (!this.bHasRowFocusIndicator || row < 0)

        return;

    if(this.indicatorRow == row && bShow)

        return;

    if(bShow)

         this.indicatorRow = row;

    else

         this.indicatorRow = -1;



    var rowElement, oneRowElement;

    rowElement = this.getRowHtmlElement(row + 1);

    if (rowElement != null)

        {

        oneRowElement = null;

        if (rowElement.length + "" != "undefined")

            oneRowElement = rowElement[0];

        else

            oneRowElement = rowElement;



        var imgElement, divRectElementLeft, divRectElementTop, divRectElementRight, divRectElementBottom;

        if (this.bRowFocusRect) // row focus indicator is rectangle

            {               

            divRectElementLeft = document.getElementById(this.name + "_" + "rowfocusindicator_left");

            divRectElementTop = document.getElementById(this.name + "_" + "rowfocusindicator_top");

            divRectElementRight = document.getElementById(this.name + "_" + "rowfocusindicator_right");

            divRectElementBottom = document.getElementById(this.name + "_" + "rowfocusindicator_bottom");

            if (divRectElementLeft == null  || divRectElementTop == null  || divRectElementRight == null  || divRectElementBottom == null)

                    return;

            }

        else

            {

             imgElement = document.getElementById(this.name + "_" + "rowfocusindicator");

             if (imgElement == null)

                 return;

            }

        if (bShow)

            {

            var offsetLeft, offsetTop;

            offsetLeft = 0;

            offsetTop = 0;

            if (oneRowElement.tagName.toUpperCase() == "TR")

                { // for grid, divRectElement is at the same level of dwElement <TABLE>. for others, divRectElement is inside the dwElement.

                 var dwElement = document.getElementById(this.name + "_datawindow");  

                 if (dwElement != null)

                    {

                    offsetLeft = dwElement.offsetLeft;

                    offsetTop = dwElement.offsetTop;

                    }          

                }

            if (this.bRowFocusRect) // row focus indicator is rectangle

                {                

                divRectElementLeft.style.left = (offsetLeft + oneRowElement.offsetLeft).toString() + "px";

                divRectElementLeft.style.top = (offsetTop + oneRowElement.offsetTop).toString() + "px";

                divRectElementLeft.style.width = "1px";



                divRectElementTop.style.left = (offsetLeft + oneRowElement.offsetLeft).toString() + "px";

                divRectElementTop.style.top = (offsetTop + oneRowElement.offsetTop).toString() + "px";

                divRectElementTop.style.width = oneRowElement.offsetWidth.toString() + "px";

                divRectElementTop.style.height = "1px";



                divRectElementRight.style.left = (offsetLeft + oneRowElement.offsetWidth).toString() + "px";

                divRectElementRight.style.top = (offsetTop + oneRowElement.offsetTop).toString() + "px";

                divRectElementRight.style.width = "1px";



                divRectElementBottom.style.left = (offsetLeft + oneRowElement.offsetLeft).toString() + "px";

                divRectElementBottom.style.height= "1px";

                divRectElementBottom.style.width = oneRowElement.offsetWidth.toString() + "px";



                if (oneRowElement != rowElement)

                    {

                    var totalHeight, i;

                    var tempElement;

                    totalHeight = 0;

                    for(i = 0; i < rowElement.length; i++)

                        {

                        tempElement = rowElement[i];

                        totalHeight += tempElement.offsetHeight;

                        }

                    divRectElementLeft.style.height = totalHeight.toString() + "px";

                    divRectElementRight.style.height = totalHeight.toString() + "px";

                    divRectElementBottom.style.top = (offsetTop + oneRowElement.offsetTop + totalHeight).toString() + "px";

                    }

                else

                    {

                    divRectElementLeft.style.height = oneRowElement.offsetHeight.toString() + "px";

                    divRectElementRight.style.height = oneRowElement.offsetHeight.toString() + "px";

                    divRectElementBottom.style.top = (offsetTop + oneRowElement.offsetTop + oneRowElement.offsetHeight).toString() + "px";                    

                    }

                

                divRectElementLeft.style.visibility = "visible";

                divRectElementTop.style.visibility = "visible";

                divRectElementRight.style.visibility = "visible";

                divRectElementBottom.style.visibility = "visible";

                // set the zIndex of divRectElement to a positive value so that it can overlap the row element since row element has not zIndex.

                divRectElementLeft.style.zIndex = 1;

                divRectElementTop.style.zIndex = 2;

                divRectElementRight.style.zIndex = 3;

                divRectElementBottom.style.zIndex = 4;        

                }

            else // bitmap row focus indicator

                { // for grid, imgElement is at the same level of dwElement <TABLE>. for others, imgElement is inside the dwElement.

                imgElement.style.left = (this.rowFocusIndicatorX + offsetLeft + oneRowElement.offsetLeft).toString() + "px";

                imgElement.style.top = (this.rowFocusIndicatorY + offsetTop + oneRowElement.offsetTop).toString() + "px";

                imgElement.style.visibility = "visible";              

                // set the zIndex of imgElementto a positive value so that it can overlap the row element since row element has not zIndex.

                imgElement.style.zIndex = 1;        

                }

            } // show

        else // hide

            {

            if (this.bRowFocusRect) // row focus indicator is rectangel

                {

                divRectElementLeft.style.visibility = "hidden";

                divRectElementTop.style.visibility = "hidden";

                divRectElementRight.style.visibility = "hidden";

                divRectElementBottom.style.visibility = "hidden";

                }

            else // bitmap row focus indicator

                {

                imgElement.style.left = "0px";

                imgElement.style.top = "0px";

                imgElement.style.visibility = "hidden";

                }

            }// hide

        } // element is not null

}



function HTDW_buttonPress(action, row, buttonName, bandID)

{

    var evtResult;



    // false from clicked will cancel processing

    if (!this.itemClicked(row, -1, buttonName, bandID))

        return;



    // button clicking event

    if (this.eventImplemented("ButtonClicking"))

        {

        var old_action = this.action;

        this.action = action;

        if(this.autoEventBind)

            evtResult = _evtDefault(this.ButtonClicking (row+1, buttonName));

        else

            evtResult = _evtDefault(this.ButtonClicking (this, row+1, buttonName));

        this.action = old_action;

        // 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"))

        {

        if(this.autoEventBind)

            evtResult = _evtDefault(this.UpdateStart ());

        else

            evtResult = _evtDefault(this.UpdateStart (this));

        // a return of 1 will cancel action

        if (evtResult == 1)

            return;

        }



    if (action == "Print")

	    {

        window.print();

        return;

        }

    // an action of "" is a user defined button which doesn't cause a page reload

    if (action != "")

        {

        if((action == "DeleteRow" || action == "InsertRow") && (bandID == 0))

            this.actionRow = row;

        else

            this.actionRow =  this.currRow;

        this.performAction(action);

        }

    else

        {

        // button clicked event

        if (this.eventImplemented("ButtonClicked"))

           {

           if(this.autoEventBind)

               this.ButtonClicked (row+1, buttonName)

           else

               this.ButtonClicked (this, row+1, buttonName)

           }            

        }

}



function HTDW_uneventfulButtonPress(action, row, buttonName, bandID)

{

    // make sure all changes have been recorded

    if (action != "" && this.AcceptText() != 1)

        // cancel processing if AcceptText fails

        return;



    if (action == "Print")

	    {

        window.print();

        return;

        }

    // an action of "" is a user defined button which doesn't cause a page reload

    if (action != "")

        {

        if((action == "DeleteRow" || action == "InsertRow") && (bandID == 0))

            this.actionRow = row;

        else

            this.actionRow =  this.currRow;

        this.performAction(action);

        }

}



// RowInfo class for client SelectRow.

function HTDW_RowInfoClass(rowKey, rowIdNo)

{

    this.key = rowKey;

    this.idNo = rowIdNo;

    this.origBkColor = null;

    this.origSelected = 0;

    if (arguments.length > 2)

        this.origBkColor = arguments[2];

    if (arguments.length > 3)

        this.origSelected = arguments[3];

     this.selected =  this.origSelected;

}



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_getRowSelectedChanges()

{

    var changes = "";

    if (this.rowInfos.length <= 0)

        return changes;



    for (index=this.firstRow; index <= this.lastRow; ++index)

        {

        if (this.rowInfos[index] != null && this.rowInfos[index].selected != this.rowInfos[index].origSelected)

           changes += ("(SelectRow " + this.rowInfos[index].key + " " + index.toString() + " " + this.rowInfos[index].idNo.toString() + " " + this.rowInfos[index].selected.toString() + ")");

        }

    return changes;

}



function HTDW_DeletedCount()

{

	return this.deletedCount;

}



function HTDW_DeleteRow(row)

{

	if(this.AcceptText() == 1)

		{

		if (row > 0)

    		    this.actionRow = row-1;

		else if(row == 0 && (this.currRow + "" != "undefined"))

    		     this.actionRow = this.currRow;

		else

		    return -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)

		{

		if(row > 0)

		    this.actionRow = row-1;

		else if(row == 0)

		    this.actionRow = -1;

		else

		    return -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_SetScroll(scrollAction, data)

{ //scrollAction: 1-scrolltorow(data is the row); 2-scroll page (data 0-prior page, 1-next page)



	var controlElement, rowElement, oneRowElement;

	controlElement = null;

	if (document.getElementById + "" != "undefined")

		controlElement = document.getElementById(this.dwControlId);

	if (controlElement == null)

		return -1;



	if (scrollAction == 1)

		{

		var row = data;

		if (row < 1)

			return -1;

		if ((row % this.rowsPerDetail) == 0)

			row = row / this.rowsPerDetail;

		else

			row = row / this.rowsPerDetail + 1;

		 rowElement = this.getRowHtmlElement(row);

		if (rowElement != null)

			{

			oneRowElement = null;

			 if (rowElement.length + "" != "undefined")

				 oneRowElement = rowElement[0];

			else

				oneRowElement = rowElement;

			}

		 if (oneRowElement == null )

			return -1;

		// do scroll

		if ((oneRowElement.offsetTop + oneRowElement.offsetHeight) > (controlElement.scrollTop + controlElement.clientHeight))

			{

			var temp = oneRowElement.offsetHeight - controlElement.clientHeight;

			controlElement.scrollTop = oneRowElement.offsetTop + (temp > 0 ? 0 : temp);//make sure begining of row is visible.			

			}

		else if (oneRowElement.offsetTop < controlElement.scrollTop)

			controlElement.scrollTop = oneRowElement.offsetTop;

		}

	else if (scrollAction == 2)

		{

		if (data)

			{

			controlElement.scrollTop = controlElement.scrollTop + controlElement.clientHeight;

			}

		else

			{

			controlElement.scrollTop = controlElement.scrollTop - controlElement.clientHeight;

			}

		}

	return 1;

}



function HTDW_SelectRow(row, select)

{

	if (this.rowInfos.length <= 0)

		return;

	if(row < (this.firstRow + 1) || row > (this.lastRow + 1) )

		return;

	if(this.IsRowSelected(row) && select)

		return;

	if(!this.IsRowSelected(row) && !select)

		return;



	var rowElement, i, oneRowElement;

	rowElement = this.getRowHtmlElement(row);

	if(rowElement != null)

		{

		if(select)

			{

			if(rowElement.length != null)

				{

				for(i = 0; i < rowElement.length; i++)

					{

					oneRowElement = rowElement(i);

					if(this.rowInfos[row-1].origBkColor == null)

						this.rowInfos[row-1].origBkColor = oneRowElement.style.backgroundColor;

					oneRowElement.style.backgroundColor = this.selectedRowColor;

					}

				}

			else

				{

				if(this.rowInfos[row-1].origBkColor == null)

					this.rowInfos[row-1].origBkColor = rowElement.style.backgroundColor;

				rowElement.style.backgroundColor = this.selectedRowColor;				

				}

			this.rowInfos[row-1].selected = 1;

			}

		else 

			{

			if(rowElement.length != null)

				{

				for(i = 0; i < rowElement.length; i++)

					{					

					oneRowElement = rowElement(i);					

					oneRowElement.style.backgroundColor = this.rowInfos[row-1].origBkColor;

					}

				}

			else

				{				

				rowElement.style.backgroundColor = this.rowInfos[row-1].origBkColor;

				}

			this.rowInfos[row-1].selected = 0;

			}

		}

}



function HTDW_IsRowSelected(row)

{

	if (this.rowInfos.length <= 0)

		return false;

	if(row < (this.firstRow + 1) || row > (this.lastRow + 1) )

		return false;

	if(this.rowInfos[row-1] != null && this.rowInfos[row-1].selected != 0)

		return true;

	return false;

}



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++;	    

			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);		

		

		this.refreshSharedDataWindows(row,col);

		

		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)

{

    var result = -1;

    row -= 1;

	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 DW_EditKeyPressed(e, control, nCase)

{

	if(nCase == 1)

	{

		if(window.event)

		{ //IE

			var str = String.fromCharCode(window.event.keyCode).toUpperCase();

			if(str.charCodeAt(0) != window.event.keyCode)

				window.event.keyCode = str.charCodeAt(0);

		}

		else if(e && (e.which || e.charCode))

		{

			var charCode, str;

			if(e.which)

				charCode = e.which;

			else

				charCode = e.charCode;

			str = String.fromCharCode(charCode).toUpperCase();

			if(str.charCodeAt(0) != charCode && (control.setSelectionRange + "") != "undefined")

			{

				var oldSelectionStart = control.selectionStart;

				var oldSelectionEnd = control.selectionEnd;

				if(control.value != null)

					control.value = control.value.substring(0, oldSelectionStart) + str + control.value.substring(oldSelectionEnd);

				else

					control.value = str;

				control.setSelectionRange(oldSelectionStart + str.length, oldSelectionStart + str.length);

				return false;

			}

		}

	}

	else if (nCase == 2)

	{

		if(window.event)

		{ //IE

			var str = String.fromCharCode(window.event.keyCode).toLowerCase();

			if(str.charCodeAt(0) != window.event.keyCode)

				window.event.keyCode = str.charCodeAt(0);

		}

		else if(e && (e.which || e.charCode))

		{

			var charCode, str;

			if(e.which)

				charCode = e.which;

			else

				charCode = e.charCode;

			str = String.fromCharCode(charCode).toLowerCase();

			if(str.charCodeAt(0) !=charCode && (control.setSelectionRange + "") != "undefined")

			{

				var oldSelectionStart = control.selectionStart;

				var oldSelectionEnd = control.selectionEnd;

				if(control.value != null)

					control.value = control.value.substring(0, oldSelectionStart) + str + control.value.substring(oldSelectionEnd);

				else

					control.value = str;

				control.setSelectionRange(oldSelectionStart + str.length, oldSelectionStart + str.length);

				return false;

			}

		}

	}

return true;

}



function DW_HideCalendar(calFrameName)

{

	var calFrame = document.getElementById(calFrameName);

	var nextFocus = document.elementFromPoint(window.event.clientX, window.event.clientY);



	if (nextFocus != calFrame && calFrame != null)

		calFrame.style.display = 'none';

}



function SetCellControlValue(control,gob,value)

{

	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)

        {

            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 && !(bSkipCurrent && control[r] == htmlDw.currentControl))

				{

         			control[r].checked=true;

				}

			}

		}

}

 

function HTDW_refreshControl(row,col)

{

	var control = null;

	var controlId = 'this.dataForm.' + this.name + '_' + row + '_' + col;

    var controlExists = eval('typeof ' + controlId);

    if (controlExists == "object")

    {

		control = eval(controlId);	          

		var value = this.rows[row][col];

		var gobName = this.cols[col].displayGobName;

		var gob = eval('this.gobs.'+gobName);

		SetCellControlValue(control,gob,value);

	}

}



function HTDW_share(masterDW)

{

	this.linkedDataWindows[this.linkedDataWindows.length]=masterDW;

	masterDW.linkedDataWindows[masterDW.linkedDataWindows.length]=this;

	this.rows = masterDW.rows;

	this.bIsSlaveSharedDataWindow=true;

}



function HTDW_refreshSharedDataWindows(row,col)

{

	if (this.eventImplemented("OnShareDataRefresh"))

	{

		var result ;

		if(this.autoEventBind)

			result = _evtDefault(this.OnShareDataRefresh());

		else

			result = _evtDefault(this.OnShareDataRefresh(this));

	}

	for (var i=0; i< this.linkedDataWindows.length; ++i)

	{

		var dw = this.linkedDataWindows[i];

		dw.refreshControl(row,col);

	}

}



function HTDW_DDDWClass_share(masterDW)

{

	masterDW.linkedDataWindows[masterDW.linkedDataWindows.length]=this;

	this.rows = masterDW.rows;

}



function HTDW_DDDWClass_refreshAffected(row,col)

{

	var control = null;

	var controlId = null;

	var controlExists = null;

	var len = this.dw.rows.length;

	var i;

	for(i=0; i<len; ++i)

	{

		control = null;

		controlId = 'this.dw.dataForm.' + this.dw.name + '_' + i + '_' + this.dwCol;

		controlExists = eval('typeof ' + controlId);

		if (controlExists == "object")

		{

			control = eval(controlId);

			if(control.options[0].value == this.options[row][1])

				control.options[0].text = this.options[row][0];	          

		}

	}

}



function HTDW_DDDWClass_refreshControl(row,col)

{

	var controlName = this.dw.name + "_" + this.gob + "_detail_" + row;

	var control = eval(controlName);

	if(col==this.displayCol)

	{

		this.options[row][0] = this.rows[row][col];

		control.children[1].innerText = this.rows[row][col];

		this.refreshAffected(row,col);

	}

	else if(col==this.dataCol)

	{

		this.options[row][1] = this.rows[row][col];

		control.children[0].innerText = this.rows[row][col];

	}

}



function HTDW_DDDWClass(dw,options,dataCol,displayCol,gob,dwCol)

{

	this.rows = null;

	this.dw = dw;

	this.gob = gob;

	this.dwCol = dwCol;

	this.options = options;

	this.dataCol = dataCol;

	this.displayCol = displayCol;

	this.refreshControl = HTDW_DDDWClass_refreshControl;

	this.refreshAffected = HTDW_DDDWClass_refreshAffected;

	this.share = HTDW_DDDWClass_share;

}



function XMLDW_CreateDOM() {

  var dom = null;

  for (var i=0; i < this.arrDOMProgID.length && dom == null; i++) {

    try {

      dom = new ActiveXObject(this.arrDOMProgID[i]);

    } catch (exception) {

    }

  }

  return dom;

}



function XMLDW_CreateXSLT() {

  var xslt = null;

  for (var i=0; i < this.arrXSLTProgID.length && xslt == null; i++) {

    try {

      xslt = new ActiveXObject(this.arrXSLTProgID[i]);

    } catch (exception) {

    }

  }

  return xslt;

}



function XMLDW_LoadDocument(filename) {

  var xmlDoc = this.createDOM();

  xmlDoc.async = false;

  xmlDoc.load(filename);

  return xmlDoc;

}



function XMLDW_LoadDocument_Msxml25(filename) {

  var xmlDoc = new ActiveXObject("MSXML.FreeThreadedDOMDocument");

  xmlDoc.async = false;

  xmlDoc.load(filename);

  return xmlDoc;

}



function XMLDW_LoadDocument_Mozilla(filename) {

  var dwXMLRequest = new XMLHttpRequest();

  dwXMLRequest.open("GET", filename, false);

  dwXMLRequest.send(null);

  return dwXMLRequest.responseXML;

}



function XMLDW_LoadDocumentString(xml) {

  var xmlDoc = this.createDOM();

  xmlDoc.async = false;

  xmlDoc.loadXML(xml);

  return xmlDoc;

}



function XMLDW_LoadDocumentString_Mozilla(xml) {

  var dwXMLParser = new DOMParser();

  return dwXMLParser.parseFromString(xml, "text/xml");

}



function XMLDW_LoadStylesheet_Mozilla(filename) {

  var dwXSLTRequest = new XMLHttpRequest();

  dwXSLTRequest.open("GET", filename, false);

  dwXSLTRequest.overrideMimeType("text/xml");

  dwXSLTRequest.send(null);



  return dwXSLTRequest.responseXML;

}



function XMLDW_DoTransform() {

  this.dwXSLT.stylesheet = this.dwXSL;

  var processor = this.dwXSLT.createProcessor();

  processor.input = this.dwXML;

  processor.transform();

  document.getElementById(this.divName).innerHTML = processor.output;

}



function XMLDW_DoTransform_Msxml25() {

  document.getElementById(this.divName).innerHTML = this.dwXML.transformNode(this.dwXSL);

}



function XMLDW_DoTransform_Mozilla() {

  var dwXSLTProcessor = new XSLTProcessor();

  dwXSLTProcessor.importStylesheet(this.dwXSL);

  var dwXHTML = dwXSLTProcessor.transformToFragment(this.dwXML, document);

  document.getElementById(this.divName).innerHTML = "";

  document.getElementById(this.divName).appendChild(dwXHTML);

}



function XMLDW_OrderBy(select, dataType) {

  this.dwXSL = this.loadDocument(this.dwXSLfile);

  var sortItem = this.dwXSL.getElementsByTagName("xsl:sort")[0];

  sortItem.setAttribute("select", select + "/text()");

  sortItem.setAttribute("data-type", dataType);

  if (this.dw != null) {

      if (this.dw.sortCol != select || !this.dw.sortAscending) {

          sortItem.setAttribute("order", "ascending");

          this.dw.sortAscending = true;

          this.dw.sortCol = select; }

      else {

          sortItem.setAttribute("order", "descending");

          this.dw.sortAscending = false; }

      }

  this.doTransform();

}



function XMLDW_OrderBy_Mozilla(select, dataType) {

  this.dwXSL = this.loadStylesheet(this.dwXSLfile);

  var sortItems,  sortItem;

  sortItems = null;

  if(this.dwXSL.getElementsByTagNameNS + "" != "undefined")

      sortItems = this.dwXSL.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "sort");

  if(sortItems == null || sortItems.length == 0)

      sortItems = this.dwXSL.getElementsByTagName("sort");

  sortItem = sortItems[0];

  sortItem.setAttribute("select", select + "/text()");

  sortItem.setAttribute("data-type", dataType);

  if (this.dw != null) {

      if (this.dw.sortCol != select || !this.dw.sortAscending) {

          sortItem.setAttribute("order", "ascending");

          this.dw.sortAscending = true;

          this.dw.sortCol = select; }

      else {

          sortItem.setAttribute("order", "descending");

          this.dw.sortAscending = false; }

      }

  this.doTransform();

}



function XMLDW_TransformCallbackPage(nextPage, dwObj) {

  var xmlRen = dwObj.xmlRenderer;

  if (xmlRen.bMozilla)

      xmlRen.dwXML = xmlRen.loadDocumentString(nextPage);

  else

      xmlRen.dwXML.loadXML(nextPage);

  var root = xmlRen.dwXML.documentElement;

  if (root.nodeName == "XSL-Required")

  {

      dwObj.pagingMode = DW_PAGING_POSTBACK;

      dwObj.performAction(dwObj.action);

  }

  else

  {

      var scriptNode = root.removeChild(root.lastChild);

      eval(scriptNode.text);

      xmlRen.doTransform();

  }

}



function XMLDW_TransformClientSidePage(action) {

  if (this.dw == null)

      return;

  var pageSize = this.dw.lastRow - this.dw.firstRow + 1;

  if (action == "PageNext")

  {

      if (this.dw.lastRow >= (this.dw.rows.length - 1))

          return;

      this.dw.firstRow = this.dw.lastRow + 1;

      this.dw.lastRow += pageSize;

  }

  else if (action == "PagePrior")

  {

      if (this.dw.firstRow == 0)

          return;

      this.dw.lastRow = this.dw.firstRow - 1;

      this.dw.firstRow -= pageSize;

      if (this.dw.firstRow < 0)

      {

          this.dw.firstRow = 0;

          this.dw.lastRow = pageSize - 1;

      }

  }

  else if (action == "PageFirst")

  {

      this.dw.firstRow = 0;

      this.dw.lastRow = pageSize - 1;

  }

  else if (action == "PageLast")

  {

      var lastPageSize = this.dw.rows.length % pageSize;

      if (lastPageSize == 0)

          lastPageSize = pageSize;

      this.dw.firstRow = this.dw.rows.length - lastPageSize;

      this.dw.lastRow = this.dw.firstRow + pageSize - 1;

  }



  var detailItem;

  if (this.bMozilla)

  {

      this.dwXSL = this.loadStylesheet(this.dwXSLfile);

      var detailItems = null;

      if (this.dwXSL.getElementsByTagNameNS + "" != "undefined")

          detailItems = this.dwXSL.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Transform", "apply-templates");

      if (detailItems == null || detailItems.length == 0)

          detailItems = this.dwXSL.getElementsByTagName("apply-templates");

      detailItem = detailItems[1];

  }

  else

  {

      this.dwXSL = this.loadDocument(this.dwXSLfile);

      detailItem = this.dwXSL.getElementsByTagName("xsl:apply-templates")[1];

  }

  detailItem.setAttribute("select", "*[not(self::band_header or self::band_footer)][@row >= " +

						this.dw.firstRow + " and @row <= " + this.dw.lastRow +"]");

  this.dw.currentControl = null;

  this.doTransform();

}



function XMLDW_InsertClientSide( ) {

  if (this.dw == null)

      return;

  var detailList = this.dwXML.getElementsByTagName("detail");

  var insertRow = (this.dw.actionRow >= 0) ? this.dw.actionRow : 0;

  var iInsert = (insertRow / this.dw.rowsPerDetail) | 0;

  var rowShift = String(iInsert * this.dw.rowsPerDetail); // init for Append

  var iInsertRowOff = insertRow % this.dw.rowsPerDetail + 1;

  var iRowOff = 0;

  var iColOff = 0;

  var column;

  var colName;

  var insertDetail;

  var insertColumn = null;

  var detail;

  var attrNode;

  var i, j;

  var bIncLastDetail = (this.dw.rows.length % this.dw.rowsPerDetail == 0);

  if (this.dw.rowsPerDetail > 1 && detailList.length > 1 && iInsert < (detailList.length - 1))

  {

      var gobType = null;

      if (this.bMozilla)

          insertDetail = detailList[iInsert];

      else

          insertDetail = detailList.item(iInsert);

      while (iRowOff != iInsertRowOff && iColOff < insertDetail.childNodes.length) {

          if (this.bMozilla)

              column = insertDetail.childNodes[iColOff++];

          else

              column = insertDetail.childNodes.item(iColOff++);

          gobType = column.getAttribute("gob");

          if (gobType != null && gobType == "text")

              continue;

          colName = column.nodeName;

          iRowOff = parseInt(colName.charAt(colName.length - 1));

      }

      if (iColOff < insertDetail.childNodes.length ||

          (gobType != null && gobType == "text"))

      {

          iColOff--;

          if (iRowOff < this.dw.rowsPerDetail)

              insertColumn = column;

      }

  }

  for (i=iInsert; i < (detailList.length - 1); i++) 

  {

      if (this.bMozilla)

          detail = detailList[i];

      else

          detail = detailList.item(i);

      if (bIncLastDetail)

          rowShift = String((i + 1) * this.dw.rowsPerDetail);

      else

          rowShift = String(i * this.dw.rowsPerDetail);

      if (this.dw.rowsPerDetail > 1)

      {

          column = null;



          var iNextColOff = 0;



          var nextDetail;

          var nextColumn = null;

          if ((i + 1) < (detailList.length - 1))

          {

              if (this.bMozilla)

              {

                  nextDetail = detailList[i + 1];

                  nextColumn = nextDetail.childNodes[0];

              }

              else

              {

                  nextDetail = detailList.item(i + 1);

                  nextColumn = nextDetail.childNodes.item(0);

              }

          }

          else if(bIncLastDetail)

          {

              var newDetail = this.dwXML.createElement("detail");

              newDetail.setAttribute("row", rowShift);

              if (this.bMozilla)

                  nextDetail = this.dwXML.documentElement.insertBefore(newDetail, detailList[i + 1]);

              else

                  nextDetail = this.dwXML.documentElement.insertBefore(newDetail, detailList.item(i + 1));

          }

          while (iNextColOff < detail.childNodes.length) {

              if (this.bMozilla)

                  column = detail.childNodes[iNextColOff];

              else

                  column = detail.childNodes.item(iNextColOff);

              var gobType = column.getAttribute("gob");

              if (gobType != null && gobType == "text")

              {

                  iNextColOff++;

                  continue;

              }

              colName = column.nodeName;

              iRowOff = parseInt(colName.charAt(colName.length - 1));

              if (iRowOff == this.dw.rowsPerDetail)

              {

                  if(nextColumn != null)

                  {

                    colName = colName.substr(0, colName.length - 1) + "0";

                  }

                  else

                  {

                    colName = colName.substr(0, colName.length - 1) + "1";

                  }

                  var newElem = this.dwXML.createElement(colName);

                  while (column.attributes.length > 0) {

                      if (this.bMozilla)

                          attrNode = column.removeAttributeNode(column.attributes[0]);

                      else

                          attrNode = column.removeAttributeNode(column.attributes.item(0));

                      newElem.setAttributeNode(attrNode);

                  }

                  newElem.text = column.text;

                  if (nextColumn != null)

                      nextDetail.insertBefore(newElem, nextColumn);

                  else

                      nextDetail.appendChild(newElem);

                  

                  detail.removeChild(column);

               }

               else

               {

                  iNextColOff++;

               }

           }



          iRowOff = 0;

          iColOff = 0

          while (iRowOff < this.dw.rowsPerDetail && iColOff < detail.childNodes.length) 

          {

              if (this.bMozilla)

                  column = detail.childNodes[iColOff++];

              else

                  column = detail.childNodes.item(iColOff++);

              var gobType = column.getAttribute("gob");

              if (gobType != null && gobType == "text")

                  continue;

              colName = column.nodeName;

              iRowOff = parseInt(colName.charAt(colName.length - 1));

              if (iRowOff < this.dw.rowsPerDetail && (iRowOff >= iInsertRowOff || i !=iInsert))

              {

                  colName = colName.substr(0, colName.length - 1) + String(iRowOff + 1);

                  var newElem = this.dwXML.createElement(colName);

                  while (column.attributes.length > 0) {

                      if (this.bMozilla)

                          attrNode = column.removeAttributeNode(column.attributes[0]);

                      else

                          attrNode = column.removeAttributeNode(column.attributes.item(0));

                      newElem.setAttributeNode(attrNode);

                  }

                  newElem.text = column.text;

                  if(insertColumn == column)

                  {

                    insertColumn = newElem;

                  }

                  detail.replaceChild(newElem, column);

              }

          }

      }

      else

      {

          detail.setAttribute("row", rowShift);

      }

  }

  for(j=0; j < 2; j++) {

      var bandFoot = null;

      if (j == 0)

          bandFoot = this.dwXML.getElementsByTagName("band_summary");

      else

          bandFoot = this.dwXML.getElementsByTagName("band_footer");

      if (bandFoot != null && bandFoot.length > 0)

      {

          if (this.bMozilla)

              bandFoot[0].setAttribute("row", rowShift);

          else

              bandFoot.item(0).setAttribute("row", rowShift);

      }

  }

  var emptyRow;

  if (this.bMozilla)

      emptyRow = detailList[i];

  else

      emptyRow = detailList.item(i);

  if (this.dw.rowsPerDetail > 1 && iInsert < (detailList.length - 1))

  {

      for (j=0; j < emptyRow.childNodes.length; j++) {

          var emptyCol;

          if (this.bMozilla)

              emptyCol = emptyRow.childNodes[j];

          else

              emptyCol = emptyRow.childNodes.item(j);

          colName = emptyCol.nodeName;

          colName = colName.substr(0, colName.length - 1) + String(iInsertRowOff);

          var newCol = this.dwXML.createElement(colName);

          newCol.text = emptyCol.text;

          if (insertColumn != null)

              insertDetail.insertBefore(newCol, insertColumn);

          else

              insertDetail.appendChild(newCol);

      }

  }

  else

  {

      var newRow = emptyRow.cloneNode(true);

      newRow.setAttribute("row", String(iInsert * this.dw.rowsPerDetail));

      if (this.bMozilla)

          this.dwXML.documentElement.insertBefore(newRow, detailList[iInsert]);

      else

          this.dwXML.documentElement.insertBefore(newRow, detailList.item(iInsert));

  }

  for (j=this.dw.rows.length; j > insertRow; j--) {

      this.dw.rows[j] = this.dw.rows[j - 1];

  }

  var reParens = /\[\]/g;

  var newRowIndex = "[" + String(insertRow) + "]";

  var newRowScript = this.dw.rowCreation.replace(reParens, newRowIndex);

  eval(newRowScript);

  this.dw.currentControl = null;

  if (this.dw.action == "AppendRow")

      this.transformClientSidePage("PageLast");

  else

      this.doTransform();

}



function XMLDW_DeleteClientSide( ) {

  if (this.dw == null)

      return;

  var detailList = this.dwXML.getElementsByTagName("detail");

  if (detailList.length < 2)

      return;

  var deleteRow = (this.dw.actionRow >= 0) ? this.dw.actionRow : 0;

  var iDelete = (deleteRow / this.dw.rowsPerDetail) | 0;

  var rowShift = "0";

  var iDeleteRowOff = deleteRow % this.dw.rowsPerDetail + 1;

  var iRowOff = 0;

  var iColOff = 0;

  var column;

  var colName;

  var deleteDetail;

  var iDeleteColOff = null;

  var iDeleteCount = 0;

  var detail;

  var attrNode;

  var i, j;

  var bDecLastDetail = (this.dw.rows.length % this.dw.rowsPerDetail == 1);

  // init rowShift for last row

  if (iDelete > 0)

  {

      if (this.dw.rowsPerDetail == 1 || bDecLastDetail)

          rowShift = String((iDelete - 1) * this.dw.rowsPerDetail);

      else

          rowShift = String(iDelete * this.dw.rowsPerDetail);

  }

  if (this.dw.rowsPerDetail > 1)

  {

      var gobType = null;

      if (this.bMozilla)

          deleteDetail = detailList[iDelete];

      else

          deleteDetail = detailList.item(iDelete);

      while (iColOff < deleteDetail.childNodes.length) {

          if (this.bMozilla)

              column = deleteDetail.childNodes[iColOff];

          else

              column = deleteDetail.childNodes.item(iColOff);

          gobType = column.getAttribute("gob");

          if (gobType != null && gobType == "text")

          {

              iColOff++;

              continue;

          }

          colName = column.nodeName;

          iRowOff = parseInt(colName.charAt(colName.length - 1));

          if (iRowOff == iDeleteRowOff)

          {

                deleteDetail.removeChild(column);          

          }

          else

          {

             iColOff++;

          }

      }

      if (iColOff < deleteDetail.childNodes.length ||

          (gobType != null && gobType == "text"))

          iColOff--;

  }

  for (var i=iDelete; i < (detailList.length - 1); i++) {

      if (this.bMozilla)

          detail = detailList[i];

      else

          detail = detailList.item(i);

      if (i > iDelete)

      {

          if (this.dw.rowsPerDetail == 1 || bDecLastDetail)

              rowShift = String((i - 1) * this.dw.rowsPerDetail);

          else

              rowShift = String(i * this.dw.rowsPerDetail);

      }

      iColOff = 0;

      if (this.dw.rowsPerDetail > 1)

      {

          var lastGob = null;

          while (iColOff < detail.childNodes.length) {

              if (this.bMozilla)

                  column = detail.childNodes[iColOff++];

              else

                  column = detail.childNodes.item(iColOff++);

              var gobType = column.getAttribute("gob");

              if (gobType != null && gobType == "text")

              {

                  if (lastGob == null)

                      lastGob = column;

                  continue;

              }

              colName = column.nodeName;

              iRowOff = parseInt(colName.charAt(colName.length - 1));

               if (i != iDelete || iRowOff > iDeleteRowOff)

               {

                  colName = colName.substr(0, colName.length - 1) + String(iRowOff - 1);

                  var newElem = this.dwXML.createElement(colName);

                  while (column.attributes.length > 0)

                  {

                      if (this.bMozilla)

                          attrNode = column.removeAttributeNode(column.attributes[0]);

                      else

                          attrNode = column.removeAttributeNode(column.attributes.item(0));

                      newElem.setAttributeNode(attrNode);

                  }

                  newElem.text = column.text;

                  detail.replaceChild(newElem, column);

               }

          }

          iRowOff = 0;

          if ((i + 1) < (detailList.length - 1))

          {

              var nextDetail;

              if (this.bMozilla)

                  nextDetail = detailList[i + 1];

              else

                  nextDetail = detailList.item(i + 1);

              var nextCol = 0;

              while (nextCol < nextDetail.childNodes.length) 

              {

                  if (this.bMozilla)

                      column = nextDetail.childNodes[nextCol];

                  else

                      column = nextDetail.childNodes.item(nextCol);

                  gobType = column.getAttribute("gob");

                  if (gobType != null && gobType == "text")

                  { 

                    nextCol ++;

                    continue;

                  }

                  colName = column.nodeName;

                  iRowOff = parseInt(colName.charAt(colName.length - 1));

                  if (iRowOff < 2)

                  {

                      colName = colName.substr(0, colName.length - 1) +

                                String(this.dw.rowsPerDetail);

                      var newElem = this.dwXML.createElement(colName);

                      while (column.attributes.length > 0) {

                          if (this.bMozilla)

                              attrNode = column.removeAttributeNode(column.attributes[0]);

                          else

                              attrNode = column.removeAttributeNode(column.attributes.item(0));

                          newElem.setAttributeNode(attrNode);

                      }

                      newElem.text = column.text;

                      if (lastGob != null)

                          detail.insertBefore(newElem, lastGob);

                      else

                          detail.appendChild(newElem);

                      nextDetail.removeChild(column);

                  }

                  else

                  {

                    nextCol++;

                  }

              }

              var bLastGobIsText = true;

              var iCol = 0;

              while( iCol < nextDetail.childNodes.length)

              {

                  if (this.bMozilla)

                      column = nextDetail.childNodes[iCol];

                  else

                      column = nextDetail.childNodes.item(iCol);

                  var gobType = column.getAttribute("gob");

                  if (gobType != null && gobType == "text")

                  {

                    iCol ++;

                  }

                  else

                  {

                    bLastGobIsText = false;

                    break;

                  }

              }

              if (nextDetail.childNodes.length == 0 || bLastGobIsText)

                  this.dwXML.documentElement.removeChild(nextDetail);

          }

          iColOff = 0;

      }

      else if (i > iDelete)

      {

          detail.setAttribute("row", rowShift);

      }

  }

  for(j=0; j < 2; j++) {

      var bandFoot = null;

      if (j == 0)

          bandFoot = this.dwXML.getElementsByTagName("band_summary");

      else

          bandFoot = this.dwXML.getElementsByTagName("band_footer");

      if (bandFoot != null && bandFoot.length > 0)

      {

          if (this.bMozilla)

              bandFoot[0].setAttribute("row", rowShift);

          else

              bandFoot.item(0).setAttribute("row", rowShift);

      }

  }

  if (this.dw.rowsPerDetail > 1 &&

      !(iDelete == (detailList.length - 2) && bDecLastDetail))

  {

   

  }

  else

  {

      if (this.bMozilla)

          this.dwXML.documentElement.removeChild(detailList[iDelete]);

      else

          this.dwXML.documentElement.removeChild(detailList.item(iDelete));

  }

  if (this.dw.context.indexOf("((DeleteRow") < 0) 

      this.dw.context += "("; 

  this.dw.context += "(DeleteRow " + this.dw.rows[deleteRow][0].rowId + ")";

  for (var k=deleteRow; k < this.dw.rows.length - 1; k++) {

      this.dw.rows[k] = this.dw.rows[k + 1];

  }

  this.dw.rows.length--;

  this.dw.currentControl = null;

  this.doTransform();

}



function XMLDW_RendererClass(parentDW, name, bMsxml25, bMozilla)

{

	this.arrDOMProgID = ["Msxml2.FreeThreadedDOMDocument.6.0",

						 "Msxml2.FreeThreadedDOMDocument.4.0",

						 "Msxml2.FreeThreadedDOMDocument.3.0",

						 "Msxml2.FreeThreadedDOMDocument.2.6",

						 "Msxml2.FreeThreadedDOMDocument",

						 "MSXML.FreeThreadedDOMDocument"];



	this.arrXSLTProgID = ["Msxml2.XSLTemplate.6.0",

						  "Msxml2.XSLTemplate.4.0",

						  "Msxml2.XSLTemplate.3.0",

						  "Msxml2.XSLTemplate.2.6",

						  "Msxml2.XSLTemplate"];

	this.dw = parentDW;

	this.divName = name;

	this.bMozilla = bMozilla;



	this.createDOM = XMLDW_CreateDOM;

	this.createXSLT = XMLDW_CreateXSLT;

	if (bMsxml25)

	{

		this.loadDocument = XMLDW_LoadDocument_Msxml25;

		this.doTransform = XMLDW_DoTransform_Msxml25;

	}

	else if (bMozilla)

	{

		this.loadDocument = XMLDW_LoadDocument_Mozilla;

		this.loadStylesheet = XMLDW_LoadStylesheet_Mozilla;

		this.doTransform = XMLDW_DoTransform_Mozilla;

		this.orderBy = XMLDW_OrderBy_Mozilla;

		this.loadDocumentString = XMLDW_LoadDocumentString_Mozilla;

	}

	else

	{

		this.loadDocument = XMLDW_LoadDocument;

		this.doTransform = XMLDW_DoTransform;

		this.orderBy = XMLDW_OrderBy;

		this.loadDocumentString = XMLDW_LoadDocumentString;

	}

	this.transformClientSidePage = XMLDW_TransformClientSidePage;

	this.insertClientSide = XMLDW_InsertClientSide;

	this.deleteClientSide = XMLDW_DeleteClientSide;

}



function HTDW_DataWindowClass(name)

{

    this.name = name;

    this.submitForm = null;

    this.actionField = null;

    this.contextField = null;

    this.sortString = null;

    this.sortCol = "";

    this.sortAscending = false;

    this.action = "";

    this.bDwDotNet = false;

    this.dwControlId = name + "_datawindow";

    this.indicatorRow = -1;

    

    // private functions

    this.buttonPress = HTDW_buttonPress;

    this.uneventfulButtonPress = HTDW_uneventfulButtonPress;

	this.performAction = HTDW_performAction;

    this.getRowHtmlElement = HTDW_getRowHtmlElement;

    this.showRowFocusIndicator =  HTDW_showRowFocusIndicator;



    this.eventImplemented = HTDW_eventImplemented;

    this.itemClicked = HTDW_itemClicked;

    this.itemDoubleClicked = HTDW_itemDoubleClicked;

    this.itemRButtonDown = HTDW_itemRButtonDown;

    this.addEventImplementation = HTDW_AddEventImplementation;

    this.autoEventBind = true;

	this.bSuppressItemGainFocusCallback=false;

	this.oPBNETData = null;

	this.nOutOfFocusRow = -1;

	this.nOutOfFocusCol = -1;



    // public function

    this.GetFullContext = HTDW_GetFullContext;   

    

    this.currRow = -1;

    this.currCol = -1;

    this.actionRow = -1;

    this.forcingBackFocusTo = null;

    this.currentControl = null;

    this.bSingleRow = false;

    this.acceptControl = null;

    

    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;

    this.positionComboBox = HTDW_positionComboBox;

    this.addDDDWOptions = HTDW_addDDDWOptions;

    this.removeDDDWOptions = HTDW_removeDDDWOptions;

    this.overrideDDDWSelect = HTDW_overrideDDDWSelect;

    this.setDDDWVisible = HTDW_setDDDWVisible;

    this.scrollDDDW = HTDW_scrollDDDW;

    this.setDDDWItem = HTDW_setDDDWItem;



    // public functions

    this.AcceptText = HTDW_acceptText;



	this.linkedDataWindows = new Array();

	this.share = HTDW_share;

	this.refreshSharedDataWindows = HTDW_refreshSharedDataWindows;

	this.refreshControl = HTDW_refreshControl;

	this.bIsSlaveSharedDataWindow = false;



	this.bIsQueryMode = false;

	this.bIsQuerySort = false;

	this.ValidateQueryCriterion = HTDW_validateQueryCriterion; 



    // private functions

    this.rowInfos = new Array();

    this.getColNum = HTDW_getColNum;

    this.getRowSelectedChanges = HTDW_getRowSelectedChanges;

    

    // 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.IsRowSelected = HTDW_IsRowSelected;

	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.SelectRow = HTDW_SelectRow;

	this.SetScroll = HTDW_SetScroll;

	this.SetItem = HTDW_SetItem

	this.SetColumn = HTDW_SetColumn

	this.SetRow = HTDW_SetRow

	this.SetSort = HTDW_SetSort

	this.Sort = HTDW_Sort;

	this.Update = HTDW_Update



}



// 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;

}


