//
// global variables for motor estimate
//
var qqprem = 0;



//
// global variable for LANSA partition
//
var partition = "ALZ";
function setPartition(p) {
	partition = p;
}



//
// global variable for redirect URL
//
var redirect = false;
function setRedirect(val) {
	if (val == true || val == false)
		redirect = val;
}



//
// function to redirect the page
//
function Redirect(val) {
	if (redirect)
		document.location = val;
}



//
// global variable for call mode - this determines the Calculate button construction
// to make either an AJAX call or open a new window. Default is MODE_AJAX.
//
var call_mode = "MODE_AJAX";
function setCallMode(m) {
	// if MODE_WINDOW set this otherwise leave default (for default, blank, or invalid)
	if (m == "MODE_WINDOW") {
		call_mode = m;
	}
	else {
		call_mode = "MODE_AJAX";
	}
}



//
// function to open a quick quote popup
//
function QQPopUp(URL) {
	var strref = "QQ^URL=" + document.URL.substring(0,50);
	strref = strref.replace(/[^a-zA-Z 0-9/.:]+/g,'^');
	var strurl = document.referrer.substring(0,100);
	strurl = strurl.replace(/[^a-zA-Z 0-9/.:]+/g,'^');
	URL = URL + '+ASTREF(A1000):' + strref + '+ASTURL(A1000):' + strurl;
	var windowprops ="location=no,scrollbars=yes,menubars=no,toolbar=no,resizable=yes,status=yes,left=115,top=75,width=800,height=450";
	popup = window.open(URL,"MenuPopup",windowprops);
}





/******************************************* DISPLAY FUNCTIONS ********************************************************/

// boolean value to show existence of estimator object
var EXISTS_EST = false;



//
// function to add county dropdown
//
function addCountyDD(container, nameidArr) {
	addGenericDD(container, nameidArr, [["", "Please select"], ["29", "Carlow"], ["25", "Cavan"], ["26", "Clare"], ["27", "Cork City"], ["28", "Cork County"], ["30", "Donegal"], ["01", "Dublin 1"], ["02", "Dublin 2"], ["03", "Dublin 3"], ["04", "Dublin 4"], ["05", "Dublin 5"], ["06", "Dublin 6"], ["07", "Dublin 7"], ["08", "Dublin 8"], ["09", "Dublin 9"], ["10", "Dublin 10"], ["11", "Dublin 11"], ["12", "Dublin 12"], ["13", "Dublin 13"], ["14", "Dublin 14"], ["15", "Dublin 15"], ["16", "Dublin 16"], ["17", "Dublin 17"], ["18", "Dublin 18"], ["20", "Dublin 20"], ["22", "Dublin 22"], ["24", "Dublin 24"], ["23", "Dublin County"], ["32", "Galway City"], ["31", "Galway County"], ["40", "Kerry"], ["33", "Kildare - Celbridge"], ["34", "Kildare - Kilcock"], ["35", "Kildare - Leixlip"], ["21", "Kildare - Maynooth"], ["36", "Kildare - Naas"], ["37", "Kildare - Straffan"], ["38", "Kildare - Other"], ["39", "Kilkenny"], ["46", "Laois"], ["41", "Leitrim"], ["AG", "Limerick City"], ["43", "Limerick County"], ["44", "Longford"], ["45", "Louth"], ["53", "Mayo"], ["47", "Meath - Ashbourne"], ["48", "Meath - Clonee"], ["49", "Meath - Dunboyne"], ["50", "Meath - Dunshaughlin"], ["51", "Meath - Other"], ["52", "Monaghan"], ["54", "Offaly"], ["55", "Roscommon"], ["56", "Sligo"], ["57", "Tipperary"], ["58", "Waterford City"], ["59", "Waterford County"], ["60", "Westmeath"], ["61", "Wexford"], ["62", "Wicklow - Blessington"], ["63", "Wicklow - Bray"], ["64", "Wicklow - Greystones"], ["65", "Wicklow - Other"]]);
}
//
// function to add county dropdown for Motor
//
function addCountyDDMot(container, nameidArr) {
	addGenericDD(container, nameidArr, [["", "Please select"], ["29", "Carlow"], ["25", "Cavan"], ["26", "Clare"], ["27", "Cork City"], ["28", "Cork County"], ["30", "Donegal"], ["01", "Dublin 1"], ["02", "Dublin 2"], ["03", "Dublin 3"], ["04", "Dublin 4"], ["05", "Dublin 5"], ["06", "Dublin 6"], ["07", "Dublin 7"], ["08", "Dublin 8"], ["09", "Dublin 9"], ["10", "Dublin 10"], ["11", "Dublin 11"], ["12", "Dublin 12"], ["13", "Dublin 13"], ["14", "Dublin 14"], ["15", "Dublin 15"], ["16", "Dublin 16"], ["17", "Dublin 17"], ["18", "Dublin 18"], ["20", "Dublin 20"], ["22", "Dublin 22"], ["24", "Dublin 24"], ["23", "Dublin County"], ["32", "Galway City"], ["31", "Galway County"], ["40", "Kerry"], ["33", "Kildare - Celbridge"], ["34", "Kildare - Kilcock"], ["35", "Kildare - Leixlip"], ["21", "Kildare - Maynooth"], ["36", "Kildare - Naas"], ["37", "Kildare - Straffan"], ["38", "Kildare - Other"], ["39", "Kilkenny"], ["46", "Laois"], ["41", "Leitrim"], ["42", "Limerick City"], ["43", "Limerick County"], ["44", "Longford"], ["45", "Louth"], ["53", "Mayo"], ["47", "Meath - Ashbourne"], ["48", "Meath - Clonee"], ["49", "Meath - Dunboyne"], ["50", "Meath - Dunshaughlin"], ["51", "Meath - Other"], ["52", "Monaghan"], ["54", "Offaly"], ["55", "Roscommon"], ["56", "Sligo"], ["57", "Tipperary"], ["58", "Waterford City"], ["59", "Waterford County"], ["60", "Westmeath"], ["61", "Wexford"], ["62", "Wicklow - Blessington"], ["63", "Wicklow - Bray"], ["64", "Wicklow - Greystones"], ["65", "Wicklow - Other"]]);
}




//
// function to add Age dropdown
//
function addAgeDD(container) {
	var ageArr = new Array();
	ageArr[0] = new Array("", "Please select");
	for (var i=1; i<64; i++)
		ageArr[i] = new Array(i+17, i+17);
	for (var j=64; j<=83; j++)
		ageArr[j] = new Array(80, j+17);
	addGenericDD(container, ["AQAGE1", "AQAGE1"], ageArr);
}



