var manufac = navigator.appName;
function newwin(picName)
{
	
	window.open(picName,'picwin','width=400,height=400');
}


function showConfig(iHtml,showLarge,howFar,dHtml)
{
	var inDiv;
	var isLarge;
	var isSmall;
	
	if (manufac == "Netscape")
	{	
		inDiv = document.getElementById("configDiv").style;
	}
	else
	{
		inDiv = configDiv.style;
	}
	
	//pull the px out of the height
	var dHeight = inDiv.height + "!";
	dHeight = dHeight.replace(/px!/g,"");
	dHeight = dHeight - 0;
	
	//escape the quotes in the innerhtml
	iHtml = iHtml.replace(/\"/g,"\\\"");


	//now check if it is supposed to show big
	if (showLarge == 1 && (dHeight - 0) < howFar)
	{
		inDiv.height = dHeight + 1;
		my_timeout = setTimeout("showConfig(\""+iHtml+"\","+showLarge+","+howFar+",\""+dHtml+"\");", .00001);	
	}
	
	//after it has been expanded show the contents and set the timer to shrink it
	if (showLarge == 1 && (dHeight - 0) >= howFar)
	{
		//after 3 seconds call the function to minimize the configurator
		my_timeout = setTimeout("shrinkConfig(\""+iHtml+"\","+showLarge+","+howFar+",\""+dHtml+"\");", 3000);
		
		//it is expanded now it is time to escape the escape characters 
		iHtml = iHtml.replace(/\\/g,"");
		if (manufac == "Netscape")
		{
			document.getElementById("configDiv").innerHTML = iHtml;
		}
		else
		{
			configDiv.innerHTML = iHtml;
		}	
	}
	
	//if this is an initial load then 
	if (showLarge == 0)
	{
		if (manufac == "Netscape")
		{
			document.getElementById("configDiv").innerHTML = dHtml;
		}
		else
		{
			configDiv.innerHTML = dHtml;
		}
	}
	
	
}

function shrinkConfig(iHtml,showSmall,howFar,dHtml)
{
	var inDiv;
	var isLarge;
	var isSmall;
	
	if (manufac == "Netscape")
	{	
		inDiv = document.getElementById("configDiv").style;
	}
	else
	{
		inDiv = configDiv.style;
	}
	
	//pull the px out of the height
	var dHeight = inDiv.height + "!";
	dHeight = dHeight.replace(/px!/g,"");
	dHeight = dHeight - 0;
	
	//escape the quotes in the innerhtml
	iHtml = iHtml.replace(/\"/g,"\\\"");
	//ditch the contents
	if (manufac == "Netscape")
	{
		document.getElementById("configDiv").innerHTML = "";
	}
	else
	{
		configDiv.innerHTML = "";
	}
	
	//reduce the size until it is at rest	
	if(dHeight > 12)
	{
		inDiv.height = dHeight - 1;
		my_timeout = setTimeout("shrinkConfig(\""+iHtml+"\","+showSmall+","+howFar+",\""+dHtml+"\");", .00001);	
	}
	else
	{
		//ditch the contents
		if (manufac == "Netscape")
		{
			document.getElementById("configDiv").innerHTML = dHtml;
		}
		else
		{
			configDiv.innerHTML = dHtml;
		}
	}

}

