// JavaScript Document

var w = 418;
var h = 210;
//var winlinks = (screen.width - w) / 2;
//var wintop = (screen.height - h) / 2;
	var windowX = window.innerWidth || self.innerWidth ;
	var windowY = window.innerHeight || self.innerHeight;
var winlinks = (windowX - w) / 2;
var wintop = (windowY - h) / 2;


function open_aircraft( aircraft, tpldir, laydir, type )
{
	popup = window.open('','popup','toolbar=0,scrollbars=auto,location=no,statusbar=no,menubar=no,resizable=0,width='+w+',height='+h+',left = '+winlinks+',top ='+ wintop);
	popup.document.open();
         if (type == "framework")
         {
		popup.document.location='index.php?page=aircraftdetails&aircraft='+aircraft+'&TPLDIR='+tpldir + '&laydir=' + laydir;
         }
         else
         {
		popup.document.location='../popup_aircraft.php?aircraft='+aircraft+'&TPLDIR='+tpldir + '&laydir=' + laydir;
         }
	popup.document.close();
}
function open_csv( tpldir ,csv_w,csv_h)
{
	popup = window.open('','popup','toolbar=0,scrollbars=auto,location=no,statusbar=no,menubar=no,resizable=0,width='+csv_w+',height='+csv_h+',left = '+winlinks+',top ='+ wintop);
	popup.document.open();
	popup.document.location='../0006/index.php?page=csv&TPLDIR='+tpldir;
	popup.document.close();
}


function open_print( booking_id, tpldir )
{
	var w = 820;
	var h = 600;
	var winlinks = (windowX - w) / 2;
	var wintop = (windowY - h) / 2;

	popup = window.open('','popup','toolbar=0,scrollbars=yes,location=no,statusbar=no,menubar=no,resizable=1,width='+w+',height='+h+',left = '+winlinks+',top ='+ wintop);
	popup.document.open();
	popup.document.location='./index.php?page=confirmation&booking_id='+booking_id+'&TPLDIR='+tpldir+'&print=true';
	popup.document.close();
}
function clearShipping(){
          document.forms['flightform'].elements['ud_mailpre'].value='';
          document.forms['flightform'].elements['ud_mailsur'].value='';
          document.forms['flightform'].elements['ud_mailstr'].value='';
          document.forms['flightform'].elements['ud_mailzip'].value='';
          document.forms['flightform'].elements['ud_mailcti'].value='';
          document.forms['flightform'].elements['ud_mailcty'].value='';

}
function checkPassengers()
{

	maxChilds = 3-document.getElementById('pax').selectedIndex;

         if((document.forms.flightform.elements.chpax.options.length-1) > maxChilds)
         {

                 for(i=document.forms.flightform.elements.chpax.length;i>maxChilds;i--)
                 {
                 	if(document.forms.flightform.elements.chpax.options[document.forms.flightform.elements.chpax.length - 1])
                         {
				document.forms.flightform.elements.chpax.options[document.forms.flightform.elements.chpax.length - 1] = null;
                         }
                 }
         }
         if((document.forms.flightform.elements.chpax.options.length-1) < maxChilds)
         {

                 for(i=(document.forms.flightform.elements.chpax.options.length-1); i < maxChilds; i++)
                 {
                 	if(document.forms.flightform.elements.chpax.options.length == 0)
                         {
                 		NeuerEintrag = new Option('-', document.forms.flightform.elements.chpax.options.length, false, false);
                         }
                         else
                         {
                 		NeuerEintrag = new Option(document.forms.flightform.elements.chpax.options.length, document.forms.flightform.elements.chpax.options.length, false, false);
                         }
			document.forms.flightform.elements.chpax.options[document.forms.flightform.elements.chpax.length ] = NeuerEintrag;
                 }
         }

	document.forms.flightform.elements.infpax.options.length = 0;
         for(i=0; i < (document.getElementById('pax').selectedIndex+2); i++)
         {
                 	if(i == 0)
                         {
                 		NeuerEintrag = new Option('-', i, false, false);
                         }
                         else
                         {
                 		NeuerEintrag = new Option(i, i, false, false);
                         }
			document.forms.flightform.elements.infpax.options[document.forms.flightform.elements.infpax.length ] = NeuerEintrag;
	}

}

