
function teststyle(){
	var t1="btn_save";
	eval("document.getElementById('"+btn+"').style.borderLeftWidth = '20px'");
}

function ssload(){alert('mike');}

function on(btn){
	eval("document.images('"+btn+"').style.cssText = 'border-left-width:1px; border-left-color:menu; border-left-style:solid;border-top-width:1px; border-top-color:menu; border-top-style:solid;border-right-width:1px; border-right-color:menu; border-right-style:solid;border-bottom-width:1px; border-bottom-color:menu; border-bottom-style:solid;filter:alpha(opacity=100);background-color:menu;'");
}

function over(btn){
	eval("document.images('"+btn+"').style.cssText = 'border-left-width:1px; border-left-color:white; border-left-style:solid;border-top-width:1px; border-top-color:white; border-top-style:solid;border-right-width:1px; border-right-color:dimgray; border-right-style:outset;border-bottom-width:1px; border-bottom-color:dimgray; border-bottom-style:outset;filter:alpha(opacity=100);background-color:menu;'");
}

function down(btn){
	eval("document.images('"+btn+"').style.cssText = 'border-left-width:1px; border-left-color:dimgray; border-left-style:inset;border-top-width:1px; border-top-color:dimgray; border-top-style:inset;border-right-width:1px; border-right-color:white; border-right-style:solid;border-bottom-width:1px; border-bottom-color:white; border-bottom-style:solid;filter:alpha(opacity=100);background-color:gainsboro;'");
}

function off(btn){
	eval("document.images('"+btn+"').style.cssText = 'border-left-width:1px; border-left-color:menu; border-left-style:solid;border-top-width:1px; border-top-color:menu; border-top-style:solid;border-right-width:1px; border-right-color:menu; border-right-style:solid;border-bottom-width:1px; border-bottom-color:menu; border-bottom-style:solid;filter:alpha(opacity=30);background-color:menu;'");
}

