var version4 = (navigator.appVersion.charAt(0) == "4"); 
var popupHandle; 
 
 function closePopup() {
if(popupHandle != null && !popupHandle.closed) popupHandle.close();
}
function displayPopup(position,url,name,height,width,evnt) {
	
	
// position=1 POPUP: makes screen display up and/or left, down and/or right 
// depending on where cursor falls and size of window to open
// position=2 CENTER: makes screen fall in center
var properties = "toolbar = 0, location = 0, height = " + height;
properties = properties + ", width=" + width;
var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;
if(navigator.appName == "Microsoft Internet Explorer") {
screenY = document.body.offsetHeight;
screenX = window.screen.availWidth;
}
else {
screenY = window.outerHeight
screenX = window.outerWidth
}
if(position == 1)	{ // if POPUP not CENTER
cursorX = evnt.screenX;
cursorY = evnt.screenY;
padAmtX = 1;
padAmtY = 1;
if((cursorY + height + padAmtY) > screenY) {
// make sizes a negative number to move left/up
padAmtY = (-30) + (height * -1);
// if up or to left, make 30 as padding amount
}
if((cursorX + width + padAmtX) > screenX)	{
padAmtX = (-30) + (width * -1);	
// if up or to left, make 30 as padding amount
}
if(navigator.appName == "Microsoft Internet Explorer") {
leftprop = cursorX + padAmtX;
topprop = cursorY + padAmtY;
}
else {
leftprop = (cursorX - pageXOffset + padAmtX);
topprop = (cursorY - pageYOffset + padAmtY);
   }
}
else{
leftvar = (screenX - width) / 2;
rightvar = (screenY - height) / 2;
if(navigator.appName == "Microsoft Internet Explorer") {
leftprop = leftvar;
topprop = rightvar;
}
else {
leftprop = (leftvar - pageXOffset);
topprop = (rightvar - pageYOffset);
   }
}
if(evnt != null) {
properties = properties + ", left = " + leftprop;
properties = properties + ", top = " + topprop;
}
closePopup();
popupHandle = open(url,name,properties);
}
//  End -->




function displayPopup2(position,url,height,width,evnt) {
	
	var position =1;
	var name='popu';
	var height = 150;
	var width = 300;
	var evnt = null;
	//var url = 'panstwa.php?p=' + par;
// position=1 POPUP: makes screen display up and/or left, down and/or right 
// depending on where cursor falls and size of window to open
// position=2 CENTER: makes screen fall in center
var properties = "toolbar = 0, location = 0, height = " + height;
properties = properties + ", width=" + width;
var leftprop, topprop, cursorX, cursorY, padAmt;
if(navigator.appName == "Microsoft Internet Explorer") {
screenY = 1000;
screenX = 1000;
}
else {
screenY = 1000;
screenX = 1000;
}
if(position == 1)	{ // if POPUP not CENTER
cursorX = 700;
cursorY = 700;
padAmtX = 900;
padAmtY = 900;
if((cursorY + height + padAmtY) > screenY) {
// make sizes a negative number to move left/up
padAmtY = (-30) + (height * -1);
// if up or to left, make 30 as padding amount
}
if((cursorX + width + padAmtX) > screenX)	{
padAmtX = (-30) + (width * -1);	
// if up or to left, make 30 as padding amount
}
if(navigator.appName == "Microsoft Internet Explorer") {
leftprop = cursorX + padAmtX;
topprop = cursorY + padAmtY;
}
else {
leftprop = (cursorX - pageXOffset + padAmtX);
topprop = (cursorY - pageYOffset + padAmtY);
   }
}
else{
leftvar = (screenX - width) / 2;
rightvar = (screenY - height) / 2;
if(navigator.appName == "Microsoft Internet Explorer") {
leftprop = leftvar;
topprop = rightvar;
}
else {
leftprop = (leftvar - pageXOffset);
topprop = (rightvar - pageYOffset);
   }
}
if(evnt == null) {
properties = properties + ", left = " + leftprop;
properties = properties + ", top = " + topprop;
}
closePopup();
popupHandle = open(url,name,properties);
}



