// JavaScript Document
// Color Simulator Scripts for new 2007 UCoat It.com 
// Authored for UCoat It America, LLC - SPB 05/25/07

//----------------------------------------------------------------------------BEGIN FUNCTION
function getColornum(){
	var finish = document.picker.storedfin.value;
	var tilecolor = document.picker.storedclr.value;
	var uflekcolor = document.picker.storedflk.value;
	var fpicsrc = (finish + tilecolor + uflekcolor);
	return fpicsrc;
}//---------------------------------------------------------------------------END FUNCTION
//----------------------------------------------------------------------------BEGIN FUNCTION
function getDescription(){
	var finishes=new Array('','',' with UGloss-AF',' with UFlek-AF', 'UltraLife');
	var finishdesc=new Array('','solid color, satin','solid color, high-gloss','decorative flake, high-gloss');
	var colors=new Array('','Light Gray','Medium Gray','Beige','Medium Blue','Tile Red','Antique White','Black');
	var glosscolors=new Array('','Light Gray','Medium Gray','Beige','Medium Blue','Tile Red','Bright White','Black');
	var flakes=new Array('','Colonial','Deco','Dove','Granite','Heritage','Pacific','Turf','Canyon','Venetian');
	var desc_string='';
	var colorcode=getColornum();
	var finishnum=colorcode.substring(0,1); finishnum=parseFloat(finishnum);
	var colornum=colorcode.substring(1,2); colornum=parseFloat(colornum);
	var fleknum=colorcode.substring(2,3); fleknum=parseFloat(fleknum);

	if (finishnum==4){
		desc_string='<p class="descheader">UCoat '+colors[colornum]+' with '+flakes[fleknum]+ ' ' +finishes[finishnum];}
	else{
		desc_string='<p class="descheader">UCoat '+colors[colornum]+' '+finishes[finishnum]+' '+flakes[fleknum];}
	
	if (finishnum==1){desc_string=desc_string+'&mdash; solid color, satin finish';}
	if (finishnum==2){desc_string=desc_string+' '+glosscolors[colornum]+'&mdash; high-gloss finish';}
	if (finishnum==3){desc_string=desc_string+'&mdash; high-gloss, decorative flake finish';}
	if (finishnum==4){desc_string=desc_string+'&mdash; high-density, decorative flake finish';}

	if(finishnum==3 || finishnum==4){if(fleknum==0){desc_string='<p class="descheader" style="color:#FFFF00;">Please choose a flake color for your '+colors[colornum]+' base.</p>'}}
	if(colornum==0){desc_string='<p class="descheader" style="color:#FFFF00;">Please choose a base color to render finish</p>'}
	
	return desc_string;
}//---------------------------------------------------------------------------END FUNCTION
//------------------------------------------------------------------------------BEGIN FUNCTION
function showSample(){
	var finish = document.picker.storedfin.value;
	var tilecolor = document.picker.storedclr.value;
	var uflekcolor = document.picker.storedflk.value;
	
	if(tilecolor==0){finish=0; uflekcolor=0;}
	if(finish==3 || finish==4){//check for addflake
		if(uflekcolor==0 && tilecolor!=0){finish=2;}}
		
	var fpicsrc = (finish + tilecolor + uflekcolor);
	
	var garagefloor = document.getElementById('garagepic');
	garagefloor.src='../imgs/simulator/floors/' + fpicsrc + '.jpg';
}//-----------------------------------------------------------------------------END OF FUNCTION
//------------------------------------------------------------------------------BEGIN FUNCTION
function updateFinish(a, b){
	var finishval;
	var colorval, flekval;
	var picker = document.getElementById('picker');
	var flaketable = document.getElementById('flakes');
	var flakeshade = document.getElementById('flakeshade');
	//get val#1 finish type
	for (i=0; i<picker.topoption.length; i++){
		if(picker.topoption[i].checked){finishval=i+1;}
	}
	 if(finishval>0){picker.storedfin.value=finishval;}else{picker.storedfin.value=1;}
	//get val#2 color type
	if(a!=0){picker.storedclr.value=a;}
	//get val#3 flake color
	if(b!=0){picker.storedflk.value=b;}
	if(finishval==1 || finishval==2){//clear flake, disable flake option
		picker.storedflk.value=0;
		flaketable.style.display='none';
		flakeshade.style.display='';}
	if(finishval==3 || finishval==4){//enable flake option
		
		flaketable.style.display='';
		flakeshade.style.display='none';}
		//alert(picker.storedfin.value+picker.storedclr.value+picker.storedflk.value);
	highlightDivs();
	showSample();
	updateDesc();
}//-----------------------------------------------------------------------------END FUNCTION
//------------------------------------------------------------------------------BEGIN FUNCTION
function updateDesc(){
	var desc='<table border="0" cellspacing="0" width="600" height="28" cellpadding="0"><tr valign="top"><td class="sim_desc">'+getDescription()+'</td></tr></table>';
	
	var tilesample='<table border="0" cellspacing="0" width="120" cellpadding="0"><tr><td><img src="../imgs/simulator/sampletiles/'+getColornum()+'.jpg" alt="" width="120" height="120"></td></tr></table>';

var descelement=document.getElementById('simulatordesc');
var tileelement=document.getElementById('cartop');
var desccoords=findPos(descelement);
var tilecoords=findPos(tileelement);
var simdesc=document.getElementById('simdesc');
var sampletile=document.getElementById('sampletile');

if(navigator.family =="nn4") {
	document.simdesc.document.write(desc);
	document.simdesc.document.close();
	document.simdesc.left=desccoords.curleft+2;
	document.simdesc.top=desccoords.curtop;
	document.sampletile.document.write(tilesample);
	document.sampletile.document.close();
	document.sampletile.left=tilecoords.curleft+456;
	document.sampletile.top=tilecoords.curtop+24;
	}
else if(navigator.family =="ie4" || navigator.family =="gecko"){
	simdesc.innerHTML=desc;
	simdesc.style.left=desccoords.curleft+2+'px';
	simdesc.style.top=desccoords.curtop+'px';
	sampletile.innerHTML=tilesample;
	sampletile.style.left=tilecoords.curleft+456+'px';
	sampletile.style.top=tilecoords.curtop+24+'px';
	}
}//-----------------------------------------------------------------------------END FUNCTION


