pde={
  // CSS classes
  pdeClass:'classTree',
  hideClass:'closed',
  showClass:'open',
  parentClosedClass:'parentClosed',
  parentOpenClass:'parentOpen',
  liDoc:'doc',
  currentClass:'current',
  // images added to the parent links
  openImage:'images/mygallery/folderopen.gif',
  closedImage:'images/mygallery/folderopen.gif',
  openMessage:'close section',
  closedMessage:'open section',
	prevSel:'',

  init:function(){
    if(!document.getElementById || !document.createTextNode){return;}
    var uls=document.getElementsByTagName('ul');
    for(var i=0;i<uls.length;i++){
			var inneruls,parentLI;
			if(!pde.cssjs('check',uls[i],pde.pdeClass)){continue;}
			var inneruls=uls[i].getElementsByTagName('ul');
			for(var j=0;j<inneruls.length;j++){
				parentLI=inneruls[j].parentNode;
				if(parentLI.getElementsByTagName('strong')[0]){
					pde.cssjs('add',parentLI,pde.currentClass);
					continue;
				}
        pde.cssjs('add',parentLI,pde.parentOpenClass);
        pde.parentTitle('add',parentLI,pde.closedMessage);
        pde.cssjs('add',inneruls[j],pde.hideClass);
        pde.addEvent(parentLI.getElementsByTagName('a')[0],'click',pde.showhide);
      }
    }
  },
  showhide:function(e){
    var elm=pde.getTarget(e);
    var ul=elm.parentNode.getElementsByTagName('ul')[0];
    var parentLI=elm.parentNode;
    if(pde.cssjs('check',ul,pde.hideClass)){
      pde.cssjs('remove',elm.parentNode.getElementsByTagName('ul')[0],pde.hideClass);
      pde.cssjs('add',elm.parentNode.getElementsByTagName('ul')[0],pde.showClass);
      pde.parentTitle('swap',parentLI,pde.openMessage,pde.closedMessage);
      pde.cssjs('swap',parentLI,pde.parentClosedClass,pde.parentOpenClass);
    } else {
      pde.cssjs('remove',elm.parentNode.getElementsByTagName('ul')[0],pde.showClass);
      pde.cssjs('add',elm.parentNode.getElementsByTagName('ul')[0],pde.hideClass);
      pde.parentTitle('swap',parentLI,pde.closedMessage,pde.openMessage);
      pde.cssjs('swap',parentLI,pde.parentOpenClass,pde.parentClosedClass);
    }
    pde.cancelClick(e);
  },
/* helper methods */
  getTarget:function(e){
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target){return false;}
    if (target.nodeName.toLowerCase() != 'a'){target = target.parentNode;}
    return target;
  },
  cancelClick:function(e){
    if (window.event){
      window.event.cancelBubble = true;
      window.event.returnValue = false;
      return;
    }
    if (e){
      e.stopPropagation();
      e.preventDefault();
    }
  },
	addEvent : function(o, n, f) {
		if (o.attachEvent)
			o.attachEvent('on' + n, f);
		else if (o.addEventListener)
			o.addEventListener(n, f, false);
		else
			o['on' + n] = f;
	},
  cssjs:function(a,o,c1,c2){
    switch (a){
      case 'swap':
        o.className=!pde.cssjs('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
      break;
      case 'add':
        if(!pde.cssjs('check',o,c1)){o.className+=o.className?' '+c1:c1;}
      break;
      case 'remove':
        var rep=o.className.match(' '+c1)?' '+c1:c1;
        o.className=o.className.replace(rep,'');
      break;
      case 'check':
        return new RegExp("(^|\s)" + c1 + "(\s|$)").test(o.className)
      break;
    }
  },
  parentTitle:function(a,o,c1,c2){
    switch (a){
      case 'swap':
        o.title=!pde.parentTitle('check',o,c1)?o.title.replace(c2,c1):o.title.replace(c1,c2);
      break;
      case 'add':
        if(!pde.parentTitle('check',o,c1)){o.title+=o.title?' '+c1:c1;}
      break;
      case 'remove':
        var rep=o.title.match(' '+c1)?' '+c1:c1;
        o.title=o.title.replace(rep,'');
      break;
      case 'check':
        return new RegExp("(^|\s)" + c1 + "(\s|$)").test(o.title)
      break;
    }
  },
	showFiles : function (fList,o) {
		document.getElementById("fileList").innerHTML = fList;
		pde.prevSel = '';
	},
	selectFile : function (fName) {
		if(pde.prevSel != '') { pde.prevSel.className="imgfile"; }
		fName.className="selImg";
		pde.prevSel = fName;
		document.getElementById("selImg").value = fName.id;
	}
}

	// list item hover
	function li_over() {
		if (this.className != 'highlightOff') {
			this.className   = 'highlightOver';
		}
	}
	// list item out
	function li_out() {
		if (this.className != 'highlightOff') {
			this.className   = 'highlightOn';
		}
	}
	// list item down
	function li_down() {
		if (this.className != 'highlightOff') {
			this.className = 'highlightOff';
		}
	}
	// list item click
	function li_click() {		
		x = document.getElementById('fileList').getElementsByTagName('li');  // Change name of ID here if different
		y = document.getElementById('fileSelect')														 // Change name of hidden filename field here if different
		z = document.getElementById('renameFile')														 // Change name of rename field here if different
		for (var i = 0; i < x.length; i++) {
			if(x[i] == this) {
				z.value = y.value = x[i].innerHTML;
			} else if (x[i].className == 'highlightOff') {
				x[i].className = 'highlightOn';
			}
		}		
	}	

	function changeClass() {
		var args = changeClass.arguments;
		if (args[0] == 0 || args[0] == 1) { // 0 = no resizeDialogToContent; 1 = resizeDialogToContent
			var start = 1;
		} else {
			var start = 0;
		}

		for(var i = start; i < args.length; i += 2) {
			if(document.getElementById(args[i]) != null) {
				document.getElementById(args[i]).className = args[i+1];
			}
		}
		// resize dialog to content
		if (args[0] == 1) {
			resizeDialogToContent();
		}
	}


