// JavaScript Document
//returns true is the selected object is an image
function isImageSelected() {
  foo.focus()
  if (foo.document.selection.type == "Control") {
   var oControlRange = foo.document.selection.createRange();
   if (oControlRange(0).tagName.toUpperCase() == "IMG") {
    selectedImage = foo.document.selection.createRange()(0);
    return true;
   }	
  }
 }	
//Image Insertion OLD	
function sImgDlg(){
  res = showModalDialog('includes/tImage.php', null, 'dialogWidth: 330px; dialogHeight: 225px; center: yes; resizable: no; scroll: no; status: no;');
  if(res == 'lib')
   res = showModalDialog('lib/lib.php', null, 'dialogWidth: 770px; dialogHeight: 450px; center: yes; resizable: no; scroll: no; status: no;');
  if(res)
   return res;
 }
 
function sNewImg(){
  if(isImageSelected())
   temp = selectedImage;
  else
   temp = 0;
  
  res = sImgDlg();
  if(res){
   document.forms.imgUpl.nSel.outerHTML = '<select name=nSel>' + document.forms.imgUpl.nSel.innerHTML + '<option value=images/' + res.replace(/^.*\//ig, '') + '">' + res.replace(/^.*\//ig, '') + '</option></select>';
   uplTd.style.display = 'block';

   foo.focus();
   foo.document.execCommand("InsertImage", false, res);
  
   if(isImageSelected() && temp){
    selectedImage.style.position = temp.style.position;
    selectedImage.style.zIndex = temp.style.zIndex;
    selectedImage.style.top = temp.style.top;
    selectedImage.style.left = temp.style.left;
    selectedImage.style.borderColor = temp.style.borderColor;
    selectedImage.border = temp.border;
    selectedImage.style.alt = temp.alt;
    selectedImage.hspace = temp.hspace;
    selectedImage.vspace = temp.vspace;
    selectedImage.align = temp.align;
   }
  }
 }
 //end Image Insertion OLD
 
 //Table Insertion OLD
 function ShowInsertTable() {
try{
  sFakedObj = new Object();
  sFakedObj.cellPadding = 1;
  sFakedObj.cellSpacing = 2;
  res = showModalDialog('includes/tprop.php', sFakedObj, 'dialogWidth: 375px; dialogHeight: 260px; center: yes; resizable: no; scroll: no; status: no;');
  if(res){
   foo.focus();
   sParent = foo.document.selection.createRange().parentElement();
   sNewTable = foo.document.createElement('<table>');
   sParent.appendChild(sNewTable);

   HTMLTable = "<table" + (res.width ? ' width=' + res.width : '') + " border=" + res.border + " cellpadding=" + res.cellPadding + " cellspacing=" + res.cellSpacing + (res.bgColor ? ' bgcolor = ' + res.bgColor : '') + (res.background ? ' background=' + res.background : '') + ">";        
   for(i=0; i<res.rows; i++){
    HTMLTable = HTMLTable + "<tr>";
    for(j=0; j<res.columns; j++)
     HTMLTable = HTMLTable + "<td>&nbsp</td>"
    HTMLTable = HTMLTable + "</tr>"
   }       			
   HTMLTable = HTMLTable + "</table>"
   sNewTable.outerHTML = HTMLTable;

	try{
		if(borderShown){
			sNewTable.runtimeStyle.borderTop = sNewTable.runtimeStyle.borderLeft = "1px dotted #BFBFBF";
			allRows = sNewTable.rows;
			for(y=0; y < allRows.length; y++){
			 allCells = allRows[y].cells;
			 for(x=0; x < allCells.length; x++)
			   allCells[x].runtimeStyle.borderRight = allCells[x].runtimeStyle.borderBottom = "1px dotted #BFBFBF";
			}
	   }
	}catch(e){}
  }
  }catch(e)
  {
  }
 }
 
 function ChangeCellBg(){
    if(CheckcursorIsinTableCell()){
	       
				   var Callcolordialog = colordialog.ChooseColorDlg();
				   Callcolordialog = Callcolordialog.toString(16);
				  if (Callcolordialog.length < 6) {
				   var Temp = "000000".substring(0,6-Callcolordialog.length);
				   Callcolordialog = Temp.concat(Callcolordialog);
				  }
          PointedTD.bgColor = Callcolordialog;
    	
	}
 }
 function ChangeColsize(){
   if(CheckcursorIsinTableCell()){
     var colwidth = prompt("Enter a Image URL:", "100%");
    PointedTD.width = colwidth;
   }
 
 }
 var sUploadsList = new Array();
var sPages = new Array("index.htm","sub.htm");
onload = function(){
		try{
		for(i in sPages){
			sPageSwitch.options[sPageSwitch.length] = new Option(sPages[i], sPages[i]);
			if(sPages[i] == location.href.replace(/^(.)*=/ig, ''))
				sPageSwitch.options[sPageSwitch.length-1].selected = true;
		}
		}catch(e){ }
		loading();
	}
//Save File Section
function SaveHTMLPage(saveType) {
		try{
			if (SelMode == 2) {
				ShowHtml()
			}
		}catch(e){}
 		document.all("EditorHTM").value = foo.document.body.innerHTML
		re = /&amp;/g
		document.all("EditorHTM").value = document.all("EditorHTM").value.replace(re,'&')
		
		htmlLength = document.all("EditorHTM").value.length

		myHTML = document.all("EditorHTM").value
		mcLength = myHTML.length / 5;

		document.all("EditorHTM").value = myHTML.substring(0, mcLength);
		document.all("EditorHTM2").value = myHTML.substring(mcLength, mcLength*2 + 1);
		document.all("EditorHTM3").value = myHTML.substring(mcLength*2+1, mcLength*3 + 1);
		document.all("EditorHTM4").value = myHTML.substring(mcLength*3+1, mcLength*4 + 1);
		document.all("EditorHTM5").value = myHTML.substring(mcLength*4+1, myHTML.length);

		document.all("SaveTpe").value = saveType;
		document.all("EditorFrm").submit(); 
	}
//End Save File Section