function dis_1 ()
{
	valid = true;

	if ( document.planner.prf_alianz.value == "1" || document.planner.prf_alianz.value == "2" || document.planner.prf_alianz.value == "3")
	{
		document.planner.prf_carrier.disabled = true;

		valid = false;
	}

	if ( document.planner.prf_alianz.value == "" )
	{
		document.planner.prf_carrier.disabled = false;

		valid = true;
	}

}

function dis_2(val)
{
	if(val=="1")
	{
		document.planner.ReturnDate.disabled = true;
	}

	if(val=="2")
	{
		document.planner.ReturnDate.disabled = false;
	}
}

function validate_s1 ()
{
	valid = true;

	if ( document.planner.OrgAirport.value == "" )
	{
		alert ( "Proszę podać miejsce wylotu");
		valid = false;
	}

	if (( document.planner.DstAirport.value == "" ) && (valid == true))
	{
		alert ( "Proszę podać miejsce przylotu");
		valid = false;
	}

	return valid;
}

function validate_s3 ()
{
	valid = false;

	alert(document.forms[0].elements[6].value);

	if ( document.planner.p.man.value == "" )
	{
		alert ( "Proszę podać miejsce wyloty");
		valid = false;
	}

	if (( document.planner.DstAirport.value == "" ) && (valid == true))
	{
		alert ( "Proszę podać miejsce przylotu");
		valid = false;
	}

	return valid;
}


function validate_s4 ()
{
	valid = true;
	
		if ((document.getElementById("StartAirPort0").value) == "" && (valid == true))
	{
		alert("Proszę podać miejsce wylotu");
		valid = false;
	}
	
			if ((document.getElementById("EndAirPort0").value) == "" && (valid == true))
	{
		alert("Proszę podać miejsce przylotu");
		valid = false;
	}
	
			if ((document.getElementById("StartAirPort1").value) == "" && (valid == true))
	{
		alert("Proszę podać miejsce wylotu drugiej trasy lub skorzystać z wyszukiwania prostego");
		valid = false;
	}
	
			if ((document.getElementById("EndAirPort1").value) == "" && (valid == true))
	{
		alert("Proszę podać miejsce przylotu drugiej trasy lub skorzystać z wyszukiwania prostego");
		valid = false;
	}

	
	return valid;
}


function updatesum() {
	
	document.planner.sum.value =
	(document.planner.man.options[document.planner.man.selectedIndex].text-0) +
	(document.planner.young.options[document.planner.young.selectedIndex].text-0) +
	(document.planner.children.options[document.planner.children.selectedIndex].text-0) +
	(document.planner.oldmen.options[document.planner.oldmen.selectedIndex].text-0) +
	(document.planner.infant.options[document.planner.infant.selectedIndex].text-0);
	
	
	// niemowlenta i dorosli
		sum2 =
	(document.planner.man.options[document.planner.man.selectedIndex].text-0) +
	(document.planner.young.options[document.planner.young.selectedIndex].text-0) +
	(document.planner.children.options[document.planner.children.selectedIndex].text-0) +
	(document.planner.oldmen.options[document.planner.oldmen.selectedIndex].text-0);
	
	if ((sum2 < document.planner.infant.options[document.planner.infant.selectedIndex].text-0)){
		alert("Dzieci 0-2 nie mogą latać bez opieki.");
	}
	
	// wlaczenie alertu jezeli dzieci leca bez opieki
	if ((document.planner.infant.options[document.planner.infant.selectedIndex].text-0 > 0)
	&&(document.planner.man.options[document.planner.man.selectedIndex].text-0 < 1)
	&&(document.planner.children.options[document.planner.children.selectedIndex].text-0 < 1)
	&&(document.planner.young.options[document.planner.young.selectedIndex].text-0 < 1)
	&&(document.planner.oldmen.options[document.planner.oldmen.selectedIndex].text-0 < 1)){

		alert("Dzieci 0-2 nie mogą latać bez opieki.");return;}
		// wlaczenie alertu jezeli suma przekracza 8
		if (document.planner.sum.value > 8){
			alert("Suma rezerwowanych miejsc nie może być większa niż 8.");return;}
			// wlaczenie alertu jezeli suma jest mniejsza niz 1
			if (document.planner.sum.value < 1){
				alert("Suma rezerwowanych miejsc nie może być równa 0.");return;}

}

