// JavaScript Document
function kus_trans_show_menu(id, disp)
{
	sub_menu = document.getElementById(id);
	sub_menu.style.display = disp; 
}

function kus_trans_hide(id)
{
	id.style.display = 'none';
}

function aa(firm_id,firm,cid)
{
this.firm_id=firm_id;
this.firm=firm;
this.cid=cid;
}

function sel_town(form1, SelTown){
	for (i=0;i<form1.Town.length;i++)
	{
		if (form1.Town[i].value == SelTown)
		{
			form1.Town[i].selected=true;
		}
	}
 // form1.Town.options[SelTown].selected=true;  
}

function fill_combo(form1, id){
form1.Resort.length=0;
flag=false;
   form1.Resort.length=0;
   for(i=1;i<city_array.length;i++)
   {
       if(city_array[i].cid==id)
       {
	     flag=true;
         add_to_select_city(city_array[i].firm_id, city_array[i].firm,form1.Resort);
       }
   }
  form1.Resort.options[0].selected=true;  
  form1.Resort.disabled = false;
}

function add_to_select_city(id,text1,list2)
{
 var opt=new Option();
    opt.value=id;
    opt.text=text1;
    list2.options[list2.options.length]=opt;
}
function returndate(form,value)
{
	if (value != 'RoundTrip')
	{
		form.outD.disabled = true;
		form.outM.disabled = true;
		form.outY.disabled = true;
	} 
	if (value =='RoundTrip')
	{
		form.outD.disabled = false;
		form.outM.disabled = false;
		form.outY.disabled = false;
	}
}
function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;  // date is valid
}

function check_transfer(res_form)
{
	
	drop = '';
	pick = '';
	type = res_form.type.value;
	today = new Date();

	if (type == 'RoundTrip')
	{
		var pickday = res_form.inD.value;
		var pickmonth = res_form.inM.value;
		var pickyear = res_form.inY.value;
		var pickup = new Date(pickyear, pickmonth-1, pickday, 23, 59);

		var dropday = res_form.outD.value;
		var dropmonth = res_form.outM.value;
		var dropyear = res_form.outY.value;
		var dropoff = new Date(dropyear, dropmonth-1, dropday, 23, 59);
		
		if (pickup < today)
		{
			alert('Arrival Date is Today or in the Past, please call +90 (0)256 618 3602 for last minute availability!');
			return false;
		}
		if (dropoff < today)
		{
			alert('Return Date is in the Past, please check!');
			return false;
		}
		if (dropoff <= pickup)
		{
			alert('Return Date is before Arrival Date, please check!');
			return false;
		}
		if (! isValidDate(pickmonth+'-'+pickday+'-'+pickyear) ) {
			alert('Arrival Date is invalid, please check!');
			return false;
		}
		if (! isValidDate(dropmonth+'-'+dropday+'-'+dropyear) ) {
			alert('Return Date is invalid, please check!');
			return false;
		}
	}
	else
	{
		var pickday = res_form.inD.value;
		var pickmonth = res_form.inM.value;
		var pickyear = res_form.inY.value;
		var pickup = new Date(pickyear, pickmonth-1, pickday, 23, 59);

		if (pickup < today)
		{
			alert('Arrival Date is Today or in the Past, please call +90 (0)256 618 3602 for last minute availability!');
			return false;
		}
		if (! isValidDate(pickmonth+'-'+pickday+'-'+pickyear) ) {
			alert('Arrival Date is invalid, please check!');
			return false;
		}
	}

	return true;
}