///////////////////////////////////////////////////
///    JavaScript Form Validation Functions      //
//   by James Heinrich <info@silisoftware.com>   //
//   available at http://www.silisoftware.com   ///
///////////////////////////////////////////////////
///                                              //
//  v1.0.3 - 17 Mar 2005                         //
//    ¤ Added IsValidHexColor() function         //
//                                               //
//  v1.0.2 - 07 Mar 2005                         //
//    ¤ Added CharacterReplace() function        //
//                                               //
//  v1.0.1 - 12 Dec 2004                         //
//    ¤ Added generic MatchesPattern() function  //
//      and made IsValidEmail() and IsValidURL() //
//      work through it                          //
//                                               //
//  v1.0.0 - 11 Dec 2004                         //
//    ¤ Initial public release                   //
//                                              ///
///////////////////////////////////////////////////

// ex: <input type="text" name="Name"  onKeyUp="RemoveInvalidChars(this, '[^A-Za-z0-9 \-]');">
// ex: <input type="text" name="Email" onKeyUp="RemoveInvalidChars(this, '[^A-Za-z0-9 \@\.\-]'); ForceLowercase(this);">
// ex: <input type="submit" value="Submit" onClick="if (!IsValidEmail(theform.email.value)) { alert("Please enter a valid E-mail address"); theform.email.focus(); return false; } else if (!IsValidURL(theform.url.value)) { alert("Please enter a valid URL"); theform.url.focus(); return false; }">

// Note: onChange event will not fire in IE if onKeyUp event returns true, so add a return false, like this:
// <input type="text" onKeyUp="RemoveInvalidChars(this, '[^A-Za-z0-9 \-]'); return false;" onChange="doSomethingElse();">

function RemoveInvalidChars(theinput, pattern) {
	reg = new RegExp(pattern, 'g');
	newstring = theinput.value.replace(reg, '');
	// only update the input if invalid chars have been replaced
	// to avoid annoying behavior (e.g. moving cursor to end of text)
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}

