//
// global variables for motor estimate
//	
var qqprem = 0;



//
// global variable for LANSA partition
//
var partition = "ALL";
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"],["01", "BT01"],["02", "BT02"],["03", "BT03"],["04", "BT04"],["05", "BT05"],["06", "BT06"],["07", "BT07"],["08", "BT08"],["09", "BT09"],["10", "BT10"],["11", "BT11"],["12", "BT12"],["13", "BT13"],["14", "BT14"],["15", "BT15"],["16", "BT16"],["17", "BT17"],["18", "BT18"],["19", "BT19"],["20", "BT20"],["21", "BT21"],["22", "BT22"],["23", "BT23"],["24", "BT24"],["25", "BT25"],["26", "BT26"],["27", "BT27"],["28", "BT28"],["29", "BT29"],["30", "BT30"],["31", "BT31"],["32", "BT32"],["33", "BT33"],["34", "BT34"],["35", "BT35"],["36", "BT36"],["37", "BT37"],["38", "BT38"],["39", "BT39"],["40", "BT40"],["41", "BT41"],["42", "BT42"],["43", "BT43"],["44", "BT44"],["45", "BT45"],["46", "BT46"],["47", "BT47"],["48", "BT48"],["49", "BT49"],
["51", "BT51"],["52", "BT52"],["53", "BT53"],["54", "BT54"],["55", "BT55"],["56", "BT56"],["57", "BT57"],["60", "BT60"],["61", "BT61"],["62", "BT62"],["63", "BT63"],["64", "BT64"],["65", "BT65"],["66", "BT66"],["67", "BT67"],["68", "BT68"],["69", "BT69"],["70", "BT70"],["71", "BT71"],["74", "BT74"],["75", "BT75"],["76", "BT76"],["77", "BT77"],["78", "BT78"],["79", "BT79"],["80", "BT80"],["81", "BT81"],["82", "BT82"],["92", "BT92"],["93", "BT93"],["94", "BT94"]]);
}




//
// function to add Age dropdown
//
function addAgeDD(container) {
	var ageArr = new Array();
	ageArr[0] = new Array("", "Please select");
	for (var i=1; i<63; i++)
		ageArr[i] = new Array(i+16, i+16);
	for (var j=63; j<=82; j++)
		ageArr[j] = new Array(80, j+17);
	addGenericDD(container, ["AQAGE1", "AQAGE1"], ageArr);
}



//
// function to add a button
//
function addLinkButtons(container, product) {
	var div = document.createElement('div');
	div.id = "est_standardButtons";
	var ul = document.createElement('ul');
	var li = document.createElement('li');
	li.className = "menu1";
	var calc = document.createElement("a");
	var txt = document.createTextNode("Calculate");
	calc.appendChild(txt);
	calc.tabIndex = 0;
	calc.id = "Calculate_id";
	calc.onclick = function () {
		getQuickEstimate(product);
	}
	calc.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);
		}
	}
	li.appendChild(calc);
	ul.appendChild(li);
	if (call_mode == "MODE_AJAX") {
		var li2 = document.createElement('li');
		li2.className = "menu2";
		var calc2 = document.createElement("a");
		var txt2 = document.createTextNode("Quote");
		calc2.appendChild(txt2);
		calc2.tabIndex = 0;
		calc2.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+afnm03+Alz+funcparms+acoc(A0100):ADN');
					break;
				case 'Contents Only':
					QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+niPROC01+nifNlg+adu');
					break;
				case 'Buildings Only':
					QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+niPROC01+nifNlg+adu');
					break;
				case 'Buildings and Contents':
					QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+niPROC01+nifNlg+adu');
					break;
				}
			}
		}
		calc2.onclick = function () {
			switch (product) {
			case 'Motor':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+aprocmot+afnm03+Alz+funcparms+acoc(A0100):ADN');
				break;
			case 'Contents Only':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+niPROC01+nifNlg+adu');
				break;
			case 'Buildings Only':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+niPROC01+nifNlg+adu');
				break;
			case 'Buildings and Contents':
				QQPopUp('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+niPROC01+nifNlg+adu');
				break;
			}
		}
		li2.appendChild(calc2);
		ul.appendChild(li2);
	}
	div.appendChild(ul);
	container.appendChild(div);
}




