
			/* <![CDATA[ */
			/* ~~~ Vodafone Namespace ~~~ */

			var VF = window.VF || {};
			
			VF.roaming = function() {
				// ### private variables and functions
				// create shortcut variables for YUI methods, etc.
				var Y = YAHOO.util,
					$D = Y.Dom,
					$E = Y.Event,
					$C = Y.Connect;
				// ### public variables and functions
				return {
					init : function() {
						this.newindex = 1;
						VF.roaming.getPlans();													// go get the list of all plans an populate 'select' options based on Prepay/On Account radio buttons
						VF.roaming.updateResult(); 												// update the results tab based on current information 
						$E.on(['radioPrepay','radioOnAccount'],'change',VF.roaming.getPlans);	// register listeners to update the plans 'select' option when the user chooses Prepay/On Account radio buttons
						$E.on('addcountry','click',VF.roaming.addCountry);						// register listener to create a new country 'select' element when 'add country' link clicked
					},
					tabChange : function(tabtochange) {
						if (tabtochange == 'tab4') {
							this.updateResult();	// updates result if user is switching to the results tab
						}
						showTab(tabtochange);		// reveals selected tab content and hides other tabs. See 'main.js' for functions.
					},
					getCountryInfo : function(country,traveller,accountValue,planValue) {
						var arrPlan = $D.get('selPlan').options;					// create array of all plan options
						var plan = '';
						for (var i=0;i<arrPlan.length;i++) {
							if (arrPlan[i].selected) plan = arrPlan[i].value;		// find selected plan option and write its value to variable 'plan'
						}
						var handleSuccess = function(o){
							if(o.responseText !== undefined){
								var resultTab = $D.get('theresults');					// create a reference to the results block on the results tab
								var result;
								//try {													// try and write the AJAX response to a new variable
									result = eval('('+o.responseText+')');				
								/*} catch(err) {											// if it fails, display the error in a new 'p' element in the results block, and also spit out the AJAX response for debugging (should remove this for production)
									result = o.responseText;
									var errorpara = document.createElement('p');
									var errorparatext = document.createTextNode('Sorry, there has been an error: '+err.name+'. <br>Message: '+err.message+'. <br>Response: '+result);
									errorpara.appendChild(errorparatext);
									resultTab.appendChild(errorpara);
								}*/
								
								if (traveller == true) {
									var hintSection = $D.get('links');
										clearNode(hintSection);	
									var newname = tidyname(result.name);
								
									// new country div
									var newCountryDiv = document.createElement('div');
										newCountryDiv.setAttribute('id', 'country'+newname);
										$D.addClass('country'+newname,'countryDiv');
										
									//new table div
									var newTableDiv = document.createElement('div');
										$D.addClass(newTableDiv, 'gen_table');
										newCountryDiv.appendChild(newTableDiv); // add TableDiv to Country Div
										
									// Create Table
									var table1 = document.createElement('table');
										newTableDiv.appendChild(table1);
									
									// Create table Header Section
									var newTableHead = document.createElement('thead');
									var newTableHeadRow = document.createElement('tr');
									var newTableHeadth = document.createElement('th');
										$D.addClass(newTableHeadRow, 'titlerow');
										newTableHeadth.setAttribute('colspan', '1');
										
									var intCodeTth = document.createElement('th');
										intCodeTth.setAttribute('colspan', '1');
										intCodeTth.appendChild(document.createTextNode('International Access Code: ' +result.networks[0].intlaccesscode));
										
									var emergencyTth = document.createElement('th');
										emergencyTth.setAttribute('colspan', '99');
										emergencyTth.appendChild(document.createTextNode('Emergency Number: ' +result.networks[0].emergency));
									



									newTableHead.appendChild(newTableHeadRow); //append Row to the Header
									newTableHeadRow.appendChild(newTableHeadth); //append the TH element to the Header Row
									newTableHeadRow.appendChild(intCodeTth); // append international codes to header
									newTableHeadRow.appendChild(emergencyTth);// append emergency to header
									newTableHeadth.appendChild(document.createTextNode(result.name)); //result.name = Country Name
									table1.appendChild(newTableHead); //append Header to Table
									
									var newTNetworkBody = document.createElement('tbody');
										table1.appendChild(newTNetworkBody); // add Body to Table

									// Create Title Row + Information
									var titleTRow = document.createElement('tr');
										$D.addClass(titleTRow, 'row_a');
										newTNetworkBody.appendChild(titleTRow);
										
									// Each TD and TH must be Seperate :(
									var networkName = document.createElement('th');
										$D.addClass(networkName, 'row-title');
										titleTRow.appendChild(networkName);
										networkName.appendChild(document.createTextNode('Network'));
									
									var titleTRowTh = document.createElement('th');
										$D.addClass(titleTRowTh, 'row-title');
										titleTRow.appendChild(titleTRowTh);
										titleTRowTh.appendChild(document.createTextNode('All Calls'));
										
									var titleRowTTh3 = document.createElement('th');
										$D.addClass(titleRowTTh3, 'row-title');
										titleTRow.appendChild(titleRowTTh3);
										titleRowTTh3.appendChild(document.createTextNode('Voicemail*'));
										
									var titleRowTTh4 = document.createElement('th');
										$D.addClass(titleRowTTh4, 'row-title');
										titleTRow.appendChild(titleRowTTh4);
										titleRowTTh4.appendChild(document.createTextNode('Customer Care Number'));
									
									var costTTotal = Number(result.planrate)+Number(result.zonerate);									
									// for each network start
									var networkcount = (result.networks.length < 3) ? result.networks.length : 3;
									for (var i=0;i<networkcount;i++) {
										// Create table Header Section

										// run addNetwork to append Each Network to the table
										VF.roaming.addTNetwork(result,newTNetworkBody,accountValue,i,traveller,costTTotal);
									}
									
									// Create Infomation Row
									var infoTRow = document.createElement('tr');
										$D.addClass(infoTRow, 'row_a');
										newTNetworkBody.appendChild(infoTRow);
										
									var serviceInputs = $D.getElementsByClassName('serviceCheck','input','serviceButtons');
									var arrServices = Array(0);
									for(var j=0;j<serviceInputs.length;j++) {
										if (serviceInputs[j].checked == true) {
											arrServices.push(serviceInputs[j].getAttribute('value'));
										}
									}
									for(var j=0;j<arrServices.length;j++) {
										if (arrServices[j].match('Data and PXT')) {
										var hintSection1 = $D.get('dataHint');
											clearNode(hintSection1);
											var UListData = document.createElement('ul');
											UListData.setAttribute('class', 'link_list3Col static');
											var DataItem = document.createElement('li');
											UListData.appendChild(DataItem);
											var DataAnc = document.createElement('a');
											DataItem.appendChild(DataAnc);
											DataAnc.setAttribute('class', 'btnPetrol');
											DataAnc.setAttribute('href', '/roaming/VFC8838_Online_Roaming.pdf');
											DataAnc.setAttribute('target', '_blank');
											DataAnc.appendChild(document.createTextNode('Save costs while roaming with Data'));
											hintSection1.appendChild(UListData);
										var DataTH = document.createElement('th');
											$D.addClass(DataTH, 'row-title');
											titleTRow.appendChild(DataTH);
											DataTH.appendChild(document.createTextNode('Data & PXT'));
										}
									}
									for(var j=0;j<arrServices.length;j++) {
										if (arrServices[j].match('Blackberry')) {
										var BBTH = document.createElement('th');
											$D.addClass(BBTH, 'row-title');
											titleTRow.appendChild(BBTH);
											BBTH.appendChild(document.createTextNode('Blackberry'));
										}
									}
									for(var j=0;j<arrServices.length;j++) {
										if (arrServices[j].match('Video Calling')) {
										var VCTH = document.createElement('th');
											$D.addClass(VCTH, 'row-title');
											titleTRow.appendChild(VCTH);
											VCTH.appendChild(document.createTextNode('Video Calls (to NZ)'));
										}
									}
									
									//Table Footer
									var Tfooter = document.createElement('div');	
										$D.addClass(Tfooter, 'tab_footer');
										newTableDiv.appendChild(Tfooter);
																		
									$D.addClass('ajaxloader','hidden');
									resultTab.appendChild(newCountryDiv);
								} else {
									var newname = tidyname(result.name);
								
									// new country div
									var newCountryDiv = document.createElement('div');
										newCountryDiv.setAttribute('id', 'country'+newname);
										$D.addClass('country'+newname,'countryDiv');
										
									//new table div
									var newTableDiv = document.createElement('div');
										$D.addClass(newTableDiv, 'gen_table');
										newCountryDiv.appendChild(newTableDiv); // add TableDiv to Country Div
										
									// Create Table
									var table1 = document.createElement('table');
										newTableDiv.appendChild(table1);
										
									//Table Footer
									var Tfooter = document.createElement('div');	
										$D.addClass(Tfooter, 'tab_footer');
										newTableDiv.appendChild(Tfooter);
										
									var newTableHead = document.createElement('thead');
									var newTableHeadRow = document.createElement('tr');
									var newTableHeadth = document.createElement('th');
										$D.addClass(newTableHeadRow, 'titlerow');
										newTableHeadth.setAttribute('colspan', '1');
										
									var intCodeth = document.createElement('th');
										intCodeth.setAttribute('colspan', '1');
										intCodeth.appendChild(document.createTextNode('International Access Code: ' +result.networks[0].intlaccesscode));
										
									var emergencyth = document.createElement('th');
										emergencyth.setAttribute('colspan', '99');
										emergencyth.appendChild(document.createTextNode('Emergency Number: ' +result.networks[0].emergency));
										
										
									newTableHead.appendChild(newTableHeadRow); //append Row to the Header
									newTableHeadRow.appendChild(newTableHeadth); //append the TH element to the Header Row
									newTableHeadRow.appendChild(intCodeth); // append international codes to header
									newTableHeadRow.appendChild(emergencyth);// append emergency to header
									newTableHeadth.appendChild(document.createTextNode(result.name)); //result.name = Country Name
									table1.appendChild(newTableHead); //append Header to Table
									
									var newTNetworkBody = document.createElement('tbody');
										table1.appendChild(newTNetworkBody); // add Body to Table
															
									// Create Title Row + Information
									var titleRow = document.createElement('tr');
										$D.addClass(titleRow, 'row_a');
										newTNetworkBody.appendChild(titleRow);
										
									// Each TD and TH must be Seperate :(
									var titleRowTh = document.createElement('th');
										$D.addClass(titleRowTh, 'row-title');
										titleRow.appendChild(titleRowTh);
										titleRowTh.appendChild(document.createTextNode('Network'));
										
									var titleRowTh1 = document.createElement('th');
										$D.addClass(titleRowTh1, 'row-title');
										titleRow.appendChild(titleRowTh1);
										titleRowTh1.appendChild(document.createTextNode('Calls to NZ'));
										
									var titleRowTh2 = document.createElement('th');
										$D.addClass(titleRowTh2, 'row-title');
										titleRow.appendChild(titleRowTh2);
										titleRowTh2.appendChild(document.createTextNode('Local Calls'));
										
									var titleRowTh3 = document.createElement('th');
										$D.addClass(titleRowTh3, 'row-title');
										titleRow.appendChild(titleRowTh3);
										titleRowTh3.appendChild(document.createTextNode('Voicemail*'));
										
									var titleRowTh4 = document.createElement('th');
										$D.addClass(titleRowTh4, 'row-title');
										titleRow.appendChild(titleRowTh4);
										titleRowTh4.appendChild(document.createTextNode('Customer Care Number'));

									var serviceInputs = $D.getElementsByClassName('serviceCheck','input','serviceButtons');
									var arrServices = Array(0);
									for(var j=0;j<serviceInputs.length;j++) {
										if (serviceInputs[j].checked == true) {
											arrServices.push(serviceInputs[j].getAttribute('value'));
										}
									}
									for(var j=0;j<arrServices.length;j++) {
										if (arrServices[j].match('Data and PXT')) {
										var titleRowTh5 = document.createElement('th');
											$D.addClass(titleRowTh5, 'row-title');
											titleRow.appendChild(titleRowTh5);
											titleRowTh5.appendChild(document.createTextNode('Data & PXT'));
											var dataHint = $D.get('dataHint');
											clearNode(dataHint);
											var UListData = document.createElement('ul');
											UListData.setAttribute('class', 'link_list3Col static');
											var DataItem = document.createElement('li');
											UListData.appendChild(DataItem);
											var DataAnc = document.createElement('a');
											DataItem.appendChild(DataAnc);
											DataAnc.setAttribute('class', 'btnPetrol');
											DataAnc.setAttribute('href', '/roaming/VFC8838_Online_Roaming.pdf');
											DataAnc.setAttribute('target', '_blank');
											DataAnc.appendChild(document.createTextNode('Save costs while roaming with data'));
											dataHint.appendChild(UListData);
										}
									}
									for(var j=0;j<arrServices.length;j++) {
										if (arrServices[j].match('Blackberry')) {
										var titleRowTh6 = document.createElement('th');
											$D.addClass(titleRowTh6, 'row-title');
											titleRow.appendChild(titleRowTh6);
											titleRowTh6.appendChild(document.createTextNode('Blackberry'));
										}
									}
									for(var j=0;j<arrServices.length;j++) {
										if (arrServices[j].match('Video Calling')) {
										var titleRowTh7 = document.createElement('th');
											$D.addClass(titleRowTh7, 'row-title');
											titleRow.appendChild(titleRowTh7);
											titleRowTh7.appendChild(document.createTextNode('Video Calls (to NZ)'));
										}
									}

									// add ajax loader and append to the div before load
									$D.addClass('ajaxloader','hidden');
									resultTab.appendChild(newCountryDiv); // add CountryDiv to Page
									
									// for each network start
									var networkcount = (result.networks.length < 3) ? result.networks.length : 3;
									for (var i=0;i<networkcount;i++) {
										// Create table Header Section
										
											


										// run addNetwork to append Each Network to the table
										VF.roaming.addNetwork(result,newTNetworkBody,accountValue,i,traveller);
									}
								}
							}
						}
						var handleFailure = function(o){
							if(o.responseText !== undefined){
								//do the error thing!
								div.innerHTML = "<!-- Transaction id: " + o.tId + "\n";
								div.innerHTML += "HTTP status: " + o.status + "\n";
								div.innerHTML += "Status code message: " + o.statusText + " -->";
							}
						}
						var callback = {
						  success: handleSuccess,
						  failure: handleFailure
						};
						var request = $C.asyncRequest('GET', '/roaming/assistant/getcountry.jsp?type=country&format=json&country='+country+'&plan='+plan, callback); 
					},
					getPlans : function() {
						var planDiv = $D.get('account');
						var chosenPlan = ($D.get('radioPrepay').checked ? 'prepay': 'onaccount');

						var handleSuccess = function(o){
							if(o.responseText !== undefined){
								var selPlan = $D.get('selPlan');
								var result = eval('('+o.responseText+')');
								var arrOptions = Array(0);
								for (var i=0;i<result.plans.length;i++) {
									var temp = document.createElement('option');
									temp.setAttribute('value', result.plans[i].selvalue);
									temp.appendChild(document.createTextNode(result.plans[i].name));
									arrOptions.push(temp);
								}
								clearNode(selPlan);
								for(var i=0;i<arrOptions.length;i++) {
									selPlan.appendChild(arrOptions[i]);
								}
								
								/* other no longer exists
								var othertemp = document.createElement('option');
								othertemp.setAttribute('value', 'other');
								othertemp.appendChild(document.createTextNode('Other'));
								selPlan.appendChild(othertemp);
								planDiv.style.visibility = 'visible';
								*/
								
							}
						}
						var handleFailure = function(o){
							if(o.responseText !== undefined){
								//do the error thing!
								div.innerHTML = "<!-- Transaction id: " + o.tId + "\n";
								div.innerHTML += "HTTP status: " + o.status + "\n";
								div.innerHTML += "Status code message: " + o.statusText + " -->";
							}
						}
						var callback = {success: handleSuccess, failure: handleFailure};
						var request = $C.asyncRequest('GET', '/roaming/assistant/getcountry.jsp?type=plans&format=json&accounttype='+chosenPlan, callback);
					},
					addCountry : function(e) {
						var countriesdiv = $D.get('countryselects'); 	// get
						newindex = newindex + 1;

						var newli = document.createElement('li');
						var newlabeldiv = document.createElement('div');
						var newlabel = document.createElement('label');
						var newlabeltext = document.createTextNode('Country');
						var newselect = $D.get('countryselects').getElementsByTagName('select')[0].cloneNode(true);
						var newremovebuttontext = document.createTextNode('Remove');
						var newremovebutton = document.createElement('a');
						
						newli.setAttribute('id', 'addedCountry' + newindex);
						
						$D.addClass(newlabeldiv,'formCopy');
						
						newlabel.setAttribute('for', 'selCountries' + newindex);

						newselect.setAttribute('id', 'selCountries' + newindex);
						newselect.setAttribute('name', 'selCountries' + newindex);
						$D.addClass(newselect, 'selCountry');

						$E.addListener(newremovebutton, 'click', VF.roaming.removeCountry); // add 'onclick' listener to remove this country if 'Remove' link clicked
						newremovebutton.setAttribute('href', '#');
						newremovebutton.setAttribute('id', 'removeCountry' + newindex);
						
						newlabeldiv.appendChild(newlabel);
						newlabel.appendChild(newlabeltext);
						newremovebutton.appendChild(newremovebuttontext);

						newli.appendChild(newlabeldiv);
						newli.appendChild(newselect);
						newli.appendChild(document.createTextNode(' '));
						newli.appendChild(newremovebutton);
				
						countriesdiv.appendChild(newli);
						$E.stopEvent(e);
					},
					removeCountry : function(e) {
						this.parentNode.parentNode.removeChild(this.parentNode);
						$E.stopEvent(e);
					},
					updateResult : function() {
						var resultTab = $D.get('theresults');
						clearNode(resultTab);
						var title = document.createElement('h3');
						title.appendChild(document.createTextNode('My Details'));
						resultTab.appendChild(title);
						
						// Get plan and publish to Results tab
						var planSelect = $D.get('selPlan');
						var planValue = planSelect.options[planSelect.selectedIndex].text;
						var newplan = document.createElement('p');
						newplan.appendChild(document.createTextNode('My plan: '+planValue));
						var accountValue = ($D.get('radioPrepay').checked ? 'Prepay': 'On Account');
						var newaccount = document.createElement('span');
						$D.addClass(newaccount, 'note');
						newaccount.appendChild(document.createTextNode(' ('+accountValue+')'));
						newplan.appendChild(newaccount);
						resultTab.appendChild(newplan);						
						
						// Get Traveller status and publish to Results tab						
						var hasTravellerChk = $D.get('chkTraveller');
						var traveller = false;
						if (hasTravellerChk != '') {
							var travellerStatus = document.createElement('p');
							if (hasTravellerChk.checked) {
								travellerStatus.appendChild(document.createTextNode('You have Vodafone Traveller'));	
								traveller = true;
							} else {
								travellerStatus.appendChild(document.createTextNode('You have Standard Roaming '));
								var spanNote = document.createElement('span');
								spanNote.setAttribute('class', 'note');
								var spanNoteA = document.createElement('a');
								spanNoteA.appendChild(document.createTextNode('How to get Vodafone Traveller'));
								spanNoteA.setAttribute('style', 'text-decoration:underline;');
								spanNoteA.setAttribute('href', '#');
								spanNoteA.setAttribute('onclick', 'kbitem_popup(\'4684\'); return false;');
								spanNote.appendChild(spanNoteA);
								travellerStatus.appendChild(spanNote);
							}
							resultTab.appendChild(travellerStatus);
						}
						
						/* Other no longer exists
						if (planValue == 'Other' && traveller == true) {
							var alertDiv = document.createElement('div');
							$D.addClass(alertDiv, 'alert');
							var alertP = document.createElement('p');
							alertDiv.appendChild(alertP);
							var alertStrong = document.createElement('strong');
							alertP.appendChild(alertStrong);
							alertStrong.appendChild(document.createTextNode('Your Plan is not compatible with Traveller'));
							var alertP1 = document.createElement('p');
							alertDiv.appendChild(alertP1);
							alertP1.setAttribute('style', 'margin:5px;');
							var alertA = document.createElement('a');
							alertA.setAttribute('href', '/traveller');
							alertA.setAttribute('style', 'text-decoration:underline;');
							alertP1.appendChild(alertA);
							alertA.appendChild(document.createTextNode('Please Upgrade'));
							alertP1.appendChild(document.createTextNode(' so you can take advantage of these great deals!'));
							resultTab.appendChild(alertDiv);	
						}
						*/
						
						//Get services
						var serviceInputs = $D.getElementsByClassName('serviceCheck','input','serviceButtons');
						var arrServices = Array(0);
						for(var i=0;i<serviceInputs.length;i++) {
							if (serviceInputs[i].checked == true) {
								arrServices.push(serviceInputs[i].getAttribute('value'));
							}
						}
						var servicesList = '';
						for(var i=0;i<arrServices.length;i++) {
							servicesList += arrServices[i];
							if(i<arrServices.length-1) servicesList += ', ';
						}
						var title = document.createElement('h3');
						title.appendChild(document.createTextNode('My Services'));
						var newservices = document.createElement('p');
						newservices.appendChild(document.createTextNode(servicesList));
						var mydestinations = document.createElement('h3');
						mydestinations.appendChild(document.createTextNode('My Destinations'));
						var gap = document.createElement('p');
						gap.appendChild(document.createTextNode(''));						
						resultTab.appendChild(mydestinations);
						resultTab.appendChild(gap);
						
						
						// ### Get chosen countries!
						var allCountrySels = $D.getElementsByClassName('selCountry');	// creates array of all country 'select' elements
						var arrCountries = Array(0);									// creates new array which we'll put all the chosen country name values into
						for(var i=0;i<allCountrySels.length;i++) {						// loop through all 'select' elements
							if(allCountrySels[i].value != '') {							// check if 'select' element has a selected option
								arrCountries.push(allCountrySels[i].value);				// if so, push the value into the new array
							}
						}

						if (arrCountries.length > 0) {											// check if there are any selected countries
							var ajaxloader = document.createElement('img');
							ajaxloader.setAttribute('id', 'ajaxloader');
							ajaxloader.setAttribute('src', 'http://www.vodafone.co.nz/images/icons/ajax-loader.gif');
							$D.get('theresults').appendChild(ajaxloader);

							for(var i=0;i<arrCountries.length;i++){								// for each selected country...
								var responsething = VF.roaming.getCountryInfo(arrCountries[i],traveller,accountValue,arrServices,planValue);	// ...do an AJAX look-up to retrieve desired data. See function 'getCountryInfo' above.
							}
						}
						
						var hintsDiv = $D.get('hints');
						clearNode(hintsDiv);
						
						if (accountValue == 'On Account'){
							var oaHint = document.createElement('p');
							oaHint.appendChild(document.createTextNode('Please note: If you have not roamed before, you need to call 777 to set up roaming; it is free to set up and only needs to be activated once. Roaming is subject to credit criteria and you must be the decision maker on the account.'))
							hintsDiv.appendChild(oaHint);
						} else {
							var ppHint = document.createElement('p');
							ppHint.appendChild(document.createTextNode('Please note: For a list of networks you can automatically roam with Prepay click here. If you are travelling to any other destination, you will need to set up creditRoam.'))
							hintsDiv.appendChild(ppHint);
						}
					},
					addNetwork : function(result,newTNetworkBody,accountValue,networkindex,arrServices,traveller,costTTotal) {
						
						// Create Information Row
						var infoRow = document.createElement('tr');
							$D.addClass(infoRow, 'row_a');
							newTNetworkBody.appendChild(infoRow);
							
						var networkCell = document.createElement('td');
							networkCell.setAttribute('width', '105');
							networkCell.appendChild(document.createTextNode(result.networks[networkindex].name));
							infoRow.appendChild(networkCell);
							
						// Test to see if user is Prepay or On Account
						var rate = '';
						for (var k=0;k<result.networks[networkindex].rates.length;k++) {
							if (accountValue == 'Prepay') {
								if (result.networks[networkindex].rates[k].name == 'Prepay') {
									rate = result.networks[networkindex].rates[k].callstonzpeak;
								} else {
									rate= result.networks[networkindex].rates[0].callstonzpeak;
								}
							} else if (accountValue == 'On Account'){
								if (result.networks[networkindex].rates[k].name == 'On Account') {
									rate = result.networks[networkindex].rates[k].callstonzpeak;
								} else {
									rate= result.networks[networkindex].rates[0].callstonzpeak;
								}
							} else {
								rate = result.networks[networkindex].rates[0].callstonzpeak;
							}
						}
						// Build Cell and only display the rate given the user's plan type choice
						var nzCallCell = document.createElement('td');
							nzCallCell.appendChild(document.createTextNode('$'+rate));
							infoRow.appendChild(nzCallCell);
							
						var localCallCell = document.createElement('td');
							localCallCell.appendChild(document.createTextNode('$'+result.networks[networkindex].rates[0].callsnationalpeak));
							infoRow.appendChild(localCallCell);


						var voicemailCell = document.createElement('td');
							// needs to be changed to voicemail number
							voicemailCell.appendChild(document.createTextNode(result.networks[networkindex].voicemail));
							infoRow.appendChild(voicemailCell);						
						
						var custCareCell = document.createElement('td');
							custCareCell.appendChild(document.createTextNode(result.networks[networkindex].customercare));
							infoRow.appendChild(custCareCell);							
							
						var serviceInputs = $D.getElementsByClassName('serviceCheck','input','serviceButtons');
						var arrServices = Array(0);
						for(var j=0;j<serviceInputs.length;j++) {
							if (serviceInputs[j].checked == true) {
								arrServices.push(serviceInputs[j].getAttribute('value'));
							}
						}
						for(var j=0;j<arrServices.length;j++) {
							if (arrServices[j].match('Data and PXT')) {
							var dataCell = document.createElement('td');
								dataCell.appendChild(document.createTextNode('$'+result.networks[networkindex].rates[0].msganddatagprsdata));
								infoRow.appendChild(dataCell);								
							}
						}
						for(var j=0;j<arrServices.length;j++) {
							if (arrServices[j].match('Blackberry')) {
							var bbCell = document.createElement('td');
								bbCell.appendChild(document.createTextNode('$'+result.networks[networkindex].rates[0].msganddatablackberryroaming));
								infoRow.appendChild(bbCell);
							}
						}
						for(var j=0;j<arrServices.length;j++) {
							if (arrServices[j].match('Video Calling')) {
							var videoCell = document.createElement('td');
								videoCell.appendChild(document.createTextNode('$'+result.networks[networkindex].rates[0].callstonzvideopeak));
								infoRow.appendChild(videoCell);
							}
						}
					},
					addTNetwork : function(result,newTNetworkBody,accountValue,networkindex,arrServices,traveller,costTTotal) {
						
						// Create Information Row
						var infoRow = document.createElement('tr');
							$D.addClass(infoRow, 'row_a');
							newTNetworkBody.appendChild(infoRow);
							
						var networkCell = document.createElement('td');
							networkCell.setAttribute('width', '105');
							networkCell.appendChild(document.createTextNode(result.networks[networkindex].name));
							infoRow.appendChild(networkCell);
							
						// Test to see if user is Prepay or On Account
						var rate = '';
						for (var k=0;k<result.networks[networkindex].rates.length;k++) {
							if (accountValue == 'Prepay') {
								if (result.networks[networkindex].rates[k].name == 'Prepay') {
									rate = result.networks[networkindex].rates[k].callstonzpeak;
								} else {
									rate= result.networks[networkindex].rates[0].callstonzpeak;
								}
							} else if (accountValue == 'On Account'){
								if (result.networks[networkindex].rates[k].name == 'On Account') {
									rate = result.networks[networkindex].rates[k].callstonzpeak;
								} else {
									rate= result.networks[networkindex].rates[0].callstonzpeak;
								}
							} else {
								rate = result.networks[networkindex].rates[0].callstonzpeak;
							}
						}
						var allCalls = Number(result.planrate)+Number(result.zonerate);
						function roundVal(val){
							var dec = 2;
							var result = Math.round(val*Math.pow(10,dec))/Math.pow(10,dec);
							return result;
						}
						// Build Cell and only display the rate given the user's plan type choice
						var nzCallCell = document.createElement('td');
							nzCallCell.appendChild(document.createTextNode('$'+roundVal(allCalls)));
							infoRow.appendChild(nzCallCell);
							
						var voicemailCell = document.createElement('td');
							// needs to be changed to voicemail number
							voicemailCell.appendChild(document.createTextNode(result.networks[networkindex].voicemail));
							infoRow.appendChild(voicemailCell);						
						
						var custCareCell = document.createElement('td');
							custCareCell.appendChild(document.createTextNode(result.networks[networkindex].customercare));
							infoRow.appendChild(custCareCell);							
							
						var serviceInputs = $D.getElementsByClassName('serviceCheck','input','serviceButtons');
						var arrServices = Array(0);
						for(var j=0;j<serviceInputs.length;j++) {
							if (serviceInputs[j].checked == true) {
								arrServices.push(serviceInputs[j].getAttribute('value'));
							}
						}
						for(var j=0;j<arrServices.length;j++) {
							if (arrServices[j].match('Data and PXT')) {
							var dataCell = document.createElement('td');
								dataCell.appendChild(document.createTextNode('$'+result.networks[networkindex].rates[0].msganddatagprsdata));
								infoRow.appendChild(dataCell);								
							}
						}
						for(var j=0;j<arrServices.length;j++) {
							if (arrServices[j].match('Blackberry')) {
							var bbCell = document.createElement('td');
								bbCell.appendChild(document.createTextNode('$'+result.networks[networkindex].rates[0].msganddatablackberryroaming));
								infoRow.appendChild(bbCell);
							}
						}
						for(var j=0;j<arrServices.length;j++) {
							if (arrServices[j].match('Video Calling')) {
							var videoCell = document.createElement('td');
								videoCell.appendChild(document.createTextNode('$'+result.networks[networkindex].rates[0].callstonzvideopeak));
								infoRow.appendChild(videoCell);
							}
						}
					}
				};
			}();

			function clearNode(node) {
				if (node && node.hasChildNodes && node.removeChild) {
					while (node.hasChildNodes()) {
						node.removeChild(node.firstChild);
					}
				}
			}
			
			function tidyname(string) {
				return string.toLowerCase().replace(/ /g,'');
			}

			YAHOO.util.Event.on(window, 'load', VF.roaming.init);	// initialises everything once the page has loaded.
			/* ]]> */
									
									
									
									
									
									
// jQuery Ajax for extended roaming countries

$j(document).ready(function(){
	// Prepare a select box
	$j.ajax({
		type: "GET",
		url: "/roaming/countries/roaming-data.xml",
		dataType: "xml",
		success: function(xml) {
			country_fixed = "";
			$j(xml).find("country").each(function(country_fixed){
			    var country_name = $j(this).attr("name");
				if ($j(this).find('sim').text() == "yes"){
					var country_fixed = country_name + ", ";
					$j("#er_countries").append(country_fixed);
				}
				$j("#selCountries1").append("<option value=\"" + country_name + "\">" + country_name + "</option>");	
			});
			var n = $j("#er_countries").text();
			var o = n.length;
			var m = n.substr(0, o-2);
			$j("#er_countries").empty();
			$j("#er_countries").append(country_fixed+m+".");
		}
	}); //close ajax
});
