function disableForm(theform) {
	if (document.all || document.getElementById) {
	for (i = 0; i < theform.length; i++) {
		var tempobj = theform.elements[i];
		if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
			tempobj.disabled = true;
		}
		return true;
	}
	else {
		return false;
	}
}

////////////////////

var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {browserType= "gecko"}

////////////////////////////////////

function addPollOption() {
var poll_ni = document.getElementById('pollOptionsDiv');
var poll_numi = document.getElementById('pollCounterValue');
var poll_num = (document.getElementById("pollCounterValue").value -1)+ 2;
poll_numi.value = poll_num;
var poll_divIdName = "pollOption"+poll_num;
var poll_newdiv = document.createElement('div');
poll_newdiv.setAttribute("id",poll_divIdName);
poll_newdiv.innerHTML = "<input name=\"poll_options[]\" type=\"text\" size=\"35\" maxlength=\"64\"> <a href=\"javascript:;\" onclick=\"removePollOption(\'"+poll_divIdName+"\')\">Remove option</a><br>";
poll_ni.appendChild(poll_newdiv);
}

function removePollOption(poll_divNum) {
var poll_d = document.getElementById('pollOptionsDiv');
var poll_olddiv = document.getElementById(poll_divNum);
poll_d.removeChild(poll_olddiv);
}


function addAttachOption() {
var attach_ni = document.getElementById('attachmentsDiv');
var attach_numi = document.getElementById('attachmentCounterValue');
var attach_num = (document.getElementById("attachmentCounterValue").value -1)+ 2;
attach_numi.value = attach_num;
var attach_divIdName = "attachOption"+attach_num;
var attach_newdiv = document.createElement('div');
attach_newdiv.setAttribute("id",attach_divIdName);
attach_newdiv.innerHTML = "<input name=\"attachments[]\" type=\"file\"> <a href=\"javascript:;\" onclick=\"removeAttachOption(\'"+attach_divIdName+"\')\">Remove attachment</a><br>";
attach_ni.appendChild(attach_newdiv);
}

function removeAttachOption(attach_divNum) {
var attach_d = document.getElementById('attachmentsDiv');
var attach_olddiv = document.getElementById(attach_divNum);
attach_d.removeChild(attach_olddiv);
}


///////////////////////////////

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setCookie(c_name,value,expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate) + "; path=/";
}

function toggle_nav( do_toggle ) {
	var hide_nav = readCookie("hide_nav");
	
	if( do_toggle ) {
		if ( hide_nav == 1 ) {
			hide_nav = 0;
		}
		else {
			hide_nav = 1;
		}
	}		
	
	//var expiry = new Date();
	//expiry.setFullYear(expiry.getFullYear()+1);
	
	if ( hide_nav == 1 ) {
		hideNav();
		setCookie("hide_nav", 1, 0.5);
		//document.cookie = "hide_nav=1; expires= " + expiry.toGMTString() + "; path=/";
	}
	else {
	 	showNav();
		setCookie("hide_nav", 0, 0.5);
		//document.cookie = "hide_nav=0; expires= " + expiry.toGMTString() + "; path=/";
	}
	
}

function showNav() {
	var tbl;
	
	if (browserType == "gecko" )
   		tbl = document.getElementById('mainTable');
	else (browserType == "ie")
		tbl = document.all['mainTable'];

    var rows = tbl.getElementsByTagName('tr');
	var cels = rows[0].getElementsByTagName('td');
	
	      cels[0].style.display='none';
		  cels[0].style.width='0%';   
		  
	      cels[1].style.display='';
		  cels[1].style.width='15%';  
		  
		  cels[2].style.width='85%';  
}

function hideNav() {
	var tbl;
	
	if (browserType == "gecko" )
   		tbl = document.getElementById('mainTable');
	else (browserType == "ie")
		tbl = document.all['mainTable'];

    var rows = tbl.getElementsByTagName('tr');
	var cels = rows[0].getElementsByTagName('td');
	
	      cels[0].style.display='';
		  cels[0].style.width='1%';  
		  
	      cels[1].style.display='none';
		  cels[1].style.width='0%';  
		  
		  cels[2].style.width='99%';    
}




///////////////////

// allow 

