// JavaScript Document
function passengerDetail(value, fieldName)
{
	document.getElementById (fieldName).value = value;
}

function showFlights()
{
	if (document.enqForm.bdReqFlights.checked == 1)
        document.getElementById('shFlights').style.display ="block";
  	else
    	document.getElementById('shFlights').style.display ="none";
}

function showCarRental()
{
	if (document.enqForm.bdReqCar.checked == 1)
    	document.getElementById('shCarRental').style.display ="block";
    else
    	document.getElementById('shCarRental').style.display ="none";
}
	  
function displayChildAgeBoxes(numChildFld, divName, totNum) 
{
	
	var numChild = document.getElementById(numChildFld).value;
	
	document.getElementById(divName).style.display = numChild > 0 ? "" : "none";
	
	for (i=1; i<=numChild; i++)
		document.getElementById(divName + i).style.display = "block";
		
	for (; i<=totNum; i++)
		document.getElementById(divName + i).style.display = "none";
}

var passengerCount = 3;
	
function addPassenger()
{
	document.getElementById('passenger'+ passengerCount).style.display ="block";
	passengerCount ++;
}

function verify()
{
	var lclMsg = "";
	
	if (document.enqForm.cdFirstName.value == "") 
		lclMsg += "- Included your first name \n";
	
	if (document.enqForm.cdLastName.value == "") 
		lclMsg += "- Included your last name \n";	
	
	if (document.enqForm.cdPhone.value == "") 
	{
		lclMsg += "- Included a valid contact phone \n";
	}
	else if (isValidPhone(document.enqForm.cdPhone.value) != true) 
	{
		lclMsg += "- Please check that your contact phone is valid \n"; 
	}
		
	if (document.enqForm.cdEmail.value == "") 
	{
		lclMsg += "- Included a valid email address \n";	
	}
	else if (isValidEmail(document.enqForm.cdEmail.value) != true) 
	{
		lclMsg += "- Please check that your email address is valid \n";
	}
	
	if (lclMsg != "") 
	{
		lclMsg = "Please ensure you have...\n" + lclMsg;
		alert(lclMsg);
		return false;
	}
	else 
	{	
		return true;
	}
}

function isValidEmail(str) 
{
   	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function isValidPhone(str) 
{
   	return (str.length > 7);
}
	
function verify_request_form(){
	var lclMsg = "";
	var flightVal = document.enqForm.bdReqFlights;
	var fromVal = document.enqForm.bdFrom;
	var regex = new RegExp(/^\s+$/);

	if (flightVal != null && flightVal.checked == true && fromVal != null && (regex.test(fromVal.value) || fromVal.value.length == 0))
		lclMsg += "- Please specify your flight from city\n";
	
	if (document.enqForm.cdFirstName.value == "")
		lclMsg += "- Included your first name \n"; 
		
	if (document.enqForm.cdLastName.value == "")
		lclMsg += "- Included your last name \n"; 
		
	if (document.enqForm.cdPhone.value == "") 
	{
		lclMsg += "- Included a valid contact phone \n";
	}
	else if (isValidPhone(document.enqForm.cdPhone.value) != true) 
	{
		lclMsg += "- Entered a valid contact phone \n"; 
	}
	
	if (document.enqForm.cdEmail.value == "")
	{
		lclMsg += "- Included a valid email address \n"; 
	} 
	else if (isValidEmail(document.enqForm.cdEmail.value) != true) 
	{
		lclMsg += "- Entered a valid email address \n"; 
	}
		
	if(lclMsg != "")
    {
		lclMsg = "Please ensure you have...\n" + lclMsg;
		alert(lclMsg);
		return false;
    }
    else
    {		
		return true;
    } 
}
