
	//=============================================================
	//		TextArea Rich 
	//		Version 3.0 Build 04804 - WS Dinamica V.1.0 build: 2
	//=============================================================
	//
	//		Codice ottimizzato da: andrea.bettoni@webandstyle.com
	//
	//=============================================================
	
	//=============================================================
	//	EDITOR LOADING CODE
	//=============================================================
	
	function init() {
		//check the browser
		var useragent = navigator.userAgent;
		var browser_name = navigator.appName;
		var pos = useragent.indexOf('MSIE');
		if (pos > -1) {
		bVer = useragent.substring(pos + 5);
		var pos = bVer.indexOf(';');
		var bVer = bVer.substring(0,pos);
		}
		
		if ((browser_name == "Microsoft Internet Explorer") && (bVer  >= 5.5)) {
			//update the "mode" in the status bar
			document.getElementById("editor_status").innerHTML = "Modalità Modifica Visuale";
			buttons('enable');	//enable all the buttons
			viewMode = 1;		//set mode to WYSIWYG 
			loadContents();		//load the editor contents!
			applyStyle();		//apply the style
		} else {
			switch(noIEdetected) {
				case "message":		document.write(noIEmessage); break;
				case "redirect":	window.location = noIEredirect; break;
			}
		}
	 }
	 
	 function loadContents() {
		if (document.body.readyState == "complete") {
			//the editor has loaded, so load the contents
			iView.document.location.href = editorLoad;
			iView.document.designMode = 'On';
			iView.document.onmouseup = my_onMouseUp;
			iView.document.onkeyup = my_onKeyUp;
			iView.document.onkeydown = getKeyPress;
			iView.document.oncontextmenu = showContextMenu;
			iView.document.onclick = onclickEvents;
			iView.document.ondblclick = doubleClick;
			
			if (b_ackup.length == 1) {
				document.getElementById("desc_redo").disabled = true; //disable the button
				document.getElementById("desc_redo").style.filter = "alpha(Opacity=20)"; //make it look disabled
				document.getElementById("desc_redo").style.cursor = "";
			}
			
			if (undo_pos == 0) {
				document.getElementById("desc_undo").disabled = true; //disable the button
				document.getElementById("desc_undo").style.filter = "alpha(Opacity=20)"; //make it look disabled
				document.getElementById("desc_undo").style.cursor = "";
			}
			
			
			
			
			
		}
 	} //END FUNCTION
	
	function applyStyle() {
		//apply a style sheet if the user has made one in config.js
		if (styleSheet != "") {
			//load the style sheet. This has to be the full path (set in config.js)
			try { iView.document.createStyleSheet(path + styleSheet); }
			catch (myError) { //bug here
			}
		}
	}
	
	 function onclickEvents() {
		//quick function to store all the onclick loading events
		hideMenu();
	}
	
	//=============================================================
	//	SAVE FUNCTION
	//=============================================================
	
	function savedocument() {	
		
		formBorders('off');
		tableBorders('off');
	
		//set the output method in config.js
		switch(saveMethod) {
			case "HTML_1"	:	//all HTML
								if (viewMode == 2) {	document.getElementById(saveField).value = iView.document.documentElement.outerText; }
								else { 					document.getElementById(saveField).value = iView.document.documentElement.outerHTML; }
								break;
								
			case "HTML_2"	:	//only HTML inside Body tags
								if (viewMode == 2) {	document.getElementById(saveField).value = iView.document.body.innerText; }
								else { 					document.getElementById(saveField).value = iView.document.body.innerHTML; }
								break;
								
			case "ALERT"	:	//output the contents to an alert box
								if (viewMode == 2) {  	alert(iView.document.documentElement.outerText); }
								else { 				 	alert(iView.document.body.innerHTML); }
								break;
								
			default			:	alert("ERRORE DURANTE IL SALVATAGGIO DEL DOCUMENTO...");
								return false;
								break;
		}
	}	
	 
	//=============================================================
	//	TEXT FUNCTIONS
	//=============================================================	
	
	function findAndReplace() {
		BACKUP('Find and Replace');
		var arr = showModalDialog( "editor/files/replace.htm", iView.document, "status:no; scroll:no; font-family:Verdana; font-size:12; dialogWidth:37em; dialogHeight:12em;help:no;status:no" );
	}
	
	function about() {
		showModalDialog( "editor/files/about.htm", iView.document, "status:no; scroll:no; font-family:Verdana; font-size:12; dialogWidth:37em; dialogHeight:25em;help:no;status:no" );
	}
	
	function cleanCode() {
		//strip any HTML added by word.
		if ( !confirm ("Procedere con la pulizia del codice HTML?") ) return;
		 
		 BACKUP('HTML Clean');
		 var str = iView.document.body.innerHTML;
		
		 var repl_p1 = /<P[^>]*>/ig;
		 var repl_p2 = '<P>';
		 str = str.replace (repl_p1, repl_p2);
		
		 var repl_h1 = /<H[^>]*>/ig;
		 var repl_h2 = '<\/H>';
		 str = str.replace (repl_h1, '');
		 str = str.replace (repl_h2, '');
		
		 var repl_z1 = /<B[^>]*>/ig;
		 str = str.replace (repl_z1, '<b>');
		
		// var repl_i1 = /<I[^>]*>/ig;
		// str = str.replace (repl_i1, '<i>');
		
		 var repl_d1 = /<DIV[^>]*>/ig;
		 var repl_d2 = '<\/DIV>';
		 str = str.replace (repl_d1, '');
		 str = str.replace (repl_d2, '');
		
		 var repl_s1a = /<SPAN[^>]*>/ig;
		 var repl_s1b = /<SPAN>/ig;
		 var repl_s1c = /<\/SPAN>/ig;
		 str = str.replace (repl_s1a, '');
		 str = str.replace (repl_s1b, '');
		 str = str.replace (repl_s1c, '');
		
		 var repl_xm = /<[\/\w?]+:[^>]*>/ig;
		 str = str.replace (repl_xm, '');
		
		 var repl_sp = /<P>&nbsp;<\/P>/ig;
		 str = str.replace (repl_sp, '');
		
		 var repl_b1 = /<STRONG>/ig;
		 var repl_b2 = /<\/STRONG>/ig;
		 str = str.replace (repl_b1, '');
		 str = str.replace (repl_b2, '');
		
		 var repl_nb = /&nbsp;&nbsp;/ig;
		 str = str.replace (repl_nb, '&nbsp;');
		
		 var r1, r2;
		 var repl_1nf = /<FONT [^>]*>/ig;
		 var repl_2nf = /<\/FONT>/ig;
		 r1 = str.replace (repl_1nf, '');
		 str = r1.replace (repl_2nf, '');
		 
		 var repl_stl = /STYLE=\"[^\"]*\"/ig;
		 str = str.replace (repl_stl, '');
		
		//reapply the borders
		if (table_borders == "on") {
			tableBorders('on');
		}
		if (form_borders == "on") {
			formBorders('on');
		}
		  iView.document.body.innerHTML = str;
		  iView.document.focus();
		 
		 //now if the borders are on, draw them back!
		 if (table_borders == "on") {
		//redraw the borders
			for(i=0;i<iView.document.all.length;i++) {
				if(iView.document.all[i].tagName.toUpperCase() == 'TD') {
				void(iView.document.all[i].style.border='1px dashed #C0C0C0');
				void(0);
				}
			}
	
			for(a=0;a<iView.document.all.length;a++) {
				if(iView.document.all[a].tagName.toUpperCase() == 'TABLE') {
					void(iView.document.all[a].style.border='1px dashed #C0C0C0');
					void(0);
				}
			}
		}
		
		if (form_borders == "on") {
		//redraw the form border
			for(i=0;i<iView.document.all.length;i++) {
				if(iView.document.all[i].tagName.toUpperCase() == 'FORM'){
				void(iView.document.all[i].style.border='1px dashed red');
				void(0); 
				}
			}
		}
	} //end function

	function doFormat(format) {
		if(format != '') {
	  		iView.document.execCommand('formatblock', false, format);
		}
	}
	
	function doChar() {
		//special characters
		 hideMenu();
		 var arr = showModalDialog( "editor/files/specialchars.htm",
								 "",
								 "status:no; scroll:no; font-family:Verdana; font-size:12; dialogWidth:500px; dialogHeight:410px;help:no;status:no" );
		  if (arr != null) {
			  iView.focus();
			  selection = iView.document.selection.createRange();
			  BACKUP('Special Char');
			  selection.pasteHTML(arr);
		  }
	}
	
	function cmdExec(cmd,opt) {
		//only backup if there is text highlighted
		switch(cmd) {
			case "paste":				BACKUP('Paste'); break;
			case "justifyleft":			BACKUP('Justify Left'); break;
			case "justifycenter":		BACKUP('Justify Center'); break;
			case "justifyright":		BACKUP('Justify Right'); break;
			case "insertunorderedlist":	BACKUP('Bullet List'); break;
			case "insertorderedlist":	BACKUP('Numbered List'); break;
			case "outdent":				BACKUP('Outdent Text'); break;
			case "indent":				BACKUP('Indent Text'); break;
			default:					if ((iView.document.selection.type == "Text") || (iView.document.selection.type == "Control")) {
										BACKUP(cmd);
										} break;
		}
	
		button_pressed = 1;
		iView.focus();
		iView.document.execCommand(cmd,"",opt);
		checkState();
	}
	
	function doFont(fName) {
		if(fName != '')
		iView.document.execCommand('fontname', false, fName);
	}
	
	function doStyleSheet(style) {
	   var theSelection = iView.document.selection.createRange();
	   if (iView.document.selection.type == "Control") {
		 el = theSelection(0).parentNode;
	   } else {
		 el = theSelection.parentElement()
	   }
	   BACKUP('Style');
	   el.className = style;
	   iView.focus();
	}
  
	function doSize(fSize) {
		if(fSize != '')
		  BACKUP('Font Size (' + fSize +')');
		  iView.document.execCommand('fontsize', false, fSize);
	}	
	
	
	//=============================================================
	//	CONTROL CHECKS
	//=============================================================		
	
	var error22_fetch = 4;
	var _wysiwygFetch = true;
	
	function isImage() {
		var range;
		if (iView.document.selection.type == "Control") {
			itself = iView.document.selection.createRange();
			if (itself(0).tagName.toUpperCase() == "IMG") {
				//the selected control is an IMAGE...so allow it
				return true;
			}
		} else {
			return false;
		}
	}

	function isForm() {
		if (iView.document.selection.type == "Control") { 
			return true;
		} else {
			iView.focus();
			var cursor = iView.document.selection.createRange();
			var element = cursor.parentElement();
			if (element.nodeName.toLowerCase() == "form") {
				//a form has been found
				return true;
			} else {
				while (element.nodeName.toLowerCase() != "form") {
					//	if there's a parentNode available, work upon that
					if (element.parentNode) {
						element = element.parentNode;
					} 
					
					if (element.nodeName.toLowerCase() == "form") {
						//a form has been found
						return true;
						break;
					}
					
					if (element.nodeName.toLowerCase() == "html") {
						break;
					}
				}
			}
		}  
	}

	function isTable() {
		if (iView.document.selection.type == "Control") { 
			//alert("Please place the cursor inside the table before selecting this option");
			//return true;
		} else {
			var cursor = iView.document.selection.createRange();
			var table = cursor.parentElement();
			if (table.nodeName.toLowerCase() == "td") {
				//a TD tag has been found, so return true
				return true;
			} else {
				while (table.nodeName.toLowerCase() != "td") {
					//	if there's a parentNode available, work upon that
					if (table.parentNode) {
						table = table.parentNode;
					} 
					
					if (table.nodeName.toLowerCase() == "td") {
						//a TD tag has been found, so return true
						return true;
						break;
					}
					
					if (table.nodeName.toLowerCase() == "html") {
						break;
					}
				}
			}		
		}
	}
	
	
	
	//=============================================================
	//	BUTTON FUNCTIONS
	//=============================================================			

	function buttons(what) {
		//disable or enable button usage (used when switching from WYSIWYG . CODE modes
		if (what == "disable") {
			buttons_disabled = true;	//turn the onclick function off
			//go through the disabled elements array and make the images look disabled
			try {
				for (x=0;x<disableElements.length;x++) {
					document.getElementById(disableElements[x]).disabled = true; //disable the button
					document.getElementById(disableElements[x]).style.filter = "alpha(Opacity=20)"; //make it look disabled
					document.getElementById(disableElements[x]).style.cursor = "";
				}
			} catch(myError) {
					alert("\nErrore:\n\nTipo errore: " + errDesc);
			}
		}
		else
		{
			buttons_disabled = false;	//turn the onclick function on
			//go through the disabled elements array and make the images look enabled
			try {
				for (x=0;x<disableElements.length;x++) {
				document.getElementById(disableElements[x]).disabled = false; //enable the button
				document.getElementById(disableElements[x]).style.filter = "alpha(Opacity=100)"; //make it look enabled again
				document.getElementById(disableElements[x]).style.cursor = "";
				}
				
			} catch(myError) {
					alert("\nErrore:\n\nTipo errore: " + errDesc);
			}
		}
	}
	
	//=============================================================
	//	MISC FUNCTIONS
	//=============================================================			

	function insertDate(what) {
		var d = new Date();
		
		switch(what) {
			case "date":		day = d.getDate();
								month = d.getMonth() + 1;
								year = d.getFullYear();
								
								switch(dateFormat)
								{
									case "DD MM YYYY"	: 	tmp = day + dateDivider + month + dateDivider + year;
															break;
															
									case "MM DD YYYY"	: 	tmp = month + dateDivider + day + dateDivider + year;
															break;
															
									default				:	tmp = day + dateDivider + month + dateDivider + year;
															break;
								}
								//now paste the date to the document
								BACKUP('Insert Date');
								insertHTML(tmp);
								break;
			
			case "time":		
								hours = d.getHours()
								minutes = d.getMinutes()
								if (minutes < 10) { minutes = "0" + minutes; }
								seconds = d.getSeconds()
								switch (timeFormat){
									case "HH MM"	:	tmp = hours + timeSeperator + minutes;
														break;
									case "HH MM SS" :	tmp = hours + timeSeperator + minutes + timeSeperator + seconds;
														break;
									default			:	tmp = hours + timeSeperator + hours;
														break;
								}
								
								if (showAM_PM) {
									if (hours >= 12){
										tmp += " PM";
									} else {
										tmp += " AM";
									}
								}
								BACKUP('Insert Time');
								insertHTML(tmp);
								
								break;	
		}
	}

	function doScrolling() {
		//open the dialogue box for the scrolling text add in
		hideMenu();
		args = showModalDialog( "editor/files/scroller.htm","","font-family:Verdana; font-size:12; dialogWidth:600px; dialogHeight:350px;help:no;status:no");
		
		if (args != null) {
			//add the HTML
			tmp  = "<marquee ";
			switch (args["style"]) {
				case "right"		:	tmp += "direction='right' "; break;
				case "left2right"	:	tmp += "direction='right' behavior='alternate' "; break;
			}
			
			tmp += ( (args["scrollamount"] == "") ? "" : "scrollamount='" + args["scrollamount"] + "' ");
			tmp += ( (args["width"] == "") ? "" : "width='" + args["width"] + "'");
			tmp += ">" + args["text"] + "</marquee>";
			BACKUP('Scrolling Marquee');
			insertHTML(tmp);
		}
	}

	function doRule() {
		//get the properties and pass them to the dialogue window
		var selection = iView.document.selection.createRange();
		var isRule 	  = null;
		var args 	  = new Array();
		
		if (iView.document.selection.type == 'Control') {
			var itself = iView.document.selection.createRange();
			if (itself(0).tagName.toUpperCase() == "HR") {
			  rule = itself(0);
			  isRule = true;
			}
		} else {
			rule = selection.parentElement();
		}
		
		var strHTML = ((rule.outerHTML != null) ? (rule.outerHTML) : (""));
	
		if (strHTML != "") {
			args["height"] 		= ((rule.size=="") ? "" : (rule.size));
			args["width"]  		= ((rule.style.width=="")  ? "100%" : (rule.style.width));
			args["align"] 		= ((rule.align=="")       ? "" : (rule.align));
			args["name"]    	= ((rule.name==null)          ? "" : (rule.name));
			args["color"]   	= ((rule.color=="")		   ? "" : (rule.color));
	
			//check if shading is on or off
			var re_1 = /noShade/i;
			args["shading"]		= ((rule.outerHTML.search(re_1) >=0) ? false : (true));
			
			hideMenu();
			arg = showModalDialog( "editor/files/hr.htm",args,"font-family:Verdana; font-size:12; dialogWidth:400px; dialogHeight:330px;help:no;status:no");
		
			if (arg != null) {
			  //build the new HR string
			  newString  = "<HR ";
			  newString += "style='width:" + arg['width'] + "' ";
			  newString += "align='" + arg["align"] + "' name='" + arg["name"] + "' ";
			  newString += "color='" + arg["color"] + "' size='" + arg["size"] + "' ";
			  newString += ( (arg["shading"] == "shading") ? "" : ("noShade ") );
			  newString += ">";
			  BACKUP('Horizontal Rule');
			  rule.outerHTML = newString;
			}
		}
	}
	
	function doInsert() {
		var theMenu = "";
		//go through the options one by one, and see if its on or off.
		if (allowInsScroll) {
			theMenu += menu_open1 + " onMouseDown=\"" + custom_inserts[0][1] + "\"" + menu_open2 + custom_inserts[0][0] + menu_close;
		}
		if (allowInsDate) {
			theMenu += menu_open1 + " onMouseDown=\"" + custom_inserts[1][1] + "\"" + menu_open2 + custom_inserts[1][0] + menu_close;
		}
		if (allowInsTime) {
			theMenu += menu_open1 + " onMouseDown=\"" + custom_inserts[2][1] + "\"" + menu_open2 + custom_inserts[2][0] + menu_close;
		}
		if (allowSpecialChar) {
			theMenu += menu_open1 + " onMouseDown=\"" + custom_inserts[3][1] + "\"" + menu_open2 + custom_inserts[3][0] + menu_close;
		}
		
		document.all['tr_dropMenu'].innerHTML = theMenu;
		hideMenu();
		var e = event;
		var a = e.srcElement;
		var box = a.getBoundingClientRect();
		var canvas = document.compatMode == null || document.compatMode == "BackCompat" ? document.body : document.documentElement;
		tr_dropMenu.style.top = box.bottom + canvas.scrollTop + "px";
		tr_dropMenu.style.left = box.left + canvas.scrollLeft + "px";
		
		e.cancelBubble = true;
		var ifr = "<iframe id=\"frameId\" src=\"\" frameborder=\"0\" scrolling=\"no\" style=\"position:absolute;top:0x;left:0px;z-index:100;display:none\" ></iframe>";
		document.all['tr_dropMenu'].insertAdjacentHTML('beforeBegin', ifr);
		document.all('frameId').style.top = box.bottom + canvas.scrollTop + "px";
		document.all('frameId').style.left = box.left + canvas.scrollLeft + "px";
		document.all('frameId').style.width = '133'; //allow for the border
		document.all('frameId').style.display = 'block';
		document.all('frameId').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		document.all['tr_dropMenu'].style.display = "block";  
	}


	//================================================================
	//	IMAGE FUNCTIONS
	//================================================================

	function doImage() {
		//get the properties and pass them to the dialogue window
		var selection = iView.document.selection.createRange();
		var image     = null;
		var isImage   = false;
		var args 	  = new Array();
		
		if (iView.document.selection.type == 'Control') {
			var itself = iView.document.selection.createRange();
			if (itself(0).tagName.toUpperCase() == "IMG") {
			  image = itself(0);
			  isImage = true;
			}
		} else {
			image = selection.parentElement();
		}
		
		var strHTML = ((image.outerHTML != null) ? (image.outerHTML) : (""));
	
		if (strHTML != "" && isImage && strHTML!="<IMG>") {
			var r, re;                   //Declare variables.
			re = /src="/i;               //Create regular expression pattern.
			r = strHTML.search(re);
			if (r > 0) {
			  strHTML = strHTML.substring(r+5);
			  re = /"/i;               //Create regular expression pattern.
			  r = strHTML.search(re);
			  strHTML = strHTML.substring(0,r);
			}
		} else {
			strHTML = "";
		}
		if (strHTML != "") {
			args["height"] = ((image.style.height=="") ? "" : (image.style.height));
			args["width"]  = ((image.style.width=="")  ? "" : (image.style.width));
			args["border"] = ((image.border=="")       ? "" : (image.border));
			args["alt"]    = ((image.alt=="")          ? "" : (image.alt));
			args["path"]   =  strHTML;
			args["name"]   = ((image.name=="")		   ? "" : (image.name));
			hideMenu();
			
			arg = showModalDialog( "editor/files/image_properties.htm",args,"font-family:Verdana; font-size:12; dialogWidth:600px; dialogHeight:330px;help:no;status:no");
		
			if (arg != null) {
			  BACKUP('Image Properties');
			  image.style.height = arg["height"];
			  image.style.width  = arg["width"];
			  image.border       = arg["border"];
			  image.alt          = arg["alt"];
			  image.src	         = arg["path"];
			  image.name		 = arg["name"];
			}
			
		} else {
			args["href"] = strHTML;
			args["Action"] = "";
			hideMenu();
			arg = showModalDialog( "editor/files/insert_image.htm",args,"font-family:Verdana; font-size:12; dialogWidth:600px; dialogHeight:330px;help:no;status:no");
			if (arg != null && arg["Action"] == "Insert") {
				BACKUP('Insert Image');
				var theSelection = iView.document.selection.createRange()
				iView.focus();
				theSelection.pasteHTML(arg["url"]);
			}
	  }
	
	
	}
  
	//======================================================================================
	//	FORM FUNCTIONS
	//======================================================================================
 
	function doForm() {
		var theMenu = "";
		
		//the insert table tag is always awailable & toggle form border
		theMenu += menu_open1 + " onMouseDown=\"" + form_menu[0][1] + "\"" + menu_open2 + form_menu[0][0] + menu_close;
		theMenu += menu_open1 + " onMouseDown=\"" + form_menu[1][1] + "\"" + menu_open2 + form_menu[1][0] + menu_close;
	
		for (x=2;x<form_menu.length;x++) {
			if (form_menu[x][1] == ""){
				theMenu += menu_seperator;
			} else {
				if (!isForm()) {
					theMenu += menu_open_dis + form_menu[x][0] + menu_close;
				} else {
					theMenu += menu_open1 + " onMouseDown=\"" + form_menu[x][1] + "\"" + menu_open2 + form_menu[x][0] + menu_close;
				}
			}
		}
		
		document.all['tr_dropMenu'].innerHTML = theMenu;
		hideMenu();
		var e = event;
		var a = e.srcElement;
		var box = a.getBoundingClientRect();
		var canvas = document.compatMode == null || document.compatMode == "BackCompat" ? document.body : document.documentElement;
		tr_dropMenu.style.top = box.bottom + canvas.scrollTop + "px";
		tr_dropMenu.style.left = box.left + canvas.scrollLeft + "px";
		
		e.cancelBubble = true;
		
		var ifr = "<iframe id=\"frameId\" src=\"\" frameborder=\"0\" scrolling=\"no\" style=\"position:absolute;top:0x;left:0px;z-index:100;display:none\" ></iframe>";
		document.all['tr_dropMenu'].insertAdjacentHTML('beforeBegin', ifr);
		document.all('frameId').style.top = box.bottom + canvas.scrollTop + "px";
		document.all('frameId').style.left = box.left + canvas.scrollLeft + "px";
		document.all('frameId').style.width = '133'; //allow for the border
		document.all('frameId').style.display = 'block';
		document.all('frameId').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		document.all['tr_dropMenu'].style.display = "block";  
	}
  
	function doForms() {
		var selection = iView.document.selection;
		var range = iView.document.selection.createRange(); 
		
		switch (selection.type){
		case 'None':
		case 'Text':
		  var cur_sel = selection.createRange();
		  cur_sel.collapse();
		  var par_el = cur_sel.parentElement();
		  break;
		case 'Control':
		  var cur_sel = selection.createRange();
		  var par_el = cur_sel.commonParentElement();
		  break;
		}
		
		var args = Array();
		if (par_el!=null && par_el.tagName.toUpperCase()=="FORM") {
		args["Action"] = par_el.action;
		args["Method"] = par_el.method;
		args["Name"]   = par_el.name;
		} else {
		args["Action"] = ""
		args["Method"] = ""
		args["Name"]   = ""
		}
	
		iView.focus();
		hideMenu();
		
		var arg = null;
		arg = showModalDialog( "editor/files/forms.htm",args,"font-family:Verdana; font-size:12; dialogWidth:400px; dialogHeight:270px;help:no;status:no");
	
		if (arg != null) {
			BACKUP('Insert Form');
			strAction = ((arg["Action"] == "") ? ("")    : (arg["Action"]));
			strMethod = ((arg["Method"] == "") ? ("POST") : (arg["Method"]));
			strName   = ((arg["Name"]   == "") ? ("")    : (arg["Name"]));
			if (arg["Oper"]=="Insert" && par_el.tagName.toUpperCase()=="FORM") {
				par_el.outerHTML = "<form name='" +strName+ "' method='" +strMethod+ "' action='" +strAction+ "'>" + par_el.innerHTML + "</form>"
			} else {
				range.pasteHTML("<form name='" +strName+ "' method='" +strMethod+ "' action='" +strAction+ "'>&nbsp;&nbsp;</form>");
			}
			if (form_borders == "on") {
				formBorders('on');
			}
		}
	}

	
	function formTextfield() {
		var args = new Array();
		args["Type"]  = "";
		args["Value"] = "";
		args["Size"]  = "";
		args["Len"]   = "";
		args["Name"]  = "";
		var range = iView.document.selection.createRange(); 
		hideMenu();
		arg = showModalDialog( "editor/files/form_textfield.htm", args, "font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:375px; scroll:no;help:no;status:no");
		  if (arg != null) {
			BACKUP('Insert Textfield');
			strType  = ((arg["Type"]  == "") ? ("") : (arg["Type"]));
			strName  = ((arg["Name"]  == "") ? ("") : (arg["Name"]));
			strValue = ((arg["Value"] == "") ? ("") : (arg["Value"]));
			strSize  = ((arg["Size"]  == "") ? ("") : (arg["Size"]));
			strLen   = ((arg["Len"]   == "") ? ("") : (arg["Len"]));
			range.pasteHTML("<INPUT type="+strType+" name='" +strName+ "' value='" +strValue+ "' size='" +strSize+ "' maxLength='" +strLen+ "'>");
		  }
	}

  	function controlProperties() {
	  //get the control properties and act upon them
	  var selection = iView.document.selection;
      var range = iView.document.selection.createRange(); 
	
	  var arg = null;
	  var args = Array();
	  args["Type"]  = range(0).type;
	  args["Name"]  = range(0).name;
	  
	  hideMenu();
	  
	  switch (range(0).type) {
		case "text"     :
		case "password" :
		  args["Type"]	= range(0).type;
		  args["Value"] = range(0).value;
		  args["Size"]  = range(0).size;
		  args["Len"]   = range(0).maxLength;
		  arg = showModalDialog( "editor/files/form_textfield.htm", args, "font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:375px; scroll:no;help:no;status:no");
		  if (arg != null) {
			BACKUP('Form (Textfield)');
			strType  = ((arg["Type"]  == "") ? ("") : (arg["Type"]));
			strName  = ((arg["Name"]  == "") ? ("") : (arg["Name"]));
			strValue = ((arg["Value"] == "") ? ("") : (arg["Value"]));
			strSize  = ((arg["Size"]  == "") ? ("") : (arg["Size"]));
			strLen   = ((arg["Len"]   == "") ? ("") : (arg["Len"]));
			range(0).outerHTML = "<INPUT type="+strType+" name='" +strName+ "' value='" +strValue+ "' size='" +strSize+ "' maxLength='" +strLen+ "'>";
		  }
		  break;
		// ========================================================
		case "file" :
		  args["Size"]  = range(0).size;
		  arg = showModalDialog( "editor/files/form_file.htm", args, "font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:300px; scroll:no");
		  if (arg != null) {
			BACKUP('Form (File)');
			strType  = ((arg["Type"]  == "") ? ("") : (arg["Type"]));
			strName  = ((arg["Name"]  == "") ? ("") : (arg["Name"]));
			strSize  = ((arg["Size"]  == "") ? ("") : (arg["Size"]));
			range(0).outerHTML = "<INPUT type="+strType+" name='" +strName+ "' size='" +strSize+ "'>";
		  }
		  break;
		// ========================================================
		case "textarea" :
		  args["Value"] = range(0).value;
		  args["Rows"]  = range(0).rows;
		  args["Cols"]  = range(0).cols;
		  args["Wrap"]	= range(0).wrap;
		  arg = showModalDialog( "editor/files/form_textarea.htm", args, "font-family:Verdana; font-size:12; dialogWidth:36em; dialogHeight:440px; scroll:no;help:no;status:no");
		  if (arg != null) {
			BACKUP('Form (TextArea)');
			strName  = ((arg["Name"]  == "") ? ("") : (arg["Name"]));
			strValue = ((arg["Value"] == "") ? ("") : (arg["Value"]));
			strRows  = ((arg["Rows"]  == "") ? ("") : (arg["Rows"]));
			strCols  = ((arg["Cols"]  == "") ? ("") : (arg["Cols"]));
			strWrap  = ((arg["Wrap"]  == "") ? ("") : (arg["Wrap"]));
			range(0).outerHTML = "<TEXTAREA name='" +strName+ "' rows='" +strRows+ "' cols='" +strCols+ "' wrap='" + strWrap + "'>" + strValue + "</TEXTAREA>";
		  }
		  break;
		// ========================================================
		case "checkbox"     :
		case "radio" :
		  args["Checked"] = range(0).checked;
		  args["Type"]	  = range(0).type;
		  args["Name"]    = range(0).name;
		  args["Value"]	  = range(0).value;
		  arg = showModalDialog( "editor/files/form_check.htm", args, "font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:330px; scroll:no;help:no;status:no");
		  if (arg != null) {
			BACKUP('Form (radio/check)');
			strType    = ((arg["Type"]    == "") ? ("") : (arg["Type"]));
			strName    = ((arg["Name"]    == "") ? ("") : (arg["Name"]));
			strChecked = ((arg["Checked"] == "") ? ("off") : (arg["Checked"]));
			strValue   = ((arg["Value"]   == "") ? ("") : (arg["Value"]));
			if (strChecked==true)
			  range(0).outerHTML = "<INPUT type="+strType+" name='" +strName+ "' value='" + strValue + "' checked=" +strChecked+ ">";
			else
			  range(0).outerHTML = "<INPUT type="+strType+" name='" +strName+ "' value='" + strValue + "' >";
		  }
		  break;
		// ========================================================
		case "select-one" :
		  args["Type"]    = "select";
		  args["Size"]    = range(0).size;
		  args["Width"]   = range(0).style.width;
	
		  strOptions      = "";
		  var len = range(0).options.length;
		  for (var i=0; i<len; i++) {
			strOptions = strOptions + range(0).options[i].text + String.fromCharCode(13)+String.fromCharCode(10);
		  }
		  args["Options"] = strOptions;
	
		  arg = showModalDialog( "editor/files/form_select.htm", args, "font-family:Verdana; font-size:12; dialogWidth:33em; dialogHeight:440px; scroll:no;help:no;status:no");
		  if (arg != null) {
			BACKUP('Form (Select List)');
			strType  = ((arg["Type"]    == "") ? ("") : (arg["Type"]));
			strName  = ((arg["Name"]    == "") ? ("") : (arg["Name"]));
			strSize  = ((arg["Size"]    == "") ? ("") : (arg["Size"]));
			strWidth = ((arg["Width"]   == "") ? ("") : (arg["Width"]));
			strValue = ((arg["Options"] == "") ? ("") : (arg["Options"]));
			
			strResult = "<SELECT name='" +strName+ "' size='" +strSize+ "' style='WIDTH:" +strWidth+ "'>";
			if (strValue != "") {
			  var strArr = strValue.split(String.fromCharCode(13)+String.fromCharCode(10));
			  for (var i=0; i<strArr.length; i++) {
				strResult = strResult + "<OPTION>" + strArr[i] + "</OPTION>";
			  }
			}
			strResult = strResult + "</SELECT>";
			range(0).outerHTML = strResult;
		  }
		  break;
		// ========================================================
		case "button" :
		case "reset" :
		case "submit" :
		  args["Value"] = range(0).value;
		  args["Size"]  = range(0).style.width;
		  arg = showModalDialog( "editor/files/form_button.htm", args, "font-family:Verdana; font-size:12; dialogWidth:30em; dialogHeight:350px; scroll:no;help:no;status:no");
		  if (arg != null) {
			BACKUP('Form (Buttons)');
			strType  = ((arg["Type"]  == "") ? ("") : (arg["Type"]));
			strName  = ((arg["Name"]  == "") ? ("") : (arg["Name"]));
			strValue = ((arg["Value"] == "") ? ("") : (arg["Value"]));
			strSize  = ((arg["Size"]  == "") ? ("") : (arg["Size"]));
			range(0).outerHTML = "<INPUT type="+strType+" name='" +strName+ "' value='" +strValue+ "' style='width:" +strSize+ "'>";
		  }
		  break;
	  }
	  
  	}

	
	//========================================================================================
	//	COLOUR MENUS
	//========================================================================================
	
	function doForeCol() {
   	   	arguments["Color"] = new String(iView.document.queryCommandValue("forecolor"));
		arguments["DefaultLanguage"] = "en";
		arguments["LanguageDetection"] = true;
		color = showModalDialog( "editor/files/colourpicker/IE5.5+/ColorPicker.htm",arguments,"font-family:Verdana; font-size:12; dialogWidth:488px; dialogHeight:323px;help:no;status:no");
	  	if (color != null) {
		   BACKUP('Font Forecolour');
		   iView.document.execCommand('forecolor', false, "#" + color);
		   document.all['color_0'].style.background = "#" + color;
	   	}
	}
 
	function doBackCol(val) {
    	arguments["Color"] = new String(iView.document.queryCommandValue("backcolor"));
		arguments["DefaultLanguage"] = "en";
		arguments["LanguageDetection"] = true;
		color = showModalDialog( "editor/files/colourpicker/IE5.5+/ColorPicker.htm",arguments,"font-family:Verdana; font-size:12; dialogWidth:488px; dialogHeight:323px;help:no;status:no");
		if (color != null) {
		   BACKUP('Font Backcolour');
		   iView.document.execCommand('backcolor', false, "#" + color);
		   document.all['color_1'].style.background = "#" + color;
		}
	}

	function doColor(whichOne) {
		//whichOne stores if its the font forecolor or backcolor.
		var theMenu = "<div>";
		var i=0;
		var style = "";
		
		//create the color menu which appears when the user clicks the color button
		theMenu = "<table cellpadding='0' cellspacing='0' border='0'>";
		theMenu += "<tr><td>";
		
		for (x=0;x<menu_colors.length;x++) {
			if ((x==0) && (i==0)) { theMenu += "<table cellpadding='1' cellspacing='2' border='0' width='100%'>"; i=1;}//if the start, draw the table!
			if (x==0) { theMenu += "<tr>" }
			
			theMenu += '<td bgcolor="#000000" unselectable="on"><a style="outline: 1px solid #000000; ';
			theMenu += 'color: ' + menu_colors[x] + '; background: ' + menu_colors[x] + ';font-size: 10px;" ';
			theMenu += 'title="' + menu_colors[x] + '" ';
			theMenu += ' onMouseDown="BACKUP(\'Font (' + whichOne + ')\');iView.document.execCommand(\'' + whichOne + '\',false,\'' + menu_colors[x] + '\'); " ';
			theMenu += ' onMouseOver="this.style.cursor=\'hand\';document.all[\'selected_color\'].style.background=\'' + menu_colors[x] + '\';document.all[\'hexVal\'].innerHTML=\'&nbsp;' + menu_colors[x] + '\'" ';
			theMenu += ' onMouseOut="document.all[\'selected_color\'].style.background=\'\'";';
			theMenu += ' unselectable="on">&nbsp;&nbsp;&nbsp;</a></td>';
	
			if (i == colorsWide) {
				theMenu += "</tr>";
				i = 0;
			}
			
			if (x+1 == menu_colors.length) {
				theMenu += "</table>";
			}
			i++;
			
		}
		
		theMenu += "</td></tr>";
		
		//put a spacer
		theMenu += "<tr><td height='5'></td></tr>";
		theMenu += "<tr><td height='2' bgcolor='#BBBBBB'></td></tr>";
		theMenu += "<tr><td height='5'></td></tr>";
		
		if (whichOne == "forecolor") { func = "doForeCol()"; }
		if (whichOne == "backcolor") { func = "doBackCol()"; }
		
		//now draw the color selector etc....
		theMenu += "<TR><td>";
		
			theMenu += "<table border='0' cellpadding='0' cellspacing='0' width='100%'>";
			theMenu += "<TR>";
			theMenu += "<TD width='25'>";
				theMenu += "<table cellspacing='0' cellpadding='0' border='0' width='100%' style='border:1px solid black'>";
				theMenu += "<tr><td height='12' id='selected_color'></td></tr>"; //color indicator
				theMenu += "</table>";
			theMenu += "</td>";
			theMenu += "<TD id='hexVal'>&nbsp;</td>";
			theMenu += "<TD width='20'><img src='editor/images/buttons/color_none.gif' unselectable='on' alt='Cancel (No Colour)' onMouseover=\"this.style.cursor='hand'; document.all['hexVal'].innerHTML='&nbsp;Cancel'\" onmousedown='hideMenu()'></td>";
			theMenu += "<TD width='20'><img src='editor/images/buttons/color_more.gif' unselectable='on' alt='More Colours' onMouseover=\"this.style.cursor='hand'; document.all['hexVal'].innerHTML='&nbsp;Picker'\" ' onmousedown='" + func + "'></td>";
			theMenu += "</tr>";
			theMenu += "</table>";
		
		
		theMenu += "</td></tr>";
		theMenu += "<tr><td height='5'></td></tr>";
		theMenu += "</table>";
		
		theMenu += "</div>";
		
			
		document.all['tr_drop_color_menu'].innerHTML = theMenu;
		hideMenu();
		var e = event;
		var a = e.srcElement;
		var box = a.getBoundingClientRect();
		var canvas = document.compatMode == null || document.compatMode == "BackCompat" ? document.body : document.documentElement;
		tr_drop_color_menu.style.top = box.bottom + canvas.scrollTop + "px";
		tr_drop_color_menu.style.left = box.left + canvas.scrollLeft + "px";
		
		e.cancelBubble = true;
		var ifr = "<iframe id=\"frameId\" src=\"\" frameborder=\"0\" scrolling=\"no\" style=\"position:absolute;top:0x;left:0px;z-index:100;display:none\" ></iframe>";
		document.all['tr_drop_color_menu'].insertAdjacentHTML('beforeBegin', ifr);
		document.all('frameId').style.top = box.bottom + canvas.scrollTop + "px";
		document.all('frameId').style.left = box.left + canvas.scrollLeft + "px";
		document.all('frameId').style.width = '133'; //allow for the border
		document.all('frameId').style.display = 'block';
		document.all('frameId').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		document.all['tr_drop_color_menu'].style.display = "block";
	
	}

	//=============================================================================
	//`	TABLE FUNCTIONS
	//=============================================================================

	function doTable() {
  	  	var theMenu = "";
		//the insert table tag is always available & the toggle borders
		theMenu += menu_open1 + " onMouseDown=\"" + table_menu[0][1] + "\"" + menu_open2 + table_menu[0][0] + menu_close;
		theMenu += menu_open1 + " onMouseDown=\"" + table_menu[1][1] + "\"" + menu_open2 + table_menu[1][0] + menu_close;
		
		for (x=2;x<table_menu.length;x++) {
			if (table_menu[x][1] == ""){
				theMenu += menu_seperator;
			} else {
				if (!isTable()) {
					theMenu += menu_open_dis + table_menu[x][0] + menu_close;
				} else {
					theMenu += menu_open1 + " onMouseDown=\"" + table_menu[x][1] + "\"" + menu_open2 + table_menu[x][0] + menu_close;
				}
			}
		}
		
		document.all['tr_dropMenu'].innerHTML = theMenu;
		hideMenu();
		var e = event;
		var a = e.srcElement;
		var box = a.getBoundingClientRect();
		var canvas = document.compatMode == null || document.compatMode == "BackCompat" ? document.body : document.documentElement;
		tr_dropMenu.style.top = box.bottom + canvas.scrollTop + "px";
		tr_dropMenu.style.left = box.left + canvas.scrollLeft + "px";
		
		e.cancelBubble = true;
		var ifr = "<iframe id=\"frameId\" src=\"\" frameborder=\"0\" scrolling=\"no\" style=\"position:absolute;top:0x;left:0px;z-index:100;display:none\" ></iframe>";
		document.all['tr_dropMenu'].insertAdjacentHTML('beforeBegin', ifr);
		document.all('frameId').style.top = box.bottom + canvas.scrollTop + "px";
		document.all('frameId').style.left = box.left + canvas.scrollLeft + "px";
		document.all('frameId').style.width = '133'; //allow for the border
		document.all('frameId').style.display = 'block';
		document.all('frameId').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		document.all['tr_dropMenu'].style.display = "block";

 	}

	function insertTable() {
	
		var args = new Array();
		args["cols"]    = "";
		args["rows"]	= "";
		args["width"]	= "";
		args["border"]	= "";
		args["borderColor"] = "";
		args["bgColor"]	= "";
		args["cellPadding"] = "";
		args["cellSpacing"] = "";
		args["background"] = "";
		
		var sel = iView.document.selection;
		var tab = sel.createRange();
		
		hideMenu();
		arg = showModalDialog( "editor/files/insert_table.htm","","font-family:Verdana; font-size:12; dialogWidth:600px; dialogHeight:320px;help:no;status:no");
		
		if (arg != null) {
			BACKUP('Insert Table');
			var theCode;
			if (table_borders == "on") { 
				style = ' style="BORDER-RIGHT:1px dotted #C0C0C0; BORDER-TOP:1px dotted #C0C0C0; BORDER-LEFT:1px dotted #C0C0C0; BORDER-BOTTOM:1px dotted #C0C0C0;"'
			} else {
			  style = "";
			}
			
			theCode = "<table " + style;
			theCode += ( (arg["width"] == "") ? "" : " width='" + arg["width"] + "'");
			theCode += ( (arg["border"] == "") ? "" : " border='" + arg["border"] + "'");
			theCode += ( (arg["borderColor"] == "please select") ? "" : " bordercolor='" + arg["borderColor"] + "'");
			theCode += ( (arg["bgColor"] == "") ? "" : " bgColor='" + arg["bgColor"] + "'");
			theCode += ( (arg["cellPadding"] == "") ? "" : " cellpadding='" + arg["cellPadding"] + "'");
			theCode += ( (arg["cellSpacing"] == "") ? "" : " cellspacing='" + arg["cellSpacing"] + "'");
			theCode += ( (arg["background"] == "") ? "" : " background='" + arg["background"] + "'");
			theCode += ">";
			
			//work out the width of the cell...
			cellWidth = (arg["width"].replace("%","") / arg["cols"]);
			if (arg["width"].indexOf("%")!=-1) { 
				percent = "%"; 
			} else {
				percent = "";
			}
			
			for (a=0; a<arg["rows"]; a++) {
				theCode += "<tr>";
				for (b=0; b<arg["cols"]; b++){
					theCode += "<td " + style + " width='" + cellWidth + "" + percent + "'>&nbsp</td>";
				}
				theCode += "</tr>";
			}
			theCode += "</table>";
		
			iView.focus();
			selection = iView.document.selection.createRange();
			selection.pasteHTML(theCode);
		}
	}
  
	function modifyTable() {
		var args = new Array();
		args["width"]  		= ""
		args["border"]  	= ""
		args["borderColor"] = ""
		args["align"]		= ""
		args["bgColor"]		= ""
		args["padding"]		= ""
		args["spacing"]		= ""
		args["background"]	= ""
		
		var cursor = iView.document.selection.createRange();
		var table = cursor.parentElement(); 
		
		while (table.nodeName && table.nodeName.toLowerCase() != "table") {
			if (table.parentNode) {
				table = table.parentNode;
			} else {
				break;
			}
		}
		//load the values to the args
		if (table.nodeName.toLowerCase() == "table") {
			args["width"] 	= 	( ((table.width=="") || (table.width==null)) 	? 	"100%" 	: 	(table.width));
			args["border"] 	= 	( ((table.border=="") || (table.border==null)) 	? 	"" 		: 	(table.border));
			args["padding"] = 	( ((table.cellPadding=="") || (table.cellPadding==null)) 	? 	"0" 	: 	(table.cellPadding));
			args["spacing"] = 	( ((table.cellSpacing=="") || (table.cellSpacing==null)) 	? 	"0" 	: 	(table.cellSpacing));
			args["bgColor"] = 	( ((table.bgColor=="") || (table.bgColor==null))? 	"" 		: 	(table.bgColor));
			args["borderColor"] = 	( ((table.borderColor=="") || (table.borderColor==null)) 	? 	"" 		: 	(table.borderColor));
			args["align"]   = 	( ((table.align=="") || (table.align==null))    ? 	""      : 	(table.align));
			args["background"]   = 	( ((table.background=="") || (table.background==null))    ? 	""      : 	(table.background));
			hideMenu();
			arg = showModalDialog( "editor/files/table_properties.htm",args,"font-family:Verdana; font-size:12; dialogWidth:600px; dialogHeight:300px;help:no;status:no");
			
			if (arg != null) {
				//update the table properties
				BACKUP('Update Table');
				table.width 		=	arg["width"];
				table.border		=	arg["border"];
				table.borderColor 	= 	arg["borderColor"];
				table.align			=	arg["align"];
				table.bgColor		=	arg["bgColor"];
				table.cellPadding	=	arg["padding"];
				table.cellSpacing	=	arg["spacing"];
				table.background	=	arg["background"];
			}
		}	
	}
	
	function insertRow(where) {
		if (isTable()) {
		
			var cursor = iView.document.selection.createRange();
			var table = cursor.parentElement();
			
			BACKUP('Insert Row ('+where+')');
			
			if (table.nodeName.toLowerCase() == "td") {
				
				  //found a TD, so do the stuff
				  var idx = 0;
				  if (where == "above") { var rowidx = -1; }
				  if (where == "below") { var rowidx = -0; }
				  
				  var tr = table.parentElement;
				  var numcells = tr.childNodes.length;
				
				  while (tr) {
					 if (tr.tagName == "TR")
						rowidx++;
					 tr = tr.previousSibling;
				  }
				  
				  var tbl = ParentTable(table);
				  
				  if (!tbl) {
				  alert("Could not add row.");
				  return;
				  } 
				  
				  
				  var r = tbl.insertRow(rowidx);
				  
				  for (var i = 0; i < numcells; i++) {
					var c = r.appendChild( iView.document.createElement("TD") );
					
					if (table.parentNode.childNodes[i].colSpan)
					   c.colSpan = table.parentNode.childNodes[i].colSpan;
				  }
					if (table_borders == "on") {
						tableBorders('on');
					}
	
			} else
			{
			
				while (table.nodeName.toLowerCase() != "td") {
					//	if there's a parentNode available, work upon that
					if (table.parentNode) {
						table = table.parentNode;
					} 
					
					if (table.nodeName.toLowerCase() == "td") {
						  
						  //found a TD, so do the stuff
						  var idx = 0;
						  
						  if (where == "above") { var rowidx = -1; }
						  if (where == "below") { var rowidx = -0; }
						  
						  var tr = table.parentElement;
						  var numcells = tr.childNodes.length;
						
						
						  while (tr) {
							 if (tr.tagName == "TR")
								rowidx++;
							 tr = tr.previousSibling;
						  }
						  
						  var tbl = ParentTable(table);
						  
						  if (!tbl) {
						  alert("Could not add row.");
						  return;
						  } 
						  
						  var r = tbl.insertRow(rowidx);
						  for (var i = 0; i < numcells; i++) {
							var c = r.appendChild( iView.document.createElement("TD") );
							
							if (table.parentNode.childNodes[i].colSpan)
							   c.colSpan = table.parentNode.childNodes[i].colSpan;
						  }
							if (table_borders == "on") {
								tableBorders('on');
							}
					}
					
				}
			}
			iView.focus();
		}
	}

	function removeRow()
	{
	
		if (isTable())
		{
			BACKUP('Remove Row');
			var cursor = iView.document.selection.createRange();
			var table = cursor.parentElement();
			
			if (table.nodeName.toLowerCase() == "td") {
		
				  var rowidx = -1;
				  var tr = table.parentElement;
				  var numcells = tr.childNodes.length;
				 
			
				  while (tr) {
					 if (tr.tagName.toLowerCase() == "tr")
						rowidx++;
					 tr = tr.previousSibling;
				  }
			
				  var tbl = ParentTable(table);
				  
				  tbl.deleteRow(rowidx);
	
				
			}
			else
			{
			
				while (table.nodeName.toLowerCase() != "td") {
					//	if there's a parentNode available, work upon that
					if (table.parentNode) {
						table = table.parentNode;
					}
				} 
							
					if (table.nodeName.toLowerCase() == "td") {
					
						  var rowidx = -1;
						  var tr = table.parentElement;
						  var numcells = tr.childNodes.length;
						 
					
						  while (tr) {
							 if (tr.tagName == "TR")
								rowidx++;
							 tr = tr.previousSibling;
						  }
					
						  var tbl = ParentTable(table);
						  
						  tbl.deleteRow(rowidx);
					
					}
				}
		} //close istable
	}

	function insertCol(type)
	{
		
		if (isTable())
		{
			BACKUP('Insert Column (' + type + ')');
			var cursor = iView.document.selection.createRange();
			var table = cursor.parentElement();
			
			if (table.nodeName.toLowerCase() == "td") {
				
				//cellidx gets the column number where the cursor is
				var cellidx = table.cellIndex;
				
				//get the parent element
				var tbl = ParentTable(table);						
				
			} else
			{
			
				while (table.nodeName.toLowerCase() != "td") {
					//	if there's a parentNode available, work upon that
					if (table.parentNode) {
						table = table.parentNode;
					} 
					
					if (table.nodeName.toLowerCase() == "td") {
						
						//cellidx gets the column number where the cursor is
						var cellidx = table.cellIndex;
						//get the parent element
						var tbl = ParentTable(table);
						
						break;
					}
					
				}
			}	
			
	
			if (!tbl) {
			alert("Could not add column.");
			return;
			} 
			
			var i;
			for (i=0;i<tbl.childNodes.length;i++) {
				 if (tbl.childNodes[i].tagName == "TR") {
					if (type == "left") { var todo = "BeforeBegin"; }
					if (type == "right") { var todo = "AfterEnd"; }
					var cell = tbl.childNodes[i].childNodes[ cellidx ];
					cell.insertAdjacentElement(todo, iView.document.createElement("TD") );
				}
				if (table_borders == "on") {
					tableBorders('on');
				}
			}
			
			iView.focus();
		
		}
	
	}

	function removeCol()
	{
		
		if (isTable())
		{
			BACKUP('Remove Column');
		
			var cursor = iView.document.selection.createRange();
			var table = cursor.parentElement();
			
			if (table.nodeName.toLowerCase() == "td") {
				
				//cellidx gets the column number where the cursor is
				var cellidx = table.cellIndex;
				
				//get the parent element
				var tbl = ParentTable(table);						
				
			} else
			{
			
				while (table.nodeName.toLowerCase() != "td") {
					//	if there's a parentNode available, work upon that
					if (table.parentNode) {
						table = table.parentNode;
					} 
					
					if (table.nodeName.toLowerCase() == "td") {
						
						//cellidx gets the column number where the cursor is
						var cellidx = table.cellIndex;
						//get the parent element
						var tbl = ParentTable(table);
						
						break;
					}
					
				}
			}	
			
	
			if (!tbl) {
			alert("Could not add column.");
			return;
			} 
			
			var i;
			for (i=0;i<tbl.childNodes.length;i++) {
				 if (tbl.childNodes[i].tagName == "TR") {
					var cell = tbl.childNodes[i].childNodes[ cellidx ];
					
					//now remove the column
					cell.removeNode(true);
					
				}
	
			}
			
			iView.focus();
		
		}
	
	}

	function ParentTable(cell) {
		  var tab = cell.parentElement
		  while (tab) {
			 if ((tab.tagName == "TBODY") || (tab.tagName == "TABLE")) {
				return tab;
			 }
			 tab = tab.parentElement;
		  }
		  return false;
	}

	function modifyCell(val)
	{
		hideMenu() //hide context menu if its open
		
		var selection = iView.document.selection.createRange();
		var cursor = iView.document.selection.createRange();
		var table = cursor.parentElement(); 
		var args = new Array();
		
		if (table.nodeName.toLowerCase() == "td") {
			args["bgColor"] = table.bgColor;
			args["background"] = table.background;
			args["width"] = table.width;
		} else
		{
	
			while (table.nodeName.toLowerCase() != "td") {
				//	if there's a parentNode available, work upon that
				if (table.parentNode) {
					table = table.parentNode;
				} 
			
				if (table.nodeName.toLowerCase() == "td") {
					args["bgColor"] = table.bgColor;
					args["background"] = table.background;
					args["width"] = table.width;
					break;
				}
			
			}
		}
		
		hideMenu();
		arg = showModalDialog( "editor/files/cell_properties.htm",args,"font-family:Verdana; font-size:12; dialogWidth:400px; dialogHeight:280px;help:no;status:no");
		
		if (arg != null) {
		  BACKUP('Modify Table Cell');
		  table.width = ( (arg["width"] == "") ? "" : arg["width"] );
		  table.bgColor = ( (arg["bgColor"] == "") ? "" : arg["bgColor"] );
		  table.background = ( (arg["background"] == "") ? "" : arg["background"] );
		}
	
	}

	//===================================================
	//	PAGE CODES
	//===================================================

	function doProperties() {
		//page properties
		var args = new Array();
		args["title"] = iView.document.body.title;
		args["bgColor"] = iView.document.body.bgColor;
		args["background"] = iView.document.body.background;
		
		arg = showModalDialog( "editor/files/pageproperties.htm",args,"font-family:Verdana; font-size:12; dialogWidth:450px; dialogHeight:270px;help:no;status:no");
		
		if (arg != null) {
			BACKUP('Page Properties');
			iView.document.body.bgColor = ( 	(arg["bgColor"] == "blank") 	? 	"" 	:  	arg["bgColor"]);
			iView.document.body.background = ( 	(arg["background"] == "") 	? 	"" 	:  	arg["background"]);
			iView.document.body.title = ( 	(arg["title"] == "") 	? 	"" 	:  	arg["title"]);
		}
	}
	
	function doPreview() {
		//show the preview drop down menu
		var theMenu = "";
		for (x=0;x<previewSizes.length;x++) {
			if (previewSizes[x][1] == ""){
				theMenu += menu_seperator;
			} else {
				theMenu += menu_open1 + " onMouseDown=\"" + previewSizes[x][1] + "\"" + menu_open2 + previewSizes[x][0] + menu_close;
			}
		}
		
		document.all['tr_dropMenu'].innerHTML = theMenu;
		hideMenu();
		var e = event;
		var a = e.srcElement;
		var box = a.getBoundingClientRect();
		var canvas = document.compatMode == null || document.compatMode == "BackCompat" ? document.body : document.documentElement;
		tr_dropMenu.style.top = box.bottom + canvas.scrollTop + "px";
		tr_dropMenu.style.left = box.left + canvas.scrollLeft + "px";
		
		e.cancelBubble = true;
		
		var ifr = "<iframe id=\"frameId\" src=\"\" frameborder=\"0\" scrolling=\"no\" style=\"position:absolute;top:0x;left:0px;z-index:100;display:none\" ></iframe>";
		document.all['tr_dropMenu'].insertAdjacentHTML('beforeBegin', ifr);
		document.all('frameId').style.top = box.bottom + canvas.scrollTop + "px";
		document.all('frameId').style.left = box.left + canvas.scrollLeft + "px";
		document.all('frameId').style.width = '133'; //allow for the border
		document.all('frameId').style.display = 'block';
		document.all('frameId').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		document.all['tr_dropMenu'].style.display = "block";
	
	}
  
	function openPreview(size) {
		//open the preview window
		array = size.split("x");	//width and height of the window
		args = new Array();
		if (viewMode == 2) {
		  args["html"] = iView.document.body.innerText;
		} else {
		  args["html"] = iView.document.body.innerHTML;
		}
		args["style"] = styleSheet; //from config file
		args["height"] = array[1];
		args["path"] = path;
		hideMenu();
		arg = showModalDialog( "editor/files/preview.htm",args,"font-family:Verdana; font-size:12; dialogWidth:"+ array[0] +"px; dialogHeight:" + array[1] + "px;help:no;status:no");
	}	
	
	//===================================================
	//	HYPERLINK
	//===================================================	

	function doLink() {
	
		hideMenu();
		var args = new Array();
		args["Url"]    = ""
		args["Target"] = ""
		args["Color"]  = ""
		args["Style"]  = ""
		args["Action"] = ""
		args["Title"]  = ""
		
		var link = null;
			
		if (iView.document.selection.type == "Control") {
			var ControlRange = iView.document.selection.createRange();
			if (ControlRange(0).tagName.toUpperCase() == "IMG") {
			  var link = ControlRange(0).parentNode;
			}
		} else {
			link = iView.document.selection.createRange().parentElement();
		}
		
		if (link.tagName.toUpperCase() == "A") {
			args["Target"] = link.target;
			args["Color"]  = link.style.color;
			args["Style"]  = link.style.textDecoration;
			args["Title"]  = link.title;
			strHTML = link.outerHTML;
			var r, re;                   //Declare variables.
			re = /href="/i;               //Create regular expression pattern.
			r = strHTML.search(re);
			if (r > 0) {
			  strHTML = strHTML.substring(r+6);
			  re = /"/i;               //Create regular expression pattern.
			  r = strHTML.search(re);
			  strHTML = strHTML.substring(0,r);
			}
			args["Url"] = strHTML;
		}
		
		var arg = new Array();
		arg = showModalDialog( "editor/files/hyperlink.htm",args,"font-family:Verdana; font-size:12; dialogWidth:450px; dialogHeight:310px;help:no;status:no");
	
		//build the URL
		var strUrl;
		var strTarget;
		var strColor;
		var strStyle;
		var strTitle;
		
		if (arg != null && arg["Action"] != "") {
			BACKUP('Insert Hyperlink');
			strUrl    = arg["Url"];
			strTarget = arg["Target"];
			strColor  = arg["Color"];
			strStyle  = arg["Style"];
			strTitle  = arg["Title"];
		
			if (arg["Action"] == "Link") {
			  var theSelection = iView.document.selection.createRange()
			  theSelection.execCommand("CreateLink", false, strUrl);
			
			  if (iView.document.selection.type == "Control") {
				newLink = theSelection(0).parentNode;
			  } else {
				newLink = theSelection.parentElement()
			  }
				
			  //if target is NOT empty, there must be one to add, so add it!
			  if (strTarget != "") {
				newLink.target = strTarget;
			  } else {
				newLink.removeAttribute("target")
			  }
			  
			  //title attributes
			  if (strTitle != "") {
				newLink.title = strTitle;
			  } else {
				newLink.removeAttribute("title")
			  }
				
			  //check to see that the selection is not equal to "NONE" or "please select"
			  if (strStyle == "please select") {
				newLink.removeAttribute("style")
			  } else {
				newLink.style.textDecoration = strStyle;
			  }
				
			  if (strColor != "None") {
				newLink.style.color = strColor;
			  }
			} else {
			  var theSelection = iView.document.selection.createRange()
			  BACKUP('Remove Hyperlink');
			  theSelection.execCommand("unlink", false, null);
			}
		}
		iView.focus();
	}
  
	//===================================================
	//	EMAIL LINKS
	//===================================================	
	
	function doEmail() {
		hideMenu();
		var args = new Array();

		// Display Link information dialog
		args["Url"]    = ""
		args["Color"]  = ""
		args["Style"]  = ""
		args["Action"] = ""
		
		var link = null;
			
		if (iView.document.selection.type == "Control") {
			var ControlRange = iView.document.selection.createRange();
			if (ControlRange(0).tagName.toUpperCase() == "IMG") {
			  var link = ControlRange(0).parentNode;
			}
		} else {
			link = iView.document.selection.createRange().parentElement();
		}
		
		if (link.tagName.toUpperCase() == "A") {
			args["Color"]  = link.style.color;
			args["Style"]  = link.style.textDecoration;
			var text = link.href;
			var myRegExp = "mailto:";
			args["Url"] = text.replace ( myRegExp, "" );
		}
		
		var arg = new Array();
		arg = showModalDialog( "editor/files/email_link.htm",args,"font-family:Verdana; font-size:12; dialogWidth:450px; dialogHeight:280px;help:no;status:no");

		//build the URL
		var strUrl;
		var strColor;
		var strStyle;
		
		if (arg != null && arg["Action"] != "") {
			strUrl    = arg["Url"];
			strColor  = arg["Color"];
			strStyle  = arg["Style"];
		
			if (arg["Action"] == "Link") {
			  var theSelection = iView.document.selection.createRange()
			  var theLink = ("mailto:" + strUrl);
			  BACKUP('Insert Email Link');
			  theSelection.execCommand("CreateLink", false, theLink);
			
			  if (iView.document.selection.type == "Control") {
				newLink = theSelection(0).parentNode;
			  } else {
				newLink = theSelection.parentElement()
			  }
				
			  //check to see that the selection is not equal to "NONE" or "please select"
			  if (strStyle == "please select") {
				newLink.removeAttribute("style")
			  } else {
				newLink.style.textDecoration = strStyle;
			  }
				
			  if (strColor != "None") {
				newLink.style.color = strColor;
			  }
			} else {
			  var theSelection = iView.document.selection.createRange()
			  BACKUP('Remove Email Link');
			  theSelection.execCommand("unlink", false, null);
			}
		}
		iView.focus();
	}

	//======================================================
	//	TOGGLE BETWEEN MODES
	//======================================================
  	function toggle()
  	{  
		if(viewMode == 1) {
		  	var allForms = iView.document.getElementsByTagName("TD");
			for (a=0; a < allForms.length; a++) {
						allForms[a].removeAttribute("style")
			}
			
			var allForms = iView.document.getElementsByTagName("TABLE");
			for (a=0; a < allForms.length; a++) {
						allForms[a].removeAttribute("style")
			}
			var allForms = iView.document.getElementsByTagName("FORM");
			for (a=0; a < allForms.length; a++) {
						allForms[a].removeAttribute("style")
			}
			
			//update the button states (ie: make them disabled)
			buttons('disable');
			
			//make the code mode button look pressed
			btnPressed("desc_code");
			
			//update the "mode" in the status bar
			document.getElementById("editor_status").innerHTML = statusCodeMode;
			
			//reset the toolbars
			resetToolbars();
			
			iHTML = iView.document.body.outerHTML;
			iView.document.body.innerText = iHTML;
			
			//get some current values
			bgColor = iView.document.body.bgColor;
			background = iView.document.body.background;
			
			//change the font to editor code
			iView.document.body.style.fontFamily = editorFont;
			iView.document.body.style.fontSize = editorFontSize;
			iView.document.body.text = editorTextColor;
			iView.document.body.bgColor = editorBgColor;
			iView.document.body.background = '';
			iView.focus();
			
			//stop the HTML path
			document.getElementById("html_path").innerHTML = "";
			showHTMLpath = false;
			
			viewMode = 2; // Code
		}
		else
		{
	   		//update the button states (ie: make them enabled)
			buttons('enable');
		  
			//update the "mode" in the status bar
			document.getElementById("editor_status").innerHTML = statusWysiwyg;
	
			iView.document.body.style.fontFamily = "";
			iView.document.body.style.fontSize = "";
			iView.document.body.text = "";
			iView.document.body.bgColor = bgColor;
			iView.document.body.background = background;
	
			//stop the editor from adding absolute URLs
			txtRange = iView.document.body.createTextRange() ; 
			txtRange.select(); 
			txtRange.execCommand("Copy"); 
			txtRange.execCommand("Paste"); 
			
			iText = iView.document.body.innerText; 
			iView.document.body.innerHTML = iText; 
			
			//start the HTML path
			showHTMLpath = true;
		  
			viewMode = 1; // set the mode to WYSIWYG view
	
			if (table_borders == "on") {
			//redraw the borders
				for(i=0;i<iView.document.all.length;i++) {
					if(iView.document.all[i].tagName.toUpperCase() == 'TD') {
					void(iView.document.all[i].style.border='1px dashed #C0C0C0');
					void(0);
					}
				}
		
				for(a=0;a<iView.document.all.length;a++) {
					if(iView.document.all[a].tagName.toUpperCase() == 'TABLE') {
						void(iView.document.all[a].style.border='1px dashed #C0C0C0');
						void(0);
					}
				}
			}
			
			if (form_borders == "on") {
			//redraw the form border
				for(i=0;i<iView.document.all.length;i++) {
					if(iView.document.all[i].tagName.toUpperCase() == 'FORM'){
					void(iView.document.all[i].style.border='1px dashed red');
					void(0); 
					}
				}
			}
		}
  	}
	
	//=====================================================================
	//	BORDER SWITCHING
	//=====================================================================


	function toggleFormBorders() {
		switch (form_borders) {
			case "on" : formBorders("off"); break;
			case "off": formBorders("on");  break;
		}
	}

	function toggleTableBorders() {
		switch (table_borders) {
			case "on"  : tableBorders("off"); break;
			case "off" : tableBorders("on");  break;
		}
	}

	function formBorders(state) {
		switch(state) {
			case "on":	for(i=0;i<iView.document.all.length;i++) {
							if(iView.document.all[i].tagName.toUpperCase() == 'FORM'){
							void(iView.document.all[i].style.border='1px dashed red');
							void(0); 
							}
						}
						form_borders = "on";
						break;
						
			case "off": var allForms = iView.document.getElementsByTagName("FORM");
						for (a=0; a < allForms.length; a++) {
									allForms[a].removeAttribute("style")
						}
						form_borders = "off";
						break;
		}
	}

	function tableBorders(state) {
		switch (state) {
			case "on":	for(i=0;i<iView.document.all.length;i++) {
							if(iView.document.all[i].tagName.toUpperCase() == 'TD') {
								void(iView.document.all[i].style.border='1px dashed #C0C0C0');
								void(0);
							}
						}
					
						for(a=0;a<iView.document.all.length;a++) {
							if(iView.document.all[a].tagName.toUpperCase() == 'TABLE') {
								void(iView.document.all[a].style.border='1px dashed #C0C0C0');
								void(0);
							}
						}
						table_borders = "on";
						break;
			
			case "off": var allForms = iView.document.getElementsByTagName("TD");
						for (a=0; a < allForms.length; a++) {
									allForms[a].removeAttribute("style")
						}
						
						var allForms = iView.document.getElementsByTagName("TABLE");
						for (a=0; a < allForms.length; a++) {
									allForms[a].removeAttribute("style")
						}
						table_borders = "off";
						break;
		}
	}

	function applyBorder() {
		//now if the borders are not being shown, apply the dotted line to them
		if (borders == "on") {
			for(i=0;i<iView.document.all.length;i++)
			{
				if(iView.document.all[i].tagName=='TD')
				void(iView.document.all[i].style.border='1px dashed #C0C0C0');
				void(0); 
			}
		}
	}

	//=====================================================
	// 	BUTTON STYLES
	//=====================================================

	function btnOver(ctrl) {
		if (ctrl.style.borderBottom != "buttonhighlight 1px solid") {
			ctrl.style.borderBottom = "buttonshadow solid 1px";
			ctrl.style.borderLeft = "buttonhighlight solid 1px";
			ctrl.style.borderRight = "buttonshadow solid 1px";
			ctrl.style.borderTop = "buttonhighlight solid 1px";
			ctrl.style.background = "#EEEEEE";
		}
		ctrl.style.cursor = "hand";
	}
	
	//click
	function btnDown(ctrl) {
		ctrl.style.borderBottom = "buttonhighlight solid 1px";
		ctrl.style.borderLeft = "buttonshadow solid 1px";
		ctrl.style.borderRight = "buttonhighlight solid 1px";
		ctrl.style.borderTop = "buttonshadow solid 1px";
		ctrl.style.background = "#BBBBBB";
	}
	
	//button in selected state
	function btnPressed(ctrl) {
		eval("document.all." + ctrl + ".style.borderBottom = 'buttonhighlight solid 1px'");
		eval("document.all." + ctrl + ".style.borderLeft = 'buttonshadow solid 1px'");
		eval("document.all." + ctrl + ".style.borderRight = 'buttonhighlight solid 1px'");
		eval("document.all." + ctrl + ".style.borderTop = 'buttonshadow solid 1px'");
		eval("document.all." + ctrl + ".style.background = '#EEEEEE'");
	}
	
	function btnOut(ctrl){
		if (ctrl.style.borderBottom != "buttonhighlight 1px solid"){
			ctrl.style.background = "";
			ctrl.style.border = "1px solid #DDDDDD";
		}
	}
	
	function btnUp(ctrl){
		//now only used for buttons with no state
		ctrl.style.border = "1px solid #DDDDDD";
		ctrl.style.backgroundColor = "";
	}	
	
	function clearButton(ctrl) {
		eval("document.all." + ctrl + ".style.borderColor = '';");
		eval("document.all." + ctrl + ".style.backgroundColor = '';");
	}
	
	//==============================================================
	//	UNDO FUNCTIONS
	//=============================================================
	
	var b_ackup = new Array();
	var history = new Array();
	var undo_pos = 0;//Position of undo 
	var flag = false;// shall we start new undo thread and delete obsolete items?

	function undoDrop() {
		//draw a drop down list of undo features
		var tmp = "";
		btnPressed('desc_undo');
		//always offer the undo option
		tmp += menu_open1 + " onMouseDown=\"undo();clearButton('desc_undo');\" " + menu_open2 + "Undo (Ctrl+Z)" + menu_close;
		tmp += menu_seperator;
		
		if (history.length){
			tmp += menu_normal + "Last " + undoListSize + " Commands" + menu_close;
			
			if (flag != false) {
				endAt = undo_pos - 1;
			} else {
				endAt = history.length;
			}
			
			for (x=0;x<endAt;x++) {
				if (x<undoListSize) {
					tmp += menu_open_dis + history[x] + menu_close;
				}
			}
		}

		document.all['drop_down_undo'].innerHTML = tmp;
		hideMenu();
		var e = event;
		var a = e.srcElement;
		var box = a.getBoundingClientRect();
		var canvas = document.compatMode == null || document.compatMode == "BackCompat" ? document.body : document.documentElement;
		drop_down_undo.style.top = box.bottom + canvas.scrollTop + "px";
		drop_down_undo.style.left = box.left + canvas.scrollLeft + "px";
		
		e.cancelBubble = true;
		var ifr = "<iframe id=\"frameId\" src=\"\" frameborder=\"0\" scrolling=\"no\" style=\"position:absolute;top:0x;left:0px;z-index:100;display:none\" ></iframe>";
		document.all['drop_down_undo'].insertAdjacentHTML('beforeBegin', ifr);
		document.all('frameId').style.top = box.bottom + canvas.scrollTop + "px";
		document.all('frameId').style.left = box.left + canvas.scrollLeft + "px";
		document.all('frameId').style.width = '133'; //allow for the border
		document.all('frameId').style.display = 'block';
		document.all('frameId').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		document.all['drop_down_undo'].style.display = "block";

	}
	
	function redoDrop() {
		//draw a drop down list of undo features
		var tmp = "";
		btnPressed('desc_redo');
		//always offer the redo option
		tmp += menu_open1 + " onMouseDown=\"redo();clearButton('desc_redo');\" " + menu_open2 + "Redo (Ctrl+Shift+Z)" + menu_close;
		tmp += menu_seperator;
		
		if (history.length){
			tmp += menu_normal + "Last " + undoListSize + " Commands" + menu_close;
			
			startAt = undo_pos;
			
			for (x=startAt;x<b_ackup.length;x++) {
				if (x<undoListSize) {
					tmp += menu_open_dis + history[x] + menu_close;
				}
			}
		}

		document.all['drop_down_redo'].innerHTML = tmp;
		hideMenu();
		var e = event;
		var a = e.srcElement;
		var box = a.getBoundingClientRect();
		var canvas = document.compatMode == null || document.compatMode == "BackCompat" ? document.body : document.documentElement;
		drop_down_redo.style.top = box.bottom + canvas.scrollTop + "px";
		drop_down_redo.style.left = box.left + canvas.scrollLeft + "px";
		
		e.cancelBubble = true;
		var ifr = "<iframe id=\"frameId\" src=\"\" frameborder=\"0\" scrolling=\"no\" style=\"position:absolute;top:0x;left:0px;z-index:100;display:none\" ></iframe>";
		document.all['drop_down_redo'].insertAdjacentHTML('beforeBegin', ifr);
		document.all('frameId').style.top = box.bottom + canvas.scrollTop + "px";
		document.all('frameId').style.left = box.left + canvas.scrollLeft + "px";
		document.all('frameId').style.width = '133'; //allow for the border
		document.all('frameId').style.display = 'block';
		document.all('frameId').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		document.all['drop_down_redo'].style.display = "block";

	}
	
	function setUndo(src) {
		//used to set the first entry in the array to the page default
		b_ackup[0]=src;
	}

	function BACKUP(what) {
		//add "what" do the list of items backed up...
		if ((what != "") && (what != null)) {
			history.unshift(what);
		}
		
		if (flag){// action if undo was clicked
			var  removed = b_ackup.splice(flag,b_ackup.length - flag);
			for (var i = 0; i < removed.length; i++) {
			delete removed[i];//delete obsolete array items
			} 
			
			if (flag > 0) {
				document.getElementById("desc_redo").disabled = false; //disable the button
				document.getElementById("desc_redo").style.filter = "alpha(Opacity=100)"; //make it look disabled
				document.getElementById("desc_redo").style.cursor = "hand";
			}
			
			b_ackup[b_ackup.length] = iView.document.body.innerHTML;
			undo_pos = b_ackup.length - 1;
			flag = false;
			
			if (undo_pos >= 1) {
				document.getElementById("desc_undo").disabled = false; //enable the button
				document.getElementById("desc_undo").style.filter = "alpha(Opacity=100)"; //make it look enabled
				document.getElementById("desc_undo").style.cursor = "hand";
			}

		} else {
			//write to backup array
			b_ackup[b_ackup.length] = iView.document.body.innerHTML;
			undo_pos = b_ackup.length - 1;								
			flag = false;
			
			if (undo_pos >= 1) {
				document.getElementById("desc_undo").disabled = false; //enable the button
				document.getElementById("desc_undo").style.filter = "alpha(Opacity=100)"; //make it look enabled
				document.getElementById("desc_undo").style.cursor = "hand";
			}
		}
	}
	
	function undo() {
				
		if (useCMDundo) {
			//using the standard cmdExec undo
			cmdExec('undo');
		} else {
			if (b_ackup.length){
				//remove the operation from the history
				//history.splice(0,1);
				if(undo_pos==0){iView.focus();return;}// beginning of backup items
				if(flag == false){BACKUP();}// save last state of document
				iView.document.body.innerHTML=b_ackup[undo_pos -1];
				undo_pos=undo_pos - 1;
				flag = undo_pos +1;
				//update buttons (undo and redo)
				if ((history.length < 1) || (undo_pos == 0)) {
					document.getElementById("desc_undo").disabled = true; //disable the button
					document.getElementById("desc_undo").style.filter = "alpha(Opacity=20)"; //make it look disabled
					document.getElementById("desc_undo").style.cursor = "";
				}
				if (flag > 0) {
					document.getElementById("desc_redo").disabled = false; //disable the button
					document.getElementById("desc_redo").style.filter = "alpha(Opacity=100)"; //make it look disabled
					document.getElementById("desc_redo").style.cursor = "hand";
				}
			}
		} 
	}						
		
	function redo() {
		if (useCMDundo) {
			//using the standard cmdExec redo
			cmdExec('redo');
		} else {
			if(undo_pos == b_ackup.length -1){iView.focus();return;}
			//end of backup array
			
			iView.document.body.innerHTML=b_ackup[undo_pos +1];
			
			undo_pos=undo_pos + 1;						
															
			flag = undo_pos +1;
		
			//update buttons (undo and redo)
			if (undo_pos > 0) {
				document.getElementById("desc_undo").disabled = false; //disable the button
				document.getElementById("desc_undo").style.filter = "alpha(Opacity=100)"; //make it look disabled
				document.getElementById("desc_undo").style.cursor = "hand";
			}
			if (flag == b_ackup.length) {
				document.getElementById("desc_redo").disabled = true; //disable the button
				document.getElementById("desc_redo").style.filter = "alpha(Opacity=20)"; //make it look disabled
				document.getElementById("desc_redo").style.cursor = "";
			}
		} 
	}
	
	//LAST BUT NOT LEAST
	//items to hide and show menus etc.
	var _menu;
	
			function showMenu(e, sId){
			hideMenu();
			_menu = document.getElementById(sId);
			var a = e.srcElement;
			var box = a.getBoundingClientRect();
			var canvas = document.compatMode == null || document.compatMode == "BackCompat" ?
											document.body : document.documentElement;
			_menu.style.top = box.bottom + canvas.scrollTop + "px";
			_menu.style.left = box.left + canvas.scrollLeft + "px";
			_menu.style.display = _menu.style.display == "block" ? "none" : "block";
			e.cancelBubble = true;
			return false;
	}
	
	function hideMenu() {
		
		//hide the iFrame backgrounds from the menus
		if( document.all('frameId') )	{
			document.all('frameId').removeNode();
			if (document.all("shadow_0"))
			{
				for (x=0;x<menu_shadowSize;x++) {
					eval("document.all['shadow_" + x + "'].style.display = \"none\";");
				}
			}
		}
		
		divAry = document.getElementsByTagName("div");
		divLen=divAry.length;
		for(j=0;j<divLen;j++){
			if (divAry[j].id.match(/^(tr_)/gi) && divAry[j].style.display == "block") {
				divAry[j].style.display = "none";
			}
		}
	
		
		if (_menu)
			_menu.style.display = "none";
	}
	
	
	
	

	
	var preload=new Image();
	preload.src="editor/images/context_seperator.gif";
