
var activeManager = 'none';
var galleryItemIds = new Array();

function manageGallery(actionId, actionText) {
  if(actionId=='gallery_add') {
    //loadForEdit(formId);
    var divId = 'gallery_manager_add';
  } else if(actionId=='gallery_edit') {
    var divId = 'gallery_manager_edit';
  } else if(actionId=='gallery_delete') {
    var divId = 'gallery_manager_delete';
  } else {
    return;
  }

  //This code was rewritten to include the toggle functionality for the blind-up/blind-down procedures.
  if(document.getElementById(divId).style.display == 'none') {
    if(activeManager != 'none') {
      document.getElementById(activeManager).style.display = 'none';
      window.setTimeout(document.getElementById(divId).style.display='block', 1000);
    } else {
      document.getElementById(divId).style.display = 'block';
    }
    activeManager = divId;
  } else {
    document.getElementById(divId).style.display = 'none';
    activeManager = 'none';
  }

}


function loadForEdit(formId) {
  theForm = document.getElementById(formId);
  var numElements = theForm.elements.length;
  for(i=0; i<numElements; i++) {
    alert(theForm.elements[i].name);
  }

}

function activateForModification(actionName) {
  var formActionStr = '';
  if(actionName == 'edit') {
    var actionText = 'Edit This Item';
    formActionStr = 'edit_items';
  } else if(actionName == 'move') {
    var actionText = 'Move This Item';
    formActionStr = 'move_items';
  } else if(actionName == 'delete') {
    var actionText = 'Remove This Item';
    formActionStr = 'delete_items';
  } else {
    var actionText = 'Edit This Item';
    formActionStr = 'edit_items';
  }
  document.getElementById('modifyActionHiddenElement').value = formActionStr;
  var numItems = galleryItemIds.length;
  for(i=0; i<numItems; i++) {
    document.getElementById('galleryItemSelectorTextDiv'+galleryItemIds[i]).innerHTML = actionText;
    document.getElementById('galleryItemSelectorDiv'+galleryItemIds[i]).style.display = 'block';
  }
  document.getElementById('modifySubmitButtonDiv').style.display = 'block';
}

function selectAllForModification(actionName) {
  for(i=0; i<numItems; i++) {
    document.getElementById('galleryItemSelectorCheckbox'+galleryItemIds[i]).checked = true;
  }
}

function unSelectAllForModification(actionName) {
  for(i=0; i<numItems; i++) {
    document.getElementById('galleryItemSelectorCheckbox'+galleryItemIds[i]).checked = false;
  }
}


function manageCategory(actionId, actionText) {
  var actionIds = new Array('category_add', 'category_edit', 'category_delete');

  document.getElementById('categoryManagementHeader').innerHTML = actionText;

  var categorySelected = false;
  for(i=0; i<actionIds.length; i++) {
    if(actionIds[i] == actionId) {
      document.getElementById(actionIds[i]).style.display = 'block';
      categorySelected = true;
    } else {
      document.getElementById(actionIds[i]).style.display = 'none';
    }
  }

  if(categorySelected) {
    document.getElementById('categoryManager').style.display = 'block';
  } else {
    document.getElementById('categoryManager').style.display = 'none';
  }
}

function checkCategorySubmit(formId) {
  theForm = document.getElementById(formId);
  if(theForm.elements['displayName'].value.length < 2) {
    theForm.elements['displayName'].style.backgroundColor = "#FFFF99";
    alert('You must supply a name to proceed.');
    return false;
  }
  if(theForm.elements['name'].value.length < 2) {
    theForm.elements['name'].style.backgroundColor = "#FFFF99";
    alert('You must supply a title to proceed.');
    return false;
  }
  return true;
}

function showHideElement(elementId, showText, hideText) {
  if(document.getElementById(elementId).style.display == 'none') {
    document.getElementById(elementId).style.display = 'block';
    if(hideText.length > 0) {
      document.getElementById(elementId+'_link').innerHTML = hideText;
    }
  } else {
    document.getElementById(elementId).style.display = 'none';
    if(showText.length > 0) {
      document.getElementById(elementId+'_link').innerHTML = showText;
    }
  }
}

