if(typeof(Array.prototype.push)!="function"){
	Array.prototype.push=function(){
		for(var i=0;i<arguments.length;i++){
			this[this.length]=arguments[i];
		}
	}
}
if(typeof(Array.prototype.pop)!="function"){
	Array.prototype.pop=function(){
		if(this.length<=0) return;
		var v=this[this.length-1];
		this.length--;
		return(v);
	}
}
if(typeof(Array.prototype.shift)!="function"){
	Array.prototype.shift=function(){
		var v=this[0];
		for(var i=1;i<this.length;i++){
			this[i-1]=this[i];
		}
		this.length=this.length-1;
		return(v);
	}
}
if(typeof(Array.prototype.unshift)!="function"){
	Array.prototype.unshift=function(){
		var ln=this.length;
		this.length=this.length+arguments.length;
		for(var i=ln-1;i>=0;i--){
			this[i+arguments.length]=this[i];
		}
		for(var i=0;i<arguments.length;i++){
			this[i]=arguments[i];
		}
		return(this);
	}
}
if(typeof(Array.prototype.splice)!="function"){
	Array.prototype.splice=function(){
		var s=arguments[0], dc=arguments[1], ic=arguments.length-2, da=new Array();
		if(ic<dc){
			for(var i=s;i<s+dc;i++){da.push(this[i]);}
			for(var i=s, j=2;j<arguments.length;i++, j++){this[i]=arguments[j];}
			for(var i=s+dc;i<this.length;i++){this[i-(dc-ic)]=this[i];}
			this.length-=(dc-ic);
		}else if(ic>dc){
			for(var i=s;i<s+dc;i++){da.push(this[i]);}
			for(var i=this.length-1;i>=s+dc;i--){this[i+(ic-dc)]=this[i];}
			for(var i=s, j=2;j<arguments.length;i++, j++){this[i]=arguments[j];}
		}else if(ic==dc){
			for(var i=s, j=2;i<s+dc;i++, j++){da.push(this[i]);this[i]=arguments[j];}
		}
		return(da);
	}
}
function Button_onMouseOver(){
	var o=event.srcElement;
	while(o.className!="btn_tedge"&&o.parentElement!=null){
		o=o.parentElement;
	}
	o.runtimeStyle.backgroundColor="#D1E249";
}
function Button_onMouseOut(){
	var o=event.srcElement;
	while(o.className!="btn_tedge"&&o.parentElement!=null){
		o=o.parentElement;
	}
	o.runtimeStyle.backgroundColor="";
}
function gotoPage(s){
	window.location.href=s;
}
var icoProcessOn=new Image(); icoProcessOn.src="/admin/_images/icoProcessOn.gif";
var icoProcessOff=new Image(); icoProcessOff.src="/admin/_images/icoProcessOff.gif";
function swapImages(){
	for(var i=0;i<arguments.length;i+=2){
		document.images[arguments[i]].src=arguments[i+1].src;
	}
}
var icoHelpOn=new Image(); icoHelpOn.src="_images/help_on.gif";
var icoHelpOff=new Image(); icoHelpOff.src="_images/help_off.gif";
var helpWin;
var bHelpMoved=false;
function HelpIcon_onClick(iHelpID){
	var h=300, w=300;
	var t=(event.screenY>screen.availHeight-h-30)?screen.availHeight-h-30:event.screenY+5;
	var l=(event.screenX>screen.availWidth-w-20)?screen.availWidth-w-20:event.screenX+5;
	helpWin=window.open("help.asp?id="+iHelpID, "helpWin", "width="+w+",height="+h+",top="+t+",left="+l+",scrollbars,resizable");
	helpWin.onmove=helpWin_onMove;
	if(!bHelpMoved) helpWin.moveTo(l,t);
	helpWin.focus();
}
function helpWin_onMove(){}
function getObject(sID){
	if(document.getElementById){
		return(document.getElementById(sID));
	}else{
		return(document.all[sID]);
	}
}
function DateFormControl_chooseDate(o){
	var v=window.showModalDialog("dialog/calendar.asp", o.value, "dialogHeight=220px; dialogWidth=180px; dialogTop="+event.screenY+"; dialogLeft="+event.screenX+"; help=no; resizable=no; scroll=no; status=yes");
	if(v!=null)	o.value=v;
}
function FileFormControl_setFile(sName, sValue, sHref){
	var oPrev=getObject(sName+"_prev");
	oPrev.firstChild.href=(sHref||sValue);
	oPrev.firstChild.innerText=sValue;
	var oSuppl=getObject(sName+"_suppl");
	oSuppl.style.display="inline";
	var oOldVal=getObject("old_"+sName);
	oOldVal.value=sValue;
	FileFormControl_showPrev(sName, true);
}
function FileFormControl_showPrev(sName, bShow){
	var oFile=getObject(sName+"_file");
	var oPrev=getObject(sName+"_prev");
	if(bShow){
		oFile.style.display="none";
		oPrev.style.display="inline";
	}else{
		oFile.style.display="inline";
		oPrev.style.display="none";
	}
}

