
//////////////////////////////////////////////////////
//    Copyright London Electronics Ltd 2008    //
//           Script by Graham Laming               //
/////////////////////////////////////////////////////

function testSelect (form) {


/////////////////////////////////////////////////////////////////////////
// Main model

    Item1 = form.model.selectedIndex;
    Result1 = form.model.options[Item1].text;
    Amount1 = parseFloat(form.model.options[Item1].value);

if (Item1>=1){basePrice=1380;}
else {basePrice=0;}

// Descriptions for basic unit + slot 1
if (Item1==0){BaseDescription=("Not chosen");}
else if (Item1==1){BaseDescription=("KD7 with single ModBus port");}
else if (Item1==2){BaseDescription=("KD7 with 6 universal analog inputs in slot 1");}
else if (Item1==3){BaseDescription=("KD7 with 6 x 0-10V inputs in slot 1");}
else if (Item1==4){BaseDescription=("KD7 with 6 x 0-20mA inputs in slot 1");}
else if (Item1==5){BaseDescription=("KD7 with 6 x 4-20mA inputs in slot 1");}
else if (Item1==6){BaseDescription=("KD7 with 3 x 0-10V and 3 x 0-20mA inputs in slot 1");}
else if (Item1==7){BaseDescription=("KD7 with 3 x 0-10V and 3 x 4-20mA inputs in slot 1");}
else if (Item1==8){BaseDescription=("KD7 with 3 x universal analog inputs in slot 1");}
else{BaseDescription=("");}

/////////////////////////////////////////////////////////////////////////
// Slot2
    Item2 = form.slot2.selectedIndex;
    Result2 = form.slot2.options[Item2].text;
    Amount2 = parseFloat(form.slot2.options[Item2].value);

//Descriptions for slot2

if (Item2==0){Slot2Description=("Not chosen");}
else if (Item2==1){Slot2Description=("6 universal analog inputs in slot 2");}
else if (Item2==2){Slot2Description=("6 x 0-10V inputs in slot 2");}
else if (Item2==3){Slot2Description=("6 x 0-20mA inputs in slot 2");}
else if (Item2==4){Slot2Description=("6 x 4-20mA inputs in slot 2");}
else if (Item2==5){Slot2Description=("3 x 0-10V and 3 x 0-20mA inputs in slot 2");}
else if (Item2==6){Slot2Description=("3 x 0-10V and 3 x 4-20mA inputs in slot 2");}
else if (Item2==7){Slot2Description=("3 x universal analog inputs in slot 2");}
else{Slot2Description=("");}

/////////////////////////////////////////////////////////////////////////
// Interface
    Item3 = form.interface.selectedIndex;
    Result3 = form.interface.options[Item3].text;
    Amount3 = parseFloat(form.interface.options[Item3].value);

if (Item3==0){InterfaceDescription=("Not chosen");}
else if (Item3==1){InterfaceDescription=("RS485 Modbus comms");}
else{InterfaceDescription=("");}


/////////////////////////////////////////////////////////////////////////
// Slot3
    Item4 = form.slot3.selectedIndex;
    Result4 = form.slot3.options[Item4].text;
    Amount4 = parseFloat(form.slot3.options[Item4].value);

if (Item4==0){Slot3Description=("Not chosen");}
else if (Item4==1){Slot3Description=("8 N.O relays + 8 x OptoMos in slot 3");}
else if (Item4==2){Slot3Description=("8 N.C relays + 8 x OptoMos in slot 3");}
else if (Item4==3){Slot3Description=("8 dig. I/P + 4 O/P 0-5mA in slot 3");}
else if (Item4==4){Slot3Description=("8 dig. I/P + 4 O/P 0-20mA in slot 3");}
else if (Item4==5){Slot3Description=("8 dig. I/P + 4 O/P 4-20mA in slot 3");}
else if (Item4==6){Slot3Description=("8 dig. I/P + 4 O/P 0-5V in slot 3");}
else if (Item4==7){Slot3Description=("8 dig. I/P + 4 O/P 0-10V in slot 3");}
else{Slot3Description=("");}


/////////////////////////////////////////////////////////////////////////
// Slot4
    Item5 = form.slot4.selectedIndex;
    Result5 = form.slot4.options[Item5].text;
    Amount5 = parseFloat(form.slot4.options[Item5].value);

if (Item5==0){Slot4Description=("Not chosen");}
else if (Item5==1){Slot4Description=("8 N.O relays + 8 x OptoMos in slot 4");}
else if (Item5==2){Slot4Description=("8 N.C relays + 8 x OptoMos in slot 4");}
else if (Item5==3){Slot4Description=("8 dig. I/P + 4 O/P 0-5mA in slot 4");}
else if (Item5==4){Slot4Description=("8 dig. I/P + 4 O/P 0-20mA in slot 4");}
else if (Item5==5){Slot4Description=("8 dig. I/P + 4 O/P 4-20mA in slot 4");}
else if (Item5==6){Slot4Description=("8 dig. I/P + 4 O/P 0-5V in slot 4");}
else if (Item5==7){Slot4Description=("8 dig. I/P + 4 O/P 0-10V in slot 4");}
else{Slot4Description=("");}

/////////////////////////////////////////////////////////////////////////
// Userinterface
    Item6 = form.userinterface.selectedIndex;
    Result6 = form.userinterface.options[Item6].text;
    Amount6 = parseFloat(form.userinterface.options[Item6].value);

if (Item6==0){UserInterfaceDescription=("USB User Interface");}
else if (Item6==1){UserInterfaceDescription=("USB, TCPIP, RS485x2 User Interfaces");}
else if (Item6==2){UserInterfaceDescription=("USB, TCPIP, RS232 User Interfaces");}
else{UserInterfaceDescription=("");}

/////////////////////////////////////////////////////////////////////////
// FlashMemory
    Item7 = form.flashmemory.selectedIndex;
    Result7 = form.flashmemory.options[Item7].text;
    Amount7 = parseFloat(form.flashmemory.options[Item7].value);

if (Item7==0){FlashMemoryDescription=("4GB Flash card");}
else if (Item7==1){FlashMemoryDescription=("4GB Flash card");}
else if (Item7==2){FlashMemoryDescription=("4GB Flash card");}
else if (Item7==6){FlashMemoryDescription=("4GB Flash card");}
else{FlashMemoryDescription=("");}

/////////////////////////////////////////////////////////////////////////
// Power
    Item8 = form.power.selectedIndex;
    Result8 = form.power.options[Item8].text;
    Amount8 = parseFloat(form.power.options[Item8].value);

if (Item8==0){PowerDescription=("90-253 V AC");}
else if (Item8==1){PowerDescription=("18-30 V DC");}
else{PowerDescription=("");}

/////////////////////////////////////////////////////////////////////////
// Mathfunctions
    Item9 = form.mathfunctions.selectedIndex;
    Result9 = form.mathfunctions.options[Item9].text;
    Amount9 = parseFloat(form.mathfunctions.options[Item9].value);


if (Item9==0){MathsDescription=("No maths functions installed");}
else if (Item9==1){MathsDescription=("Inter-channel maths functions installed");}
else{MathsDescription=("");}

/////////////////////////////////////////////////////////////////////////
// PC Software
    Item10 = form.pcsoftware.selectedIndex;
    Result10 = form.pcsoftware.options[Item10].text;
    Amount10 = parseFloat(form.pcsoftware.options[Item10].value);

if (Item10==0){SoftwareDescription=("KD7 connect, KD7 check");}
else if (Item10==1){SoftwareDescription=("KD7 connect, KD7 setup, KD7 check, KD7 archive");}
else{SoftwareDescription=("");}

/////////////////////////////////////////////////////////////////////////
// Acceptance
    Item11 = form.acceptance.selectedIndex;
    Result11 = form.acceptance.options[Item11].text;
    Amount11 = parseFloat(form.acceptance.options[Item11].value);

if (Item11==0){TestingDescription=("Standard CofC");}
else if (Item11==1){TestingDescription=("Extra QA Cert");}
else if (Item11==2){TestingDescription=("To order");}
else{TestingDescription=("");}

/////////////////////////////////////////////////////////////////////////
// Currency Conversion
    Item70 = form.currency.selectedIndex;
    Result70 = form.currency.options[Item70].text;
    Amount70 = parseFloat(form.currency.options[Item70].value);
    currencyConversion=Amount70;
    currency=Result70;


    
// Calculate total price in Pounds

// Markup of pounds value from Euros value
var markup=0.82236;

    totalprice=Amount1+Amount2+Amount3+Amount4+Amount5+Amount6+Amount7+Amount9+Amount10+Amount11;

// Convert to chosen currency and round up to nearst whole unit
    TotalLocalCurrency=markup*((basePrice+totalprice)*currencyConversion);
var TotalLocalCurrency = Math.round(TotalLocalCurrency * 100)/100;


// Discount
     DiscountAmt = 0
     Discounted=(100-DiscountAmt)*TotalLocalCurrency/100;


// Quantities and totals
     Quantity = form.qty.value;
     PriceTimesQty=Quantity*Discounted;
var PriceTimesQty = Math.round(PriceTimesQty * 100) / 100;

Fullmodel=("KD7-"+Result1+"-"+Result2+Result3+Result4+Result5+Result6+Result7+Result8+Result9+Result10+Result11+"");
listprice=(currency+TotalLocalCurrency+"  each");
statediscount=(DiscountAmt+" % Discount");
Discounted=(currency+Discounted+ " each");
Finalprice=(currency+PriceTimesQty+"");


//////////////////////////////////////////////////////////////////////////////

// MRP number is made as follows. 
// Concantenate the index of each selected object to make a base 11 number. 
// Use low index (short choice) options for the MSB end to limit size of concantenated number. 
// Convert to base 31. 
// Pad to 8 characters, force a K to the left character. 
// Make all upper case
// Split in 2 and add a - separator. This gives 0-uuuuuuu (base 31) options
// Prevent obscenities by eliminating vowels ...
// To do this,  we remove vowels and replace by the unused letters v,w,x,y and z
// a->v, e->w, i->x, o->y, u->z


Base10composite=(""+Item9+Item8+Item11+Item10+Item7+Item6+Item5+Item4+Item3+Item2+Item1+"");
number=parseFloat(Base10composite);
MRP= (number.toString(30));


//////////  Pad to MRP Format

MRPbasiclength=(MRP.length);
if (MRPbasiclength==1)
{MRPnew=("K000000"+MRP);}
else if (MRPbasiclength==2)
{MRPnew=("K00000"+MRP);}
else if (MRPbasiclength==3)
{MRPnew=("K0000"+MRP);}
else if (MRPbasiclength==4)
{MRPnew=("K000"+MRP);}
else if (MRPbasiclength==5)
{MRPnew=("K00"+MRP);}
else if (MRPbasiclength==6)
{MRPnew=("K0"+MRP);}
else if (MRPbasiclength==7)
{MRPnew=("K"+MRP);}
else MRPnew=MRPnew;

//Make upper case
var MRPupper = MRPnew.toUpperCase();

// Divide the 8 char MRP in 2 halves and insert a - separator
var MRPleft = MRPupper.substring(0,4);
var MRPright = MRPupper.substring(4,8);
MRPfinal=(MRPleft+"-"+MRPright);



// Now get rid of any vowels, by substituting for v,w,x,y,or z

// Change any A to a V
var str = MRPfinal;
var newstr = str.replace("A", "V", "gi");
MRPfinal=newstr;

// Change any E to a W
var str = MRPfinal;
var newstr = str.replace("E", "W", "gi");
MRPfinal=newstr;

// Change any I to a X
var str = MRPfinal;
var newstr = str.replace("I", "X", "gi");
MRPfinal=newstr;

// Change any O to a Y
var str = MRPfinal;
var newstr = str.replace("O", "Y", "gi");
MRPfinal=newstr;

// Change any U to a Z
var str = MRPfinal;
var newstr = str.replace("U", "Z", "gi");
MRPfinal=newstr;


/////////////////////////////////////////////////////////////////////////////////////////
// Only write discount data if discount exists

if (DiscountAmt!=0){var Discounted=(Discounted+" each, discounted");}
else{var Discounted=" ";}

if (DiscountAmt!=0){var statediscount=("Less "+DiscountAmt+" % discount");}
else{var statediscount=" ";}

////////////////////////////////////////////////////////////////////////////////////////

// Print results to table in page

/*
document.getElementById('MRP_result').innerHTML = MRPfinal;
*/
document.getElementById('Quant_result').innerHTML = Quantity;

document.getElementById('Model_complete').innerHTML = Fullmodel;

document.getElementById('Base_result').innerHTML = BaseDescription;
document.getElementById('Slot2_result').innerHTML = Slot2Description;
document.getElementById('Interface_result').innerHTML = InterfaceDescription;
document.getElementById('Slot3_result').innerHTML = Slot3Description;
document.getElementById('Slot4_result').innerHTML = Slot4Description;
document.getElementById('UserInterface_result').innerHTML = UserInterfaceDescription;
document.getElementById('Powersupply_result').innerHTML = PowerDescription;
document.getElementById('Maths_result').innerHTML = MathsDescription;
document.getElementById('Memory_result').innerHTML = FlashMemoryDescription;
document.getElementById('Software_result').innerHTML = SoftwareDescription;
document.getElementById('Certs_result').innerHTML = TestingDescription;
document.getElementById('list_price_result').innerHTML = listprice;
document.getElementById('discount_amt_result').innerHTML = statediscount;
document.getElementById('discounted_amt_result').innerHTML = Discounted;
document.getElementById('total_result').innerHTML = Finalprice;
}