var initialImages
global_reload = false
source = new Array();
/* check whether the page loaded completly.if not loaded completly wait until the page load completly.*/
function loading()
{
	foo.location.href=document.all("pageurl").value;
	foo.document.designMode = 'On';
	if(global_reload == true) {
		global_reload=false;
	}
	foo.location.reload();
	window.setTimeout("loadAfter()",200);
}

function loadAfter() {
	if(foo.document.readyState != "complete") {
		window.setTimeout("loadAfter()",200);
		return;
	}
	foo.focus();
	initialImages = foo.document.images;
	for(i=0;i<initialImages.length;i++) {
	
		source.push(initialImages[i].src);	
	}
}
function changeFont(tFont) {
   try{
		if (SelMode == 2) {
			document.all("showhtml").checked=false;
			ShowHtml()
			foo.focus();
			alert('Please use this option in the design mode.');
			return false;
		}
	}catch(e){} 
    foo.document.execCommand(tFont);
	foo.focus();	
}
function doFont(t) {
   try{
		if (SelMode == 2) {
			document.all("showhtml").checked=false;
			ShowHtml()
			foo.focus();
			alert('Please use this option in the design mode.');
			return false;
		}
	}catch(e){} 

	foo.document.execCommand('FontName',false,t[t.selectedIndex].value);
	foo.focus();
	t.selectedIndex=0;
}
function doSize(t) {
	foo.document.execCommand('FontSize',true,t[t.selectedIndex].value);
	foo.focus();
	t.selectedIndex=0;
}
function fooLoad()
{
	//alert('');
	return true;
}
	
var Mode = "1";
function setHeight() {
	//height = 119
	height = 300
	
	if (Mode == 2)
	{ 
		height = 87
	}
	return (document.body.clientHeight-height)
}
	
function button_down(eButton){
	eButton.style.borderBottom = "buttonhighlight solid 1px";
	eButton.style.borderLeft = "buttonshadow solid 1px";
	eButton.style.borderRight = "buttonhighlight solid 1px";
	eButton.style.borderTop = "buttonshadow solid 1px";
}

function button_over(eButton){
	if (eButton.style.borderBottom != "buttonhighlight 1px solid")
	{
	eButton.style.borderBottom = "buttonshadow solid 1px";
	eButton.style.borderLeft = "buttonhighlight solid 1px";
	eButton.style.borderRight = "buttonshadow solid 1px";
	eButton.style.borderTop = "buttonhighlight solid 1px";
	}
}
function button_out2(eButton){
	if (eButton.style.borderBottom != "buttonhighlight 1px solid")
	{
	eButton.style.borderColor = "threedface";
	}
	eButton.style.borderColor = "threedface";
}