function chkAdd(sessionState)
{

	var WidthExists = eval(document.productForm["matWidth"]);
	var UnitExists = eval(document.productForm["matUnit"]);
	var DepthExists = eval(document.productForm["matDepth"]);
	var SizeExists = eval(document.productForm["matSize"]);
	var NrExists = eval(document.productForm["matNr"]);
	var HeightExists = eval(document.productForm["matHeight"]);
	var LeftExists = eval(document.productForm["matLeft"]);
	var CasterExists = eval(document.productForm["matCaster"]);
	var LcolorExists = eval(document.productForm["matLcolor"]);
	var McolorExists = eval(document.productForm["matMcolor"]);
	var errorDiv;
	var messageDiv;
	//comment this block out after the ppage2 has been debugged
	// if (manufac == "Netscape")
	//{
	//	 errorDiv = document.getElementById("errorunder").style;
	//	 messageDiv = document.getElementById("errorcontent");
	//}
	//else
	//{
	//	errorDiv = errorunder.style;
	//	messageDiv = errorcontent;
	//}	

	
	if (WidthExists)
	{
		if (getRadioValue("productForm","matWidth") == "")
		{
			errorDiv.visibility = 'visible';
			errorDiv.position = 'absolute';
			errorDiv.left = '445px';
			errorDiv.top = '803px';
			return false;
		}	
	}
	if (UnitExists)
	{
		if (getRadioValue("productForm","matUnit") == "")
		{
			errorDiv.visibility = 'visible';
			errorDiv.position = 'absolute';
			errorDiv.left = '445px';
			errorDiv.top = '803px';
			return false;
		}	
	}
	if (DepthExists)
	{
		if (getRadioValue("productForm","matDepth") == "")
		{
			errorDiv.visibility = 'visible';
			errorDiv.position = 'absolute';
			errorDiv.left = '445px';
			errorDiv.top = '803px';
			return false;
		}	
	}
	if (SizeExists)
	{
		if (getRadioValue("productForm","matSize") == "")
		{
			errorDiv.visibility = 'visible';
			errorDiv.position = 'absolute';
			errorDiv.left = '445px';
			errorDiv.top = '803px';
			return false;
		}	
	}
	if (NrExists)
	{
		if (getRadioValue("productForm","matNr") == "")
		{
			errorDiv.visibility = 'visible';
			errorDiv.position = 'absolute';
			errorDiv.left = '445px';
			errorDiv.top = '803px';
			return false;
		}	
	}
	if (HeightExists)
	{
		if (getRadioValue("productForm","matHeight") == "")
		{
			errorDiv.visibility = 'visible';
			errorDiv.position = 'absolute';
			errorDiv.left = '445px';
			errorDiv.top = '803px';
			return false;
		}	
	}
	if (LeftExists)
	{
		if (getRadioValue("productForm","matLeft") == "")
		{
			errorDiv.visibility = 'visible';
			errorDiv.position = 'absolute';
			errorDiv.left = '445px';
			errorDiv.top = '803px';
			return false;
		}	
	}
	if (CasterExists)
	{
		if (getRadioValue("productForm","matCaster") == "")
		{
			errorDiv.visibility = 'visible';
			errorDiv.position = 'absolute';
			errorDiv.left = '445px';
			errorDiv.top = '803px';
			return false;
		}	
	}
	if (LcolorExists)
	{
		if (getRadioValue("productForm","matLcolor") == "")
		{
			errorDiv.visibility = 'visible';
			errorDiv.position = 'absolute';
			errorDiv.left = '445px';
			errorDiv.top = '803px';
			return false;
		}	
	}
	if (McolorExists)
	{
		if (getRadioValue("productForm","matMcolor") == "")
		{
			errorDiv.visibility = 'visible';
			errorDiv.position = 'absolute';
			errorDiv.left = '445px';
			errorDiv.top = '803px';
			return false;
		}	
	}

	if (sessionState == 2)
	{
		var iConfirm = confirm("You have items in your configuration that are compatible with your current cart. Selecting a new cart configuration will remove your items!");
		if (iConfirm == false)
		{
			return false;
		}
	}
	//return false;
}


