Listing 1

<script language='JavaScript'>
function dw_OnSubmit( )
{
	/** gets the context and action */
	this.submitForm.dw_context.value = this.GetFullContext();
	this.submitForm.dw_action.value = this.action;
	
	/** custom processing... */
	
	/** gather the data of the submit form in a query string format */
	var args = getFormValues(this.submitForm);
	
	/** triggers the AJAX request */
	loadXMLDoc( this.submitForm.action, args, dw_callBack );
	
	/** prevent the client control from submitting */
	return 1;
}
</script>

Listing 2

/*
Cross-browser instantiating of the XMLHttpRequest object
*/
function CreateXMLHttpRequestObject () {

	var lo_xmlHttpReq = null;

    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			lo_xmlHttpReq = new XMLHttpRequest();
        } catch(e) {
			lo_xmlHttpReq = null;
        }
    } 

    // branch for IE/Windows ActiveX version
	else if(window.ActiveXObject) {
       	try {
        	lo_xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		lo_xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		lo_xmlHttpReq = null;
        	}
		}
    }

	return lo_xmlHttpReq;
}

/*
Triggers an AJAX request

Parameters
URL - XML generator page 
callBack - function pointer that will be called when the XML is loaded
[Arg] - Parameters to the URL in query string format
*/
function loadXMLDoc ( URL, callBack, Arg ) {

	var xmlHttpObj = CreateXMLHttpRequestObject ();
	
	try {

		xmlHttpObj.onreadystatechange = function () { 
			processReqChange ( xmlHttpObj, callBack ); 
		};

		if ( Arg != null ) {
			URL += "?" + Arg
		}

		xmlHttpObj.open( "GET", URL, true );

		try {
			xmlHttpObj.setRequestHeader( "Content-Type", "text/xml" );
		} catch (e) { }

		xmlHttpObj.send ( null );
		return true;
	}
	catch(e) {
		alert ( "AJAX error. (loadXMLDoc)\n" + e.name + ": " + e.message );
		return false;
	}
}

/*
Checks if the AJAX request is complete, and, if so, triggers the callBack function
*/
function processReqChange ( xmlHttpObj, callBack ) {

    // only if req shows "loaded"
    if (xmlHttpObj.readyState == 4) {

        // only if "OK"
        if (xmlHttpObj.status == 200) {

            // ...processing statements go here...
			var xml = xmlHttpObj.responseXML;

			callBack ( xml );

        } else {
			if ( typeof xmlHttpObj.statusText == "undefined" )
	            alert( "There was a problem retrieving the XML data. (" + xmlHttpObj.status + ")" );
			else
	            alert( "There was a problem retrieving the XML data.\n" + xmlHttpObj.statusText + " (" +
				 xmlHttpObj.status + ")" );
        }
    }
}

/**
Get all values in a form in query string format
*/
function getFormValues ( form )
{
	var queryString = "";

	for( var i = 0; i < form.elements.length; i++ )
	{
		if ( queryString != "" )
			queryString += "&";

		queryString += escape( form.elements[i].name ) + "=" + escape( form.elements[i].value );
	}

	return queryString;
}

Listing 3

'Removes the JavaScript part
Function stripJSCode ( ByRef htmlCode )

	Set regExpJS = New RegExp
	With regExpJS
		.Pattern = "(<script[^>]*?>)(.|\n)*?(?=</script\s*>)(</script\s*>){1}"
		.IgnoreCase = True
		.Global = True
	End With

	Set matchJS = regExpJS.Execute( htmlCode )

	Dim scripts( )
	ReDim scripts( matchJS.Count - 1 )

	Set regExpHTML = New RegExp
	With regExpHTML
		.Pattern = "<(\w|/)([^>]|\n)*>"
		.IgnoreCase = True
		.Global = True
	End With

	For i = 0 To matchJS.Count - 1
		scripts(i) = regExpHTML.Replace( matchJS(i).Value, "" )
	Next

	htmlCode = regExpJS.Replace( htmlCode, "" )

	If i = 0 Then
		stripJSCode = null
	Else
		stripJSCode = scripts
	End If

End Function

