// JavaScript Document

var fMonths = new Array("January", "February", "March", 
"April", "May", "June", "July", "August", "September", 
"October", "November", "December");


function clearSearchPrompt(aInput){
 	if(aInput.value=="[Enter Search Term]"){
	  aInput.value="";
		aInput.style.color="#000000";
	}
	return true;
}

function restoreSearchPromt(aInput){
  if(aInput.value==""){
	  aInput.value="[Enter Search Term]";
		aInput.style.color="#849094";
	}
}

/*********************************************************************************
 loading div creation
*********************************************************************************/

function createLoadingDiv(aContainer, aId, aTop, aLeft, aMarginTop){
  var zMarginTop = (aMarginTop)? aMarginTop : 100;
  var zTemp = new Element('div',{'class': 'loaderSC','id': aId});
  aContainer.appendChild(zTemp);
//  zTemp.up().extend();
//  zTemp.style.position = 'absolute';
  var zDimensions = zTemp.up().getDimensions();
  var zCalcTop = zDimensions.height / 2;
  var zCalcLeft = (zDimensions.width / 2) - 25; // loading image is 50px
  zTemp.style.marginTop = zMarginTop +'px';
  zTemp.style.marginLeft = zCalcLeft +'px';
  
  return zTemp;
}




function resetCenterContainer(aTitle){
  var zCenterContainerdiv = $('div_CenterContainer');
	if (!$('centerloading')){  
    var zLoadingDiv = createLoadingDiv(zCenterContainerdiv,'centerloading');
  } else {
    var zLoadingDiv = $('centerloading');
  }
  zLoadingDiv.style.display = 'block';
  
  while (zCenterContainerdiv.childNodes[0]) {
    zCenterContainerdiv.removeChild(zCenterContainerdiv.childNodes[0]);
  }
  if (aTitle){
    var zContentHeading = new Element('div',{'id': 'PageHeading','class': 'ContentHeading'});
    zContentHeading.update(aTitle);
    zContentHeading.style.position = 'relative';
    zCenterContainerdiv.appendChild(zContentHeading);
  }
  return true;
}

function openStLuciaMap(){
//  var win = new Window({className: "dialog", width:500, height:420, zIndex: 100, resizable: true, title: "St. Lucia Map", showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true}); 
//  win.getContent().innerHTML= '<div id="StLuciaMap" style="width: 500px; height: 400px"></div>';
//  win.setStatusBar("Status bar info");
//  win.showCenter();
//  $('div_CenterContainer').innerHTML = '<div id="StLuciaMap" style="width: 500px; height: 400px"></div>';
/*
  var zStLuciaMapContainer = new Element('div',{'id': 'StLuciaMapContainer'});
  zStLuciaMapContainer.update ('Help, this is not working as expected...');
  var zStLuciaMap = new Element('div',{'id': 'StLuciaMap','width': 500, 'height': 400});
  var map = new GMap2(zStLuciaMap);
  map.setCenter(new GLatLng(13.89274421457224, -60.983734130859375), 10, G_SATELLITE_MAP);
  zStLuciaMapContainer.appendChild(zStLuciaMap);
  Modalbox.show(zStLuciaMapContainer, {title: 'St. Lucia Map', width: 500, height: 420});
*/  
  Modalbox.show('../stluciamap.html', {title: 'St. Lucia Map', width: 499, height: 427, contentOverflow: 'hidden', contentHeightAdjust: 0});
  $('MB_content').style.padding = '0px';
  $('MB_content').style.margin = '0px';
  $('MB_frame').style.overflow = 'hidden';
  $('MB_frame').style.paddingBottom = '0px';
  
//  loadMap();

}
/*
function loadMap() {
  if (GBrowserIsCompatible()) {
    
    var map = new GMap2(document.getElementById("StLuciaMap"));
    map.enableContinuousZoom();
		map.enableScrollWheelZoom();
//    alert(document.getElementById("StLuciaMap"));
    map.setCenter(new GLatLng(13.919405039068674, -60.96038818359375), 10, G_HYBRID_MAP);
    map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
  }
}
*/


function clearPrompt(aInput,aValue){
 	if(aInput.value==aValue){
	  aInput.value="";
		aInput.style.color="#000000";
	}
	return true;
}

function restorePromt(aInput,aValue){
  if(aInput.value==""){
	  aInput.value=aValue;
		aInput.style.color="#849094";
	}
	return true;
}

function splashFadeOut(){
  for (var i=0;i<arguments.length;i++){
/*    new Effect.Fade('SplashNav' + arguments[i],
    { 
      duration: 0.0, 
      from: 1.0, to: 0.5 
    });
*/
    for (var j=1.0;j>=0.3;j=j-0.002){
      Element.Methods.setOpacity('SplashNav' + arguments[i],j);
    }

  }
  return false;
}
function splashFadeIn(){
  for (var i=0;i<arguments.length;i++){
    /*
    new Effect.Appear('SplashNav' + arguments[i],
    { 
      duration: 0.0
    });
    */
    for (var j=0.3;j<=1.0;j=j+0.002){
      Element.Methods.setOpacity('SplashNav' + arguments[i],j);
    }

  }
  return false;
}

function splashHighlight(skipElementNumber){
//  new Effect.Highlight(element, { endcolor: '#E9E9E9', startcolor: '#F68629' });
  Element.Methods.setOpacity('SplashNav1',1.0);
  Element.Methods.setOpacity('SplashNav2',1.0);
  Element.Methods.setOpacity('SplashNav3',1.0);
  
  if (skipElementNumber != 1){     
    Element.Methods.setOpacity('SplashNav1',0.3);
  }
  if (skipElementNumber != 2){
  
    Element.Methods.setOpacity('SplashNav2',0.3);
  }
  if (skipElementNumber != 3){

    Element.Methods.setOpacity('SplashNav3',0.3);
  }
  return true;
}
function removeSplashHighlight(skipElementNumber){   
  Element.Methods.setOpacity('SplashNav1',1.0);
  Element.Methods.setOpacity('SplashNav2',1.0);
  Element.Methods.setOpacity('SplashNav3',1.0);
  return true;
}

function showError(aRequest, aError){
  // ignore errors if showErrors is false
  if (showErrors){
    alert("Error encountered: \n" + aError);
  }
}

var showErrors = true;

function displayError(message)
{
  // ignore errors if showErrors is false
  if (showErrors)
  {
    // turn error displaying Off
    showErrors = false;
    // display error message
    alert("Error encountered: \n" + message);
  }
}

var searchResults = [];


function keypressHandler (event)
{
 // I think this next line of code is accurate,
 // but I don't have a good selection of browsers
 // with me today to test this effectivly.
 var key = event.which || event.keyCode;

 switch (key) {
   case Event.KEY_RETURN:
//     alert('moved right');
     break;
   case Event.KEY_LEFT:
//     alert('moved left');
     break;
 }
}

var SearchFunctions = {
  doSearch: function(e){
    var key = e.which || e.keyCode;
    if (key == Event.KEY_RETURN){
      getContent('search.php',displaySearchResults,{aKeyword: $('inpSiteSearch').value});
      Event.stopObserving($('inpSiteSearch'), 'keyup', SearchFunctions.doSearch);
      $('inpSiteSearch').blur();
    }
    
  }
};
