﻿var lastWhiteColorValue = 0;
var lastLightColorValue = 1;
var lastDarkColorValue = 9;

function instantQuoteColorChanged(obj)
{
	colorGroupChanged(getColorGroup(obj.options[obj.selectedIndex].text), obj.value);
}

function clickColor(obj)
{
    var colorValue = obj.id.replace("color_", "");
    var colorGroup = 'dark';
    if(colorValue == "0")
    {
        colorGroup = 'white';
    }
    
    if((parseInt(colorValue) > 0) && (parseInt(colorValue) < 9))
    {
        colorGroup = 'light';
    }
    
    colorGroupChanged(colorGroup, colorValue);
    
}

function getColorGroup(colorText)
{
	if(colorText == 'White')
	{
		return 'white';
	}
	
	for(var i = 0; i < ArrayOfTShirtColorItemlightColors.length; i++)
	{
		if(ArrayOfTShirtColorItemlightColors[i].Color.replace(/_/, " ") == colorText)
		{
			return 'light';
		}
	}
	return 'dark';
}

function drawTables()
{
	var frontTable = document.getElementById("frontTable");
	var backTable = document.getElementById("backTable");
	frontTable.style.display = 'none';
	backTable.style.display = 'none';	
	
	var controlInstantQuoteTShirts_selectColor = document.getElementById("controlInstantQuoteTShirts_selectColor");
	var controlInstantQuoteTShirts_selectSides = document.getElementById("controlInstantQuoteTShirts_selectSides");
	var controlInstantQuoteTShirts_selectFrontColors = document.getElementById("controlInstantQuoteTShirts_selectFrontColors");
	var controlInstantQuoteTShirts_selectBackColors = document.getElementById("controlInstantQuoteTShirts_selectBackColors");
	
	var color = getColorGroup(controlInstantQuoteTShirts_selectColor.options[controlInstantQuoteTShirts_selectColor.selectedIndex].text);
	
	if(controlInstantQuoteTShirts_selectSides.value == 0)
	{
		if(color == 'white')
		{
			frontTable.innerHTML = drawTShirtsTable('front', PricingWhite, controlInstantQuoteTShirts_selectFrontColors.value);
		}
		else if(color == 'light')
		{
			frontTable.innerHTML = drawTShirtsTable('front', PricingLight, controlInstantQuoteTShirts_selectFrontColors.value);
		}
		else
		{
			frontTable.innerHTML = drawTShirtsTable('front', PricingDark, controlInstantQuoteTShirts_selectFrontColors.value);
		}
		frontTable.style.display = 'block';

	}
	else if(controlInstantQuoteTShirts_selectSides.value == 1)
	{
		if(color == 'white')
		{
			backTable.innerHTML = drawTShirtsTable('back', PricingWhite, controlInstantQuoteTShirts_selectBackColors.value);
		}
		else if(color == 'light')
		{
			backTable.innerHTML = drawTShirtsTable('back', PricingLight, controlInstantQuoteTShirts_selectBackColors.value);
		}
		else
		{
			backTable.innerHTML = drawTShirtsTable('back', PricingDark, controlInstantQuoteTShirts_selectBackColors.value);
		}
		backTable.style.display = 'block';

	}
	else
	{
		//backandfront
		if(color == 'white')
		{
			frontTable.innerHTML = drawTShirtsTable('front', PricingWhite, controlInstantQuoteTShirts_selectFrontColors.value);
		}
		else if(color == 'light')
		{
			frontTable.innerHTML = drawTShirtsTable('front', PricingLight, controlInstantQuoteTShirts_selectFrontColors.value);
		}
		else
		{
			frontTable.innerHTML = drawTShirtsTable('front', PricingDark, controlInstantQuoteTShirts_selectFrontColors.value);
		}
		
		if(color == 'white')
		{
			backTable.innerHTML = drawTShirtsTable('backandfront', PricingExtra, controlInstantQuoteTShirts_selectBackColors.value);
		}
		else if(color == 'light')
		{
			backTable.innerHTML = drawTShirtsTable('backandfront', PricingExtra, controlInstantQuoteTShirts_selectBackColors.value);
		}
		else
		{
			backTable.innerHTML = drawTShirtsTable('backandfront', PricingExtra, controlInstantQuoteTShirts_selectBackColors.value);
		}
		
		frontTable.style.display = 'block';
		backTable.style.display = 'block';

		
	}
	
}

