
// ------...------...------...------...------...------...------...------...------...------...------
var myimages = new Array();

function stat(txt) {
  if (txt == '')
    window.status = " ";
  else
    window.status = txt;
  return true;
}

// ------...------...------...------...------...------...------...------...------...------...------

function es() {
  window.status = " ";
  return true;
}

// ------...------...------...------...------...------...------...------...------...------...------

function btn(formName,action) {
  var e = document.getElementById(formName);

  if (e) {
    e.action.value=action;
    e.submit();
  }
  return false;
}

// ------...------...------...------...------...------...------...------...------...------...------

function btn2(formName,action) {
  // for <input fields (so we get <enter> functionality.
  var e = document.getElementById(formName);

  if (e)
    e.action.value=action;
  return false;
}

// ------...------...------...------...------...------...------...------...------...------...------

function roll(me,clr,img) {
  var str = me.src;
  var len = str.length;
  
  if (len > 6) {
    if ((str.charAt(len-5) == "g") && (str.charAt(len-6) == "_"))
      return;
    if ((str.charAt(len-5) == "d") && (str.charAt(len-6) == "_")) {
      me.src = str.substring(0,len-6) + str.substring(len-4);
    }
    else {
      me.src = str.substring(0,len-4) + "_d" + str.substring(len-4);
    }
  }
  if (clr)
    window.status = " ";
  else
    stat(me.title);
  return true;
}

// ------...------...------...------...------...------...------...------...------...------...------

function roll_tr(me,clr,c) {
  
  me.style.background = c;
  if (clr) {
    window.status = " ";
  }
  else {
    stat(me.title);
  }
  return true;
}

// ------...------...------...------...------...------...------...------...------...------...------

// set-cookie-reload
function scr(name,value) {
  setcookie(name,value,0,"/");
  location.reload(true);
}

// ------...------...------...------...------...------...------...------...------...------...------

function setcookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
}

// ------...------...------...------...------...------...------...------...------...------...------

function getcookie(name) {
	var start = document.cookie.indexOf(name + "=");
	var len   = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) {
		return null;
	}
	if (start == -1) 
	  return null;
	var end = document.cookie.indexOf(";",len);
	if (end == -1) 
	  end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}

// ------...------...------...------...------...------...------...------...------...------...------

function preloadimg() {
  for (i=0;i<preloadimg.arguments.length;i++) {
    myimages[i]     = new Image()
    myimages[i].src = preloadimg.arguments[i]
  }
}

// ------...------...------...------...------...------...------...------...------...------...------

function setCtrlFocus() {

  if (document.forms.length <= 0)
    return;
  for (x=0;x<document.forms.length;x++) {
    var field = document.forms[x];
    for (i=0;i<field.length;i++)
      if ((field.elements[i].type == "text") || 
          (field.elements[i].type == "textarea") || 
          (field.elements[i].type.toString().charAt(0) == "s")) {
        if (document.forms[x].elements[i].disabled == false) {
          document.forms[x].elements[i].focus();
          document.forms[x].elements[i].select();
          break;
        }
      }
  }
}

// ------...------...------...------...------...------...------...------...------...------...------

function mySchdSelChange(which) {

  which = which-0;
  switch (which) {
    case 1:
      scr('c_mySchdView',which);
      break;
    case 2:
      scr('c_mySchdView',which);
      break;
    case 3:
      setcookie('c_mySchdView',3,0,"/");
      setcookie('c_pilotType',1,0,"/");
      pilotFind(0);
      break;
    case 4:
      setcookie('c_mySchdView',4,0,"/");
      setcookie('c_pilotType',4,0,"/");
      pilotFind(0);
      break;
    case 5:
      //pilotFind(0);
      scr('c_mySchdView',which);
      break;
  }
}

// ------...------...------...------...------...------...------...------...------...------...------

function pilotFind(param) {
  thewin = window.open("efs_dlg_pilot.php?param=" + param,"FindPilot",'height=410,width=440,resizable=no,scrollbars=no');
  if (thewin)
    thewin.focus();
}

function pilotPick(id) {
  setcookie("c_pickPilot",id,0,"/");
  window.opener.location.reload(true);
  window.close();
}

function pilotPickName(ctrlID,name) {
  var ctrl = window.opener.document.getElementById(ctrlID);
  
  if (ctrl)
    ctrl.value = name;
  window.close();
}

// ------...------...------...------...------...------...------...------...------...------...------

function getOffset(el,which) {
  // Function for IE to calculate position of an element.
  var amt = 0;
  switch (which) {
    case 8: 
      amt  = el.offsetTop;
      while (el = el.offsetParent)
        amt += el.offsetTop;
      break;
    case 1: 
      amt  = el.offsetTop;
      amt += el.offsetHeight;
      while (el = el.offsetParent)
        amt += el.offsetTop;
      break;
    case 0:
      amt  = el.offsetLeft;
      while (el = el.offsetParent) 
        amt += el.offsetLeft;
      break;
  }
  return amt;
}

// ------...------...------...------...------...------...------...------...------...------...------

function onLoadResize(x,y) {
  var ctrlDiv = document.getElementById('sizer');
  self.resizeTo(x,ctrlDiv.offsetHeight+y);
}

// ------...------...------...------...------...------...------...------...------...------...------

function prtschd() {
  if (thewin = window.open("efs_prt_my_schedule.php","PrintSchd",'height=350,width=710,resizable=yes,scrollbars=yes'))
    thewin.focus();
}

// ------...------...------...------...------...------...------...------...------...------...------
/*
function removePage(page) {
  window.history.back(1);
  location.href=page;
  window.history.forward(1);
}
*/
// ------...------...------...------...------...------...------...------...------...------...------

function goURL(page) {
  location.href=page;
}

// ------...------...------...------...------...------...------...------...------...------...------

function tID(tickID) {
  parm = "?tckID=" + tickID;
  if (thewin = window.open("efs_dlg_ticket.php" + parm,"Ticket",'height=2,width=400,resizable=no,status=no,scrollbars=no,menubar=no'))
    thewin.focus();
}

// ------...------...------...------...------...------...------...------...------...------...------

function msgID(msg_ID) {
  setcookie("c_messageID",msg_ID,0,"/");
  location.href="efs_admin_messages_edit.php";
}

// ------...------...------...------...------...------...------...------...------...------...------

function acID(ac_ID) {
  setcookie("c_aircraftID",ac_ID,0,"/");
  location.href="efs_admin_aircraft_edit.php";
}

// ------...------...------...------...------...------...------...------...------...------...------

function usrID(usr_ID) {
  setcookie("c_userID",usr_ID,0,"/");
  location.href="efs_admin_users_edit.php";
}

// ------...------...------...------...------...------...------...------...------...------...------

function setViz(ctrlName,show) {
  var ctrl = document.getElementById(ctrlName);
  
  if (ctrl)
    if (show) {
      ctrl.style.visibility = 'visible';
      ctrl.style.display    = 'inline';
    }
    else {
      ctrl.style.visibility = "hidden";
      ctrl.style.display    = 'none';
    }
}

// ------...------...------...------...------...------...------...------...------...------...------

function ctrlPanel(which) {
  thewin = window.open("/efs_dlg_ctrl_panel.php","ControlPanel",'height=1,width=426,resizable=no,scrollbars=no');
  if (thewin)
    thewin.focus();
}

// ------...------...------...------...------...------...------...------...------...------...------
