// CHANGE AD PASSWORD VIA OWA

function ChangePassword()
{
  var popup = window.open('/change-password.nu', 'NU', 'width=650, height=380,toolbar=0,scrollbars=0,status=1,menubar=0,location=0');
  popup.opener = window;
}


// FUNCTIONALITY FOR PID AND ICON LOOKUPS

function lookupID(pid)
{
  if(pid.length < 3)
  { $('#id-suggestions').hide(); }
  else
  {
    $.post("/admin/common/lookup-id.nu", {q: ""+pid+""}, function(data)
    {
      if(data == '--')
      { $('#id-suggestions').hide(); }
      else
      {
        $('#id-suggestions').show();
        $('#id-suggestions').html(data);
      }
    });
  }
}

function fillID(thisValue)
{
  $('#PersonID').val(thisValue);
  setTimeout("$('#id-suggestions').fadeOut();", 200);
}

function lookupIcon(size,icon)
{
  if(icon.length < 3)
  { $('#icon-suggestions').hide(); }
  else
  {
    $.post("/admin/common/lookup-icon.nu", {s: ""+size+"", q: ""+icon+""}, function(data)
    {
      if(data == '--')
      { $('#icon-suggestions').hide(); }
      else
      {
        $('#icon-suggestions').show();
        $('#icon-suggestions').html(data);
      }
    });
  }
}

function fillIcon(thisValue)
{
  $('#Icon').val(thisValue);
  setTimeout("$('#icon-suggestions').fadeOut();", 200);
}


// HEADER ANIMATIONS FOR LOG IN, LOG OUT, AND SITE SUB-PAGES

function HeaderSite(WhichSite)
{
  var CurrentSite  = document.getElementById('CurrentSite');
  var CurrentPages = document.getElementById('CurrentPages');
  
  
  if(CurrentPages.value == 'E' && WhichSite == 'E')
  { document.location.href = '/'; }
  else
  { CurrentPages.value = WhichSite; }
  
  
  if(CurrentSite.value != '' && CurrentSite.value != WhichSite && WhichSite != 'IQ' && WhichSite != 'D' && WhichSite != 'M')
  { LogInto(''); }
  
  
  if(WhichSite != 'NU')
  { HeaderSite2('NU'); }
  
  if(WhichSite != 'E')
  { HeaderSite2('E'); }
  
  if(WhichSite != 'L')
  { HeaderSite2('L'); }
  
  if(WhichSite != 'B')
  { HeaderSite2('B'); }
  
  if(WhichSite != 'IQ')
  { HeaderSite2('IQ'); }
  
  if(WhichSite != 'D')
  { HeaderSite2('D'); }
  
  if(WhichSite != 'M')
  { HeaderSite2('M'); }
  
  if(document.getElementById('header-sites-' + WhichSite).className == WhichSite)
  { $('#header-sites-' + WhichSite).toggleClass(WhichSite + '-over'); }
  
  setTimeout('$(\'#header-pages-' + WhichSite + '\').fadeIn();', 250);
}

function HeaderSite2(WhichSite)
{
  document.getElementById('header-sites-' + WhichSite).className = WhichSite;
  $('#header-pages-' + WhichSite).hide();
}

function LogInto(WhichSite)
{
  var CurrentSite  = document.getElementById('CurrentSite');
  var CurrentPages = document.getElementById('CurrentPages');
  
  if(CurrentSite.value != WhichSite)
  {
    $('#header-status-E').hide();
    $('#header-status-M').hide();
    $('#header-status-D').hide();
    $('#header-status-IQ').hide();
    
    if((CurrentSite.value != '' && WhichSite == '') || (CurrentSite.value == '' && WhichSite != ''))
    { $('#header-status').toggleClass('MovedDown',500); }
    
    if(WhichSite != '')
    {
      if(CurrentPages.value != 'E')
      { HeaderSite(WhichSite); }
      
      $('#header-status-0').effect('fade');
      $('#header-search').effect('fade');
      $('#header-splash').effect('fade');
    }
    
    if(WhichSite == '')
    {
      setTimeout('$(\'#header-status-0\').fadeIn();', 500);
      setTimeout('$(\'#header-search\').fadeIn();', 500);
      setTimeout('$(\'#header-splash\').fadeIn();', 1000);
    }
    else if(WhichSite == 'L')
    {
      $('#header-status-L').toggleClass('Processing',0);
      setTimeout('$(\'#header-status-L\').fadeIn();', 500);
    }
    else
    {
      if(document.getElementById('Login-' + WhichSite))
      {
        document.getElementById('Login-' + WhichSite).reset();
        setTimeout('document.getElementById(\'Focus-' + WhichSite + '\').focus();', 1500);
      }
      
      setTimeout('$(\'#header-status-' + WhichSite + '\').effect(\'slide\',250);', 500);
    }
    
    CurrentSite.value = WhichSite;
  }
}