function tablecommand(command){
	var cellflag=false;
	var rowflag=false;
	var tableflag=false;
	var cellindex,rowindex,tableref;
	var xsel=document.frames("LatticeEditDocument").document.selection;
	var xobj=document.frames("LatticeEditDocument").document.selection.createRange();
	if(xsel.type=="None"||xsel.type=="Text"){
		xsel=xobj.parentElement();
		while(xsel.tagName!="BODY"&&cellflag==false){
			if(xsel.tagName=="TD"){cellindex=xsel.cellIndex;cellflag=true;}
			if(cellflag==false){xsel=xsel.parentElement;}
		}
	}else if(xsel.type=="Control"){
		xsel=xobj.item(0);
		if(xsel.tagName=="TD"){
			cellindex=xsel.cellIndex;
			cellflag=true;
		}else{
			while(xsel.tagName!="BODY"&&cellflag==false){
				if(xsel.tagName=="TD"){cellindex=xsel.cellIndex;cellflag=true;}
				if(cellflag==false){xsel=xsel.parentElement;}
			}
		}
	}
	if(cellflag==true){
		xsel=document.frames("LatticeEditDocument").document.selection;
		xobj=document.frames("LatticeEditDocument").document.selection.createRange();
		if(xsel.type=="None"||xsel.type=="Text"){
			xsel=xobj.parentElement();
			while(xsel.tagName!="BODY"&&rowflag==false){
				if(xsel.tagName=="TR"){
					rowindex=xsel.rowIndex;
					rowflag=true;
				}
				if(rowflag==false){xsel=xsel.parentElement;}
			}
		}else if(xsel.type=="Control"){
			xsel=xobj.item(0);
			if(xsel.tagName=="TR"){
				rowindex=xsel.rowIndex;
				rowflag=true;
			}else{
				while(xsel.tagName!="BODY"&&rowflag==false){
					if(xsel.tagName=="TR"){
						rowindex=xsel.rowIndex;
						rowflag=true;
					}
					if(rowflag==false){
						xsel=xsel.parentElement;
					}
				}
			}
		}
		xsel=document.frames("LatticeEditDocument").document.selection;
		xobj=document.frames("LatticeEditDocument").document.selection.createRange();
		if(xsel.type=="None"||xsel.type=="Text"){
			xsel=xobj.parentElement();
			while(xsel.tagName!="BODY"&&tableflag==false){
				if(xsel.tagName=="TABLE"){tableflag=true;}
				if(tableflag==false){xsel=xsel.parentElement;}
			}
		}else if(xsel.type=="Control"){
			xsel=xobj.item(0);
			if(xsel.tagName=="TABLE"){
				tableflag=true;
			}else{
				while(xsel.tagName!="BODY"&&tableflag==false){
					if(xsel.tagName=="TABLE"){tableflag=true;}
					if(tableflag==false){xsel=xsel.parentElement;}
				}
			}
		}
		if(command=="ic"){
			var temprowcount=xsel.rows.length;
			var tempcell;
			var tempspancount=0;
			var tempspanholder;
			var tempcellwidth=xsel.rows[rowindex].cells[cellindex].width;
			var xpositequiv=-1;
			var xposcount=0;
			while(xposcount<=cellindex){
				xpositequiv+=parseInt(xsel.rows[rowindex].cells[xposcount].colSpan);
				xposcount++;
			}
			var ypositequiv=-1;
			var yposcount=0;
			var ymax=xsel.rows[rowindex].cells.length;
			while(yposcount<=ymax-1){
				ypositequiv+=parseInt(xsel.rows[rowindex].cells[yposcount].colSpan);
				yposcount++;
			}
			var idealinsert=xpositequiv+1;
			var zi2=0;
			var zirowtouse=0;
			var zirowtot=xsel.rows.length;
			var rowarray=new Array(zirowtot);
			var rowarray2=new Array(zirowtot);
			for(init1=0;init1<=zirowtot-1;init1++){
				rowarray[init1]=0;
				rowarray2[init1]=0;
			}
			for(zi1=0;zi1<=zirowtot-1;zi1++){
				zi2=0;
				while(zi2<idealinsert&&(rowarray[zi1]==null||rowarray[zi1]<idealinsert)){
					rowarray[zi1]+=parseInt(xsel.rows[zi1].cells[zi2].colSpan);
					rowarray2[zi1]++;
					zi2++;
				}
			}
			var allequal=true;
			var zi3a,zi3b;
			var zthemax=0;
			for(zi3=0;zi3<=zirowtot-1;zi3++){
				zi3a=rowarray[0];
				zi3b=rowarray[zi3];
				if(zi3b>zthemax){zthemax=zi3b;}
				if(zi3a!=zi3b){allequal=false;}
			}
			if(allequal==false){
				var zi4=0;
				var allequal2=true;
				while(zthemax<=ypositequiv&&allequal==false){
					for(zi5=0;zi5<=zirowtot-1;zi5++){
						rowarray[zi5]+=parseInt(xsel.rows[zi5].cells[rowarray2[zi5]].colSpan);
					}
					for(zi3=0;zi3<=zirowtot-1;zi3++){
						zi3a=rowarray[0];
						zi3b=rowarray[zi3];
						if(zi3b>zthemax){zthemax=zi3b;}
						if(zi3a!=zi3b){allequal2=false;}
					}
					if(allequal2==true){allequal=true;}
					for(zi8=0;zi8<=zirowtot-1;zi8++){rowarray2[zi8]++;}
					}
				}
				var zi9;
				for(zi7=0;zi7<=zirowtot-1;zi7++){
					zi9=xsel.rows[zi7].insertCell(rowarray2[zi7]);
					zi9.width=tempcellwidth;
				}
		}else if(command=="dc"){
			var temprowcount=xsel.rows.length;
			for(iccount=0;iccount<=temprowcount-1;iccount++){
				xsel.rows[iccount].deleteCell(cellindex);
			}
			}else if(command=="ir"){
				var tempcell;
				var tempcellb;
				var tempcellcount=xsel.rows[rowindex].cells.length;
				var cellcolarray=new Array(tempcellcount);
				var cellrowarray=new Array(tempcellcount);
				for(cacount=0;cacount<=tempcellcount-1;cacount++){
					cellcolarray[cacount]=xsel.rows[rowindex].cells(cacount).colSpan;
					cellrowarray[cacount]=xsel.rows[rowindex].cells(cacount).rowSpan;
				}
				tempcell=xsel.insertRow(rowindex);
				for(cbcount=0;cbcount<=tempcellcount-1;cbcount++){
					tempcellb=tempcell.insertCell();
					if(cellcolarray[cbcount]!=1){tempcellb.colSpan=cellcolarray[cbcount];}
				}
		}else if(command=="dr"){
				var temprowcount=xsel.rows.length;tempcell=xsel.deleteRow(rowindex);
		}else if(command=="mc"){
				if(xsel.rows[rowindex].cells[cellindex+1]){
					var x=parseInt(xsel.rows[rowindex].cells[cellindex].colSpan)+parseInt(xsel.rows[rowindex].cells[cellindex+1].colSpan);
					var y=xsel.rows[rowindex].cells[cellindex].innerHTML+" "+xsel.rows[rowindex].cells[cellindex+1].innerHTML;
					xsel.rows[rowindex].deleteCell(cellindex+1);
					xsel.rows[rowindex].cells[cellindex].colSpan=x;
					xsel.rows[rowindex].cells[cellindex].innerHTML=y;
				}
		}else if(command=="md"){
				var yatemprow=xsel.rows.length;
				var yamax=0;
				for(ya1=0;ya1<=yatemprow-1;ya1++){
					var ypositequiv=-1;
					var yposcount=0;
					var ymax=xsel.rows[ya1].cells.length;
					while(yposcount<=ymax-1){
						ypositequiv+=parseInt(xsel.rows[ya1].cells[yposcount].colSpan);
						yposcount++;
					}
					if(ypositequiv>yamax){yamax=ypositequiv;}
				}
				var rowarray=new Array();
				var rowarray2=new Array();
				var myrowcount=xsel.rows.length;
				for(ra1=0;ra1<=myrowcount-1;ra1++){
					rowarray[ra1]=new Array();
					rowarray2[ra1]=0;
					for(cr1=0;cr1<=yamax;cr1++){rowarray[ra1][cr1]=777;}
				}
				var tempra;
				var ra2=0;
				for(ra3=0;ra3<=yamax;ra3++){
					ra2=0;
					while(ra2<=myrowcount-1){
						if(xsel.rows[ra2].cells[ra3]){
							tempra=parseInt(xsel.rows[ra2].cells[ra3].rowSpan);
							if(tempra>1){
								rowarray[ra2][ra3]=ra3+rowarray2[ra2];
								for(zoo=1;zoo<=tempra-1;zoo++){rowarray2[ra2+zoo]--;}
							}
						}
						if(rowarray[ra2][ra3-1]!=ra3+rowarray2[ra2]){
							rowarray[ra2][ra3]=ra3+rowarray2[ra2];
						}else{
							rowarray[ra2][ra3]=555;
						}
						ra2++;
					}
				}
				var samx="";
				var samcount=0;
				for(rx1=0;rx1<=myrowcount-1;rx1++){
					samcount=rowarray[rx1].length;
					for(rx2=0;rx2<=samcount-1;rx2++){
						samx+="-"+rowarray[rx1][rx2];
					}
					samx+="\n";
				}
				var j=parseInt(xsel.rows[rowindex].cells[cellindex].rowSpan);
				var jcount=rowarray[rowindex].length;
				var jval=0;
				for(jc1=0;jc1<=jcount-1;jc1++){
					if(rowarray[rowindex][jc1]==cellindex){jval=jc1;}
				}
				if(xsel.rows[rowindex+j]){
					var cellindex2=rowarray[rowindex+j][jval];
					var x=parseInt(xsel.rows[rowindex].cells[cellindex].rowSpan)+parseInt(xsel.rows[rowindex+j].cells[cellindex2].rowSpan);
					var y=xsel.rows[rowindex].cells[cellindex].innerHTML+" "+xsel.rows[rowindex+j].cells[cellindex2].innerHTML;
					xsel.rows[rowindex+j].deleteCell(cellindex2);
					xsel.rows[rowindex].cells[cellindex].rowSpan=x;
					xsel.rows[rowindex].cells[cellindex].innerHTML=y;
				}
		}else if(command=="sc"){
				var getrowspan=parseInt(xsel.rows[rowindex].cells[cellindex].rowSpan);
				var getcolspan=parseInt(xsel.rows[rowindex].cells[cellindex].colSpan);
				if(getrowspan>1){
					var xr1=getrowspan-1;
					var xrposit=rowindex;
					var xrcposit=cellindex;
					var xrholder;xsel.rows[rowindex].cells[cellindex].rowSpan=1;
					for(xr2=1;xr2<=xr1;xr2++){
						xrholder=xsel.rows[xrposit+xr2].insertCell(xrcposit);
						xrholder.colSpan=xsel.rows[rowindex].cells[cellindex].colSpan;
					}
				}
				if(getcolspan>1){
					var yr1=getcolspan-1;
					var yrposit=rowindex;
					var yrcposit=cellindex;
					var yrholder;xsel.rows[rowindex].cells[cellindex].colSpan=1;
					for(yr2=1;yr2<=yr1;yr2++){
						yrholder=xsel.rows[yrposit].insertCell(yrcposit);
						yrholder.rowSpan=xsel.rows[rowindex].cells[cellindex].rowSpan;
					}
				}
			}
		}
}

