//global variables
var madeChanges = false;

function openPopup(doc){
  if(!doc) return;
  doc = replaceSpace(doc);
  var params = "location=no,menubar=no,resizable=yes,scrollbars=yes,width=600,height=400";
  var windowObj = window.open(doc, "Popup", params);
  windowObj.focus();
}

function editContent(objEditButton){
 if(!objEditButton.offsetParent.offsetParent.offsetParent){
  alert("There is a problem with this page. Please notify the webmaster.")
  return;
 }else{
  var objContentTD;
  var objContentSPAN;
  objContentTD = objEditButton.offsetParent.offsetParent.offsetParent;
  for(i=0;i<objContentTD.children.length;i++){
    if(objContentTD.children[i].id.indexOf("maincontent")>-1){
	 objContentSPAN = objContentTD.children[i];
	 break;
	}//end if
  }//end for
  var args = new Array(objContentSPAN);
  var w = window.showModalDialog('editcontent.asp',args,'dialogWidth:700px; dialogHeight:500px; center:yes; status:no; help:no');
  if(w){
   if(w!=objContentSPAN.innerHTML){
    madeChanges = true;
   }
   objContentSPAN.innerHTML = w;
  }
 }//end else
}

function checkForChanges(){
 if(madeChanges){
  var save = confirm("This page has changed. Would you like to save your changes?");
  if(save){
   savePage();
  }
 }
}

function replaceSpace(sString){
 if(!sString) return;
 return sString.replace(/\s/g,"%20");
}

function savePage(){
 var oForm = document.pageHTMLForm;
 var oField = oForm.pageHTML;
 var oHTML = document.body.innerHTML;
 oHTML = oHTML.replace(/\n/g,"");
 oHTML = oHTML.replace(/\r/g,"");
 oHTML = oHTML.replace(/\t/g,"");

 oField.value = oHTML;
 madeChanges = false;
 oForm.submit();
 
}