'Removes CSS part
Function stripCSSCode ( ByRef htmlCode )

	Set regExpStyle = New RegExp
	With regExpStyle
		.Pattern = "(<style[^>]*?>)(.|\n)*?(?=</style\s*>)(</style\s*>){1}"
		.IgnoreCase = True
		.Global = True
	End With

	Set matchStyle = regExpStyle.Execute( htmlCode )

	Dim styles( )
	ReDim styles( matchStyle.Count - 1 )

	For i = 0 To matchStyle.Count - 1
		styles(i) = matchStyle(i).Value
	Next

	htmlCode = regExpStyle.Replace( htmlCode, "" )
	stripCSSCode = styles

End Function

Listing 4

<htmldw>
	<!-- The HTML part holding form's, span's and all HTML tags -->
	<html><![CDATA[
		<SPAN STYLE="position:relative; height:0.750in; width:6.061in;background-color:transparent" >

<FORM  NAME="dw_submitForm" METHOD="POST" ACTION="sessao.asp">
<INPUT TYPE="hidden" NAME="dw_action" VALUE="none">
<INPUT TYPE="hidden" NAME="dw_context" VALUE="">
</FORM>
	....
	]]></html>

	<!-- The CSS part holding all style tags -->
	<style>
		<![CDATA[
<STYLE TYPE="text/css">
<!--
.dw692{;background-color:transparent}
...
		</style>
		]]>
	</style>

	<!-- The JavaScript part holding all code -->
	<javascript>
		<![CDATA[
// create our control object
dw = new HTDW_DataWindowClass("dw"
 ,document.dw_submitForm,document.dw_submitForm.dw_action,document.dw_submitForm.dw_context );

// save state for scripting functions
dw.rowCount = 1;
dw.deletedCount = 0;
dw.filteredCount = 0;
...
		]]>
	</javascript>
</htmldw>

Listing 5

<?xml version="1.0" standalone="no"?>
<htmldw>
	<!-- This is the HTML part of the WebDataWindow control -->
	<html><
	![CDATA[<SPAN STYLE="position:relative; height:0.750in; width:6.061in;background-color:transparent" >

<FORM  NAME="dw_submitForm" METHOD="POST" ACTION="sessao.asp">
<INPUT TYPE="hidden" NAME="pac_reg" VALUE="400">
<INPUT TYPE="hidden" NAME="dw_action" VALUE="none">
<INPUT TYPE="hidden" NAME="dw_context" VALUE="">
</FORM>

<FORM  NAME="dw_dataForm" METHOD="" ACTION="" onSubmit="{return false;}">
<SPAN CLASS=dw692 STYLE="position:absolute; left:0.000in; top:0.000in; width:6.061in; height:0.250in"
 onClick="{dw.itemClicked(0,-1,'datawindow');}" >
      <SPAN CLASS=dw694 STYLE="position:absolute; left:0.000in; top:0.010in; width:0.187in"  onClick="{return
	   dw.itemClicked(0,-1,'t_2');}" ></SPAN>
     <SPAN CLASS=dw695 STYLE="position:absolute; left:0.251in; top:0.010in; width:3.124in"  onClick="{return
	  dw.itemClicked(0,-1,'h_shm_bul_med_t');}" >Medicamento</SPAN>
     <SPAN CLASS=dw695 STYLE="position:absolute; left:4.874in; top:0.010in; width:1.187in"  onClick="{return
	  dw.itemClicked(0,-1,'t_1');}" >Via</SPAN>
     <SPAN CLASS=dw695 STYLE="position:absolute; left:3.438in; top:0.010in; width:1.374in"  onClick="{return
	  dw.itemClicked(0,-1,'h_shm_dose_t');}" >Dose</SPAN>