var oRichTextFormControl=new Object();
function RichTextFormControl_init(sName, sFileDir){
	var oDiv=getObject("dv_"+sName);
	if(oDiv!=null){
		var o=new Object();
		o.viewingSource=false;
		o.div=oDiv;
		o.undo=new Array(oDiv.innerHTML);
		o.fileDir=(sFileDir==null)?"":sFileDir.toLowerCase();
		oRichTextFormControl[sName]=o;
		document.body.attachEvent("onmousedown", RichTextFormControl_recordInsertionPoint);
	}
}
var oInsertionPoint;
function RichTextFormControl_recordInsertionPoint(){
	oInsertionPoint=document.selection.createRange();
}
function RichTextFormControl_viewHTML(sName){
	var oDiv=getObject("dv_"+sName);
	var oTxt=getObject(sName);
	var oLink=event.srcElement;
	if(oDiv.style.display=="none"){
		oRichTextFormControl[sName].viewingSource=false;
		oDiv.innerHTML=oTxt.value;
		oDiv.style.display="block";
		oTxt.style.display="none";
		oDiv.focus();
		oLink.alt="Show HTML Source";
	}else{
		oRichTextFormControl[sName].viewingSource=true;
		oTxt.value=oDiv.innerHTML;
		oDiv.style.display="none";
		oTxt.style.display="block";
		oTxt.focus();
		oLink.alt="Hide HTML Source";
	}
}
function RichTextFormControl_exec(sName, sCommand){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null&&!oCtrl.viewingSource){
		RichTextFormControl_do(sName);
		oCtrl.div.focus();
		oCtrl.div.document.execCommand(sCommand, false, null);
		
		
			/*p = oCtrl.div.document.selection.createRange().parentElement();
			noEndless = 100;
			while(p.tageName!="UL" && noEndless > 0)
			{
				p=p.parentElement();
				noEndless--;
			}
			if(p.tagName == "UL")
			{
				p.className='navigation';
			}*/

			//oCtrl.div.document.selection.createRange().parentElement().setAttribute('class','navigation');
	       	//oCtrl.div.document.selection.createRange().parentElement().className='navigation';

		
	}
}

var sRichTextFormControl_anchorList="";
function RichTextFormControl_showAnchorList(sName){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null&&!oCtrl.viewingSource){
		sRichTextFormControl_anchorList="anchorList_"+sName;
		var aAnchors=RichTextFormControl_anchorArray(sName)
		var sAnchors="";
		if(aAnchors!=null){
			for (var i=0;i<aAnchors.length;i++){
				sAnchors+="<a href=\"javascript:void(0);\" onClick=\"RichTextFormControl_removeAnchor('"+sName+"','"+aAnchors[i]+"')\">"+aAnchors[i]+"</a><br/>";
			}
		}else{
			sAnchors="There are no anchors on this page.";
		}
		var o=getObject(sRichTextFormControl_anchorList);
		if(o!=null){
			o.innerHTML=sAnchors;
			o.style.display="block";
		}
		setTimeout("document.attachEvent(\"onclick\", RichTextFormControl_hideAnchorList);", 500);
	}
}