function showcmenu(x,y){
	if(islattice=="lok"||keynotchecked==true){
		contextcode="";
		eval('window.showModalDialog("../latticeeditor/cmenu.htm",window,"dialogHeight: 375px;dialogLeft: '+x+'; dialogWidth: 150px; help: no;scroll: no; status: no")');
		if(contextcode=="1"){
			tableProp();
		}else if(contextcode=="2"){
			cellProp();
		}else if(contextcode=="3"){
			imageProp();
		}else if(contextcode=="20"){
			insertbookmark();
		}else if(contextcode=="4"){
			btncommand("btn_cut");
		}else if(contextcode=="5"){
			btncommand("btn_copy");
		}else if(contextcode=="6"){
			btncommand("btn_paste");
		}else if(contextcode=="31"){
			tablecommand("ic");
		}else if(contextcode=="32"){
			tablecommand("dc");
		}else if(contextcode=="33"){
			tablecommand("ir");
		}else if(contextcode=="34"){
			tablecommand("dr");
		}else if(contextcode=="35"){
			tablecommand("mc");
		}else if(contextcode=="36"){
			tablecommand("md");
		}else if(contextcode=="37"){
			tablecommand("sc");
		}else if(contextcode=="7"){
			//document.frames("LatticeTemp").focus();
			document.frames("LatticeTemp").document.execCommand("Refresh",false);
			document.frames("LatticeTemp").document.execCommand("Paste",false);
			var cc7=document.frames("LatticeTemp").document.body.innerText;
			//document.frames("LatticeEditDocument").focus();
			var xobj=document.frames("LatticeEditDocument").document.selection.createRange();
			xobj.pasteHTML(cc7);
		}else if(contextcode=="8"){
			//document.frames("LatticeTemp").focus();
			document.frames("LatticeTemp").document.execCommand("Refresh",false);
			document.frames("LatticeTemp").document.execCommand("Paste",false);
			var editBody=document.frames("LatticeTemp").document.body;
			for(var intLoop=0;intLoop<editBody.all.length;intLoop++){
				el=editBody.all[intLoop];
				el.removeAttribute("className","",0);
				el.removeAttribute("style","",0);
			}
			var html=document.frames("LatticeTemp").document.body.innerHTML;
			html=html.replace(/<o:p>&nbsp;<\/o:p>/g,"");
			html=html.replace(/o:/g,"");
			//document.frames("LatticeEditDocument").focus();
			var xobj=document.frames("LatticeEditDocument").document.selection.createRange();
			xobj.pasteHTML(html);
		}else if(contextcode=="9"){
			var tableflag=false;
			var xsel=document.frames("LatticeEditDocument").document.selection;
			var xobj=document.frames("LatticeEditDocument").document.selection.createRange();
			if(xsel.type=="None"||xsel.type=="Text"){
				xsel=xobj.parentElement();
				while(xsel.tagName!="BODY"&&tableflag==false){
					if(xsel.tagName=="TABLE"){tableflag=true;}
					if(tableflag==false){xsel=xsel.parentElement;}
				}
			}else if(xsel.type=="Control"){
				xsel=xobj.item(0);
				if(xsel.tagName=="TABLE"){
					tableflag=true;
				}else{
					while(xsel.tagName!="BODY"&&tableflag==false){
						if(xsel.tagName=="TABLE"){tableflag=true;}
						if(tableflag==false){xsel=xsel.parentElement;}
					}
				}
			}
			if(tableflag==true){
				xsel.removeAttribute("className","",0);
				xsel.removeAttribute("style","",0);
				var ccp=parseInt(xsel.border)+1;
				xsel.border=ccp;ccp=parseInt(xsel.border)-1;
				xsel.border=ccp;
			}
		}else{
		}
	}
}

