// reload for Netscape
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

// Preload images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//MM_preloadImages('/images/navnew/nav_welcome_roll.gif','/images/navnew/nav_classinfo_roll.gif','/images/navnew/nav_teachers_roll.gif','/images/navnew/nav_teachers_roll.gif','/images/navnew/nav_style_roll.gif','/images/navnew/nav_events_roll.gif','/images/navnew/nav_bodywork_roll.gif');

// replace any strange characters
String.prototype.normalize = function()
{
//  return this.replace( /^\s+/g , '' ).replace( /\s+$/g , '' ).replace( /\s+/g , " " ) ;

  return this.replace( /%20+/g , ' ' ).replace( /_/g , "" ).replace( /-/g , "" ).replace( /,/g , "" ).replace( /\s+/g , "" ) ;
  
}

// determine server
if (top.location != self.location) {
  top.location = self.location;
}

var url = self.location.href;
//url = url.toLowerCase();

var DOM   = '';
var local = 'localhost/nwdoulas/'; //'website/';
var live  = 'nwdoulas.com';
((url.indexOf(local) > -1)? DOM = local: DOM =  live);

// determine path, section of site and subdirectory variable
var endOfDOM = url.lastIndexOf(DOM);
var endOfURL = url.substring((endOfDOM + DOM.length), url.length);

// determine filename
var HTM = '.php';
var endOfHTM = url.lastIndexOf(HTM);
var beg_file = url.lastIndexOf('/');
var filename = url.substring(beg_file + 1, endOfHTM).normalize();

//alert('subdir =' + subdir)
//alert('section =' + section)
//alert('filename =' + filename)



// determine path, section of site and subdirectory variable
var endoDOM = url.lastIndexOf(DOM);
var endoURL = url.substring((endoDOM + DOM.length), url.length);


// determine path, section of site and subdirectory variable
var filen = '';
var dir = '';
//var section = '';
for (i=0; i<endoURL.length; i++) {
  if (i < endoURL.lastIndexOf('/') )      { dir  += endoURL.charAt(i); }
  if (i > endoURL.lastIndexOf('/') )      { filen += endoURL.charAt(i); } 
  //if (endOfURL.charAt(i)=='/')         { path += '../'; }
}

dir   = dir.replace(/\//g,'%2F'); // get directory URL ready for editor
filen = filen.replace(/%20/g,'+'); // get filename URL ready for editor
// Set Key Press to open editor in edit mode after login
var editURL = 'f='+filen+'&action=edit&dir='+dir;
//alert(editURL)

var adminURL = 'http://' + live + '/editor/edit.php?'; 
var adminWin = ''; // set window name
// set event detection for ! char
document.onkeypress = function(e)
{
 // prevents 'Firefox: event is not defined' error
 e = e?e:event;

 // accomodates several browser variations of determining what key was pressed.
 var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;

 // 27 - the ESC key
 if(keyCode == 33) { // 33 = !
		/*alert("live is: " + live + "\n\n" +
			  "adminURL is: " + adminURL + "\n\n" +
			  "filen is: " + filen); */
		//if (url.indexOf("!")) {
			editorUP(adminURL+editURL);
		//} else {
			//alert("Oops, you put a \"!\" in the address bar where web site addresses go.\n\nPlease refresh the page and try again.")
		//}
 }
}

// open website in edtior window
function editorUP(url) {
	if (!adminWin.closed && adminWin.location) {
		adminWin.location.href = url;
	}
	else {
		adminWin = window.open(url,'newWin','left=50,top=100,width=800,height=550,menubar=yes,toolbar=yes,location=yes,resizable=yes,scrollbars=yes');
		if (!adminWin.opener) adminWin.opener = self;
	}
	if (window.focus) {adminWin.focus()}
	return false;
}