
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/colors/cobble/small/toscana-cobble.jpg",
"images/colors/cobble/small/sierrablend.jpg",
"images/colors/cobble/small/rioblendrough.jpg",
"images/colors/cobble/small/sedonablendcobble.jpg",
"images/colors/cobble/small/lajollablendrough.jpg",
"images/colors/paver/small/desertblend.jpg",
"images/colors/paver/small/sierrablendsmooth.jpg",
"images/colors/paver/small/rioblend.jpg",
"images/colors/paver/small/sedonablendsmooth.jpg",
"images/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(
"Dublin Cobble", 
"Dublin Modular Combo", 
"Dublin Modular Square", 
"Dublin Fan", 
"Mega Bergerac Combo",
"Mega Bergerac Square",
"Holland 1",
"Keykock 1",
"Cambridge 1",
"Holland 2",
"Keykock 2",
"Cambridge 2"
);
var arrPatternsImg = new Array(
"images/pattern/cobblepats/small/1.gif",
"images/pattern/cobblepats/small/2.gif",
"images/pattern/cobblepats/small/3.gif",
"images/pattern/cobblepats/small/4.gif",
"images/pattern/cobblepats/small/5.gif",
"images/pattern/cobblepats/small/6.gif",
"images/pattern/paverpats/small/basketweave.gif",
"images/pattern/paverpats/small/california-weave.gif",
"images/pattern/paverpats/small/common.gif",
"images/pattern/paverpats/small/dutch-bond.gif",
"images/pattern/paverpats/small/georgia-stack.gif",
"images/pattern/paverpats/small/herringbone.gif"
);
var arrPatternsDim = new Array(
"(60mm)",
"(60mm)",
"(60mm)",
"(60mm)",
"(80mm)",
"(80mm)",
"(60mm)",
"(60mm)",
"(6x6')",
"(80mm)",
"(80mm)",
"(6x9')"
) 
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=550,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','Height (Ft)');
		fMessage('l_total','Total Sq/Ft');
	}
	if(type == 'mts')
	{
		fMessage('name_w','Width (Mts)');
		fMessage('name_h','Height (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);
}