function drawTShirtsTable(side, arrayRef, quantity)
{
	var template = 	"<table style='width: 100%; border-color: #c0c0c0; border-width: 0; text-align: center;' cellpadding='5' cellspacing='1'>" + 
										"<tr style='background-color: #BDCBDD'>" + 
												"<td NOWRAP colspan='1' style='color: #143F85; text-align: center;'>" + 
												"<img alt='Front' src='/img/tshirts/front.gif'></td>" + 
												"<td colspan='6'>Price for artwork on <b>Front (per shirt)</b></td>" +
										"</tr>"
		if(side == 'back')									
		{
			template = 	"<table style='width: 100%; border-color: #c0c0c0; border-width: 0; text-align: center;' cellpadding='5' cellspacing='1'>" + 
										"<tr style='background-color: #BDCBDD'>" + 
												"<td NOWRAP colspan='1' style='color: #143F85; text-align: center;'>" + 
												"<img alt='Back' src='/img/tshirts/back.gif'></td>" + 
												"<td colspan='6'>Price for artwork on <b>Back (per shirt)</b></td>" +
										"</tr>";
		}
		else if(side == 'backandfront')
		{
			template = 	
			"<table style='width: 100%; border-color: #c0c0c0; border-width: 0; text-align: center;' cellpadding='5' cellspacing='1'>" + 
										"<tr style='background-color: #BDCBDD'>" + 
												"<td NOWRAP colspan='1' style='color: #143F85; text-align: center;'>" + 
												"<table style='border-color: #c0c0c0; border-width: 0' cellpadding='0' cellspacing='0'>" + 
												"<tr>" + 
										//			"<td>" + 
										//	"<font style='font-size: small'>" + 
										//	"<img alt='Front' src='/img/tshirts/front.gif'></font></td>" + 
										//			"<td style='font-weight: 700'>+</td>" + 
													"<td style='text-align:center;'>" + 
													"<img alt='back' src='/img/tshirts/back.gif'></td>" + 
												"</tr>" + 
											"</table></td>" + 
												"<td colspan='6'>Price for artwork on <b>Back (per shirt)</b></td>" +
										"</tr>";
			
							
		}
										
		template += "<tr style='font-weight: 700; color: #FFFFFF; background-color: #5995CA'>" + 
					"<td NOWRAP style='text-align: center; background-color: #99BDDF'>Quantity</td>";
					
					for(var i = 0; i < arrayRef[0].length - 1; i++)
					{
						template += "<td NOWRAP>" + (i + 1) + " Color</td>";
					}
					template += "</tr>";
					
								template += "<tr>" + 
												"<td NOWRAP style='font-weight: 700; color: #FFFFFF; background-color: #99BDDF;'>&lt; " + minimumQuantity + "</td>" + 
												"<td colspan='6' style='font-weight: 700; background-color: #FFFFFF;'>" + 
												"<a href='/pages/contactus.html'>Contact us to get a quote for less than " + minimumQuantity + " shirts</a></td>" + 
											"</tr>";
											
					var countTotal = CountTotal();						
					
					for(var i = 0; i < arrayRef.length; i++)
					{
						var flag = false;
						var color = "style='background-color: #EAEAEA'";	
						var colorFirstColumn = "style='background-color: #99BDDF'";	
						var foreColor = "";
						var foreColorFirstColumn = "style='color: #FFFFFF'";			
						
						if(i % 2 != 0)
						{
							color = "";							
						}
						
						if(i == 0)
						{
						    color = "style='background-color: #F0F0F0;'";
						    //colorFirstColumn = "style='background-color: #DFDFDF'";
						    foreColor = "style='color: #999999'";
						    //foreColorFirstColumn = "style='color: #999999'";
						}
						
						var amount = "12 - 23";
						if(i == 0)
						{
						    amount = "12 - 23";
							
							if((23 >= countTotal) && (countTotal >= 12))
							{
								flag = true;
							}
						}
						else if(i == 1)
						{
							amount = "24 - 49";
							if((49 >= countTotal) && (countTotal >= 24))
							{
								flag = true;
							}

						}
						else if(i == 2)
						{
							amount = "50 - 99";
							if((99 >= countTotal) && (countTotal >= 50))
							{
								flag = true;
							}

						}
						if(i == 3)
						{
							amount = "100 - 149";
							
							if((149 >= countTotal) && (countTotal >= 100))
							{
								flag = true;
							}							
						}
						else if(i == 4)
						{
							amount = "150 - 299";
							if((299 >= countTotal) && (countTotal >= 150))
							{
								flag = true;
							}
						}
						else if(i == 5)
						{
							amount = "300 - 549";
							if((549 >= countTotal) && (countTotal >= 300))
							{
								flag = true;
							}

						}
						else if(i == 6)
						{
							amount = "550 - 999";
							if((999 >= countTotal) && (countTotal >= 550))
							{
								flag = true;
							}							
						}
						else if(i == 7)
						{
							amount = "1000 - 3000";
							if((3000 >= countTotal) && (countTotal >= 1000))
							{
								flag = true;
							}
						}
						
						template += "<tr " + color + ">" + 
									"<td NOWRAP " + colorFirstColumn + ">" +
									"<b " + foreColorFirstColumn + ">" + amount + "</b></td>";

							for(var j = 1; j < arrayRef[i].length; j++)
							{
								/*
									if(j > quantity)
									{
										break;
									}
								*/	
								    var selected = foreColor;
									if((j == quantity) && (flag))
									{
										selected = "style='background-color: #964156; color: #FFFFFF;'";
									}		
									
									
									var prefix = "";
									if(side == 'backandfront')
									{
									    prefix = "+";
									}
									
									template += "<td " + selected + ">" + prefix + "$" + arrayRef[i][j].toFixed(2) + "</td>";
									
							}
							template += "</tr>";
					}
										
		template += "<tr><td>&nbsp;</td></tr></table>";
		return template;
}