//
// function to add a button
//
function addLinkButtons(container, product) {
	var row = document.createElement('tr');
	var cell = document.createElement('td');
	cell.align = "right";
	cell.colSpan = "3";
	var but1 = document.createElement('input');
	but1.type = "button";
	but1.value = "Submit";
	but1.id = "quick_btn";
	but1.onclick = function () {
		getQuickEstimate(product);
	}
	but1.onkeypress = function (e) {
	    var key; 
		if(window.event)
			key = window.event.keyCode; // IE
		else 
			key = e.which; //firefox 
		if (key==13 || key==32) {
			getQuickEstimate(product);
		}
	}
	cell.appendChild(but1);
	if (call_mode == "MODE_AJAX") {
		var but2= document.createElement('input');
		but2.type = "button";
		but2.value = "Quote";
		but2.id = "quick_quote";
		but2.onkeypress = function (e) {
			var key; 
			if(window.event)
				key = window.event.keyCode; // IE
			else 
				key = e.which; //firefox 
			if (key==13 || key==32) {
				switch (product) {
				case 'Motor':
					QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprocmot+afnm02+Alz+funcparms+acoc(A0100):ADR');
					break;
				case 'Pet':
					QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprocpet+afnp02+Alz+funcparms+acoc(A0100):PET+asorc(A0030):ADR');
					break;
				case 'Travel':
					QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aproctrv+afnt02+Alz+funcparms+acoc(A0100):TRV+asorc(A0030):ADR');
					break;
				case 'Household':
					QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprochse+afnh02+Alz+funcparms+acoc(A0100):HSE+asorc(A0030):ADR');
					break;
				case 'Contents Only':
					QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprochse+afnh02+Alz+funcparms+acoc(A0100):HSE+asorc(A0030):ADR');
					break;
				case 'Holiday Home':
					QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprochse+afnh02+Alz+funcparms+acoc(A0100):HSE+asorc(A0030):ADR');
					break;
				case 'Landlord':
					QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprochse+afnh02+Alz+funcparms+acoc(A0100):HSE+asorc(A0030):ADR');
					break;
				case 'Pupil Personal Accident':
					QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprocppa+afnpp1+all');
					break;
				}
			}
		}
		but2.onclick = function () {
			switch (product) {
			case 'Motor':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprocmot+afnm02+Alz+funcparms+acoc(A0100):ADR');
				break;
			case 'Pet':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprocpet+afnp02+Alz+funcparms+acoc(A0100):PET+asorc(A0030):ADR');
				break;
			case 'Travel':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aproctrv+afnt02+Alz+funcparms+acoc(A0100):TRV+asorc(A0030):ADR');
				break;
			case 'Household':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprochse+afnh02+Alz+funcparms+acoc(A0100):HSE+asorc(A0030):ADR');
				break;
			case 'Contents Only':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprochse+afnh02+Alz+funcparms+acoc(A0100):HSE+asorc(A0030):ADR');
				break;
			case 'Holiday Home':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprochse+afnh02+Alz+funcparms+acoc(A0100):HSE+asorc(A0030):ADR');
				break;
			case 'Landlord':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprochse+afnh02+Alz+funcparms+acoc(A0100):HSE+asorc(A0030):ADR');
				break;
			case 'Pupil Personal Accident':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprocppa+afnpp1+all');
				break;
			}
		}
		cell.appendChild(but2);
	}
	row.appendChild(cell);
	container.appendChild(row);
}




//
// function to display a given estimator
//
function showEst(product, div) {
	destroyEst();
	if (!EXISTS_EST) {
		// main containers
		tease_div = document.createElement('div');
		tease_div.id = "est_overallcontainer";
		tease_div.className = "estimator-wrapper";
		// tabs container
		tabs_div = document.createElement('div');
		tabs_div.className = "tabs_container";
		// tab container
		tab_div = document.createElement('div');
		tab_div.id = "TabContainer";
		// header division
		h_div = document.createElement('div');
		h_div.className = "form-title";
		h_txt = document.createTextNode(product + " Estimator");
		h2 = document.createElement('h2');
		h2.appendChild(h_txt);
		h_div.appendChild(h2);
		// footer
		f_div = document.createElement('div');
		f_div.className = "est_footer";
		p = document.createElement('p');
		if (product == "Pupil Personal Accident") {
			p_txt = document.createTextNode("This is a quick estimator and is based on details submitted below.  Cover is only guaranteed and confirmed when the quote system has been used. To do this click the 'Quote' button after getting an estimate in order to purchase cover for the coming school year.");
		} else {
			switch (call_mode) {
				case 'MODE_AJAX':
					p_txt = document.createTextNode("NB: This is a quick estimator and is based on your answers and some assumptions based on typical customer profiles. Estimates are only a rough guide and are not guaranteed. A quote is only guaranteed and confirmed when the quote system has been used. To do this click the 'Quote' button after getting your estimate.");
					break;
				case 'MODE_WINDOW':
					p_txt = document.createTextNode("NB: This is a quick estimator and is based on your answers and some assumptions based on typical customer profiles. Estimates are only a rough guide and are not guaranteed. A quote is only guaranteed and confirmed when the quote system has been used. To do this click on 'Get Full Quote' after getting your estimate.");
					break;
			}
		}
		p.appendChild(p_txt);
		f_div.appendChild(p);
		// create table and attributes
		var table = document.createElement("table");
		table.border = "0";
		table.width = "680";
		table.id = "est_table";
		table.bgColor = "#e3e4e5";
		var tabBody = document.createElement("tbody");
		// add the note row to the table
		var row = document.createElement('tr');
		tabBody.appendChild(row);
		// add product specific dropdowns and buttons
		switch (product) {
			case 'Motor':
				setMotor(tabBody, table);
				break;
			case 'Pet':
				setPet(tabBody, table);
				break;
			case 'Household':
				setHou(tabBody, table);
				break;
			case 'Contents Only':
				setHouco(tabBody, table);
				break;
			case 'Holiday Home':
				setHol(tabBody, table);
				break;
			case 'Landlord':
				setLand(tabBody, table);
				break;
			case 'Travel':
				setTravel(tabBody, table);
				break;
			case 'Pupil Personal Accident':
				setPpa(tabBody, table);
				break;
		}
		// add the table to the form
		table.appendChild(tabBody);
		// add buttons
		addLinkButtons(tabBody, product);
		// add quote div to the main div
		tab_div.appendChild(h_div);
		tab_div.appendChild(table);
		tabs_div.appendChild(tab_div);
		tease_div.appendChild(tabs_div);
		tease_div.appendChild(f_div);
		document.getElementById(div).appendChild(tease_div);
		EXISTS_EST = true;
	}
}



//
// function to add the motor specific dropdowns and buttons
//
function setMotor(tabBody, table) {
	// add the gender row to the table
	var row1 = document.createElement('tr');
	addTextCell(row1, "1 > Gender: ");
	addGenericDD(getNewCell(row1), ["AGENDC1", "AGENDC1"], [["", "Please select"], ["M", "Male"], ["F", "Female"]]);
	addImageCell(row1, 5);
	tabBody.appendChild(row1);
	// add the age row to the table
	var row2 = document.createElement('tr');
	addTextCell(row2, "2 > Age: ");
	addAgeDD(getNewCell(row2));
	tabBody.appendChild(row2);
	// add the county row to the dropdown
	var row3 = document.createElement('tr');
	addTextCell(row3, "3 > County: ");
	addCountyDDMot(getNewCell(row3), ["AQCOUNTY1", "AQCOUNTY1"]);
	tabBody.appendChild(row3);
	// add car type row the the dropdown
	var row4 = document.createElement('tr');
	addTextCell(row4, "4 > Car Type: ");
	addGenericDD(getNewCell(row4), ["AQCART1", "AQCART1"], [["0", "Please select"], ["3", "Compact - Nissan Micra 1.0"], ["8", "Family - Toyota Corolla 1.4"], ["10", "Mid size family- Ford Focus 1.6"], ["12", "Full size - Toyota Avensis 1.8"], ["16", "Executive - BMW 318 2.0"]]);
	tabBody.appendChild(row4);
	// add ncd row to the table
	var row5 = document.createElement('tr');
	addTextCell(row5, "5 > No Claims Discount: ");
	addGenericDD(getNewCell(row5), ["AQNCB1", "AQNCB1"], [["", "Please select"], ["1", "1 Year"], ["2", "2 Years"], ["3", "3 Years"], ["4", "4 Years"], ["5", "5 Years"], ["6", "6+ Years"]]);
	tabBody.appendChild(row5);
}



