function init(p,imgPath) {
  nav(p,imgPath);
  getcontent_height;
  set_scroll();
}

iens6=document.all||document.getElementById
ns4=document.layers

//specify speed of scroll (greater=faster)
var slow_speed=5
var fast_speed=10


function moveup(speed) {
  if (iens6&&parseInt(crossobj.style.top)<0) {
    crossobj.style.top=parseInt(crossobj.style.top)+speed+"px"
  } else if (ns4&&crossobj.top<=0) {
    crossobj.top+=speed
  }
  if (speed == fast_speed) {
    moveupvar_f=setTimeout("moveup("+speed+")",20)
  } else {
    moveupvar_s=setTimeout("moveup("+speed+")",20)
  }
}
function movedown(speed) {
  if (iens6&&parseInt(crossobj.style.top)>=(contentheight*(-1)+100)) {
    crossobj.style.top=parseInt(crossobj.style.top)-speed+"px"
  }
  if (speed == fast_speed) {
    movedownvar_f=setTimeout("movedown("+speed+")",20)
  } else {
    movedownvar_s=setTimeout("movedown("+speed+")",20)
  }
}

function getcontent_height(){
  if (iens6) {
    contentheight=crossobj.offsetHeight
  } else if (ns4) {
    document.nscontainer.document.nscontent.visibility="show"
  }
}

function set_scroll() {
  var tempVar = "";

  if (scroll_up = document.getElementById('s_up')) {
    scroll_up.onmouseover = function() {
      tempVar = this.src;
      this.src = "/img/scroll_up_mo.gif";
      moveup(slow_speed);
    }
    scroll_up.onmouseout = function() {
      clearTimeout(moveupvar_s);
      if (tempVar != "") {
        this.src = tempVar;
      }
    }
    scroll_up.onmousedown = function() {
      moveup(fast_speed);
    }
    scroll_up.onmouseup = function() {
      clearTimeout(moveupvar_f);
      if (moveupvar_s !="") {
        clearTimeout(moveupvar_s);
      }
    }
    scroll_up.ondrag = function() {
      clearTimeout(moveupvar_f);
      clearTimeout(moveupvar_s);
      if (tempVar != "") {
        this.src = tempVar;
      }
    }
  }

  if (scroll_down = document.getElementById('s_down')) {
    scroll_down.onmouseover = function() {
      tempVar = this.src;
      this.src = "/img/scroll_down_mo.gif";
      movedown(slow_speed);
    }
    scroll_down.onmouseout = function() {
      clearTimeout(movedownvar_s);

      if (tempVar != "") {
        this.src = tempVar;
      }
    }
    scroll_down.onmousedown = function() {
      movedown(fast_speed);
    }
    scroll_down.onmouseup = function() {
      clearTimeout(movedownvar_f);
      if (movedownvar_s !="") {
        clearTimeout(movedownvar_s);
      }
    }
    scroll_down.ondrag = function() {
      clearTimeout(movedownvar_f);
      clearTimeout(movedownvar_s);
      if (tempVar != "") {
        this.src = tempVar;
      }
    }
  }
}


function isNotEmpty(elem) {
  var str = elem.value;
  if(str == null || str.length == 0)
   return false;
  else
   return true;
}

 // THIS FUNCTION PERFORMS VALIDATION BASED ON A SET OF CUSTOM HTML ATTRIBUTES
function validate(form) {
  var attrVal, attrReg, attrEq, attrFail, strTemp;
  var f = document.forms[0];

  for (var i = 0; i < form.length; i++) {
    attrVal = form[i].getAttribute("validate");

    switch (attrVal) {
      case 'required' :
        if (!isNotEmpty(form[i])) {
          attrFail = form[i].getAttribute("failure");

          if (attrFail)
            alert(attrFail);
          else
            alert('You must complete all required form fields.');

          if (form[i].type != "hidden") {
            form[i].focus();
          }
          return false;
        }
        break;

      case 'regex' :

        attrReg = form[i].getAttribute("regex");

        if (attrReg != null && attrReg.length != 0) {
          var regex = new RegExp(attrReg);
          strTemp = form[i].value;
          if (!strTemp.match(regex)) {
            attrFail = form[i].getAttribute("failure");

            if (attrFail)
              alert(attrFail);
            else
              alert('Invalid data format at field "' + form[i].name + '".');
            if (form[i].type != "hidden") {
              form[i].focus();
            }
            return false;
          }
        }
        break;

      case 'equals' :
        attrEq = form[i].getAttribute("equals");
        var objEq = document.getElementById(attrEq);
        if (objEq) {
          if (form[i].value != objEq.value) {
            attrFail = form[i].getAttribute("failure");

            if (attrFail)
              alert(attrFail);
            else
              alert('Form fields do not match');
            if (form[i].type != "hidden") {
              form[i].focus();
            }
            return false;
          }
        }
        break;
    }

  }

  if (document.getElementById('subButton')) {
    document.getElementById('subButton').disabled = true;
  }
  return true;
}

