
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(
'Ardennes Grey',
'Ardennes Grey',
'Brittany Beige',
'Brownstone Red',
'Oxford Charcoal',
'Sheffield',
'Essex',
'Bluestone',
'Ardennes Grey',
'Bluestone',
'Brittany Beige',
'Brownstone Red',
'Lannon',
'Lannon Sand',
'Moss',
'Autumn Blend',
'Buff',
'Cedar Red',
'Charcoal',
'Lakeshore',
'Pewter',
'Ardennes Grey',
'Brittany Beige',
'Brownstone Red'
);
var arrColorsImg = new Array(
'images/colors/tiles/bergerac/2_18_ARDENNESGREY.jpg',
'images/colors/tiles/bergerac/Berg4pc_ArdennesGrey.jpg',
'images/colors/tiles/bergerac/Berg4pc_BrittanyBeige.jpg',
'images/colors/tiles/bergerac/Berg4pc_BrwnstoneRed.jpg',
'images/colors/tiles/celtikwall/IMG_1455_CELT-OX-CHARCOAL.jpg',
'images/colors/tiles/celtikwall/IMG_1456_CELT-SHEFFIELD.jpg',
'images/colors/tiles/celtikwall/IMG_1459_CELT-ESSEX.jpg',
'images/colors/tiles/dublincobble/BE_MegaBerg_SUB_Bluestone.jpg',
'images/colors/tiles/dublincobble/Dub4pc_ArdennesGrey.jpg',
'images/colors/tiles/dublincobble/Dub4pc_Bluestone.jpg',
'images/colors/tiles/dublincobble/Dub4pc_BrittanyBeige.jpg',
'images/colors/tiles/dublincobble/Dub4pc_BrwnstoneRed.jpg',
'images/colors/tiles/dublincobble/Dub4pc_Lannon.jpg',
'images/colors/tiles/dublincobble/Dub4pc_Lannonsand.jpg',
'images/colors/tiles/dublincobble/Dub4pc_Moss.jpg',
'images/colors/tiles/hollandpavers/UL9000AutumnBlend.jpg',
'images/colors/tiles/hollandpavers/UL9000Buff.jpg',
'images/colors/tiles/hollandpavers/UL9000CedarRed.jpg',
'images/colors/tiles/hollandpavers/UL9000Charcoal.jpg',
'images/colors/tiles/hollandpavers/UL9000Lakeshore.jpg',
'images/colors/tiles/hollandpavers/UL9000Pewter.jpg',
'images/colors/tiles/megabergerac/Mega3pc_ArdennesGrey.jpg',
'images/colors/tiles/megabergerac/Mega3pc_BrittanyBeige.jpg',
'images/colors/tiles/megabergerac/Mega3pc_BrwnstoneRed.jpg'
);

for(i=0;i<arrColorsImg.length;i++)
{
 	img = new Image(77,77);
  	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/pattern/bergerac1.gif",
"images/pattern/bergerac2.gif",
"images/pattern/bergerac3.gif",
"images/pattern/bergerac4.gif",
"images/pattern/Dublin1.gif",
"images/pattern/Dublin2.gif",
"images/pattern/Dublin3.gif",
"images/pattern/Dublin4.gif",
"images/pattern/Dublin5.gif",
"images/pattern/Dublin6.gif",
"images/pattern/holland1.gif",
"images/pattern/holland2.gif",
"images/pattern/holland3.gif",
"images/pattern/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);
}