function showHideDivNoScroll(elementId, showText, hideText) {
  if(document.getElementById(elementId).style.display == 'none') {
    document.getElementById(elementId).style.display = 'block';
    if(hideText!=null && hideText.length > 0) {
      document.getElementById(elementId+'_link').innerHTML = hideText;
    }
  } else {
    document.getElementById(elementId).style.display = 'none';
    if(hideText!=null && showText.length > 0) {
      document.getElementById(elementId+'_link').innerHTML = showText;
    }
  }
}

function selectRadioBox(radioBoxId) {
  var aRadioBox = document.getElementById(radioBoxId);
  aRadioBox.checked = true;
}

function addAirport(airportId, airports) {
  var numAirports = airports.length;
  airports[numAirports] = airportId;
}

var blindDownObj;

function selectAirport(selectedAirportId, airports, latitude, longitude) {

  var numAirports = airports.length;
  var lastAirport = numAirports - 1;
  var selectedAirportIndex = -2;

  for(i=0; i<numAirports; i++) {
    var airportId = airports[i];
    var airportDivId = 'airport_listing_' + airportId;
    var airportSelectDivId = 'airport_listing_select_' + airportId;

    var airportDivObj       = document.getElementById(airportDivId);
    var airportSelectDivObj = document.getElementById(airportSelectDivId);

    if(airportId==selectedAirportId) {
      airportDivObj.style.background = 'url(images/fliptabbkghighlight.gif) repeat-x top';
      airportSelectDivObj.style.display = 'block';
    } else {
      airportDivObj.style.background = 'none';
      airportSelectDivObj.style.display = 'none';
    }
  }

  loadGoogleMap('mapDiv', latitude, longitude, 'normal', 12);
  loadGoogleMap('miniMapDiv', latitude, longitude, 'mini', 13);

  return;
}

var airportFinderWindowObj = false;

function openAirportFinder(textInputId) {
  var airportWindowUrl = 'airport_finder_popup.php?option=com_gallery&action=display_single&dynamicElement='+textInputId;

  if(!airportFinderWindowObj) {
    var airportWindowOptions = 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=no, width=675, height=575';
    var airportFinderWindowObj = window.open(airportWindowUrl,'airportFinderWindowName',airportWindowOptions);
    if(!airportFinderWindowObj.opener) {
      airportFinderWindowObj.opener = self;
    }
  } else {
    if(!airportFinderWindowObj.closed && airportFinderWindowObj.location) {
      //Go back to the original page search page to refresh for the new values.
      airportFinderWindowObj.location.href = airportWindowUrl;
    } else {
      var airportWindowOptions = 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=no, width=675, height=575';
      var airportFinderWindowObj = window.open(airportWindowUrl,'airportFinderWindowName',airportWindowOptions);
      if(!airportFinderWindowObj.opener) {
        airportFinderWindowObj.opener = self;
      }
    }
  }
  if(window.focus) {
    airportFinderWindowObj.focus();
  }
  return;

}

//trip_plan_required_departure_airport
function selectAirportAndClose(inputTextId, airportLocationId) {
  opener.document.getElementById(inputTextId).value = airportLocationId;
  self.close();
}

/******** Functions for the Group Wizard *********/

var groupWizardWindowObj = false;

function openGroupWizard() {
  var groupWizardUrl = 'group_wizard.php';

  if(!groupWizardWindowObj) {
    var groupWizardWindowOptions = 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=no, width=675, height=575';
    var groupWizardWindowObj = window.open(groupWizardUrl,'groupWizardWindowName',groupWizardWindowOptions);
    if(!groupWizardWindowObj.opener) {
      groupWizardWindowObj.opener = self;
    }
  } else {
    if(!groupWizardWindowObj.closed && groupWizardWindowObj.location) {
      //Go back to the original page search page to refresh for the new values.
      groupWizardWindowObj.location.href = groupWizardUrl;
    } else {
      var airportWindowOptions = 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=no, width=675, height=575';
      var groupWizardWindowObj = window.open(groupWizardUrl,'groupWizardWindowName',groupWizardWindowOptions);
      if(!groupWizardWindowObj.opener) {
        groupWizardWindowObj.opener = self;
      }
    }
  }
  if(window.focus) {
    groupWizardWindowObj.focus();
  }
  return;

}