//
// function to add the pet specific dropdowns and buttons
//
function setPet(tabBody, table) {
	// add the pet type row to the table
	var row1 = document.createElement('tr');
	addTextCell(row1, "1 > Pet Types: ");
	addGenericDD(getNewCell(row1), ["AAQPET", "AAQPET"], [["X", "Please Select"], ["CAT", "Cat"], ["DOG", "Dog"]]);
	addImageCell(row1, 5);
	tabBody.appendChild(row1);
	// add the breed type row to the table
	var row2 = document.createElement('tr');
	addTextCell(row2, "2 > Breed Type: ");
	addGenericDD(getNewCell(row2), ["AAQBRD", "AAQBRD"], [["X", "Please Select"], ["CBC", "Cross breed cat"], ["PEC", "Pedigree cat"], ["CBD", "Cross breed dog"], ["PED", "Pedigree dog"], ["BEU", "Special Breed: Beauceron"], ["BUD", "Special Breed: Bulldog"], ["DRH", "Special Breed: Deerhound"], ["DDB", "Special Breed: Dogue de Bourdeaux"], ["OES", "Special Breed: Old English Sheepdog"], ["AMB", "Special Breed: All Mastiff breeds"], ["AMD", "Special Breed: All mountain dogs"], ["NFL", "Special Breed: Newfoundland"], ["SBR", "Special Breed: St.Bernard"], ["GRD", "Special Breed: Great Dane"], ["IWH", "Special Breed: Irish Wolf Hound"], ["LEO", "Special Breed: Leonberger"], ["SHP", "Special Breed: Shar-pei"]]);
	tabBody.appendChild(row2);
	// add the micro chipped row to the dropdown
	var row3 = document.createElement('tr');
	addTextCell(row3, "3 > Micro Chipped: ");
	addGenericDD(getNewCell(row3), ["AAQMIC", "AAQMIC"], [["X", "Please Select"], ["Y", "Yes"], ["N", "No"]]);
	tabBody.appendChild(row3);
	// add owners age row the the dropdown
	var row4 = document.createElement('tr');
	addTextCell(row4, "4 > Owners Age: ");
	addGenericDD(getNewCell(row4), ["AAQOWA", "AAQOWA"], [["X", "Please Select"], ["Y", "Under 60 Years"], ["N", "60 Years and over"]]);
	tabBody.appendChild(row4);
	// add pet age row to the table
	var row5 = document.createElement('tr');
	addTextCell(row5, "5 > Pets Age: ");
	addGenericDD(getNewCell(row5), ["AAQPTA", "AAQPTA"], [["X", "Please Select"], ["A", "Under 1 Year Old"], ["B", "1 Year Old"], ["C", "2 Years Old"], ["D", "3 Years Old"], ["E", "4 Years Old"], ["F", "5 Years Old"], ["G", "6 Years Old"], ["H", "7 Years Old"], ["N", "8 Years Old"]]);
	tabBody.appendChild(row5);
}



//
// function to add the household specific dropdowns and buttons
//
function setHou(tabBody, table) {
	// add the building sum insured row to the table
	var row1 = document.createElement('tr');
	addTextCell(row1, "1 > Building Sum Insured: ");
	addGenericDD(getNewCell(row1), ["SLSBLSI", "LSBLSI_S"], [["0" , "Please select"], ["140000", "140,000"], ["145000", "145,000"], ["150000", "150,000"], ["155000", "155,000"], ["160000", "160,000"], ["165000", "165,000"], ["170000", "170,000"], ["175000", "175,000"], ["180000", "180,000"], ["185000", "185,000"], ["190000", "190,000"], ["195000", "195,000"], ["200000", "200,000"], ["205000", "205,000"], ["210000", "210,000"], ["215000", "215,000"], ["220000", "220,000"], ["225000", "225,000"], ["230000", "230,000"], ["235000", "235,000"], ["240000", "240,000"], ["245000", "245,000"], ["250000", "250,000"], ["260000", "260,000"], ["270000", "270,000"], ["280000", "280,000"], ["290000", "290,000"], ["300000", "300,000"], ["310000", "310,000"], ["320000", "320,000"], ["330000", "330,000"], ["340000", "340,000"], ["350000", "350,000"], ["360000", "360,000"], ["370000", "370,000"], ["380000", "380,000"], ["390000", "390,000"], ["400000", "400,000"], ["410000", "410,000"], ["420000", "420,000"], ["430000", "430,000"], ["440000", "440,000"], ["450000", "450,000"], ["475000", "475,000"], ["500000", "500,000"], ["525000", "525,000"], ["550000", "550,000"], ["575000", "575,000"], ["600000", "600,000"], ["625000", "625,000"], ["635000", "635,000"]]);
	addImageCell(row1, 5);
	tabBody.appendChild(row1);
	// add the contents sum insured row to the table
	var row2 = document.createElement('tr');
	addTextCell(row2, "2 > Contents Sum Insured: ");
	addGenericDD(getNewCell(row2), ["SWKCSIN", "LWKCSIN"], [["0", "Please select"], ["10", "10%"], ["11", "11%"], ["12", "12%"], ["13", "13%"], ["14", "14%"], ["15", "15%"], ["16", "16%"], ["17", "17%"], ["18", "18%"], ["19", "19%"], ["20", "20%"], ["21", "21%"], ["22", "22%"], ["23", "23%"], ["24", "24%"], ["25", "25%"], ["26", "26%"], ["27", "27%"], ["28", "28%"], ["29", "29%"], ["30", "30%"], ["31", "31%"], ["32", "32%"], ["33", "33%"], ["34", "34%"], ["35", "35%"], ["36", "36%"], ["37", "37%"], ["38", "38%"], ["39", "39%"], ["40", "40%"], ["41", "41%"], ["42", "42%"], ["43", "43%"], ["44", "44%"], ["45", "45%"], ["46", "46%"], ["47", "47%"], ["48", "48%"], ["49", "49%"], ["50", "50%"]]);
	tabBody.appendChild(row2);
	// add the area row to the dropdown
	var row3 = document.createElement('tr');
	addTextCell(row3, "3 > Area: ");
	addCountyDD(getNewCell(row3), ["AHRLOCC", "HRLOCC_S"]);
	tabBody.appendChild(row3);
	// add accidental damage row the the dropdown
	var row4 = document.createElement('tr');
	addTextCell(row4, "4 > Accidental Damage: ");
	addGenericDD(getNewCell(row4), ["AWKADCR", "WKADCR_S"], [["", "Please select"], ["YES", "Yes on contents"], ["NO", "No on contents"]]);
	tabBody.appendChild(row4);
	// add age row to the table
	var row5 = document.createElement('tr');
	addTextCell(row5, "5 > Age: ");
 	addGenericDD(getNewCell(row5), ["AWKAGEN", "WKAGEN_S"], [["", "Please select"], ["19", "19"], ["20", "20"], ["21", "21"], ["22", "22"], ["23", "23"], ["24", "24"], ["25", "25"], ["26", "26"], ["27", "27"], ["28", "28"], ["29", "29"], ["30", "30"], ["31", "31"], ["32", "32"], ["33", "33"], ["34", "34"], ["35", "35"], ["36", "36"], ["37", "37"], ["38", "38"], ["39", "39"], ["40", "40"], ["41", "41"], ["42", "42"], ["43", "43"], ["44", "44"], ["45", "45"], ["46", "46"], ["47", "47"], ["48", "48"], ["49", "49"], ["50", "50"], ["51", "51"], ["52", "52"], ["53", "53"], ["54", "54"], ["55", "55"], ["56", "56"], ["57", "57"], ["58", "58"], ["59", "59"], ["60", "60"], ["61", "61"], ["62", "62"], ["63", "63"], ["64", "64"], ["65", "65"], ["66", "66"], ["67", "67"], ["68", "68"], ["69", "69"], ["70", "70"], ["71", "71"], ["72", "72"], ["73", "73"], ["74", "74"], ["75", "75"], ["76", "76"], ["77", "77"], ["78", "78"], ["79", "79"], ["80", "80"]]);
	tabBody.appendChild(row5);
}


