function updatePopupTitles() {
if ($('sizeLink') != undefined && $('choice1').options[$('choice1').selectedIndex].text != undefined)
{$('sizeLink').title = 'Your chosen size: ' + $('choice1').options[$('choice1').selectedIndex].text;}

if ($('fabricLink') != undefined && $('choice2').options[$('choice2').selectedIndex].text != undefined)
{$('fabricLink').title = 'Your chosen fabric: ' + $('choice2').options[$('choice2').selectedIndex].text;}

if ($('woodLink') != undefined && $('choice3').options[$('choice3').selectedIndex].text != undefined)
{$('woodLink').title = 'Your chosen wood: ' + $('choice3').options[$('choice3').selectedIndex].text;}

if ($('studLink') != undefined && $('choice5').options[$('choice5').selectedIndex].text != undefined)
{$('studLink').title = 'Your chosen stud: ' + $('choice5').options[$('choice5').selectedIndex].text;}
}

function updateSize(){
$('size').src = '/images/upload/model_'+$('choice1').value+'_tb.jpg';
$('sizeLink').href = '/images/upload/model_'+$('choice1').value+'_1.jpg';
updatePopupTitles();
}

function updateFabric(){
$('fabric').src = '/images/upload/fabrics_'+$('choice2').value+'_1_1.jpg';
$('fabricLink').href = '/images/upload/fabrics_'+$('choice2').value+'_2_1.jpg';
updatePopupTitles();
}

function updateWood(){
$('wood').src = '/images/upload/woods_'+$('choice3').value+'_1_1.jpg';
$('woodLink').href = '/images/upload/woods_'+$('choice3').value+'_2_1.jpg';
updatePopupTitles();
}

function updateStud(){
$('stud').src = '/images/upload/studs_'+$('choice5').value+'_1_1.jpg';
$('studLink').href = '/images/upload/studs_'+$('choice5').value+'_2_1.jpg';
updatePopupTitles();
}

function quantityUp(){
if ($('pQuantity').innerHTML < $('maxquantity').value) {$('pQuantity').innerHTML = 0 + parseInt($('pQuantity').innerHTML) + 1};
}

function quantityDown(){
if ($('pQuantity').innerHTML > 1) {$('pQuantity').innerHTML = 0 + parseInt($('pQuantity').innerHTML) - 1};
}

function submitform(){
var errors=''
try { obj = $('choice2').options[$('choice2').options.selectedIndex].value;}
catch(e) { obj = null; }
if (obj == -1) {
errors+='- please select a fabric\n';
}
try { obj3 = $('choice3').options[$('choice3').options.selectedIndex].value;}
catch(e) { obj3 = null; }
if (obj3 == -1) {
errors+='- please select a wood';
}
if (errors) {
	
//alert('Sorry! To add to basket:\n'+errors);

var boxA = new MooPrompt('Sorry! To add to basket:', errors, {
buttons: 1,
width:300,
button1: 'Ok',
onButton1: function() {
window.status = 'You just clicked okay.';
}
});

}
else
{$('addtobasketform').submit();}
}


function submitfavourites(){
var errors=''
try { obj = $('choice2').options[$('choice2').options.selectedIndex].value;}
catch(e) { obj = null; }
if (obj == -1) {
errors+='- please select a fabric\n';
}
try { obj3 = $('choice3').options[$('choice3').options.selectedIndex].value;}
catch(e) { obj3 = null; }
if (obj3 == -1) {
errors+='- please select a wood';
}
if (errors) {
//alert('Sorry! To add to Favourites :\n'+errors)

var boxA = new MooPrompt('Sorry! To add to Favourites:', errors, {
buttons: 1,
width:300,
button1: 'Ok',
onButton1: function() {
window.status = 'You just clicked okay.';
}
});

;}
else
{
$('addtobasketform').action = "/favourites/add"; 
$('addtobasketform').submit();}
}


