/* cimoldali repjegy form  js-ei */

function progress1() {

	document.getElementById('repjegyek_form').action="http://www.travelstoremaker.com/cgit/runhttl";
	document.getElementById('repjegyek_form').method="get";
	document.getElementById('repjegyek_form').submit();
	
	return true;
} 

function isLeapYear(argYear)
{
	return ((argYear % 4 == 0) && (argYear % 100 != 0)) || (argYear % 400 == 0)
}


function daysInMonth(argMonth, argYear) {
	switch (Number(argMonth)) {
		case 1: // Jan
		case 3: // Mar
		case 5: // May
		case 7: // Jul
		case 8: // Aug
		case 10: // Oct
		case 12: // Dec
		return 31;
		break;
		case 4: // Apr
		case 6: // Jun
		case 9: // Sep
		case 11: // Nov
		return 30;
		break;
		case 2: // Feb
		if (isLeapYear(argYear))
		return 29
		else
		return 28
		break;
		default:
		return 0;
	}
}

function checkair()
{
	if (document.getElementById("fromcity").value=="")
	{
		niceMsg ('air_start');
		return false;
	}
	if (document.getElementById("fromcity").value==" ")
	{
		niceMsg ('air_start');
		return false;
	}
	if (document.getElementById("tocity").value=="")
	{
		niceMsg ('air_end');
		return false;
	}
	if (document.getElementById("tocity").value==" ")
	{
		niceMsg ('air_end');
		return false;
	}
	if ((document.repjegyek_form.numptc1.selectedIndex+document.repjegyek_form.numptc2.selectedIndex+document.repjegyek_form.numptc3.selectedIndex) == 0)
	{
		niceMsg('air_passnum');
		return false;
	}
	if ((document.repjegyek_form.numptc1.selectedIndex+document.repjegyek_form.numptc2.selectedIndex+document.repjegyek_form.numptc3.selectedIndex) >= 10)
	{
		niceMsg ('air_pass_sum');
		return false;
	}
	if (document.repjegyek_form.numptc1.selectedIndex == 0 && document.repjegyek_form.numptc3.selectedIndex >= 1)
	{
		niceMsg('air_child');
		return false;
	}

	var outday=document.repjegyek_form.outday.selectedIndex + 1;
	var outmonth=document.repjegyek_form.outmonth.selectedIndex;
	var outyear=document.repjegyek_form.outyear.value;

	var outDate = new Date();
	outDate.setFullYear(outyear, outmonth, outday);

	var retday=document.repjegyek_form.retday.selectedIndex + 1;
	var retmonth=document.repjegyek_form.retmonth.selectedIndex;
	var retyear=document.repjegyek_form.retyear.value;

	var calendar=new Date();
	var nowday=calendar.getDate();
	var nowmonth=calendar.getMonth();
	var nowyear=calendar.getFullYear();

	// legkisebb dátum, amit be lehet állítani a repjegykeresőbe
	var minDate=new Date()
	minDate.setDate(minDate.getDate()+4);

	if(outyear==nowyear && outmonth<nowmonth)
	{
		document.repjegyek_form.retyear.value=parseFloat(outyear)+1;
	}
	else if(outyear==nowyear && outmonth==nowmonth && outday<nowday)
	{
		document.repjegyek_form.retyear.value=parseFloat(outyear)+1;
	}
	else if(outDate<minDate)
	{
		niceMsg ('air_start_min');
		return false;
	}

	if (outyear>retyear)
	{
		document.repjegyek_form.retyear.value=parseFloat(outyear)+1;
	}
	if (outyear==retyear && outmonth>retmonth)
	{
		document.repjegyek_form.retyear.value=parseFloat(outyear)+1;
	}
	else if(outyear==retyear && outmonth==retmonth && outday>retday)
	{
		document.repjegyek_form.retyear.value=parseFloat(outyear)+1;
	}
	else if(outyear==retyear && outmonth==retmonth && outday==retday)
	{
		document.repjegyek_form.retyear.value=parseFloat(outyear)+1;
	}
	if (outday > daysInMonth (outmonth+1,outyear))
	{
		niceMsg ('air_start_error');
		return false;
	}
	else if (retday > daysInMonth (retmonth+1,retyear))
	{
		niceMsg ('air_end_error');
		return false;
	}
	return true;
}

