﻿
// ### Search  ############################################
function search()
{
  var sInput = document.getElementById('searchInput');
  document.location.href = '/search?search='+ sInput.value;
}

function searchOnEnter(field,e)
{
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;

  if (keycode == 13)
  {
    searchClick();
    return false;
  }
  else
    return true;
}


// ### Expand animation for search field ############################################
var x=1;
var fullWidth = 172;
var isExpanded = false;
function searchClick()
{
  if(!isExpanded)
  {
    isExpanded = true;
    document.getElementById("search").style.display='block';
    expand();
  }
  else
  {
    search();
  }
}
function expand() {
  document.getElementById("search").style.width=x+'px';
  if(x>fullWidth) {
    var input = document.getElementById("searchInput");
    input.value = '';
    input.focus();
    clearTimeout(t);
    return;
  }
  x += 5;
  t=setTimeout('expand()',5);
}

// ### Expand animation for main menu ############################################
var smGrowth = 1;
var smFullHeight = 1;
var smHeightPerItem = 25;
var smID = "submenu";
var smIsExpanded = false;

function showSubMenu()
{
  if(!smIsExpanded)
  {
    smIsExpanded = true;
    var ul = document.getElementById(smID);
 
    if(ul != null)
    {   
      //Find number of items and total height
      smFullHeight = (ul.getElementsByTagName('li').length) * smHeightPerItem;
      
      ul.style.display = 'block';
      document.getElementById(smID).style.height = smFullHeight + "px";
    }
  }
}

function expandSubMenu()
{
  if(!smIsExpanded)
  {
    smIsExpanded = true;
    var ul = document.getElementById(smID);
 
    if(ul != null)
    {   
      //Find number of items and total height
      smFullHeight = (ul.getElementsByTagName('li').length) * smHeightPerItem;
      
      ul.style.display = 'block';
      smExpand();
    }
  }
}
function smExpand() {
  document.getElementById(smID).style.height = smGrowth+'px';
  if(smGrowth > smFullHeight) {
    clearTimeout(t1);
    return;
  }
  smGrowth += 10;
  t1 = setTimeout('smExpand()',50);
}

// ### Application form: More attachments ############################################
function MoreAttachments()
{
  var lastFieldAdded = false;
  for(var i = 2; i < 6; i++)
  {
    var cv = document.getElementById('cv'+i);
    
    if(cv.style.display == 'none')
    {
      cv.style.display = 'block';
      try {
        cv.style.display = 'table-row';
      }
      catch(err) {}
      if(i == 5)
        lastFieldAdded = true;
      break;
    }
    
  }
  
  //if last field added, hide more link
  if(lastFieldAdded)
  {
    var more = document.getElementById('more');
    more.style.display = 'none';
  }  
}
