var archedDisclaimer = false;

function OutlineMenu(action)
{
	if(action=="increase")
	{
		Outline=Outline + 1;
		if(Outline > 5)
		{
			Outline = 5;
		}
	}
	if(action=="decrease")
	{
		Outline=Outline - 1;
		if(Outline < 0)
		{
			Outline = 0;
		}
	}
	document.outlineimage.src = "/images/bar"+Outline+".gif";
	Update();
}
function ShadowMenu(action)
{
	if(action=="increase")
	{
		ShadowThickness=ShadowThickness + 1;
		if(ShadowThickness > 5)
		{
			ShadowThickness = 5;
		}
	}
	if(action=="decrease")
	{
		ShadowThickness=ShadowThickness - 1;
		if(ShadowThickness < 0)
		{
			ShadowThickness = 0;
		}
	}
	document.shadowimage.src = "/images/bar"+ShadowThickness+".gif";
	Update();
}

function UpdateGraphicLocation()
{
	GraphicPosition = document.textform.graphiclocation.options[document.textform.graphiclocation.selectedIndex].value;
	Update();
}

function LoadState()
{
	document.textform.title.value = TitleText;
	
	document.textform.width.value = Width;
	document.textform.height.value = Height;
	document.textform.comment.value = Comment;
	
	if(LetteringIsDomed)
		document.textform.letteringdomed.checked = true;
		
	if(GraphicIsDomed)
		document.textform.graphicdomed.checked = true;
		
	if(LetteringIsDomedGlitter)
		document.textform.letteringdomedglitter.checked = true;
		
	if(GraphicIsDomedGlitter)
		document.textform.graphicdomedglitter.checked = true;
		
	OverrideDoming();	
	
	if(IsRegistration)
	{
		$('#regnumbers').attr('checked','checked');
		$('#pairtext').show();
	}
	else
	{
		$('#regnumbers').removeAttr('checked');
		$('#pairtext').hide();
	}
	
	for(i=0;i< document.textform.font.options.length;i++)
	{
		if(document.textform.font.options[i].value==TitleFont)
			document.textform.font.selectedIndex = i;
	}
	
	for(i=0;i< document.textform.graphiclocation.options.length;i++)
	{
		if(document.textform.graphiclocation.options[i].value==GraphicPosition)
			document.textform.graphiclocation.selectedIndex = i;
	}

	document.outlineimage.src = "/images/bar"+Outline+".gif";
	document.shadowimage.src = "/images/bar"+ShadowThickness+".gif";
	
	document.getElementById('shadowlink').innerHTML = shadowlink;
	document.getElementById('outlinelink').innerHTML = outlinelink;
	document.getElementById('graphiclink').innerHTML = graphiclink;
	
	document.getElementById('outlinecolors').style.display= "none";
	document.getElementById('shadowcolors').style.display= "none";
	document.getElementById('graphiccolors').style.display= "none";

				
	if(TitleBold == "false")
		document.textform.bold.checked = false;
	else
		document.textform.bold.checked = true;	
	
	if(TitleItalic == "false")
		document.textform.italic.checked = false;
	else
		document.textform.italic.checked = true;		
	Update();
}



function UpdateBold()
{

	if(document.textform.bold.checked == true)
	{
		TitleBold = "true";
	}
	else
	{
		TitleBold = "false";
	}		
	
	Update();
}

function UpdateItalic()
{

	if(document.textform.italic.checked == true)
	{
		TitleItalic = "true";
	}
	else
	{
		TitleItalic = "false";
	}		

	Update();
}

function changeFont(newIndex)
{
	document.textform.font.selectedIndex = newIndex;
	TitleFont = document.textform.font.options[newIndex].value;
	Update();
}

function UpdateFont()
{

	TitleFont = document.textform.font.options[document.textform.font.selectedIndex].value;

	Update();

}