function addimage(){
	if(imageisinserted==0){
		var insertimagetext="";
		insertimagetext='<IMG SRC="';
		insertimagetext+=imageurl;
		insertimagetext+='"';
		if(imagespecifysize=="yes"){
			insertimagetext+=' WIDTH="'+imagewidth+'"';
			insertimagetext+=' HEIGHT="'+imageheight+'"';
		}
		if(imagebordersize==""||imagebordersize=="0"){
			insertimagetext+=' BORDER="0"';
		}else{
			insertimagetext+=' BORDER="'+imagebordersize+'"';
		}
		if(imagealignment!="Default"){
			insertimagetext+=' ALIGN="'+imagealignment+'"';
		}
		if(imagehspacing==""||imagehspacing=="0"){
			insertimagetext+='';
		}else{
			insertimagetext+=' HSPACE="'+imagehspacing+'"';
		}
		if(imagevspacing==""||imagevspacing=="0"){
			insertimagetext+='';
		}else{
			insertimagetext+=' VSPACE="'+imagevspacing+'"';
		}
		insertimagetext+='>';
		var xman=frames ['LatticeEditDocument'].document.selection.createRange();
		var yman=frames ['LatticeEditDocument'].document.selection;
		var w=""+yman.type;
		var z=w.toUpperCase();
		if(z!="CONTROL"){
			xman.pasteHTML(insertimagetext);
		}else{
			yman.clear();
			xman=frames ['LatticeEditDocument'].document.selection.createRange();
			xman.pasteHTML(insertimagetext);
		}
		imageisinserted=1;
	}
}

function changebutton(btn,state){
	var currentstate=eval("state_"+btn);
	if(currentstate!=1){
		if((state==2&&currentstate==3)||(state==0&&currentstate==3)){
			if((btn=="btn_find"||btn=="btn_fontcolor"||btn=="btn_fonthilight")&&(eval("state_"+btn)!=2)){
				if(state=="0"){
					if(currentstate!=0){on(btn);}
				}
				if(state=="1"){
					if(currentstate!=1){off(btn);}
				}
				if(state=="2"){
					if(currentstate!=2){over(btn);}
				}
				if(state=="3"){
					if(currentstate!=3){down(btn);}
				}
				eval("state_"+btn+" = "+state);
			}
			var m=0;
		}else{
			if(state=="0"){
				if(currentstate!=0){on(btn);}
			}
			if(state=="1"){
				if(currentstate!=1){off(btn);}
			}
			if(state=="2"){
				if(currentstate!=2){over(btn);}
			}
			if(state=="3"){
				if(currentstate!=3){down(btn);}
			}
			eval("state_"+btn+" = "+state);
		}
	}
}