//
// function to add the contents only specific dropdowns and buttons
//
function setHouco(tabBody, table) {
	// add the contents sum insured row to the table
	var row1 = document.createElement('tr');
	addTextCell(row1, "1 > Contents Sum Insured: ");
	addGenericDD(getNewCell(row1), ["SLSCTSI", "LSCTSI_C"], [["0", "Please select"], ["20000", "20,000"], ["25000", "25,000"], ["30000", "30,000"], ["35000", "35,000"], ["40000", "40,000"], ["45000", "45,000"], ["50000", "50,000"], ["55000", "55,000"], ["60000", "60,000"], ["65000", "65,000"], ["70000", "70,000"], ["75000", "75,000"], ["80000", "80,000"], ["85000", "85,000"], ["90000", "90,000"], ["95000", "95,000"], ["100000", "100,000"], ["105000", "105,000"], ["110000", "110,000"], ["115000", "115,000"], ["120000", "120,000"], ["125000", "125,000"], ["130000", "130,000"], ["135000", "135,000"], ["140000", "140,000"], ["145000", "145,000"], ["150000", "150,000"]]);
	addImageCell(row1, 4);
	tabBody.appendChild(row1);
	// add the area row to the dropdown
	var row3 = document.createElement('tr');
	addTextCell(row3, "2 > Area: ");
	addCountyDD(getNewCell(row3), ["AHRLOCC", "HRLOCC_C"]);
	tabBody.appendChild(row3);
	// add accidental damage row the the dropdown
	var row4 = document.createElement('tr');
	addTextCell(row4, "3 > Accidental Damage: ");
	addGenericDD(getNewCell(row4), ["AWKADCR", "WKADCR_C"], [["", "Please select"], ["YES", "Yes on contents"], ["NO", "No on contents"]]);
	tabBody.appendChild(row4);
	// add age row to the table
	var row5 = document.createElement('tr');
	addTextCell(row5, "4 > Age: ");
 	addGenericDD(getNewCell(row5), ["AWKAGEN", "WKAGEN_C"], [["", "Please select"], ["19", "19"], ["20", "20"], ["21", "21"], ["22", "22"], ["23", "23"], ["24", "24"], ["25", "25"], ["26", "26"], ["27", "27"], ["28", "28"], ["29", "29"], ["30", "30"], ["31", "31"], ["32", "32"], ["33", "33"], ["34", "34"], ["35", "35"], ["36", "36"], ["37", "37"], ["38", "38"], ["39", "39"], ["40", "40"], ["41", "41"], ["42", "42"], ["43", "43"], ["44", "44"], ["45", "45"], ["46", "46"], ["47", "47"], ["48", "48"], ["49", "49"], ["50", "50"], ["51", "51"], ["52", "52"], ["53", "53"], ["54", "54"], ["55", "55"], ["56", "56"], ["57", "57"], ["58", "58"], ["59", "59"], ["60", "60"], ["61", "61"], ["62", "62"], ["63", "63"], ["64", "64"], ["65", "65"], ["66", "66"], ["67", "67"], ["68", "68"], ["69", "69"], ["70", "70"], ["71", "71"], ["72", "72"], ["73", "73"], ["74", "74"], ["75", "75"], ["76", "76"], ["77", "77"], ["78", "78"], ["79", "79"], ["80", "80"]]);
	tabBody.appendChild(row5);
}



//
// function to add the holiday home specific dropdowns and buttons
//
function setHol(tabBody, table) {
	// add the building sum insured row to the table
	var row1 = document.createElement('tr');
	addTextCell(row1, "1 > Building Sum Insured: ");
	addGenericDD(getNewCell(row1), ["SLSBLSI", "LSBLSI_H"], [["0", "Please select"], ["140000", "140,000"], ["145000", "145,000"], ["150000", "150,000"], ["155000", "155,000"], ["160000", "160,000"], ["165000", "165,000"], ["170000", "170,000"], ["175000", "175,000"], ["180000", "180,000"], ["185000", "185,000"], ["190000", "190,000"], ["195000", "195,000"], ["200000", "200,000"], ["205000", "205,000"], ["210000", "210,000"], ["215000", "215,000"], ["220000", "220,000"], ["225000", "225,000"], ["230000", "230,000"], ["235000", "235,000"], ["240000", "240,000"], ["245000", "245,000"], ["250000", "250,000"], ["260000", "260,000"], ["270000", "270,000"], ["280000", "280,000"], ["290000", "290,000"], ["300000", "300,000"], ["310000", "310,000"], ["320000", "320,000"], ["330000", "330,000"], ["340000", "340,000"], ["350000", "350,000"], ["360000", "360,000"], ["370000", "370,000"], ["380000", "380,000"], ["390000", "390,000"], ["400000", "400,000"], ["410000", "410,000"], ["420000", "420,000"], ["430000", "430,000"], ["440000", "440,000"], ["450000", "450,000"], ["475000", "475,000"], ["500000", "500,000"], ["525000", "525,000"], ["550000", "550,000"], ["575000", "575,000"], ["600000", "600,000"], ["625000", "625,000"], ["635000", "635,000"]]);
	addImageCell(row1, 4);
	tabBody.appendChild(row1);
	// add the contents sum insured row to the table
	var row2 = document.createElement('tr');
	addTextCell(row2, "2 > Contents Sum Insured: ");
	addGenericDD(getNewCell(row2), ["SLSCTSI", "LSCTSI_H"], [["0", "Please select"], ["20000", "20,000"], ["25000", "25,000"], ["30000", "30,000"], ["35000", "35,000"], ["40000", "40,000"], ["45000", "45,000"], ["50000", "50,000"], ["55000", "55,000"], ["60000", "60,000"], ["65000", "65,000"], ["70000", "70,000"], ["75000", "75,000"], ["80000", "80,000"], ["85000", "85,000"], ["90000", "90,000"], ["95000", "95,000"], ["100000", "100,000"], ["105000", "105,000"], ["110000", "110,000"], ["115000", "115,000"], ["120000", "120,000"], ["125000", "125,000"]]);
	tabBody.appendChild(row2);
	// add the area row to the dropdown
	var row3 = document.createElement('tr');
	addTextCell(row3, "3 > Area: ");
	addCountyDD(getNewCell(row3), ["AHRLOCC", "HRLOCC_H"]);
	tabBody.appendChild(row3);
	// add age row to the table
	var row5 = document.createElement('tr');
	addTextCell(row5, "4 > Age: ");
 	addGenericDD(getNewCell(row5), ["AWKAGEN", "WKAGEN_H"], [["", "Please select"], ["19", "19"], ["20", "20"], ["21", "21"], ["22", "22"], ["23", "23"], ["24", "24"], ["25", "25"], ["26", "26"], ["27", "27"], ["28", "28"], ["29", "29"], ["30", "30"], ["31", "31"], ["32", "32"], ["33", "33"], ["34", "34"], ["35", "35"], ["36", "36"], ["37", "37"], ["38", "38"], ["39", "39"], ["40", "40"], ["41", "41"], ["42", "42"], ["43", "43"], ["44", "44"], ["45", "45"], ["46", "46"], ["47", "47"], ["48", "48"], ["49", "49"], ["50", "50"], ["51", "51"], ["52", "52"], ["53", "53"], ["54", "54"], ["55", "55"], ["56", "56"], ["57", "57"], ["58", "58"], ["59", "59"], ["60", "60"], ["61", "61"], ["62", "62"], ["63", "63"], ["64", "64"], ["65", "65"], ["66", "66"], ["67", "67"], ["68", "68"], ["69", "69"], ["70", "70"], ["71", "71"], ["72", "72"], ["73", "73"], ["74", "74"], ["75", "75"], ["76", "76"], ["77", "77"], ["78", "78"], ["79", "79"], ["80", "80"]]);
	tabBody.appendChild(row5);
}