function button_out(eButton){
	eButton.style.borderColor = "threedface";
}
var SlectedColor = null;
function changefontcolor(colorType){
	if(foo.document.selection.type=='None'){
	  alert("please select the text first");
	  return false;
	}

		  if(SlectedColor == null)
		   var Callcolordialog = colordialog.ChooseColorDlg();
		  else
		   var Callcolordialog = colordialog.ChooseColorDlg(SlectedColor);

		  Callcolordialog = Callcolordialog.toString(16);
		  /* if the user close the window without selecting the color nothing to be done*/
		  if (Callcolordialog != "0") {
				  if (Callcolordialog.length < 6) {
				   var Temp = "000000".substring(0,6-Callcolordialog.length);
				   Callcolordialog = Temp.concat(Callcolordialog);
				  }
		
				  Command = (colorType == 2) ? 'BackColor' : 'ForeColor';
				  foo.document.execCommand(Command, false, Callcolordialog);
				  SlectedColor = Callcolordialog;
				  SlectedColor = null;
		 }		  

}
	
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;
   }	
  }
 }	
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;
   }
  }
 }
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)
  {
  }
 }
 //New
 function Createtable(){
   try{
		if (SelMode == 2) {
			document.all("showhtml").checked=false;
			ShowHtml()
			foo.focus();
			alert('Please use this option in the design mode.');
			return false;
		}
	}catch(e){} 
  	try{
		  foo.document.selection.createRange().parentElement()
		
	   }catch(e){
	      alert("You cannot insert table here.");
		  return;
	   }
	 TbObj = new Object();
	  TbObj.cellPadding = 1;
	  TbObj.cellSpacing = 2;
		 res = showModalDialog('tblpro.php', TbObj, 'dialogWidth: 360px; dialogHeight: 210px; center: yes; resizable: no; scroll: no; status: no;');
		 if(res){
		   foo.focus();
		  
		
		   SelParent = foo.document.selection.createRange().parentElement();
		  
		   NewTable = foo.document.createElement('<table>');
		   SelParent.appendChild(NewTable);
		   
			  if(res.width>0)
			     res.width=res.width+'%';
			  else 
			     res.width="100%";
			
			  if(res.border>=0)
			     res.border=res.border;
			  else 
			     res.border="1";
			  if(res.bgColor !="")
			     res.bgColor=res.bgColor;
			  else 
			     res.bgColor="white";	 
			
			  if(res.cellPadding >2)
			     res.cellPadding=res.cellPadding;
			  else 
			    res.cellPadding="2";	
			  if(res.cellSpacing >2)
			     res.cellSpacing=res.cellSpacing;
			  else 
			    res.cellSpacing="2";		 
			   
		       
			 
			 
		   //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 : '') + ">";        
		   StrNewTable = "<table width=" + res.width + "  border=" + res.border + " cellpadding=" + res.cellPadding + " cellspacing=" + res.cellSpacing + ' bgcolor = ' + res.bgColor + ">";        
		  
		   for(i=0; i<res.rows; i++){
		   
		    StrNewTable = StrNewTable + "<tr>";
		    for(j=0; j<res.columns; j++)
		     StrNewTable = StrNewTable + "<td>&nbsp;</td>"
			 
		     StrNewTable = StrNewTable + "</tr>"
			 
		   }       			
		   StrNewTable = StrNewTable + "</table>"
		   NewTable.outerHTML = StrNewTable;
		 }  
		 
 }
 
 function CheckcursorIsinTableCell(){
     foo.focus();

	if(document.selection.type != "Control"){
	  
	           var pointedElem = document.selection.createRange().parentElement();
			   while(pointedElem.tagName.toUpperCase() != "TD" && pointedElem.tagName.toUpperCase() != "TH"){
			    pointedElem = pointedElem.parentElement
			    if(pointedElem == null)
			     break
			   }
			   
			   if(pointedElem){
					    PointedTD = pointedElem
					    PointedTR = PointedTD.parentElement
					    PointedTBODY =  PointedTR.parentElement
					    PointedTable = PointedTBODY.parentElement
					    return true
			   }else{
			        alert("Please place the cursor inside the table cell");
			   }	
	  }
	  
 }

 function InsertColumbefore(){
      try{
		if (SelMode == 2) {
			document.all("showhtml").checked=false;
			ShowHtml()
			foo.focus();
			alert('Please use this option in the design mode.');
			return false;
		}
	}catch(e){}
		 if (CheckcursorIsinTableCell()){
		   Movecolumn = (PointedTR.cells.length-1) - (PointedTD.cellIndex)
		   TotalRows = PointedTable.rows
		   for(i=0;i<TotalRows.length;i++){
		    rowCount = TotalRows[i].cells.length - 1
		    WheretoInsert = rowCount - Movecolumn
		    if(WheretoInsert < 0)
		     WheretoInsert = 0
		    newCell = TotalRows[i].insertCell(WheretoInsert)
		    newCell.innerHTML = " "
		   }	
		  }
 }
 function InsertColumafter(){
      try{
		if (SelMode == 2) {
			document.all("showhtml").checked=false;
			ShowHtml()
			foo.focus();
			alert('Please use this option in the design mode.');
			return false;
		}
	}catch(e){}
		 if (CheckcursorIsinTableCell()){
		   Movecolumn = (PointedTR.cells.length-1) - (PointedTD.cellIndex + 1)
		   TotalRows = PointedTable.rows
		   for(i=0;i<TotalRows.length;i++){
		    rowCount = TotalRows[i].cells.length - 1
		    WheretoInsert = rowCount - Movecolumn 
		    if(WheretoInsert < 0)
		     WheretoInsert = 0
		    newCell = TotalRows[i].insertCell(WheretoInsert)
		    newCell.innerHTML = " "
		   }	
		  }
 }
 function InsertRowbefore(){
    try{
		if (SelMode == 2) {
			document.all("showhtml").checked=false;
			ShowHtml()
			foo.focus();
			alert('Please use this option in the design mode.');
			return false;
		}
	}catch(e){}
  if(CheckcursorIsinTableCell()){
   var TotCols = 0
   TotRows = PointedTR.cells
   for(var i=0;i<TotRows.length;i++) 
    TotCols = TotCols + TotRows[i].getAttribute('colSpan')
   var Newtablerow = PointedTable.insertRow(PointedTR.rowIndex)
   for(i = 0; i < TotCols; i++){
    Newtablecolumn = Newtablerow.insertCell()
    Newtablecolumn.innerHTML = " "
   }
  }	
 }
 function InsertRowafter(){
    try{
		if (SelMode == 2) {
			document.all("showhtml").checked=false;
			ShowHtml()
			foo.focus();
			alert('Please use this option in the design mode.');
			return false;
		}
	}catch(e){}
  if(CheckcursorIsinTableCell()){
   var TotCols = 0
   TotRows = PointedTR.cells
   for(var i=0;i<TotRows.length;i++) 
    TotCols = TotCols + TotRows[i].getAttribute('colSpan')
   var Newtablerow = PointedTable.insertRow(PointedTR.rowIndex + 1)
   for(i = 0; i < TotCols; i++){
    Newtablecolumn = Newtablerow.insertCell()
    Newtablecolumn.innerHTML = " "
   }
  }	
 }

 function DeleteRow(){
  if(CheckcursorIsinTableCell())
   PointedTable.deleteRow(PointedTR.rowIndex)
 }
 function DeleteColumn(){
  if(CheckcursorIsinTableCell()){
   Movecolumn = (PointedTR.cells.length-1) - (PointedTD.cellIndex)
   TotalRows = PointedTable.rows
   for(var i=0;i<TotalRows.length;i++){
    LastRow = TotalRows[i].cells.length - 1
    DeleteR = LastRow - Movecolumn
    if(DeleteR < 0)
     DeleteR = 0
    Totalcells = TotalRows[i].cells
    if(Totalcells[DeleteR].colSpan > 1)
     Totalcells[DeleteR].colSpan = Totalcells[DeleteR].colSpan - 1
    else
     TotalRows[i].deleteCell(DeleteR)
   }
  }
 }
 
 function ModifyTable(){
    try{
		if (SelMode == 2) {
			document.all("showhtml").checked=false;
			ShowHtml()
			foo.focus();
			alert('Please use this option in the design mode.');
			return false;
		}
	}catch(e){}
	  TbObj = new Object();
	  TbObj.cellPadding = 1;
	  TbObj.cellSpacing = 2;
	  if(CheckcursorIsinTableCell()){
	 // alert(PointedTable.rows.length);
        res = showModalDialog('./tblpromodi.php', PointedTable, 'dialogWidth: 360px; dialogHeight: 220px; center: yes; resizable: no; scroll: no; status: no;');

			 if(res){
					    if(res.width)
					     PointedTable.width = res.width+'%';
					    else
					     PointedTable.removeAttribute('width',0);
					
					    if(res.cellPadding)
					     PointedTable.cellPadding = res.cellPadding;
					    else
					     PointedTable.removeAttribute('cellPadding',0);
					    
					    if(res.bgColor)
					     PointedTable.bgColor = res.bgColor;
					    else
					     PointedTable.removeAttribute('bgColor',0);
					
					    if(res.background)
					     PointedTable.background = res.background;
					    else
					     PointedTable.removeAttribute('background',0);
					
						if(res.cellSpacing)
					     PointedTable.cellSpacing = res.cellSpacing;
					    else
					     PointedTable.removeAttribute('cellSpacing',0);
					
						if(res.border)
					     PointedTable.border = res.border;
					    else
					     PointedTable.removeAttribute('border',0);
					    if(res.borderColor)
					     PointedTable.borderColor = res.borderColor;
					    else
					     PointedTable.removeAttribute('borderColor',0);
					    if(res.align)
					     PointedTable.align = res.align;
					    else
					     PointedTable.removeAttribute('align',0);
						 
					}
	}	   
 }
 
 function ModifyCell(){
    try{
		if (SelMode == 2) {
			document.all("showhtml").checked=false;
			ShowHtml()
			foo.focus();
			alert('Please use this option in the design mode.');
			return false;
		}
	}catch(e){}
  if(CheckcursorIsinTableCell()){
   res = showModalDialog('./cellprop.php', PointedTD, 'dialogWidth: 370px; dialogHeight: 320px; center: yes; resizable: no; scroll: no; status: no;');
 
   if(res){
    if(res.colSpan)
    PointedTD.colSpan = res.colSpan;
	  else 
	PointedTD.colSpan = "1"
	 if(res.rowSpan)
     PointedTD.rowSpan  =res.rowSpan;
	  else 
	PointedTD.rowSpan = "1"
	
    
    if(res.width)
     PointedTD.width = res.width+'%';
    else
     PointedTD.removeAttribute('width',0);

    if(res.height)
     PointedTD.height = res.height+'%';
    else
     PointedTD.removeAttribute('height',0);
    
    if(res.bgColor)
     PointedTD.bgColor = res.bgColor;
    else
     PointedTD.removeAttribute('bgColor',0);

    if(res.background)
     PointedTD.background = res.background;
    else
     PointedTD.removeAttribute('background',0);

		  if(res.align && !res.align.match(/^None$/i))
     PointedTD.align = res.align;
    else
     PointedTD.removeAttribute('align',0);

	  	if(res.vAlign && !res.vAlign.match(/^None$/i))
     PointedTD.vAlign = res.vAlign;
    else
     PointedTD.removeAttribute('vAlign',0);
   }
  }
 } 
 
 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;
   }
 
 }
 
