/*  javascript functions */

var destschoolref;

function gourl(u) {
  window.location.href = u;
  return false;
}

function gourlfullscreen(url, options) {
  var winOptions = '';
  switch (options)
  {
    case 'scroll':
      winOptions = 'directories=no, menubar=no, status=no, toolbar=no, scrollbars=yes';
      break;
      
    default:
      winOptions = 'directories=no, menubar=no, status=no, toolbar=no';
  }
  
  var newWin = window.open(url, 'newWindow', winOptions + ", height=" + screen.height + ", width=" + screen.width);
  newWin.moveTo(0,0);
  newWin.focus();
  return false;
}

// goes to a new url based on a prefix url with the selected objects value appended
function gourl_select(select, url_base) {
  window.location.href = url_base + select[select.selectedIndex].value;
  return false;
}

function show(o) {
  if(o.shown) {
    o.style.position = 'absolute';
    o.style.height = '1px';
    o.shown = false;
  } else {
    o.style.position = 'relative';
    o.style.height = 'auto';
    o.shown = true;
  } 
}

function confirmLogInAs() {
  return confirm('Are you sure you want to log in as this user? You will not be logged in as an administrator.');
}

function toggle(obj) {
  var t = document.getElementById(obj.getAttribute('toggleid'))
  if(t.style.display == 'block') {
    t.style.display = 'none';
    obj.className = 'toggle-off';
  } else {
    t.style.display = 'block';
    obj.className = 'toggle-on';
  }
  obj.blur();
  return false;
}

function toggle_all(obj) {
  var tw = (obj.className == 'toggle-off')?true:false;
  var tags = document.getElementsByTagName('A');
  for(var i = 0; i<tags.length;i++) {
    if(tags[i].getAttribute('toggleid') && tags[i].className == obj.className) {
      document.getElementById(tags[i].getAttribute('toggleid')).style.display = tw?'block':'none';
      tags[i].className = tw?'toggle-on':'toggle-off';
    }
  }
  obj.className = tw?'toggle-on':'toggle-off';
  obj.innerHTML = tw?'Collapse All':'Expand All';
  obj.blur();
  return false;
}

function form_toggleOnOther(e) {
  var sele = document.getElementById(e)
  var othd = document.getElementById(e + "-othdiv")
  var othi = document.getElementById(e + "-other")

  if(!sele || !othd || !othi) return;

  if(sele.options[sele.selectedIndex].value == 'other') {
     othd.style.display = 'block';
  } else {
     othi.value = '';
     othd.style.display = 'none';
  }
}

function form_helppopup(url) {
  window.open(url, "help_pop", "status=0,toobar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=400,width=700").focus();
  return false;
}

function setDestSchool(id, name, state) {
  document.getElementById(destschoolref + '-destschoolid').value = id;
  document.getElementById(destschoolref + '-state').value = state;
  document.getElementById(destschoolref + '-orgname').value = name;
} 

function ocfe_eoi_orgname(e) {
  alert(e)
}

function ocfe_eoi_physasmail(e) {
  alert(e)
}

function ocfe_e5fs_xschoolselector(e) {
  destschoolref = 'fe-e5fs';
  window.open('../../special/schoolselector.asp', "sch_pop", "status=0,toobar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=400,width=600").focus();
}

function ocfe_e3fs_xschoolselector(e) {
  destschoolref = 'fe-e3fs';
  window.open('../../special/schoolselector.asp', "sch_pop", "status=0,toobar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=400,width=600").focus();
}

// EOI Project Coordinator & Deputy Coordinator Street Address/PO Box hide/show
function ocfe_e3fs_mailtype(e) { ocfe_multi_mailtype('e3fs'); }
function ocfe_e3fo_mailtype(e) { ocfe_multi_mailtype('e3fo'); }

// PP Partner Orgs Street Address/PO Box hide/show
function ocfe_e5fs_mailtype(e) { ocfe_multi_mailtype('e5fs'); }
function ocfe_e5fo_mailtype(e) { ocfe_multi_mailtype('e5fo'); }

function ocfe_multi_mailtype(mref) {
  var sele = document.getElementById('fe-' + mref + '-mailtype');
  var boxe = document.getElementById('fc-' + mref + '-mailboxnum');
  var sune = document.getElementById('fc-' + mref + '-mailunitnum');
  var snue = document.getElementById('fc-' + mref + '-mailstreetnum');
  var snme = document.getElementById('fc-' + mref + '-mailstreetname');
  var sste = document.getElementById('fc-' + mref + '-mailstreettype');
  var cope = document.getElementById('fe-' + mref + '-copymailtophys');

  if(sele.value == 'bag'){
    boxe.style.display = 'inline';
    snue.style.display = 'none';
    sune.style.display = 'none';
    snme.style.display = 'none';
    sste.style.display = 'none';
    cope.disabled = true;
  } else {
    boxe.style.display = 'none';
    snue.style.display = 'inline';
    sune.style.display = 'inline';
    snme.style.display = 'inline';
    sste.style.display = 'inline';
    cope.disabled = false;
  }
}

// EOI Project Coordinator & Deputy Coordinator Mailing Address -> Physical Address copy
function ocfe_e3fs_copymailtophys(e) { ocfe_multi_copymailtophys('e3fs'); }
function ocfe_e3fo_copymailtophys(e) { ocfe_multi_copymailtophys('e3fo'); }

// PP Partner Orgs Mailing Address -> Physical Address copy
function ocfe_e5fs_copymailtophys(e) { ocfe_multi_copymailtophys('e5fs'); }
function ocfe_e5fo_copymailtophys(e) { ocfe_multi_copymailtophys('e5fo'); }

function ocfe_multi_copymailtophys(mref) { 
  document.getElementById('fe-' + mref + '-physunitnum').value = document.getElementById('fe-' + mref + '-mailunitnum').value;
  document.getElementById('fe-' + mref + '-physstreetnum').value = document.getElementById('fe-' + mref + '-mailstreetnum').value;
  document.getElementById('fe-' + mref + '-physstreetname').value = document.getElementById('fe-' + mref + '-mailstreetname').value;
  document.getElementById('fe-' + mref + '-physstreettype').selectedIndex = document.getElementById('fe-' + mref + '-mailstreettype').selectedIndex;
  document.getElementById('fe-' + mref + '-physcity').value = document.getElementById('fe-' + mref + '-mailcity').value;
  document.getElementById('fe-' + mref + '-physstate').selectedIndex = document.getElementById('fe-' + mref + '-mailstate').selectedIndex;
  document.getElementById('fe-' + mref + '-physpostcode').value = document.getElementById('fe-' + mref + '-mailpostcode').value;
}
