function check_browser() {
  supported = true;
  if (navigator.appName == 'Microsoft Internet Explorer') {
    brVer = navigator.userAgent;
    brVerId = brVer.indexOf('MSIE');
    brNum = brVer.substr(brVerId+5,3);
    if(brNum < 6) supported = false;
  } else if (navigator.appName=='Netscape') {
    brVer = navigator.userAgent;
    brVerId = brVer.search(/\//);
    brNum = brVer.substr(brVerId+1, 3);
    if(brNum < 5) supported = false;
/*
    if(brVer.match(/Safari/)) {
      safariVerId = brVer.match(/Safari\/(.*)\./);
      if(!(safariVerId[1] > 400.0)) supported = false;
    }
*/
  }
  if(!supported)
    document.getElementById('js_msg').innerHTML='<div class="errorbox">Your browser version is not fully supported.</div><br>'
}

function display_cdg_list(groupId) {
  document.getElementById('teacher_link_'+groupId).innerHTML='<p><b>Instructors</b></p>';
  new Effect.BlindDown('teacher_list_'+groupId);
  return false;
}

function hide_cdg_list(groupId) {
  new Effect.BlindUp('teacher_list_'+groupId);
  document.getElementById('teacher_link_'+groupId).innerHTML="<p><a href='#' onclick=\"display_cdg_list("+groupId+")\">Manage Instructors</a></p>";
  return false;
}

function form_wait(form) {
  form['commit'].value='Please wait...';
  form['commit'].disabled=true;
  return true;
}

function disable_submit(form) {
  form['commit'].value='Please wait...';
  form['commit'].disabled=true;
  return true;
}

function enable_submit(form, val) {
  form['commit'].value= (val == null)? 'Submit' : val;
  form['commit'].disabled=false;
  return true;
}

function confirmTerms() {
  if (!document.getElementById('terms_accept').checked) {
    document.getElementById('js_msg').innerHTML='<div class="errorbox"><p>We could not process your request for the following reasons. Please try again.</p><ul><li>You must agree to the Terms of Use.</li></ul></div><br />'
    return false
  }
  return true
}

function requireAll(form) {
  var pass=true;
  for (i=0;i<form.length;i++) {
    var tempobj=form.elements[i];
    
    if ( tempobj.type.match(/text|textarea|password/) ) {
       if ( tempobj.value=='') {
         pass=false;
         tempobj.className = 'formerr'
       } else if (tempobj.className == 'formerr') {
         tempobj.className = ''
       }
    } else if (tempobj.type == 'select') {
      if (tempobj.selectedIndex==0) {
         pass=false;
         tempobj.className = 'formerr'
      } else if (tempobj.className == 'formerr')
         tempobj.className = ''
    } else if (tempobj.type.match(/radio|checkbox/)) {
      var radiogroup = form.elements[tempobj.name]; // get the whole set of radio buttons.
      var itemchecked = false;
      for(var j = 0 ; j < radiogroup.length ; ++j) {
        if(radiogroup[j].checked) {
	      itemchecked = true;
	      break;
	    }
      }
      if(!itemchecked) { 
        pass = false
        if( label = document.getElementById(tempobj.name))
         label.className = 'formerr'
      } else if ( (label = document.getElementById(tempobj.name)) && label.className == 'formerr')
         label.className = ''
    } 
  } //end of for
  if (!pass) {
    document.getElementById('js_msg').display='inline'
    document.getElementById('js_msg').innerHTML='<div class=\"errorbox\">Please fill in all the information.</div>'
    return false
  } else {
    return true
  }
}

/* school assignment */
function clearOptions(form) {
  var choicebox = form.available
  for (i=0; i<=choicebox.options.length; i++) {
    choicebox.options[i] = null
  }
}

function delAff() {
  var groups = document.getElementById('groups')
  for (i=0; i<groups.options.length; i++) {
    if (groups.options[i].selected) 
      groups.options[i] = null 
  }
}

function confirmDelAff() {
  if( confirm("Deleting a school from your affiliated list will remove all of your services attached to this school. To delete an affiliation where you act as a service administrator, please submit a request at Key Online - Help.") ) {
    delAff()
  }
}

function addAff() {
  var selectBox = document.getElementById('available')
  var selected = selectBox.selectedIndex
  if (selected < 1) return
  var choice = document.getElementById('available').options[selected]
  var groups = document.getElementById('groups')
  var listed = false
  for (i=0; i<groups.options.length; i++) {
    if (groups.options[i].value == choice.value) {
      listed = true
      break
    }
  }
  if (!listed)
    groups.options[groups.options.length] = new Option(choice.text, choice.value)
}

function pileAff() {
  var glist = document.getElementById('groups') 
  var gIds = ''
  for (i=0; i<glist.options.length; i++) {
    if(gIds.length>0) gIds += ','
    gIds += glist.options[i].value  
  } 
  document.getElementById('groupIds').value = gIds
}
/* end of school assignment */

function check_number(key) {
  if (!key.value.toString().search(/^[0-9]+$/) == 0) {
    alert('Please enter a valid number.');
    key.focus();
  }
}

function toggle_txt_version(version) {  
  if(version=='DA') {    
    document.getElementById('adoption_DA').style.display='inline';    
    document.getElementById('adoption_DA2').style.display='none';    
    document.getElementById('adoption_DA2CA').style.display='none';    
    document.getElementById('adoption_DA2').value='';  
    document.getElementById('adoption_DA2CA').value='';  
  }  
  if(version=='DA2') {    
    document.getElementById('adoption_DA2').style.display='inline';    
    document.getElementById('adoption_DA').style.display='none';    
    document.getElementById('adoption_DA2CA').style.display='none';    
    document.getElementById('adoption_DA').value='';  
    document.getElementById('adoption_DA2CA').value='';  
  }  
  if(version=='DA2CA') {    
    document.getElementById('adoption_DA2CA').style.display='inline';    
    document.getElementById('adoption_DA').style.display='none';    
    document.getElementById('adoption_DA2').style.display='none';    
    document.getElementById('adoption_DA').value='';  
    document.getElementById('adoption_DA2').value='';  
  }  
  if(version=='DG3') {    
    document.getElementById('adoption_DG3').style.display='inline';    
    document.getElementById('adoption_DG4').style.display='none';    
    document.getElementById('adoption_DG4').value='';  
  }  
  if(version=='DG4') {    
    document.getElementById('adoption_DG4').style.display='inline';    
    document.getElementById('adoption_DG3').style.display='none';    
    document.getElementById('adoption_DG3').value='';  
  }  
  if(version=='PreCalc') {    
    document.getElementById('adoption_PreCalc').style.display='inline';    
    document.getElementById('adoption_PreCalc2').style.display='none';    
    document.getElementById('adoption_PreCalc2').value='';
  }  
  if(version=='PreCalc2') {    
    document.getElementById('adoption_PreCalc2').style.display='inline';    
    document.getElementById('adoption_PreCalc').style.display='none';    
    document.getElementById('adoption_PreCalc').value='';  
  }  
  if(version=='SIA') {    
    document.getElementById('adoption_SIA').style.display='inline';    
    document.getElementById('adoption_SIA2').style.display='none';    
    document.getElementById('adoption_SIA2').value='';  
  }  
  if(version=='SIA2') {    
    document.getElementById('adoption_SIA2').style.display='inline';    
    document.getElementById('adoption_SIA').style.display='none';    
    document.getElementById('adoption_SIA').value='';  
  }
}

function jump_input(field, val) {
  if (val.length==field.maxLength) {
    var next=field.tabIndex;
    if (next<field.form.length) {
      field.form.elements[next].focus();
    }
  }
}
