/* concentric */
function switchPix(whichImage,imageNumber){
  document.images[whichImage].src = preLoad[imageNumber].src;
}
// from http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
// end


/*-------------------------------------------------
  checkPageForms()
  -------------------------------------------------
  Cycles through the elements of a form. The
  function actually checks for labels with the
  class "required". When a "required" label is
  found, the script checks that a value has been
  filled out for that input.
---------------------------------------------------*/
function checkPageForms(frm, formName){
  var setFocus=false;
  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 = frm.getAttribute('id');
      if(id == null){ id = frm.attributes['id'].value; }
      // 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;
        for(var i=0; i<labels.length;i++){
          var l = labels[i];
          if(l.className == "required" || l.className == "error"){
            //if(typeof(elemID.value) != "undefined"){ elemID = elemID.value; }
            var elemID = l.getAttribute('for');
            if(elemID == null){ elemID = l.attributes['for'].value; }
            var e = document.getElementById(elemID);
            if(e){
              // Process the different input types
              var nodeName = e.nodeName;
              if(nodeName.toLowerCase() == "input"){
                // Input elements
                var eType = e.getAttribute('type');
                if(eType == null){ eType = e.attributes['type'].value; }
                if(eType == "text"){
                  // Text type inputs
                  if(qTrim(e.value) == ""){ 
                    l.className = "error";
                    error = true;
                    if(!setFocus){ e.focus(); setFocus=true; }
                  }
                  else { l.className = "required"; }
                }
              }
              else if(nodeName.toLowerCase() == "select"){
                // Select elements
                var ix = e.selectedIndex;
                var o = qTrim(e.options[ix].value);
                if(o == "#" || o == "-" || o == "" || o == "--" || o == "##"){ 
                  l.className = "error"; 
                  error = true;
                  if(!setFocus){ e.focus(); setFocus=true; }
                }
                else { l.className = "required"; }
              }
              else if(nodeName.toLowerCase() == "textarea"){
                // Textarea elements
                if(qTrim(e.value) == ""){ 
                  l.className = "error"; 
                  error = true;
                  if(!setFocus){ e.focus(); }
                }
                else { l.className = "required"; setFocus=true; }
              }
            }
          }
        }
        if(error){
          alert("There was an error with the form. Please enter a value "+
                "for all the fields marked in red.");
          error = false;
          return false;
        }
      }
      else { return true; }
    }
  }
  return true;
}
/* qTrim() */
function qTrim(value) { return value.replace(/\n/,"").replace(/\r/,"").replace(" ",""); }