//function to swap the line art based on user decisions
function swapLineArt(Designator,imgSwap,isBench)
{
	if (Designator == "AA02" || Designator == "AA03")
	{
	var imgCell = eval("document.secondcell");
	}
	else
	{
	var imgCell = eval("document." + imgSwap);
	}
	
	var img2Change;
	var perspectivechange;
	if (isBench == "0") 
	{
		//first make sure the objects exist
		var WidthExists = eval(document.productForm["matWidth"]);
		var UnitExists = eval(document.productForm["matUnit"]);
		var DepthExists = eval(document.productForm["matDepth"]);
		var SizeExists = eval(document.productForm["matSize"]);
		var NrExists = eval(document.productForm["matNr"]);
		var HeightExists = eval(document.productForm["matHeight"]);
		var LeftExists = eval(document.productForm["matLeft"]);
		img2Change = "images/lineart/" + Designator;
		//validate and write the string
		if(WidthExists)
		{
			if (Designator != getRadioValue('productForm','matWidth'))
			{
				img2Change = img2Change + getRadioValue('productForm','matWidth');
			}
		}
		if(UnitExists)
		{img2Change = img2Change + getRadioValue('productForm','matUnit');}
		if(DepthExists)
		{img2Change = img2Change + getRadioValue('productForm','matDepth');}
		if(SizeExists)
		{
			//check to see if this convoi
			if (Designator == "BU" && imgSwap == 'secondcell')
			{
				img2Change = "images/lineart/" + Designator + "Perspective_" + getRadioValue('productForm','matSize');
			}
			else
			{
				img2Change = img2Change + getRadioValue('productForm','matSize');	
			}
		}
		if(NrExists)
		{img2Change = img2Change + getRadioValue('productForm','matNr');}
		if(HeightExists)
		{
			if (Designator != getRadioValue('productForm','matHeight'))
			{
				img2Change = img2Change + getRadioValue('productForm','matHeight');
			}
		}
		
		if (LeftExists)
		{
		img2Change = img2Change + getRadioValue('productForm','matLeft');
		}
		
		img2Change = img2Change + ".gif";
		imgCell.src = img2Change;
	}
	else
	{
		img2Change = "images/lineart/" + getRadioValue('productForm','matDepth') + getRadioValue('productForm','matWidth') + getRadioValue('productForm','matHeight') + ".gif";
		perspectivechange = "images/lineart/SPerspective_" + getRadioValue('productForm','matHeight') + ".gif";
		document.firstcell.src = img2Change;
		document.secondcell.src = perspectivechange;
	}
	
	//rack system?
	if (Designator == "R")
	{
		perspectivechange = "images/lineart/RPerspective" + getRadioValue('productForm','matUnit') + ".gif";
		document.perspec.src = perspectivechange;
	
	}
}

//function to return the value from a selected radio button
function getRadioValue(formName,radioName)
{
	var loopRadio = eval("document." + formName + "." + radioName);

	if (eval(loopRadio[0]))
	{
		for (counter = 0; counter < loopRadio.length;counter++)
		{
			if (loopRadio[counter].checked)
			{
				return loopRadio[counter].value;	
			}	
		}
	}
	else
	{
		if (loopRadio.checked)
		{
			return loopRadio.value;
		}
	}
	return "";
}


function showName(colorName,pmid)
{
	var typeString;
	
	if (pmid == 54)
	{
		typeString = "Standard Fabric:";
	}
	else
	{
		typeString = "Laminate:";
	}
	
	if (manufac == "Netscape")
	{
		document.getElementById("lamNameText").innerHTML = typeString + " <strong>" + colorName + "</strong>";
	}
	else
	{
		lamNameText.innerHTML = typeString + " <strong>" + colorName + "</strong>";
	}	
	if (colorName != '' && pmid == 54)
	{
		showPremName('',pmid);
	}
}

function showPremName(colorName,pmid)
{
	var typeString;
	
	if (pmid == 54)
	{
		typeString = "Premium Fabric:";
	}
	else
	{
		typeString = "Premium Laminate:";
	}
	
	if (manufac == "Netscape")
	{
		document.getElementById("premNameText").innerHTML = typeString + " <strong>" + colorName + "</strong><br><font size=1>Additional $50.";
	}
	else
	{
		premNameText.innerHTML = typeString + " <strong>" + colorName + "</strong><br><font style='font-size:8px;'>Additional $50.";
	}
	if (colorName != '' && pmid == 54)
	{	
		showName('',pmid);
	}
}

function showNameMetal(colorName,pmid)
{
	if (pmid == 54)
	{
		typeString = "Laminate:";
	}
	else
	{
		typeString = "Metal:";
	}

	if (manufac == "Netscape")
	{
		document.getElementById("MetalNameText").innerHTML = typeString + " <strong>" + colorName + "</strong>";
	}
	else
	{
		MetalNameText.innerHTML = typeString + " <strong>" + colorName + "</strong>";
	}
	
}

function showLabel(lblText, DivName)
{
	if (manufac == "Netscape")
	{
	var dName = document.getElementById(DivName);
	}
	else
	{
	var dName = eval(DivName);
	}
	
	//alert("foo" + dName);
	dName.innerHTML = "<strong>" + lblText + "</strong>";
}

