// JavaScript Document
var head_imgs = new Array();
head_imgs[1] = "bookyourflight_title.gif";
head_imgs[2] = "find_hotel_title.gif";
head_imgs[3] = "carhire_title.gif";
head_imgs[4] = "travel_insurance_title.gif";
head_imgs[5] = "tickets_search_title.gif";
head_imgs[6] = "international_simcards.gif";
head_imgs[7] = "trainticket_search.gif";
head_imgs[8] = "airport_parking_title.gif";
head_imgs[9] = "national_express.gif";
head_imgs[10] = "currency_exchange.gif";
head_imgs[11] = "holidaytaxis_title.gif";
head_imgs[12] = "rail_europe_title.gif";
head_imgs[13] = "package_holidays_title.gif";
head_imgs[14] = "activities_title.gif";
head_imgs[15] = "cityscan_title.gif";

var head_width = new Array();
head_width[1] = "96";
head_width[2] = "61";
head_width[3] = "52";
head_width[4] = "98";
head_width[5] = "86";
head_width[6] = "130";
head_width[7] = "110";
head_width[8] = "152";
head_width[9] = "99";
head_width[10] = "107";
head_width[11] = "75";
head_width[12] = "60";
head_width[13] = "102";
head_width[14] = "54";
head_width[15] = "53";

var head_height = new Array();
head_height[1] = "20";
head_height[2] = "16";
head_height[3] = "16";
head_height[4] = "16";
head_height[5] = "16";
head_height[6] = "16";
head_height[7] = "16";
head_height[8] = "16";
head_height[9] = "16";
head_height[10] = "16";
head_height[11] = "16";
head_height[12] = "16";
head_height[13] = "16";
head_height[14] = "16";
head_height[15] = "16";

var pak_len = 15;

function switch_package(head_id,text_id,out_id,ind)
{
	for(var i=1;i<=pak_len;i++)
	{
		if(i==ind)
		{
			show(out_id+i);
			setClass(text_id+i,"pack_head_org");
		}
		else
		{
			hide(out_id+i);
			setClass(text_id+i,"poll_head");
		}
		// Insurance state set up
		if(ind==4)
		{
			setStateOptions('qf_txtResideCountryID', 'qf_txtResideID', 'previous_state');
		}
	}
	var content = '<img src="images/'+head_imgs[ind]+'" alt="My Price" width="'+head_width[ind]+'" height="'+head_height[ind]+'" />';
	setWidth(head_id,head_width[ind]);
	setContent(head_id,content)
}
/* validate travel insurance form*/
function validate_insurance()
{
	var c_no_trav	   = 6;
	var c_max_age	   = 120;

	//Determine number of travelers.
	var l_no_trav = 0;
	for (i = 0; i < c_no_trav; i ++)
	{
		if (document.QuoteForm.txtAge[i].value > 0) 
			l_no_trav ++;
	}
	if (l_no_trav == 0)
	{
		alert("Please input the age of the traveler.");
		document.QuoteForm.txtAge[0].focus();
		return (false);
	}
	//Determine oldest traveler.
	var l_max_age = 0
	for (i = 0; i < c_no_trav; i ++)
	{
		var l_age = new Number(document.QuoteForm.txtAge[i].value)
		if (l_age > c_max_age)
		{
			alert("The maximum age allowed is " + c_max_age + ".");
			document.QuoteForm.txtAge[i].select();
			return (false);
		}
		if (l_age > l_max_age) l_max_age = l_age;
	}
	//Validate residence.
	if (document.getElementById('qf_txtResideID'))
	{
		var ResideID = document.getElementById('qf_txtResideID').value;
		if (ResideID == '')
		{
			alert("Please Select a Country, State or Province from the list.");
			document.QuoteForm.txtResideID.focus();
			return (false);			
		}
	}
	if (document.QuoteForm.txtResideCountryID)
	{
		if (document.QuoteForm.txtResideCountryID.value == "")
		{
			alert("Please Select a Country from the list.");
			document.QuoteForm.txtResideCountryID.focus();
			return (false);
		}
	}
	//Validate first destination country.
	if (document.QuoteForm.txtTripDestID.value == "")
	{
		alert("Please Select the first or primary destination country.");
		document.QuoteForm.txtTripDestID.focus();
		return (false);
	}
//	document.QuoteForm.action = "http://www.squaremouth.com/travel-insurance/quote.pl";
	document.QuoteForm.action = "http://www.squaremouth.com/travel-insurance/index.pl?pid=20471";
	document.QuoteForm.target="blank";
	document.QuoteForm.submit();
	return (true);
}
//setStateOptions
function setStateOptions(country_field_id, state_field_id, previous_state_field_id) {

	var obj = document.getElementById(country_field_id);
	var objVal = obj.options[obj.selectedIndex].value;
	var oChg = document.getElementById(state_field_id);
	var previous_state = document.getElementById(previous_state_field_id).value;
	
	var States = new Array();
	States['-1'] = Array('OTH|Other');
	States['34'] = Array('AB|Alberta','BC|British Columbia','MB|Manitoba','NB|New Brunswick','NL|Newfoundland','NS|Nova Scotia','NU|Nunavut','NT|NW Territories','ON|Ontario','PE|Prince Edward Isl','QC|Quebec','SK|Saskatchewan','YT|Yukon Territory');
	States['209'] = Array('AL|Alabama','AK|Alaska','AZ|Arizona','AR|Arkansas','CA|California','CO|Colorado','CT|Connecticut','DE|Delaware','DC|Dist. of Columbia','FL|Florida','GA|Georgia','HI|Hawaii','ID|Idaho','IL|Illinois','IN|Indiana','IA|Iowa','KS|Kansas','KY|Kentucky','LA|Louisiana','ME|Maine','MD|Maryland','MA|Massachusetts','MI|Michigan','MN|Minnesota','MS|Mississippi','MO|Missouri','MT|Montana','NE|Nebraska','NV|Nevada','NH|New Hampshire','NJ|New Jersey','NM|New Mexico','NY|New York','NC|North Carolina','ND|North Dakota','OH|Ohio','OK|Oklahoma','OR|Oregon','PA|Pennsylvania','RI|Rhode Island','SC|South Carolina','SD|South Dakota','TN|Tennessee','TX|Texas','UT|Utah','VT|Vermont','VA|Virginia','WA|Washington','WV|West Virginia','WI|Wisconsin','WY|Wyoming');
	
	var state_arr = States[objVal];
	if (objVal < 0 || state_arr == undefined) {
		clearStateSelect('Please Select', '');
		oChg.options[oChg.options.length] = new Option('Other', 'OTH', 0, 1);
		if ( !((objVal==209) || (objVal==34)) )
		{
			hide(state_field_id);
		}
		return true;
	}
	clearStateSelect('Please Select', '');
	oChg.style.display = '';
	if ((objVal==209) || (objVal==34))
	{
		show(state_field_id); 
	}
	for (var i=0; i < state_arr.length; i++) {
		var v = state_arr[i].split('|');
		var checked;
		if (v[0] == previous_state) {
			checked = 1;
		} else {
			checked = 0;
		}
		oChg.options[oChg.options.length] = new Option(v[1], v[0], 0, checked);
	}
}
function clearStateSelect(inText, inVal) {
	var oList = document.getElementById('qf_txtResideID')
	for (var i = oList.options.length; i >= 0; i--)
	{
		  oList.options[i] = null;
	}
	oList.style.display = 'none';
	oList.options.length = 0; 
	oList.options[oList.options.length] = new Option(inText, inVal);
}

