var glMaxRegions = 3	// Maximum number of Regions user can select

$( function() {
	if ($('#selWhich_regions_interested_in').length) {
		$('#selWhich_regions_interested_in').change(function() {
			$(this).attr("title", $(this).val());
		});
		$('#selWhich_regions_interested_in').change();
	}

	if ($('.navigationTabs ul #ParcNav1_tab1 a').length) {
		$('.navigationTabs ul li a').click(function() {
			$('#tb1, #tb2, #tb3, #tb4, #tb5').hide();
			var myTab = $(this).parent().attr("id").substr(12);
			$('#tb' + myTab).show();

			$('.navigationTabs ul li').removeClass('active');
			$(this).parent().addClass('active');
			return false;
		});
		
		
		$(".navigationTabs ul li:eq(0) a").click();
		$(".navigationTabs ul li a").each(function() {
			if (location.href.indexOf("?" + $(this).attr("tabName")) != -1) $(this).click();
		});
	}
});

$(function() {
	if ($('.travelInformation .destination .destinations').length) {
		$('.travelInformation .destination .destinations li a').click(function() {
			var travelOptionTab = $('.travelInformation h2').attr("class");

			// Car hire processing
			if (travelOptionTab == "car") $('.travelInformation .destination div').hide();

			$('.travelInformation .destination .destinations li a').each(function() {
				$(this).removeClass().addClass($(this).attr("href"));
			});
			var selectedCountry = $(this).attr("href");
			$(this).removeClass().addClass(selectedCountry + "Active");

			// Car hire processing
			if (travelOptionTab == "car") {
				$('.travelInformation .destination #' + selectedCountry).show();
			} else {
				var params, flashvars, attributes, selectedCountryCode = '';

				switch (selectedCountry) {
					case "portugal":
						$("#airportH").html("Airports in Portugal");
						flashvars = { country: 4, xmlLink: "/flash/maps/assets/TAFData.xml", mapZoom3Link: "/flash/maps/map_zoom_3.swf" };
						selectedCountryCode = "PT";
						break;
					case "spain":
						$("#airportH").html("Airports in Spain");
						flashvars = { country: 5, xmlLink: "/flash/maps/assets/TAFData.xml", mapZoom3Link: "/flash/maps/map_zoom_3.swf" };
						selectedCountryCode = "ES";
						break;
					case "croatia":
						$("#airportH").html("Airports in Croatia");
						flashvars = { country: 0, xmlLink: "/flash/maps/assets/TAFData.xml", mapZoom3Link: "/flash/maps/map_zoom_3.swf" };
						selectedCountryCode = "HR";
						break;
					case "netherlands":
						$("#airportH").html("Airports in Netherlands");
						flashvars = { country: 3, xmlLink: "/flash/maps/assets/TAFData.xml", mapZoom3Link: "/flash/maps/map_zoom_3.swf" };
						selectedCountryCode = "NL";
						break;
					case "france":
						$("#airportH").html("Airports in France");
						flashvars = { country: 1, xmlLink: "/flash/maps/assets/TAFData.xml", mapZoom3Link: "/flash/maps/map_zoom_3.swf" };
						selectedCountryCode = "FR";
						break;
					case "italy":
						$("#airportH").html("Airports in Italy");
						flashvars = { country: 2, xmlLink: "/flash/maps/assets/TAFData.xml", mapZoom3Link: "/flash/maps/map_zoom_3.swf" };
						selectedCountryCode = "IT";
						break;
				}
				params = { wmode: "transparent", menu: "true", play: "true", scale: "showall", devicefont: "false", quality: "high", allowFullScreen: "false", allowScriptAccess: "sameDomain", align: "middle" };
				attributes = {};
				swfobject.embedSWF("/flash/maps/map_country_airports_page.swf", "flashMap", "303", "382", "8.0.0", false, flashvars, params, attributes);
				first(selectedCountryCode);
			}

			return false;
		});

		$('.travelInformation .destination .destinations li a.france').click();
	}
});

