//
// This script contains Delta Airlines specific methods.
//
// Copyright 2008 Liberty Mutual Group. All rights reserved.
//
// Author Carrie Ann Roberge
//
///////////////////////////////////////////////////////////////////////////
// Delta Delta Delta Delta Delta Delta Delta Delta Delta Delta Delta     //
///////////////////////////////////////////////////////////////////////////

var SRC_ARRAY = new Array("delta_eMail", "delta_eStatement", "delta_display", "delta_edMail", "delta_multipartner_email");
var KEYCODE_ID_ARRAY = new Array("IEDLTNE0", "IDDL69I0", "IDDL3900", "IEDLTNED", "IELDTNPA");

var WEB_ID = "0000010846";
var AFFINITY = "delta";
var KEYCODE_ID = "";
var PHONE_NUM = "888-490-3727";

// Resetting form variables in landing page.
function init_gateway()
{
	var src_code = swfobject.getQueryParamValue("src");

	if (src_code.length > 0)
	{
		for (var index = 0; index < SRC_ARRAY.length; index++) 
		{
			if (src_code.toLowerCase().indexOf (SRC_ARRAY [index].toLowerCase()) == 0)
			{
				KEYCODE_ID = KEYCODE_ID_ARRAY [index];

				break;
			}
		}
	}
	
	document.forms.getAQuoteForm.MM_webID.value = WEB_ID;
	document.forms.getAQuoteForm.keyCode.value = KEYCODE_ID;

	var phoneElement = document.getElementById("phoneNumberText");
	phoneElement.innerHTML = "Or call 1-" + PHONE_NUM;
}

function getSrcBasedWebID()
{
	return WEB_ID;  
}

function cf_getAQuoteDeltaSubmit(getAQuoteForm)
{
	var selectControl = getAQuoteForm.policyType.options;
	var index = getAQuoteForm.policyType.selectedIndex;
	var choice = selectControl[index].value;
	var keyCodeID = getAQuoteForm.keyCode.value;

	// disable keyCode if not available
	if (keyCodeID == "") 
	{
		getAQuoteForm.keyCode.disabled = true;
	} 
	else 
	{
		getAQuoteForm.keyCode.disabled = false;
	}
	
	if (choice == "Auto" || choice == "H3" || choice == "H4" || choice == "H6")
	{
		if ((cf_validateZIPCode(getAQuoteForm.zipCode)) && (cf_validateSkyMiles(getAQuoteForm.MemberID)))
		{
		    document.forms.getAQuoteForm.action = rc.urlLookup ("QuoteServiceStartQuote");
			document.forms.getAQuoteForm.submit();
		}
	}
}

function cf_getAQuoteDeltaEnter(getAQuoteForm)
{
	var keycode;
	
	if (window.event) 
	{
		keycode = window.event.keyCode;
	}

	if (keycode == 13)
	{
		cf_getAQuoteDeltaSubmit(getAQuoteForm);
	}
}

function cf_validateSkyMiles(DeltaPin)
{
    var format = /^\d/;
	var ok = (format.exec(DeltaPin.value) == null)? false: true;
	//alert(ok);
	
	if (ok == true)
	{
		//alert("I am true");
		var count = DeltaPin.value.length;
		//alert(count);
		if ((count != 9)&&(count != 10)&&(count !=12))
		{
			ok = false;
		}
	}

	if (ok == false)
	{
	 alert("Please enter a valid SkyMiles number.");
	 DeltaPin.focus();
	}
	return ok;
}