function accessoryOpen(divName)
{

	if (manufac == "Netscape")
	{
		var dname = document.getElementById(divName);
		dname.style.visibility = 'visible';
		//document.getElementById("accessdiv").style.visibility = 'hidden';
	}
	else
	{
		var dname = eval(divName + ".style");
		dname.visibility = 'visible';
		//accessdiv.style.visibility = 'hidden';
	
	}
	
}

function accessoryClose(divName)
{

	if (manufac == "Netscape")
	{
		var dname = document.getElementById(divName);
		dname.style.visibility = 'hidden';
		//document.getElementById("accessdiv").style.visibility = 'visible';
	}
	else
	{
		var dname = eval(divName + ".style");
		dname.visibility = 'hidden';
		//accessdiv.style.visibility = 'visible';
}
}



var lcId = new Date().getTime();
var flashProxy = new FlashProxy(lcId, 'JavaScriptFlashGateway.swf');

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else
  {
    return document.getElementById(movieName);
  }
}

//parameters are pic to show, name of the movie, name of the button to switch,number of buttons, name of description to show
function transferItemToFlash(picString,FlashMovie,buttonName,buttonCount,description)
{
	//change the pic in the flash
	var flashMovie=getFlashMovieObject(FlashMovie);
	
    flashMovie.SetVariable("/:picName",picString);
	flashProxy.call("changeString");
	
	//change the button to on and reset the rest
	
	if (manufac == "Netscape")
	{
		var descriptionChange = document.getElementById(description).style;
		var buttonChange = document.getElementById(buttonName);
	}
	else
	{
		var descriptionChange = eval(description + ".style");
		var buttonChange = eval(buttonName);
	}
	
	var buttonLoop;
	var divLoop;
	for(i=1;i<=buttonCount;i++)
	{
			
		if (manufac == "Netscape")
		{
			divLoop = document.getElementById("descDiv" + i).style;
			buttonLoop = document.getElementById("button" + i);
			buttonLoop.className = 'stndButton';
		}
		else
		{
			divLoop = eval("descDiv" + i + ".style");
			buttonLoop = eval("button" + i);
			buttonLoop.className = 'stndButton';
		}
		
		divLoop.visibility = 'hidden';	
	}
	
	buttonChange.className = 'stndButtonSelected';
	descriptionChange.visibility = 'visible';
		
}

function transferItemInsteadOfFlash(picString,FlashMovie,buttonName,buttonCount,description)
{
	document.getElementById("pictCont").innerHTML = "<img src='"+picString+"' width='400' height='400'>";
		
	//change the button to on and reset the rest
	var buttonChange = document.getElementById(buttonName);
	var descriptionChange = document.getElementById(description).style;
	
	var buttonLoop;
	var divLoop;
	for(i=1;i<=buttonCount;i++)
	{
		buttonLoop = document.getElementById("button" + i);
		buttonLoop.className = 'stndButton';	
		
		divLoop = document.getElementById("descDiv" + i).style;
		
		divLoop.visibility = 'hidden';	
	}
	
	
	buttonChange.className = 'stndButtonSelected';
	descriptionChange.visibility = 'visible';
}


