function WDG_JsRecordset($RecordsetName)
    {
        $rs = $GLOBALS[$RecordsetName];
        if (is_resource($rs)) {
            $recordset = new KT_Recordset($rs);
        } else {
            $recordset =& $rs;
        }
        $nl = "\r\n";
        $this->outputString .= <<<EOD
<script>
top.jsRawData_{$RecordsetName} = [

EOD;
        $fieldCount = $recordset->FieldCount();
        $fieldNames = array();
        for ($i = 0; $i < $fieldCount; $i++) {
            $meta = $recordset->FetchField($i);
            if ($meta) {
                $fieldNames[] = $meta->name;
                $this->outputString .= ($i == 0 ? '[' : ', ') . '"' . $meta->name . '"';
            }
        }
        $this->outputString .= <<<EOD
],
//data

EOD;
        while (!$recordset->EOF) {
            $arr = array();
            foreach ($fieldNames as $field) {
                $arr[] = $recordset->Fields($field);
            }
            $this->outputString .= WDG_phparray2jsarray($arr) . ', ';
            $recordset->MoveNext();
        }
        $this->outputString .= <<<EOD
[]
];
top.{$RecordsetName} = new JSRecordset('{$RecordsetName}');
</script>
EOD;
        //restore old rs position
        $recordset->MoveFirst();
    }
function WDG_phparray2jsarray($obj)
{
    //FORCE the frst level to be an array
    $tm = '';
    if (is_array($obj)) {
        if (count($obj) == 0) {
            $tm = '[]';
        } else {
            $tm .= '[';
            foreach ($obj as $v) {
                $tm .= WDG_phparray2jsarray($v) . ',';
            }
            $tm = substr($tm, 0, strlen($tm) - 1);
            $tm .= ']';
        }
    } else {
        if (is_scalar($obj) || is_null($obj)) {
            $tm .= '"' . addcslashes($obj, "\\\"\r\n") . '"';
        } else {
            $tmp = '[]';
        }
    }
    return $tm;
}