//
// function to add the landlordspecific dropdowns and buttons
//
function setLand(tabBody, table) {
	// add the building sum insured row to the table
	var row1 = document.createElement('tr');
	addTextCell(row1, "1 > Building Sum Insured: ");
	addGenericDD(getNewCell(row1), ["SLSBLSI", "LSBLSI_L"], [["0", "Please select"], ["140000", "140,000"], ["145000", "145,000"], ["150000", "150,000"], ["155000", "155,000"], ["160000", "160,000"], ["165000", "165,000"], ["170000", "170,000"], ["175000", "175,000"], ["180000", "180,000"], ["185000", "185,000"], ["190000", "190,000"], ["195000", "195,000"], ["200000", "200,000"], ["205000", "205,000"], ["210000", "210,000"], ["215000", "215,000"], ["220000", "220,000"], ["225000", "225,000"], ["230000", "230,000"], ["235000", "235,000"], ["240000", "240,000"], ["245000", "245,000"], ["250000", "250,000"], ["260000", "260,000"], ["270000", "270,000"], ["280000", "280,000"], ["290000", "290,000"], ["300000", "300,000"], ["310000", "310,000"], ["320000", "320,000"], ["330000", "330,000"], ["340000", "340,000"], ["350000", "350,000"], ["360000", "360,000"], ["370000", "370,000"], ["380000", "380,000"], ["390000", "390,000"], ["400000", "400,000"], ["410000", "410,000"], ["420000", "420,000"], ["430000", "430,000"], ["440000", "440,000"], ["450000", "450,000"], ["475000", "475,000"], ["500000", "500,000"], ["525000", "525,000"], ["550000", "550,000"], ["575000", "575,000"], ["600000", "600,000"], ["625000", "625,000"], ["635000", "635,000"]]);
	addImageCell(row1, 4);
	tabBody.appendChild(row1);
	// add the contents sum insured row to the table
	var row2 = document.createElement('tr');
	addTextCell(row2, "2 > Contents Sum Insured: ");
	addGenericDD(getNewCell(row2), ["SLSCTSI", "LSCTSI_L"], [["0", "Please select"], ["20000", "20,000"], ["25000", "25,000"], ["30000", "30,000"], ["35000", "35,000"], ["40000", "40,000"], ["45000", "45,000"], ["50000", "50,000"], ["55000", "55,000"], ["60000", "60,000"], ["65000", "65,000"], ["70000", "70,000"], ["75000", "75,000"], ["80000", "80,000"], ["85000", "85,000"], ["90000", "90,000"], ["95000", "95,000"], ["100000", "100,000"], ["105000", "105,000"], ["110000", "110,000"], ["115000", "115,000"], ["120000", "120,000"], ["125000", "125,000"]]);
	tabBody.appendChild(row2);
	// add the area row to the dropdown
	var row3 = document.createElement('tr');
	addTextCell(row3, "3 > Area: ");
	addCountyDD(getNewCell(row3), ["AHRLOCC", "HRLOCC_L"]);
	tabBody.appendChild(row3);
	// add age row to the table
	var row5 = document.createElement('tr');
	addTextCell(row5, "4 > Age: ");
 	addGenericDD(getNewCell(row5), ["AWKAGEN", "WKAGEN_L"], [["", "Please select"], ["19", "19"], ["20", "20"], ["21", "21"], ["22", "22"], ["23", "23"], ["24", "24"], ["25", "25"], ["26", "26"], ["27", "27"], ["28", "28"], ["29", "29"], ["30", "30"], ["31", "31"], ["32", "32"], ["33", "33"], ["34", "34"], ["35", "35"], ["36", "36"], ["37", "37"], ["38", "38"], ["39", "39"], ["40", "40"], ["41", "41"], ["42", "42"], ["43", "43"], ["44", "44"], ["45", "45"], ["46", "46"], ["47", "47"], ["48", "48"], ["49", "49"], ["50", "50"], ["51", "51"], ["52", "52"], ["53", "53"], ["54", "54"], ["55", "55"], ["56", "56"], ["57", "57"], ["58", "58"], ["59", "59"], ["60", "60"], ["61", "61"], ["62", "62"], ["63", "63"], ["64", "64"], ["65", "65"], ["66", "66"], ["67", "67"], ["68", "68"], ["69", "69"], ["70", "70"], ["71", "71"], ["72", "72"], ["73", "73"], ["74", "74"], ["75", "75"], ["76", "76"], ["77", "77"], ["78", "78"], ["79", "79"], ["80", "80"]]);
	tabBody.appendChild(row5);
}



//
// function to add the travel specific dropdowns and buttons
//
function setTravel(tabBody, table) {
	// add the age row to the table
	var row1 = document.createElement('tr');
	addTextCell(row1, "1 > Age: ");
	addGenericDD(getNewCell(row1), ["AQAGE", "AQAGE_T"], [["X", "Please Select"], ["A", "18-49"], ["B", "50-59"], ["C", "60-64"], ["D", "65"], ["E", "66"], ["F", "67"], ["G", "68"], ["H", "69"], ["I", "70"], ["J", "71"], ["K", "72"], ["L", "73"], ["M", "74"], ["N", "75"], ["O", "76-99"]]);
	addImageCell(row1, 5);
	tabBody.appendChild(row1);
	// add the who is ot be insured row to the table
	var row2 = document.createElement('tr');
	addTextCell(row2, "2 > Who is to be insured:");
	addGenericDD(getNewCell(row2), ["AQWHO", "AQWHO_T"], [["X", "Please Select"], ["A", "Insured Only"], ["B", "Individual " + "\u0026" + " Spouse/Partner"], ["C", "Insured " + "\u0026" + " Family"], ["D", "Individual, Partner " + "\u0026" + " Family"]]);
	tabBody.appendChild(row2);
	// add the geography row to the dropdown
	var row3 = document.createElement('tr');
	addTextCell(row3, "3 > Geography: ");
	addGenericDD(getNewCell(row3), ["AQGEO", "AQGEO_T"], [["X", "Please Select"], ["A", "Europe Only"], ["B", "Worldwide Incl USA/Canada/Caribbean"], ["C", "Worldwide Excl USA/Canada/Caribbean"]]);
	tabBody.appendChild(row3);
	// add optional extras row the the dropdown
	var row4 = document.createElement('tr');
	addTextCell(row4, "4 > Optional extras: ");
	addGenericDD(getNewCell(row4), ["AQOPE", "AQOPE_T"], [["X","Please Select"], ["A", "Winter Sports Cover"], ["B", "Winter Sports Equipment"], ["C", "Golf Extension"], ["D", "All Of The Above"], ["F", "Winter Sports " + "\u0026" + " Winter Sports Equipment"], ["G", "Winter Sports " + "\u0026" + " Golf Cover"], ["E", "None Of The Above"]]);
	tabBody.appendChild(row4);
	// add allianz policyholder row to the table
	var row5 = document.createElement('tr');
	addTextCell(row5, "5 > Journey Duration: ");
	addGenericDD(getNewCell(row5), ["AQCUR", "AQCUR_T"], [["X", "Please Select"], ["A", "Up To 35 Days"], ["B", "Up To 60 Days"], ["C", "Up To 90 Days"]]);
	tabBody.appendChild(row5);
}