function UpdateShadowColor(PassedColor,display)
{

	ShadowColor = PassedColor;
	if(ShadowThickness == 0) 
	{
			ShadowThickness = 4;
			document.shadowimage.src = "/images/bar"+ShadowThickness+".gif";
	}
	document.getElementById('shadowlink').innerHTML = display;
	Update();
}

function UpdateOutlineColor(PassedColor,display)
{

	OutlineColor = PassedColor;
	if(Outline == 0) 
	{
			Outline = 4;
			document.outlineimage.src = "/images/bar"+Outline+".gif";
	}
	document.getElementById('outlinelink').innerHTML = display;
	Update();
}

function UpdateGraphicColor(PassedColor,display)
{
	GraphicColor = PassedColor;
	document.getElementById('graphiclink').innerHTML = display;
	Update();

}

function UpdateBackgroundColor(PassedColor)
{

	BackgroundColor = PassedColor;
	Update();
}


function UpdateColor(PassedColor)
{

	TitleFontColor = PassedColor;

	Update();
}

function UpdateAlign(Direction)
{

	TitleAlign = Direction;

	Update();
}

function SelectGraphic()
{
	url="/lettering/graphics.asp";
	window.open(url,"Fonts","width=850 ,height=340 ,scrollbars=1,toolbar=no,left=100,top=20");
}

function UpdateReg(param)
{
	if(param == true)
	{
		document.textform.regnumbers.checked = true;
		document.textform.title.value = 'IN 3434 VS';
		TitleText = 'IN 3434 VS';
		$('#dialog-modal').dialog('close');
	}
	if(document.textform.regnumbers.checked == true)
	{
		IsRegistration = true;		
		CurrentGraphic = 0;
		Arch = "false";
		Update();
		$('#graphicrow').hide();
		$('#pairtext').show();
	}
	else
	{
		IsRegistration = false;
		Update();
		$('#graphicrow').show();
		$('#pairtext').hide();
	}
}

function OverrideDoming()
{
		if(LetteringIsDomed || GraphicIsDomed)
		{
			LetteringIsDomed = false;
			LetteringIsDomedGlitter = false;
			GraphicIsDomed = false;
			GraphicIsDomedGlitter = false;
			document.textform.letteringdomed.checked = false;
			document.textform.letteringdomedglitter.checked = false;
			document.textform.graphicdomed.checked = false;
			document.textform.graphicdomedglitter.checked = false;
			alert("We are currently not offering domed lettering. Your design and price is now for regular lettering.");
		}
}

function UpdateLetteringDomed()
{
	if(document.textform.letteringdomed.checked == true)
	{
		LetteringIsDomed = true;
	}
	else
	{
		LetteringIsDomed = false;
		document.textform.letteringdomedglitter.checked = false;
		LetteringIsDomedGlitter = false;
	}
	OverrideDoming();
	UpdatePrice();
}

function UpdateGraphicDomed()
{
	if(document.textform.graphicdomed.checked == true)
	{
		GraphicIsDomed = true;
	}
	else
	{
		GraphicIsDomed = false;
		document.textform.graphicdomedglitter.checked = false;
		GraphicIsDomedGlitter = false;		
	}
	OverrideDoming();
	UpdatePrice();
}

function UpdateLetteringDomedGlitter()
{
	if(document.textform.letteringdomedglitter.checked == true)
	{
		LetteringIsDomedGlitter = true;
		document.textform.letteringdomed.checked = true;
		LetteringIsDomed = true;
	}
	else
	{
		LetteringIsDomedGlitter = false;
	}
	OverrideDoming();
	UpdatePrice();
}

function UpdateGraphicDomedGlitter()
{
	if(document.textform.graphicdomedglitter.checked == true)
	{
		GraphicIsDomedGlitter = true;
		document.textform.graphicdomed.checked = true;
		GraphicIsDomed = true;
	}
	else
	{
		GraphicIsDomedGlitter = false;
	}
	OverrideDoming();
	UpdatePrice();
}