function RichTextFormControl_hideAnchorList(sName){
	if(typeof(sName=="object")){
		// called from attached event
		var o=getObject(sRichTextFormControl_anchorList);
	}else{
		// called from script
		var o=getObject("anchorList_"+sName);
	}
	if(o!=null) o.style.display="none";
	document.detachEvent("onclick", RichTextFormControl_hideAnchorList);
}

function RichTextFormControl_removeAnchor(sName, sAnchor){
	var oDiv=getObject("dv_"+sName);
	var contentHTML=oDiv.innerHTML;
	var re=new RegExp("<A name="+sAnchor+"></A>","g");
	oDiv.innerHTML=contentHTML.replace(re,"");
	RichTextFormControl_hideAnchorList(sName);
}


var sRichTextFormControl_currentPalette="";
function RichTextFormControl_showColorPalette(sName, sCommand){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null&&!oCtrl.viewingSource){
		sRichTextFormControl_currentPalette="colorPalette_"+sName+"_"+sCommand;
		var o=getObject(sRichTextFormControl_currentPalette);
		if(o!=null) o.style.display="block";
		setTimeout("document.attachEvent(\"onclick\", RichTextFormControl_hideColorPalette);", 500);
	}
}
function RichTextFormControl_hideColorPalette(sName, sCommand){
	if(typeof(sName=="object")){
		// called from attached event
		var o=getObject(sRichTextFormControl_currentPalette);
	}else{
		// called from script
		var o=getObject("colorPalette_"+sName+"_"+sCommand);
	}
	if(o!=null) o.style.display="none";
	document.detachEvent("onclick", RichTextFormControl_hideColorPalette);
}

function RichTextFormControl_setColor(sName, sCommand, sColor){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null&&!oCtrl.viewingSource){
		RichTextFormControl_do(sName);
		oCtrl.div.focus();
		oCtrl.div.document.execCommand(sCommand, false, sColor);
	}
	RichTextFormControl_hideColorPalette(sName, sCommand)
}