//
// function to add the schools ppa specific dropdowns and buttons
//
function setPpa(tabBody, table) {
	// add the cover row to the table
	var row1 = document.createElement('tr');
	addTextCellWidth(row1, "1 > What Cover is required: ", 200);
	addGenericDD(getNewCell(row1), ["AQCOV", "AQCOV_T"], [["X", "Please Select"], ["A", "Option A - All Pupils in School"], ["B", "Option B - Optional Covers"]]);
	addImageCell(row1, 3);
	tabBody.appendChild(row1);
	// add the number of 24 hour pupils row to the table
	var row3 = document.createElement('tr');
	addTextCellWidth(row3, "2 > Pupils - 24 Hour Cover*:", 200);
	addInput(getNewCell(row3), "AQPUP", "AQPUP_T");
	tabBody.appendChild(row3);
	// add the number of school activities pupils row to the table
	var row4 = document.createElement('tr');
	addTextCellWidth(row4, "3 > Pupils - School Activities*:", 200);
	addInput(getNewCell(row4), "AQPU2", "AQPU2_T");
	tabBody.appendChild(row4);
	// add the note row to the table
	var row5 = document.createElement('tr');
	var cell5 = document.createElement('td');
	cell5.colSpan = 3;
	var cell_txt = document.createTextNode("* For Option A please enter number of pupils for 24 Hour Cover OR Schools Activities (only ONE option). For Option B please enter number of pupils for EITHER / BOTH.");
	cell5.style.fontSize = "10px";
	cell5.appendChild(cell_txt);
	row5.appendChild(cell5);
	tabBody.appendChild(row5);
}



// function to list all child objects in the motor div
function destroyEst() {
	if (EXISTS_EST) {
		while (document.getElementById('est_overallcontainer').childNodes.length > 0) {
			traverseDomTree_recurse(document.getElementById('est_overallcontainer'), 0);
		}
		document.getElementById('est_overallcontainer').parentNode.removeChild(document.getElementById('est_overallcontainer'));
		EXISTS_EST = false;
	}
}