function validateBrochureForm(f) {
	var strEmail = f.TXTEMAIL.value;
	
	if ($(".brochure input:checked").length == 0) {
		alert("Please choose a brochure");
		$(".brochure input:checkbox:eq(0)").focus();
		return false;
	}

	if ($(".brochure input:checked").length == 1) $('#BROCHURE_SOURCE').val($(".brochure input:checked").val());
	else $('#BROCHURE_SOURCE').val("Both");

	if (f.TXTTITLE.value == "") {
		alert("Please enter your title.");
		f.TXTTITLE.focus();
		return false;
	}

	if (f.TXTFIRSTNAME.value=="") {
		alert("Please enter your first name.");
		f.TXTFIRSTNAME.focus();
		return false;
	}

	if (f.TXTSURNAME.value=="") {
		alert("Please enter your last name.");
		f.TXTSURNAME.focus();
		return false;
	}

	if (f.TXTADDRESSLINE1.value=="" && f.TXTADDRESSLINE2.value=="" && f.TXTADDRESSLINE3.value=="" && f.TXTADDRESSLINE4.value=="" ) {
		alert("Please enter address.");
		f.TXTADDRESSLINE1.focus();
		return false;
	}

	if (f.TXTPOSTCODE.value=="") {
		alert("Please enter your postcode.");
		f.TXTPOSTCODE.focus();
		return false;
	}

	if (f.TXTCOUNTRY.value=="") {
		alert("Please enter your Country name.");
		f.TXTCOUNTRY.focus();
		return false;
	}

	if (strEmail == "") {
		alert("Please enter your email address.");
		f.TXTEMAIL.focus();
		return false;
	}

	if (strEmail != "") {
		strEmail=strEmail.toLowerCase();
		Pat1 = /^([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+$/;
		if (!Pat1.test(strEmail)) {
			alert("Please enter Valid email address.");
			f.TXTEMAIL.focus();
			return false;
		}
	}

	if (f.selWhere_did_you_here_about_us.selectedIndex == 0) {
		alert("Please select how did you hear about us.");
		f.selWhere_did_you_here_about_us.focus();
		return false;
	}

//alert(f.selWhich_regions_interested_in.length);
var region_selected = false;
for(i=0; i<f.selWhich_regions_interested_in.length; i++)
{
  if(f.selWhich_regions_interested_in[i].checked)
  {
    //alert(f.selWhich_regions_interested_in[i].value);
    region_selected = true;
  }
}
if (!region_selected)
{
  alert("Please select which regions you are interested in (maximum 3)");
  return false;
}  
/*OLD validation for use with select drop down
	if (f.selWhich_regions_interested_in.selectedIndex == 0) {
		alert("Please select which regions you are interested in");
		f.selWhich_regions_interested_in.focus();
		return false;
	} else {
		var lnSelected = 0;
		$("#selWhich_regions_interested_in option:selected").each(function () {
				lnSelected++;
			});
		if (lnSelected > glMaxRegions) {
			alert("Please select which regions you are interested in (maximum 3)");
			f.selWhich_regions_interested_in.focus();
			return false;
		}
	}
*/

	if (f.descParty.selectedIndex==0) {
		alert("Please select how would you describe your party.");
		f.descParty.focus();
		return false;
	}

	if (!f.chkfour.checked) {
		alert("Please accept our Privacy Policy.");
		f.chkfour.focus();
		return false;
	}
		
	return true;
}


function proceedRequest() {
	if (validateBrochureForm(document.frmRequestBrochure)) {
		//formatRegions();
    formatRegions(document.frmRequestBrochure);
		return true;
	} else {
		return false;
	}
}

function formatRegions(f)
{
  var lsSepRegions = ""; 
  var idx = 0;
  var itemsChecked = 0;
  for (idx = 0; idx < f.selWhich_regions_interested_in.length; idx++) 
  {
    if (f.selWhich_regions_interested_in[idx].checked) 
    {
      lsSepRegions += "\"" + f.selWhich_regions_interested_in[idx].value + "\"";
      itemsChecked++;
      
      if (itemsChecked < (glMaxRegions)) //we want to seperate with comman "1" , "2" , "3" but not a comma on last one
      {
        lsSepRegions += ",";
      }
    } 
  }
  

  while (itemsChecked < glMaxRegions) //less than glMaxRegions checked, we still need to to do quotes "1" , "" , ""
  {
    lsSepRegions += "\"\"";
    itemsChecked++;
    if (itemsChecked < (glMaxRegions)) //we want to seperate with comma but not a comma on last one
    {
      lsSepRegions += ",";
    }
  }
	$("#SEP_REGIONS").val(lsSepRegions);
}

/*
function formatRegions(f)
{
  var lsSepRegions = ""; 
  var idx = 0;
	for (idx = 0; idx < glMaxRegions; idx++) {
		if (idx < f.selWhich_regions_interested_in.length) {
			lsSepRegions += "\"" + f.selWhich_regions_interested_in[idx].value + "\"";
		} else {
			lsSepRegions += "\"\"";
		}
		if (idx < (glMaxRegions - 1)) {lsSepRegions += ",";}
	}
	$("#SEP_REGIONS").val(lsSepRegions);
}
*/
/*OLD function for use with select drop down
function formatRegions() {
	var laRegions = $("#selWhich_regions_interested_in").val(), lsSepRegions = "", idx = 0;
	for (idx = 0; idx < glMaxRegions; idx++) {
		if (idx < laRegions.length) {
			lsSepRegions += "\"" + laRegions[idx] + "\"";
		} else {
			lsSepRegions += "\"\"";
		}
		if (idx < (glMaxRegions - 1)) {lsSepRegions += ",";}
	}
	$("#SEP_REGIONS").val(lsSepRegions);
}
*/