function RichTextFormControl_anchor(sName){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null&&!oCtrl.viewingSource){
		RichTextFormControl_do(sName);
		oCtrl.div.focus();
		var oSel=document.selection;
		var oRng=oSel.createRange();
		var sAnchorName=oRng.text;
		sAnchorName=sAnchorName.replace(/\W/gi,"");
		oRng.collapse();
		sAnchorName=window.showModalDialog("dialog/anchor.asp", sAnchorName, "dialogHeight:250px;dialogWidth:475px;help:no;resizable:no;scroll:no;status:no");
		if (sAnchorName!=null&&sAnchorName!=""){
			oRng.pasteHTML("<a name=\""+sAnchorName+"\"></a>")
		}
	}
}
function RichTextFormControl_link(sName, sType, sCountryID, sProductID){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null&&!oCtrl.viewingSource){
		RichTextFormControl_do(sName);
		oCtrl.div.focus();
		var oSel=document.selection;
		var oRng=oSel.createRange();
		if(oSel.type=="None"||oSel.type=="Text"){
			if(oRng.text==""){
				oRng.expand("word");
				// expand to word includes trailing spaces
				while(oRng.text.length>0&&oRng.text.charAt(oRng.text.length-1)==" "){
					oRng.moveEnd("character", -1);
				}
				oRng.select();
			}
			if(oRng.text==""){
				alert("Select some text to make into a link.");
				return(false);
			}
			var oLink=oRng.parentElement();
		}else if(oSel.type=="Control"){
			var oLink=oRng(0).parentElement;
		}
		if(oLink.tagName=="A"){
			if(oSel.type=="Text"&&oLink.innerText!=oRng.text){
				// select the entire text of the link
				oRng.expand("sentence");
				oRng.findText(oLink.innerText);
				oRng.select();
			}
			var sHref=oLink.href;
			var sTarget=oLink.target;
			if(sHref!=null){
				if(sHref.toLowerCase().indexOf("mailto:")==0){
					sType="mail";
					sHref=sHref.replace(/^mailto:/gi, "");
				}
				if(oCtrl.fileDir!=""&&sHref.toLowerCase().indexOf(oCtrl.fileDir)>-1){
					// this link is for an attached file
					RichTextFormControl_file(sName);
					return;
				}
				if(sHref.toLowerCase().indexOf(oCtrl.fileDir.replace(/\/[a-zA-Z0-9]+\/$/,""))>-1&&sHref.toLowerCase().indexOf("#")>-1){
					sType="anchor";
				}
			}
		}else{
			oLink=null;
			var sHref=null;
			var sTarget=null;
		}

		var aAnchor=RichTextFormControl_anchorArray(sName);
		if(sType=="anchor") {
			if(aAnchor==null){
				alert("There currently are no anchors on this page.\n Please add an anchor first.");
				return false;
			}
		}
		var a=window.showModalDialog("dialog/link.asp?c="+sCountryID+"&p="+sProductID, [sHref, sType, sTarget, aAnchor], "dialogHeight:275px;dialogWidth:475px;help:no;resizable:no;scroll:no;status:yes");

		if(a!=null){
			sHref=a[0];
			sTarget=a[1];
			sNewType=a[2];
			if(sHref==""){
				oCtrl.div.document.execCommand("Unlink");
			}else{
				if(sNewType=="anchor"&&sHref.indexOf("#")!=0) {
					sHref="#"+sHref;
				}
				if(sNewType=="mail"&&sHref.indexOf("mailto:")!=0) sHref="mailto:"+sHref;
				if(oLink!=null){
					oLink.href=sHref;
					oLink.target=sTarget;
				}else{
					var sLink="<a href=\""+sHref+"\"";
					if(sNewType!="mail"&&sNewType!="anchor"&&sTarget!=null&&sTarget!="") sLink+=" target=\""+sTarget+"\"";
					sLink+=">";
					// alert(oSel.type);
					if(oSel.type=="Control"){
						oCtrl.div.document.execCommand("CreateLink", false, sHref);
						if(sTarget!=null&&sTarget!="") oRng(0).parentElement.target=sTarget;
						// oRng(0).insertAdjacentHTML("afterEnd", "</a>");
						// oRng(0).insertAdjacentHTML("beforeBegin", sLink);
					}else{
						oRng.pasteHTML(sLink+oRng.text+"</a>");
					}
				}
				// oCtrl.div.document.execCommand("CreateLink", false, sHref);
			}
		}
	}
}