/******** Functions for loading and display Google Maps *********/

function loadGoogleMap(mapDivId, latitude, longitude, type, zoomlevel) {
  if (GBrowserIsCompatible()) {
    var googleMap = new GMap2(document.getElementById(mapDivId));
    googleMap.setCenter(new GLatLng(latitude, longitude), zoomlevel);
    if(type=='mini') {
      googleMap.addControl(new GSmallMapControl());
    } else {
      googleMap.addControl(new GLargeMapControl());
      googleMap.addControl(new GMapTypeControl());
    }
    var point = new GLatLng(latitude, longitude);
    googleMap.addOverlay(new GMarker(point));
  }
}

var googleMapsToLoad = new Array();

function addGoogleMapToInit(mapDivId, latitude, longitude, type, zoomlevel) {
  var aMapProperties = new Array();
  aMapProperties[0] = mapDivId;
  aMapProperties[1] = latitude;
  aMapProperties[2] = longitude;
  aMapProperties[3] = type;
  aMapProperties[4] = zoomlevel;

  var numMaps = googleMapsToLoad.length;
  googleMapsToLoad[numMaps] = aMapProperties;
}

function initGoogleMaps() {
  while(googleMapsToLoad.length > 0) {
    var aMapProperties = googleMapsToLoad.pop();

    var mapDivId   = aMapProperties[0];
    var latitude   = aMapProperties[1];
    var longitude  = aMapProperties[2];
    var type       = aMapProperties[3];
    var zoomlevel  = aMapProperties[4];

    loadGoogleMap(mapDivId, latitude, longitude, type, zoomlevel);
  }
}


var nearestAirports = new Array();
var nearestAirportMap = null;

function selectNearestAirport(latitude, longitude) {
  nearestAirportMap.setCenter(new GLatLng(latitude, longitude), 11);
}

function loadNearestMap(mapDivId, latitude, longitude, zoomlevel) {
  if (GBrowserIsCompatible()) {
    nearestAirportMap = new GMap2(document.getElementById(mapDivId));
    nearestAirportMap.setCenter(new GLatLng(latitude, longitude), zoomlevel);
    nearestAirportMap.addControl(new GLargeMapControl());
    nearestAirportMap.addControl(new GMapTypeControl());

    var airportIcon = new GIcon(G_DEFAULT_ICON);
    airportIcon.image = "http://192.168.0.10/images/map_icons/airport.gif";
    airportIcon.shadow = 'http://192.168.0.10/images/map_icons/airport_shadow.gif';
    airportIcon.iconSize = new GSize(16, 20);
    airportIcon.shadowSize = new GSize(20, 20);
    airportIcon.iconAnchor = new GPoint(10, 14);
    //airportIcon.infoWindowAnchor = new GPoint(5, 1);

    // Set up our GMarkerOptions object
    markerOptions = { icon:airportIcon };

    var numAirports = nearestAirports.length;
    if(numAirports > 0) {
      for(i=0;i<numAirports;i++) {
        var aAirportProps = nearestAirports[i];
        var point = new GLatLng(aAirportProps[1], aAirportProps[2]);
        nearestAirportMap.addOverlay(new GMarker(point, markerOptions));
      }
    }
  }
}

function addNearestAirport(markerId, latitude, longitude) {
  var aNearestAirportProperties = new Array();
  aNearestAirportProperties[0] = markerId;
  aNearestAirportProperties[1] = latitude;
  aNearestAirportProperties[2] = longitude;
  var numAirports = nearestAirports.length;
  nearestAirports[numAirports] = aNearestAirportProperties;
}



/******** Functions for loading and display MSN Virtual Earth Maps *********/

function loadMsnMap(mapDivId, latitude, longitude, zoomlevel) {
  var msnMap = new VEMap(mapDivId);
  msnMap.LoadMap(new VELatLong(latitude, longitude), zoomlevel, 'r', false, VEMapMode.Mode2D, true);
}

