// JavaScript Document
function maketwo(ss)
{
	var snum=ss.toString();
	if (snum.indexOf('.')==snum.length-2)
	{
			snum=snum+"0";
	}
	
	if (snum.indexOf('.')==-1)
	{
			snum=snum+".00";
	}
	return snum;
}
function UpdateTotal()
{
var test='';

var whatsmissing='';
var thetab=myTabs.get('activeIndex');

      var f = document.price_quote;
      var f2 = document.price_quote.tipisize;
	  
var tipisize =f2.options[f2.selectedIndex].value;

valuestopass='?tipisize='+tipisize;

	var sizesArray=
		["12","14","16","18","20","22","24","26","28"]

var sizecol=sizesArray.indexOf(tipisize);
var currenttotal=0;

 var package= ExtractSingleValue(f.package);
 valuestopass+='&package='+package;
 var packagefabric= (f.packagefabric.value);


	
	if (package!='complete')
	{
		jQuery("#economypoles").attr('disabled','disabled');
		f.economypoles.checked=false;
				jQuery("#economypoleslabel").css({opacity:.65});
	}
	else
	{
			jQuery("#economypoles").removeAttr("disabled");
					jQuery("#economypoleslabel").css({opacity:1});


	}



var codename='';
var addliner=false;

if (thetab==0)
//add in the package price if on the package tab
{
 var packageliner= getRadio(f.packageliner);//.checked?'yes':'');
	valuestopass+='&packageliner='+packageliner;
//plinermsg

if ((packageliner=='packageliner9foot' )&&(sizecol<3))
		{
		writeDiv('9footerrorpackage',"<br>Unavailable - 9' liner available on 18' and larger tipis.");
							writeDiv('plinermsg',"");

		}
		else
		{
 	
				writeDiv('9footerrorpackage',"");
		}
		
		if ((packageliner=='packageliner9foot' )&&(sizecol>=3)) //add in 9' liner price
		{
		//add breakout price -5%
		var acode='9l13mbs';
		//if flame retardent selected, use tis instead:
		//9l13frmbs
		
		
		
		var slen=packagefabric.length;
		 if (slen>2)
		{
			acode='9l13frmbs';
		}
		
						toadd=tipiPriceCalculator(acode,sizecol);
						toadd=toadd*.95;
						toadd=Math.round(toadd*100)/100
						currenttotal+=toadd;
										writeDiv('plinermsg',"Added $"+maketwo(toadd));
		
		}
		else
		{
										writeDiv('plinermsg','');

		}
		
				
if (packageliner=='packageliner6foot')	 
			{
 			addliner=true;
 			}
if (packageliner=='packagelinernone')	 
			{
					writeDiv('plinermsg',"");
 			}

 
 	 valuestopass+='&packagefabric='+packagefabric;
		if (package=='complete'||package=='basic')
		{
		codename=package+packagefabric;
		var preprice=tipiPriceCalculator(codename,sizecol);
		
		if (addliner)
		{
		codename+='l';
		}
		toadd=tipiPriceCalculator(codename,sizecol);
		currenttotal+=toadd;
		if (addliner)
		{
		var myd=toadd-preprice;
 			writeDiv('plinermsg',"Added $"+maketwo(myd));

		}
		else
		{
					//writeDiv('plinermsg',"");

		}
		
		}

var mmfloor=f.floor.checked?'yes':'';
		if (mmfloor=='yes')
		{
			 valuestopass+='&mmfloor=yes';
			toadd=tipiPriceCalculator('mfloor',sizecol);
			currenttotal+=toadd;
			writeDiv('pfloormsg'," Added $"+maketwo(toadd));
 		}
		else
		{
			writeDiv('pfloormsg',"");

		}
		
var pozan=f.pozan.checked?'yes':'';
		if (pozan=='yes')
		{
			 valuestopass+='&ozan=yes';
			toadd=tipiPriceCalculator('ozan',sizecol);
			currenttotal+=toadd;
			writeDiv('pozanmsg'," Added $"+maketwo(toadd));
 		}
else
		{
			writeDiv('pozanmsg',"");

		}
var steelstakes=f.steelstakes.checked?'yes':'';
		if (steelstakes=='yes')
		{
			 valuestopass+='&steelstakes=yes';
			toadd=tipiPriceCalculator('upgradestakes',sizecol);
			currenttotal+=toadd;
		writeDiv('psteelstakesmsg'," Added $"+maketwo(toadd));
 		}
		else
		{
			writeDiv('psteelstakesmsg',"");

		}
		
	var deckkit=f.deckkit.checked?'yes':'';
		if (deckkit=='yes')
		{
			 valuestopass+='&deckkit=yes';
			toadd=tipiPriceCalculator('upgradestakes',sizecol);
			currenttotal+=toadd;
		writeDiv('pdeckmsg'," Added $"+maketwo(toadd));
 		}
				else
		{
							writeDiv('pdeckmsg',"");

		}

		
	var handbook=f.handbook.checked?'yes':'';
		if (handbook=='yes')
		{
			 valuestopass+='&handbook=yes';
			toadd=15;
			currenttotal+=toadd;
			writeDiv('phandbookmsg'," Added $"+maketwo(toadd));
 		}
		else
		{
			writeDiv('phandbookmsg',"");

		}
		
	
				
	var economypoles=f.economypoles.checked?'yes':'';
	//ECONOMY POLES - actually means they want the hand peeled 
		if (economypoles=='yes')
		{
			 valuestopass+='&economypoles=yes';
			 
			 var a=tipiPriceCalculator('reccomended',sizecol);
			 var b=tipiPriceCalculator('economy',sizecol);
			 var dif=a-b;
			 
			 
			currenttotal+=dif;
					writeDiv('ppolesmsg'," Added $"+maketwo(dif));

		//	writeDiv('ozanssubtotal',toadd);
 		}
		else
		{
							writeDiv('ppolesmsg',"");

		}
		

//zero tab
}
	
	//do we consider the extra tabs?
	
if (thetab==1)
{

var linertipisize =f.linertipisize.options[f.linertipisize.selectedIndex].value;

		sizecol=sizesArray.indexOf(linertipisize);
 		
		var componentcover= "";
		componentcover=(f.componentcover.value);
	var toadd=0;	
		if (componentcover!=''&&componentcover!='Choose...')	 
		{
		valuestopass+='&componentcover='+componentcover;
		toadd=tipiPriceCalculator(componentcover,sizecol);
		currenttotal+=toadd;
		writeDiv('componentcoversubtotal',toadd);
 		}
		var componentliners= (f.componentliners.value);
		if ((componentliners=='9l13mbs'||componentliners=='9l13frmbs')&&(sizecol<3))
		{
		writeDiv('9footerror',"Unavailable - 9' liner available for 18' and larger tipis.");
						writeDiv('componentlinerssubtotal','0');

		}
		else
		{
				writeDiv('9footerror',"");

			if (componentliners!=''&&componentliners!='Choose...')	 
			{
				 valuestopass+='&componentliners='+componentliners;
				toadd=tipiPriceCalculator(componentliners,sizecol);
				currenttotal+=toadd;
				writeDiv('componentlinerssubtotal',toadd);
			}
			else
			{
								writeDiv('componentlinerssubtotal',"0");

			}
		}


		var ozan=f.ozan.checked?'yes':'';
		if (ozan=='yes')
		{
			 valuestopass+='&ozan=yes';
			toadd=tipiPriceCalculator('ozan',sizecol);
			currenttotal+=toadd;
			writeDiv('ozanssubtotal',toadd);
 		}
		else
		{
			writeDiv('ozanssubtotal',0);
		}
		var mfloor=f.mfloor.checked?'yes':'';
		if (mfloor=='yes')
		{
			 valuestopass+='&mfloor=yes';
			toadd=tipiPriceCalculator('mfloor',sizecol);
			currenttotal+=toadd;
			writeDiv('mfloorssubtotal',toadd);
 		}
		else
		{
			writeDiv('mfloorssubtotal',0);
		}
			var accessories=f.accessories.checked?'yes':'';
		if (accessories=='yes')
		{
			 valuestopass+='&accessories=yes';
			toadd=tipiPriceCalculator('accessories',sizecol);
			currenttotal+=toadd;
			writeDiv('accessoriessubtotal',toadd);
 		}
		else
		{
			writeDiv('accessoriessubtotal',0);
		}

	
	
			var upgradestakes=f.upgradestakes.checked?'yes':'';
	
		if (upgradestakes=='yes')
		{
			 valuestopass+='&upgradestakes=yes';
			toadd=tipiPriceCalculator('upgradestakes',sizecol);
			currenttotal+=toadd;
			writeDiv('upgradestakessubtotal',toadd);
 		}
		else
		{
			writeDiv('upgradestakessubtotal',0);
		}



			var linerrope=f.linerrope.checked?'yes':'';
		if (linerrope=='yes')
		{
			 valuestopass+='&linerrope=yes';
			toadd=tipiPriceCalculator('linerrope',sizecol);
			currenttotal+=toadd;
			writeDiv('linerropesubtotal',toadd);
 		}
		else
		{
			writeDiv('linerropesubtotal',0);
		}
}

if (thetab==2)
{

var poletipisize =f.poletipisize.options[f.poletipisize.selectedIndex].value;

		sizecol=sizesArray.indexOf(poletipisize);

			var poles=ExtractSingleValue(f.poles);
			 if (poles==''||poles=='on')
			 {
				writeDiv('polessubtotal',0);
		 }
			 else
  		{
			 valuestopass+='&poles='+poles;
			toadd=tipiPriceCalculator(poles,sizecol);
			currenttotal+=toadd;
			writeDiv('polessubtotal',toadd);
 		}
} //end of if this was just a package tab calculation  










if (currenttotal)
{
	currenttotal=Math.round(currenttotal*100)/100
	currenttotal=currenttotal.toString();
	//var lb='';
	//lb=last(currenttotal,2);
	if (currenttotal.indexOf('.')==currenttotal.length-2)
	{
			currenttotal=currenttotal+"0";
	}
	
	if (currenttotal.indexOf('.')==-1)
	{
			currenttotal=currenttotal+".00";
	}
	
		writeDiv('TotalInline2',currenttotal);
			writeDiv('TotalInline',currenttotal);
}
	else
{
			writeDiv('TotalInline2',"0");
			writeDiv('TotalInline',"0");

}

	
	
	
}
  
  function last(s,i)
  {
	  var ll=s.length;
	  var lls=ll-i;
	  if (ll>i)
	  {
	  	return subString(lls+1,ll);
	  }
	  else
	  {
		  return s;
	  }
	  
  }
  
  
  function getText(object) {
    return escape(object.value)
}