function RichTextFormControl_anchorArray(sName){
	var oDiv=getObject("dv_"+sName);
	var sContent=oDiv.innerHTML;
	var re=new RegExp("<A name=([^>]+)>","g");
	var aAnchors=sContent.match(re);
	if(aAnchors!=null){
		for(var i=0;i<aAnchors.length;i++){
			aAnchors[i]=aAnchors[i].replace(re, "$1");
		}
	}
	return(aAnchors);
}
function RichTextFormControl_file(sName){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null&&!oCtrl.viewingSource){
		RichTextFormControl_do(sName);
		oCtrl.div.focus();
		var oFile={href:"", linkText:""};

		var oSel=document.selection;
		var oRng=oSel.createRange();
		if(oSel.type=="None"||oSel.type=="Text"){
			var oLink=oRng.parentElement();
			if(oLink.tagName=="A"){
				oFile.href=oLink.href;
				oFile.linkText=oLink.innerText;
			}else{
				oLink=null;
			}
		}
		oFile=window.showModalDialog("dialog/file.asp", oFile, "dialogHeight:275px;dialogWidth:475px;help:no;resizable:no;scroll:no;status:yes");
		if(oFile!=null){
			if(oLink!=null){
				oLink.href=oFile.href;
				oLink.innerText=oFile.linkText;
			}else{
				var sFile="<a href=\""+oFile.href+"\" target=\"_blank\">"+oFile.linkText+"</a>";
				if(document.selection.type=="None"){
					// need to see if the current insertion point is contained within the control
					var o=oInsertionPoint.parentElement();
					var bMatched=false;
					while(o.tagName!="BODY"){
						if(o==oCtrl.div){
							bMatched=true;
							break;
						}
						o=o.parentElement;
					}
					if(bMatched){
						// insert text at insertion point
						oInsertionPoint.pasteHTML(sFile);
					}else{
						// insert text at end of control
						oCtrl.div.insertAdjacentHTML("beforeEnd", sFile);
					}
				}else{
					var oRng=docuemnt.selection.createRange();
					oRng.pasteHTML(sFile);
				}
			}
		}
	}
}
function RichTextFormControl_image(sName){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null&&!oCtrl.viewingSource){
		RichTextFormControl_do(sName);
		oCtrl.div.focus();
		var oImg={src:"", alt:"", align:""};
		if(document.selection.type=="Control"){
			var oRng=document.selection.createRange();
			if(oRng(0).tagName=="IMG") oImg={src:oRng(0).src, alt:oRng(0).alt, align:oRng(0).align};
		}
		oImg=window.showModalDialog("dialog/image.asp", oImg, "dialogHeight:275px;dialogWidth:475px;help:no;resizable:no;scroll:no;status:yes");
		if(oImg!=null){
			if(document.selection.type=="None"){
				var sImg="<img src=\""+oImg.src+"\"";
				if(oImg.alt!="") sImg+=" alt=\""+oImg.alt+"\"";
				if(oImg.align!="") {
					sImg+=" align=\""+oImg.align+"\"";
					if(oImg.align=="left") 
						sImg+=" style=\"margin-right: 10px;\"";
					else
						sImg+=" style=\"margin-left: 10px;\"";
				}
				sImg+=" border=\"0\">";
				// need to see if the current insertion point is contained within the control
				var o=oInsertionPoint.parentElement();
				var bMatched=false;
				while(o.tagName!="BODY"){
					if(o==oCtrl.div){
						bMatched=true;
						break;
					}
					o=o.parentElement;
				}
				if(bMatched){
					// insert text at insertion point
					setTimeout("oInsertionPoint.pasteHTML(\""+sImg.replace(/"/g, "\\\"")+"\");", 1);
				}else{
					// insert text at end of control
					setTimeout("oRichTextFormControl."+sName+".div.insertAdjacentHTML(\"beforeEnd\", \""+sImg.replace(/"/g, "\\\"")+"\");", 1);
				}
			}else if(document.selection.type=="Control"){
				var oRng=document.selection.createRange();
				if(oRng(0).tagName=="IMG"){
					oRng(0).src=oImg.src;
					oRng(0).align=oImg.align;
					oRng(0).alt=oImg.alt;
				}
			}else{
				var sImg="<img src=\""+oImg.src+"\"";
				if(oImg.alt!="") sImg+=" alt=\""+oImg.alt+"\"";
				if(oImg.align!="") sImg+=" align=\""+oImg.align+"\"";
				sImg+=" border=\"0\">";
				var oRng=document.selection.createRange();
				oRng.pasteHTML(sImg);
			}
		}
	}
}
function RichTextFormControl_do(sName){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null){
		if(oCtrl.undo.length>100) oCtrl.undo.pop();
		oCtrl.undo.unshift(oCtrl.div.innerHTML);
		RichTextFormControl_updateSource(sName);
	}
}
function RichTextFormControl_undo(sName){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null&&!oCtrl.viewingSource){
		if(oCtrl.undo==null||oCtrl.undo.length==0) return(false);
		if(oCtrl.undo.length==1){
			oCtrl.div.innerHTML=oCtrl.undo[0];
		}else{
			oCtrl.div.innerHTML=oCtrl.undo.shift();
		}
		RichTextFormControl_updateSource(sName);
	}
}
function RichTextFormControl_fontSize(sName,iSize,sType){
	var oCtrl=oRichTextFormControl[sName];
	if (sType=="absolute") {
		if (iSize!="") oCtrl.div.document.execCommand("FontSize", false, iSize);
		else oCtrl.div.document.execCommand("FontSize", false, null);
		var o=getObject("FontSize");
		o.selectedIndex=0;
	} else if(sType=="relative") {
		if (iSize!="") {
			if (oCtrl.div.document.queryCommandValue("FontSize")!=null) {
				oCtrl.div.document.execCommand("FontSize", false, oCtrl.div.document.queryCommandValue("FontSize")+iSize);
			} else {
				oCtrl.div.document.execCommand("FontSize", false, iSize);
			}
		} else {
			oCtrl.div.document.execCommand("FontSize", false, null);
		}
	}
}
function RichTextFormControl_updateSource(sName){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null){
		var oDiv=getObject("dv_"+sName);
		var oTxt=getObject(sName);
		if(oDiv!=null&&oTxt!=null){
			if(oCtrl.viewingSource){
				oDiv.innerHTML=oTxt.value;
			}else{
				oTxt.value=oDiv.innerHTML;
			}
		}
	}
}
function RichTextFormControl_onBeforePaste(sName){
	// alert(window.clipboardData.getData("Text"));
	event.returnValue=false;
}
function RichTextFormControl_onPaste(sName){
	var oCtrl=oRichTextFormControl[sName];
	if(oCtrl!=null){
		event.returnValue=false;
		var s=window.clipboardData.getData("Text").replace(/\r\n/g, "<br />");
		var oRng=document.selection.createRange();
		oRng.pasteHTML(s);
	}
}
function ListBuilder_add(fm, sName){
	var o=new Option();
	var sValue=String(fm["LB_"+sName+"_input"].value).trim();
	if(sValue=="") return(false);
	o.value=sValue;
	o.text=sValue;
	fm[sName].options[fm[sName].options.length]=o;
	fm["LB_"+sName+"_input"].value="";
}
function ListBuilder_rem(fm, sName){
	if(fm[sName].selectedIndex==-1) return(false);
	for(var i=0;i<fm[sName].options.length;i++){
	if(fm[sName].options[i].selected){
			fm[sName].options[i]=null;
			i--;
		}
	}
}
function ListBuilder_selectAll(fm, sName){
	for(var i=0;i<fm[sName].options.length;i++){
		fm[sName].options[i].selected=true;
	}
}
function init(){
	// empty function to be overloaded if body onLoad functionality is required
}
function input_onKeyPress(){
	if(event.keyCode==13)	submitForm(event.srcElement.form, event.srcElement.form.fn.value, true);
}
function initForms(){
	var b=false;
	for(var i=0;i<document.forms.length;i++){
		var o=document.forms[i];
		for(var j=0;j<o.elements.length;j++){
			var e=o.elements[j];
			if(!b){
				try{
					e.focus();
					b=true;
				}catch(e){
					b=false;
				}
			}
			if(e.type=="text"||e.type=="password"){
				if(typeof(e.attachEvent)=="object"){
					e.attachEvent("onkeypress", input_onKeyPress);
				}else if(typeof(e.addEventListener)=="function"){
					e.addEventListener("onkeypress", input_onKeyPress, true);
				}
			}
		}
	}
}