</SPAN><SPAN>
</SPAN>
<SPAN CLASS=dw692 STYLE="position:absolute; left:0.000in; top:0.250in; width:6.061in; height:0.250in"
 onClick="{dw.itemClicked(0,-1,'datawindow');}" >
      <SPAN CLASS=dw69A STYLE="position:absolute; 
	  left:0.000in; top:0.010in; 
	  width:0.187in"  onClick="{return dw.itemClicked(0,-1,'t_3');}" >
	   <A HREF="javascript:dw.DeleteRow ( 1 );" NAME="t_3_0" >Apagar</A>
	   </SPAN>
     <INPUT TYPE="text" NAME="bul_bul_nome_0" SIZE=33 VALUE="" CLASS=dw69B TABINDEX=1002 STYLE="position:absolute;
	  left:0.937in; 
	  top:0.010in; width:2.188in" READONLY onFocus="{dw.itemGainFocus(0,9,this,dw.gobs.bul_bul_nome);}"
	   onClick="{var ret;  ret= dw.itemClicked(0,9,'bul_bul_nome'); 
	   return ret;}" onChange="{this.bChanged = true;}"
	    onkeypress="DW_EditKeyPressed(-1)" onBlur="{dw.itemLoseFocus (this);}">
     <SPAN CLASS=dw69C STYLE="position:absolute; 
	 left:3.188in; 
	 top:0.010in; width:0.187in"  onClick="{return
	  dw.itemClicked(0,-1,'t_4');}" >
	  <A HREF="javascript:dw_SearchBul( 1 );" NAME="t_4_0" >Buscar</A>
	  </SPAN>
     <INPUT TYPE="text" NAME="h_shm_bul_med_0" SIZE=9 VALUE="" CLASS=dw69D TABINDEX=1001 STYLE="position:absolute;
	  left:0.251in; 
	  top:0.010in; 
	  width:0.624in" onFocus="{dw.itemGainFocus(0,3,this,dw.gobs.h_shm_bul_med);}"
	   onClick="{var ret;  ret= dw.itemClicked(0,3,'h_shm_bul_med'); 
	   return ret;}" onChange="{this.bChanged = true;}"
	    onkeypress="DW_EditKeyPressed(-1)" onBlur="{dw.itemLoseFocus (this);}">
     <INPUT TYPE="text" NAME="h_shm_dose_0" SIZE=4 MAXLENGTH=15 VALUE="" CLASS=dw69D TABINDEX=1003
	  STYLE="position:absolute; 
	  left:3.438in; 
	  top:0.010in; width:0.312in" onFocus="{dw.itemGainFocus(0,4,this,dw.gobs.h_shm_dose); 
	   dw.selectControlContent(this);}" onClick="{var ret;
	    ret= dw.itemClicked(0,4,'h_shm_dose'); 
		return ret;}" onChange="{this.bChanged = true;}"
		 onkeypress="DW_EditKeyPressed(-1)" onBlur="{dw.itemLoseFocus (this);}">
     <SELECT NAME="h_shm_bun_cod_0" CLASS=dw69D TABINDEX=1004 STYLE="position:absolute; 
	 left:3.812in; 
	 top:0.010in;
	  width:1.000in" onFocus="{dw.itemGainFocus(0,5,this,dw.gobs.h_shm_bun_cod);}
	  " onClick="{var ret;  ret= dw.itemClicked(0,5,'h_shm_bun_cod'); 
	   return ret;}" onChange="{this.bChanged = true;dw.AcceptText();}"
	    onBlur="{dw.itemLoseFocus (this);}">
		<OPTION VALUE="" SELECTED>
<OPTION VALUE="PER">%
<OPTION VALUE="NE">[Nao Especificado]
<OPTION VALUE="ALM">almotolia(s)
<OPTION VALUE="AMP">ampola(s)
<OPTION VALUE="APL">aplicacao(oes)
</SELECT>
     <SELECT NAME="h_shm_bvi_cod_0" CLASS=dw69D TABINDEX=1005 STYLE="position:absolute; 
	 left:4.874in; 
	 top:0.010in; width:1.187in" onFocus="{dw.itemGainFocus(0,6,this,dw.gobs.h_shm_bvi_cod);}\
" onClick="{var ret;  ret= dw.itemClicked(0,6,'h_shm_bvi_cod'); 
return ret;}" onChange="{this.bChanged = true;dw.AcceptText();}" 
onBlur="{dw.itemLoseFocus (this);}">
<OPTION VALUE="" SELECTED>
<OPTION VALUE="NE">[Nao Especificado]
<OPTION VALUE="SNE">sonda nasoenterica
<OPTION VALUE="SNG">sonda nasogastrica
<OPTION VALUE="VB">via barriga
<OPTION VALUE="VN">via endovenosa
<OPTION VALUE="GST">via gastrotomia
<OPTION VALUE="INL">via inalatoria
</SELECT>
</SPAN>
<SPAN CLASS=dw692 STYLE="position:absolute; 
left:0.000in; top:0.500in; 
width:6.061in; 
height:0.250in"  onClick="{dw.itemClicked(0,-1,'datawindow');}" >
     <INPUT TYPE="submit" TABINDEX=1009  NAME="cb_submit_shm" VALUE="Gravar" CLASS=dw6A3 STYLE="position:absolute;
	  left:0.000in; 
	  top:0.073in; 
	  width:0.624in; height:0.188in" onClick="{dw.buttonPress('Update',0,'cb_submit_shm'); dw.restoreFocus();}">
