// JavaScript Document

function giveNumber(iValue) {
var sValue = Math.round(iValue * 100) + "";
var sPart1 = sValue.substr(0, sValue.length-2);
var sPart2 = sValue.substr(sValue.length-2);
return (sPart1 == "" ? "0" : sPart1) + "." + (sPart2 == "0" ? "00" : sPart2);
}


function updatePrice(addno) {
var separator = '£';
var thisaddform = document.getElementById('buyit_'+addno); 

try { obj = thisaddform.choice1.options[thisaddform.choice1.options.selectedIndex].text;}
catch(e) { obj = null; }
if (obj == null) {
var choice1 = 'hello';
}
else {
var choice1 = thisaddform.choice1.options[thisaddform.choice1.options.selectedIndex].text;
// remove thousands comma seperator from drop down
choice1 = choice1.replace(',','');

}

try { obj = thisaddform.choice2.options[thisaddform.choice2.options.selectedIndex].text;}
catch(e) { obj = null; }
if (obj == null) {
var choice2 = 'hello';
}
else {
var choice2 = thisaddform.choice2.options[thisaddform.choice2.options.selectedIndex].text;
// remove thousands comma seperator from drop down
choice2 = choice2.replace(',','');
}

try { obj = thisaddform.choice3.options[thisaddform.choice3.options.selectedIndex].text;}
catch(e) { obj = null; }
if (obj == null) {
var choice3 = 'hello';
}
else {
var choice3 = thisaddform.choice3.options[thisaddform.choice3.options.selectedIndex].text;
// remove thousands comma seperator from drop down
choice3 = choice3.replace(',','');
}

var stringArray1 = choice1.split(separator);
if (stringArray1[1] == undefined ) { stringArray1[1] = 0 }
var stringArray2 = choice2.split(separator);
if (stringArray2[1] == undefined ) { stringArray2[1] = 0 }
var stringArray3 = choice3.split(separator);
if (stringArray3[1] == undefined ) { stringArray3[1] = 0 }

OrigPrice_1 = thisaddform.unitprice.value;

var CalcPrice = 0;
CalcPrice = (OrigPrice_1 * 1) + (stringArray1[1] *1) + (stringArray2[1] *1) + (stringArray3[1] *1);

try { obj = thisaddform.vat.options[thisaddform.vat.options.selectedIndex].text;}
catch(e) { obj = null; }
if (obj == null) {
var choice3 = 'hello';
}
else {
if (thisaddform.vat.options[thisaddform.vat.options.selectedIndex].text != 'Including VAT') {CalcPrice = CalcPrice / (1+(opsVATrate/100));}
}

document.getElementById('Words_'+addno).innerHTML = giveNumber(eval( CalcPrice ));
}
