var productids = new Array('businesscar', 'butchers', 'cafes', 'florists', 'hairbeauty', 'hotel', 'landlords', 'motortrade', 'office', 'pi', 'publicliability', 'shop', 'club', 'startups', 'van');
var productnames = new Array('Business Car', 'Butcher', 'Cafe', 'Florist', 'Hair &amp; Beauty', 'Hotel', 'Landlord', 'Motor Trade', 'Office', 'Professional Indemnity', 'Public Liability', 'Shop', 'Sports &amp; Social Club', 'Start Up', 'Van');
var currentproduct = '';

$(document).ready(function(){
	toggleClosedAllPhoneNumbers();
	hideContactBoxes();
	addChooser();
});

function hideContactBoxes() {
	for (var i = 1; i < productids.length; i++) {
		document.getElementById(productids[i]+'productblock').style.display = 'none';
	}
	currentproductid = productids[0];
}

function addChooser() {
	$str = '<label for="product"><img src="/i/contact_select_product.gif" alt="Select a product" width="119" height="17" /></label>';
	$str += '<form action="/<?php echo $page->url; ?>" method="get">';
	$str += '<div class="formcontentwrapper">';
	$str += '<select id="product" name="product" tabindex="<?php echo $tabindex++; ?>" onchange="showProduct(); return false;">';
	for (var i = 0; i < productids.length; i++) {
		$str += '<option value="'+productids[i]+'">'+productnames[i]+' Insurance</option>';
	}
	$str += '</select>';
	$str += '</div>';
	$str += '</form>';
	document.getElementById('chooser').innerHTML = $str;
	document.getElementById('chooser').style.display = 'block';
}

function showProduct() {
	toggleClosedPhoneNumbersForProduct(currentproductid);
	document.getElementById(currentproductid+'productblock').style.display = 'none';
	document.getElementById(document.getElementById('product').value+'productblock').style.display = 'block';
	currentproductid = document.getElementById('product').value;
	document.getElementById('product').blur(); // for Firefox
}

function toggleClosedAllPhoneNumbers() {
	for (var i = 0; i < productids.length; i++) {
		toggleClosedPhoneNumbersForProduct(productids[i]);
	}
}

function toggleClosedPhoneNumbersForProduct(productid) {
	document.getElementById(productid+'quotesalesnumber').style.display = 'none';
	document.getElementById(productid+'quotesalestype').style.backgroundImage = "url('/i/contactphoneclosed.gif')";
	document.getElementById(productid+'existinggeneralnumber').style.display = 'none';
	document.getElementById(productid+'existinggeneraltype').style.backgroundImage = "url('/i/contactphoneclosed.gif')";
	document.getElementById(productid+'claimsnumber').style.display = 'none';
	document.getElementById(productid+'claimstype').style.backgroundImage = "url('/i/contactphoneclosed.gif')";
	if (document.getElementById(productid+'breakdownnumber')) {
		document.getElementById(productid+'breakdownnumber').style.display = 'none';
		document.getElementById(productid+'breakdowntype').style.backgroundImage = "url('/i/contactphoneclosed.gif')";
	}
}

function togglePhoneNumberDisplay(id) {
	var numberElementID = id.replace('type', 'number');
	if (document.getElementById(numberElementID).style.display == 'none') {
		document.getElementById(numberElementID).style.display = 'block';
		document.getElementById(id).style.backgroundImage = "url('/i/contactphoneopen.gif')";
	} else {
		document.getElementById(numberElementID).style.display = 'none';
		document.getElementById(id).style.backgroundImage = "url('/i/contactphoneclosed.gif')";
	}
}