//
// 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_portletquoteTeaser";
		// header division
		h_div = document.createElement('div');
		h_div.className = "est_portletHeaderHighlight";
		h_txt = document.createTextNode(product + " Estimator");
		h_div.innerHTML = "&nbsp; &nbsp;";
		h_div.appendChild(h_txt);
		tease_div.appendChild(h_div);
		// main div
		m_div = document.createElement('div');
		m_div.id = "est_portletQuoteCurtain";
		// text div
		t_div = document.createElement('div');
		t_div.id = "est_portletQuoteCurtainCol1";
		t_div.className = "est_termstext";
		t_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 an estimate.");
		t_div.appendChild(t_txt);
		// add the text div to the main div
		m_div.appendChild(t_div);
		// quote div
		var q_div = document.createElement('div');
		q_div.id = "est_fsuoteCurtainCol2";
		// create table and attributes
		var table = document.createElement("table");
		table.border = "0";
		table.id = "est_table";
		var tabBody = document.createElement("tbody");
		// add the header row to the table
		var row = document.createElement('tr');
		addMultiColTextCell(row, "Please enter details below: ", 5);
		tabBody.appendChild(row);

		// add product specific dropdowns and buttons
		switch (product) {
			case 'Motor':
				setMotor(tabBody, table, q_div);
				break;
			case 'Contents Only':
				setHouco(tabBody, table, q_div);
				break;
			case 'Buildings Only':
				setHoubo(tabBody, table, q_div);
				break;
			case 'Buildings and Contents':
				setHoubc(tabBody, table, q_div);
				break;

		}

		// add an empty row
		var row7 = document.createElement('tr');
		addMultiColTextCell(row7, "", 5);
		tabBody.appendChild(row7);
		// add the table to the form
		table.appendChild(tabBody);
		q_div.appendChild(table);
		// add buttons
		addLinkButtons(q_div, product);
		// add quote div to the main div
		m_div.appendChild(q_div);
		tease_div.appendChild(m_div);
		document.getElementById(div).appendChild(tease_div);
		EXISTS_EST = true;
	}
}



//
// function to add the motor specific dropdowns and buttons
//
function setMotor(tabBody, table, q_div) {
	// add the gender row to the table
	var row1 = document.createElement('tr');
	addTextCell(row1, "Gender: ");
	addGenericDD(getNewCell(row1), ["AGENDC1", "AGENDC1"], [["", "Please select"], ["M", "Male"], ["F", "Female"]]);
	addMultiRowTextCell(row1, "", 5, 15);
	addMultiRowTextCell(row1, "Press calculate to get your estimate", 5, 130);
	addMultiRowTextCell(row1, "", 5, 9);
	tabBody.appendChild(row1);

	// add the age row to the table
	var row2 = document.createElement('tr');
	addTextCell(row2, "Age: ");
	addAgeDD(getNewCell(row2));
	tabBody.appendChild(row2);

	// add the county row to the dropdown
	var row3 = document.createElement('tr');
	addTextCell(row3, "Location: ");
	addCountyDD(getNewCell(row3), ["AQCOUNTY1", "AQCOUNTY1"]);
	tabBody.appendChild(row3);
	// add car type row the the dropdown
	var row4 = document.createElement('tr');
	addTextCell(row4, "Car Type: ");
	addGenericDD(getNewCell(row4), ["AQCART1", "AQCART1"], [["0", "Please select"], ["7", "Compact - Renault Clio 1.1"], ["10", "Family - Toyota Corolla 1.4"], ["17", "Full size - Toyota Avensis 1.8"], ["23", "Executive - BMW 318 2.0"]]);
	tabBody.appendChild(row4);
	// add ncd row to the table
	var row5 = document.createElement('tr');
	addTextCell(row5, "NCD: ");
	addGenericDD(getNewCell(row5), ["AQNCB1", "AQNCB1"], [["", "Please select"], ["1", "1 Year"], ["2", "2 Years"], ["3", "3 Years"], ["4", "4 Years"], ["5", "5 Years"], ["6", "5+ Years"]]);
	tabBody.appendChild(row5);
}