var arrOldValues;

	
function SelectAllList(CONTROL){
	for(var i = 0;i < CONTROL.length;i++){
		CONTROL.options[i].selected = true;
	}
}

function DeselectAllList(CONTROL){
	for(var i = 0;i < CONTROL.length;i++){
		CONTROL.options[i].selected = false;
	}
}


function FillListValues(CONTROL){
	var arrNewValues;
	var intNewPos;
	var strTemp = GetSelectValues(CONTROL);
	
	arrNewValues = strTemp.split(",");
		
	for(var i=0;i<arrNewValues.length-1;i++){
		if(arrNewValues[i]==1){
			intNewPos = i;
		}
	}

	for(var i=0;i<arrOldValues.length-1;i++){
		if(arrOldValues[i]==1 && i !=intNewPos){
			CONTROL.options[i].selected = true;
		}
		else if(arrOldValues[i]==0 && i !=intNewPos){
			CONTROL.options[i].selected = false;
		}
		else {
			CONTROL.options[i].selected = false;
		}
	
		if(arrOldValues[intNewPos] == 1){
			CONTROL.options[intNewPos].selected = false;
		}
		else{
			CONTROL.options[intNewPos].selected = true;
		}
	}	
	
}
	

function GetSelectValues(CONTROL){
	var strTemp = "";
	for(var i = 0;i < CONTROL.length;i++){
		if(CONTROL.options[i].selected == true){
			strTemp += "1,";
		}
		else{
		strTemp += "0,";
		}
	}
	return strTemp;
}

function GetCurrentListValues(CONTROL){
	var strValues = "";
	strValues = GetSelectValues(CONTROL);
	arrOldValues = strValues.split(",")
}



///////////////////////////////////////////////////////////////////////////////////////

function checkTheseBoxes( fieldName, checkedValue, inputIDs ) {
	var theBoxArray = inputIDs.split(',');	
	
	for (i=0; i<theBoxArray.length; i++) {
		var theBoxName = fieldName + "[" + theBoxArray[i] + "]";
		
  		 if (browserType == "gecko" )
     		document.checkBox = eval('document.getElementById(theBoxName)');
 		 else (browserType == "ie")
 		    document.checkBox = eval('document.all[theBoxName]');

		if ( document.checkBox.disabled == false ) {
			document.checkBox.checked = checkedValue;
		}
	}
}	

///////////////////////////////////////////////////////////////////////////////////////////


function hideDiv(component) {
  if (browserType == "gecko" )
     document.poppedLayer = eval('document.getElementById(component)');
  else if (browserType == "ie")
     document.poppedLayer = eval('document.all[component]');
  else
     document.poppedLayer = eval('document.layers[component]');
  document.poppedLayer.style.visibility = "hidden";
}

function showDiv(component) {
  if (browserType == "gecko" )
     document.poppedLayer = eval('document.getElementById(component)');
  else if (browserType == "ie")
     document.poppedLayer = eval('document.all[component]');
  else
     document.poppedLayer = eval('document.layers[component]');
  document.poppedLayer.style.visibility = "visible";
}

var toggleStatus = true;
function toggleDiv(component) {
	if (toggleStatus) toggleStatus = false
	else 				toggleStatus = true;
	
	if(toggleStatus) hideDiv(component)
	else			showDiv(component);
}


/////////////////////////////////////////////////////////////////////////////////////////


function addSelectedToList( sourceList, targetList ) {

	var srcList = document.all(sourceList);
	var tgtList = document.all(targetList);

	var srcLen = srcList.length;
	var tgtLen = tgtList.length;
	var tgt = "x";

	//build array of target items
	for (var i=tgtLen-1; i > -1; i--) {
		tgt += "," + tgtList.options[i].value + ","
	}

	//Pull selected resources and add them to list
	for (var i=0; i < srcLen; i++) {
		if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) {
			opt = new Option( srcList.options[i].text, srcList.options[i].value );
			tgtList.options[tgtList.length] = opt;
		}
	}
}

function removeSelectedFromList( targetList ) {

	var srcList = document.getElementById(targetList);

	var srcLen = srcList.length;

	for (var i=srcLen-1; i > -1; i--) {
		if (srcList.options[i].selected) {
			srcList.options[i] = null;
		}
	}
}