//End Table Insertion 

//showhtml
var SelMode=1;
 function ShowHtml() {
  
  if (SelMode == 1) {
   document.getElementById('savedata').disabled=true;
   selctedrange = foo.document.selection.createRange();
   Htmltext = selctedrange.htmlText;
   
   foo.document.body.innerText = foo.document.documentElement.outerHTML.replace(/&amp;/g, '&');
   //foo.document.body.innerText = foo.document.documentElement.outerHTML;
   code = foo.document.body.innerHTML;
  
   code = code.replace(/(&lt;([\s\S]*?)&gt;)/gi, "<font color=#000080>$1</font>")
   code = code.replace(/(&lt;(table|tbody|th|tr|td|\/table|\/tbody|\/th|\/tr|\/td)([\s\S]*?)&gt;)/gi, "<font color=#008080>$1</font>")
   code = code.replace(/(&lt;!--([\s\S]*?)&gt;)/gi, "<font color=#808080>$1</font>")
   code = code.replace(/(&lt;img([\s\S]*?)&gt;)/gi, "<font color=#800080>$1</font>")
   code = code.replace(/(&lt;(a|\/a)([\s\S]*?)&gt;)/gi, "<font color=#008000>$1</font>")
   code = code.replace(/(&lt;(script|\/script)([\s\S]*?)&gt;)/gi,"<font color=#800000>$1</font>")
   
   foo.document.body.innerHTML = code;
   foo.document.body.runtimeStyle.fontFamily = "Verdana"
   foo.document.body.runtimeStyle.fontSize = "10pt"
   foo.document.body.runtimeStyle.bgColor = '#FFFFFF';
   foo.document.body.runtimeStyle.color = '#000000';
   foo.document.body.runtimeStyle.text = '#000000';
   foo.document.body.runtimeStyle.background = '';
   foo.document.body.runtimeStyle.marginTop = '10px';
   foo.document.body.runtimeStyle.marginLeft = '10px';

   Selectednewrange = foo.document.selection.createRange();
   r = foo.document.body.createTextRange();
   if(Htmltext && r.findText(Htmltext)){
    r.select();
    r.scrollIntoView();
   }

   foo.document.onkeypress = function(){
    if(foo.event.shiftKey && foo.event.keyCode == 13){
     sRange = foo.document.selection.createRange();
     sRange.text = '<BR>';
    }
   }

   SelMode = 2;
  }else{
  
  document.getElementById('savedata').disabled=false;
   foo.document.body.innerHTML = foo.document.body.innerText;
  foo.document.body.runtimeStyle.cssText = "";
  foo.document.onkeypress = '';
   SelMode = 1;
   
  }
 }