</SPAN></FORM>

</SPAN>]]>
	</html>
	<!-- This is the JavaScript code part of the WebDataWindow control -->
	<javascript><![CDATA[;
// create our control object
dw = new HTDW_DataWindowClass("dw"
 ,document.dw_submitForm,document.dw_submitForm.dw_action,document.dw_submitForm.dw_context );

// save state for scripting functions
dw.rowCount = 1;
dw.deletedCount = 0;
dw.filteredCount = 0;
dw.modifiedCount = 1;
dw.sortString = "h_shm_reg_dthr A";
dw.bStylePositioning = true;
dw.b4GLWeb = false;


dw.context = "(dw 0)(1681 (InsertRow 0 ((1 0 '400')(2 0 '3')(3 1 )(4 1 )(5 1 )(6 1 )
(7 0 'MEDICWARE')(8 0 '2006-04-28 13:35:17:000000')(9 1 ))))";

var DW_shortDateFormat = "d/M/yyyy";
var DW_longDateFormat = "dddd, d' de 'MMMM' de 'yyyy";
var DW_timeFormat = "hh:mm:ss";

var DW_posCurrencyFormat = "R$ #,##0.00";
var DW_negCurrencyFormat = "(R$ #,##0.00)";
var DW_decimalChar = ",";
var DW_thousandsChar = ".";
;
 dw.cols[1] = new HTDW_ColumnClass(1, 'h_shm_pac_reg',DW_IntParse,DW_IsNumber,null,null,null,null);
 dw.cols[2] = new HTDW_ColumnClass(2, 'h_shm_shd_id',DW_IntParse,DW_IsNumber,null,null,null,null);
 dw.cols[3] = new HTDW_ColumnClass(3, 'h_shm_bul_med',DW_StringParse,DW_IsString,null,null,null,'h_shm_bul_med');
 dw.gobs.h_shm_bul_med = new HTDW_ColumnGob('h_shm_bul_med',3, 0, 0, false, false, false, null, null, null,
  dw.cols[3]);
 dw.cols[3].addDepend(new HTDW_DependColumn(dw.gobs.h_shm_bul_med));
 dw.cols[4] = new HTDW_ColumnClass(4, 'h_shm_dose',DW_StringParse,DW_IsString,null,null,null,'h_shm_dose');
 dw.gobs.h_shm_dose = new HTDW_ColumnGob('h_shm_dose',4, 0, 0, false, true, false, null, null, null, dw.cols[4]);
 dw.cols[4].addDepend(new HTDW_DependColumn(dw.gobs.h_shm_dose));
 dw.cols[5] = new HTDW_ColumnClass(5, 'h_shm_bun_cod',DW_StringParse,DW_IsString,null,null,null,'h_shm_bun_cod');
 dw.gobs.h_shm_bun_cod = new HTDW_ColumnGob('h_shm_bun_cod',5, 0, 0, false, true, false, null, null, null, dw.cols[5]);
 dw.cols[5].addDepend(new HTDW_DependColumn(dw.gobs.h_shm_bun_cod));
 dw.cols[6] = new HTDW_ColumnClass(6, 'h_shm_bvi_cod',DW_StringParse,DW_IsString,null,null,null,'h_shm_bvi_cod');
 dw.gobs.h_shm_bvi_cod = new HTDW_ColumnGob('h_shm_bvi_cod',6, 0, 0, false, true, false, null, null, null, dw.cols[6]);
 dw.cols[6].addDepend(new HTDW_DependColumn(dw.gobs.h_shm_bvi_cod));
 dw.cols[7] = new HTDW_ColumnClass(7, 'h_shm_reg_usr_login',DW_StringParse,DW_IsString,null,null,null,null);
 dw.cols[8] = new HTDW_ColumnClass(8, 'h_shm_reg_dthr',DW_DatetimeParse,DW_IsDatetime,null,null,null,null);
 dw.cols[9] = new HTDW_ColumnClass(9, 'bul_bul_nome',DW_StringParse,DW_IsString,null,null,null,'bul_bul_nome');
 dw.gobs.bul_bul_nome = new HTDW_ColumnGob('bul_bul_nome',9, 0, 0, false, false, false, null, null, null, dw.cols[9]);
 dw.cols[9].addDepend(new HTDW_DependColumn(dw.gobs.bul_bul_nome));