function getOption(object) {
    return escape(object.options[object.selectedIndex].text);
}

function getRadio(object) {
    for (var i = 0; i < object.length; i++)
         if (object[i].checked)
             return object[i].value;

    return '';
}

function getCheckboxes() {
    var output = '';
    for (var i = 0; i < getCheckboxes.arguments.length; i++)
         output += getCheckbox(getCheckboxes[i]) + escape(' ');
    return output;
}

function getCheckbox(object) {
    if (object.checked)
        return escape(object.value);
    else
        return '';
}


  
  
  function ExtractSingleValue( group )
   {
      for ( var i = 0; group[i]; ++i )
      {
         var o = group[i];
         if ( o.checked )
            return( o.value );
      }
      return( '' );
   }


   function ExtractSelectedIndex( group )
   {
      for ( var i = 0; group[i]; ++i )
      {
         var o = group[i];
         if ( o.checked )
            return( i );
      }
   }
 function writeDiv (thediv,towrite)
 {
        document.getElementById( thediv ).innerHTML = towrite;
  }
 
 var arraysready=0;
 
 
 //this var holds exact values from pdf
 //and gets rotated for use in calculator routine
 //
 var pricesFromPDF=[
//complete packages					
 [543,729,629,859,739,969],
[670,884,782,1048,910,1176],
[820,1078,960,1282,1066,1388],
[973,1272,1144,1516,1237,1609],
[1126,1475,1331,1766,1452,1886],
[1270,1640,1521,1983,1652,2113],
[1433,1838,1727,2231,1913,2418],
[1658,2086,1999,2534,2127,2661],
[2401,2854,2823,3388,2928,3492],

[348,534,433,664,544,774],
[433,647,545,811,673,939],
[523,782,664,986,769,1091],
[618,917,788,1161,882,1254],
[726,1075,931,1366,1052,1486],
[870,1240,1122,1583,1252,1714],
[997,1402,1291,1795,1477,1982],
[1145,1573,1486,2021,1613,2148],
[1387,1841,1809,2374,1914,2479]			
					
 ];
 
		 
		 
      var priceArray =
         [           
		 //old
		  [  568,702,861,1023,1183,1408,1622,1811,2336],
[752,914,1117,1320,1530,1776,2024,2238,2788],
[654,814,1001,1194,1388,1660,1915,2153,2758],
[883,1078,1322,1564,1821,2119,2418,2685,3321],
[763,940,1104,1284,1504,1785,2096,2273,2938],
[991,1203,1424,1655,1937,2245,2599,2806,3501],
//old
[111,426,516,609,717,860,987,1133,1375],
[525,638,772,907,1064,1228,1389,1560,1826],
[427,538,656,780,922,1112,1280,1475,1797],
[656,802,977,1150,1355,1571,1783,2007,2360],
[535,664,759,870,1039,1238,1461,1596,1977],
[764,927,1079,1241,1472,1697,1963,2128,2540],

 
//covers
[300,380,470,560,670,815,940,1090,1335],
[385,495,610,735,880,1070,1245,1445,1775],
[495,625,720,830,1005,1210,1440,1575,1880],
//liners =-6'
[190,215,265,300,355,375,410,435,460],
[235,270,330,380,445,470,515,545,575],
//liners - 9'
[,,,420,490,535,595,625,665],
[,,,560,650,710,790,835,885],
//floors,ozans,coveraccessories,stakes,liner rope
[165,190,225,280,320,420,465,555,650],
[90,100,135,145,165,230,255,280,365],
[40,50,55,60,70,75,80,90,95],
[35,45,45,50,50,55,60,60,60],
[5,5,10,10,10,15,15,15,15],
//poles
[319,387,484,581,654,769,908,968,1282],
[197,239,299,359,404,404,441,518,1024]
		    ];
 	function setuptipiarrays()
	{
	
//rewrite current data

var maxx=17;
var maxy=5;
var x=0,y=0;
var fromv=0;
var did='';
for (x=0;x<=maxx;x++)
{
	for (y=0;y<=maxy;y++)
	{
		fromv=pricesFromPDF[x][y];
		var yadd=0;
		var xmin=0;
		if (x>(maxx/2))
		{
			yadd=6;
			xmin=9;
		}
		priceArray[y+yadd][x-xmin]=fromv;
		//did=did+'price:y/x '+(y+yadd)+'/'+(x-xmin)+' @ '+fromv+'<br />';
	}
}


		arraysready=1;
		//document.write(did);
	}					

function tipiPriceCalculator(c,s)
{

if (arraysready==0)
{
setuptipiarrays();
}

	var optionNames=
	
		['complete13','complete13l','complete13fr','complete13frl','complete15fr','complete15frl',
		'basic13','basic13l','basic13fr','basic13frl','basic15fr','basic15frl',
	      
		  'co13mbs','co13mbsfr','co15ts','6l13mbs','6l13frmbs','9l13mbs','9l13frmbs',
		  'mfloor','ozan','accessories','upgradestakes','linerrope','reccomended','economy'
		  
		  ];	
		 
		 var r=0;
		 r=optionNames.indexOf(c);
		 
		 
		 
		
	p=priceArray[r][s];
	////alert (s+" - "+p);
	return p;


}
