       function editElement(element){
         var elementPos;
         var divPos;
         var parentElement = element.parentNode;

         var displayStyle = getStyle(element, 'display');

         elementPos = findPos(element);

         var keepSearchingForStyles = true;
         var textAlign = '';
         var fontSize = '';
         var fontStyle = '';
         var width = '';
         var fontFamily = '';
         var fontWeight = '';
         var curElement = element;

         

         while(keepSearchingForStyles){

           //alert("curElement = " + curElement.id);

           if(textAlign == '' && curElement.style.textAlign != '')
             textAlign = curElement.style.textAlign;
 
           if(fontSize == '' && curElement.style.fontSize != '')
             fontSize = curElement.style.fontSize;
 
           if(fontStyle == '' && curElement.style.fontStyle != '')
             fontStyle = curElement.style.fontStyle;

           if(width == '' && curElement.style.width != '')
             width = curElement.style.width;
 
           if(fontFamily == '' && curElement.style.fontFamily != '')
             fontFamily = curElement.style.fontFamily;

           if(fontWeight == '' && curElement.style.fontWeight != '')
             fontWeight = curElement.style.fontWeight;

           if((textAlign != '' && fontSize != '' && fontStyle != '' && width != '' && fontFamily != '' && fontWeight != '') || !curElement.parentNode.style)
             keepSearchingForStyles = false;
           else
             curElement = curElement.parentNode;
         }

         var editDiv = document.createElement('div');
         editDiv.style.zIndex = 1;
         editDiv.style.position = "absolute";
         editDiv.style.left = elementPos[0] + "px";
         editDiv.style.top = (elementPos[1] - 4) + "px";
         //editDiv.style.width = width;     
         /* editDiv.style.height = height; */

         if(displayStyle == 'block'){
           editDiv.style.textAlign = textAlign;
         }
         else{
           editDiv.style.textAlign = 'left';
         }

         var editBox = document.createElement('input');
         editBox.type = "text";

         var textBoxSize = element.innerHTML.length;
          
         //pad textBoxSize to account for variable width fonts
         textBoxSize = textBoxSize + (textBoxSize / 5);

         editBox.size = textBoxSize;

         //set the style.width if it's a span element or better yet make all text spans???    

         
         var s = element.innerHTML;
         s = s.replace('&amp;', '&');
  

         editBox.value = s;
         editBox.style.fontSize = fontSize;
         editBox.style.fontStyle = fontStyle;
         editBox.style.fontFamily = fontFamily;
         editBox.style.textAlign = textAlign;
         editBox.style.fontWeight = fontWeight;
         editBox.onkeyup = function(event){checkForSave(this, element, event)};


         /*
         var editDiv = document.createElement('div');
         editDiv.style.zIndex = 1;
         editDiv.style.position = "absolute";
         editDiv.style.left = elementPos[0] + "px";
         editDiv.style.top = elementPos[1] + "px";
         editDiv.style.width = parentElement.style.width;       
         editDiv.style.height = element.style.height;
         editDiv.style.textAlign = element.style.textAlign;

         var editBox = document.createElement('input');
         editBox.type = "text";
         editBox.size = element.innerHTML.length;
         editBox.value = element.innerHTML;
         editBox.style.height = "100%";
         editBox.style.fontSize = element.style.fontSize;
         editBox.style.fontStyle = element.style.fontStyle;
         editBox.style.fontFamily = element.style.fontFamily;
         editBox.style.textAlign = element.style.textAlign;
         editBox.onkeyup = function(event){checkForSave(this, element, event)};
         */
  
         editDiv.appendChild(editBox);
         parentElement.appendChild(editDiv);
       }
       
       function adjustElementMarginTop(elementId, numPixels){
         var element = document.getElementById(elementId);
         
         var currentMarginTop = element.style.marginTop.substring(0, element.style.marginTop.length-2);
         var newMarginTop = parseInt(currentMarginTop) + numPixels;
         
         element.style.marginTop = newMarginTop + "px";
       }
       
       
       function adjustElementHeight(elementId, numPixels){
         var element = document.getElementById(elementId);
         
         var currentHeight = element.style.height.substring(0, element.style.height.length-2);
         var newHeight = parseInt(currentHeight) + numPixels;
         
         element.style.height = newHeight + "px";
       }
       
       function checkHeightAdjustment(elementId, numPixelsToAdjust, elementToAdjustId, offset, ieOffset){
         var element = document.getElementById(elementId);
         var elementToAdjust = document.getElementById(elementToAdjustId);
         
         
         var elementHeight = element.offsetHeight;
         
         var ua = window.navigator.userAgent;
	 var msie = ua.indexOf ( "MSIE " );
         
         if(msie > 0)
           elementHeight += ieOffset;
         else
           elementHeight += offset;
         
         
         var checkHeight = parseInt(elementToAdjust.style.height.substring(0, elementToAdjust.style.height.length-2));
           /*
           alert("elementToAdjustId = " + elementToAdjustId + "\n" +
                 "elementHeight = " + elementHeight + "\n" +
                 "numPixelsToAdjust = " + numPixelsToAdjust + "\n" +
                 "checkHeight = " + checkHeight);  
           */
      
         if((elementHeight + numPixelsToAdjust) > checkHeight){
           /*
           alert("elementToAdjustId = " + elementToAdjustId + "\n" +
                 "elementHeight = " + elementHeight + "\n" +
                 "numPixelsToAdjust = " + numPixelsToAdjust + "\n" +
                 "checkHeight = " + checkHeight);      
           */         
         
           adjustElementHeight(elementToAdjustId, numPixelsToAdjust);
           
           return true;
         }
         else
           return false;
       }
       
       var height = 0;
       
       function getTotalHeight(element){
       
         
       
         /*
         var children = element.childNodes;
         
         if(children){
           for(var i=0; i<children.length; i++){
             var child = children[i];
             var childHeight = 0;
             
             if(child.style && child.style.height){               
                 childHeight = parseInt(child.style.height.substring(0, child.style.height.length-2));
                             
             }
             
             height = height + childHeight;
             
             
             if(child.style && child.style.display != "none"){
               getTotalHeight(child);      
               alert(child.id + " = " + height);
             }
           
             if(i > 1000){
               alert("leaving loop");
               break;   
             }
           }
         }
         
         return height;
         
         */
       }


       function addElement(element, copyElementId, containerId, newId){
         var ua = window.navigator.userAgent;
	 var msie = ua.indexOf ( "MSIE " );
       
         var copyElement = document.getElementById(copyElementId);

         var newElement = document.createElement(copyElement.nodeName);
         
         for(var i=0; i<copyElement.attributes.length; i++){
           if(copyElement.attributes[i].specified){     
             if(copyElement.attributes[i].nodeName == 'style'){
               if(msie > 0){
                 newElement.style.cssText = copyElement.style.cssText;
               }
               else
                 newElement.setAttribute(copyElement.attributes[i].nodeName, copyElement.attributes[i].nodeValue);
             }
             else
               newElement.setAttribute(copyElement.attributes[i].nodeName, copyElement.attributes[i].nodeValue);             
           }
         }
         
         

         var html = copyElement.innerHTML;
         
         var startIndex = 0;


         while(startIndex != -1){
           html = html.replace(copyElementId, newId);

           startIndex = html.indexOf(copyElementId);
         }        
 
         newElement.innerHTML = html;         
         newElement.id = newId;

         //Remove 'Last' from id of copyElement and all of its children
         var newCopyElementId = copyElement.id.replace('Last', '');
         copyElement.id = newCopyElementId;

         var copyElementChildren = copyElement.childNodes;

         for(var i=0; i<copyElementChildren.length; i++){
           var copyElementChild = copyElementChildren[i];
           copyElementChild.id = copyElementChild.id.replace('Last', '');
         }


         /*
         for(var i=0; i<copyElement.childNodes.length; i++){
           var curElement = copyElement.childNodes[i];    
           var prevChild;
           var newChild = document.createElement(curElement.nodeName);      

           for(var j=0; j<curElement.attributes.length; j++){
             newChild.setAttribute(curElement.attributes[i].nodeName, curElement.attributes[i].nodeValue);

             newChild.innerHTML = curElement.innerHTML;
           }

           if(prevChild){
             prevChild.appendChild(newChild);
           }
           else{
             newElement.appendChild(newChild);
           }

           alert(newChild.id);
          
           prevChild = newChild;
         }
         */
         
         var container = document.getElementById(containerId);

         //container.appendChild(newElement);
         container.insertBefore(newElement, element.parentNode)
      

         //increment onclick of element
         var newIdWOLast = newId.replace('Last', '');

         var stopLooking = false;
         var index = 0;

         while(!stopLooking){
           index++;
                     
           stopLooking = isNaN(parseInt(newIdWOLast.substring(newIdWOLast.length-index)));

           if(index > newIdWOLast.length)
             break;
         }

         var position = newIdWOLast.substring(newIdWOLast.length-(index-1));
         var restOfId = newIdWOLast.substring(0, newIdWOLast.length-(index-1));


         var oldOnClick = element.getAttribute('onclick');
         var newOnClick = restOfId + (parseInt(position) + 1) + 'Last';
         
                 
         if(msie > 0){
           var anonFunc = 'function anonymous(){';
           var ieOnClick = element.onclick.toString().replace(newId, newOnClick).replace(copyElementId, newId);
           
           
           ieOnClick = ieOnClick.substring(ieOnClick.indexOf(anonFunc) + anonFunc.length + 3, ieOnClick.length-2);
           
           
           //element.setAttribute('onclick', ieOnClick);
           
           element.onclick = new Function(ieOnClick); 
           
         }
         else          
           element.setAttribute('onclick', element.getAttribute('onclick').replace(newId, newOnClick).replace(copyElementId, newId));
         
       }

              


       function findPos(obj){
         var curleft = curtop = 0;

         if (obj.offsetParent){
	   do{
	      curleft += obj.offsetLeft;
	      curtop += obj.offsetTop;
           } while (obj = obj.offsetParent);

         }
	 return [curleft,curtop];
       }

       function getStyle(el,styleProp){

	 if (el.currentStyle)
           var y = el.currentStyle[styleProp];
	 else if (window.getComputedStyle)
	   var y = document.defaultView.getComputedStyle(el,null).getPropertyValue(styleProp);
	 
         return y;
       }


       function checkForSave(element, saveElement, e){
         var ua = window.navigator.userAgent;
	 var msie = ua.indexOf ( "MSIE " );
       
         var save;

         if(window.event)
           e = window.event;
           
           
         //alert(e.keyCode);

         if(e.keyCode == 13){
           if(element.value == ' '){
             save = confirm("You are attempting to save a single blank space.  If you want to delete this, click Cancel and remove the blank space.  Otherwise, click OK to save the blank space.");
             
             if(save){
               saveElement.innerHTML = '&nbsp;';

               var parent = element.parentNode;
               var grandParent = parent.parentNode;

               parent.removeChild(element);
               grandParent.removeChild(parent);
             }
             else{
               var parent = element.parentNode;
               var grandParent = parent.parentNode;
  
               parent.removeChild(element);
               grandParent.removeChild(parent);
             }             
           }
           else if(element.value.replace(/^\s+|\s+$/, '') == ''){
             save = confirm("Would you like to delete this?");


             if(save){
	       var plusSignRegExp = new RegExp(/plusSign/);

               var saveParent = saveElement.parentNode;

               saveParent.removeChild(saveElement);     

               if(saveParent.childNodes.length == 1){
               
                 var saveGrandParent = saveParent.parentNode;               

                 //Check to see if id contains 'Last', if so need to add 'Last' to previous element
               
                 var lastRegExp = new RegExp(/Last/);
                 var result=lastRegExp.test(saveElement.id);
                 
                 if(result){                  
                 
                   var newIdWOLast = saveParent.id.replace('Last', '');
                   var stopLooking = false;
                   var index = 0;

                   while(!stopLooking){
                     index++;
                     
                     stopLooking = isNaN(parseInt(newIdWOLast.substring(newIdWOLast.length-index)));

                     if(index > newIdWOLast.length)
                       break;
                   }

                   var position = newIdWOLast.substring(newIdWOLast.length-(index-1));
                   var restOfId = newIdWOLast.substring(0, newIdWOLast.length-(index-1));
                   var newLastId = restOfId + (parseInt(position) - 1) + 'Last';
                   var oldAddId = restOfId + (parseInt(position) + 1) + 'Last';
                   var lastId = newLastId.replace('Last', '');
                   
                       
                   while(!document.getElementById(lastId) && position > 0){
                     position = position - 1;
                     
		     newLastId = restOfId + (parseInt(position) - 1) + 'Last';
		     oldAddId = restOfId + (parseInt(position) + 1) + 'Last';
                     lastId = newLastId.replace('Last', '');
                   }

                   
                   var lastElement = document.getElementById(lastId);
                   
                   if(lastElement){
                     var lastElementChildren = lastElement.childNodes;

                     for(var i=0; i<lastElementChildren.length; i++){
                       if(lastElementChildren[i].id)
                         lastElementChildren[i].id = lastElementChildren[i].id.replace(lastId, newLastId);
                     }

                     lastElement.id = newLastId;
                   }


                   /*
                   var position = newIdWOLast.substring(newIdWOLast.length-1);
                   var restOfId = newIdWOLast.substring(0, newIdWOLast.length-1);


                   var oldOnClick = element.getAttribute('onclick');
                   var newOnClick = restOfId + (parseInt(position) + 1) + 'Last';
                   */

                   //need to update plusSign div's onclick to reduce number in the 2nd and 4th params by 1     
                   for(var i=0; i<saveGrandParent.childNodes.length; i++){
                     if(saveGrandParent.childNodes[i].id){
                       if(plusSignRegExp.test(saveGrandParent.childNodes[i].id)){
                         var plusSignButtonId = saveGrandParent.childNodes[i].id.replace('Div', '');
                         var plusSignButton = document.getElementById(plusSignButtonId);

                         var oldOnClick = element.getAttribute('onclick');

                         if(msie > 0){
                           var anonFunc = 'function anonymous(){';
                           
                           var ieOnClick = plusSignButton.onclick.toString().replace(saveParent.id, newLastId).replace(saveParent.id, newLastId);                           
           
                           ieOnClick = ieOnClick.substring(ieOnClick.indexOf(anonFunc) + anonFunc.length + 3, ieOnClick.length-2);
           
                           plusSignButton.onclick = new Function(ieOnClick);      
                         }
                         else   
                           plusSignButton.setAttribute('onclick', plusSignButton.getAttribute('onclick').replace(saveParent.id, newLastId).replace(oldAddId, saveParent.id));
                       }
                     }
                   }
                 }                 

                 saveGrandParent.removeChild(saveParent);
                 
                 //continue to delete parent nodes if there is only 1 child
                 var deletingLastContainer = false;
                 
                 if(saveGrandParent.childNodes){
                   while(saveGrandParent.childNodes.length == 0){           
                     var saveGreatGrandParent = saveGrandParent.parentNode;     
                     
                     if(saveGrandParent.id && lastRegExp.test(saveGrandParent.id) && !deletingLastContainer){
			var newIdWOLast = saveGrandParent.id.replace('Last', '');
			var stopLooking = false;
			var index = 0;

			while(!stopLooking){
			  index++;

			  stopLooking = isNaN(parseInt(newIdWOLast.substring(newIdWOLast.length-index)));

			  if(index > newIdWOLast.length)
			    break;
			}


			var position = newIdWOLast.substring(newIdWOLast.length-(index-1));
			var restOfId = newIdWOLast.substring(0, newIdWOLast.length-(index-1));
			var newLastId = restOfId + (parseInt(position) - 1) + 'Last';
			var oldAddId = restOfId + (parseInt(position) + 1) + 'Last';
			var lastId = newLastId.replace('Last', '');

			while(!document.getElementById(lastId)){
			  position = position - 1;

			  newLastId = restOfId + (parseInt(position) - 1) + 'Last';
			  oldAddId = restOfId + (parseInt(position) + 1) + 'Last';
			  lastId = newLastId.replace('Last', '');
			}     
			
			var lastElement = document.getElementById(lastId);
			var lastElementChildren = lastElement.childNodes;

			for(var i=0; i<lastElementChildren.length; i++){
			  if(lastElementChildren[i].id)
			    lastElementChildren[i].id = lastElementChildren[i].id.replace(lastId, newLastId);
			}

			lastElement.id = newLastId;			
                     
			for(var i=0; i<saveGreatGrandParent.childNodes.length; i++){
			  if(saveGreatGrandParent.childNodes[i].id){
			  
			    if(plusSignRegExp.test(saveGreatGrandParent.childNodes[i].id)){

				 var plusSignButtonId = saveGreatGrandParent.childNodes[i].id.replace('Div', '');
				 var plusSignButton = document.getElementById(plusSignButtonId);

				 var oldOnClick = element.getAttribute('onclick');

				 if(msie > 0){
				   var anonFunc = 'function anonymous(){';

				   var ieOnClick = plusSignButton.onclick.toString().replace(saveGrandParent.id, newLastId).replace(saveGrandParent.id, newLastId);                           

				   ieOnClick = ieOnClick.substring(ieOnClick.indexOf(anonFunc) + anonFunc.length + 3, ieOnClick.length-2);

				   plusSignButton.onclick = new Function(ieOnClick);      
				 }
				 else   
				   plusSignButton.setAttribute('onclick', plusSignButton.getAttribute('onclick').replace(saveGrandParent.id, newLastId).replace(oldAddId, saveGrandParent.id));
				   
				 deletingLastContainer = true;
			    }
			  }
			}     
                     }                     
                     
                     saveGreatGrandParent.removeChild(saveGrandParent);
                     saveGrandParent = saveGreatGrandParent;
                   }
                 }
               }

               var parent = element.parentNode;
               var grandParent = parent.parentNode;

               parent.removeChild(element);
               grandParent.removeChild(parent);
               
             }
           }
           else{
             save = confirm("Would you like to save this?");

             if(save){
               saveElement.innerHTML = element.value;

               var parent = element.parentNode;
               var grandParent = parent.parentNode;

               parent.removeChild(element);
               grandParent.removeChild(parent);
             }
             else{
               var parent = element.parentNode;
               var grandParent = parent.parentNode;
  
               parent.removeChild(element);
               grandParent.removeChild(parent);
             }
           }
         }
         else if(e.keyCode == 119){        
         
             if(saveElement.style.fontStyle != 'italic'){
		var selectedText;
		// IE version
		if (document.selection != undefined)
		{
		  //element.focus();
		  var sel = document.selection.createRange();
		  selectedText = sel.text;
		}
		// Mozilla version
		else if (element.selectionStart != undefined)
		{
		  var startPos = element.selectionStart;
		  var endPos = element.selectionEnd;
		  selectedText = element.value.substring(startPos, endPos)
		}
		save = confirm("Would you like to save this with '" + selectedText + "' in italics?");

		if(save){
		  var elementValue = element.value;

		  var textBeforeItalics = elementValue.substring(0, elementValue.indexOf(selectedText));
		  var textItalics = selectedText;
		  var textAfterItalics = elementValue.substring(elementValue.indexOf(selectedText) + selectedText.length);

		  /*
		  alert("textBeforeItalics = *" + textBeforeItalics + "*\n" + 
		     "textItalics = *" + textItalics + "*\n" + 
		     "textAfterItalics = *" + textAfterItalics + "*");
		  */


		  var removeOrigElem = false;

		  if(textBeforeItalics.replace(/^\s+|\s+$/, '') != ''){
		 var beforeItalics = document.createElement("span");

		 beforeItalics.innerHTML = textBeforeItalics;
		 beforeItalics.style.fontSize = saveElement.style.fontSize;
		 beforeItalics.style.fontStyle = saveElement.style.fontStyle;
		 beforeItalics.style.fontFamily = saveElement.style.fontFamily;
		 beforeItalics.style.textAlign = saveElement.style.textAlign;
		 beforeItalics.style.fontWeight = saveElement.style.fontWeight;

		 var oldOnClick = saveElement.getAttribute('onclick');

		 if(msie > 0){
		   var anonFunc = 'function anonymous(){';
		   var ieOnClick = oldOnClick.toString();

		   ieOnClick = ieOnClick.substring(ieOnClick.indexOf(anonFunc) + anonFunc.length + 3, ieOnClick.length-2);		   


		   //element.setAttribute('onclick', ieOnClick);

		   beforeItalics.onclick = new Function(ieOnClick); 

		 }
		 else          
		   beforeItalics.setAttribute('onclick', oldOnClick);		 

		 saveElement.parentNode.appendChild(beforeItalics);

		 removeOrigElem = true;
		  }

		  if(textItalics.replace(/^\s+|\s+$/, '') != ''){
		 var italics = document.createElement("span");

		 italics.innerHTML = textItalics;
		 italics.style.fontSize = saveElement.style.fontSize;
		 italics.style.fontStyle = "italic";
		 italics.style.fontFamily = saveElement.style.fontFamily;
		 italics.style.textAlign = saveElement.style.textAlign;
		 italics.style.fontWeight = saveElement.style.fontWeight;

		 var oldOnClick = saveElement.getAttribute('onclick');


		 if(msie > 0){
		   var anonFunc = 'function anonymous(){';
		   var ieOnClick = oldOnClick.toString();


		   ieOnClick = ieOnClick.substring(ieOnClick.indexOf(anonFunc) + anonFunc.length + 3, ieOnClick.length-2);


		   //element.setAttribute('onclick', ieOnClick);

		   italics.onclick = new Function(ieOnClick); 

		 }
		 else          
		   italics.setAttribute('onclick', oldOnClick);			 

		 saveElement.parentNode.appendChild(italics)	       

		 removeOrigElem = true;
		  }

		  if(textAfterItalics.replace(/^\s+|\s+$/, '') != ''){
		 var afterItalics = document.createElement("span");

		 afterItalics.innerHTML = textAfterItalics;
		 afterItalics.style.fontSize = saveElement.style.fontSize;
		 afterItalics.style.fontStyle = saveElement.style.fontStyle;
		 afterItalics.style.fontFamily = saveElement.style.fontFamily;
		 afterItalics.style.textAlign = saveElement.style.textAlign;
		 afterItalics.style.fontWeight = saveElement.style.fontWeight;

		 var oldOnClick = saveElement.getAttribute('onclick');


		 if(msie > 0){
		   var anonFunc = 'function anonymous(){';
		   var ieOnClick = oldOnClick.toString();

		   ieOnClick = ieOnClick.substring(ieOnClick.indexOf(anonFunc) + anonFunc.length + 3, ieOnClick.length-2);


		   //element.setAttribute('onclick', ieOnClick);

		   afterItalics.onclick = new Function(ieOnClick); 

		 }
		 else          
		   afterItalics.setAttribute('onclick', oldOnClick);			 

		 saveElement.parentNode.appendChild(afterItalics);	       

		 removeOrigElem = true;
		  }

		  if(removeOrigElem){
		 var parent = saveElement.parentNode;
		 parent.removeChild(saveElement);
		  }




		  //saveElement.innerHTML = element.value;

		  var parent = element.parentNode;
		  var grandParent = parent.parentNode;

		  parent.removeChild(element);
		  grandParent.removeChild(parent);

		}
		else{

		  var parent = element.parentNode;
		  var grandParent = parent.parentNode;

		  parent.removeChild(element);

		}
	   }
	     
         }
       }


       function createSaveButton(saveFile){
         var saveForm = document.createElement("form");
         saveForm.method = "post";
         saveForm.action = "saveFile.php";
         saveForm.name = "saveForm";
         saveForm.id = "saveForm";

         var filename = document.createElement("input");
         filename.type = "hidden";
         filename.name = "filename";
         filename.id = "filename";
         filename.value =  saveFile + ".php";   //document.title + ".php";    //"testUpdateFile.php";   //menu.php

         var updateFilename = document.createElement("input");
         updateFilename.type = "hidden";
         updateFilename.name = "updateFilename";
         updateFilename.id = "updateFilename";
         updateFilename.value =  saveFile + "Update.php";   //document.title + "Update.php";   //"testUpdateFileUpdate.php";  //"menuUpdate.php"
         
         var saveButton = document.createElement("input");
         saveButton.type = "button";
         saveButton.value = "Save Changes";
         saveButton.id = "saveButton";
         saveButton.onclick = function(){saveChanges()};
         saveButton.style.display = "block";
         saveButton.style.marginLeft = "auto";
         saveButton.style.marginRight = "auto";
         saveButton.style.marginTop = "20px";
         
         saveForm.appendChild(filename);
         saveForm.appendChild(updateFilename);
         saveForm.appendChild(saveButton);
         document.body.appendChild(saveForm);

         
       }
       
       var save = false;

       function saveChanges(){

         //var save = confirm("Are you sure you want to save these changes?");

         if(save){

           //document.getElementById("saveForm").removeChild(document.getElementById("saveButton"));

           var header = '<!-- HEADER -->';
           var footer = '<!-- FOOTER -->';
           //var onload = 'onload="createSaveButton();"';
           var beginbody = '<body'
           var endbody = '<!-- ENDBODY -->';
           var copy = '<!-- COPY -->';
           var copyCode = "<!-- COPY --><?php copy($_GET['filename'], $_GET['copyOfFilename']); ?><!-- COPY -->";
           var onclickEdit = 'onclick="editElement(this);"';
           var beginForm = '<form id="saveForm"';
           var endForm = '</form>';
           var plusSign = '<!-- PLUSSIGN -->';
           var cursorDefault = 'style="cursor: default;"';
           
           var beginPlusSign = '<div id="plusSign';
           var endPlusSign = '<!-- ENDPLUSSIGN -->';

           var innerHTMLString = document.documentElement.innerHTML;

           var ua = window.navigator.userAgent;
           var msie = ua.indexOf ( "MSIE " );
              
              
           if(msie > 0){
             var anonFunc = 'function anonymous(){';
	                                
             var imgElements = document.getElementsByTagName('img');
             
             for(var i=0; i<imgElements.length; i++){
               var curElem = imgElements[i];
               
               
               if(curElem.onclick){
               
                 for(var j=0; j<curElem.attributes.length; j++){
                   if(curElem.attributes[j].nodeName == 'onclick'){
                     if(curElem.attributes[j].nodeValue == null){
	                          
		       var ieOnClick = curElem.onclick.toString().substring(curElem.onclick.toString().indexOf(anonFunc) + anonFunc.length + 3, curElem.onclick.toString().length-2);
       
                       curElem.setAttribute('onclick', ieOnClick);
                     }
                   }
                 }
               }
               
             }
             
             innerHTMLString = ieInnerHTML(document.documentElement);
           }    
           
            

           var htmlString = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml">\n' + innerHTMLString + '</html>';
           var updateHtmlString = "<?php\n  if(isset($_COOKIE['sessid'])){\n    $sessidCookie = $_COOKIE['sessid'];\n    $sessidDB = '';\n\n    $hostname = 'purewine.db.3392727.hostedresource.com';\n    $dbname = 'purewine';\n    $dbusername = 'purewine';\n    $dbpassword = 'Pwc8210';\n\n\    $con = mysql_connect($hostname, $dbusername, $dbpassword);\n\n    if(!$con){\n      header('Location: updateLogin.php?message=Could%20not%20connect%20to%20DB');\n      exit();\n    }\n\n    mysql_select_db($dbname);\n\n    $sessionQuery = sprintf(\"SELECT id FROM session WHERE id = '%s'\",\n        mysql_real_escape_string($sessidCookie));\n\n    $result = mysql_query($sessionQuery);\n\n    if(!$result){\n      header('Location: updateLogin.php?message=Invalid%20session');\n      exit();\n    }\n\n    while ($row = mysql_fetch_assoc($result)) {\n      $sessidDB = $row['id'];\n    }\n\n    if($sessidCookie != $sessidDB){\n      header('Location: updateLogin.php?message=Invalid%20session');\n      exit();\n    }\n  }\n  else{\n    header('Location: updateLogin.php');\n  }\n\n?>\n" + htmlString;
           
           
           //alert(htmlString.substring(8500, 13500));
           
           
           if(htmlString.indexOf(cursorDefault) != -1){
             htmlString = htmlString.replace(cursorDefault, "");
             updateHtmlString = updateHtmlString.replace(cursorDefault, "");
           }


           htmlString = htmlString.replace(htmlString.substring(htmlString.indexOf('<script id="updateScript"'), htmlString.indexOf('</script>') + 9), '');
  
           htmlString = htmlString.replace(htmlString.substring(htmlString.indexOf(copy), htmlString.indexOf(copy, htmlString.indexOf(copy) + copy.length) + copy.length), "");

           updateHtmlString = updateHtmlString.replace(updateHtmlString.substring(updateHtmlString.indexOf(copy), updateHtmlString.indexOf(copy, updateHtmlString.indexOf(copy) + copy.length) + copy.length), copyCode);

           htmlString = htmlString.replace(htmlString.substring(htmlString.indexOf(header) + header.length, htmlString.indexOf(header, htmlString.indexOf(header) + header.length)), "<?php include 'purewinecafeheader'; ?>");
           htmlString = htmlString.replace(htmlString.substring(htmlString.indexOf(footer) + footer.length, htmlString.indexOf(footer, htmlString.indexOf(footer) + footer.length)), "<?php include 'purewinecafefooter'; ?>");

           updateHtmlString = updateHtmlString.replace(updateHtmlString.substring(updateHtmlString.indexOf(header) + header.length, updateHtmlString.indexOf(header, updateHtmlString.indexOf(header) + header.length)), "<?php include 'purewinecafeupdateheader'; ?>");
           updateHtmlString = updateHtmlString.replace(updateHtmlString.substring(updateHtmlString.indexOf(footer) + footer.length, updateHtmlString.indexOf(footer, updateHtmlString.indexOf(footer) + footer.length)), "<?php include 'purewinecafefooter'; ?>");
         
           //htmlString = htmlString.replace(htmlString.substring(htmlString.indexOf(onload) - 1, htmlString.indexOf(onload) + onload.length), '');
           
           htmlString = htmlString.replace(htmlString.substring(htmlString.indexOf(beginbody), htmlString.indexOf(endbody)), "<body>");
           
           //htmlString = htmlString.replace(htmlString.substring(htmlString.indexOf(body) + body.length, htmlString.indexOf(body, htmlString.indexOf(body) + body.length)), "<body>");

           var onclickEditIndex = htmlString.indexOf(onclickEdit);

           while(onclickEditIndex != -1){
             htmlString = htmlString.replace(htmlString.substring(onclickEditIndex - 1, onclickEditIndex + onclickEdit.length), '');

             onclickEditIndex = htmlString.indexOf(onclickEdit);
           }

           /*
           var plusSignIndex = htmlString.indexOf(plusSign);

           while(plusSignIndex != -1){
             htmlString = htmlString.replace(htmlString.substring(htmlString.indexOf(plusSign), htmlString.indexOf(plusSign, htmlString.indexOf(plusSign) + plusSign.length) + plusSign.length), "");

             plusSignIndex = htmlString.indexOf(plusSign);
           }
           */
           
           var plusSignIndex = htmlString.indexOf(endPlusSign);

           while(plusSignIndex != -1){
             htmlString = htmlString.replace(htmlString.substring(htmlString.indexOf(beginPlusSign), htmlString.indexOf(endPlusSign, htmlString.indexOf(beginPlusSign) + beginPlusSign.length) + endPlusSign.length), "");

             plusSignIndex = htmlString.indexOf(endPlusSign);
           }           

           htmlString = htmlString.replace(htmlString.substring(htmlString.indexOf(beginForm), htmlString.indexOf(endForm, htmlString.indexOf(beginForm)) + endForm.length), ''); 
           

           //updateHtmlString = updateHtmlString.replace(updateHtmlString.substring(updateHtmlString.indexOf(beginForm), updateHtmlString.indexOf(endForm, updateHtmlString.indexOf(beginForm)) + endForm.length), ''); 

           //htmlString = htmlString.replace(htmlString.substring(htmlString.indexOf(onclickEdit) - 1, htmlString.indexOf(onclickEdit) + onclickEdit.length), '');

         
           var textToSave = document.createElement("input");
           textToSave.type = "hidden";
           textToSave.name = "textToSave";
           textToSave.id = "textToSave";
           textToSave.value = htmlString;

           var updateTextToSave = document.createElement("input");
           updateTextToSave.type = "hidden";
           updateTextToSave.name = "updateTextToSave";
           updateTextToSave.id = "updateTextToSave";
           updateTextToSave.value = updateHtmlString;

           document.getElementById("saveForm").appendChild(textToSave);
           document.getElementById("saveForm").appendChild(updateTextToSave);
        
           //alert("Update = " + updateHtmlString);  //.substring(3500, 6500));

           //alert(htmlString.substring(6500, 11500));
           
           document.getElementById("saveForm").submit();
         }
       }

function ieInnerHTML(obj) {
 var zz = obj.innerHTML,
     z = 
   zz.match(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/g);
  if (z){
    for (var i=0;i<z.length;i++){
      var y, zSaved = z[i];
      z[i] = z[i].replace(/(<?\w+)|(<\/?\w+)\s/,
                          function(a){return a.toLowerCase();});
      y = z[i].match(/\=\w+[?\s+|?>]/g);
       if (y){
        for (var j=0;j<y.length;j++){
          z[i] = z[i].replace(y[j],y[j]
                     .replace(/\=(\w+)([?\s+|?>])/g,'="$1"$2'));
        }
       }
       zz = zz.replace(zSaved,z[i]);
     }
   }
  return zz;
 }