;
 dw.rows[0] = new HTDW_RowClass( "((1 0 '400')(2 0 '3')(3 1 ))",2,400,3,null,null,null,null,"MEDICWARE",new
  DW_DatetimeClass(106,3,28,13,35,17,0),null);
;

dw.firstRow = 0;
dw.lastRow = 1 - 1;
dw.bSingleRow = (dw.firstRow == dw.lastRow);
dw.dataForm = document.dw_dataForm;
;dw.AJAX=true;]]>
	</javascript>
	<!-- This is the CSS part of the WebDataWindow control -->
	<style><![CDATA[<STYLE TYPE="text/css">
<!--
.dw692{;background-color:transparent}
.dw694{;background-color:#eaeaea; width:100%;COLOR:#000000;FONT:8pt "Verdana",
 sans-serif;FONT-STYLE:normal;FONT-WEIGHT:normal;TEXT-DECORATION:none;TEXT-ALIGN:left;BORDER-STYLE:none}
 .dw695{;background-color:#eaeaea; width:100%;COLOR:#000000;FONT:8pt "Verdana",
  sans-serif;FONT-STYLE:normal;FONT-WEIGHT:normal;TEXT-DECORATION:none;TEXT-ALIGN:center;BORDER-STYLE:none}
.dw69A{;background-color:transparent;COLOR:#000000;FONT:12pt "Arial",
 sans-serif;FONT-STYLE:normal;FONT-WEIGHT:normal;TEXT-DECORATION:none;TEXT-ALIGN:left;BORDER-STYLE:none}
.dw69B{;background-color:#eaeaea; width:100%;COLOR:#000000;FONT:8pt "Verdana",
 sans-serif;FONT-STYLE:normal;FONT-WEIGHT:normal;TEXT-DECORATION:none;TEXT-ALIGN:left;BORDER-STYLE:inset}
.dw69C{;background-color:#ffffff; width:100%;COLOR:#000000;FONT:8pt "Verdana",
 sans-serif;FONT-STYLE:normal;FONT-WEIGHT:normal;TEXT-DECORATION:none;TEXT-ALIGN:left;BORDER-STYLE:none}
.dw69D{;background-color:transparent;COLOR:#000000;FONT:8pt "Verdana",
 sans-serif;FONT-STYLE:normal;FONT-WEIGHT:normal;TEXT-DECORATION:none;TEXT-ALIGN:left;BORDER-STYLE:inset}
.dw6A3{;background-color:#d4d0c8; width:100%;COLOR:#000000;FONT:7pt "Verdana",
 sans-serif;FONT-STYLE:normal;FONT-WEIGHT:normal;TEXT-DECORATION:none;TEXT-ALIGN:center}
-->
</STYLE>]]>
	</style>
</htmldw>

Listing 6

/** callback AJAX function */
function dw_callBack( xml )
{
	/** perform some initial validations on the xml returned and other custom processing */

	/** gets the client control parts */
	var htmldwHTML;
	var htmldwCSS;
	var htmldwJavaScript;

	/** Use XPath to get XML parts */
	if (window.ActiveXObject)
	{
		htmldwHTML = xml.selectSingleNode( "/htmldw/html" ).text;
		htmldwCSS = xml.selectSingleNode( "/htmldw/style" ).text;
		htmldwJavaScript = xml.selectSingleNode( "/htmldw/javascript" ).text;
	}
	else
	{
		htmldwHTML = document.evaluate ( "/htmldw/html", xml, 
			null, XPathResult.STRING_TYPE, null ).stringValue;
		htmldwCSS = document.evaluate ( "/htmldw/style", 
			xml, null, XPathResult.STRING_TYPE, null ).stringValue;
		htmldwJavaScript = document.evaluate ( "/htmldw/javascript", 
			xml, null, XPathResult.STRING_TYPE, null ).stringValue;
	}
	
	/** identifies the object that is currently holding the client control */
	var htmldwContainer = dw.submitForm.parent.parent;
	
	/** change htmldw container innerHTML property */
	htmldwContainer.innerHTML = htmldwHTML;
	
	/** add the CSS part */
	htmldwContainer.innerHTML += htmldwCSS;
	
	/** eval the JavaScript part */
	try
	{
		eval( htmldwJavaScript );
	}
	catch( exp )
	{ 
		alert( "Error running WebDataWindow code. \n" + exp.message );
	}
}