
var IEx = (document.all)?1:0;
var NS4 = (document.layers)?1:0
var NS6 = (document.getElementById) && (navigator.appName.indexOf("Netscape")>=0)?1:0
var dealer = "Valley Building";

// COLORS DATA
var arrColorsName = new Array(
"Toscana ",
"Sierra Blend  ",
"Rio ",
"Sedona ",
"La Jolla "
);
var arrColorsImg = new Array(
"images/estimator/colors/cobble/small/toscana-cobble.jpg",
"images/estimator/colors/cobble/small/sierrablend.jpg",
"images/estimator/colors/cobble/small/rioblendrough.jpg",
"images/estimator/colors/cobble/small/sedonablendcobble.jpg",
"images/estimator/colors/cobble/small/lajollablendrough.jpg",
"images/estimator/colors/paver/small/desertblend.jpg",
"images/estimator/colors/paver/small/sierrablendsmooth.jpg",
"images/estimator/colors/paver/small/rioblend.jpg",
"images/estimator/colors/paver/small/sedonablendsmooth.jpg",
"images/estimator/colors/paver/small/lajollablend.jpg"
);
for(i=0;i<arrColorsImg.length;i++)
{
 	img = new Image(80,80);
  	img.src = arrColorsImg[i];
}
 

// PATTERN DATA
var arrPatternsName = new Array(
"I-Pattern 75%Rec - 25%Square", 
"Cambridge Cobble 6x9 herringbone", 
"Cambridge Cobble 6x6 stack bond", 
"Cambridge Cobble 6x9 stack bond", 
"0% Large Square",
"10-15% Large Square",
"20-15% Large Square", 
"0% Large Square coarse ashlar", 
"Ashlar Running Bond", 
"50% Large Square", 
"Basket Weave 100% Standard",
"Herringbone 1 100% Standard",
"Herringbone 2 100% Standard",
"Running Bond 100% Standard"
);
var arrPatternsImg = new Array(
"images/estimator/patterns/bergerac1.gif",
"images/estimator/patterns/bergerac2.gif",
"images/estimator/patterns/bergerac3.gif",
"images/estimator/patterns/bergerac4.gif",
"images/estimator/patterns/Dublin1.gif",
"images/estimator/patterns/Dublin2.gif",
"images/estimator/patterns/Dublin3.gif",
"images/estimator/patterns/Dublin4.gif",
"images/estimator/patterns/Dublin5.gif",
"images/estimator/patterns/Dublin6.gif",
"images/estimator/patterns/holland1.gif",
"images/estimator/patterns/holland2.gif",
"images/estimator/patterns/holland3.gif",
"images/estimator/patterns/holland4.gif"
);
var arrPatternsDim = new Array(
"(60mm)",
"(60mm)",
"(60mm)",
"(60mm)",
"(60mm)",
"(60mm)",
"(60mm)",
"(60mm)",
"(60mm)",
"(60mm)",
"(60mm)",
"(60mm)"
) 
var arrPatternsNr = new Array(118,118,106,96,88,68,120,114,120,84,91,112);
for(i=0;i<arrPatternsImg.length;i++)
{
  	img = new Image(80,80);
  	img.src = arrPatternsImg[i];
}



function fBuildPattern()
{
	x=-1;
	for(i=0;i<arrPatternsName.length;i++)
	{
		x++;
		var opt = new Option();
		opt.value = i;
		opt.text = arrPatternsName[i];
		document.estimator.pattern.options[x] = opt;
	}
	document.estimator.pattern.length = x + 1;
	document.estimator.pattern.selectedIndex = 0;
}

function fPattern()
{
	i = document.estimator.pattern.selectedIndex;
	document.images['pattern_img'].src = arrPatternsImg[i];
	
//	if(i>5)
//	{
//		document.images['pcolor_img'].src = arrColorsImg[5 + document.estimator.pcolor.selectedIndex];
//	}
//	else
//	{
//		document.images['pcolor_img'].src = arrColorsImg[document.estimator.pcolor.selectedIndex];
//	}
}


function fBuildColor()
{
	x=-1;
	for(i=0;i<arrColorsName.length;i++)
	{
		x++;
		var opt = new Option();
		opt.value = i;
		opt.text = arrColorsName[i];
		document.estimator.pcolor.options[x] = opt;
	}
	document.estimator.pcolor.length = x + 1;
	document.estimator.pcolor.selectedIndex = 0;
}

function fColor()
{
	if(document.estimator.pattern.selectedIndex > 5)
	{
		document.images['pcolor_img'].src = arrColorsImg[5 + document.estimator.pcolor.selectedIndex];
	}
	else
	{
		document.images['pcolor_img'].src = arrColorsImg[document.estimator.pcolor.selectedIndex];	
	}
}
 
function fGenCalcul()
{
	var area_w = 0;
	var area_h = 0;
	if(fIsDigits(document.estimator.area_w.value))
		area_w = document.estimator.area_w.value;
	if(fIsDigits(document.estimator.area_h.value))
		area_h = document.estimator.area_h.value;
		
	total = area_w * area_h;
	if(document.estimator.measure[1].checked == true)
		total = total * 3.2808 * 3.2808;
		
	pallets = total / arrPatternsNr[document.estimator.pattern.selectedIndex];
	sand = total / 300;
		
	document.estimator.total.value = formatNR(area_w * area_h, 2);
	document.estimator.pallets.value = formatNR(pallets, 2);
	document.estimator.sand.value = formatNR(sand, 3);
}


function fGenPrint()
{
	wP = window.open('estimator_report.htm','wP','width=700,height=450,top=17,left=17,scrollbars=1,toolbar=1')
	wP.focus();
}

function fMessage(id, text)
{
	if(IEx || NS6)
	{
	 	obj = document.getElementById(id);
 		obj.innerHTML = text;
	}
}
function fLabel(type)
{
	if(type == 'std')
	{
		fMessage('name_w','Width (Ft)');
		fMessage('name_h','Length (Ft)');
		fMessage('l_total','Total Sq/Ft');
	}
	if(type == 'mts')
	{
		fMessage('name_w','Width (Mts)');
		fMessage('name_h','Length (Mts)');
		fMessage('l_total','Total Sq/Mts');
	}	
}


// Test number
function fIsDigits(inString) 
{
	var theString = trim(inString);
	if(theString.length < 1)
		return false;
	for(i = 0; i < theString.length; i++) 
	{
		if(theString.charAt(i) != '0' &&
		theString.charAt(i) != '1' &&
		theString.charAt(i) != '2' &&
		theString.charAt(i) != '3' &&
		theString.charAt(i) != '4' &&
		theString.charAt(i) != '5' &&
		theString.charAt(i) != '6' &&
		theString.charAt(i) != '7' &&
		theString.charAt(i) != '8' &&
		theString.charAt(i) != '\.' &&	
		theString.charAt(i) != '9') 
			return false;
	}
	return true;
}	 

function trim(inString) 
{
	if(inString == null) return "";
	var first;
	var last;
	
	for(first = 0; first < inString.length && inString.charAt(first) == ' '; first++);
	for(last = inString.length - 1; last > 0 && inString.charAt(last) == ' '; last--);
	
	if(last < first) return "";				
	return inString.substring(first, last + 1);
}

function formatNR(nr, dec)
{
str = "" + Math.round(eval(nr) * Math.pow(10,dec));
while(str.length < dec)
	str = "0" + str;
decidx = str.length - dec;
tmp = str.substring(0,decidx);
if(tmp == '')
	tmp = '0';
if(dec > 0)
	tmp = tmp + '.' + str.substring(decidx, str.length);
return(tmp);
}
