// this variables are necessary for the demo only

//encoding parameters
var lang = "he";
var encoding = "utf-8";

//determine IE version
var ie_data = navigator.userAgent.match(/MSIE ([0-9|\.]+)/);
var ie_version = null;
	if (ie_data) {
		ie_version = parseFloat(ie_data[1]);
	}

var can_parse = false;

// this variables are necessary for the demo only

function write2iframe(){

//var page_mode = get_page_mode();
//*

//get html text to convert
var text2set = document.getElementById('html2convert_source').value;
	//if (!page_mode) text2set = '<html><body>'+text2set+'</body></html>';

//write the text to iframe to access it later via dom object
	if (document.all) {
var iframe_doc = html2convert.document;
	} else {
var iframe_doc = document.getElementById('html2convert').contentWindow.document;
	}

	if (document.all && ie_version < 5.5) {
		//ie5.0 could generates onload event earlier then loading is actually finished
		iframe_doc.onload = setTimeout('parse_iframe()', 1);
	}

	iframe_doc.open();
	iframe_doc.write(text2set);
	iframe_doc.close();

}

//convert html to xhtml and write to destination textarea
function parse_iframe(){
	if (!can_parse) return;

//var page_mode = get_page_mode();
	var page_mode = 0;
//determine source dom object
	if (document.all) {
		var iframe_doc = html2convert.document;
	} else {
		var iframe_doc = document.getElementById('html2convert').contentWindow.document;
	}

	if (page_mode) {
		var source_obj = iframe_doc;
	} else {
		if (document.all) {
			var source_obj = iframe_doc.body; //html fragment ie
		} else {
			var source_obj = iframe_doc.documentElement; //html fragment mozilla
		}
	}

	var xhtml_content = get_xhtml(source_obj, lang, encoding);
	globaldata = xhtml_content;

	/*if (document.all) {
		html2convert_result.value = xhtml_content;
	} else {
		document.getElementById('html2convert_result').value = xhtml_content;
	}*/
}

//allow to convert if the whole document is loaded only
function init(){
	can_parse = true;

	if (document.all) {
		var iframe_doc = html2convert.document;
		iframe_doc.designMode = "On";
	} else {
		var iframe_doc = document.getElementById('html2convert').contentWindow.document;

		var iframe_win =  document.getElementById('html2convert').contentWindow;
		iframe_win.document.designMode = "On";
	}

}

function get_page_mode(){
	if (document.all) {
		return page_mode.checked;
	} else {
		return document.getElementById('page_mode').checked;
	}

}