//
// function to add the contents only specific dropdowns and buttons
//
function setHouco(tabBody, table, q_div) {
	// add the contents sum insured row to the table
	var row1 = document.createElement('tr');
	addTextCell(row1, "Contents Sum Insured: ");
	addGenericDD(getNewCell(row1), ["SLSCTSI", "LSCTSI_C"], [["0", "Please select"],["15000", "15,000"], ["16000", "16,000"],  ["17000", "17,000"],  ["18000", "18,000"], ["19000", "19,000"],  ["20000", "20,000"],  ["21000", "21,000"],  ["22000", "22,000"],  ["23000", "23,000"],  ["24000", "24,000"],  ["25000", "25,000"],  ["26000", "26,000"],  ["27000", "27,000"], ["28000", "28,000"], ["29000", "29,000"], ["30000", "30,000"], ["31000", "31,000"], 
["32000", "32,000"], ["33000", "33,000"], ["34000", "34,000"], ["35000", "35,000"], ["36000", "36,000"], ["37000", "37,000"], ["38000", "38,000"], ["39000", "39,000"], ["40000", "40,000"], ["41000", "41,000"], ["42000", "42,000"], ["43000", "43,000"], ["44000", "44,000"], ["45000", "45,000"], ["46000", "46,000"], ["47000", "47,000"], ["48000", "48,000"], ["49000", "49,000"], ["50000", "50,000"], ["51000", "51,000"], ["52000", "52,000"], ["53000", "53,000"], 
["54000", "54,000"], ["55000", "55,000"], ["56000", "56,000"], ["57000", "57,000"], ["58000", "58,000"], ["59000", "59,000"], ["60000", "60,000"], ["61000", "61,000"], ["62000", "62,000"], ["63000", "63,000"], ["64000", "64,000"], ["65000", "65,000"], ["66000", "66,000"], ["67000", "67,000"], ["68000", "68,000"], ["69000", "69,000"], ["70000", "70,000"], ["71000", "71,000"], ["72000", "72,000"], ["73000", "73,000"], ["74000", "74,000"], ["75000", "75,000"], 
["76000", "76,000"], ["77000", "77,000"], ["78000", "78,000"], ["79000", "79,000"], ["80000", "80,000"], ["81000", "81,000"], ["82000", "82,000"], ["83000", "83,000"], ["84000", "84,000"], ["85000", "85,000"], ["86000", "86,000"], ["87000", "87,000"], ["88000", "88,000"], ["89000", "89,000"], ["90000", "90,000"], ["91000", "91,000"], ["92000", "92,000"], ["93000", "93,000"], ["94000", "94,000"], ["95000", "95,000"], ["96000", "96,000"], ["97000", "97,000"], ["98000", "98,000"], 
["99000", "99,000"],  ["100000", "100,000"]]);

	addMultiRowTextCell(row1, "", 5, 15);
	addMultiRowTextCell(row1, "Premium Estimate is:", 5, 130);
	addMultiRowTextCell(row1, "", 5, 9);
	tabBody.appendChild(row1);
	
	// add the bedroom to the dropdown
	var row2 = document.createElement('tr');
	addTextCell(row2, "Bedrooms: ");
	addGenericDD(getNewCell(row2), ["AWKBED", "WKBED_C"], [["", "Please select"], ["01", "1"],["02", "2"],["03", "3"],["04", "4"],["05", "5"],["06", "6+"]]);
	tabBody.appendChild(row2);

	// add the Location row to the dropdown
	var row3 = document.createElement('tr');
	addTextCell(row3, "Location: ");
	addCountyDD(getNewCell(row3), ["ANILOCC", "NILOCC_C"]);
	tabBody.appendChild(row3);

	// add accidental damage row the the dropdown
	var row5 = document.createElement('tr');
	addTextCell(row5, "Accidental Damage: ");
	addGenericDD(getNewCell(row5), ["AWKADCR", "WKADCR_C"], [["", "Please select"], ["YES", "Yes on contents"], ["NO", "No on contents"]]);
	tabBody.appendChild(row5);

	// add age row to the table
	var row6 = document.createElement('tr');
	addTextCell(row6, "Age: ");
	addGenericDD(getNewCell(row6), ["AWKAGER", "WKAGER_C"], [["", "Please select"], ["25", "25"], ["30", "30"], ["35", "35"], ["40", "40"], ["45", "45"], ["50", "50"], ["55", "55"], ["60", "60"], ["65", "65"],["70", "70"]]);
	tabBody.appendChild(row6);
}