// **************************************************
// **   Start of Table Functions
// **
// ** Added 24/Jan/2005 Brad Miller
// **
// **************************************************

var borderShown = "yes";
var editor="";  // the name of the content div that is about to be edited

function isTableSelected() {
	if (document.selection.type == "Control") {
		var oRange = document.selection.createRange();
		if (oRange(0).tagName.toUpperCase() == "TABLE") {
			selectedTable = document.selection.createRange()(0);
			return true;
		}	
	}
}

function isCursorInTableCell(sName) {
	if (document.selection.type != "Control") {
		if (isAllowed(sName)) {
			var elem = document.selection.createRange().parentElement()
			while (elem.tagName.toUpperCase() != "TD" && elem.tagName.toUpperCase() != "TH") {
				if (elem == null)
					break;
				if (elem.tagName.toUpperCase()=="DIV")
					return false;
				elem = elem.parentElement
			}
			if (elem) {
				selectedTD = elem
				selectedTR = selectedTD.parentElement
				selectedTBODY =  selectedTR.parentElement
				selectedTable = selectedTBODY.parentElement
				return true
			}
		}
	}
}

function showInsertTableWin(sName) {
	if (isAllowed(sName)) {
		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-300) / 2 
			tableWin=window.open("dialog/table.asp?a=Insert&i=Table","", "width=500,height=230,scrollbars=no,resizable=no,titlebar=0,top="+topPos+",left="+leftPos);
	}
}