function submitprojects(){
var errors=''
try { obj = $('choice2').options[$('choice2').options.selectedIndex].value;}
catch(e) { obj = null; }
if (obj == -1) {
errors+='- please select a fabric\n';
}
try { obj3 = $('choice3').options[$('choice3').options.selectedIndex].value;}
catch(e) { obj3 = null; }
if (obj3 == -1) {
errors+='- please select a wood';
}
if (errors) {
//alert('Sorry! To add to Favourites :\n'+errors)

var boxA = new MooPrompt('Sorry! To add to Project:', errors, {
buttons: 1,
width:300,
button1: 'Ok',
onButton1: function() {
window.status = 'You just clicked okay.';
}
});

;}
else
{
$('addtobasketform').action = "/projects/add"; 
$('addtobasketform').submit();}
}



function r2(n) { 
ans = n * 1000 
ans = Math.round(ans /10) + "" 
while (ans.length < 3) {ans = "0" + ans} 
len = ans.length 
ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
return ans 
} 



function updatePrice(vatrate) {
try { obj = $('choice1').options.selectedIndex;}
catch(e) { obj = null; }
if (obj == null) {
model_price = 0
model_fabric_plain = 0
model_fabric_patterned = 0
model_fabric_leather = 0
model_wood_pqm = 0
model_dimensions = ''
model_fabricreq = ''
model_fabric_amount = 0
model_cushion_seats = 0
}
else {
var choice1 = $('choice1').options.selectedIndex+1;
model_price = model[choice1][2]
model_fabric_plain = model[choice1][3]
model_fabric_patterned = model[choice1][4]
model_fabric_leather = model[choice1][5]
model_wood_pqm = model[choice1][6]
model_dimensions = model[choice1][7]
model_fabricreq = model[choice1][8]
model_fabric_amount = model_fabric_plain
model_cushion_seats = model[choice1][9]
}
try { obj = $('choice2').options.selectedIndex;}
catch(e) { obj = null; }
if (obj == null) {
fabric_price = 0
fabric_type = 0
}
else {
var choice2 = $('choice2').options.selectedIndex+1;


if (choice2 == 3) { document.location = javarootpage+'/fabrics/filter/plain'; };
if (choice2 == 4) { document.location = javarootpage+'/fabrics/filter/patterned'; };
if (choice2 == 5) { document.location = javarootpage+'/fabrics/filter/leather'; };
if (choice2 == 6) { document.location = javarootpage+'/fabrics/filter/vinyl'; };
if (choice2 == 7) { document.location = javarootpage+'/fabrics/filter/velvet'; };
if (choice2 == 8) { document.location = javarootpage+'/fabrics/filter/weaves'; };



fabric_price = fabric[choice2][2]
fabric_type = fabric[choice2][3]


if (fabric_type == 'Patterned Fabric') { model_fabric_amount = model_fabric_patterned };
if (fabric_type == 'Leather') { model_fabric_amount = model_fabric_leather };
if (fabric_type == 'Velvet') { model_fabric_amount = model_fabric_patterned };

}
try { obj = $('choice3').options.selectedIndex;}
catch(e) { obj = null; }
if (obj == null) {
wood_price = 0
}
else {
var choice3 = $('choice3').options.selectedIndex+1;
wood_price = wood[choice3][2]
}
try { obj = $('choice4').options.selectedIndex;}
catch(e) { obj = null; }
if (obj == null) {
cushion_price = 0
}
else {
var choice4 = $('choice4').options.selectedIndex+1;
cushion_price = cushion[choice4][2]
}
var Quantity = $('pQuantity').innerHTML;
$('quantity').value = Quantity;
CalcPrice = (model_price *1) + (fabric_price * model_fabric_amount) + (wood_price * model_wood_pqm) + (cushion_price * model_cushion_seats);
if (Quantity == parseInt(Quantity)) { CalcPrice = CalcPrice * Quantity }
CalcPrice = CalcPrice * vatrate
$('pPrice').innerHTML = r2(eval( CalcPrice ));
$('pDim').innerHTML = model_dimensions;
$('fDim').innerHTML = model_fabricreq;
}
