function disablecol(obj,index){
  var temp;
  if(obj.value != "Plastic"){
   for(i=0; i<document.companyform.length; i++){
    temp = document.companyform.elements[i];
    if(temp.name == "dropcolour" + index)
     temp.disabled = true;
   }
  }
  if(obj.value == "Plastic"){
   for(i=0; i<document.companyform.length; i++){
    temp = document.companyform.elements[i];
    if(temp.name == "dropcolour" + index)
     temp.disabled = false;
   }
  }
}
function quote(){
 var temp = 0.00;
 var price = 0.00;
 var doc = document.companyform;
 checkminmax();
 var ls0 = new Array(5);
 ls0[0] = doc.req0label0.value;
 ls0[1] = doc.req0label0.value.length;
 ls0[2] = doc.req0size0.value;
 ls0[3] = doc.req0qty0.value;
 ls0[4] = doc.dropmaterial0.selectedIndex;
 var ls1 = new Array(5);
 ls1[0] = doc.req1label1.value;
 ls1[1] = doc.req1label1.value.length;
 ls1[2] = doc.req1size1.value;
 ls1[3] = doc.req1qty1.value;
 ls1[4] = doc.dropmaterial1.selectedIndex;
 var ls2 = new Array(5);
 ls2[0] = doc.req2label2.value;
 ls2[1] = doc.req2label2.value.length;
 ls2[2] = doc.req2size2.value;
 ls2[3] = doc.req2qty2.value;
 ls2[4] = doc.dropmaterial2.selectedIndex;
 var ls3 = new Array(5);
 ls3[0] = doc.req3label3.value;
 ls3[1] = doc.req3label3.value.length;
 ls3[2] = doc.req3size3.value;
 ls3[3] = doc.req3qty3.value;
 ls3[4] = doc.dropmaterial3.selectedIndex;
 var ls4 = new Array(5);
 ls4[0] = doc.req4label4.value;
 ls4[1] = doc.req4label4.value.length;
 ls4[2] = doc.req4size4.value;
 ls4[3] = doc.req4qty4.value;
 ls4[4] = doc.dropmaterial4.selectedIndex;
 var ls5 = new Array(5);
 ls5[0] = doc.req5label5.value;
 ls5[1] = doc.req5label5.value.length;
 ls5[2] = doc.req5size5.value;
 ls5[3] = doc.req5qty5.value;
 ls5[4] = doc.dropmaterial5.selectedIndex;
 var ls6 = new Array(5);
 ls6[0] = doc.req6label6.value;
 ls6[1] = doc.req6label6.value.length;
 ls6[2] = doc.req6size6.value;
 ls6[3] = doc.req6qty6.value;
 ls6[4] = doc.dropmaterial6.selectedIndex;
 var ls7 = new Array(5);
 ls7[0] = doc.req7label7.value;
 ls7[1] = doc.req7label7.value.length;
 ls7[2] = doc.req7size7.value;
 ls7[3] = doc.req7qty7.value;
 ls7[4] = doc.dropmaterial7.selectedIndex;
 var ls8 = new Array(5);
 ls8[0] = doc.req8label8.value;
 ls8[1] = doc.req8label8.value.length;
 ls8[2] = doc.req8size8.value;
 ls8[3] = doc.req8qty8.value;
 ls8[4] = doc.dropmaterial8.selectedIndex;
 var ls9 = new Array(5);
 ls9[0] = doc.req9label9.value;
 ls9[1] = doc.req9label9.value.length;
 ls9[2] = doc.req9size9.value;
 ls9[3] = doc.req9qty9.value;
 ls9[4] = doc.dropmaterial9.selectedIndex;
 var all = new Array(ls0,ls1,ls2,ls3,ls4,ls5,ls6,ls7,ls8,ls9);
 temp = Math.round(total(all)*100)/100;
 price = "$" + temp;
 price2 = "$" + (Math.round((temp * 1.1)*100)/100)
 document.companyform.PriceBox.value = price;
 document.companyform.PriceBox2.value = price2;
 
}
function total(list){
 var qdiscount = new Array(21);
 var plastic = 0;
 var aluminium = 1;
 var brass = 2;
 var steel = 3;
 qdiscount[0] = 0;
 qdiscount[1] = 1;
 qdiscount[2] = 1;
 qdiscount[3] = 0.85;
 qdiscount[4] = 0.80;
 for(i=5;i<10;i++){
  qdiscount[i] = 0.70;
 }
 for(i=10;i<15;i++){
  qdiscount[i] = 0.65;
 }
 for(i=15;i<20;i++){
  qdiscount[i] = 0.60;
 }
 qdiscount[20] = 0.50;
 var index = new Array(51);
 index[0] = 0;
 index[1] = 0;
 index[2] = 0.33;
 index[3] = 0.39;
 index[4] = 0.45;
 index[5] = 0.49;
 index[6] = 0.54;
 index[7] = 0.58;
 index[8] = 0.63;
 index[9] = 0.76;
 index[10] = 0.90;
 index[11] = 0.90;
 for(i=12;i<15;i++){
  index[i] = 0.99;
 }
 for(i=15;i<20;i++){
  index[i] = 1.14;
 }
 for(i=20;i<30;i++){
  index[i] = 1.27;
 }
 for(i=30;i<40;i++){
  index[i] = 1.50;
 }
 for(i=40;i<50;i++){
  index[i] = 1.68;
 }
 index[50] = 1.96;
 var temp = 0.00;
 var chars = 0;
 var size = 0;
 var tempstring = "";
 var qty = 0;
 var qd = 1;
 var material = plastic;
 for(i=0;i<10;i++){
  var multi = 1;
  if(list[i][0] != "*" && list[i][0] != "" && list[i][2] != "*" && list[i][2] != "" && list[i][3] != "*" && list[i][3] != ""){
   chars = list[i][1];
   size = list[i][2];
   qty = list[i][3];
   material = list[i][4];
   if(material == aluminium)
    multi = 2;
   if(material == brass)
    multi = 4;
   if(material == steel)
    multi = 5;
   if(qty > 20)
    qd = 20;
   else
    qd = qty;  
   temp = temp + qdiscount[qd]*(qty * (multi * (chars * index[size])));
  }
 }
 return temp;
}
function checkminmax(){
 for(j=0;j<document.companyform.length;j++){
  var temp = document.companyform.elements[j];
  if(temp.name.substring(4,8) == "size"){
   if(temp.value != '*' && temp.value != ''){
    if(temp.value < 2)
     temp.value = 2;
    if(temp.value > 50)
     temp.value = 50;
   }
  }
 }
}
function setdate(){
 var mydate=new Date();
 var year=mydate.getYear();
 if (year > 1000)
  year-=2000;
 if (year < 10)
  year="0"+year;
 var day=mydate.getDate();
 var month=mydate.getMonth()+1;
 document.companyform.req1datebox.value = day+"/"+month+"/"+year;
}
setdate(); 
function myreset(whichform){
 for (i=0;i<whichform.length;i++){
  var temp=whichform.elements[i];
  if(temp.name != "Submit Button" && temp.name != "Reset Button" && temp.name != "Quote Button"){
   if(temp.name.substring(0,4)!="drop") 
    temp.value=temp.defaultValue;
   else
    temp.options.selectedIndex=0;   
  }
 } 
 setdate();
 return false;
}
function resetlabels(){
 for (i=0;i<document.companyform.length;i++){
  var temp=document.companyform.elements[i];
  if(temp.name != "Submit Button" && temp.name != "Reset Button" && temp.name != "req0companybox" && temp.name != "req0contactbox" && temp.name != "req0telephonebox" && temp.name != "dropdelivery"){
   if(temp.name.substring(0,3) == "req" || temp.name.substring(0,4) == "drop"){
    if(temp.name.substring(0,4)!="drop") 
     temp.value=temp.defaultValue;
    else
     temp.options.selectedIndex=0;   
   }
  }
 } 
 setdate();
 return false;
}   
function checkrequired(which){
 quote();
 var pass=true;
 var chkfrm = new Array(10);
 for(i=0;i<10;i++){
  chkfrm[i] = false;
 }
 chkfrm[0] = true;
  for(i=0;i<which.length;i++){
  var tempobj=which.elements[i];
  for(j=1;j<10;j++){
   if((tempobj.name == "req" + j + "label" + j) && (tempobj.value != "*" && tempobj.value != ""))
    chkfrm[j] = true;
  }
 }
 for(i=0;i<which.length;i++){
  var tempobj=which.elements[i];
  for(j=0;j<10;j++){   
   if(chkfrm[j] == true && tempobj.name.substring(0,4) == "req" + j){
    if(((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=="")||((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='*')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
     pass=false;
     break;
    }
   }
  }
 } 
 if(!pass){
  alert("Boxes with an asterix and at least one label must be filled in.");
  return false;
 }
 else
  document.companyform.addressscroll.value = document.companyform.addressscroll.value + "~"
  document.companyform.commentsscroll.value = document.companyform.commentsscroll.value + "~"
  document.companyform.submit();
  alert("Form Submitted. Thankyou"); 
  return true;
}