function Update(parameters)
{
	if($('regnumbers').checked == true)
	{
		CurrentGraphic = 0;
	}

	URLString = "/lettering/generate-lettering-design.asp?Font="+encodeURIComponent(TitleFont);
	if(parameters != undefined)
		URLString += parameters;
			
	  URLString += "&FontColor="+TitleFontColor;
	  URLString += "&Text="+encodeURIComponent(TitleText);
	  URLString += "&Align="+TitleAlign;
	  URLString += "&Bold="+TitleBold;
	  URLString += "&Italic="+TitleItalic;
	  
	  URLString += "&Outline="+encodeURIComponent(Outline);
	  URLString += "&ShadowThickness="+ShadowThickness;
	  URLString += "&ShadowColor="+ShadowColor;
	  URLString += "&OutlineColor="+OutlineColor;
	  URLString += "&BackgroundColor="+BackgroundColor;
	  URLString += "&CurrentGraphic="+CurrentGraphic;
	  URLString += "&GraphicPosition="+GraphicPosition;
	  URLString += "&GraphicColor="+GraphicColor;
	  URLString += "&GraphicWidth="+encodeURIComponent(GraphicWidth);
	  URLString += "&GraphicHeight="+encodeURIComponent(GraphicHeight);
	  URLString += "&Comment="+encodeURIComponent(Comment);
	  URLString += "&Reg="+encodeURIComponent(IsRegistration);
	  
	  URLString += "&Arch="+encodeURIComponent(Arch);
	  URLString += "&SignCartId="+encodeURIComponent(SignCartId);	
	  URLString += "&Width="+encodeURIComponent(Width);
	  URLString += "&Height="+encodeURIComponent(Height);
	  URLString += "&Price="+encodeURIComponent(Price);	  
	  URLString += "&Save="+encodeURIComponent(Save);  		
	  URLString += "&Edit="+encodeURIComponent(Edit);  
	  URLString += "&Gdomed="+encodeURIComponent(GraphicIsDomed);
	  URLString += "&Ldomed="+encodeURIComponent(LetteringIsDomed);
	  URLString += "&GdomedG="+encodeURIComponent(GraphicIsDomedGlitter);
	  URLString += "&LdomedG="+encodeURIComponent(LetteringIsDomedGlitter);	  
	//alert(URLString);
	frames['imageframe'].location = URLString;

}


function UpdateHeight()
{
	if(document.textform.width.value < MinWidth)
	{
		document.textform.width.value = MinWidth;
		UpdateHeight();
	}
	else
	{
		if(document.textform.width.value / TextProportion > MaxSize && document.textform.width.value > MaxSize)
		{
			document.textform.width.value = MaxSize;
			UpdateHeight();
		}
		else
		{
			NewValue = document.textform.width.value / TextProportion;
			if(NewValue >= MinHeight)
			{
				document.textform.height.value = Math.round(10*NewValue)/10;
			}
			else
			{
				alert("The size you entered causes the height to fall below the minimum allowed size");
				document.textform.height.value = MinHeight;
				UpdateWidth();
			}
		}
	}
	Height = document.textform.height.value;
	Width = document.textform.width.value;
	if(IsRegistration)
	{
		Height = 3;
		document.textform.height.value = Height;
		UpdateWidth();
	}
	
	UpdatePrice();
	UpdateGraphicSize();
}

function UpdateWidth()
{
	if(document.textform.height.value < MinHeight)
	{
		document.textform.height.value = MinHeight;
		UpdateWidth();
	}
	else
	{
		if(document.textform.height.value > MaxSize && document.textform.height.value * TextProportion > MaxSize)
		{
			document.textform.height.value = MaxSize;
			UpdateWidth();
		}
		else
		{

			NewValue = document.textform.height.value * TextProportion;
			if(NewValue >= MinWidth)
			{
				document.textform.width.value = Math.round(10*NewValue)/10;
			}
			else
			{
				alert("The size you entered causes the width to fall below the minimum allowed size");
				document.textform.width.value = MinWidth;
				UpdateHeight();
			}
		}
	}
	Width = document.textform.width.value;
	Height = document.textform.height.value;
	if(IsRegistration && Height != 3)
	{
		Height = 3;
		document.textform.height.value = Height;
		UpdateWidth();
	}
	
	UpdatePrice();
	UpdateGraphicSize();
}

