// 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 close_coll(ind)
   {
      s = document.getElementById("sp_" + ind);
      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_cname() {
    var d=document.rfp.cname;
    if (isBlank(d.value) || d.value == 'null' || d.value=='undefined' ) {
      var reply=prompt("Company Name is Required")
      document.rfp.cname.value=reply;
  //    return false;
    }
    else
      return true}

  function check_comments() {
    var d=document.rfp.comments;
    if (isBlank(d.value) || d.value == 'null' || d.value=='undefined' ) {
      alert('Please submit your comments');
      document.rfp.comments.focus();
      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_address() {
    var d=document.rfp.addr;
    if (isBlank(d.value)  || d.value == 'null' || d.value=='undefined') {
      var reply=prompt("Address is Required")
      document.rfp.addr.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_ph() {
    var d=document.rfp.ph;
    if (isBlank(d.value)  || d.value == 'null' || d.value=='undefined') {
      var reply=prompt("Phone Number is Required")
      document.rfp.ph.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_numstu() {
    var numb='0123456789';
    p=document.rfp.numstu;
    if (p.value=='') {
        alert('Number of Students Required');
        p.focus();
        return false;
    }
    for (i=0;i<p.value.length;i++) {
       if(numb.indexOf(p.value.charAt(i),0)==-1) {
        alert('Invalid Number of Students');
        p.focus();
        return false;
       }
    }
    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_eml() {

      var e=document.rfp.eml;
      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_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=='Please describe your particular need')) {
             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=='Please describe your particular need') {
               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_numstu() &&
          check_terms()  &&
          check_other()  ) {
             document.rfp.code.value='ji67D6k*vyt8%#9';
             document.rfp.submit();
       }
  }

  function validate_maillist()
  {
      if (
          check_fname() &&
          check_lname() &&
          check_boxes() &&
          check_focus_solutions() &&
          check_WRAP_tme() &&
          check_eml2()  ) { 
             return true; }
          else { return false; }
  }

  function validate_foodlist()
  {
      if (
          check_fname() &&
          check_lname() &&
          check_cname() &&
          check_focus_solutions() &&
          check_WRAP_tme() &&
          check_eml2()  ) {
             return true; }
          else { return false; }
  }


  function validate_monthUpd()
  {
      if (
          check_fname() &&
          check_lname() &&
          check_find()  &&
          check_boxes() &&
          check_focus_solutions() &&
          check_WRAP_tme() &&
          check_eml2()  ) {
             return true; }
          else { return false; }
  }

  function check_find() {
    if (document.rfp.find.selectedIndex==0) {
         alert('How did you find out about us?');
         document.rfp.find.focus();
         return false
    }
    else return true;
  }



  function validate_contact()
  {
      if (
          check_fname() &&
          check_lname() &&
          check_email() &&
          check_comments()  ) {
             return true; }
          else { return false; }
  }

  function check_boxes()                                                                                                               
  {                                  
    var d=document.rfp;                                                                                                  
    if (d.focus.checked || d.solutions.checked || d.WRAP.checked || d.tme.checked) { 
        return true;
    } else {         
            alert ('Please check a mailing list');  
            return false;                                                                                                                         }
  }  

  function check_eml2()
  {
    var d=document.rfp.eml;
    if (d.value == '') 
    { return true;
    } else {
             eml2=check_eml();
             if (eml2) {
                 return true;
             } else {
                     return false;
             }
           }
  }

  function check_WRAP_tme()                                                                                                     
  {
    var d=document.rfp;                                                                                                                
    if (d.WRAP.checked || d.tme.checked) { 
        emailCheck=check_eml();
        if (!emailCheck) {
           return false;
        }   
    }
    return true;
  }

  function check_focus_solutions()
  {
    var d=document.rfp;
    if (d.focus.checked || d.solutions.checked) {
         if (d.addr.value=='' || d.city.value=='' || d.zip.value=='' || (d.ctry.selectedIndex==1 && d.state.selectedIndex==0))
         {
             alert ('Please provide a complete mailing address');
             d.addr.focus();
             return false;
         } else return true;
    }
    return true;
  }

  function enableAssistance()
  {
    if (document.rfp.cat_other_desc.value == 'Please describe your particular need') {
       document.rfp.cat_other_desc.disabled=false;
       document.rfp.cat_other_desc.value='';
    }
  }

  function doClear(theText) {
     if (theText.value == theText.defaultValue)
        {
         if (theText.value == 'Please describe your particular need') {
           theText.value = ""
         }
        }
  }
  
  
  //added 9/28/05
  
  function imgOn (img) {
  //close all menus first
  //close_coll();
  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

// added 5/25/06
  function imgSwitch(ind) {
    image = document.getElementById("arrow" + ind);
    image.src = "/images/darrow.gif";
  }
// end of showhide.js
