// function Trim
function trim(aStr) {
return aStr.replace(/^\s{1,}/, "").replace(/\s{1,}$/, "")
}
function getSelectedValue(element)
{
	return element.options.selectedIndex.value;
}
	
	function frm_validate(oForm) {
// NAME
		if (trim(oForm.name.value)=="") {
			alert("Please fill in your name");
			oForm.name.focus();
			return false;
		}
// COMPANY	(only if it's Press Inquiry)
		if (oForm.inquirytype[1].checked == true)
		{
			if (trim(oForm.company.value)=="") {
			alert("Please fill in your company");
			oForm.company.focus();
			return false;
			}
		}
// EMAIL		
		if (!checkEMail(oForm.from.value)) {
			alert("Please enter a valid internet e-mail address. Example: john.woods@amadeus.net");
			oForm.from.focus();
			return false;
		}

// TELEPHONE (only if it's Investors Inquiry)			 	
		if (oForm.inquirytype[2].checked)
		{
			if (trim(oForm.phone.value)=="") {
			alert("Please fill in your telephone");
			oForm.phone.focus();
			return false;
			}
		}
// COUNTRY		
		field = document.getElementById("countries");	
		if  (field.options[field.selectedIndex].text == "Please select")
			{
			alert("Please select a value for your country");
			oForm.countries.focus();
			return false;
		} else {
			oForm.countrydisplay.value = field.options[field.selectedIndex].text;
		}
// INFORMATION REQUEST
		if (trim(oForm.body.value)=="") {
			alert("Please fill in the Information request");
			oForm.body.focus();
			return false;
		}	
	
// aqui es donde se rellena el campo 'to'
// first areas is not empty
if (oForm.inquirytype[0].checked)
		{		
    		var checked = false;
			var counter=0;
			var numberAreas = oForm.areas.length;
			for (var r = 0; r < numberAreas; r++)
				{
				   if ( oForm.areas[r].checked)
						{
							counter=counter+1;		  
							checked=oForm.areas[r].email;
						}
				}
			
	        if ((!checked) || counter > 1)
				{
				oForm.to.value=oForm.areas[numberAreas - 1].email;
				}
			else
				{ // something selected,
				oForm.to.value=checked;
				}
		}
		
if (oForm.inquirytype[1].checked)
		{
		oForm.to.value="externalcommunication@amadeus.net";//"externalcommunication@amadeus.net";
		}
if (oForm.inquirytype[2].checked)
		{
		oForm.to.value="ir@amadeus.net";
		}
//alert(oForm.to.value);
/*
if (oForm.annualReport.checked) {
		oForm.annualreportdisplay.value = "Yes"; 
	}
*/
} // End of fuction