function btncommand(btn){
	islattice="lok";
	if(islattice=="lok"){
		if(btn=="btn_bold"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("Bold")==true){
				document.frames("LatticeEditDocument").document.execCommand("Bold",false);
			}
		}
		if(btn=="btn_italics"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("Italic")==true){
				document.frames("LatticeEditDocument").document.execCommand("Italic",false);
			}
		}
		if(btn=="btn_underline"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("Underline")==true){
				document.frames("LatticeEditDocument").document.execCommand("Underline",false);
			}
		}
		if(btn=="btn_left"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("JustifyLeft")==true){document.frames("LatticeEditDocument").document.execCommand("JustifyLeft",false);}
		}
		if(btn=="btn_center"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("JustifyCenter")==true){document.frames("LatticeEditDocument").document.execCommand("JustifyCenter",false);}
		}
		if(btn=="btn_right"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("JustifyRight")==true){document.frames("LatticeEditDocument").document.execCommand("JustifyRight",false);}
		}
		if(btn=="btn_numlist"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("InsertOrderedList")==true){
				if(state_numlist!=3){
					document.frames("LatticeEditDocument").document.execCommand("InsertOrderedList",false);
					state_numlist=3;
					changebutton("btn_numlist",3);
				}else{
					document.frames("LatticeEditDocument").document.execCommand("InsertOrderedList",false);
					state_numlist=0;
					changebutton("btn_numlist",0);
				}
			}
		}
		if(btn=="btn_bltlist"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("InsertUnorderedList")==true){
				if(state_numlist!=3){
					document.frames("LatticeEditDocument").document.execCommand("InsertUnorderedList",false);
					state_bltlist=3;
					changebutton("btn_bltlist",3);
				}else{
					document.frames("LatticeEditDocument").document.execCommand("InsertUnorderedList",false);
					state_bltlist=0;
					changebutton("btn_bltlist",0);
				}
			}
		}
		if(btn=="btn_outdent"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("Outdent")==true){
				document.frames("LatticeEditDocument").document.execCommand("Outdent",false);
			}
			state_btn_outdent=5;
			changebutton("btn_outdent",0);
		}
		if(btn=="btn_indent"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("Indent")==true){
				document.frames("LatticeEditDocument").document.execCommand("Indent",false);
				state_btn_indent=5;changebutton("btn_indent",0);
			}
		}
		if(btn=="btn_cut"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("Cut")==true){
				document.frames("LatticeEditDocument").document.execCommand("Cut",false);
				state_btn_cut=0;
				changebutton("btn_cut",0);
			}
		}
		if(btn=="btn_copy"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("Copy")==true){
				document.frames("LatticeEditDocument").document.execCommand("Copy",false);
				state_btn_copy=0;
				changebutton("btn_copy",0);
			}
		}
		if(btn=="btn_paste"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("Paste")==true){
				document.frames("LatticeEditDocument").document.execCommand("Paste",false);
				state_btn_paste=0;
				changebutton("btn_paste",0);
			}
		}
		if(btn=="btn_undo"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("Undo")==true){
				document.frames("LatticeEditDocument").focus();
				document.frames("LatticeEditDocument").document.execCommand("Undo",false);
				state_btn_undo=0;changebutton("btn_undo",0);
			}
		}
		if(btn=="btn_redo"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("Redo")==true){
				document.frames("LatticeEditDocument").document.execCommand("Redo",false);
				state_btn_redo=0;
				changebutton("btn_redo",0);
			}
		}
		if(btn=="btn_find"){
			if(find_status!=1){
				find_status=1;
				state_btn_find=5;
				changebutton("btn_find",0);
				window.showModelessDialog("../latticeeditor/find.htm",window,"dialogHeight: 125px; dialogWidth: 420px; help: no;scroll: no; status: no");
			}else{
				state_btn_find=5;
				changebutton("btn_find",0);
			}
		}
		if(btn=="btn_table"){
			if(table_status!=1){
				table_status=1;
				state_btn_table=5;
				changebutton("btn_table",0);
				tablemoondowneropen=1;
				window.showModalDialog("../latticeeditor/inserttable.htm",window,"dialogHeight: 400px; dialogWidth: 420px; help: no;scroll: no; status: no");
				if(tableiscancel=="no"){
					var inserttabletext='<TABLE BORDER="';
					var temptablestyle="";
					var tempcellstyle="";
					if(tableclass!=""){temptablestyle=' class="'+tableclass+'"';}
					if(tablecellclass!=""){tempcellstyle=' class="'+tablecellclass+'"';}
					inserttabletext+=(parseInt(tablebordersize)+1);
					inserttabletext+='"';
					if(tablewidthspecified=="yes"){
						inserttabletext+=' WIDTH="';
						inserttabletext+=tablewidth;
						if(tablewidthtype=="percentage"){
							inserttabletext+='%';
						}
						inserttabletext+='"';
					}
					inserttabletext+=temptablestyle;
					if(tablebordercolor!="Default"){inserttabletext+=' BORDERCOLOR="'+tablebordercolor+'"';}
					if(tablebackgroundcolor!="Default"){inserttabletext+=' BGCOLOR="'+tablebackgroundcolor+'"';}
					if(tablealign!="Default"){inserttabletext+=' ALIGN="'+tablealign+'"';}
					inserttabletext+=' CELLPADDING="'+tablecellpadding+'"';
					inserttabletext+=' CELLSPACING="'+tablecellspacing+'"';
					inserttabletext+='>\n';
					var tempcellwidth=""+parseInt(100/tablecolumns)+"%";
					var temprowtext="<TR>";
					for(var i=1;i<=tablecolumns;i++){temprowtext+='<TD WIDTH="'+tempcellwidth+'"'+tempcellstyle+'></TD>';}
					temprowtext+="</TR>\n";
					for(var j=1;j<=tablerows;j++){inserttabletext+=temprowtext;}
					inserttabletext+='</TABLE>';
					var xman=frames ['LatticeEditDocument'].document.selection.createRange();
					xman.pasteHTML(inserttabletext);
				}
			}else{
				state_btn_table=5;
				changebutton("btn_table",0);
			}
		}
		if(btn=="btn_image"){
			if(image_status!=1){
				image_status=1;
				state_btn_image=5;
				changebutton("btn_image",0);
				imagedialogopen=1;
				window.showModalDialog("../latticeeditor/insertimage.htm",window,"dialogHeight: 420px; dialogWidth: 460px; help: no;scroll: no; status: no");
				if((imageiscancel=="no")&&(imageurl!="Default")&&(imageurl!="")){
					imageisinserted=0;
					frames ['LatticeEditDocument'].document.testimage=new Object();
					frames ['LatticeEditDocument'].document.testimage.ImageCache=new Array();
					frames ['LatticeEditDocument'].document.testimage.ImageCache[0]=new Image();
					frames ['LatticeEditDocument'].document.testimage.ImageCache[0].onload=addimage;
					frames ['LatticeEditDocument'].document.testimage.ImageCache[0].src=imageurl;
				}
			}else{
				state_btn_image=5;changebutton("btn_image",0);
			}
		}
		if(btn=="btn_hyperlink"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("CreateLink")==true){
				setlink();
				state_btn_hyperlink=5;
				changebutton("btn_hyperlink",0);
			}else{
				state_btn_hyperlink=5;
				changebutton("btn_hyperlink",0);
			}
		}
		if(btn=="btn_unlink"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("Unlink")==true){
				document.frames("LatticeEditDocument").document.execCommand("Unlink");
				state_btn_unlink=5;
				changebutton("btn_unlink",0);
			}else{
				state_btn_unlink=5;
				changebutton("btn_unlink",0);
			}
		}
		if(btn=="btn_hr"){
			if(document.frames("LatticeEditDocument").document.queryCommandEnabled("InsertHorizontalRule")==true){
				document.frames("LatticeEditDocument").document.execCommand("InsertHorizontalRule");
				state_btn_hr=5;
				changebutton("btn_hr",0);
			}else{
				state_btn_hr=5;
				changebutton("btn_hr",0);
			}
		}if(btn=="btn_html"){
			if(html_status!=1){
				html_status=1;
				state_btn_html=5;
				changebutton("btn_html",0);
				htmlmoondowneropen=1;
				originalwysiwyg=document.frames("LatticeEditDocument").document.body.innerHTML;
				locationhere=""+parent.location.href;
				window.showModalDialog("../latticeeditor/edithtml.htm",window,"dialogHeight: 440px; dialogWidth: 630px; help: no;scroll: no; status: no");
				if(htmliscancel=="no"){
					document.frames("LatticeEditDocument").document.body.innerHTML=originalwysiwyg;
				}
			}else{
				state_btn_table=5;changebutton("btn_table",0);
			}
		}
		if(btn=="btn_special"){
			if(specialchar_status!=1){
				specialchar_status=1;
				state_btn_special=5;
				changebutton("btn_special",0);
				specialcharmoondowneropen=1;
				window.showModalDialog("../latticeeditor/specialchar.htm",window,"dialogHeight: 200px; dialogWidth: 300px; help: no;scroll: no; status: no");
				if(specialchariscancel=="no"){
					var xman=frames ['LatticeEditDocument'].document.selection.createRange();
					xman.pasteHTML(chartoinsert);
				}
			}else{
				state_btn_special=5;
				changebutton("btn_special",0);
			}
		}
		if(btn=="btn_about"){
			if(about_status!=1){
				about_status=1;
				state_btn_about=5;
				changebutton("btn_about",0);
				window.showModalDialog("../latticeeditor/about.htm",window,"dialogHeight: 300px; dialogWidth: 410px; help: no;scroll: no; status: no");
			}else{
				state_btn_about=5;
				changebutton("btn_about",0);
			}
		}

		if(btn=="btn_save"){
			if(0!=1){
				state_btn_save=5;
				changebutton("btn_save",0);
				document.frames("LatticeEditDocument").document.execCommand('SaveAs',true);
				//eval("window.parent."+SaveFunction);
			}else{
				state_btn_save=5;
				changebutton("btn_save",0);
			}
		}
		
		if(btn=="FormatSelect"){
			if(document.getElementById("FormatSelect")){
				var x=window.LatticeEditorForm.FormatSelect.selectedIndex;
				var y=window.LatticeEditorForm.FormatSelect.options[x].value;
				if(x>0){
					if(document.frames("LatticeEditDocument").document.queryCommandEnabled("FormatBlock")==true){
						document.frames("LatticeEditDocument").document.execCommand("FormatBlock",false,"Normal");
						document.frames("LatticeEditDocument").document.execCommand("FormatBlock",false,y);
						window.LatticeEditorForm.FormatSelect.options[0].value=y;
						window.LatticeEditorForm.FormatSelect.options[0].selected=true;
					}
				}
			}
		}
		if(btn=="FontNameSelect"){
			if(document.getElementById("FontNameSelect")){
				var x=window.LatticeEditorForm.FontNameSelect.selectedIndex;
				var y=window.LatticeEditorForm.FontNameSelect.options[x].value;
				if(x>0){
					if(document.frames("LatticeEditDocument").document.queryCommandEnabled("FontName")==true){
						document.frames("LatticeEditDocument").document.execCommand("FontName",false,y);
						window.LatticeEditorForm.FontNameSelect.options[0].value=y;
						window.LatticeEditorForm.FontNameSelect.options[0].selected=true;
					}
				}
			}
		}
		if(btn=="FontSizeSelect"){
			if(document.getElementById("FontSizeSelect")){
				var x=window.LatticeEditorForm.FontSizeSelect.selectedIndex;
				var y=window.LatticeEditorForm.FontSizeSelect.options[x].value;
				if(x>0){
					if(document.frames("LatticeEditDocument").document.queryCommandEnabled("FontSize")==true){
						document.frames("LatticeEditDocument").document.execCommand("FontSize",false,y);
						window.LatticeEditorForm.FontSizeSelect.options[0].value=y;
						window.LatticeEditorForm.FontSizeSelect.options[0].selected=true;
					}
				}
			}
		}
		
		if(btn=="btn_fontcolor"){
			
				col = websn_getTblCol();
  				if (col != "" && col != null) {
				document.frames("LatticeEditDocument").document.execCommand("ForeColor",false,col);
   				}
			
		}
		if(btn=="btn_fonthilight"){
			col = websn_getTblCol();
  				if (col != "" && col != null) {
				document.frames("LatticeEditDocument").document.execCommand("BackColor",false,col);
   				}
			}
		if((btn!="btn_find")&&(btn!="btn_fontcolor")&&(btn!="btn_fonthilight")){displayChanged();}
	}
}