function ForceUppercase(theinput) {
	// ex: <input type="text" onKeyUp="RemoveInvalidChars(this, '[^A-Za-z0-9 \-]');">
	newstring = theinput.value.toUpperCase();
	// only update the input if invalid chars have been replaced
	// to avoid annoying behavior (e.g. moving cursor to end of text)
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}

function ForceLowercase(theinput) {
	newstring = theinput.value.toLowerCase();
	// only update the input if invalid chars have been replaced
	// to avoid annoying behavior (e.g. moving cursor to end of text)
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}

function CharacterReplace(theinput, from, to) {
	newstring = theinput.value.replace(from, to);
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}

function FormatPhoneNumber(theinput) {
	reg = new RegExp('[^0-9]', 'g');
	numbersonly = theinput.value.replace(reg, '');

	if (numbersonly.length > 7) {
		newstring = '(' + numbersonly.substr(0, 3) + ')' + numbersonly.substr(3, 3) + '-' + numbersonly.substr(6, 4);
	} else if (numbersonly.length > 3) {
		newstring = numbersonly.substr(0, 3) + '-' + numbersonly.substr(3, 4);
	} else {
		newstring = numbersonly;
	}
	// only update the input if the text has changed
	// to avoid annoying behavior (e.g. moving cursor to end of text)
	if (newstring != theinput.value) {
		theinput.value = newstring;
	}
	return true;
}

function MatchesPattern(theString, pattern) {
	// Note: regular expressions passed to this function that have escaped
	// characters also need the escape character escaped, otherwise JavaScript
	// will make it disappear, for example:
	// MatchesPattern(mystring, '\w\.\w');    // won't work
	// MatchesPattern(mystring, '\\w\\.\\w'); // will work
	reg = new RegExp(pattern, 'g');
	return Boolean(reg.exec(theString));
}

function IsValidEmail(emailstring) {
	// regex adapted from http://www.yxscripts.com/fg/form.html
	return MatchesPattern(emailstring, '\\w[\\w\\-\\.]*\\@\\w[\\w\\-]+(\\.[\\w\\-]{2,})+');
}

function IsValidURL(urlstring) {
	return MatchesPattern(urlstring, 'http:\\/\\/[\\w\\-]+(\\.[\\w\\-]+)+');
}

function IsValidHexColor(urlstring) {
	return MatchesPattern(urlstring, '^#[0-9a-zA-Z]{6}$');
}

function SetElementTextColor(theelement, thecolor) {
	if (theelement.style) {
		theelement.style.color = thecolor;
	}
	return true;
}

function HighlightThis(theelement) {
	if (theelement.style) {
		theelement.style.background = '#FFFF00';
	}
	return true;
}

function UnHighlightThis(theelement) {
	if (theelement.style) {
		theelement.style.background = '#FFFFFF';
	}
	return true;
}

function StringPad(string, length, character) {
	while (string.length < length) {
  		string = character + string;
	}
 	return string;
}

function RGB2hex(red, green, blue) {
	r = StringPad(parseInt(red).toString(16),   2, '0');
 	g = StringPad(parseInt(green).toString(16), 2, '0');
	b = StringPad(parseInt(blue).toString(16),  2, '0');
	return r+g+b;
}


///////////////////////////////////////////////////
// getElementsByClassName by Stuart Colville
// http://muffinresearch.co.uk/archives/2006/04/29/getelementsbyclassname-deluxe-edition/
///////////////////////////////////////////////////
/*
v1.03 Copyright (c) 2006 Stuart Colville
http://muffinresearch.co.uk/archives/2006/04/29/getelementsbyclassname-deluxe-edition/

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial 
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
IN THE SOFTWARE.
*/
  
function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;    
  var objColl = objContElm.getElementsByTagName(strTag);
  if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
  var arr = new Array();                              
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';   
  var arrClass = strClass.split(delim);    
  for (var i = 0, j = objColl.length; i < j; i++) {                         
    var arrObjClass = objColl[i].className.split(' ');   
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (var k = 0, l = arrObjClass.length; k < l; k++) {
      for (var m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if ((delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr.push(objColl[i]); 
          break comparisonLoop;
        }
      }
    }
  }
  return arr; 
}

// To cover IE 5 Mac lack of the push method
// Array.prototype.push = function(value) {this[this.length] = value; };