// showhide.js

   function setFocus() 
   {
     var d=document.rfp;
     d.fname.focus();
   }

   function exp_coll(ind)
   {
      s = document.getElementById("sp_" + ind);
      if (s.style.display == 'none')
      {
        s.style.display = 'block';
      }
        else if (s.style.display == 'block')
             {
               s.style.display = 'none';
             }
   }

  function isBlank(s) {
    var len=s.length
    var i
    for (i=0;i<len;i=i+1) {
      if(s.charAt(i)!=" ")
        return false }
    return true
    }

  function check_fname() {
    var d=document.rfp.fname;
    if (isBlank(d.value) || d.value == 'null' || d.value=='undefined' ) {
      var reply=prompt("First Name is Required")
      document.rfp.fname.value=reply;
 //   return false;
    }
    else
      return true}

  function check_descript() {
    var d=document.rfp.descript;
    if (isBlank(d.value) || d.value == 'null' || d.value=='undefined' ) {
      alert('Project Description is Required');
      document.rfp.descript.focus();
      return false;
    }
    else
      return true}

  function check_reason() {
    var d=document.rfp.reason;
    if (isBlank(d.value) || d.value == 'null' || d.value=='undefined' ) {
      alert('Reason for this Project is Required');
      document.rfp.reason.focus();
      return false;
    }
    else
      return true}

  function check_lname() {
    var d=document.rfp.lname;
    if (isBlank(d.value) || d.value == 'null' || d.value=='undefined') {
      var reply=prompt("Last Name is Required")
      document.rfp.lname.value=reply;
      }
    else
      return true}

  function check_addr() {
    var d=document.rfp.address;
    if (isBlank(d.value)  || d.value == 'null' || d.value=='undefined') {
      var reply=prompt("Campus Address is Required")
      document.rfp.address.value=reply;
      }
    else
      return true}

  function check_phone() {
    var d=document.rfp.phone;
    if (isBlank(d.value)  || d.value == 'null' || d.value=='undefined') {
      var reply=prompt("Campus Phone Number is Required")
      document.rfp.phone.value=reply;
    }
    else
      return true}

  function check_dept() {
    if (document.rfp.dept.selectedIndex==0) {
      if (check_deptManual() ) {
        return true;
      } else
            { 
              alert('Department is required');
              document.rfp.dept.focus();
              return false
            }
    }
    else
      return true;
  }

  function check_deptManual() {

    if (!isBlank(document.rfp.dept_manual.value)) {
       return true;
    }
  }


  function check_dhead() {
    var d=document.rfp.dhead;
    if (isBlank(d.value) || d.value == 'null' || d.value=='undefined') {
      var reply=prompt("Department Head Name is Required")
      document.rfp.dhead.value=reply;
    }
    else
      return true}

  function isValid(p,v) {
     if (p.value=="") {
        alert('Number of Students Required');
        p.focus();
        return false;
     }
     for (i=0;i<p.value.length;i++) {
        if(v.indexOf(p.value.charAt(i),0)==-1) return false;
     }
     return true;
  }

  function check_num_impact() {
    p=document.rfp;
    if (p.numstu.value=='' && (p.impact.value=='Describe here' || isBlank(p.impact.value)) ) 
    {
         alert('Please enter number of students or potential impact');
         p.numstu.focus();
         return false;
    } else {
             if (p.impact.value=='Describe here' || isBlank(p.impact.value) )
             {

                   if (isNaN(p.numstu.value)) 
                   {
                           alert('Invalid Number of Students');
                           p.numstu.focus();
                           return false;
                   }  else return true;

             } else return true; 
           }
    
  }

  function check_number() {
     p=document.rfp;
     if (p.impact.value!='Describe here' || !isBlank(p.impact.value))
     {
                    if(isNaN(p.numstu.value)) {
                           alert('Invalid Number of Students - leave blank if not applicable');
                           p.numstu.focus();
                           return false;
                   }  else return true;
                   if (p.numstu.value=='') return true;                              

     } else return true;
  }


  function check_courseInfo() {
    var d=document.rfp.course_info;
    if (isBlank(d.value) || d.value == 'null' || d.value=='undefined') {
      var reply=prompt("Course Number and Name is Required")
      document.rfp.course_info.value=reply;
    }
    else
      return true}

  function check_email() {
      var e=document.rfp.email;
      var invalidChars=" /:,;";
      var bad=0;
      if (e.value=='') { bad=1; }
      for (i=0; i<invalidChars.length; i++) {
        badChar=invalidChars.charAt(i)
        if (e.value.indexOf(badChar,0) > -1) {
           bad=1;
        }
      }

      atPos = e.value.indexOf("@",1)
      if (atPos == -1) { bad=1; }
      if (e.value.indexOf("@",atPos+1) != -1) { bad=1; }
 
      periodPos = e.value.indexOf(".",atPos)
      if (periodPos == -1) { bad=1; }
      if (periodPos+3 > e.length) { bad=1; }
      
      if (bad==0) 
      {
        return true
      }
       else {
              alert('Invalid Email Address, please re-enter')
              e.focus()
              return false
            }
  }

  function check_cemail() {
      if (document.rfp.cemail.value != document.rfp.email.value) {
          alert('Check Your Confirm Email Address')
          document.rfp.cemail.focus()
          return false}
      else
         return true
  }

  function check_cms110() 
  {
     var count=0;
     for (i=0; i<document.rfp.cms110.length; i++) 
     {
       if (document.rfp.cms110[i].checked) 
       {
         count++;
       }
     }
     if (count == 0) 
     {
        alert('Taken CMS110?')
        document.rfp.dhead.focus()
        return false 
     }
     else {
            return true
          } 
  }

  function check_hosted() 
  {
     var count=0;
     for (i=0; i<document.rfp.hosted.length; i++) 
     {
       if (document.rfp.hosted[i].checked) 
       {
         count++
       }
     }
     if (count == 0) 
     {
        alert('Materials on Web?')
        document.rfp.course_info.focus()
        return false 
     }
     else {
            return true
          }
  }

  function check_online() 
  {
     var count=0;
     for (i=0; i<document.rfp.online.length; i++) 
     {
       if (document.rfp.online[i].checked) 
       {
         count++
       }
     }
     if (count == 0) 
     {
        alert('Materials on Blackboard?')
        document.rfp.hosted[0].focus()
        return false 
     }
     else {
            return true
          }
  }

  function check_category() 
  {
     var count=0;
     var d=document.rfp;
     for (i=0; i<d.category.length; i++) 
     {
       if (d.category[i].checked) 
       {
         count++
         if (d.category[i].value=='0' && ((isBlank(d.cat_other_desc.value)) || d.cat_other_desc.value=='Describe here')) {
             alert('Please describe your particular need');
             d.cat_other_desc.focus();
             return false;
         } 
       }
     }
     if (count == 0) 
     {
        alert('Please Select a Category.')
        d.online[0].focus()
        return false 
     }
     else {
            return true
          }
  }

  function check_othercat()
  {
     var count=0;
     var d=document.rfp;
     if (d.cat_other_desc.value != '') {
       for (i=0; i<d.category.length; i++)
       {
          if (d.category[i].value=='0' && d.category[i].checked)
          {
             count++;
          }
          if (d.category[i].value=='0' && (!d.category[i].checked) && d.cat_other_desc.value=='Describe here') {
               count++;
          }
       }
       if (count == 0) {
              alert("Please select 'I need assistance with..', if applicable, or erase text.");
              d.online[0].focus();
              return false;
       } else return true;
     }
     return true;
  }

  function check_criteria() 
  {
     var count=0;
     for (i=0; i<document.rfp.criteria.length; i++) 
     {
       if (document.rfp.criteria[i].checked) 
       {
         count++
       }
     }
     if (count == 0) 
     {
        alert('Please Select a Criteria.')
        document.rfp.category[0].focus()
        return false 
     }
     else {
            return true
          }
  }

  function check_terms() 
  {
     var count=0;
     var d=document.rfp;
     for (i=0; i<d.terms.length; i++) 
     {
       if (d.terms[i].checked) 
       {
         count++
         if (d.terms[i].value=='Other') {
            if (isBlank(d.otherterm.value)) {
              alert('Please specify other, if applicable, or uncheck box.');
              d.otherterm.focus();
              return false;
           } 
         }
       }
     }
     if (count == 0) 
     {
        alert('Please Select Term(s) Course Offered.')
        document.rfp.terms[0].focus()
        return false 
     }
     else {
            return true
          }
  }

  function check_other()
  {
//alert('here');
     var count=0;
     var d=document.rfp;
     if (d.otherterm.value != '') {
       for (i=0; i<d.terms.length; i++)
       {
          if (d.terms[i].value=='Other' && d.terms[i].checked) 
          {
             count++;
          }
       }
       if (count == 0) {
              alert("Please check 'Other', if applicable, or erase text.");
              d.otherterm.focus();
              return false;
       } else return true;
     }  return true;
  }

  function check_certify() 
  {
       document.confirm.scode.value='uy740G5F*^fe5dlk';
       var go='no';
       if (document.confirm.certify.checked) 
     {
        go='yes';
     }
     else {
            var returnValue=window.confirm('Click OK to certify information is correct and SUBMIT application, otherwise click Cancel');
            if (returnValue)
            {
              document.confirm.certify.checked=true;
              go='yes'
            }
               else
                    {
                       document.confirm.certify.focus()
                    }
           }
     if (go == 'yes') { document.confirm.submit(); }
  }

  function validate_form()
  {
      if (               
          check_fname() &&
          check_lname() &&
          check_addr() &&
          check_phone() &&
          check_email() &&
          check_cemail() &&
          check_dept() &&
          check_dhead() &&
          check_cms110() &&
          check_courseInfo() &&
          check_hosted() &&
          check_online() &&
          check_category() &&
          check_othercat() &&
          check_criteria() &&
          check_descript() &&
          check_reason() &&
          check_num_impact() &&
          check_number() &&
          check_terms()  &&
          check_other()  ) {
             document.rfp.code.value='ji67D6k*vyt8%#9';
             document.rfp.submit();
       }
  }

  function enableAssistance()
  {
    if (document.rfp.cat_other_desc.value == 'Describe here') {
       document.rfp.cat_other_desc.disabled=false;
       document.rfp.cat_other_desc.value='';
    }
  }

  function doClear(theText) {
     if (theText.value == theText.defaultValue)
        {
         if (theText.value == 'Describe here') {
           theText.value = ""
         }
        }
  }
  
  
  //added 9/28/05
  
  function imgOn (img) {
  var curimg = 'arrow'+img;
  //var imgsrc = document.eval(curimg).src;
  var imgsrc  = 'document.'+curimg+'.src';
  var imgname = 'document.'+curimg;
  if (eval(imgsrc).indexOf("uarrow") > 0) {
    eval(imgname).src =  "/images/darrow.gif";
  }else{
    eval(imgname).src =  "/images/uarrow.gif";
    //document.eval(curimg).src =  "../../images/uarrow.gif";
  }
  exp_coll(img);
}
//end of added 9/28/05

// end of showhide.js
