var bundleBuilderNational = new function() {
	var currentBundle = [0,1];
	var timeout;

	var bundleData = [
		[
			["REGISTRATION_DUAL_BB_M_PHONE_M","MM",0,2,10],
			["REGISTRATION_DUAL_BB_M_PHONE_L","ML",2.5,2,12.5],
			["REGISTRATION_DUAL_BB_M_PHONE_XL","MX",6,2,16]
		],
		[
			["REGISTRATION_DUAL_BB_L_PHONE_M","LM",0,2,14],
			["REGISTRATION_DUAL_BB_L_PHONE_L","LL",2.5,2,16.5],
			["REGISTRATION_DUAL_BB_L_PHONE_XL","LX",6,2,20]
		],
		[
			["REGISTRATION_DUAL_BB_XL_PHONE_M","XM",0,2,20],
			["REGISTRATION_DUAL_BB_XL_PHONE_L","XL",2.50,2,22.5],
			["REGISTRATION_DUAL_BB_XL_PHONE_XL","XX",6,2,26]
		]
	];

	var services = new Array();
		services['Broadband'] = 0;
		services['Phone']     = 1;

	var serviceLevels = [
		[
			['M',  '../broadband/solusM.html', '10GB monthly downloads'],
			['L',  '../broadband/solusL.html', '40GB monthly downloads'],
			['XL', '../broadband/solusXL.html', 'Unlimited monthly downloads']
		],
		[
			['M',  '../bbandphone/phone.html', 'Unlimited weekend UK landline calls'],
			['L',  '../bbandphone/phone.html', 'Unlimited evening and weekend UK landline calls'],
			['XL', '../bbandphone/phone.html', 'Unlimited anytime UK landline calls']
		]
	];

    return {
		/* Function to update the display of the current Bundle */
		displayBundle: function() {
			var dynamicString = "";
			var price  = "";

			document.getElementById('pricing-section').innerHTML = dynamicString;
			
			for(var service in services) {
				for(var option=0; option<document.forms['builderNational'][service].length; option++) {
					if(document.forms['builderNational'][service][option].checked) {
						currentBundle[services[service]] = option;
					}
				}
			}
			
			price = '&pound;' + (bundleData[currentBundle[0]][currentBundle[1]][2]);
			if(price.match(/\.\d$/)) { price += "0"; }			

			dynamicString += '<div id="what-you-pay"><h2>You pay</h2></div>\n';
			dynamicString += '<div id="pricing-info">\n';
			if(price != '&pound;'+0) {
			//alert(price);
				dynamicString += '<p class="price">' + price + ' a month*</p>\n';								
			}else {
				dynamicString += '<p class="price">FREE*</p>\n';
			}
			
			if(bundleData[currentBundle[0]][currentBundle[1]].length > 3) {
				dynamicString += '<p>for the first ' + bundleData[currentBundle[0]][currentBundle[1]][3] + ' months,<br />\n';
				price = '&pound;' + (bundleData[currentBundle[0]][currentBundle[1]][4]);
				if(price.match(/\.\d$/)) { price += "0"; }
				
				dynamicString += 'from <em>' + price + '</em> a month after that.<br />\n';
			}
			dynamicString += '12 month contract</p>\n';
			dynamicString += '</div>\n';
			dynamicString += '<div id="call-to-action" class="upgrade">\n';
			dynamicString += '<form action="https://national.virginmedia.com/myservices/register" method="post">\n';
			dynamicString += '<ul class="button"><li><strong>\n';
			dynamicString += '<input name="next.x" type="submit" value="Order now" />\n';
			dynamicString += '</strong></li></ul>\n';
			dynamicString += '<input name="scenario" type="hidden" value="' + bundleData[currentBundle[0]][currentBundle[1]][0] + '" />\n';
			dynamicString += '<input id="postcode" name="postcode" type="hidden" />\n';
			dynamicString += '</form>\n';
			dynamicString += '</div>\n';

			document.getElementById('pricing-section').innerHTML = dynamicString;
		},

        InsertNationalBundleBuilder: function() {
			document.write('<div class="national-builder" id="national-builder">\n');
			document.write('<div class="national-builder-header" id="national-builder-header"></div>\n');
			document.write('<div class="national-builder-content" id="national-builder-content">\n');
			document.write('<div class="national-builder-innercontent" id="national-builder-innercontent">\n');
			document.write('<div class="column-tops"/></div>\n');
			document.write('<div class="columns">\n');
			document.write('<div class="products">\n');
			document.write('<form name="builderNational">\n');
			
			for(service in services) {
				document.write('<div class="product-section" id="product-section' + services[service] + '">\n');
				// ### Icons for Services are included here you may want to update the directory ### //
				document.write('<img src="../images/bundlebuilder/icon-' + service.toLowerCase() + '.gif" /><h2>' + service + '</h2>\n');
				for(var productRef=0 ;productRef<serviceLevels[services[service]].length; productRef++) {
					var checked = "";
					
					//alert('current bundle' + currentBundle[services[service]] +  ' product ref' + productRef);
					
					//if(currentBundle[services[service]] == productRef) {
					if(productRef == 0) {
						checked = ' checked="checked"';
					}
				
					document.write('<div class="product-option" id="product-option-' + services[service] + '-' + productRef + '">\n');
					document.write('<h3><label for="' + service + '-Size-' + serviceLevels[services[service]][productRef][0] + '">Size ' + serviceLevels[services[service]][productRef][0] + '</label></h3>\n');
					document.write('<div class="control"><input type="radio" name="' + service + '" value="' + serviceLevels[services[service]][productRef][0] + '" id="' + service + '-Size-' + serviceLevels[services[service]][productRef][0] + '" onclick="bundleBuilderNational.displayBundle();" ' + checked + '/></div>\n');
					document.write('<p>' + serviceLevels[services[service]][productRef][2] + '</p>\n');
					document.write('<p><a href="' + serviceLevels[services[service]][productRef][1] + '" title="View details of ' + service + ' Size ' + serviceLevels[services[service]][productRef][0] + '" onclick="_hbLink(\'' + service + '+Size+' + serviceLevels[services[service]][productRef][0] + '\');">' + service + ' ' + serviceLevels[services[service]][productRef][0] + ' &gt;</a></p>\n');
					document.write('</div>\n');
				}
				document.write('</div>\n');
			}
			document.write('</form>\n');
			document.write('</div>\n');
			document.write('</div>\n');
			document.write('<div class="column-bottoms"></div>\n');
			document.write('<div class="pricing-section" id="pricing-section">\n');
			document.write('</div>\n');
			document.write('<p>*When you take a Virgin phone line for &pound;11.99 a month</p>\n');
			document.write('</div>\n');
			document.write('<div class="national-builder-footer" id="national-builder-footer"></div>\n');
			document.write('</div>\n');

			bundleBuilderNational.displayBundle();
		}
    };
}