//
// function to add the Buildings Only specific dropdowns and buttons
//
function setHoubo(tabBody, table, q_div) {
	// add the contents sum insured row to the table
	var row1 = document.createElement('tr');
	addTextCell(row1, "Building Sum Insured: ");
	addGenericDD(getNewCell(row1), ["SLSBLSI", "LSBLSI_C"], [["0", "Please select"],

["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"], ["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"],  ["210000", "210,000"],  
["220000", "220,000"], ["230000", "230,000"], ["240000", "240,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"], ["460000", "460,000"], ["470000", "470,000"], 
["480000", "480,000"], ["490000", "490,000"], ["500000", "500,000"]]); 



	addMultiRowTextCell(row1, "", 5, 15);
	addMultiRowTextCell(row1, "Premium Estimate is:", 5, 130);
	addMultiRowTextCell(row1, "", 5, 9);
	tabBody.appendChild(row1);
	
	// add the bedroom to the dropdown
	var row2 = document.createElement('tr');
	addTextCell(row2, "Bedrooms: ");
	addGenericDD(getNewCell(row2), ["AWKBED", "WKBED_C"], [["", "Please select"], ["01", "1"],["02", "2"],["03", "3"],["04", "4"],["05", "5"],["06", "6+"]]);
	tabBody.appendChild(row2);

	// add the Location row to the dropdown
	var row3 = document.createElement('tr');
	addTextCell(row3, "Location: ");
	addCountyDD(getNewCell(row3), ["ANILOCC", "NILOCC_C"]);
	tabBody.appendChild(row3);

	
	// add age row to the table
	var row4 = document.createElement('tr');
	addTextCell(row4, "Age: ");
	addGenericDD(getNewCell(row4), ["AWKAGER", "WKAGER_C"], [["", "Please select"], ["25", "25"], ["30", "30"], ["35", "35"], ["40", "40"], ["45", "45"], ["50", "50"], ["55", "55"], ["60", "60"], ["65", "65"],["70", "70"]]);
	tabBody.appendChild(row4);
}


//
// function to add the Buildings & Contents specific dropdowns and buttons
//
function setHoubc(tabBody, table, q_div) {
	// add the contents sum insured row to the table
	var row1 = document.createElement('tr');
	addTextCell(row1, "Building Sum Insured: ");
	addGenericDD(getNewCell(row1), ["SLSBLSI", "LSBLSI_C"], [["0", "Please select"],

["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"], ["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"],  ["210000", "210,000"],  
["220000", "220,000"], ["230000", "230,000"], ["240000", "240,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"], ["460000", "460,000"], ["470000", "470,000"], 
["480000", "480,000"], ["490000", "490,000"], ["500000", "500,000"]]); 



	addMultiRowTextCell(row1, "", 5, 15);
	addMultiRowTextCell(row1, "Premium Estimate is:", 5, 130);
	addMultiRowTextCell(row1, "", 5, 9);
	tabBody.appendChild(row1);
	
	// add the bedroom to the dropdown
	var row2 = document.createElement('tr');
	addTextCell(row2, "Bedrooms: ");
	addGenericDD(getNewCell(row2), ["AWKBED", "WKBED_C"], [["", "Please select"], ["01", "1"],["02", "2"],["03", "3"],["04", "4"],["05", "5"],["06", "6+"]]);
	tabBody.appendChild(row2);

	// add the Location row to the dropdown
	var row3 = document.createElement('tr');
	addTextCell(row3, "Location: ");
	addCountyDD(getNewCell(row3), ["ANILOCC", "NILOCC_C"]);
	tabBody.appendChild(row3);

	
	// add age row to the table
	var row4 = document.createElement('tr');
	addTextCell(row4, "Age: ");
	addGenericDD(getNewCell(row4), ["AWKAGER", "WKAGER_C"], [["", "Please select"], ["25", "25"], ["30", "30"], ["35", "35"], ["40", "40"], ["45", "45"], ["50", "50"], ["55", "55"], ["60", "60"], ["65", "65"],["70", "70"]]);
	tabBody.appendChild(row4);
	
	
	// add the contents text line
	var row5 = document.createElement('tr');
	addMultiColTextCell(row5, "* based on Contents value of GBP50,000", 2);
	tabBody.appendChild(row5);
	
}