function UpdateGraphicSize()
{
	
	GraphicWidth = Math.round(10*(Width / GraphicWidthProportion))/10; 
	GraphicHeight = Math.round(10*(GraphicWidth / GraphicProportion))/10;
	if(GraphicWidth < 0 || GraphicWidth == Infinity) 
		GraphicWidth = 0;
	if(GraphicHeight < 0 || GraphicHeight == Infinity)
		GraphicHeight = 0;
	document.textform.graphicheight.value = GraphicHeight;
	document.textform.graphicwidth.value = GraphicWidth;
}

Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).
        if (this[i] == value) {
            return true;
        }
    }
    return false;
};


function UpdatePrice()
{

	SquareFeet = (Width* Height)/144;
	Price = (SquareFeet*M) +B;
	var basePrice = Price;
	
	if(IsRegistration)
	{
		Price = basePrice * 1.5;
	}
	if(LetteringIsDomed)
	{
		Price += basePrice * LetteringDomedPrice;
	}
	if(LetteringIsDomedGlitter)
	{
		Price += basePrice * .1;
	}
	
	if(TextureArray.inArray(ShadowColor) && ShadowThickness > 0)
	{
		Price += basePrice * SpecialVinylPrice;
	}
	if(TextureArray.inArray(OutlineColor) && Outline > 0)
	{
		Price += basePrice * SpecialVinylPrice;
	}
	if(TextureArray.inArray(TitleFontColor))
	{
		Price += basePrice * SpecialVinylPrice;
	}
	
	if(ReflectiveArray.inArray(ShadowColor) && ShadowThickness > 0)
	{
		Price += basePrice * ReflectiveVinylPrice;
	}
	if(ReflectiveArray.inArray(OutlineColor) && Outline > 0)
	{
		Price += basePrice * ReflectiveVinylPrice;
	}
	if(ReflectiveArray.inArray(TitleFontColor))
	{
		Price += basePrice * ReflectiveVinylPrice;
	}
	
	if(FlourArray.inArray(ShadowColor) && ShadowThickness > 0)
	{
		Price += basePrice * FlourVinylPrice;
	}
	if(FlourArray.inArray(OutlineColor) && Outline > 0)
	{
		Price += basePrice * FlourVinylPrice;
	}
	if(FlourArray.inArray(TitleFontColor))
	{
		Price += basePrice * FlourVinylPrice;
	}

	if(ShadowThickness > 0 && Outline > 0 && CurrentGraphic > 0)
	{
		if(LetteringIsDomed)
		{
			Price += basePrice * (AdditionalLayerPrice+.15);
		}
		else
		{
			Price += basePrice * (AdditionalLayerPrice+.45);
		}
		
		if(GraphicIsDomed)
		{
			if(LetteringIsDomed)
			{
				Price += (basePrice * GraphicDomedPrice);
			}
			else
			{
				Price += (basePrice * (GraphicDomedPrice+1.5));
			}
			if(GraphicIsDomedGlitter)
			{
				Price += (basePrice * .03);
			}
		}
	}
	else if(ShadowThickness > 0 && Outline > 0)
	{
		if(LetteringIsDomed)
		{
			Price += basePrice * (AdditionalLayerPrice+.08);
		}
		else
		{
			Price += basePrice * (AdditionalLayerPrice+.25);
		}
	}
	else if(ShadowThickness > 0 && CurrentGraphic > 0)
	{
		if(LetteringIsDomed)
		{
			Price += basePrice * (AdditionalLayerPrice+.08);
		}
		else
		{
			Price += basePrice * (AdditionalLayerPrice+.25);
		}
		if(GraphicIsDomed)
		{
			if(LetteringIsDomed)
			{
				Price += (basePrice * GraphicDomedPrice);
			}
			else
			{
				Price += (basePrice * (GraphicDomedPrice+1.5));
			}	
			if(GraphicIsDomedGlitter)
			{
				Price += (basePrice * .03);
			}
		}
	}	
	else if(Outline > 0 && CurrentGraphic > 0)
	{
		if(LetteringIsDomed)
		{
			Price += basePrice * (AdditionalLayerPrice+.08);
		}
		else
		{
			Price += basePrice * (AdditionalLayerPrice+.25);
		}
		
		if(GraphicIsDomed)
		{
			if(LetteringIsDomed)
			{
				Price += (basePrice * GraphicDomedPrice);
			}
			else
			{
				Price += (basePrice * (GraphicDomedPrice+1.5));
			}	
			if(GraphicIsDomedGlitter)
			{
				Price += (basePrice * .03);
			}
		}
	}	
	else if(ShadowThickness > 0)
	{
		if(LetteringIsDomed)
		{
			Price += basePrice * (AdditionalLayerPrice-.25);
		}
		else
		{
			Price += basePrice * AdditionalLayerPrice;
		}		
	}	
	else if(Outline > 0)
	{
		if(LetteringIsDomed)
		{
			Price += basePrice * (AdditionalLayerPrice-.25);
		}
		else
		{
			Price += basePrice * AdditionalLayerPrice;
		}		
	}
	else if(CurrentGraphic > 0) 
	{
		
		if(GraphicIsDomed && CurrentGraphic > 0)
		{
			if(LetteringIsDomed)
			{
				Price += (basePrice * GraphicPrice) + (Price * GraphicDomedPrice);
			}
			else
			{
				Price += (basePrice * GraphicPrice) + (Price * (GraphicDomedPrice+1.5));
			}
			if(GraphicIsDomedGlitter)
			{
				Price += (basePrice * .03);
			}
		}
		else
		{
			Price += basePrice * GraphicPrice;
		}
	}
	
	
	Price = Math.round(10*Price)/10;
	

	$('#price').hide( 'slide', '', 500, function(){document.textform.price.value="$"+Price.toFixed(2);$('#price').show( 'slide', '', 500, '' );} );


}


