//This is the javascript that needs to get included in each page you want to be editable.

//Edit this line to be your default web server document

var default_document = "index.htm";
var install_path = "/editor/";  /*set this to the absolute path to inpage_editor folder, usually /inpage_editor/ MUST HAVE TRAILING / */
debug = "false";   										 //Set debug ="TRUE" to enable debugging mode.


var editor = "true";
var path = location.pathname;
var incflag;
var filename;


function editThis(id, include) {

if (arguments.length > 1) {
	//We have an include file here.
	if (debug == "TRUE")alert("You are editing an INCLUDE file ")	
	var incflag = "true";
	path = location.pathname; //Since we want the relpath link to go back to the source file
	filename = include;

} else {
	//We just have a regular flat file.
	filename = setFileName();
	path = (path.slice(1,path.lastIndexOf('/') + 1)); //just the path
	
}

//Debugging Section
if (debug == "TRUE") alert ("You are going to edit " + id)
if (debug == "TRUE") alert ("The Path of the file is " + path)
if (debug == "TRUE") alert ("The Filename of the file is " + filename)

//Password Prompt
var pass = prompt ("Please enter password to edit","")


//Pass the data over to the editor
window.location.href = install_path + "index.php?path=" + path + "&filename=" + filename + "&id=" + id  + "&pass=" + pass + "&incflag=" + incflag;

} //last for editThis


//These functions show or hide the editbuttons.	
function show(x)
{ 
	classChange('block');
}

function hide(x)
{
   	classChange('none');
}

function classChange(change) {
	for (i=0; i < document.getElementsByTagName('div').length; i++) {
		if (document.getElementsByTagName('div').item(i).className == 'editbut'){
			document.getElementsByTagName('div').item(i).style.display = change;
		}
	}
}

//setFileName puts on the default document name, if the URL ends in /
function setFileName() {

var pattern = /\/$/;
if (pattern.test(path)) {
	//If the path ends in /, we load the filename as default_document.
	filename = default_document;
	} else {
	filename = (path.slice(path.lastIndexOf('/') + 1));
	}
return filename;
		
}

function processCon(newcontent){

document.contentHolder.newContent.value = editorarea.value;
			if (debug != "TRUE"){
					contentHolder.submit();
			}

}