// JavaScript Library for ExecuJet Aviation Group
// (c) 2008 m.a.x. Informationstechnologie AG
// http://www.maxonline.de


// specialized functions -->

function openImagePopup(myImage,myWidth,myHeight) {
   myHeight += 12;
   myWidth += 12;
   imgWindow = window.open(myImage,'image','height=' + myHeight + ',width=' + myWidth + ',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');   
   imgWindow.resizeTo(myWidth+2,myHeight+30);
   imgWindow.moveTo(200,200);
   imgWindow.focus();
}

function ShowSearch(containerId) 
{
   if (document.getElementById)
   {
      changeOpac(0, containerId);
      document.getElementById(containerId).style.visibility = "visible";
      opacity(containerId, 0, 100, 500);
      setTimeout("SetFocus('ctl00_SearchBox_wucSearchTerm')",500);
   }
   return false;
}

function ShowLanguageSelector(containerId) 
{
   if (document.getElementById)
   {
      changeOpac(0, containerId);
      document.getElementById(containerId).style.visibility = "visible";
      opacity(containerId, 0, 100, 500);
   }
   return false;
}


function ShowFleetRegionFilter(containerId) 
{
   if (document.getElementById)
   {
      changeOpac(0, containerId);
      document.getElementById(containerId).style.visibility = "visible";
      opacity(containerId, 0, 100, 500);
      setTimeout("SetFocus('FleetFilterRegionSelect')",500);
   }
   return false;
}

function ShowFleetCategoryFilter(containerId) 
{
   if (document.getElementById)
   {
      changeOpac(0, containerId);
      document.getElementById(containerId).style.visibility = "visible";
      opacity(containerId, 0, 100, 500);
      setTimeout("SetFocus('FleetFilterCategorySelect')",500);
   }
   return false;
}

function ShowSalesCategoryFilter(containerId) 
{
   if (document.getElementById)
   {
      changeOpac(0, containerId);
      document.getElementById(containerId).style.visibility = "visible";
      opacity(containerId, 0, 100, 500);
      setTimeout("SetFocus('SalesFilterCategorySelect')",500);
   }
   return false;
}

// get available height for splashscreen
function GetSplashscreenHeight()
{
   var layoutheight = 370;
   var flashheight = 450;
   var viewportheight = GetViewportHeight();
   var availableheight = viewportheight - layoutheight;
   if(availableheight >= flashheight) availableheight = flashheight;
   return availableheight;
}









// common functions -->
function ShowLayer(containerId, controlId)
{
   return ShowLayer(containerId, controlId, '');
}

function ShowLayer(containerId, controlId, linkId)
{
   if (document.getElementById)
   {
      changeOpac(0, containerId);
      document.getElementById(containerId).style.visibility = "visible";
      opacity(containerId, 0, 100, 500);
      
      if (linkId != '')
         opacity(linkId, 100, 0, 500);
      
      if(controlId!=null)
         setTimeout("SetFocus('"+controlId.toString()+"')",500);
   }
   return false;
}






// set focus to given element
function SetFocus(controlId)
{
   document.getElementById(controlId).focus();
}

function SetAvinodeDesign(obj)
{
   // var iframeDocument = obj.contentWindow ? obj.contentWindow.document : obj.contentDocument;
   // var root = iframeDocument.documentElement || iframeDocument.body;
   // iframeDocument.getElementsByTagName("body").style.backgroundColor = "#FF9933";
   //alert(HTML);
}

// get viewport height
function GetViewportHeight()
{
   var viewportheight; 
   // mozilla/netscape/opera/IE7
   if (typeof window.innerWidth != 'undefined') { viewportheight = window.innerHeight; }
   // IE6 in standards compliant mode
   else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) { viewportheight = document.documentElement.clientHeight; }
   // older versions of IE
   else { viewportheight = document.getElementsByTagName('body')[0].clientHeight; }
   return viewportheight;
}





// --------------------

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
   if (document.getElementById(id)) {
	   var object = document.getElementById(id).style; 
	   object.opacity = (opacity / 100);
	   object.MozOpacity = (opacity / 100);
	   object.KhtmlOpacity = (opacity / 100);
	   object.filter = "alpha(opacity=" + opacity + ")";
	}
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

// gets an element by class name
function getElementsByClass(searchClass, node, tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


// attaches mouse events to sfhover css classes (workaround for IE 6, which does
// not support :hover pseudo classes on elements other than <a>).
function sfHover() 
{
   var elements = getElementsByClass('jsNav');
   
   if (elements) {
      for(var e=0; e<elements.length; e++) 
      {
         var sfEls = elements[e].getElementsByTagName("LI");
	      for (var i=0; i<sfEls.length; i++)
	      {
	         sfEls[i].onmouseover=function()
	         {
			      this.className+=" sfhover";
		      }
		      sfEls[i].onmouseout=function() 
		      {
			      this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		      }
	      }
	   }
	}
}






if (window.attachEvent) window.attachEvent("onload", sfHover);