//
// function to get an estimate
//
function getQuickEstimate(product) {
	if (call_mode == "MODE_AJAX") {
		document.getElementById('calc_result').style.background = "url('')";
		document.getElementById('calc_result').style.backgroundColor = '#F06F1B';
		switch (product) {
			case 'Motor':
				var ret = sendQEAjaxRequest('/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN02+'+partition+'+funcparms+WKSC(A0010):+WKGE(A0010):'+document.getElementById('AGENDC1').value+'+WKAG(S0030):'+document.getElementById('AQAGE1').value+'+WKAR(A0020):'+document.getElementById('AQCOUNTY1').value+'+WKGP(S0020):'+document.getElementById('AQCART1').value+'+WKNC(S0020):'+document.getElementById('AQNCB1').value, product);
				break;
			case 'Pet':
				var ret = sendQEAjaxRequest('/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN05+'+partition+'+funcparms+WKSC(A0010):+AQPET(A0030):'+document.getElementById('AAQPET').value+'+AQBRD(A0030):'+document.getElementById('AAQBRD').value+'+AQMIC(A0010):'+document.getElementById('AAQMIC').value+'+AQOWA(A0010):'+document.getElementById('AAQOWA').value+'+AQPTA(A0010):'+document.getElementById('AAQPTA').value, product);
				break;
			case 'Travel':
				var ret = sendQEAjaxRequest('/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN04+'+partition+'+funcparms+WKSC(A0010):+AQAGE(A0010):'+document.getElementById('AQAGE_T').value+'+AQWHO(A0010):'+document.getElementById('AQWHO_T').value+'+AQGEO(A0010):'+document.getElementById('AQGEO_T').value+'+AQOPE(A0010):'+document.getElementById('AQOPE_T').value+'+AQCUR(A0010):'+document.getElementById('AQCUR_T').value, product);
				break;
			case 'Household':
				var ret = sendQEAjaxRequest('/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN03+'+partition+'+funcparms+WKCOVC(A0030):BAC+HRPROD(A0030):DCR+ASTRS(A0030):ROI+WKSC(A0010):+LSBLSI(S0070):'+document.getElementById('LSBLSI_S').value+'+WKCSIN(S0020):'+document.getElementById('LWKCSIN').value+'+HRLOCC(A0020):'+document.getElementById('HRLOCC_S').value+'+WKADCR(A0030):'+document.getElementById('WKADCR_S').value+'+WKAGEN(P0030):'+document.getElementById('WKAGEN_S').value, product);
				break;
			case 'Contents Only':
				var ret = sendQEAjaxRequest('/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN03+'+partition + '+funcparms+WKCOVC(A0030):BAC+HRPROD(A0030):DHR+ASTRS(A0030):ROI+WKSC(A0010):+LSBLSI(S0070):0+LSCTSI(S0070):'+document.getElementById('LSCTSI_C').value+'+HRLOCC(A0020):'+document.getElementById('HRLOCC_C').value+'+WKADCR(A0030):'+document.getElementById('WKADCR_C').value+'+WKAGEN(P0030):'+document.getElementById('WKAGEN_C').value, product);
				break;
			case 'Holiday Home':
				var ret = sendQEAjaxRequest('/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN03+'+partition+'+funcparms+WKCOVC(A0030):HBC+HRPROD(A0030):DHR+ASTRS(A0030):ROI+WKSC(A0010):+LSBLSI(S0070):'+document.getElementById('LSBLSI_H').value+'+LSCTSI(S0070):'+document.getElementById('LSCTSI_H').value+'+HRLOCC(A0020):'+document.getElementById('HRLOCC_H').value+'+WKAGEN(P0030):'+document.getElementById('WKAGEN_H').value, product);
				break;
			case 'Landlord':
				var ret = sendQEAjaxRequest('/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN03+'+partition+'+funcparms+WKCOVC(A0030):LBC+HRPROD(A0030):DHR+ASTRS(A0030):ROI+WKSC(A0010):+HROCCU(A0020):L1+LSBLSI(S0070):'+document.getElementById('LSBLSI_L').value+'+LSCTSI(S0070):'+document.getElementById('LSCTSI_L').value+'+HRLOCC(A0020):'+document.getElementById('HRLOCC_L').value+'+WKAGEN(P0030):'+document.getElementById('WKAGEN_L').value, product);
				break;
			case 'Pupil Personal Accident':
				if ((document.getElementById('AQCOV_T').value != 'X') && ((document.getElementById('AQPUP_T').value != '') || (document.getElementById('AQPU2_T').value != ''))) {
					var calcval = 0.0;
					var intin = parseInt(document.getElementById('AQPUP_T').value);
					var intin2 = parseInt(document.getElementById('AQPU2_T').value);
					if (document.getElementById('AQCOV_T').value == 'A') {
						if ((document.getElementById('AQPUP_T').value != '') && (document.getElementById('AQPU2_T').value != '')) {
							alert("For Option A you can only enter pupils for one cover");
						} else {					
							if (document.getElementById('AQPUP_T').value != '') {
								calcval = 4.90 * intin;
							}
							if (document.getElementById('AQPU2_T').value != '') {
								calcval = 2.80 * intin2;
							}
						}
					}
					if (document.getElementById('AQCOV_T').value == 'B') {
						if (document.getElementById('AQPUP_T').value != '')
								calcval = (5.60 * intin);
						if (document.getElementById('AQPU2_T').value != '')
								calcval +=  (3.50 * intin2);
					}
					document.getElementById('calc_result').innerHTML = "&euro; " + (Math.round(calcval*100)/100).toFixed(2);
				}
				else {
					alert("Please answer all questions");
				}
				break;
			default:
				document.getElementById('calc_result').innerHTML ="An error has occurred. No product selected.";
				break;
		}
	}
	if (call_mode == "MODE_WINDOW") {
		switch (product) {
			case 'Motor':
				if (document.getElementById('AGENDC1').value != '' && document.getElementById('AQAGE1').value != '' && document.getElementById('AQCOUNTY1').value != '' && document.getElementById('AQCART1').value != 0 && document.getElementById('AQNCB1').value != '') {
					Redirect('/Estimators/?QE=HOU');
					var ret = window.open('https://www.allianz.ie/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN02+'+partition+'+funcparms+WKSC(A0010):S+WKGE(A0010):'+document.getElementById('AGENDC1').value+'+WKAG(S0030):'+document.getElementById('AQAGE1').value+'+WKAR(A0020):'+document.getElementById('AQCOUNTY1').value+'+WKGP(S0020):'+document.getElementById('AQCART1').value+'+WKNC(S0020):'+document.getElementById('AQNCB1').value+'+ACOC(A0100):ADR');
				} else {
					alert("Please answer all questions");
				}
				break;
			case 'Pet':
				if (document.getElementById('AAQPET').value != 'X' && document.getElementById('AAQBRD').value != 'X' && document.getElementById('AAQMIC').value != 'X' && document.getElementById('AAQOWA').value != 'X' && document.getElementById('AAQPTA').value != 'X') {
					var ret = window.open('/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN05+'+partition + '+funcparms+WKSC(A0010):S+AQPET(A0030):'+document.getElementById('AAQPET').value+'+AQBRD(A0030):'+document.getElementById('AAQBRD').value+'+AQMIC(A0010):'+document.getElementById('AAQMIC').value+'+AQOWA(A0010):'+document.getElementById('AAQOWA').value+'+AQPTA(A0010):'+document.getElementById('AAQPTA').value);
				} else {
					alert("Please answer all questions");
				}
				break;

			case 'Travel':
				if (document.getElementById('AQAGE_T').value != 'X' && document.getElementById('AQWHO_T').value != 'X' && document.getElementById('AQOPE_T').value != 'X' && document.getElementById('AQCUR_T').value != 'X' && document.getElementById('AQGEO_T').value != 'X') {
					Redirect('/Estimators/?QE=MOT');
					var ret = window.open('https://www.allianz.ie/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN04+'+partition+'+funcparms+WKSC(A0010):S+AQAGE(A0010):'+document.getElementById('AQAGE_T').value+'+AQWHO(A0010):'+document.getElementById('AQWHO_T').value+'+AQGEO(A0010):'+document.getElementById('AQGEO_T').value+'+AQOPE(A0010):'+document.getElementById('AQOPE_T').value+'+AQCUR(A0010):'+document.getElementById('AQCUR_T').value);
				} else {
					alert("Please answer all questions");
				}
				break;
			case 'Household':
				if (document.getElementById('LSBLSI_S').value != '0' && document.getElementById('LWKCSIN').value != '0' && document.getElementById('HRLOCC_S').value != '' && document.getElementById('WKADCR_S').value != '' && document.getElementById('WKAGEN_S').value != '') {
					Redirect('/Estimators/?QE=MOT');
					var ret = window.open('https://www.allianz.ie/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN03+'+partition + '+funcparms+WKCOVC(A0030):BAC+HRPROD(A0030):DCR+ASTRS(A0030):ROI+WKSC(A0010):S+LSBLSI(S0070):'+document.getElementById('LSBLSI_S').value+'+WKCSIN(S0020):'+document.getElementById('LWKCSIN').value+'+HRLOCC(A0020):'+document.getElementById('HRLOCC_S').value+'+WKADCR(A0030):'+document.getElementById('WKADCR_S').value+'+WKAGEN(P0030):'+document.getElementById('WKAGEN_S').value);
				} else {
					alert("Please answer all questions");
				}
				break;	
			case 'Contents Only':
				if (document.getElementById('LSCTSI_C').value != '0' && document.getElementById('HRLOCC_C').value != '' && document.getElementById('WKADCR_C').value != '' && document.getElementById('WKAGEN_C').value != '') {
					Redirect('/Estimators/?QE=MOT');
					var ret = window.open('https://www.allianz.ie/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN03+'+partition + '+funcparms+WKCOVC(A0030):BAC+HRPROD(A0030):DHR+ASTRS(A0030):ROI+WKSC(A0010):S+LSBLSI(S0070):0+LSCTSI(S0070):'+document.getElementById('LSCTSI_C').value+'+HRLOCC(A0020):'+document.getElementById('HRLOCC_C').value+'+WKADCR(A0030):'+document.getElementById('WKADCR_C').value+'+WKAGEN(P0030):'+document.getElementById('WKAGEN_C').value);
				} else {
					alert("Please answer all questions");
				}
				break;
			case 'Holiday Home':
				if ((document.getElementById('LSBLSI_H').value != '0' || document.getElementById('LSCTSI_H').value != '0') && document.getElementById('HRLOCC_H').value != '' && document.getElementById('WKAGEN_H').value != '') {
					Redirect('/Estimators/?QE=MOT');
					var ret = window.open('https://www.allianz.ie/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN03+'+partition+'+funcparms+WKCOVC(A0030):HBC+HRPROD(A0030):DHR+ASTRS(A0030):ROI+WKSC(A0010):S+LSBLSI(S0070):'+document.getElementById('LSBLSI_H').value+'+LSCTSI(S0070):'+document.getElementById('LSCTSI_H').value+'+HRLOCC(A0020):'+document.getElementById('HRLOCC_H').value+'+WKAGEN(P0030):'+document.getElementById('WKAGEN_H').value);
				} else {
					if (document.getElementById('LSBLSI_H').value == '0' && document.getElementById('LSCTSI_H').value == '0') {
					alert("Please provide value for either Buildings Sum Insured or Contents Sum Insured");
					}
					else {
					alert("Please select Area and Age");
					}
				}
				break;
			case 'Landlord':
				if ((document.getElementById('LSBLSI_L').value != '0' || document.getElementById('LSCTSI_L').value != '0') && document.getElementById('HRLOCC_L').value != '' && document.getElementById('WKAGEN_L').value != '') {
					Redirect('/Estimators/?QE=MOT');
					var ret = window.open('https://www.allianz.ie/CGI-BIN/LANSAWEB?procfun+MQQPROC+MQQFN03+'+partition+'+funcparms+WKCOVC(A0030):LBC+HRPROD(A0030):DHR+ASTRS(A0030):ROI+WKSC(A0010):S+HROCCU(A0020):L1+LSBLSI(S0070):'+document.getElementById('LSBLSI_L').value+'+LSCTSI(S0070):'+document.getElementById('LSCTSI_L').value+'+HRLOCC(A0020):'+document.getElementById('HRLOCC_L').value+'+WKAGEN(P0030):'+document.getElementById('WKAGEN_L').value);
				} else {
					if (document.getElementById('LSBLSI_L').value == '0' && document.getElementById('LSCTSI_L').value == '0') {
					alert("Please provide value for either Buildings Sum Insured or Contents Sum Insured");
					}
					else {			
					alert("Please select Area and Age");
					}
				}
				break;
			case 'Pupil Personal Accident':
				if ((document.getElementById('AQCOV_T').value != 'X') && ((document.getElementById('AQPUP_T').value != '') || (document.getElementById('AQPU2_T').value != ''))) {
					var calcval = 0.0;
					var intin = parseInt(document.getElementById('AQPUP_T').value);
					var intin2 = parseInt(document.getElementById('AQPU2_T').value);
					if (document.getElementById('AQCOV_T').value == 'A') {
						if ((document.getElementById('AQPUP_T').value != '') && (document.getElementById('AQPU2_T').value != '')) {
							alert("For Option A you can only enter pupils for one cover");
						} else {					
							if (document.getElementById('AQPUP_T').value != '') {
								calcval = 4.90 * intin;
							}
							if (document.getElementById('AQPU2_T').value != '') {
								calcval = 2.80 * intin2;
							}
						}
					}
					if (document.getElementById('AQCOV_T').value == 'B') {
						if (document.getElementById('AQPUP_T').value != '')
								calcval = (5.60 * intin);
						if (document.getElementById('AQPU2_T').value != '')
								calcval +=  (3.50 * intin2);
					}
					document.getElementById('calc_result').innerHTML = "&euro; " + (Math.round(calcval*100)/100).toFixed(2);
				}
				else {
					alert("Please answer all questions");
				}
				break;
			default:
				document.getElementById('calc_result').innerHTML ="An error has occurred. No product selected.";
				break;
		}
	}
}