function websn_getTblCol() {
 if (document.createAttribute) {
   var retCol = self.dlgColHelperTbl.ChooseColorDlg();
   retCol = retCol.toString(16);
   if (retCol.length < 6) {
     var tmp = "000000".substring(0,6-retCol.length);
     retCol = tmp.concat(retCol);
	 var c = 66;
   }
 }
 else {
  bascol = showModalDialog("../latticeeditor/colpick.html", "", "dialogWidth:350px; dialogHeight:370px; status:no; help:no");
  if (bascol != null) {
    retCol = bascol['col'];
  }
 }
 return retCol;
}

function itag(x){alert(x);}

function thisspot(){
	var devid=DeveloperID;
	var x=""+window.location.hostname;
	var y=x.length;
	var count=0;
	var total=0;
	var holder=0;
	var getdevid=parseInt(devid);
	if(y>0){
		for(count=0;count<=y-1;count++){
			holder=parseInt(x.charCodeAt(count));
			holder=holder+((holder-count)+(holder*count));
			total+=holder;
		}
		holder=total*getdevid*y;
		var xholder=holder*7;
		var yholder=xholder.toString();
		var zholder=holder.toString();
		var tempchar=zholder.charAt(3);
		if(tempchar=="0"){
			total=""+zholder+"9J7G3F"+yholder;
		}else if(tempchar=="1"){
			total=""+zholder+"Z37J8"+yholder;
		}else if(tempchar=="2"){
			total=""+zholder+"8VF6H92"+yholder;
		}else if(tempchar=="3"){
			total=""+zholder+"BN95T5S"+yholder;
		}else if(tempchar=="4"){
			total=""+zholder+"NF62CZ9P"+yholder;
		}else if(tempchar=="5"){
			total=""+zholder+"YW4Q7RB88K"+yholder;
		}else if(tempchar=="6"){
			total=""+zholder+"BS9JM52F"+yholder;
		}else if(tempchar=="7"){
			total=""+zholder+"63GE9U"+yholder;
		}else if(tempchar=="8"){
			total=""+zholder+"D7PWFBVCX"+yholder;
		}else{
			total=""+zholder+"2FV95HY6"+yholder;
		}
	}else{
	}
	return total;
}



