
style.type = 'text/css';
    if (style.styleSheet){
         style.styleSheet.cssText = css;
     } else {
         style.appendChild(document.createTextNode(css));
     }
head.appendChild(style);


//---------------------------------------------------------



function isInArray(value, array) {
       return array.indexOf(value) > -1;
}
    
    function handle2(txt,e){
        if(e.keyCode === 13){
           calclat2(txt);
        }
        return false;
    }
    
    function calclat2(txt){
	if (totalelements>0) {
	    for(var strt=0; strt<totalelements; strt++){
		if (document.getElementById("qtyss"+strt) && document.getElementById("qty"+strt)) {
		     document.getElementById("qtyss"+strt).value = document.getElementById("qty"+strt).value;
		} else if (document.getElementById("qtyssx"+strt) && document.getElementById("qtyn"+strt)) {
		     document.getElementById("qtyssx"+strt).value = document.getElementById("qtyn"+strt).value;
		     //alert(document.getElementById("qty"+strt).value);
		}
		   
	    }
	    calclat(txt);
	}
    }

    
    function handle(txt,e){
        if(e.keyCode === 13){
           calclat(txt);
        }
        return false;
    }
    
    function calclat(txt){
         var getent = txt.value;
       
         if (parseFloat(getent) > 0) {
            //value is OK
         }else{
            txt.value = "0";
         }
         
         if (totalelements>0) {
           document.quotegen.qgb11.value = totalelements;
           var pr = new Array;
           var qtty = new Array;
	   var qtty2 = new Array;
           var amt = new Array;
	   var amt2 = new Array;
           var subtotal = 0;
           var qty_disc = new Array;
           
           var dss1 = new Array;
           var dss2 = new Array;
           var dss3 = new Array;
           var dss4 = new Array;
           var dss5 = new Array;
           var dss6 = new Array;
           var dss7 = new Array;
           var dss8 = new Array;
           var dss9 = new Array;
	   
	   var dss10 = new Array;
	   var dss11 = new Array;
           var dss12 = new Array;
           var dss13 = new Array;
           var dss14 = new Array;
           var dss15 = new Array;
	   
	   var dss21 = new Array;
           var dss22 = new Array;
           var dss23 = new Array;
           var dss24 = new Array;
           var dss25 = new Array;
           var dss26 = new Array;
           var dss27 = new Array;
           var dss28 = new Array;
           var dss29 = new Array;
	   
	   var dss30 = new Array;
	   var dss31 = new Array;
           var dss32 = new Array;
           var dss33 = new Array;
           var dss34 = new Array;
           var dss35 = new Array;
	   
	   var ord_disc = document.quotegen.disord.value;
           var prs_disc = document.quotegen.disprs.value;
	   var min_order = document.quotegen.minord.value;

           var nods ='';
	   var nods2 ='';
           var multyplier = 0;
	   var qty_multyplier = 0;
	   var total_qty=0;
	   var res_prs = 0;
	   var qttya=0; var qttyb=0; var qttyc=0;
	   var tot_in_form=0;
	   var formula_val = new Array;
	   var calc_formula='';
	   
	   
           for(var strt=0; strt<totalelements; strt++){
	    
               pr[strt] = eval("document.quotegen.price"+strt+".value");
               qtty[strt] = eval("document.quotegen.qty"+strt+".value");
	       qtty2[strt] = 0;
	       
	       if (document.getElementById("f40f"+strt)) {
		   tot_in_form = document.getElementById("f40f"+strt).value;
		   calc_formula= document.getElementById("f40v"+strt).value;
		   for(var stps=0; stps<parseInt(tot_in_form); stps++){
		      if (document.getElementById("qtyx"+strt+"_"+stps)) {
			  document.getElementById("qtyxx"+strt+"_"+stps).value = document.getElementById("qtyx"+strt+"_"+stps).value;
			  formula_val[stps] = document.getElementById("qtyx"+strt+"_"+stps).value;
			  pr[strt]=0;
			  qtty[strt] = 0;
		      }
		   }
		   
		   
	       }
	       
	       if (document.getElementById("qtyss"+strt)) {
		   qtty[strt] = document.getElementById("qtyss"+strt).value;
		   document.getElementById("qty"+strt).value = qtty[strt];
		   //nods = "document.quotegen.qty"+strt+".value = qtty[strt];";
                   //eval(nods);
	       }
	       if (document.getElementById("qtyssx"+strt)) {
		   qtty2[strt] = document.getElementById("qtyssx"+strt).value;
		   document.getElementById("qtyn"+strt).value = qtty2[strt];
	       }
	       
	       if (document.getElementById("qtyssa"+strt)) {
		   qtty[strt] = document.getElementById("qtyssa"+strt).value;
		   document.getElementById("qtya"+strt).value = qtty[strt];
		   document.getElementById("qty"+strt).value = qtty[strt];
	       }
	       if (document.getElementById("qtyssb"+strt)) {
		   qttyb = document.getElementById("qtyssb"+strt).value;
		   document.getElementById("qtyb"+strt).value = qttyb;
		   qtty[strt] = parseFloat(qtty[strt]) * parseFloat(qttyb);
                   document.getElementById("qty"+strt).value = qtty[strt];
	       }
	       if (document.getElementById("qtyssc"+strt)) {
		   qttyc = document.getElementById("qtyssc"+strt).value;
		   document.getElementById("qtyc"+strt).value = qttyc;
		   qtty[strt] = parseFloat(qtty[strt]) * parseFloat(qttyc);
                   document.getElementById("qty"+strt).value = qtty[strt];
		   
	       }
               
	       nods = "checkqty"+strt;
                if (document.getElementById(nods)) {
                  if (document.getElementById(nods).checked) {
                      qtty[strt] = 1;
		      document.getElementById("qty"+strt).value = 1;
                      //nodsx = "document.quotegen.qty"+strt+".value = 1;";
                      //eval(nodsx);
                  }else{
                      qtty[strt] = 0;
		      document.getElementById("qty"+strt).value = 0;
                      //nodsx = "document.quotegen.qty"+strt+".value = 0;";
                      //eval(nodsx);
                  }
                }
	
		
		nods2 = "checkqtys"+strt;    // Formula number
                if (document.getElementById(nods2)) { 
		  
		  if (document.getElementById(nods2).value==2) {       // Formula #2
                      qtty[strt] = 0;
		      document.getElementById("qty"+strt).value = 0.00000001;

		      
		      if (document.getElementById(nods)) {   // Check box
                        if (document.getElementById(nods).checked) {
			    if(pr[strt].includes("%")){
			       res_prs = pr[strt].replace("%", "");
		               multyplier = multyplier + parseFloat(res_prs)/100;
		            }else{
			       multyplier = multyplier + parseFloat(pr[strt]);
		            }
			}else{
			    document.getElementById("qty"+strt).value = 0.000000001;
			}
			
		      }else{
		         
		         if(pr[strt].includes("%")){
		            res_prs = pr[strt].replace("%", "");
		            multyplier = multyplier+parseFloat(res_prs)/100;
		         }else{
			    multyplier = multyplier+parseFloat(pr[strt]);
		         }
		      }

                  }else if (document.getElementById(nods2).value==3) {  //Formula #3
                      qtty[strt] = 0;
		      document.getElementById("qty"+strt).value = 0.00000001;
                      //nods2 = "document.quotegen.qty"+strt+".value = 0.00000001;";
                      //eval(nods2);
		      
		      if (document.getElementById(nods)) {   // Check box
                        if (document.getElementById(nods).checked) {
			    if(pr[strt].includes("%")){
			       res_prs = pr[strt].replace("%", "");
		               qty_multyplier = qty_multyplier+parseFloat(res_prs)/100;
		            }else{
			       qty_multyplier = qty_multyplier + parseFloat(pr[strt]);
		            }
			}else{
			    document.getElementById("qty"+strt).value = 0.000000001;
			}
			
		      }else{
		         
		         if(pr[strt].includes("%")){
			    res_prs = pr[strt].replace("%", "");
		            qty_multyplier = qty_multyplier+parseFloat(res_prs)/100;
		         }else{
			    qty_multyplier = qty_multyplier + parseFloat(pr[strt]);
		         } 
		      }
                  }
                }
	

		
               amt[strt] = 0;
	       amt2[strt] = 0;

               if (document.getElementById("disa"+strt)){dss1[strt] = document.getElementById("disa"+strt).value;}else{dss1[strt] = 0;}
	       if (document.getElementById("disb"+strt)){dss2[strt] = document.getElementById("disb"+strt).value;}else{dss2[strt] = 0;}
	       if (document.getElementById("disc"+strt)){dss3[strt] = document.getElementById("disc"+strt).value;}else{dss3[strt] = 0;}
	       if (document.getElementById("disd"+strt)){dss4[strt] = document.getElementById("disd"+strt).value;}else{dss4[strt] = 0;}
	       if (document.getElementById("dise"+strt)){dss5[strt] = document.getElementById("dise"+strt).value;}else{dss5[strt] = 0;}
	       if (document.getElementById("disf"+strt)){dss6[strt] = document.getElementById("disf"+strt).value;}else{dss6[strt] = 0;}
	       if (document.getElementById("disg"+strt)){dss7[strt] = document.getElementById("disg"+strt).value;}else{dss7[strt] = 0;}
	       if (document.getElementById("disj"+strt)){dss8[strt] = document.getElementById("disj"+strt).value;}else{dss8[strt] = 0;}
	       if (document.getElementById("dish"+strt)){dss9[strt] = document.getElementById("dish"+strt).value;}else{dss9[strt] = 0;}
	       if (document.getElementById("disk"+strt)){dss10[strt] = document.getElementById("disk"+strt).value;}else{dss10[strt] = 0;}
	       if (document.getElementById("disl"+strt)){dss11[strt] = document.getElementById("disl"+strt).value;}else{dss11[strt] = 0;}
	       if (document.getElementById("dism"+strt)){dss12[strt] = document.getElementById("dism"+strt).value;}else{dss12[strt] = 0;}
	       if (document.getElementById("disn"+strt)){dss13[strt] = document.getElementById("disn"+strt).value;}else{dss13[strt] = 0;}
	       if (document.getElementById("diso"+strt)){dss14[strt] = document.getElementById("diso"+strt).value;}else{dss14[strt] = 0;}
	       if (document.getElementById("disp"+strt)){dss15[strt] = document.getElementById("disp"+strt).value;}else{dss15[strt] = 0;}
	       
	       if (document.getElementById("disaa"+strt)){dss21[strt] = document.getElementById("disaa"+strt).value;}else{dss21[strt] = 0;}
	       if (document.getElementById("disbb"+strt)){dss22[strt] = document.getElementById("disbb"+strt).value;}else{dss22[strt] = 0;}
	       if (document.getElementById("discc"+strt)){dss23[strt] = document.getElementById("discc"+strt).value;}else{dss23[strt] = 0;}
	       if (document.getElementById("disdd"+strt)){dss24[strt] = document.getElementById("disdd"+strt).value;}else{dss24[strt] = 0;}
	       if (document.getElementById("disee"+strt)){dss25[strt] = document.getElementById("disee"+strt).value;}else{dss25[strt] = 0;}
	       if (document.getElementById("disff"+strt)){dss26[strt] = document.getElementById("disff"+strt).value;}else{dss26[strt] = 0;}
	       if (document.getElementById("disgg"+strt)){dss27[strt] = document.getElementById("disgg"+strt).value;}else{dss27[strt] = 0;}
	       if (document.getElementById("disjj"+strt)){dss28[strt] = document.getElementById("disjj"+strt).value;}else{dss28[strt] = 0;}
	       if (document.getElementById("dishh"+strt)){dss29[strt] = document.getElementById("dishh"+strt).value;}else{dss29[strt] = 0;}
	       if (document.getElementById("diskk"+strt)){dss30[strt] = document.getElementById("diskk"+strt).value;}else{dss30[strt] = 0;}
	       if (document.getElementById("disll"+strt)){dss31[strt] = document.getElementById("disll"+strt).value;}else{dss31[strt] = 0;}
	       if (document.getElementById("dismm"+strt)){dss32[strt] = document.getElementById("dismm"+strt).value;}else{dss32[strt] = 0;}
	       if (document.getElementById("disnn"+strt)){dss33[strt] = document.getElementById("disnn"+strt).value;}else{dss33[strt] = 0;}
	       if (document.getElementById("disoo"+strt)){dss34[strt] = document.getElementById("disoo"+strt).value;}else{dss34[strt] = 0;}
	       if (document.getElementById("dispp"+strt)){dss35[strt] = document.getElementById("dispp"+strt).value;}else{dss35[strt] = 0;}

	       
               qty_disc[strt] = 0;
               
               if (parseFloat(pr[strt])>0 && parseFloat(qtty[strt])>0) {
                
                   if (parseFloat(qtty[strt])>=parseFloat(dss1[strt]) && parseFloat(qtty[strt])<=parseFloat(dss2[strt]) && parseFloat(dss3[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss1[strt]) && !isNaN(dss2[strt]) && !isNaN(dss3[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty[strt]))*dss3[strt]/100;
                   }else if (parseFloat(qtty[strt])>=parseFloat(dss4[strt]) && parseFloat(qtty[strt])<=parseFloat(dss5[strt]) && parseFloat(dss6[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss4[strt]) && !isNaN(dss5[strt]) && !isNaN(dss6[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty[strt]))*dss6[strt]/100;
                   }else if (parseFloat(qtty[strt])>=parseFloat(dss7[strt]) && parseFloat(qtty[strt])<=parseFloat(dss8[strt]) && parseFloat(dss9[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss7[strt]) && !isNaN(dss8[strt]) && !isNaN(dss9[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty[strt]))*dss9[strt]/100;
                   }else if (parseFloat(qtty[strt])>=parseFloat(dss10[strt]) && parseFloat(qtty[strt])<=parseFloat(dss11[strt]) && parseFloat(dss12[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss10[strt]) && !isNaN(dss11[strt]) && !isNaN(dss12[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty[strt]))*dss12[strt]/100;
		   }else if (parseFloat(qtty[strt])>=parseFloat(dss13[strt]) && parseFloat(qtty[strt])<=parseFloat(dss14[strt]) && parseFloat(dss15[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss13[strt]) && !isNaN(dss14[strt]) && !isNaN(dss15[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty[strt]))*dss15[strt]/100;
		   
		   }else if (parseFloat(qtty[strt])>=parseFloat(dss21[strt]) && parseFloat(qtty[strt])<=parseFloat(dss22[strt]) && parseFloat(dss23[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss21[strt]) && !isNaN(dss22[strt]) && !isNaN(dss23[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty[strt]))*dss23[strt]/100;
                   }else if (parseFloat(qtty[strt])>=parseFloat(dss24[strt]) && parseFloat(qtty[strt])<=parseFloat(dss25[strt]) && parseFloat(dss26[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss24[strt]) && !isNaN(dss25[strt]) && !isNaN(dss26[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty[strt]))*dss26[strt]/100;
                   }else if (parseFloat(qtty[strt])>=parseFloat(dss27[strt]) && parseFloat(qtty[strt])<=parseFloat(dss28[strt]) && parseFloat(dss29[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss27[strt]) && !isNaN(dss28[strt]) && !isNaN(dss29[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty[strt]))*dss29[strt]/100;
                   }else if (parseFloat(qtty[strt])>=parseFloat(dss30[strt]) && parseFloat(qtty[strt])<=parseFloat(dss31[strt]) && parseFloat(dss32[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss30[strt]) && !isNaN(dss31[strt]) && !isNaN(dss32[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty[strt]))*dss32[strt]/100;
		   }else if (parseFloat(qtty[strt])>=parseFloat(dss33[strt]) && parseFloat(qtty[strt])<=parseFloat(dss34[strt]) && parseFloat(dss35[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss33[strt]) && !isNaN(dss34[strt]) && !isNaN(dss35[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty[strt]))*dss35[strt]/100;
		   }
                   
                   amt[strt] = (parseFloat(pr[strt])*parseFloat(qtty[strt])) - qty_disc[strt];
		   
               }else if (parseFloat(pr[strt])>0 && parseFloat(qtty2[strt])>0) {
		
		   if (parseFloat(qtty2[strt])>=parseFloat(dss1[strt]) && parseFloat(qtty2[strt])<=parseFloat(dss2[strt]) && parseFloat(dss3[strt])>0 && !isNaN(qtty2[strt]) && !isNaN(dss1[strt]) && !isNaN(dss2[strt]) && !isNaN(dss3[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty2[strt]))*dss3[strt]/100;
                   }else if (parseFloat(qtty2[strt])>=parseFloat(dss4[strt]) && parseFloat(qtty2[strt])<=parseFloat(dss5[strt]) && parseFloat(dss6[strt])>0 && !isNaN(qtty2[strt]) && !isNaN(dss4[strt]) && !isNaN(dss5[strt]) && !isNaN(dss6[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty2[strt]))*dss6[strt]/100;
                   }else if (parseFloat(qtty2[strt])>=parseFloat(dss7[strt]) && parseFloat(qtty2[strt])<=parseFloat(dss8[strt]) && parseFloat(dss9[strt])>0 && !isNaN(qtty2[strt]) && !isNaN(dss7[strt]) && !isNaN(dss8[strt]) && !isNaN(dss9[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty2[strt]))*dss9[strt]/100;
                   }else if (parseFloat(qtty2[strt])>=parseFloat(dss10[strt]) && parseFloat(qtty2[strt])<=parseFloat(dss11[strt]) && parseFloat(dss12[strt])>0 && !isNaN(qtty2[strt]) && !isNaN(dss10[strt]) && !isNaN(dss11[strt]) && !isNaN(dss12[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty2[strt]))*dss12[strt]/100;
		   }else if (parseFloat(qtty2[strt])>=parseFloat(dss13[strt]) && parseFloat(qtty2[strt])<=parseFloat(dss14[strt]) && parseFloat(dss15[strt])>0 && !isNaN(qtty2[strt]) && !isNaN(dss13[strt]) && !isNaN(dss14[strt]) && !isNaN(dss15[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty2[strt]))*dss15[strt]/100;
		  
		   }else if (parseFloat(qtty2[strt])>=parseFloat(dss21[strt]) && parseFloat(qtty2[strt])<=parseFloat(dss22[strt]) && parseFloat(dss23[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss21[strt]) && !isNaN(dss22[strt]) && !isNaN(dss23[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty2[strt]))*dss23[strt]/100;
                   }else if (parseFloat(qtty2[strt])>=parseFloat(dss24[strt]) && parseFloat(qtty2[strt])<=parseFloat(dss25[strt]) && parseFloat(dss26[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss24[strt]) && !isNaN(dss25[strt]) && !isNaN(dss26[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty2[strt]))*dss26[strt]/100;
                   }else if (parseFloat(qtty2[strt])>=parseFloat(dss27[strt]) && parseFloat(qtty2[strt])<=parseFloat(dss28[strt]) && parseFloat(dss29[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss27[strt]) && !isNaN(dss28[strt]) && !isNaN(dss29[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty2[strt]))*dss29[strt]/100;
                   }else if (parseFloat(qtty2[strt])>=parseFloat(dss30[strt]) && parseFloat(qtty2[strt])<=parseFloat(dss31[strt]) && parseFloat(dss32[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss30[strt]) && !isNaN(dss31[strt]) && !isNaN(dss32[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty2[strt]))*dss32[strt]/100;
		   }else if (parseFloat(qtty2[strt])>=parseFloat(dss33[strt]) && parseFloat(qtty2[strt])<=parseFloat(dss34[strt]) && parseFloat(dss35[strt])>0 && !isNaN(qtty[strt]) && !isNaN(dss33[strt]) && !isNaN(dss34[strt]) && !isNaN(dss35[strt])) {
                       qty_disc[strt] = (parseFloat(pr[strt])*parseFloat(qtty2[strt]))*dss35[strt]/100;
		   }
                   
                   amt2[strt] = (parseFloat(pr[strt])*parseFloat(qtty2[strt])) - qty_disc[strt];
		   
	       }
	       
	       
	      if (document.getElementById(nods2).value==6) {  //Formula #6
		    amt[strt] = 0;
		    var newval="";
		    //alert(calc_formula);
		    for(var fvl=0; fvl<formula_val.length;fvl++){
			newval = "VALUE"+(fvl+1);
			//calc_formula = calc_formula.replace(newval, formula_val[fvl]);//formula_val[stps]
			calc_formula = calc_formula.replace(new RegExp(newval, 'gi'), formula_val[fvl]);//new RegExp(find[i], 'gi')
		    }
		    //alert(calc_formula);
		    //alert(JSON.stringify(formula_val));
		    var strn = calc_formula.replace(/[^-()\d/*+.]/g, '');
		    amt[strt] = eval(strn);
	      }
	       
               
              var fnkd = "document.quotegen.discnt"+strt+".value = qty_disc["+strt+"].toFixed(2);";
              eval(fnkd);
	      
	      if (amt[strt]>0.0001) {
		  fnkd = "document.quotegen.amnt"+strt+".value = amt["+strt+"].toFixed(2);";
	      }else if (amt2[strt]>0.0001) {
		  fnkd = "document.quotegen.amnt"+strt+".value = amt2["+strt+"].toFixed(2);";
	      
	      }else{
		  fnkd = 'document.quotegen.amnt'+strt+'.value = "";';
	      }
              eval(fnkd);
	      
           } //end of loop
           
           
	   subtotal = amt.reduce(function(pv, cv) { return pv + cv; }, 0);
	   total_qty= qtty.reduce(function(pv, cv) { return parseFloat(pv) + parseFloat(cv); }, 0);
	   //total_qty= qtty.toString();
	   
	   var discount = 0;
	   
	   if (multyplier>0) {
	     
	       if (nssww=="display:none;") {
		   document.getElementById("addcharg").style.display = "none";
	       }else{
		   document.getElementById("addcharg").style.display = "table-row";
	       }
	       
	      document.quotegen.qgb0.value = (multyplier * subtotal).toFixed(2);
	      subtotal = subtotal + multyplier * subtotal;
	   
	   }else if(multyplier<0) {
	       document.getElementById("addcharg").style.display = "none";
	       document.quotegen.qgb0.value = '0';
	       discount = multyplier * subtotal*-1;
	    
	   }else{
	       document.getElementById("addcharg").style.display = "none";
	       document.quotegen.qgb0.value = '0';
	   }
	   
	   if (qty_multyplier>0) {
	       
	       if (nssww2=="display:none;") {
		   document.getElementById("addcharg").style.display = "none";
	       }else{
		   document.getElementById("addcharg").style.display = "table-row";
	       }
	       
	      document.quotegen.qgb0.value = (parseFloat(document.quotegen.qgb0.value)+(qty_multyplier * total_qty)).toFixed(2);
	      subtotal = subtotal + qty_multyplier * total_qty;
	   
	   }else if(qty_multyplier<0) {
	       document.getElementById("addcharg").style.display = "none";
	       document.quotegen.qgb0.value = '0';
	       discount = discount + qty_multyplier * total_qty*-1;
	    
	   }
	   
	     if(parseFloat(document.quotegen.qgb0.value)==0){
		document.getElementById("addcharg").style.display = "none";
	     }
	   
	   // Add to subtotal independent Input
	      var add_subtotal = amt2.reduce(function(pv, cv) { return pv + cv; }, 0);
	      subtotal = subtotal + add_subtotal;
	   //----------------------------------
	   
	   
           document.quotegen.qgb1.value = subtotal.toFixed(2); // Subtotal Amount
	            
           
              if (parseFloat(ord_disc) <= subtotal) {
                  discount = discount + subtotal * parseFloat(prs_disc)/100;
              }
	      
	   if(discount>0){
	       document.quotegen.qgb2.value = discount.toFixed(2);
	       document.getElementById("qgb2").style.display = "table-row";
	   }else{
	       document.getElementById("qgb2").style.display = "none";
	     }   
           
           
           var t_befor_tax = 0;
           
           if (parseFloat(tax1a)>=0) { }else{tax1a=0;}
           var tax1 = 0;
           
           if (parseFloat(tax2a)>=0) { }else{tax2a=0;}
           var tax2 = 0;
           
           if (parseFloat(tax3a)>=0) { }else{tax3a=0;}
           var tax3 = 0;
           
           var total_amount = 0;
           
           t_befor_tax = subtotal - discount;
           
           if (parseFloat(min_order) > t_befor_tax) {
	       t_befor_tax = parseFloat(min_order);
	   }
           
           document.quotegen.qgb3.value = t_befor_tax.toFixed(2);
           
           
           
           tax1 = t_befor_tax * parseFloat(tax1a)/100;
           document.quotegen.qgb4.value = tax1.toFixed(2);
           tax2 = t_befor_tax * parseFloat(tax2a)/100;
           document.quotegen.qgb5.value = tax2.toFixed(2);
           tax3 = t_befor_tax * parseFloat(tax3a)/100;
           document.quotegen.qgb6.value = tax3.toFixed(2);
           
           total_amount = t_befor_tax + tax1 + tax2 + tax3;
           document.quotegen.qgb7.value = total_amount.toFixed(2);
	   document.quotegen.qgb30.value = total_qty.toFixed(2);

         }
         
 
  //alert("OK");
 
    }
    








    function submitf() {
       if( parseFloat(document.quotegen.qgb7.value)>0 ) {
           document.getElementById("subord").style.display = "block";
           document.getElementById("buttn1").style.display = "none";//addcharg
           return true;
       }else{
           alert("Please fill out this form.");
           return false;
       }
    }


//================= Calendar Event ===================================    
    
var mySplitXt=new Array;
var Cyy=new Array;
var Cmm=new Array;
var Cdd=new Array;
var Ctt=new Array;
var Caa=new Array;

var now = new Date;
var sccd=now.getDate();
var sccm=now.getMonth();
var sccy=now.getFullYear();
var ccm=now.getMonth();
var ccy=now.getFullYear();
var selectedd, selectedm, selectedy;
var updobj;

var mnn=new Array('31','28','31','30','31','30','31','31','30','31','30','31');
var mnl=new Array('31','29','31','30','31','30','31','31','30','31','30','31');
var calvalarr=new Array(42);
var datetoday = '';


document.write('<div id="fc" style="'+ cssc[0] +'"><table style="'+cssc[1]+'">');
document.write('<tr style="'+cssc[2]+'"><td style="'+cssc[4]+'" onclick="upmonth(-1)"> &laquo; </td><td colspan="5" id="mns" style="'+cssc[3]+'"></td><td style="'+cssc[4]+'" onclick="upmonth(1)"> &raquo; </td></tr>');
document.write('<tr style="'+nfont+'"><td style="'+nfont+'">'+Sunday+'</td><td style="'+nfont+'">'+Monday+'</td><td style="'+nfont+'">'+Tuesday+'</td><td style="'+nfont+'">'+Wednesday+'</td><td style="'+nfont+'">'+Thursday+'</td><td style="'+nfont+'">'+Friday+'</td><td style="'+nfont+'">'+Saturday+'</td></tr>');

  for(var kk=1;kk<=6;kk++) {
	  document.write('<tr>');
	  for(var tt=1;tt<=7;tt++) {
		num=7 * (kk-1) - (-tt);
		document.write('<td id="v' + num + '" style="vertical-align: text-top;width: ' + parseInt(nwid) + 'px;height: ' + parseInt(nhei)+'px; word-wrap:break-word;"></td>');
	  }
	  document.write('</tr>');
          datetoday = addnull(sccd,sccm+1,sccy);
  }

document.write('</table></div>');


function AssignDateList(TheData) {
   var mySplitRt = TheData.split("\n");
   x1=0;

   for(i = 0; i < mySplitRt.length; i++){
	   mySplitXt = mySplitRt[i].split(",");
	   if (mySplitXt.length == 5){
		   Cyy[x1] = mySplitXt[0];
		   Cmm[x1] = mySplitXt[1];
		   Cdd[x1] = mySplitXt[2];
		   if(mySplitXt[3] ==''){Ctt[x1]=''}else{Ctt[x1]= mySplitXt[3];}
		   Caa[x1] = mySplitXt[4];
		   x1++;
            }
   }
}

        
function getObj(objID) {
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
    return true;
}

function checkClick(e) {
	e?evt=e:evt=event;
	CSE=evt.target?evt.target:evt.srcElement;
	if (CSE.tagName!='SPAN')	
	if (getObj('fc'))
		if (!isChild(CSE,getObj('fc')))
			getObj('fc').style.display='none';
}

function isChild(s,d) {
	while(s) {
		if (s==d) 
			return true;
		s=s.parentNode;
	}
	return false;
}

function Top(obj){
	var curtop = 0;
	if (obj.offsetParent)	{
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function lcs(ielem) {
    document.onkeydown = function (e) { return false;}

	updobj=ielem;   
        getObj('fc').style.top = (Top(ielem)+ielem.offsetHeight-260)+'px';
	getObj('fc').style.display='';
	curdt=ielem.value;
	curdtarr=curdt.split('-');
	isdt=true;
	for(var k=0;k<curdtarr.length;k++) {
		if (isNaN(curdtarr[k]))
			isdt=false;
	}
	if (isdt&(curdtarr.length==3)) {
		ccm=curdtarr[1]-1;
		ccy=curdtarr[2];
		selectedd=parseInt ( curdtarr[0], 10 );
		selectedm=parseInt ( curdtarr[1]-1, 10 );
		selectedy=parseInt ( curdtarr[2], 10 );
		prepcalendar(curdtarr[0],curdtarr[1]-1,curdtarr[2]);
	}
}

function lcs2() {
    document.onkeydown = function (e) { return true;}
}


function evtTgt(e){
	var el;
	if(e.target)el=e.target;
	else if(e.srcElement)el=e.srcElement;
	if(el.nodeType==3)el=el.parentNode; // defeat Safari bug
	return el;
}

function EvtObj(e){  if(!e)e=window.event;return e;}
function cs_over(e) {evtTgt(EvtObj(e)).style.background='#FFFFFF';}
function cs_out(e) { evtTgt(EvtObj(e)).style.background='#eeeeee';}
function cs_click(e) {
	updobj.value=calvalarr[evtTgt(EvtObj(e)).id.substring(1,evtTgt(EvtObj(e)).id.length)];
	getObj('fc').style.display='none';
        checkcal();
}

function f_cps(obj) {
	obj.style.background='transparent';
	obj.style.font='10px Arial';
	obj.style.textAlign='left';
	obj.style.textDecoration='none';
	obj.style.border='none'; //1px solid #999999
	obj.style.cursor='pointer';
}


// day selected
function prepcalendar(hd,cm,cy) {
	now=new Date();
	sd=now.getDate();
	td=new Date();
	td.setDate(1);
	td.setFullYear(cy);
	td.setMonth(cm);
	cd=td.getDay();
	var col='#333333';
	var pos=0;
        var s='';
        var x1 = 0;
        AssignDateList(DateList);
        var chekday='';
	
        getObj('mns').innerHTML = mn[cm]+' &nbsp; '+cy+' &nbsp; ';
        
	marr=((cy%4)==0)?mnl:mnn;
	for(var d=1;d<=42;d++) {
		f_cps(getObj('v'+parseInt(d)));
		if ((d >= (cd -(-1)))&&(d<=cd-(-marr[cm]))) {
			dip=((d-cd < sd)&&(cm==sccm)&&(cy==sccy));
			htd=((hd!='')&&(d-cd==hd));

			getObj('v'+parseInt(d)).onmouseover=cs_over;
			getObj('v'+parseInt(d)).onmouseout=cs_out;
			getObj('v'+parseInt(d)).onclick=cs_click;
                        col='#003300';
                        var newbgr = '#efefef';
			
                        if ((sccm == cm && sccd == (d-cd) && sccy == cy)){// if today
			    col='#ffff00'; //006600 0f3
                            newbgr = '#cfcfcf';
                        }
			// if selected date
			if (cm == selectedm && cy == selectedy && selectedd == (d-cd) )	{
			    getObj('v'+parseInt(d)).style.background = newbgr; //sellll
                            getObj('v'+parseInt(d)).onmouseout=null;
			}
                        s='';
 
			for(pos=0;pos<Cyy.length; pos++){
			    if((Cdd[pos]==(d-cd) && Cmm[pos]==(cm+1) && Cyy[pos]==cy)){
                                s+='<br />'+Ctt[pos]+' '+Caa[pos];
                                chekday = Caa[pos].toLowerCase().trim();
                                if (chekday == 'fully booked' || chekday == 'closed' || chekday == 'not available') {
                                    col = '#ff0000';
                                    newbgr = '#FFA8A8';
                                    getObj('v'+d).innerHTML='&nbsp;';
			            getObj('v'+parseInt(d)).onmouseover=null;
			            getObj('v'+parseInt(d)).onmouseout=null;
			            getObj('v'+parseInt(d)).onclick=null;
			            getObj('v'+parseInt(d)).style.cursor='default';
                                    
                                }
                                
                            }   
			}
                        getObj('v'+parseInt(d)).style.background = newbgr;
			getObj('v'+parseInt(d)).style.color=col;
                        getObj('v'+parseInt(d)).innerHTML='<span id="dayevent" onclick="event.cancelBubble=true;this.select(); cs_click(this);">'+(d-cd)+'</span>';
                        col='#000000';
			calvalarr[d]=addnull(d-cd,cm-(-1),cy);
		}else {
			getObj('v'+d).innerHTML='&nbsp;';
			getObj('v'+parseInt(d)).onmouseover=null;
			getObj('v'+parseInt(d)).onmouseout=null;
			getObj('v'+parseInt(d)).onclick=null;
			getObj('v'+parseInt(d)).style.cursor='default';
	        }
	}
}


function upmonth(s){
	marr=((ccy%4)==0)?mnl:mnn;
	ccm+=s;
	if (ccm>=12){
		ccm-=12;
		ccy++;
	}else if(ccm<0)	{
		ccm+=12;
		ccy--;
	}
	prepcalendar('',ccm,ccy);
}

function addnull(d,m,y){
	var d0='',m0='';
	if (d<10)d0='0';
	if (m<10)m0='0';
	return ''+d0+d+'-'+m0+m+'-'+y;
}

prepcalendar('',ccm,ccy);


//-------------------------------------------------------------------




function submitform() {

       var mmm = document.quotegen.oqgb2.value;
       var wersion = document.quotegen.oqgb13.value;
       
       if (typeof CryptoJS.MD5 != 'function') {
             alert("Probably the Server is overloaded, down or unreachable because of a network problem, outage or a website maintenance is in progress. Please wait 1 second and try again.");
	     return false;
       }else if (document.quotegen.oqgb1.value==""){
	     alert("Please enter your Name!");
	     return false;
       } else if ((mmm.indexOf("@") == -1)||(mmm.indexOf(".") == -1)){ 
	     alert("Please enter valid Email Address!");
	     return false;
       }else if (CryptoJS.MD5(wersion) != document.quotegen.oqgb20.value) {
             alert("The reCaptcha code was incorrect.");
	     document.quotegen.oqgb13.value = "";
             return false;
       
       }
       //alert("OK");
       document.quotegen.method = "POST";
       document.quotegen.submit();
       return true;
}



function findate(){
    var selected_date = document.quotegen.oqgb5.value;
    var sel_d = selected_date.split("-");
    var ressl = DateList.split("\r\n");
    var list='';
    var carrn = '';
    for(var x = 0; x<ressl.length; x++){
	carrn = ressl[x].split(",");
	if (sel_d[2] == carrn[0] && sel_d[1] == carrn[1] && sel_d[0] == carrn[2]) {
	    list+= carrn[3]+";";
	}
    }
    if (list!='') {
	my_function(list); //alert(list);
    }else{
	my_function2();
    }
    
}  


function checkcal() {
    var ress = datetoday.split("-");
    var sellct = document.quotegen.oqgb5.value;
    var sellt = sellct.split("-");
    //alert(datetoday+' '+sellct );
     if (parseInt(ress[2]) > parseInt(sellt[2])) {
        document.quotegen.oqgb5.value ='';
        alert("The date you mentioned has already passed.");
	return false;
     }
     if (parseInt(ress[1]) > parseInt(sellt[1]) && (parseInt(ress[2]) == parseInt(sellt[2]))) {
        document.quotegen.oqgb5.value ='';
        alert("The date you mentioned has already passed.");
	return false;
     }else if (parseInt(ress[0]) > parseInt(sellt[0]) && ((parseInt(ress[1]) == parseInt(sellt[1])) && (parseInt(ress[2]) == parseInt(sellt[2])))) {
        document.quotegen.oqgb5.value ='';
        alert("The date you mentioned has already passed.");
	return false;
     }
     
  findate();
  return true;
}







//---------------------------------------------------------------------    

function my_function2(){
    var selects = document.getElementById('selectime');
    while(selects.options.length > 0){                
          selects.remove(0);
    }
    
    for(var i = 0; i<time_array.length; i++){
	   var opt = document.createElement('option');
           opt.value = time_array[i];
           opt.innerHTML = time_array[i];
           selects.appendChild(opt);
    }
}


function my_function(dat){
    
  var selects = document.getElementById('selectime');
  if("" != dat){
    var seltime = dat.split(";");
  
    while(selects.options.length > 0){                
          selects.remove(0);
    }
    
    for (var i = 0; i<time_array.length; i++){
	if(isInArray(time_array[i], seltime) == false){    
	   var opt = document.createElement('option');
           opt.value = time_array[i];
           opt.innerHTML = time_array[i];
           selects.appendChild(opt);
	}
    }
  }
  
}

    function showselbox(nod,nod2) {

      //alert(document.getElementById('sells_'+nod+'_'+nod2).style.display);
      var x ="";
      var curren = document.getElementById('curshow'+nod).value;
      for(var y=1;y<100;y++){
	x = document.getElementById('sells_'+nod+'_'+y);
	if (x) {
	  if(x.style.display=='none' || x.style.display=='' || x.style.display==null){	
             x.style.display = "block";
          }else{
             x.style.display = "none";
          }
	}
      }
      document.getElementById('sells_'+nod+'_'+curren).style.display = "block";


    }
    
    function setselbox(nod,nod2) {
	//alert(nod+'-'+nod2);
	var z = document.getElementById('sells_'+nod+'_'+nod2);
	document.getElementById('name'+nod).value = document.getElementById('namesel_'+nod+'_'+nod2).value;
	document.getElementById('price'+nod).value = document.getElementById('price_'+nod+'_'+nod2).value;
	var x ="";
        for(var y=1;y<100;y++){
	  x = document.getElementById('sells_'+nod+'_'+y);
	    if (x) {
                x.style.display = "none";
            }
        }
	
	z.style.display = "block";
	//z.style.backgroundColor = "transparent";
	document.getElementById('curshow'+nod).value = nod2;
	calclat(nod);
    }    
    
    