function navigate(number) {
    var arr = $('step1', 'step2', 'step3', 'step3');
    
    if(window.location.href.indexOf('request.jsp')>=0) {
      window.location = "request.html?newRequest=1";
      return
    }
    if(number==-1) {
      number = document.getElementById('step').value;
    }
    if(number==1){
      var titleList = document.getElementById('title1').options;
      var title = document.getElementById('selectedTitle').value.substring(0,5);
      
      for(i=0;i<titleList.length;i++) {
            if(titleList[i].value.indexOf(title)>=0) {
              titleList.selectedIndex=i;
            }
      }
    }
    if(number==null) {
      window.location = "request.html?newRequest=1";
      return
    }
    if(number==2){
      window.location = "request.html?requestComplete=1";
      return
    }
    if(number==3) {
      number=2;
    }
    arr.each(function(el){
            if(el.hasClassName("show")) el.removeClassName("show");
            if(el.hasClassName("hide") == false) el.addClassName("hide");
    });
    arr[number].toggleClassName("hide");
    
    var crumb = $$('#fmCrumb li');
    crumb.each(function(item,index){
            if(item.hasClassName("active")) item.removeClassName("active");
            if(index < number) item.addClassName("filled");
    });
    crumb[number].addClassName("active");
}


function validateForms() {
  var step = $("step");
  var currentStep;
  var isValid = false;
  var msg = $("submitErrorMessage");
  
  if(step == null) {
    currentStep = 0;
  } else {
   currentStep = step.value;
  }
  
  if(currentStep==0){
    isValid = vStepOne();
    message = 'No Literature Selected';
  } else if(currentStep==1){
    isValid = vStepTwo();
    message = 'Invalid Entries Found';
  }
  if(isValid) {
    return true;
  }
  
  msg.update(message).setStyle({ color:'red'});
  msg.className = 'filled';
  return false;
}

/* VALIDATE */
/* step 1 */
function vStepOne(){
	var el = document.getElementById('step1');
        var items = el.getElementsByTagName('select');
        var countActive = 0;
	var isValid = false;
        
        for (var i=0;i<items.length;i++) {
            if(items[i].value>0) {
              isValid = true;
              break;
            }
        }
        return isValid;
}

function vStepTwo() {
	var el = $$('#step2 .txt');
	var countActive = 0;
	var isValid = true;

	el.each(function(item){
		if(item.hasClassName("hide")){
		  // do not validate item if not showing
		} else { //validate below
                        if (item.down("input") && item.down("input").name.indexOf('contact')>=0) {
                          var str = (item.down("input")&&item.innerHTML.indexOf("*")>=0)?item.down("input").value:"not required";
                          
                          if(str.length < 2) {
                            if(item.down(".isValid")) {
                              item.down(".isValid").update("Entry Required").setStyle({ color:'red'});
                              isValid = false;
                            }
                          } else {
                            if(item.down(".isValid")) {
                              item.down(".isValid").update("").setStyle({ color:'red'});
                            }
                          }
                          
                          if(item.innerHTML.indexOf('contact.emailConfirm')>=0) {
                            var email1 = $("email");
                            var email2 = $("emailConfirm");
                            
                            if(email1.value != email2.value) {
                              if(item.down(".isValid")) {
                                item.down(".isValid").update("Emails not Matching").setStyle({ color:'red'});
                                isValid = false;
                              }
                            }
                          }
                          if(item.down("input").name.indexOf('contact')>=0)
                          countActive++;
                        }
		}
	});
	if(countActive == 0) {
          alert("do not pass go until you add valid data");
          isValid = false;
	}
        return isValid;
}