// function to list all child objects in the motor div
function destroyEst() {
	if (EXISTS_EST) {
		while (document.getElementById('est_portletquoteTeaser').childNodes.length > 0) {
			traverseDomTree_recurse(document.getElementById('est_portletquoteTeaser'), 0);
		}
		document.getElementById('est_portletquoteTeaser').parentNode.removeChild(document.getElementById('est_portletquoteTeaser'));
		EXISTS_EST = false;
	}
}



//
// function to get an estimate
//
function getQuickEstimate(product) {
	if (call_mode == "MODE_AJAX") {
		switch (product) {
			case 'Motor':
				var ret = sendQEAjaxRequest('http://www.allianz.ie/CGI-BIN/lansaweb?procfun+MQQPROC+MQQFN07+'+partition+'+funcparms+WKSC(A0010):+WKGE(A0010):'+document.getElementById('AGENDC1').value+'+WKAG(S0030):'+document.getElementById('AQAGE1').value+'+WKAR(A0040):'+document.getElementById('AQCOUNTY1').value+'+WKGP(S0020):'+document.getElementById('AQCART1').value+'+WKNC(S0020):'+document.getElementById('AQNCB1').value, product);
				break;
			case 'Contents Only':
				var ret = sendQEAjaxRequest('http://www.allianz.ie/CGI-BIN/lansaweb?procfun+MQQPROC+MQQFN06+'+partition + '+funcparms+WKCOVC(A0030):CO+HRPROD(A0030):DHN+ASTRS(A0030):NI+WKSC(A0010):+LSBLSI(S0070):0+LSCTSI(S0070):'+document.getElementById('LSCTSI_C').value+'+NILOCC(A0040):'+document.getElementById('NILOCC_C').value+'+WKBED(A0020):'+document.getElementById('WKBED_C').value+'+WKADCR(A0030):'+document.getElementById('WKADCR_C').value+'+WKAGER(A0020):'+document.getElementById('WKAGER_C').value, product);
				break;
			case 'Buildings Only':
				var ret = sendQEAjaxRequest('http://www.allianz.ie/CGI-BIN/lansaweb?procfun+MQQPROC+MQQFN06+'+partition + '+funcparms+WKCOVC(A0030):BO+HRPROD(A0030):DHN+ASTRS(A0030):NI+WKSC(A0010):+LSBLSI(S0070):'+document.getElementById('LSBLSI_C').value+'+LSCTSI(S0070):0+NILOCC(A0040):'+document.getElementById('NILOCC_C').value+'+WKBED(A0020):'+document.getElementById('WKBED_C').value+'+WKADCR(A0030):NO+WKAGER(A0020):'+document.getElementById('WKAGER_C').value, product);
				break;
			case 'Buildings and Contents':
				var ret = sendQEAjaxRequest('http://www.allianz.ie/CGI-BIN/lansaweb?procfun+MQQPROC+MQQFN06+'+partition + '+funcparms+WKCOVC(A0030):BAC+HRPROD(A0030):DBN+ASTRS(A0030):NI+WKSC(A0010):+LSBLSI(S0070):'+document.getElementById('LSBLSI_C').value+'+LSCTSI(S0070):50000+NILOCC(A0040):'+document.getElementById('NILOCC_C').value+'+WKBED(A0020):'+document.getElementById('WKBED_C').value+'+WKADCR(A0030):YES+WKAGER(A0020):'+document.getElementById('WKAGER_C').value, product);
				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+MQQFN07+'+partition+'+funcparms+WKSC(A0010):S+WKGE(A0010):'+document.getElementById('AGENDC1').value+'+WKAG(S0030):'+document.getElementById('AQAGE1').value+'+WKAR(A0040):'+document.getElementById('AQCOUNTY1').value+'+WKGP(S0020):'+document.getElementById('AQCART1').value+'+WKNC(S0020):'+document.getElementById('AQNCB1').value+'+ACOC(A0100):ADN');
				} else {
					alert("Please answer all questions");
				}
				break;
			case 'Contents Only':
				if (document.getElementById('LSCTSI_C').value != 0 && document.getElementById('NILOCC_C').value != '' && document.getElementById('WKBED_C').value != 0 && document.getElementById('WKADCR_C').value != '' && document.getElementById('WKAGER_C').value != 0) {
					Redirect('/Estimators/?QE=MOT');
					var ret = window.open('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+MQQPROC+MQQFN06+'+partition + '+funcparms+WKCOVC(A0030):CO+HRPROD(A0030):DHN+ASTRS(A0030):NI+WKSC(A0010):S+LSBLSI(S0070):0+LSCTSI(S0070):'+document.getElementById('LSCTSI_C').value+'+NILOCC(A0040):'+document.getElementById('NILOCC_C').value+'+WKBED(A0020):'+document.getElementById('WKBED_C').value+'+WKADCR(A0030):'+document.getElementById('WKADCR_C').value+'+WKAGER(A0020):'+document.getElementById('WKAGER_C').value);
				} else {
					alert("Please answer all questions");
				}
				break;
			case 'Buildings Only':
				if (document.getElementById('LSBLSI_C').value != 0 && document.getElementById('NILOCC_C').value != '' && document.getElementById('WKBED_C').value != 0 && document.getElementById('WKAGER_C').value != 0) {
					Redirect('/Estimators/?QE=MOT');
					var ret = window.open('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+MQQPROC+MQQFN06+'+partition + '+funcparms+WKCOVC(A0030):BO+HRPROD(A0030):DHN+ASTRS(A0030):NI+WKSC(A0010):S+LSBLSI(S0070):'+document.getElementById('LSBLSI_C').value+'+LSCTSI(S0070):0+NILOCC(A0040):'+document.getElementById('NILOCC_C').value+'+WKBED(A0020):'+document.getElementById('WKBED_C').value+'+WKADCR(A0030):NO+WKAGER(A0020):'+document.getElementById('WKAGER_C').value);
				} else {
					alert("Please answer all questions");
				}
				break;
			case 'Buildings and Contents':
				if (document.getElementById('LSBLSI_C').value != 0 && document.getElementById('NILOCC_C').value != "" && document.getElementById('WKBED_C').value != 0 && document.getElementById('WKAGER_C').value != 0) {
					Redirect('/Estimators/?QE=MOT');
					var ret = window.open('https://www.allianz.ie/CGI-BIN/lansaweb?procfun+MQQPROC+MQQFN06+'+partition + '+funcparms+WKCOVC(A0030):BAC+HRPROD(A0030):DBN+ASTRS(A0030):NI+WKSC(A0010):S+LSBLSI(S0070):'+document.getElementById('LSBLSI_C').value+'+LSCTSI(S0070):50000+NILOCC(A0040):'+document.getElementById('NILOCC_C').value+'+WKBED(A0020):'+document.getElementById('WKBED_C').value+'+WKADCR(A0030):YES+WKAGER(A0020):'+document.getElementById('WKAGER_C').value);
				} else {
					alert("Please answer all questions");
				}
				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.appendChild(txt);
	cell.width = "149";
	cell.className = "est_tableCellText";
	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 cell of specified width
//
function addTextCellWidth(row, text, width) {
	var txt = document.createTextNode(text);
	var cell = document.createElement('td');
	cell.appendChild(txt);
	cell.width = width;
	cell.className = "est_tableCellText";
	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 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: &pound;" + 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) {  }
	}
}