function ChangeMetalColor(mColor,mHex,cName,mName)
{
     var flashMovie=getFlashMovieObject("colorConcept");
     var red, drkred, lghtred, offsetred;
     var green, drkgreen, lghtgreen, offsetgreen;
     var blue, drkblue, lghtblue, offsetblue;
     red = hextorgb(mHex,"R");
     green = hextorgb(mHex, "G");
     blue = hextorgb(mHex, "B");
     //config for security carts
     
	//config for security carts
	if (mName == 43)
	{
	    /*
	    IDs of radio buttons.,
	    ctl00_cph_content_rb_00_1
        ctl00_cph_content_rb_11_1

        ctl00_cph_content_rb_00_2
        ctl00_cph_content_rb_11_2
        */
      
      	//If the first metal color has been selected, also select the first laminate color.
		if (mHex == '333333' && document.aspnetForm.ctl00_cph_content_rb_00_1.checked == true)
		{
			ChangeLaminateColor('BK','333333',cName, mName);
		    ChangeLabelColor('ctl00_cph_content_lbl2', 'Laminate: ', 'BLACK');
		    document.aspnetForm.ctl00_cph_content_rb_00_2.checked = true;
		   /* showName('BLACK'); */
		}		    		
  
        //If the second metal color has been selected, also select the second laminate color.
		if (mHex == 'CCCCCC' && document.aspnetForm.ctl00_cph_content_rb_11_1.checked == true)
		{
			ChangeLaminateColor('FG','ABA59F',cName, mName);
		    ChangeLabelColor('ctl00_cph_content_lbl2', 'Laminate: ', 'FOG');
		    document.aspnetForm.ctl00_cph_content_rb_11_2.checked = true;
		   /* showName('BLACK'); */
		}		
	}
   
     //now make the offset rgb for the corners etc....
     if (red - 75 > 0)
     {
		offsetred = red - 75;
     }
     else
     {
		offsetred = 0;
     }
     //green
     if (green - 75 > 0)
     {
		offsetgreen = green - 75;
     }
     else
     {
		offsetgreen = 0;
     }
     //blue
     if (blue - 75 > 0)
     {
		offsetblue = blue - 75;
     }
     else
     {
		offsetblue = 0;
     }
     
     //For Elevate Adjusta, change the "modelName" to use Elevate Corner.
     if (mName == 120)
     {
        mName = 59;
     }
     
     //alert("name: " + mName);
     flashMovie.SetVariable("/:metalTubeColor",mColor);
     flashMovie.SetVariable("/:modelName",mName);
     flashMovie.SetVariable("/:rOffsetMetal",offsetred);
     flashMovie.SetVariable("/:gOffsetMetal",offsetgreen);
     flashMovie.SetVariable("/:bOffsetMetal",offsetblue);
}

function ChangeLaminateColor(mColor,mHex,cName, mName)
{
     var flashMovie=getFlashMovieObject("colorConcept");
     var red, drkred, lghtred, offsetred;
     var green, drkgreen, lghtgreen, offsetgreen;
     var blue, drkblue, lghtblue, offsetblue;
		
	//config the metal colors for carts
	if (mName == 22 || mName == 23 || mName == 24 || mName == 25 || mName == 26 || mName == 27 || mName == 28 || mName == 29 || mName == 31 || mName == 30)
	{
		//color for the light grey, bone
		if (mHex == 'C6C5CD' || mHex == 'EBE9D9')
		{
			ChangeMetalColor('PG','C5B7AE',cName,mName);
		}
		if (mHex == '333333' || mHex == 'DEC4A0')
		{
			ChangeMetalColor('BK','333333',cName,mName);
		}
	}
	
	//config for security carts
	if (mName == 43)
	{
	    //If the first laminate color has been selected, also select the first metal color.
		if (mHex == '333333' && document.aspnetForm.ctl00_cph_content_rb_00_2.checked == true)
		{
			ChangeLaminateColor('FG','ABA59F',cName, mName);
		    ChangeLabelColor('ctl00_cph_content_lbl1', 'Metal: ', 'BLACK');
		    document.aspnetForm.ctl00_cph_content_rb_00_1.checked = true;
		   /* showName('BLACK'); */
		}
		 
		//If the second laminate color has been selected, also select the second metal color.
		if (mHex == 'ABA59F' && document.aspnetForm.ctl00_cph_content_rb_11_2.checked == true)
		{
			ChangeLaminateColor('BK','333333',cName, mName);
		    ChangeLabelColor('ctl00_cph_content_lbl1', 'Metal: ', 'SILVER METALLIC');
		    document.aspnetForm.ctl00_cph_content_rb_11_1.checked = true;
		   /* showName('BLACK'); */
		}		    
	}
	
     red = hextorgb(mHex,"R");
     green = hextorgb(mHex, "G");
     blue = hextorgb(mHex, "B");
     
     //now make the lighter colors
     if (red + 20 < 255)
     {	
		lghtred = red + 20;
     }
     else
     {
		lghtred = 255;
     }
     //blue
     if (blue + 20 < 255)
     {
		lghtblue = blue + 20;
     }
     else
     {
		lghtblue = 255;
     }
     //green
     if (green + 20 < 255)
     {
		lghtgreen = green + 20;
     }
     else
     {
		lghtgreen = 255;
     }
     
     //now make the darker color
     if (red - 25 > 0)
     {
		drkred = red - 25;
     }
     else
     {
		drkred = red;
     }
     //blue
     if (blue - 25 > 0)
     {
		drkblue = blue - 25;
     }
     else
     {
		drkblue = blue;
     }
     //green
     if (green - 25 > 0)
     {
		drkgreen =  green - 25;
     }
     else
     {
		drkgreen = green;
     }
     
     //now make the offset rgb for the corners etc....
     if (red - 75 > 0)
     {
		offsetred = red - 75;
     }
     else
     {
		offsetred = 0;
     }
     //green
     if (green - 75 > 0)
     {
		offsetgreen = green - 75;
     }
     else
     {
		offsetgreen = 0;
     }
     //blue
     if (blue - 75 > 0)
     {
		offsetblue = blue - 75;
     }
     else
     {
		offsetblue = 0;
     }
     
    //For Elevate Adjusta, change the "modelName" to use Elevate Corner.
     if (mName == 120)
     {
        mName = 59;
     }
     
     //alert("foo lam");
     flashMovie.SetVariable("/:laminateColor","0x"+mHex);
     flashMovie.SetVariable("/:laminateDrkColor","0x"+rgbtohex(drkred,drkgreen,drkblue));
     flashMovie.SetVariable("/:laminateLgtColor","0x"+rgbtohex(lghtred,lghtgreen,lghtblue));
     flashMovie.SetVariable("/:rOffset",offsetred);
     flashMovie.SetVariable("/:gOffset",offsetgreen);
     flashMovie.SetVariable("/:bOffset",offsetblue);
     flashMovie.SetVariable("/:dLamName",cName);
     flashMovie.SetVariable("/:modelName",mName);
}