//end showhtml

//Form Show

function isAllowed() {
		var sel
		var obj
		// if (editDefault != 1) {
		//	return true
		// } else {
			
			sel = foo.document.selection
			
			if (sel.type != "Control")
			{
				obj = sel.createRange().parentElement()
			} else {
				obj = sel.createRange()(0)
			}
			
			if (obj.isContentEditable) {
				return true
			} else {
				return false
			}

		return true
			
		//}
	}
function isCursorInForm() {
		if (document.selection.type != "Control") {
                          var elem = document.selection.createRange().parentElement()
                          while (elem.tagName != "FORM")
                          {
                            elem = elem.parentElement
                            if (elem == null)
                              break
                          }
				if (elem) {
					selectedForm = elem
					return true
				}
		}
	}

function insertForm() {
		if (isAllowed())
		{
			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-400) / 2 
	 		insertFormWin = window.open('insertform.php','','width=500,height=440,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}
	}

function modifyForm() {
		if (isAllowed)
		{

		if (isCursorInForm()) {
			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-400) / 2 
	 		modifyFormWin = window.open('modifyform.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
	}
function doTextField() {
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "INPUT") {
				if ((oControlRange(0).type.toUpperCase() == "TEXT") || (oControlRange(0).type.toUpperCase() == "PASSWORD")) {
					selectedTextField = foo.document.selection.createRange()(0);
					textFieldWin = window.open('modifytextfield.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				}
				return true;
			}	
		} else {
			textFieldWin = window.open('inserttextfield.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
	}

function doTextArea() {
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "TEXTAREA") {
					selectedTextArea = foo.document.selection.createRange()(0);
					textFieldWin = window.open('modifytextarea.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				return true;
			}	
		} else {
			textFieldWin = window.open('inserttextarea.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
	}
function doHidden() {
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "INPUT") {
				if (oControlRange(0).type.toUpperCase() == "HIDDEN") {
					selectedHidden = foo.document.selection.createRange()(0);
					hiddenWin = window.open('modifyhidden.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				}
				return true;
			}	
		} else {
			hiddenWin = window.open('inserthidden.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
	}	
function doButton() {
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "INPUT") {
				if ((oControlRange(0).type.toUpperCase() == "RESET") || (oControlRange(0).type.toUpperCase() == "SUBMIT") || (oControlRange(0).type.toUpperCase() == "BUTTON")) {
					selectedButton = foo.document.selection.createRange()(0);
					buttonWin = window.open('modifybutton.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				}
				return true;
			}	
		} else {
			buttonWin = window.open('insertbutton.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
	}	
function doCheckbox() {
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "INPUT") {
				if (oControlRange(0).type.toUpperCase() == "CHECKBOX") {
					selectedCheckbox = foo.document.selection.createRange()(0);
					checkboxWin = window.open('modifycheckbox.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				}
				return true;
			}	
		} else {
			checkboxWin = window.open('insertcheckbox.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
	}

function doRadio() {
		if (isAllowed()) {

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "INPUT") {
				if (oControlRange(0).type.toUpperCase() == "RADIO") {
					selectedRadio = foo.document.selection.createRange()(0);
					radioWin = window.open('modifyradio.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				}
				return true;
			}	
		} else {
			radioWin = window.open('insertradio.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
	}	
//End Form Show

//Insert Link
var sUploadsList = new Array();
var sPages = new Array("index.html","search.html");
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();
	}
	
function insertInternalLink(chk) {
   try{
		if (SelMode == 2) {
			document.all("showhtml").checked=false;
			ShowHtml()
			foo.focus();
			alert('Please use this option in the design mode.');
			return false;
		}
	}catch(e){}
	if(foo.document.selection.type == 'None'){
      alert('Please select text or image first.');
    }else{
   sSel = new Object();
   sSel.defLinkColor = foo.document.body.link ? foo.document.body.link : '#0000ff';

   if(foo.document.selection.type == "Control"){
    var oControlRange = foo.document.selection.createRange();
    if(oControlRange(0).tagName.toUpperCase() == "IMG")
     oSel = oControlRange(0).parentNode;
   }else{
    oSel = foo.document.selection.createRange().parentElement();
   }

   sRange = foo.document.selection.createRange();

   if(sRange.queryCommandValue('ForeColor')){
    sSel.linkcolor = sRange.queryCommandValue('ForeColor').toString(16);
    while(sSel.linkcolor.length < 6)
     sSel.linkcolor = '0' + sSel.linkcolor;
    sSel.linkcolor = sSel.linkcolor.substr(4) + sSel.linkcolor.substr(2, 2) + sSel.linkcolor.substr(0, 2);
   }
   if(sRange.queryCommandState('Underline', false, null))
    sSel.linkDec = 'underline';

   if(oSel.tagName != 'A'){
    firedObj = oSel;
    while(firedObj.tagName != "BODY" && firedObj.tagName != "A")
     firedObj = firedObj.parentElement;
    if(firedObj.tagName == 'A')
     oSel = firedObj;
   }

   if(oSel.tagName == "A"){
    if(oSel.childNodes[0] && oSel.childNodes[0].tagName){
     tmpObj = oSel.childNodes[0];
     while(!tmpObj.tagName == 'FONT' && typeof(tmpObj.childNodes[0]) != 'undefined')
      tmpObj = tmpObj.childNodes[0];
     
     if(tmpObj.tagName == 'FONT' && tmpObj.outerHTML && tmpObj.outerHTML.match(/<font[^>]*onmouseover/i)){
      if(temp = tmpObj.outerHTML.match(/this\.color='#([0-9a-fA-F]*)/i))
       sSel.hovercolor = temp[0].replace(/.*'#/, '');
      if(temp = tmpObj.outerHTML.match(/textDecoration='([^']*)/i))
       sSel.hoverDec = temp[0].replace(/.*'/, '');
     }
    }

    sSel.popup = oSel.target == '_blank' ? true : false;

    if(oSel.outerHTML.match(/onclick=/ig) && oSel.onclick.match(/^open\(/)){
      sHref = oSel.onclick.replace(/^.*\/|['|"].*$/g, '');
      sSel.popup = true;
      sSel.res = oSel.onclick.replace(/^.*resizable=|;.*$/g, '');
      sSel.status = oSel.onclick.replace(/^.*status=|;.*$/g, '');
      sSel.tool = oSel.onclick.replace(/^.*toolbar=|;.*$/g, '');
      sSel.width = oSel.onclick.replace(/^.*width=|;.*$/g, '');
      sSel.height = oSel.onclick.replace(/^.*height=|;.*$/g, '');
    }else{
     sHref = unescape(oSel.href);
    }

    if(sHref.match(/@/)){
     sSel.type = 3;
     sSel.url = sHref.replace(/^mailto:( )*/ig, '');
    }else if(sHref.match(/^http:\/\/guestbook/i)){
     sSel.type = 1;
     sSel.url = sHref;
    }else if(sHref.match(/usr/ig) || !sHref.match(/http:/ig)){
     sHref = sHref.replace(/(.)*\//ig, '');
     match = false;
     for(key in sUploadsList)
      match = sUploadsList[key] == sHref;
     if(match){
      sSel.type = 4;
      sSel.url = sHref;
     }else{
      sSel.type = 1;
      sSel.url = sHref ? sHref : 'index.html';
     }
    }else{
     sSel.type = 2;
     sSel.url = sHref;
    }   
   }

   sSel.self = location.href.replace(/.*file=/ig, '');
   sSel.pages = sPageSwitch.options;
	if(chk == 1)
	{
	res=showModalDialog('insertinternal.php', sSel, 'dialogWidth: 280px; dialogHeight: 235px; center: yes; resizable: no; scroll: no; status: no;');
	}
	else if(chk == 2)
	{
	res=showModalDialog('insertmail.php', sSel, 'dialogWidth: 280px; dialogHeight: 235px; center: yes; resizable: no; scroll: no; status: no;');
	}
	else if(chk == 3)
	{
	res=showModalDialog('insertanchor.php', sSel, 'dialogWidth: 280px; dialogHeight:535px; center: yes; resizable: no; scroll: no; status: no;');
	}
	if(res && res.url){
    oNewSelection = foo.document.selection.createRange();
    if(foo.document.selection.type == "Control"){
     selectedImage = foo.document.selection.createRange()(0);
     selectedImage.border = selectedImage.border ? selectedImage.border : 0;
    }

    oNewSelection.execCommand("CreateLink",false,res.url);
	}
  }

}
//End Insert Link

//insert br
function inserttag(sTag){
  foo.focus();
  foo.document.selection.createRange().pasteHTML("<br>");
}
//end insert br

//Special characters
var cPopup = window.createPopup();
	
 function showMenu(menu, width, height){
  var lefter = event.clientX;
  var leftoff = event.offsetX
  var topper = event.clientY;
  var topoff = event.offsetY;
  var cPopBody = cPopup.document.body;
  
  var HTMLContent = eval(menu).innerHTML
  cPopBody.innerHTML = HTMLContent
  cPopup.show(lefter - leftoff - 2, topper - topoff + 22, width, height, document.body);
  
  return false;
 }
function insertChar(oChar) {
  foo.focus();
  var sel = foo.document.selection;
  var rng = sel.createRange();
  rng.pasteHTML(oChar.innerHTML)
  cPopup.hide()
 }
//End special Characters

//Page Properties
 function ModifyProperties(){
  open('pageprop.php','','width=740,height=340,scrollbars=no,toolbar=0');
 }
//End PageProperties

//Insert image
 function insertImage() {
        try{
			if (SelMode == 2) {
				document.all("showhtml").checked=false;
				ShowHtml()
			}
		}catch(e){} 
	 res = showModalDialog('insertimage.php', null, 'dialogWidth: 360px; dialogHeight: 200px; center: yes; resizable: no; scroll: yes; status: no;');	 
	 
	 if(res){
	
	     if(res.url!=""){
		     if(res.url=="uploadimage.php"){
			    res = showModalDialog(res.url, null, 'dialogWidth: 320px; dialogHeight: 200px; center: yes; resizable: no; scroll: yes; status: no;');	 
			 }else{
	   		       res = showModalDialog(res.url, null, 'dialogWidth: 600px; dialogHeight: 600px; center: yes; resizable: no; scroll: yes; status: no;');	 
			 }	   
		   if(res.url!=""){
		        imagePath=res.url;
				if(imagePath !="")
				foo.focus();
				document.getElementById('foo').contentWindow.document.execCommand('InsertImage', false, imagePath);
		   }
		  } 
	   
	 }
	
 }
//End Insert Image

//Insert flash
function insertFlash() {
	imagePath="";
	res = showModalDialog('insertflash.php', null, 'dialogWidth: 360px; dialogHeight: 400px; center: yes; resizable: no; scroll: no; status: no;');	 
	if(res.type == 1) {
		res = showModalDialog('uploadflash.php', null, 'dialogWidth: 360px; dialogHeight: 400px; center: yes; resizable: no; scroll: no; status: no;');	 
	}
	if(res.url != "") {
		imagePath=res.url;
	}		
	SelectFlash(imagePath);	

	}
function SelectFlash(FlashName)
	{
		var sel = foo.document.selection;

		if (sel != null)
		{
			var rng = sel.createRange();
			
			if (rng != null)
			{
				FlashObject = 
				'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0">' +
				'<param name=movie value="' + FlashName + '">' +
				'<embed src="' + FlashName +
				'" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"></embed></object>';

				rng.pasteHTML(FlashObject);
				//self.close();
			}
		}
	}
//End Insert Flash

//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

//Add/Edit/Remove Page
	function addPage() {
			
		}
    function editPage() {
			
		}
	function removePage() {
			
		}
	
//Add/Edit/Remove Page
function isCursorInTable() {
		if (document.selection.type != "Control") {
                          var elem = document.selection.createRange().parentElement()
                          while (elem.tagName != "TABLE")
                          {
                            elem = elem.parentElement
                            if (elem == null)
                              break
                          }
				if (elem) {
					selectedForm = elem
					return true
				}
		}
	}
	
	 function LogoEditor() {
	       res = showModalDialog('imageeditor.php', null, 'dialogWidth: 560px; dialogHeight: 600px; center: yes; resizable: no; scroll: yes; status: no;');	 
	     if(res){
		        imagePath=res.url;
				document.getElementById('foo').contentWindow.document.execCommand('InsertImage', false, imagePath);
		   }
     }
	