//------------------------------------------------------------------------------BEGIN FUNCTION
function highlightDivs(){
	var picker=document.getElementById('picker');
	var hi_color=parseFloat(picker.storedclr.value);
	var hi_finish=parseFloat(picker.storedfin.value);
	var flk_finish=parseFloat(picker.storedflk.value);
	//check ucoat swatches
	for(i=1; i<8; i++){
		var colordiv=document.getElementById('c'+i);
		if(hi_color==i){colordiv.className='framepic_h';}else{colordiv.className='framepic';}
	}
	//check finish divs
	for(i=1; i<5; i++){
		var findiv=document.getElementById('fin'+i);
		if(hi_finish==i){findiv.className='bottomborder_h';}else{findiv.className='bottomborder';}
	}
	
	//check finish divs
	for(i=1; i<9; i++){
		var flkdiv=document.getElementById('f'+i);
		if(flk_finish==i){flkdiv.className='framepic_h';}else{flkdiv.className='framepic';}
	}
}//-----------------------------------------------------------------------------END FUNCTION

/*//------------------------------------------------------------------------------BEGIN FUNCTION
function simthrowEst(){
	var fin=document.picker.storedfin.value;
	var clr=document.picker.storedclr.value;
	var flk=document.picker.storedflk.value;
	var myquery='?fin='+fin+'&clr='+clr+'&flk='+flk;
	document.location='estimator.htm'+myquery;
}//-----------------------------------------------------------------------------END FUNCTION*/
