// JavaScript Document

var currentEnabled = null;

function enableElement(elem) 
	{
		if (currentEnabled)
			{
				currentEnabled.disabled = true;
			}
		elem.disabled = false;
		currentEnabled = elem;
	}


function GGGValidator()
{
	//FirstName
	if("First Name"==document.form.FirstName.value)
		{
			document.form.FirstName.value='';
			document.form.FirstName.focus();
			return false;
		}
	//LastName
	if("Last Name"==document.form.LastName.value)
		{
			document.form.LastName.value='';
			document.form.LastName.focus();
			return false;
		}
	//Phone
	if("Phone"==document.form.Phone.value)
		{
			document.form.Phone.value='';
			document.form.Phone.focus();
			return false;
		}
	//Email
	if("Email"==document.form.EMAIL.value)
		{
			document.form.EMAIL.value='';
			document.form.EMAIL.focus();
			return false;
		}
	//AircraftTailNumber
	if("Aircraft Tail Number"==document.form.ACTailNumber.value)
		{
			document.form.ACTailNumber.value='';
			document.form.ACTailNumber.focus();
			return false;
		}
	//AircraftType
	if(""==document.form.ACType.value)
		{
			document.form.ACType.focus();
			return false;
		}
	//Company
	if("Company"==document.form.Company.value)
		{
			document.form.Company.value='';
			document.form.Company.focus();
			return false;
		}
	//Address
	if("Address"==document.form.Address.value)
		{
			document.form.Address.value='';
			document.form.Address.focus();
			return false;
		}
	//City
	if("City"==document.form.City.value)
		{
			document.form.City.value='';
			document.form.City.focus();
			return false;
		}
	//PostalCode
	if("Postal Code"==document.form.PostalCode.value)
		{
			document.form.PostalCode.value='';
			document.form.PostalCode.focus();
			return false;
		}
	//Country
	if(""==document.form.Country.value)
		{
			document.form.Country.focus();
			return false;
		}
		
	//Terms Initials
	if(""==document.form.TermsOfAcceptance_Initials.value)
		{
			alert("You must type your initials in the field provided to acknowledge that you have read and accept the Terms and Agreement.");
			document.form.TermsOfAcceptance_Initials.focus();
			return false;
		}
}

function Oreo()
	{
		GGGValidator();
		GGGEmailValidator();
		
		cookiejar.crumble ('spkp080001');
		
		var firstname=document.form.FirstName.value;
		var lastname=document.form.LastName.value;
		
		if("Title"==document.form.Title.value)
			{
				var title=' ';
			}
		else
			{
				var title=document.form.Title.value;
			}
			
		var phone=document.form.Phone.value;
		var email=document.form.EMAIL.value;
		var actail=document.form.ACTailNumber.value;
		var actype=document.form.ACType.value;
		var company=document.form.Company.value;
		var address=document.form.Address.value;
		
		if(""==document.form.Address2.value)
			{
				var address2=' ';
			}
		else
			{
				var address2=document.form.Address2.value;
			}
		
		var city=document.form.City.value;
		
		if("State"==document.form.State.value)
			{
				var state=' ';
			}
		else
			{
				var state=document.form.State.value;
			}
			
		var postalcode=document.form.PostalCode.value;
		var country=document.form.Country.value;
		var refform='FTO';
		
		for (loopy=0;loopy<document.form.UniversalClient.length;loopy++)
			{
				if (document.form.UniversalClient[loopy].checked)
					{
						var uwac = document.form.UniversalClient[loopy].value;
					}
			}
			
		for (loopy=0;loopy<document.form.ContactTime.length;loopy++)
			{
				if (document.form.ContactTime[loopy].checked)
					{
						var ct = document.form.ContactTime[loopy].value;
					}
			}
			
		if("Time of Day"==document.form.TimeOfDay.value)
			{
				var timeofday=' ';
			}
		else
			{
				var timeofday=document.form.TimeOfDay.value;
			}		

		if("none"==document.form.TimeZone.value)
			{
				var tz=' ';
			}
		else
			{
				var tz=document.form.TimeZone.value;
			}	

		for (loopy=0;loopy<document.form.RunwayAnalysis.length;loopy++)
			{
				if (document.form.RunwayAnalysis[loopy].checked)
					{
						var runa = document.form.RunwayAnalysis[loopy].value;
					}
			}
		for (loopy=0;loopy<document.form.WeightBalance.length;loopy++)
			{
				if (document.form.WeightBalance[loopy].checked)
					{
						var wb = document.form.WeightBalance[loopy].value;
					}
			}
		for (loopy=0;loopy<document.form.DataLinkServices.length;loopy++)
			{
				if (document.form.DataLinkServices[loopy].checked)
					{
						var dls = document.form.DataLinkServices[loopy].value;
					}
			}
			
		var comm=document.form.Comments.value;
		var terms='Yes';
		var termsinitials=document.form.TermsOfAcceptance_Initials.value;
		if("PROMO CODE"==document.form.State.value)
			{
				var promo=' ';
			}
		else
			{
				var promo=document.form.PromoCode.value;
			}
		
		subcookiejar.bake ('spkp080001',
			{
			   firstname: firstname,
			   lastname: lastname,
			   title: title,
			   phone: phone,
			   email: email,
			   actail: actail,
			   actype: actype,
			   company: company,
			   address: address,
			   address2: address2,
			   city: city,
			   state: state,
			   postalcode: postalcode,
			   country: country,
			   refform: refform,
			   uwac: uwac,
			   ct: ct,
			   timeofday: timeofday,
			   tz: tz,
			   runa: runa,
			   wb: wb,
			   dls: dls,
			   comm: comm,
			   terms: terms,
			   termsinitials: termsinitials,
			   promo: promo
			}, 1);
	}

function echeck(str)
	{

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		if (str.indexOf(at)==-1)
			{
			   alert("Invalid e-mail format.");
			   return false;
			}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
			{
				alert("Invalid e-mail format.");
				return false;
			}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
			{
				alert("Invalid e-mail format.");
				return false;
			}
			
		if (str.indexOf(at,(lat+1))!=-1)
			{
				alert("Invalid e-mail format.");
				return false;
			}
			
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
			{
				alert("Invalid e-mail format.");
				return false;
			}

		 if (str.indexOf(dot,(lat+2))==-1)
		 	{
				alert("Invalid e-mail format.");
				return false;
			}
		
		 if (str.indexOf(" ")!=-1)
		 	{
				alert("Invalid e-mail format.");
				return false;
			}

 		 return true;					
	}


function GGGEmailValidator()
	{
		if ((document.form.EMAIL.value==null)||(document.form.EMAIL.value==""))
		{
			alert("Invalid e-mail format.");
			document.form.EMAIL.value='';
			document.form.EMAIL.focus();
			return false;
		}
		
		if (echeck(document.form.EMAIL.value)==false)
		{
			document.form.EMAIL.value='';
			document.form.EMAIL.focus();
			return false;
		}
		return true;
	}