function val()
{
	var wyszdata1=new Array();
	var wyszdata2=new Array();
	// data w formacie dzien-miesiac-rok
	//var formatdaty = /(\d?\d)[^0-9](\d?\d)[^0-9](\d{4})/;
	var formatdaty = /^(\d{4})\D(\d\d)\D(\d\d)$/;

	wyszdata1=document.planner.DepartDate.value.match(formatdaty);
	wyszdata2=document.planner.ReturnDate.value.match(formatdaty);
	if(document.planner.ReturnDate.value.match(formatdaty)==null)
	{
		alert('Sprawdź format daty powrotu');
		return false;
	}


	//              if(wyszdata2[1]*1 + wyszdata2[2]*100 + wyszdata2[3]*10000 - wyszdata1[1]*1 - wyszdata1[2]*100 - wyszdata1[3]*10000 < 0)


	if((wyszdata2[1]<2007) || (wyszdata2[1]>2008))
	{
		alert('Sprawdź rok w dacie powrotu.')
		return false;
	}

	if((wyszdata2[2]<1) || (wyszdata2[2]>12))
	{
		alert('Sprawdź miesiąc w dacie powrotu.')
		return false;
	}


	if((wyszdata2[3]<1) || (wyszdata2[3]>31))
	{
		alert('Sprawdź dzień w dacie powrotu.')
		return false;
	}


	if(wyszdata2[1]*10000 + wyszdata2[2]*100 + wyszdata2[3]*1 - wyszdata1[1]*10000 - wyszdata1[2]*100 - wyszdata1[3]*1 < 0)

	{
		alert('Data wylotu musi być mniejsza od daty powrotu.'+ wyszdata2[1])
		return false;
	}

}

function disableHandler(date, y, m, d){
	var minDate = new Date();
	if((date.getFullYear() < minDate.getFullYear()) || (date.getFullYear() == minDate.getFullYear()
	&& date.getMonth() < minDate.getMonth()) || (date.getFullYear() == minDate.getFullYear()
	&& date.getMonth() == minDate.getMonth()
	&& date.getDate() < minDate.getDate())) // rezerwacja na 4 dni do przodu
	{
		return true;
	}
}

function setit(){

	var formatdaty = /([0-9]{4})+[-]+([0-9]{2})+[-]+([0-9]{2})/;
	wyszdata1=document.planner.DepartDate.value.match(formatdaty);

	if(document.planner.DepartDate.value.match(formatdaty)==null)
	{
		alert('Sprawdź format daty wylotu');
		return false;
	}

	if((wyszdata1[1]<2007) || (wyszdata1[1]>2008))
	{
		alert('Sprawdź rok w dacie wylotu.')
		return false;
	}

	if((wyszdata1[2]<1) || (wyszdata1[2]>12))
	{
		alert('Sprawdź miesiąc w dacie wylotu.')
		return false;
	}

	if((wyszdata1[3]<1) || (wyszdata1[3]>31))
	{
		alert('Sprawdź dzień w dacie wylotu.')
		return false;
	}

	if (document.planner.ReturnDate.value < document.planner.DepartDate.value){
		document.planner.ReturnDate.value = document.planner.DepartDate.value;

		//var d = document.getElementById("DepartDate_e").firstChild.nodeValue;
		//document.getElementById("ReturnDate_e").appendChild(document.createTextNode("aaa"));

	}
	return document.planner.ReturnDate.value;
}

function setit2(){

	
	
	if (document.getElementById("Date0").value > document.getElementById("Date1").value)
	{
	document.getElementById("Date1").value = document.getElementById("Date0").value;
	}
	
	if (document.getElementById("Date1").value > document.getElementById("Date2").value)
	{
	document.getElementById("Date2").value = document.getElementById("Date1").value;
	}
	
	if (document.getElementById("Date2").value > document.getElementById("Date3").value)
	{
	document.getElementById("Date3").value = document.getElementById("Date2").value;
	}
	
	
	
	//alert(forminputs[2].getAttribute('value'));
	

}