function showModifyTableWin(sName) {
	if (isAllowed(sName)) {
		if (isTableSelected() || isCursorInTableCell(sName)) {
			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-300) / 2 
 			tableWin = window.open("dialog/table.asp?a=Modify&i=Table","","width=500,height=210,scrollbars=no,resizable=no,titlebar=0,top="+topPos+",left="+leftPos);
		}
	}
}

function showModifyCellWin(sName) {
	if (isAllowed(sName)) {
		if (isCursorInTableCell(sName)) {
			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-300) / 2 
 			tableWin = window.open("dialog/table.asp?a=Modify&i=Cell","","width=500,height=210,scrollbars=no,resizable=no,titlebar=0,top="+topPos+",left="+leftPos);
		}
	}
}

function insertColAfter(sName) {
	if (isCursorInTableCell(sName)) {
		moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex)
		allRows = selectedTable.rows
		for (i=0;i<allRows.length;i++) {
			rowCount = allRows[i].cells.length - 1
			position = rowCount - moveFromEnd
			if (position < 0) {
				position = 0
			}
			newCell = allRows[i].insertCell(position+1)
			newCell.innerHTML = "&nbsp;"
			newCell.className = "content";
			if (borderShown == "yes") {
				newCell.runtimeStyle.border = "1px dotted #BFBFBF"
			}
		}
	}
}


function insertColBefore(sName) {
	if (isCursorInTableCell(sName)) {
		moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex)
		allRows = selectedTable.rows
		for (i=0;i<allRows.length;i++) {
			rowCount = allRows[i].cells.length - 1
			position = rowCount - moveFromEnd
			if (position < 0) {
				position = 0
			}
			newCell = allRows[i].insertCell(position)
			newCell.innerHTML = "&nbsp;"
			newCell.className = "content";
			if (borderShown == "yes") {
				newCell.runtimeStyle.border = "1px dotted #BFBFBF"
			}
		}
	}
}

function insertRowAbove(sName) {
	if (isCursorInTableCell(sName)) {
		var numCols = 0
		allCells = selectedTR.cells
		for (var i=0;i<allCells.length;i++) {
		 	numCols = numCols + allCells[i].getAttribute('colSpan')
		}
		var newTR = selectedTable.insertRow(selectedTR.rowIndex)
		for (i = 0; i < numCols; i++) {
		 	newTD = newTR.insertCell()
			newTD.innerHTML = "&nbsp;"
			newTD.className="content";
			if (borderShown == "yes") {
				newTD.runtimeStyle.border = "1px dotted #BFBFBF"
			}
		}
	}
}

function insertRowBelow(sName) {
	if (isCursorInTableCell(sName)) {
		var numCols = 0
		allCells = selectedTR.cells
		for (var i=0;i<allCells.length;i++) {
		 	numCols = numCols + allCells[i].getAttribute('colSpan')
		}
		var newTR = selectedTable.insertRow(selectedTR.rowIndex+1)
		for (i = 0; i < numCols; i++) {
		 	newTD = newTR.insertCell()
			newTD.innerHTML = "&nbsp;"
			newTD.className="content";
			if (borderShown == "yes") {
				newTD.runtimeStyle.border = "1px dotted #BFBFBF"
			}
		}
	}
}