function amountOfSidesChangedInstantQuote(selectedValue)
{
    switch(selectedValue)
    {
        case "0" :
            amountOfSidesChanged("front");
            break;
        case "1" :
            amountOfSidesChanged("back");
            break;
        case "2" :
            amountOfSidesChanged("frontAndBack");
            break;
    }
}

function amountOfSidesChanged(side)
{
	document.getElementById("frontSideOnly1").style.backgroundColor = '#E6E6E6';
	document.getElementById("frontBackSideOnly1").style.backgroundColor = '#E6E6E6';
	document.getElementById("frontAndBackSide1").style.backgroundColor = '#E6E6E6';
	
	document.getElementById("frontSideOnly2").style.backgroundColor = '#E6E6E6';
	document.getElementById("frontBackSideOnly2").style.backgroundColor = '#E6E6E6';
	document.getElementById("frontAndBackSide2").style.backgroundColor = '#E6E6E6';
		
	document.getElementById("frontSideOnly3").style.backgroundColor = '#E6E6E6';
	document.getElementById("frontBackSideOnly3").style.backgroundColor = '#E6E6E6';
	document.getElementById("frontAndBackSide3").style.backgroundColor = '#E6E6E6';
	
	
	
	document.getElementById("frontSideOnly3Img").style.display = 'none';	
	document.getElementById("frontBackSideOnly3Img").style.display = 'none';	
	document.getElementById("frontAndBackSide3Img").style.display = 'none';	

	var controlInstantQuoteTShirts_selectSides = document.getElementById('controlInstantQuoteTShirts_selectSides');
	
	if(side == 'front')
	{
		controlInstantQuoteTShirts_selectSides.selectedIndex = 0;
		document.getElementById("frontSideOnly1").style.backgroundColor = '#BDCBDD';
		document.getElementById("frontSideOnly2").style.backgroundColor = '#BDCBDD';
		document.getElementById("frontSideOnly3").style.backgroundColor = '#BDCBDD';
		
		document.getElementById("frontSideOnly1").style.color = '#FFFFFF';
		document.getElementById("frontBackSideOnly1").style.color = '#000000';
		document.getElementById("frontAndBackSide1").style.color = '#000000';
		
		document.getElementById("frontSideOnly3Img").style.display = 'block';	
	}
	else if(side == 'back')
	{
		controlInstantQuoteTShirts_selectSides.selectedIndex = 1;
		document.getElementById("frontBackSideOnly1").style.backgroundColor = '#BDCBDD';
		document.getElementById("frontBackSideOnly2").style.backgroundColor = '#BDCBDD';
		document.getElementById("frontBackSideOnly3").style.backgroundColor = '#BDCBDD';
		document.getElementById("frontBackSideOnly3Img").style.display = 'block';	
	
	    document.getElementById("frontSideOnly1").style.color = '#000000';
		document.getElementById("frontBackSideOnly1").style.color = '#FFFFFF';
		document.getElementById("frontAndBackSide1").style.color = '#000000';
	}
	else if(side == 'frontAndBack')
	{
		controlInstantQuoteTShirts_selectSides.selectedIndex = 2;
		document.getElementById("frontAndBackSide1").style.backgroundColor = '#BDCBDD';
		document.getElementById("frontAndBackSide2").style.backgroundColor = '#BDCBDD';
		document.getElementById("frontAndBackSide3").style.backgroundColor = '#BDCBDD';
		document.getElementById("frontAndBackSide3Img").style.display = 'block';
		
		document.getElementById("frontSideOnly1").style.color = '#000000';
		document.getElementById("frontBackSideOnly1").style.color = '#000000';
		document.getElementById("frontAndBackSide1").style.color = '#FFFFFF';	
	}
	drawTables();
	ShowColorNumbers()
	CountInstantQuote();
}