//hex and RGB formatting and reformatting
function hextorgb(hexdec,clr) 
{
	n1 = replacevals(hexdec.charAt(0));
	n2 = replacevals(hexdec.charAt(1));
	n3 = replacevals(hexdec.charAt(2));
	n4 = replacevals(hexdec.charAt(3));
	n5 = replacevals(hexdec.charAt(4));
	n6 = replacevals(hexdec.charAt(5));

	var returnval = ((16 * n1) + (1 * n2));
	var returnval1 = 16 * n3 + n4;
	var returnval2 = 16 * n5 + n6;
	
	if (clr == "R")
	{
		return ((16 * n1) + (1 * n2))
	}
	
	if (clr == "G")
	{
		return ((16 * n3) + (1 * n4))
	}
	
	if (clr == "B")
	{
		return ((16 * n5) + (1 * n6))
	}

	//return ((16 * n1) + (1 * n2))+","+((16 * n3) + (1 * n4))+","+((16 * n5) + (1 * n6));
}

function replacevals(n) 
{
	if (n == "a" || n == "A") { n = "10"; }
	if (n == "b" || n == "B") { n = "11"; }
	if (n == "c" || n == "C") { n = "12"; }
	if (n == "d" || n == "D") { n = "13"; }
	if (n == "e" || n == "E") { n = "14"; }
	if (n == "f" || n == "F") { n = "15"; }

	return n
}

function replacevalsreverse(thenum) 
{
	if (thenum == 10) { thenum = "A"; }
	if (thenum == 11) { thenum = "B"; }
	if (thenum == 12) { thenum = "C"; }
	if (thenum == 13) { thenum = "D"; }
	if (thenum == 14) { thenum = "E"; }
	if (thenum == 15) { thenum = "F"; }

	return thenum;
}

function rgbtohex(num1, num2, num3) 
{
	return calc10to16(num1) + calc10to16(num2) + calc10to16(num3);
}

function calc10to16(num) 
{
	if (num < 16) 
	{
		var thenum = replacevalsreverse(num);
		return thenum;
	}
	else 
	{
		var themod=num % 16;
		var thenum=((num-themod) / 16);
		thenum = replacevalsreverse(thenum)
		themod = replacevalsreverse(themod)

		return ""+thenum+themod
	}
}