function deleteRow(sName) {
	if (isCursorInTableCell(sName)) {
		selectedTable.deleteRow(selectedTR.rowIndex)
	}
}

function deleteCol(sName) {
	if (isCursorInTableCell(sName)) {
		moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex)
		allRows = selectedTable.rows
		for (var i=0;i<allRows.length;i++) {
			endOfRow = allRows[i].cells.length - 1
			position = endOfRow - moveFromEnd
			if (position < 0) {
				position = 0
			}
			allCellsInRow = allRows[i].cells
			if (allCellsInRow[position].colSpan > 1) {
				allCellsInRow[position].colSpan = allCellsInRow[position].colSpan - 1
			} else { 
				allRows[i].deleteCell(position)
			}
		}
	}
}

function increaseColspan(sName) {
	if (isCursorInTableCell(sName)) {
		var colSpanTD = selectedTD.getAttribute("colSpan")
		allCells = selectedTR.cells
		if (selectedTD.cellIndex + 1 != selectedTR.cells.length) {
			var addColspan = allCells[selectedTD.cellIndex+1].getAttribute("colSpan")
			selectedTD.colSpan = colSpanTD + addColspan
			selectedTR.deleteCell(selectedTD.cellIndex+1)
		}	
	}
}


function decreaseColspan(sName) {
	if (isCursorInTableCell(sName)) {
		if (selectedTD.colSpan != 1) {
			selectedTR.insertCell(selectedTD.cellIndex+1)
			selectedTD.colSpan = selectedTD.colSpan - 1	
		}
	}
}
var winPopup = window.createPopup();
function tableMenu(sName) {
   
	var lefter = event.clientX;
	var leftoff = event.offsetX
	var topper = event.clientY;
	var topoff = event.offsetY;
	var winPopBody = winPopup.document.body;
	moveMe = 0;
	
	if (isCursorInTableCell(sName) || isTableSelected()) {
		document.getElementById("modifyTable").disabled = false;
	} else {
		document.getElementById("modifyTable").disabled = true;
	}

	if (isCursorInTableCell(sName)) {
		document.getElementById("modifyCell").disabled = false;
		document.getElementById("rowAbove").disabled = false;
		document.getElementById("rowBelow").disabled = false;
		document.getElementById("deleteRow").disabled = false;
		document.getElementById("colAfter").disabled = false;
		document.getElementById("colBefore").disabled = false;
		document.getElementById("deleteCol").disabled = false;
		document.getElementById("increaseSpan").disabled = false;
		document.getElementById("decreaseSpan").disabled = false;
	} else {
		document.getElementById("modifyCell").disabled = true;
		document.getElementById("rowAbove").disabled = true;
		document.getElementById("rowBelow").disabled = true;
		document.getElementById("deleteRow").disabled = true;
		document.getElementById("colAfter").disabled = true;
		document.getElementById("colBefore").disabled = true;
		document.getElementById("deleteCol").disabled = true;
		document.getElementById("increaseSpan").disabled = true;
		document.getElementById("decreaseSpan").disabled = true;
	}

	var HTMLContent = document.getElementById("tableMenu").innerHTML;
	winPopBody.innerHTML = HTMLContent
	winPopup.show(lefter - leftoff - 2 - moveMe, topper - topoff + 22, 160, 262, document.body);

	return false;
}

function isAllowed(sName) {
	oRichTextFormControl[sName].div.focus()
	return true;
}

function contextHilite(menu) {
    menu.runtimeStyle.backgroundColor = "Highlight";
    if (menu.state) {
        menu.runtimeStyle.color = "GrayText";
    } else {
        menu.runtimeStyle.color = "HighlightText";
    }
}

function contextDelite(menu) {
    menu.runtimeStyle.backgroundColor = "";
    menu.runtimeStyle.color = "";
}