function selectAllInList(targetList, value){
	var theList = document.getElementById(targetList);
	for(var i = 0;i < theList.length;i++){
		theList.options[i].selected = value;
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/*==================================================*
 $Id: filterlist.js,v 1.3 2003/10/08 17:13:49 pat Exp $
 Copyright 2003 Patrick Fitzgerald
 http://www.barelyfitz.com/webdesign/articles/filterlist/

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *==================================================*/

function filterlist(selectobj) {

  //==================================================
  // PARAMETERS
  //==================================================

  // HTML SELECT object
  // For example, set this to document.myform.myselect
  this.selectobj = selectobj;

  // Flags for regexp matching.
  // "i" = ignore case; "" = do not ignore case
  // You can use the set_ignore_case() method to set this
  this.flags = 'i';

  // Which parts of the select list do you want to match?
  this.match_text = true;
  this.match_value = false;

  // You can set the hook variable to a function that
  // is called whenever the select list is filtered.
  // For example:
  // myfilterlist.hook = function() { }

  // Flag for debug alerts
  // Set to true if you are having problems.
  this.show_debug = false;

  //==================================================
  // METHODS
  //==================================================

  //--------------------------------------------------
  this.init = function() {
    // This method initilizes the object.
    // This method is called automatically when you create the object.
    // You should call this again if you alter the selectobj parameter.

    if (!this.selectobj) return this.debug('selectobj not defined');
    if (!this.selectobj.options) return this.debug('selectobj.options not defined');

    // Make a copy of the select list options array
    this.optionscopy = new Array();
    if (this.selectobj && this.selectobj.options) {
      for (var i=0; i < this.selectobj.options.length; i++) {

        // Create a new Option
        this.optionscopy[i] = new Option();

        // Set the text for the Option
        this.optionscopy[i].text = selectobj.options[i].text;

        // Set the value for the Option.
        // If the value wasn't set in the original select list,
        // then use the text.
        if (selectobj.options[i].value) {
          this.optionscopy[i].value = selectobj.options[i].value;
        } else {
          this.optionscopy[i].value = selectobj.options[i].text;
        }

      }
    }
  }

  //--------------------------------------------------
  this.reset = function() {
    // This method resets the select list to the original state.
    // It also unselects all of the options.

    this.set('');
  }


  //--------------------------------------------------
  this.set = function(pattern) {
    // This method removes all of the options from the select list,
    // then adds only the options that match the pattern regexp.
    // It also unselects all of the options.

    var loop=0, index=0, regexp, e;

    if (!this.selectobj) return this.debug('selectobj not defined');
    if (!this.selectobj.options) return this.debug('selectobj.options not defined');

    // Clear the select list so nothing is displayed
    this.selectobj.options.length = 0;

    // Set up the regular expression.
    // If there is an error in the regexp,
    // then return without selecting any items.
    try {

      // Initialize the regexp
      regexp = new RegExp(pattern, this.flags);

    } catch(e) {

      // There was an error creating the regexp.

      // If the user specified a function hook,
      // call it now, then return
      if (typeof this.hook == 'function') {
        this.hook();
      }

      return;
    }

    // Loop through the entire select list and
    // add the matching items to the select list
    for (loop=0; loop < this.optionscopy.length; loop++) {

      // This is the option that we're currently testing
      var option = this.optionscopy[loop];

      // Check if we have a match
      if ((this.match_text && regexp.test(option.text)) ||
          (this.match_value && regexp.test(option.value))) {

        // We have a match, so add this option to the select list
        // and increment the index

        this.selectobj.options[index++] =
          new Option(option.text, option.value, false);

      }
    }

    // If the user specified a function hook,
    // call it now
    if (typeof this.hook == 'function') {
      this.hook();
    }

  }


  //--------------------------------------------------
  this.set_ignore_case = function(value) {
    // This method sets the regexp flags.
    // If value is true, sets the flags to "i".
    // If value is false, sets the flags to "".

    if (value) {
      this.flags = 'i';
    } else {
      this.flags = '';
    }
  }


  //--------------------------------------------------
  this.debug = function(msg) {
    if (this.show_debug) {
      alert('FilterList: ' + msg);
    }
  }


  //==================================================
  // Initialize the object
  //==================================================
  this.init();

}