function displayChanged(){
	var tempState;
	var tempSupported;
	if(document.getElementById("btn_bold")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("Bold");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("Bold");
		if(tempSupported==false){
			changebutton("btn_bold",1);
		}else{
			if(tempState==true){
				state_btn_bold=5;changebutton("btn_bold",3);
			}else{
				state_btn_bold=5;changebutton("btn_bold",0);
			}
		}
	}
	if(document.getElementById("btn_italics")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("Italic");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("Italic");
		if(tempSupported==false){
			changebutton("btn_italics",1);
		}else{
			if(tempState==true){
				state_btn_italics=5;changebutton("btn_italics",3);
			}else{
				state_btn_italics=5;changebutton("btn_italics",0);
			}
		}
	}
	if(document.getElementById("btn_underline")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("Underline");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("Underline");
		if(tempSupported==false){
			changebutton("btn_underline",1);
		}else{
			if(tempState==true){
				state_btn_underline=5;changebutton("btn_underline",3);
			}else{
				state_btn_underline=5;changebutton("btn_underline",0);
			}
		}
	}if(document.getElementById("btn_left")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("JustifyLeft");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("JustifyLeft");
		if(tempSupported==false){
			changebutton("btn_left",1);
		}else{
			if(tempState==true){
				state_btn_left=5;
				changebutton("btn_left",3);
			}else{
				state_btn_left=5;
				changebutton("btn_left",0);
			}
		}
	}
	if(document.getElementById("btn_center")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("JustifyCenter");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("JustifyCenter");
		if(tempSupported==false){
			changebutton("btn_center",1);
		}else{
			if(tempState==true){
				state_btn_center=5;
				changebutton("btn_center",3);
			}else{
				state_btn_center=5;changebutton("btn_center",0);
			}
		}
	}
	if(document.getElementById("btn_right")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("JustifyRight");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("JustifyRight");
		if(tempSupported==false){
			changebutton("btn_right",1);
		}else{
			if(tempState==true){
				state_btn_right=5;changebutton("btn_right",3);
			}else{
				state_btn_right=5;changebutton("btn_right",0);
			}
		}
	}
	if(document.getElementById("btn_bltlist")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("InsertUnorderedList");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("InsertUnorderedList");
		if(tempSupported==false){
			changebutton("btn_bltlist",1);
		}else{
			if(tempState==true){
				state_btn_bltlist=5;
				changebutton("btn_bltlist",3);
			}else{
				state_btn_bltlist=5;
				changebutton("btn_bltlist",0);
			}
		}
	}
	if(document.getElementById("btn_numlist")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("InsertOrderedList");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("InsertOrderedList");
		if(tempSupported==false){
			changebutton("btn_numlist",1);
		}else{
			if(tempState==true){
				state_btn_numlist=5;changebutton("btn_numlist",3);
			}else{
				state_btn_numlist=5;
				changebutton("btn_numlist",0);
			}
		}
	}
	if(document.getElementById("btn_cut")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("Cut");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("Cut");
		if(tempSupported==false){
			changebutton("btn_cut",1);
		}else{
			if(tempState==true){
				state_btn_cut=5;changebutton("btn_cut",3);
			}else{
				state_btn_cut=5;changebutton("btn_cut",0);
			}
		}
	}
	if(document.getElementById("btn_copy")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("Copy");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("Copy");
		if(tempSupported==false){
			changebutton("btn_copy",1);
		}else{
			if(tempState==true){
				state_btn_copy=5;
				changebutton("btn_copy",3);
			}else{
				state_btn_copy=5;
				changebutton("btn_copy",0);
			}
		}
	}
	if(document.getElementById("btn_paste")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("Paste");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("Paste");
		if(tempSupported==false){
			changebutton("btn_paste",1);
		}else{
			if(tempState==true){
				state_btn_paste=5;
				changebutton("btn_paste",3);
			}else{
				state_btn_paste=5;changebutton("btn_paste",0);
			}
		}
	}
	if(document.getElementById("btn_undo")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("Undo");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("Undo");
		if(tempSupported==false){
			changebutton("btn_undo",1);
		}else{
			if(tempState==true){
				state_btn_undo=5;
				changebutton("btn_undo",3);
			}else{
				state_btn_undo=5;
				changebutton("btn_undo",0);
			}
		}
	}
	if(document.getElementById("btn_redo")){
		tempSupported=document.frames("LatticeEditDocument").document.queryCommandEnabled("Redo");
		tempState=document.frames("LatticeEditDocument").document.queryCommandValue("Redo");
		if(tempSupported==false){
			changebutton("btn_redo",1);
		}else{
			if(tempState==true){
				state_btn_redo=5;
				changebutton("btn_redo",3);
			}else{
				state_btn_redo=5;changebutton("btn_redo",0);
			}
		}
	}
	if(document.getElementById("FormatSelect")){
		var tempformatvalue=document.frames("LatticeEditDocument").document.queryCommandValue("FormatBlock");
		if(tempformatvalue!=document.LatticeEditorForm.FormatSelect.options[0].text){
			document.LatticeEditorForm.FormatSelect.options[0].text=tempformatvalue;
			document.LatticeEditorForm.FormatSelect.options[0].selected=true;
		}
	}
	var temprange=document.frames("LatticeEditDocument").document.selection.createRange();
	var tempfontnamevalue=temprange.queryCommandValue("FontName");
	if(document.getElementById("FontNameSelect")){
		if(tempfontnamevalue!=document.LatticeEditorForm.FontNameSelect.options[0].text&&tempfontnamevalue!=null&&tempfontnamevalue!=""){
			document.LatticeEditorForm.FontNameSelect.options[0].text=tempfontnamevalue;
			document.LatticeEditorForm.FontNameSelect.options[0].selected=true;
		}
	}
	var tempfontsize=document.frames("LatticeEditDocument").document.queryCommandValue("FontSize");
	if(tempfontsize=="1"){tempfontsize="1 ( 8pt)";}
	if(tempfontsize=="2"){tempfontsize="1 (10pt)";}
	if(tempfontsize=="3"){tempfontsize="1 (12pt)";}
	if(tempfontsize=="4"){tempfontsize="1 (14pt)";}
	if(tempfontsize=="5"){tempfontsize="1 (18pt)";}
	if(tempfontsize=="6"){tempfontsize="1 (24pt)";}
	if(tempfontsize=="7"){tempfontsize="1 (36pt)";}
	if(document.getElementById("FontSizeSelect")){
		if(tempfontsize!=document.LatticeEditorForm.FontSizeSelect.options[0].text&&tempfontsize!=null&&tempfontsize!=""){
			document.LatticeEditorForm.FontSizeSelect.options[0].text=tempfontsize;
			document.LatticeEditorForm.FontSizeSelect.options[0].selected=true;
		}
	}
	document.frames("LatticeEditDocument").focus();
}