function colorGroupChanged(colorRoups, colorValue)
{
	var whiteColorsTable = document.getElementById("whiteColorsTable");
	var lightColorsTable = document.getElementById("lightColorsTable");
	var darkColorsTable = document.getElementById("darkColorsTable");
	
	document.getElementById("whiteDown").style.display = 'none';	
	document.getElementById("lightDown").style.display = 'none';	
	document.getElementById("darkDown").style.display = 'none';	
	
	document.getElementById("whiteTD").style.backgroundColor = '#E7E7E7';
	document.getElementById("lightTD").style.backgroundColor = '#E7E7E7';
	document.getElementById("darkTD").style.backgroundColor = '#E7E7E7';
	
	document.getElementById("whiteTD").style.color = '';
	document.getElementById("lightTD").style.color = '';
	document.getElementById("darkTD").style.color = '';
	
	document.getElementById(colorRoups + "TD").style.backgroundColor = '#BDCBDD';
	document.getElementById(colorRoups + "TD").style.color = '#FFFFFF';
	
	document.getElementById(colorRoups + "Down").style.display = 'block';	
	
	var controlInstantQuoteTShirts_selectColor = document.getElementById("controlInstantQuoteTShirts_selectColor");
	
	//var colorArrayRef = ArrayOfTShirtColorItemwhiteColors;
	if(colorRoups == 'white')
	{
		controlInstantQuoteTShirts_selectColor.selectedIndex = colorValue;
		lastWhiteColorValue = colorValue;
		whiteColorsTable.style.display = 'block';
		lightColorsTable.style.display = 'none';
		darkColorsTable.style.display = 'none';
		document.getElementById("colorShirtLabel").innerHTML = 'Prices for <b>White Shirts</b>';
	}
	else if(colorRoups == 'light')
	{
		controlInstantQuoteTShirts_selectColor.selectedIndex = colorValue;
		lastLightColorValue = colorValue;
		//colorArrayRef = ArrayOfTShirtColorItemlightColors;
		whiteColorsTable.style.display = 'none';
		lightColorsTable.style.display = 'block';
		darkColorsTable.style.display = 'none';
		document.getElementById("colorShirtLabel").innerHTML = 'Prices for <b>Light Colored Shirts</b>';
	}
	else if(colorRoups == 'dark')
	{
		controlInstantQuoteTShirts_selectColor.selectedIndex = colorValue;
		lastDarkColorValue = colorValue;
		//colorArrayRef = ArrayOfTShirtColorItemdarkColors;
		whiteColorsTable.style.display = 'none';
		lightColorsTable.style.display = 'none';
		darkColorsTable.style.display = 'block';
		document.getElementById("colorShirtLabel").innerHTML = 'Prices for <b>Dark Color Shirts</b>';
	}

	
	for(var i = 0; i <= 36; i++)
	{
	    var cell = document.getElementById("color_" + i);
	    if(cell != null)
	    {
	        if(colorValue == i)
	        {
    	       cell.style.backgroundColor = "#D0D7E4"; 
	        }
	        else
	        {
    	        cell.style.backgroundColor = "";
	        }
	    }
	} 

	CountInstantQuote();
	drawTables();
}