var cancelForm = false;

//maked all added functions work onload. at the end of each function you want to work onload add addLoadEvent(function); to the end of the function.
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

//assign colored rows to members section
function assignRowColor() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById('mmbrs')) return false;
	ulList = document.getElementById('mn').getElementsByTagName('ul');
	for (var i=0; i<ulList.length; i++) {
		if (i % 2 == 0) {
			ulList[i].className = 'wht'
		} else {
			ulList[i].className = 'brwn'
		}
	}
}
addLoadEvent(assignRowColor);

//scroolbar on homepage
function hideScrollBar() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById('cntntcpy')) return false;
	var cpyHght = document.getElementById("cntntcpy").offsetHeight;
	if (cpyHght > 171) {
		document.getElementById("scrllbr").style.display = 'block';
	}
}
addLoadEvent(hideScrollBar);

var timerID = null;
var pos = 0;
function sliderUp() {
	if ((pos * -1) > 0) {
		pos = eval(pos + 15);
	}
	if (document.getElementById) {
		document.getElementById("cntntcpy").style.top =	pos+"px";
	}
	timerID = window.setTimeout('sliderUp()',100);
}

function sliderDn() {
	if ((pos * -1) < (document.getElementById("cntntcpy").offsetHeight - 102)) {
		pos = eval(pos - 15);
	}
	if (document.getElementById) {
		document.getElementById("cntntcpy").style.top = pos+"px";
	}
	timerID = window.setTimeout('sliderDn()',100);
}


function terminateTimer() {
    window.clearTimeout(timerID);
}

/*--------------------------------------------------------------
  getAttribute()
  
  A crossbrowser way to get an attribute from an element.
  
  Arguments:
    elem      the element reference
    attr      a string for the attribute name
 */
function getAttribute(elem,attr){
  if(elem.getAttribute){
    a = elem.getAttribute(attr);
    if(a != null){ return a; }
  }
  if(elem.attributes && elem.attributes[attr]){ return elem.attributes[attr].value; }
  for(var i=0;i<elem.attributes.length;i++){
    if(elem.attributes[i].specified){
      if(elem.attributes[i].name == attr){ return elem.attributes[i].value; }
    }
    else { return elem.attributes[i]; }
  }
  return null;
}

/*--------------------------------------------------------------
  checkPageForms()
 */
function checkPageForms(frm, formName){
  if(!cancelForm){
    // Check if the form element exists
    if(!frm){ return false; }
    // Browser must pass this basic test to proceed
    if(document.getElementById){
      var id = getAttribute(frm,'id');
      // If a form name is passed to this function, then
      // it must equal the value of the ID of this form
      // (this is so multiple forms can be checked on a
      // single page)
      if(id == formName || formName == ""){
        var labels = frm.getElementsByTagName('label');
        var error  = false;
        var eFocus = null;
        var titles = "";
        for(var i=0; i<labels.length;i++){
          var l = labels[i];
          if(l.className.indexOf('required') >= 0 || l.className.indexOf('error') >= 0){
            var elemID = getAttribute(l,'for');
            var e = document.getElementById(elemID);
            if(e){
              // Process the different input types
              var nodeName = e.nodeName;
              if(nodeName.toLowerCase() == "input"){
                // Input elements
                var eType = getAttribute(e,'type');
                if(eType == "text"){            // TEXT
                  if(qTrim(e.value) == ""){
                    // found an error
                    l.className = "error";
                    error = true;
                    e.className += " error";
                    var t = getAttribute(e,'title');
                    if(t){ titles += "\n  - "+ t; }
                    if(eFocus == null){ eFocus = e; }
                  }
                  else { l.className = "required"; }
                }
								else if(eType == "password"){    // PASSWORD
                  if(qTrim(e.value) == ""){ 
                    // found an error
                    l.className = "error"; 
                    error = true;
                    var t = getAttribute(e,'title');
                    if(t){ titles += "\n  - "+ t; }
                    if(eFocus == null){ eFocus = e; }
                  }
                  else { l.className = "required"; }
                }
                else if(eType == "radio"){      // RADIO BUTTONS
                  if(!e.checked){ 
                    l.className="error"; 
                    error = true;
                    var t = getAttribute(e,'title');
                    if(t){ titles += "\n  - "+ t; }
                    if(eFocus == null){ eFocus = e; }
                  }
                  else { l.className = "required"; }
                }
                else if(eType == "file"){            // FILE
                  if(qTrim(e.value) == ""){
                    // found an error
                    l.className = "error";
                    error = true;
                    e.className += " error";
                    var t = getAttribute(e,'title');
                    if(t){ titles += "\n  - "+ t; }
                    if(eFocus == null){ eFocus = e; }
                  }
                  else { l.className = "required"; }
                }
              }
              else if(nodeName.toLowerCase() == "select"){  // SELECT
                // Select elements
                var ix = e.selectedIndex;
                var o = qTrim(e.options[ix].value);
                if(o == "#" || o == "-" || o == "" || o == "--" || o == "##"){
                  // found an error
                  l.className = "error"; 
                  error = true;
                  var t = getAttribute(e,'title');
                  if(t){ titles += "\n  - "+ t; }
                  if(eFocus == null){ eFocus = e; }
                }
                else { l.className = "required"; }
              }
              else if(nodeName.toLowerCase() == "textarea"){  // TEXTAREA
                // Textarea elements
                if(qTrim(e.value) == ""){ 
                  // found an error
                  l.className = "error"; error = true;
                  var t = getAttribute(e,'title');
                  if(t){ titles += "\n  - "+ t; }
                  if(eFocus == null){ eFocus = e; }
                }
                else { l.className = "required"; }
              }
            }
          }
        }
        if(error){
          if(eFocus != null){ eFocus.focus(); }
          if(titles == ""){
            alert("There was an error with the form. Please enter a value "+
                  "for all the fields marked in red.");
          }
          else { 
            alert("There was an error with the form. Please enter a value "+
                  "for all the following fields (marked in red):\n"+titles);
          }
          error = false;
          return false;
        }
      }
      else { return true; }
    }
  }
  return true;
}

/*--------------------------------------------------------------
  qTrim()
 */
function qTrim(value) { return value.replace(/\n/,"").replace(/\r/,"").replace(" ",""); }