function changedate(formname)
{
	if (formname=="air")
	{
		if (document.repjegyek_form.outday.selectedIndex+4>=30)
		{
			document.repjegyek_form.retday.selectedIndex=document.repjegyek_form.outday.selectedIndex-30+4;
			if (document.repjegyek_form.outmonth.selectedIndex>=11)
			{
				document.repjegyek_form.retmonth.selectedIndex=0;
				document.repjegyek_form.retyear.value=parseFloat(document.repjegyek_form.outyear.value)+1;
			}
			else
			{
				document.repjegyek_form.retmonth.selectedIndex=document.repjegyek_form.outmonth.selectedIndex+1;
				document.repjegyek_form.retyear.value=document.repjegyek_form.outyear.value;
			}

		}
		else
		{
			document.repjegyek_form.retmonth.selectedIndex=document.repjegyek_form.outmonth.selectedIndex;
			document.repjegyek_form.retday.selectedIndex=document.repjegyek_form.outday.selectedIndex+4;
			document.repjegyek_form.retyear.value=document.repjegyek_form.outyear.value;
		}

		cal=new Date();
		sel_omonth = document.repjegyek_form.outmonth.selectedIndex;
		sel_rmonth = document.repjegyek_form.retmonth.selectedIndex;
		this_month = cal.getMonth();
		this_year = cal.getFullYear();
		if ( sel_omonth < this_month )
			document.repjegyek_form.outyear.value = this_year + 1;
		else
			document.repjegyek_form.outyear.value=this_year;

		if ( sel_rmonth < this_month )
			document.repjegyek_form.retyear.value = this_year + 1;
		else
			document.repjegyek_form.retyear.value=this_year;
	}
}

function changedate2(formname)
{
	if (formname=="air")
	{
		var od = parseInt(String(document.repjegyek_form.outyear.value + '' + (document.repjegyek_form.outmonth.value < 10 ? '0' : '') + document.repjegyek_form.outmonth.value + '' + (document.repjegyek_form.outday.value < 10 ? '0' : '') + document.repjegyek_form.outday.value));
		var rd = parseInt(String(document.repjegyek_form.retyear.value + '' + (document.repjegyek_form.retmonth.value < 10 ? '0' : '') + document.repjegyek_form.retmonth.value + '' + (document.repjegyek_form.retday.value < 10 ? '0' : '') + document.repjegyek_form.retday.value));

		if(rd < od)
		{
			if(document.repjegyek_form.retyear.selectedIndex == 0)
			{
				document.repjegyek_form.retyear.selectedIndex == 1;
			}
			else
			{
				document.repjegyek_form.retmonth.selectedIndex=document.repjegyek_form.outmonth.selectedIndex;
				document.repjegyek_form.retday.selectedIndex=document.repjegyek_form.outday.value;
				document.repjegyek_form.retyear.selectedIndex=document.repjegyek_form.outyear.selectedIndex;
			}
		}

		cal=new Date();
		sel_omonth = document.repjegyek_form.outmonth.selectedIndex;
		sel_rmonth = document.repjegyek_form.retmonth.selectedIndex;
		this_month = cal.getMonth();
		this_year = cal.getFullYear();
		if ( sel_omonth < this_month )
			document.repjegyek_form.outyear.value = this_year + 1;
		else
			document.repjegyek_form.outyear.value=this_year;

		if ( sel_rmonth < this_month )
			document.repjegyek_form.retyear.value = this_year + 1;
		else
			document.repjegyek_form.retyear.value=this_year;
	}

}

function set_date() {
	
	calendar=new Date();
		
	var advpurchase=4;
	calendar.setDate(calendar.getDate()+advpurchase);
	document.repjegyek_form.outday.selectedIndex=calendar.getDate()-1;
	document.repjegyek_form.outmonth.selectedIndex=calendar.getMonth();
	document.repjegyek_form.outyear.value=calendar.getFullYear();
	calendar.setDate(calendar.getDate()+7);
	document.repjegyek_form.retday.selectedIndex=calendar.getDate()-1;
	document.repjegyek_form.retmonth.selectedIndex=calendar.getMonth()
	document.repjegyek_form.retyear.value=calendar.getFullYear();
}