function LogOut()
{
  $.post("/common/v5/logout.nu", {}, function(data) { $('#header-status-L').html(data); });
  
  LogInto('L');
  
  setTimeout('$(\'#header-status\').toggleClass(\'MovedDown\',500); $(\'#header-status-L\').effect(\'fade\');', 2000);
  setTimeout('document.location.href = document.Logout.ReturnTo.value;', 2500);
}


// ROW HIGHLIGHTING

function table1_over(row)
{ row.setAttribute('bgcolor', '#ffffcc', 0); }

function table1_out(row, color)
{ row.setAttribute('bgcolor', color, 0); }


// IPOD TOUCH & IPHONE SCALING

function touchReScale()
{
  // document.getElementById('viewport').removeAttribute('content');
  // alert(document.getElementById('viewport').getAttribute('content'));
  
  var ScreenWidth  = window.innerWidth;
  var ScreenHeight = window.innerHeight;
  
  // alert(ScreenSize);
  
  
  //if(ScreenWidth < ScreenHeight)
  //{
  //  //alert('Portrait');
  //  document.getElementById('viewport').setAttribute("content", "width=480; initial-scale=0.667; maximum-scale=0.667; user-scalable=0");
  //}
  //else
  //{
  //  //alert('Landscape');
  //  document.getElementById('viewport').setAttribute("content", "width=480; initial-scale=1.0; maximum-scale=1.0; user-scalable=0");
  //}
  
  document.getElementById('viewport').setAttribute("content", "width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0");
  setTimeout('scrollTo(0,0);', 250);
  
  // setTimeout('alert(document.getElementById(\'viewport\').getAttribute(\'content\'));', 500);
}


// LOGIN FORM CHECKING

function CompleteEMail(i)
{
  if(i.value.indexOf('@') == -1 && i.value != "" && i.value.length > 2)
  { i.value = i.value + "@northwestu.edu"; }
}

function CheckLogin(WhichSite)
{
  var f = document.getElementById('Login-' + WhichSite);
  var errors = 1; 
  
  if(WhichSite == 'E')
  {
    if(f.auth_email.value.indexOf('@northwestu.edu') < 2)
    {
      alert('Please be sure to type a valid e-mail address.');
      f.auth_email.value = '';
      f.auth_email.focus();
    }
    else if(f.auth_passw.value.length < 4)
    {
      alert('Please be sure to type a valid password.');
      f.auth_passw.value = '';
      f.auth_passw.focus();
    }
    else
    { errors = 0; }
  }
  else if(WhichSite == 'M')
  {
    if(f.username.value.indexOf('@northwestu.edu') < 2)
    {
      alert('Please be sure to type a valid e-mail address.');
      f.username.value = '';
      f.username.focus();
    }
    else if(f.password.value.length < 4)
    {
      alert('Please be sure to type a valid password.');
      f.password.value = '';
      f.password.focus();
    }
    else
    { errors = 0; }
  }
  else if(WhichSite == 'D')
  {
    if(f.username.value.indexOf('@northwestu.edu') < 2)
    {
      alert('Please be sure to type a valid e-mail address.');
      f.username.value = '';
      f.username.focus();
    }
    else if(f.password.value.length < 4)
    {
      alert('Please be sure to type a valid password.');
      f.password.value = '';
      f.password.focus();
    }
    else
    { errors = 0; }
  }
  else if(WhichSite == 'IQ')
  {
    if(f.ctl00$ucUserLogin$lvLoginUser$ucLoginUser$lcLoginUser$UserName.value.indexOf('@northwestu.edu') < 2)
    {
      alert('Please be sure to type a valid e-mail address.');
      f.ctl00$ucUserLogin$lvLoginUser$ucLoginUser$lcLoginUser$UserName.value = '';
      f.ctl00$ucUserLogin$lvLoginUser$ucLoginUser$lcLoginUser$UserName.focus();
    }
    else if(f.ctl00$ucUserLogin$lvLoginUser$ucLoginUser$lcLoginUser$Password.value.length < 4)
    {
      alert('Please be sure to type a valid password.');
      f.ctl00$ucUserLogin$lvLoginUser$ucLoginUser$lcLoginUser$Password.value = '';
      f.ctl00$ucUserLogin$lvLoginUser$ucLoginUser$lcLoginUser$Password.focus();
    }
    else
    { errors = 0; }
  }
  
  if(errors)
  { return false; }
  else
  { return true; }
}
