function findselected() {
var ret = document.getElementById('select_return');
var ret_day = document.getElementById('return_date_day');
var ret_month = document.getElementById('return_date_month');
var ret_year = document.getElementById('return_date_year');
var ret_hour = document.getElementById('return_time_hour');
var ret_min = document.getElementById('return_time_min');
(ret.value == "Y")? (ret_day.disabled=false, ret_month.disabled=false, ret_year.disabled=false, ret_hour.disabled=false, ret_min.disabled=false) : (ret_day.disabled=true, ret_month.disabled=true, ret_year.disabled=true, ret_hour.disabled=true, ret_min.disabled=true)
}

function changelabel() {
	document.getElementById('country').value = 'HOLA';
var type = document.getElementById('transfer_type');
var country = document.getElementById('country');
(type.value == "AR")? (country.value='hola') : (country.value='chao')
}

function validate_transfer_selected(field,alerttxt) {
	with (field){
		if (value==""){
			alert(alerttxt);
			return false;
		}
		else {return true}
	}
}

function validate_country_selected(field,alerttxt) {
	with (field){
		if (value==""){
			alert(alerttxt);
			return false;
		}
		else {return true}
	}
}

function validate_airport_selected(field,alerttxt) {
	with (field){
		if (value==""){
			alert(alerttxt);
			return false;
		}
		else {return true}
	}
}

function validate_resort_selected(field,alerttxt) {
	with (field){
		if (value==""){
			alert(alerttxt);
			return false;
		}
		else {return true}
	}
}

function validate_arrival_time_selected(field,alerttxt) {
	with (field){
		if (value==""){
			alert(alerttxt);
			return false;
		}
		else {return true}
	}
}


function validate_adults_selected(field,alerttxt) {
	with (field){
		if (value==""){
			alert(alerttxt);
			return false;
		}
		else {return true}
	}
}

function validate_infants_selected(field,alerttxt) {
	with (field){
		if (value==""){
			alert(alerttxt);
			return false;
		}
		else {return true}
	}
}


function validate_return(field,alerttxt) {
	with (field){
		if (value==""){
			alert(alerttxt);
			return false;
		}
		else {return true}
	}
}

function checkdate(input){
var validformat=/^\d{2}\/\d{2}\/\d{2}$/ //Basic check for format validity
var returnval=false
if (!validformat.test(input.value))
alert("Invalid Date Format. Please correct and submit again.")
else{ //Detailed check for valid date ranges
var monthfield=input.value.split("/")[0]
var dayfield=input.value.split("/")[1]
var yearfield=input.value.split("/")[2]
var dayobj = new Date(yearfield, monthfield-1, dayfield)
if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
else
returnval=true
}
if (returnval==false) input.select()
return returnval
}








/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDatex(dtStr){
	var now = new Date();
	var currentmonthnumber = now.getMonth();
	var currentmonthday = now.getDate();
	var currentyear = now.getYear();	
	
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth) 
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
	
	
	if (currentmonthnumber > month && currentyear == year) {
		alert("Please enter a valid date")
		return false
	}
	
	if (currentyear > year) {
		alert("Please enter a valid date")
		return false
	}	
	
	//mismo mes pero el dia es menor al actual
	currentmonthnumber = currentmonthnumber +1
	if (currentmonthnumber == month && currentmonthday > day) {
		alert("Please enter a valid date")
		return false
	}
	
	//var d = new Date(month+"/"+day+"/"+year);
	//alert((d.getMonth())+"/"+d.getDate()+"/"+d.getFullYear());	
	
	if (currentmonthnumber == month && currentmonthday == day) {	
		alert("For transfers within 24 hours of departure please call +353 85 77 33 939")
		return false
	}
	
	if (currentmonthnumber == month && currentmonthday == day-1) {
		alert("For transfers within 24 hours of departure please call +353 85 77 33 939")
		return false
	}	
	
return true
}

function isDate(dtStr, dt2){
	var now = new Date();
	var currentmonthnumber = now.getMonth();
	var currentmonthday = now.getDate();
	var currentyear = now.getYear();	
	
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	
	
	//**************************************
	var daysInMonth = DaysArray(12)
	var p1=dt2.indexOf(dtCh)
	var p2=dt2.indexOf(dtCh,p1+1)
	var strM=dt2.substring(0,p1)
	var strD=dt2.substring(p1+1,p2)
	var strY=dt2.substring(p2+1)
	strYe=strY
	if (strD.charAt(0)=="0" && strD.length>1) strD=strD.substring(1)
	if (strM.charAt(0)=="0" && strM.length>1) strM=strM.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYe.charAt(0)=="0" && strYe.length>1) strYe=strYe.substring(1)
	}
	travelmonth=parseInt(strM)
	travelday=parseInt(strD)
	travelyear=parseInt(strYe)	
	//**************************************
	
	
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
		
	var d1 = new Date(travelmonth+"/"+travelday+"/"+travelyear);
	var d2 = new Date(month+"/"+day+"/"+year);
	
	if (d2 < d1) {
		alert("Incorrect return date")
		return false
	}	
	
//	if (currentmonthnumber > month && currentyear == year) {
//		alert("Please enter a valid date")
//		return false
//	}
	
//	if (currentyear > year) {
//		alert("Please enter a valid date")
//		return false
//	}
	
	//mismo mes pero el dia es menor al actual
//	currentmonthnumber = currentmonthnumber +1
//	if (currentmonthnumber == month && currentmonthday > day) {
//		alert("Please enter a valid date")
//		return false
//	}	
	
return true
}







function validate_form(thisform) {
	
	with (thisform) {  

		if (validate_transfer_selected(transfer_type,"You must select a transfer type")==false) {
			transfer_type.focus();
			return false;
		}

		else if (validate_country_selected(select_destinations,"You must select a country")==false) {
			select_destinations.focus();
			return false;
		}

		else if (validate_airport_selected(select_airports,"You must select an airport/resort")==false) {
			select_airports.focus();
			return false;
		}

		else if (validate_resort_selected(resorts,"You must select a resort")==false) {
			resorts.focus();return false;
		}

		else if (validate_arrival_time_selected(arrival_time_hour,"You must select a flight time")==false) {
			arrival_time_hour.focus();return false;
		}

		else if (validate_arrival_time_selected(arrival_time_min,"You must select a flight time")==false) {
			arrival_time_min.focus();return false;
		}
		
		else if (isDatex(document.getElementById("traveldate_month").value + "/" + document.getElementById("traveldate_day").value + "/" + document.getElementById("traveldate_year").value)==false) {
			traveldate_day.focus();
			return false;
		}
			
		else if (document.getElementById("select_return").value == 'Y') {
			
			if (isDate(document.getElementById("return_date_month").value + "/" + document.getElementById("return_date_day").value + "/" + document.getElementById("return_date_year").value, document.getElementById("traveldate_month").value + "/" + document.getElementById("traveldate_day").value + "/" + document.getElementById("traveldate_year").value)==false) {
				return_date_day.focus();
				return false;
			}			
			
			if (validate_arrival_time_selected(return_time_hour,"You must select a departure flight time")==false) {
				return_time_hour.focus();return false;
			}
			
			if (validate_arrival_time_selected(return_time_min,"You must select a departure flight time")==false) {
				return_time_min.focus();return false;
			}
		}		

		else if (validate_adults_selected(passengers,"You must enter the number of adults/children")==false) {
			passengers.focus();return false;
		}

		else if (validate_infants_selected(infants,"You must enter the number of infants")==false) {
			infants.focus();return false;
		}

		else {
			submitForm();
		}
	}
}