1/*
2 * HTML Parser By John Resig (ejohn.org)
3 * Original code by Erik Arvidsson, Mozilla Public License
4 * http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
5 * @license    GPL 3 or later (http://www.gnu.org/licenses/gpl.html)
6*/
7
8var HTMLParser;
9var HTMLParserInstalled=true;
10var HTMLParser_Elements = new Array();
11(function(){
12
13	// Regular Expressions for parsing tags and attributes
14	var startTag = /^<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,
15		endTag = /^<\/(\w+)[^>]*>/,
16		attr = /(\w+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;
17
18	// Empty Elements - HTML 4.01
19	var empty = makeMap("br,col,hr,img");
20   // HTMLParser_Elements['empty'] = empty;
21
22	// Block Elements - HTML 4.01
23	var block = makeMap("blockquote,center,del,div,dl,dt,hr,iframe,ins,li,ol,p,pre,table,tbody,td,tfoot,th,thead,tr,ul");
24  //  HTMLParser_Elements['block'] = block;
25
26	// Inline Elements - HTML 4.01
27	var inline = makeMap("a,abbr,acronym,b,big,br,cite,code,del,em,font,h1,h2,h3,h4,h5,h6,i,img,ins,kbd,q,s,samp,small,span,strike,strong,sub,sup,tt,u,var");
28
29	// Elements that you can, intentionally, leave open
30	// (and which close themselves)
31	var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
32
33	// Attributes that have their values filled in disabled="disabled"
34	var fillAttrs = makeMap("checked,disabled,ismap,noresize,nowrap,readonly,selected");
35
36	// Special Elements (can contain anything)
37	var special = makeMap("script,style");
38
39
40	HTMLParser = this.HTMLParser = function( html, handler ) {
41		var index, chars, match, stack = [], last = html;
42
43		stack.last = function(){
44			return this[ this.length - 1 ];
45		};
46
47		while ( html ) {
48			chars = true;
49
50			// Make sure we're not in a script or style element
51			if ( !stack.last() || !special[ stack.last() ] ) {
52
53				// Comment
54				if ( html.indexOf("<!--") == 0 ) {
55					index = html.indexOf("-->");
56
57					if ( index >= 0 ) {
58						if ( handler.comment )
59							handler.comment( html.substring( 4, index ) );
60						html = html.substring( index + 3 );
61						chars = false;
62					}
63
64				// end tag
65				} else if ( html.indexOf("</") == 0 ) {
66					match = html.match( endTag );
67
68					if ( match ) {
69						html = html.substring( match[0].length );
70						match[0].replace( endTag, parseEndTag );
71						chars = false;
72					}
73
74				// start tag
75				} else if ( html.indexOf("<") == 0 ) {
76					match = html.match( startTag );
77
78					if ( match ) {
79						html = html.substring( match[0].length );
80						match[0].replace( startTag, parseStartTag );
81						chars = false;
82					}
83				}
84
85				if ( chars ) {
86					index = html.indexOf("<");
87
88					var text = index < 0 ? html : html.substring( 0, index );
89					html = index < 0 ? "" : html.substring( index );
90
91					if ( handler.chars )
92						handler.chars( text );
93				}
94
95			} else {
96				html = html.replace(new RegExp("(.*)<\/" + stack.last() + "[^>]*>"), function(all, text){
97					text = text.replace(/<!--(.*?)-->/g, "$1")
98						.replace(/<!\[CDATA\[(.*?)]]>/g, "$1");
99
100					if ( handler.chars )
101						handler.chars( text );
102
103					return "";
104				});
105
106				parseEndTag( "", stack.last() );
107			}
108
109			if ( html == last )
110				throw "Parse Error: " + html;
111			last = html;
112		}
113
114		// Clean up any remaining tags
115		parseEndTag();
116
117		function parseStartTag( tag, tagName, rest, unary ) {
118			if ( block[ tagName ] ) {
119				while ( stack.last() && inline[ stack.last() ] ) {
120					parseEndTag( "", stack.last() );
121				}
122			}
123
124			if ( closeSelf[ tagName ] && stack.last() == tagName ) {
125				parseEndTag( "", tagName );
126			}
127
128			unary = empty[ tagName ] || !!unary;
129
130			if ( !unary )
131				stack.push( tagName );
132
133			if ( handler.start ) {
134				var attrs = [];
135
136				rest.replace(attr, function(match, name) {
137					var value = arguments[2] ? arguments[2] :
138						arguments[3] ? arguments[3] :
139						arguments[4] ? arguments[4] :
140						fillAttrs[name] ? name : "";
141
142					attrs.push({
143						name: name,
144						value: value,
145						escaped: value.replace(/(^|[^\\])"/g, '$1\\\"') //"
146					});
147				});
148
149				if ( handler.start )
150					handler.start( tagName, attrs, unary );
151			}
152		}
153
154		function parseEndTag( tag, tagName ) {
155			// If no tag name is provided, clean shop
156			if ( !tagName )
157				var pos = 0;
158
159			// Find the closest opened tag of the same type
160			else
161				for ( var pos = stack.length - 1; pos >= 0; pos-- )
162					if ( stack[ pos ] == tagName )
163						break;
164
165			if ( pos >= 0 ) {
166				// Close all the open elements, up the stack
167				for ( var i = stack.length - 1; i >= pos; i-- )
168					if ( handler.end )
169						handler.end( stack[ i ] );
170
171				// Remove the open elements from the stack
172				stack.length = pos;
173			}
174		}
175	};
176
177
178	function makeMap(str){
179		var obj = {}, items = str.split(",");
180		for ( var i = 0; i < items.length; i++ )
181			obj[ items[i] ] = true;
182		return obj;
183	}
184})();
185
186
187function HTMLParser_test_result(results) {
188
189var test_str = "";
190for ( i=0; i < results.length; i++) {
191   var character = results.charAt(i);
192   if(results.charCodeAt(i) == 10)
193         character ='\\n';
194   if(results.charCodeAt(i) == 32)
195         character ='SP';
196   var entry =  character + ' ';
197
198  test_str += entry;
199  if(results.charCodeAt(i) == 10) {
200       test_str += "\n";
201   }
202}
203
204if(!confirm(test_str)) return false;
205return true;
206
207}
208
209function hide_backup_msg() {
210  document.getElementById("backup_msg").style.display="none";
211  return false;
212}
213
214function show_backup_msg(msg) {
215  document.getElementById("backup_msg").style.display="block";
216  document.getElementById("backup_msg_area").innerHTML = "Backed up to: " + msg;
217
218  return false;
219}
220
221  // legacy function
222  function remove_draft(){
223 }
224
225function dwedit_draft_delete(cname) {
226        var debug = false;
227        var params = "draft_id=" +cname;
228        jQuery.ajax({
229           url: DOKU_BASE + 'lib/plugins/fckg/scripts/prev_delete.php',
230           async: false,
231           data: params,
232           type: 'POST',
233           dataType: 'html',
234           success: function(data){
235               if(debug) {
236                  alert(data);
237               }
238
239    }
240    });
241
242}
243
244
245  function GetE(e) {
246       return  document.getElementById(e);
247  }
248var dokuBase = location.host + DOKU_BASE;
249
250