/******************************************** GENERAL FUNCTIONS **************************************************************/



//
// function to add a cell with text to a row
//
function addTextCell(row, text){
	var txt = document.createTextNode(text);
	var cell = document.createElement('td');
	cell.className = "fCol";
	var lab = document.createElement('label');
	lab.appendChild(txt);
	cell.appendChild(lab);
	row.appendChild(cell);
}



//
// function to add a cell with text to a row
//
function addTextCellWidth(row, text, width){
	var txt = document.createTextNode(text);
	var cell = document.createElement('td');
	cell.width = width;
	cell.className = "fCol";
	var lab = document.createElement('label');
	lab.appendChild(txt);
	cell.appendChild(lab);
	row.appendChild(cell);
}


//
// function to add a multi-column cell with text to a row
//
function addMultiColTextCell(row, text, cols){
	var txt = document.createTextNode(text);
	var cell = document.createElement('td');
	cell.appendChild(txt);
	cell.className = "est_tableText";
	cell.colSpan = cols;
	row.appendChild(cell);
}



//
// function to add a multi-row cell with text to a row
//
function addMultiRowTextCell(row, text, rows, width){
	var txt = document.createTextNode(text);
	var cell = document.createElement('td');
	cell.appendChild(txt);
	cell.className = "est_tableText";
	cell.rowSpan = rows;
	if (text != "") {
		cell.className = "est_tableCellPremiumText";
		cell.id = "calc_result";
	}
	cell.width = width;
	row.appendChild(cell);
}



//
// function to add a multi-row cell with text to a row
//
function addImageCell(row, rows){
	var cell = document.createElement('td');
	cell.id = "calc_result";
	cell.height =  "170px";
//	var img = document.createElement('img');
//	img.src = "img/calc.jpg";
//	img.alt = "Calculate Now";
//	cell.appendChild(img);
	cell.className = "endCol";
	cell.rowSpan = rows;
	cell.width = "130px";
	row.appendChild(cell);
}



//
// function to add a cell with an object to a row
//
function getNewCell(row) {
	var cell = document.createElement('td');
	row.appendChild(cell);
	return cell;
}



//
// function to create a new text input object
//
function addInput(container, name, id) {
	var inp = document.createElement('input');
	inp.name = name;
	inp.className = 'est_tableDropdown';
	inp.id = id;
	inp.maxLength = 5;
	inp.size = 5;
	container.appendChild(inp);
}



//
// function to create a new Select object
//
function createSelect(name, id) {
	var sel = document.createElement('select');
	sel.name = name;
	sel.className = 'est_tableDropdown';
	sel.id = id;
	return sel;
}



//
// generic function to create dropdowns dynamically
//
function addGenericDD(container, select, options) {
	var seltemp = createSelect(select[0], select[1]);
	for (i=0; i<options.length; i++) {
		addSelectItem(seltemp, options[i][0], options[i][1]);
	}
	container.appendChild(seltemp);
}



//
// function to add a select item to a dropdown
//
function addSelectItem(select, itemvalue, itemtext) {
	var option = document.createElement('option');
	option.value = itemvalue;
	option.text = itemtext;
	try {
		select.add(option,null);
	} catch(ex) {
		select.add(option);
	}
}



//
// function to send the Ajax request
//
function sendQEAjaxRequest(url, product) {
	document.getElementById('calc_result').innerHTML = "Generating Estimate. <br /><br /> Please wait...";
	var req = null;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		if (req.overrideMimeType) {
			req.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)  {}
		}
	}
	req.onreadystatechange = function() {
		if(req.readyState == 4) {
			if(req.status == 200) {
				var ajaxIn = req.responseText;
				var loc = ajaxIn.indexOf(':');

				if (ajaxIn.substring(0, loc) > 1) {
					document.getElementById('calc_result').innerHTML = "Premium Estimate is: &euro;" + ajaxIn.substring(0, loc);
				}
				else {
					ajaxIn = ajaxIn.substring(loc+1, ajaxIn.length - loc + 2);
					var loc2 = ajaxIn.indexOf(':');
					if (loc2 > 1) {
						ajaxIn = ajaxIn.substring(0, loc2);
					}
					document.getElementById('calc_result').innerHTML = ajaxIn;
				}
			}
			else {
				alert("Error: returned status code " + req.status + " " + req.statusText);
			}
		}
	};
	try {
		req.open("GET", url, true);
		req.send(null);
	}
	catch (ex) {
		alert("Error: returned status code " + req.status + " " + req.statusText);
	}
}



//
// function to remove all of the document nodes
//
function traverseDomTree_recurse(curr_element, level) {
	var i;
	if(curr_element.childNodes.length <= 0) {
		curr_element.parentNode.removeChild(curr_element);
		curr_element = null;
	} else {
		try {
			for(i=0; curr_element.childNodes.item(i); i++) {
				traverseDomTree_recurse(curr_element.childNodes.item(i), level+1);
			}
		} catch (e) {  }
	}
}