function disableme(){
	showcmenu(document.frames("LatticeEditDocument").event.screenX,document.frames("LatticeEditDocument").event.screenY);
	return false;
}

function displayChangedDelayedMore(){
	if(millisecondtimerflag==1){millisecondtimerflag=0;displayChanged();}
}

function displayChangedDelayed(){
	var xtime=new Date();
	var xmill=xtime.getTime();
	if((xmill-millisecondtimer)>200){
		displayChanged();
		millisecondtimer=xmill;
		millisecondtimerflag=0;
	}else{
		millisecondtimer=xmill;
		millisecondtimerflag=1;
		setTimeout("displayChangedDelayedMore()",205);
	}
}

function initEditor(){
	if(document.getElementById("line1")){document.getElementById("line1").style.width=LatticeWidth;}
	if(document.getElementById("line2")){document.getElementById("line2").style.width=LatticeWidth;}
	if(document.getElementById("line3")){document.getElementById("line3").style.width=LatticeWidth;}
	document.getElementById("LatticeEditDocument").style.height=LatticeHeight;
	document.getElementById("LatticeEditDocument").style.width=LatticeWidth;
	//document.frames("LatticeEditDocument").document.open();
	
	//document.frames("LatticeEditDocument").document.write(unescape(InitialHTML));
	document.frames("LatticeEditDocument").document.body.style.backgroundColor=BackgroundColor;
	document.frames("LatticeEditDocument").document.body.background=BackgroundImage;
	document.frames("LatticeEditDocument").document.designMode="On";
	document.frames("LatticeEditDocument").document.onkeydown=displayChangedDelayed;
	document.frames("LatticeEditDocument").document.onmouseup=displayChanged;
	document.frames("LatticeEditDocument").document.oncontextmenu=disableme;
	var gettables=document.frames ['LatticeEditDocument'].document.all.tags("TABLE");
	if(gettables.length>0){
		var tablecount=1;
		while(tablecount<=gettables.length){
			gettables[tablecount-1].border=parseInt(gettables[tablecount-1].border)+1;
			tablecount++;
		}
	}
	document.frames("LatticeEditDocument").document.execCommand("LiveResize","",1);
	document.frames("LatticeEditDocument").document.execCommand("2D-Position",true,true);
	if(document.getElementById("FontNameSelect")){
		var xfonts=FontSelection;
		if(xfonts!=""){
			if(xfonts.indexOf("|")>0){
				var fontarray=xfonts.split("|");
				for(var i=1;i<=fontarray.length;i++){
					if(fontarray[i-1].indexOf(";")>0){
						var tempsplit=fontarray[i-1].split(";");
						var fontoption=window.document.createElement("OPTION");
						window.document.LatticeEditorForm.FontNameSelect.options.add(fontoption);
						fontoption.innerText=tempsplit[0];
						fontoption.value=tempsplit[1];
					}else{
						var fontoption=window.document.createElement("OPTION");
						window.document.LatticeEditorForm.FontNameSelect.options.add(fontoption);
						fontoption.innerText=fontarray[i-1];
						fontoption.value=fontarray[i-1];
					}
				}
			}else{
				if(xfonts.indexOf(";")>0){
					var tempsplit=xfonts.split(";");
					var fontoption=window.document.createElement("OPTION");
					window.document.LatticeEditorForm.FontNameSelect.options.add(fontoption);
					fontoption.innerText=tempsplit[0];
					fontoption.value=tempsplit[1];
				}else{
					var fontoption=window.document.createElement("OPTION");
					window.document.LatticeEditorForm.FontNameSelect.options.add(fontoption);
					fontoption.innerText=xfonts;
					fontoption.value=xfonts;
				}
			}
		}
	}
	if(document.getElementById("FormatSelect")){original_formatselect=document.LatticeEditorForm.FormatSelect.options[0].text;}
	document.frames("LatticeTemp").document.open();
	document.frames("LatticeTemp").document.write("<P>&nbsp;</P>");
	document.frames("LatticeTemp").document.designMode="On";
	document.frames("LatticeTemp").document.oncontextmenu=disableme;
	document.frames("LatticeTemp").document.execCommand("LiveResize","",1);
	document.frames("LatticeTemp").document.execCommand("2D-Position",true,true);
	document.frames("LatticeTemp").document.execCommand("MultipleSelection","",true);
	var hanger=0;
	//hidebuttons();
	hiderows();
	initfinished=1;
	document.frames("LatticeEditDocument").focus();
	
}

function setStyle(){
	if(StyleSheetURL!=""&&stylesheetloaded==0){
		stylesheetloaded=1;
		document.frames("LatticeEditDocument").document.createStyleSheet(StyleSheetURL);
	}
}