function toggle_display(obj)
{
	objs = obj.split('-');
         for(i=0;i < objs.length; i++){
			if(document.getElementById(objs[i])!=null)
			{
		         if (document.getElementById(objs[i]).style.display == '')
		         {
		                 document.getElementById(objs[i]).style.display = 'none';
		         }
		         else
		         {
		                 document.getElementById(objs[i]).style.display = '';
		         }
			 }
         }

}
function toggle_display_show(obj)
{
	objs = obj.split('-');
         for(i=0;i < objs.length; i++){
	                 document.getElementById(objs[i]).style.display = 'block';
	         }

}
function toggle_display_hide(obj)
{
	objs = obj.split('-');
         for(i=0;i < objs.length; i++){
	                 document.getElementById(objs[i]).style.display = 'none';
	         }

}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;

	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = xScroll;
	} else {
		pageWidth = xScroll;
		//pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function getPageScroll(e){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
    X = e.pageX || event.clientX + document.body.scrollLeft;
    Y = e.pageY || event.clientY + document.body.scrollTop;

	arrayPageScroll = new Array(xScroll,yScroll,X,Y)
	return arrayPageScroll;
}

function centerOnScreen(centerObject)
{

	var windowX =(document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth;
	var windowY =(document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight;
	var scrollX =(document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft;
	//var scrollY =(document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop;
	var pageX 	=(document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth;
	var pageY 	=(document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;

	if(typeof window.pageYOffset != 'undefined')
	{
		scrollY = window.pageYOffset;
	}
	else
	{
		if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
		{
	 		scrollY = document.documentElement.scrollTop;
		}
		else
		{
			if(typeof document.body != 'undefined')
			{
	 			scrollY = document.body.scrollTop;
			}
		}
	}


	if((centerObject) && (centerObject.style))
	{
		centerObject.style.position	="absolute";
		centerObject.style.display	="";
		centerObject.style.left			=((window.innerWidth ? window.innerWidth : document.body.clientWidth) / 2) - (parseInt(centerObject.style.width) / 2) + "px";
		centerObject.style.top			=scrollY + ((window.innerHeight ? (window.innerHeight / 1.6) : (document.documentElement.clientHeight / 1.6)) - (parseInt(centerObject.style.width) / 2)) + "px";

	}
	else
	{
		alert("centerOnScreen:no Object...");
	}
}


function number_format (number, decimals, dec_point, thousands_sep)
{
  var exponent = "";
  var numberstr = number.toString ();
  var eindex = numberstr.indexOf ("e");
  if (eindex > -1)
  {
    exponent = numberstr.substring (eindex);
    number = parseFloat (numberstr.substring (0, eindex));
  }
  
  if (decimals != null)
  {
    var temp = Math.pow (10, decimals);
    number = Math.round (number * temp) / temp;
  }
  var sign = number < 0 ? "-" : "";
  var integer = (number > 0 ? 
      Math.floor (number) : Math.abs (Math.ceil (number))).toString ();
  
  var fractional = number.toString ().substring (integer.length + sign.length);
  dec_point = dec_point != null ? dec_point : ".";
  fractional = decimals != null && decimals > 0 || fractional.length > 1 ? 
               (dec_point + fractional.substring (1)) : "";
  if (decimals != null && decimals > 0)
  {
    for (i = fractional.length - 1, z = decimals; i < z; ++i)
      fractional += "0";
  }
  
  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? 
                  thousands_sep : null;
  if (thousands_sep != null && thousands_sep != "")
  {
	for (i = integer.length - 3; i > 0; i -= 3)
      integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
  }
  
  return sign + integer + fractional + exponent;
}