function toggle_visibility(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'none')
		$( "#"+id ).show( 'fold', '', 500, '' );
	else
		$( "#"+id ).hide( 'fold', '', 500, '' );
}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
		Comment=document.textform.comment.value;
    } 
}


function PrintWindow()
{
	var strImage = frames['imageframe'].document.getElementById('productimage').src;
	var strImage = strImage.substr(strImage.lastIndexOf('/')+1,strImage.length-strImage.lastIndexOf('/'));
	window.open ("/signs/print-sign.asp?image="+encodeURIComponent(strImage),"PrintSign","menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes");
}

function archOff()
{
	Arch='false';
	Update();
}

function archUp()
{
	if(!IsRegistration)
	{
		if(archedDisclaimer)
		{
			Arch='upper';
			Update();
		}
		else
		{
			if(confirm('Please note the size shown below is the total size of the entire graphic, not the height of the letters individually.'))
			{
				archedDisclaimer = true;
				Arch='upper';
				Update();
			}
		}
	}
	else
	{
		alert('Curves not allowed with registration numbers');
	}
}

function archDown()
{
	if(!IsRegistration)
	{
		if(archedDisclaimer)
		{
			Arch='lower';
			Update();
		}
		else
		{
			if(confirm('Please note the size shown below is the total size of the entire graphic, not the height of the letters individually.'))
			{
				archedDisclaimer = true;
				Arch='lower';
				Update();
			}
		}
	}
	else
	{
		alert('Curves not allowed with registration numbers');
	}
}