var msnMapsToLoad = new Array();

function addMsnMapToInit(mapDivId, latitude, longitude, type, zoomlevel) {
  var aMapProperties = new Array();
  aMapProperties[0] = mapDivId;
  aMapProperties[1] = latitude;
  aMapProperties[2] = longitude;
  aMapProperties[3] = type;
  aMapProperties[4] = zoomlevel;

  var numMaps = googleMapsToLoad.length;
  googleMapsToLoad[numMaps] = aMapProperties;
}

function initMsnMaps() {
  while(msnMapsToLoad.length > 0) {
    var aMapProperties = msnMapsToLoad.pop();

    var mapDivId   = aMapProperties[0];
    var latitude   = aMapProperties[1];
    var longitude  = aMapProperties[2];
    var type       = aMapProperties[3];
    var zoomlevel  = aMapProperties[4];

    loadMsnMap(mapDivId, latitude, longitude, type, zoomlevel);
  }
}

/**************** Skyvector Map display functions ****************/

function loadSkyvectorMap(mapDivId, latitude, longitude) {
  var SkyvectorMap = new VEMap(mapDivId);
  SkyvectorMap.LoadMap(new VELatLong(latitude, longitude), zoomlevel, 'r', false, VEMapMode.Mode2D, true);
}

var skyvectorMapsToLoad = new Array();

function addSkyvectorMapToInit(mapDivId, latitude, longitude, type, zoomlevel) {
  var aMapProperties = new Array();
  aMapProperties[0] = mapDivId;
  aMapProperties[1] = latitude;
  aMapProperties[2] = longitude;
  aMapProperties[3] = type;
  aMapProperties[4] = zoomlevel;

  var numMaps = googleMapsToLoad.length;
  googleMapsToLoad[numMaps] = aMapProperties;
}

function initSkyvectorMaps() {
  while(SkyvectorMapsToLoad.length > 0) {
    var aMapProperties = SkyvectorMapsToLoad.pop();

    var mapDivId   = aMapProperties[0];
    var latitude   = aMapProperties[1];
    var longitude  = aMapProperties[2];
    var type       = aMapProperties[3];
    var zoomlevel  = aMapProperties[4];

    loadSkyvectorMap(mapDivId, latitude, longitude, type, zoomlevel);
  }
}


/******************** Group Management Functions ********************/

function addUserToCircle(userId, circleId) {

}

function removeUserFromCircle(userId, circleId) {

}

function initTinyMce(type, textAreaId) {
  if(type == 'simple') {
    tinyMCE.init({
      // General options
      mode : "exact",
    	elements : textAreaId,

      theme : "advanced",
      theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,|,justifyleft,justifycenter,justifyright,justifyfull,|,sub,sup,charmap",

      theme_advanced_buttons2: "",
      theme_advanced_buttons3: "",
      theme_advanced_buttons4: "",
      theme_advanced_toolbar_location : "top",
      theme_advanced_toolbar_align : "left",
      theme_advanced_resizing : false
    });
  } else if(type == 'advanced') {
    tinyMCE.init({
      // General options
      mode : "exact",
    	elements : textAreaId,

      theme : "advanced",
      plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",

      // Theme options
      theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontsizeselect,|,sub,sup,charmap,|,spellchecker,|,cite,abbr,acronym,del,ins,|,fullscreen",
      theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,code,|,insertdate,inserttime",
      theme_advanced_buttons3 : "",
      theme_advanced_toolbar_location : "top",
      theme_advanced_toolbar_align : "left",
      theme_advanced_statusbar_location : "bottom",
      theme_advanced_resizing : false,

      // Example content CSS (should be your site CSS)
      //content_css : "css/example.css",

      // Drop lists for link/image/media/template dialogs
      //template_external_list_url : "js/template_list.js",
      //external_link_list_url : "js/link_list.js",
      //external_image_list_url : "js/image_list.js",
      //media_external_list_url : "js/media_list.js",
    });
  }
}


//document.ondragstart = function () {
//    window.event.dataTransfer.effectAllowed = "all";
//};




