/* detailPage specific JS*/
function saveFontValue()
{//get the current font value and save it to the hidden input
	var saveFont=$("#fontList option:selected").text();
	
	document.forms.cart_quantity["id[txt_19]"].value=saveFont;
	//alert(document.forms.cart_quantity["id[txt_19]"].value);
}
function autoSaveTest()
{
	//set the main form action to the session manager
	//document.forms.sessionManagerForm.submit();
	$("#cart_quantity").attr("action","sessionManager.php");
	$("#cart_quantity").attr("target","sessionManagerFrame");
	
	document.forms.cart_quantity.submit();
	//set form and timeout
	setTimeout("autoSaveTest()",autoSaveDuration);
	
}
function onChange_headshot_paper(show,hide,initial)
{
	if((zone=="east")||(zone=="unsupported"))
	{
		$("#headshots_quantity_east_"+show).show();
		$("#headshots_quantity_east_"+hide).hide();
		if(initial==1)
		{
			$("#id_2").val("");
			$("#id_3").val("");
		}
	}
	else if(zone=="west")
	{
		$("#headshots_quantity_west_"+show).show();
		$("#headshots_quantity_west_"+hide).hide();
		if(initial==1)
		{
			$("#id_36").val("");
			$("#id_37").val("");
		}
	}
}
function onChange_pc_choice(oType)
{//depending upon the post card choice, reload page and empty session
	
	$("#forceClearSession").val("1");
	$("#postCardType").val(oType);
	var currentUrl=window.location;
	$("#forceSessionClear").attr("action",currentUrl);
	//window.location=newUrl;
	//reload the page and clear the session
	document.forms.forceSessionClear.submit();
}
var isReorder=false;
function isReorderButton()
{
	if($("input[name='id[5]']").getValue()==25)
	{
		//is a reorder
		isReorder=true;
		//var pathArray = window.location.pathname.split( '/' );
		//attrib-9-0
		//$("#attrib-9-0").val("Web Reorder");
		//set the photographer to default 
		//alert(window.location);
	}
	else
	{
		isReorder=false;
		if(reordering==1)
		{//this is a reorder, changing back into a regular order, reload the page
			if ($.getURLParam("isReorder")!=null) {
				//set a paramater to force clear the window
				$("#forceClearSession").val("1");
				var currentUrl=window.location;
				currentUrl=currentUrl+"";
			  	var truncateAt=currentUrl.lastIndexOf("&");
				var newUrl=currentUrl.substring(0,truncateAt);
				$("#forceSessionClear").attr("action",newUrl);
				//window.location=newUrl;
				//reload the page and clear the session
				setTimeout('document.forms.forceSessionClear.submit()',100);

			}
		}
	}
}//end isReorder
var currentPrice=0;
function changeQuantity(product,thisZone,elemId,elemNum)
{
	buildCurrentPrice();
}

function buildCurrentPrice()
{
	currentPrice=0;
	
	if((zone=="east")||(zone=="unsupported"))
	{
		if(pId==3)
		{
			if(priceCube[2][$("#id_2").val()])
			{//regular
				currentPrice=currentPrice+(priceCube[2][$("#id_2").val()]);
			}
			if(priceCube[3][$("#id_3").val()])
			{//regular
				currentPrice=currentPrice+(priceCube[3][$("#id_3").val()]);
			}
		}//end headshots
		
		if(pId==5)
		{//BizCards
		
			if((priceCube[33][$("#id_33").val()])&&((zone=="east")||(zone=="unsupported")))
			{//regular
				
				currentPrice=currentPrice+(priceCube[33][$("#id_33").val()]);
			}
			else if ((priceCube[38][$("#id_38").val()])&&((zone=="west")))
			{
				currentPrice=currentPrice+(priceCube[38][$("#id_38").val()]);
			}
		}//end headshots
		if(pId==4)
		{//PostCards
			
			if((priceCube[34][$("#id_34").val()])&&((zone=="east")||(zone=="unsupported")))
			{//regular
				
				currentPrice=currentPrice+(priceCube[34][$("#id_34").val()]);
			}
			else if ((priceCube[40][$("#id_40").val()])&&((zone=="west")))
			{
				currentPrice=currentPrice+(priceCube[40][$("#id_40").val()]);
			}
			else
			{
				
			}
			if($("input[name='id[25]']").getValue()==47)
			{//2 image post card, add price
				currentPrice=currentPrice+15;
			}
		}//end postcards
		if(pId==6)
		{//CompCards
			
			if((priceCube[32][$("#id_32").val()])&&((zone=="east")||(zone=="unsupported")))
			{//regular
				
				currentPrice=currentPrice+(priceCube[32][$("#id_32").val()]);
			}
			else
			{
				
			}
			
			//alert(currentPrice);
		}//end compcards
	
		//apply discounts
		if(  ( $("input[name='id[5]']").getValue()==25  ) &&(currentPrice!=0)  )
		{//if reorder is selected
			currentPrice=currentPrice-(currentPrice*discountAmount);
		}//end reorder selected
		
		
	}
	else if(zone=="west")
	{
		if(pId==3)
		{
			if(priceCube[36][$("#id_36").val()])
			{//regular
				currentPrice=currentPrice+(priceCube[36][$("#id_36").val()]);
			}
			if(priceCube[37][$("#id_37").val()])
			{//regular
				currentPrice=currentPrice+(priceCube[37][$("#id_37").val()]);
			}

		}// end headshots
		if(pId==4)
		{//PC
			if(priceCube[40][$("#id_40").val()])
			{//regular
				currentPrice=currentPrice+(priceCube[40][$("#id_40").val()]);
			}
			if($("input[name='id[25]']").getValue()==47)
			{//2 image post card, add price
				currentPrice=currentPrice+15;
			}
		}//end headshots
		if(pId==5)
		{//BC
		
			if(priceCube[38][$("#id_38").val()])
			{//regular
				currentPrice=currentPrice+(priceCube[38][$("#id_38").val()]);
			}
		}//end headshots
		
		
		//west set up fee
		currentPrice=currentPrice+setupFee;
		
		if($("input[name='id[5]']").length>0)
		{
			//apply discounts
			if(  ( $("input[name='id[5]']").getValue()==25  ) &&(currentPrice!=0)  )
			{//if reorder is selected
				currentPrice=currentPrice-(currentPrice*discountAmount);
			}//end reorder selected
			
		}
		
	}
	
	
	if(  ( $("input[name='id[49][149]']").getValue()==149  ) )
	{//if reorder is selected
		currentPrice=currentPrice+15;
	}//end reorder selected
	if(  ( $("input[name='id[41]']").getValue()==125  ) )
	{//if reorder is selected
		currentPrice=currentPrice+25;
	}//end reorder selected
	if(  ( $("input[name='id[47]']").getValue()==146  ) )
	{//if reorder is selected
		currentPrice=currentPrice+10;
	}//end reorder selected
	if(  ( $("input[name='id[47]']").getValue()==147  ) )
	{//if reorder is selected
		currentPrice=currentPrice+22.5;
	}//end reorder selected
	if(  ( $("input[name='id[47]']").getValue()==148  ) )
	{//if reorder is selected
		currentPrice=currentPrice+22.5;
	}//end reorder selected
	
	if(  ( $("input[name='id[45]']").getValue()==140  ) )
	{//if proof
		currentPrice=currentPrice+10;
	}//end proof
	if(  ( $("input[name='id[45]']").getValue()==141  ) )
	{//if proof
	
		currentPrice=currentPrice+30;
	}//end proof

	currentPrice=currentPrice+"";
	var fooDot=currentPrice.lastIndexOf(".");
	var fooLength=currentPrice.length;
	if((fooLength-fooDot==2)&&(currentPrice>0))
	{
		currentPrice=currentPrice+"0";
	}
	else
	{
		currentPrice=currentPrice+".00";
	}
	


	//check for ending zero
	$(".wizardPriceValue").text("Sub Total: $ "+currentPrice);
	//alert($(".wizardPriceValue"));
}




function askInitials()
{
	$('#widg_wizard_proof').dialog("open");
}
function selectRadio(itemId,removeItemId)
{
	$("#"+removeItemId).removeAttr("checked");
	$("#"+itemId).attr("checked", "checked");
}
function clearCheck(itemArray)
{
	for(i=0;i<arguments.length;i++)
	{
		$("#"+arguments[i]).removeAttr("checked");	
	}
}
function clearText(textBox)
{
	$("#"+textBox).val(" ");	
}


/* ****************************************************************************************************   FONT TOOL */


// hack to make IE resize a transparent image
function resizeIEImg(url)
{
	var imageTag="<img style=\"FILTER: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+url+"', sizingMethod='scale');\" src=\"onepixel.png\" width=\""+document.getElementById('IEtextHere').offsetWidth/2+"\" height=\""+document.getElementById('IEtextHere').offsetHeight/2+"\"";
	document.getElementById("textHere").innerHTML=imageTag+" onload='moveDiv();' />";
}

// move text to center of background image
function moveDiv()
{
	var divMTag=document.getElementById('textHere');
	var divFTag=document.getElementById('imageHere');
	var obj=divFTag;
	if(obj){
		var posX=obj.offsetLeft+obj.offsetWidth/2;
		var posY=obj.offsetTop+obj.offsetHeight/2;
		while (obj.offsetParent)
		{
			if (obj==document.getElementsByTagName('body')[0]) {break}
			else
			{
				posX=posX+obj.offsetParent.offsetLeft;
				posY=posY+obj.offsetParent.offsetTop;
				obj=obj.offsetParent;
			}
		}
	}
    divMTag.style.left=(posX-divMTag.offsetWidth/2)+'px';
    divMTag.style.top=(posY-divMTag.offsetHeight/2)+'px';
}


// update font
function updateImage(fontName)
{
	
	var fullName="";
	if($("input[name='id[txt_16]']").val()!="")
	{
		var firstName=$("input[name='id[txt_16]']").val();	
		fullName=firstName;
	}
	if($("input[name='id[txt_17]']").val()!="")
	{
		var midName=" "+$("input[name='id[txt_17]']").val();	
		fullName=fullName+midName;
	}
	if($("input[name='id[txt_18]']").val()!="")
	{
		var lastName=" "+$("input[name='id[txt_18]']").val();	
		fullName=fullName+lastName;
	}
	//HERE I AM - when name is stored in session, it won't set the font
	//alert($("input[name='id[txt_16]']").val()+" in updateImage in detailPage.js");
	if(fullName!="")
	{
	
		//id[txt_16]
		var fontV=fontName;
		var textV=fullName;
		//alert();
		sizeV=$("#fontSize").val();
		caseV=$("#attrib-20").val();
		if(caseV==66)
		{
			caseV="mixed";
		}
		if(caseV==67)
		{
			caseV="lower";
		}
		if(caseV==68)
		{
			caseV="upper";
		}
		if(caseV==69)
		{
			caseV="smallcaps";
		}
		
		//var textC="0,0,0";
		textC=$("input[name='id[21]']").getValue();
		//alert(textC);
		if(textC==70)
		{
			//black
			textC="0,0,0";
		}
		if(textC==71)
		{
			//white
			textC="255,255,255";
		}
		textC=textC.split(",");
		textCRV=textC[0];
		textCGV=textC[1];
		textCBV=textC[2];
		//textCRV=document.getElementById("textCR").value;
		//textCGV=document.getElementById("textCG").value;
		//textCBV=document.getElementById("textCB").value;
	
		url="fontTool/fonts_proc.php?font="+fontV+"&text="+textV+"&size="+sizeV+"&case="+caseV+"&textCR="+textCRV+"&textCG="+textCGV+"&textCB="+textCBV;
		//alert(url);
		var img = document.createElement('img');
			
		// Correct problem on IE.  Does not display transparent PNG images
		if (navigator.appName=="Microsoft Internet Explorer" && navigator.appVersion.indexOf('MSIE 6') > -1 && navigator.appVersion.indexOf('MSIE 7') == -1 && navigator.appVersion.indexOf('MSIE 8') == -1)
		{	// IE
			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+url+"', sizingMethod='image')";
			img.src = 'onepixel.png';
			img.onload = "resizeIEImg('"+url+"')";
			document.getElementById("IEtextHere").innerHTML = '';
			document.getElementById("IEtextHere").appendChild(img);
		}
		else 
		{	
			img.src = url;
			img.onload = "moveDiv()";
			if(document.getElementById("textHere"))
			{
				document.getElementById("textHere").innerHTML = '';
				document.getElementById("textHere").appendChild(img);
			}
		}
		
		//change the div color
		if($("input[name='id[21]']").getValue()==70)
		{//black text
			$('.textToolContainer').css({"background-color":"#ffffff","padding":"10px"});
		}
		if($("input[name='id[21]']").getValue()==71)
		{//black text
			$('.textToolContainer').css({"background-color":"#000000","padding":"10px"});
		}
		
	
	}//name exists
}

function setupDIL()
{
	/* **********************************************************************************  BEGIN DEFAULT LAYOUTS *******************************************************/
	if((pId==9)||(pId==7))
	{//if product is bdr or retouching, don't show dil, use alternate
		$('.dil_image_container').css({
			"margin-left":"auto",
			"margin-right":"auto",
			"clear":"both"
		});
		$('.wizard_product_imageContainer').css({
			"text-align":"center",
			"margin-top":"0px"
		});
		layoutChoice=150;
		
		if(prodLayArray[layoutChoice]['DIL']['imageCont']!="")
		{//an image property exists
		
			for(var z in prodLayArray[layoutChoice]['DIL']['imageCont'])
			{//loop through all properties for this layout choice
			//alert(prodLayArray[layoutChoice]['DIL']['imageCont'][z]);
				var cssProperty=prodLayArray[layoutChoice]['DIL']['imageCont'][z];
				var cssObject = Object();
				if(z=="url")
				{
					var key="background-image";
					var value="url(images_interface/wizard/DIL_base/"+cssProperty+")";
					//alert(value);
				}
				else
				{
					var key=z;
					var value=cssProperty;
				}
				var cssName = key;
				var cssValue = value;
				cssObject[cssName] = cssValue;
				
				if(z=="margin-top")
				{//apply top margin to a container div
					//alert(z);
					$('.dil_container2').css({"height":""+cssValue});
				}
				else
				{//otherwise apply to image container
					$('.dil_image_container').css(cssObject);
				}
			}//end for
		}
		//hide name container
		$('.dil_name_container').hide();
		
	}
	else
	{//other proucts get dil
	
		$('.dil_image_container').css({
			"border":"2px solid #000000",
			"margin-left":"auto",
			"margin-right":"auto",
			"clear":"both"
		});
		$('.wizard_product_imageContainer').css({
			"background-color":"#ffffff",
			"text-align":"center",
			"margin-top":"0px"
		});
		var nameSize=16;
		var phoneSize=Math.round(nameSize*.70);
		var emailSize=Math.round(nameSize*.70);
		
		var textColor='&textCR=0&textCG=0&textCB=0';
		var layoutChoice=false;
		var bgColor=false;
		var borderLine=false;
		var nameBorder=false;
		var nameLocation=false;
		var selectedTextColor=false;
		if(!($("input[name='id[52]']:checked").val()))
		{//if no layout exists (reorder)
			layoutChoice=150;
			bgColor=49;
			borderLine=52;
			nameBorder=64;
			nameLocation=59;
			selectedTextColor=70;
		}
		else
		{
			layoutChoice=$("input[name='id[52]']:checked").val();
			bgColor=$("input[name='id[10]']").getValue();
			borderLine=$("input[name='id[11]']").getValue();
			nameBorder=$("input[name='id[14]']:checked").val();
			nameLocation=$("#attrib-13").val();
			selectedTextColor=$("input[name='id[21]']:checked").val();
		}
		if(nameBorder!=false)
		{
			if(prodLayArray[layoutChoice]['DIL']['nameCont'][nameBorder][nameLocation]['font-size'])
			{//if there is a font size attribute
				var str=prodLayArray[layoutChoice]['DIL']['nameCont'][nameBorder][nameLocation]['font-size'];
				str=str.substring(0,(str.length-2));
				nameSize=str;
				emailSize=Math.round(str*.70);
				//emailSize=Math.round(str*.55);	
				phoneSize=emailSize;
			}
		}
		
		/* **********************************************************************************  BEGIN PRODUCT CONT CSS *******************************************************/
		if(prodLayArray[layoutChoice]['DIL']['productCont']!="")
		{//an image property exists
		//alert(layoutChoice);
			for(var z in prodLayArray[layoutChoice]['DIL']['productCont'])
			{//loop through all properties for this layout choice
				var cssProperty=prodLayArray[layoutChoice]['DIL']['productCont'][z];
				var cssObject = Object();
				var cssName = z;
				var cssValue = cssProperty;
				//alert(z+" "+cssProperty);
				cssObject[cssName] = cssValue;
				$('.wizard_product_imageContainer').css(cssObject);
			
			}//end for loop
		}//end if product container
		
		if(selectedTextColor==71)
		{//white text
			textColor='&textCR=255&textCG=255&textCB=255';
		}
		else
		{//black
			textColor='&textCR=0&textCG=0&textCB=0';
		}
		
		/* **********************************************************************************  BEGIN BORDER COLOR *******************************************************/
		//borderColor
		
		//alert(textColor);
		if(bgColor==49)
		{//white border
			$('.wizard_product_imageContainer').css({"background-color":"#ffffff"});
			//set image border to match
			$('.dil_image_container').css({"border":"2px solid #ffffff"});
			
			if($("input[name='id[14]']").getValue()==64)
			{//if name on image
			
				textColor='&textCR=0&textCG=0&textCB=0';
				
				//set check mark to black
				//$("input[name='id[21]']:checked").val();
				$("#attrib-21-71").removeAttr("checked");
				$("#attrib-21-70").attr("checked", "checked");
			}
			else
			{
				
			}
		}
		if(bgColor==50)
		{//black border
			$('.wizard_product_imageContainer').css({"background-color":"#000000","border":"2px solid #333333"});
			$('.dil_image_container').css({"border":"2px solid #000000"});
			//$('.wizard_product_imageContainer').css({});
			if($("input[name='id[14]']").getValue()==64)
			{//only change color if name is on border
				//$('.dil_name_image').attr('src','fontTool/fonts_proc.php?font=Bradley Hand ITC TT Bold.ttf&text=Your Name Here&size=14&case=mixed&textCR=255&textCG=255&textCB=255');
				textColor='&textCR=255&textCG=255&textCB=255';
				$("#attrib-21-70").removeAttr("checked");
				$("#attrib-21-71").attr("checked", "checked");
			}
			else
			{
				//$('.dil_name_image').attr('src','fontTool/fonts_proc.php?font=Bradley Hand ITC TT Bold.ttf&text=Your Name Here&size=14&case=mixed&textCR=0&textCG=0&textCB=0');
				//textColor='&textCR=0&textCG=0&textCB=0';
				//$("#attrib-21-71").removeAttr("checked");
				//$("#attrib-21-70").attr("checked");
			}
		}
		else
		{
			$('.dil_image_container').css({"border":"0px solid #000000"});	
		}
		//get image
		
		$('.dil_name_image').attr('src','fontTool/fonts_proc.php?font=Bradley Hand ITC TT Bold.ttf&text=Your Name Here&size='+nameSize+'&case=mixed'+textColor);
		/* **********************************************************************************  BEGIN LINE COLOR *******************************************************/
		//Image border Line
		if(borderLine==52)
		{//black line
			$('.dil_image_container').css({"border":"2px solid #000000"});
		}
		if(borderLine==53)
		{//white line
			$('.dil_image_container').css({"border":"2px solid #ffffff"});
		}
		if(borderLine==54)
		{//no line
			//$('.dil_image_container').css({"border":"2px solid #ffffff"});
			if(bgColor==50)
			{
				$('.dil_image_container').css({"border":"2px solid #000000"});
			}
			else
			{
				$('.dil_image_container').css({"border":"2px solid #ffffff"});
			}
		}
		
		/* **********************************************************************************  BEGIN NAME FLOATS *******************************************************/
		//if 2 image postcard, hide name div
		if($("input[name='id[25]']").getValue()==47)
		{
			$('.dil_name').hide();	
		}
		
		if(prodLayArray[layoutChoice]['DIL']['nameCont'][nameBorder]!="")
		{//a name on border placement exists
		
			if(prodLayArray[layoutChoice]['DIL']['nameCont'][nameBorder])
			{
				for(var z in prodLayArray[layoutChoice]['DIL']['nameCont'][nameBorder][nameLocation])
				{//loop through all properties for this layout choice
					
					if(prodLayArray[layoutChoice]['DIL']['nameCont'][nameBorder][nameLocation][z]!="")
					{//a value exists, set it
						var cssProperty=prodLayArray[layoutChoice]['DIL']['nameCont'][nameBorder][nameLocation][z];
						var cssObject = Object();
						var cssName = z;
						var cssValue = cssProperty;
						if(cssName=="rotate")
						{//rotate the text
							//regenerate text as rotated	
							//name
							//rotate
							//prodLayArray[layoutChoice]['DIL']['nameCont'][nameBorder][nameLocation]['font-size']
							//$('.dil_name_name').css({"width":"60px","position":"relative","height":""+prodLayArray[layoutChoice]['DIL']['imageCont']["height"]});
							//$('.dil_name_phone').css({"position":"absolute","bottom":"0px","left":"18px"});
							//$('.dil_name_email').css({"position":"absolute","bottom":"0px","left":"35px"});
							//$('.dil_name_ExtraCont').css({"position":"absolute","bottom":"0px","left":"0px"});
							
							$('.dil_name_image').attr('src','fontTool/fonts_proc.php?font=Bradley Hand ITC TT Bold.ttf&text=Your Name Here&size='+nameSize+'&case=mixed'+textColor+'&textAngle='+cssProperty);
							//phone
							$('.dil_name_phone').attr('src','fontTool/fonts_proc.php?font=Bradley Hand ITC TT Bold.ttf&text=212-555-5555&size='+phoneSize+'&case=mixed'+textColor+'&textAngle='+cssProperty);
							//email
							$('.dil_name_email').attr('src','fontTool/fonts_proc.php?font=Bradley Hand ITC TT Bold.ttf&text=email@reproductions.com&size='+emailSize+'&case=mixed'+textColor+'&textAngle='+cssProperty);
							
							$('.dil_name_imageHidden').attr('src','fontTool/fonts_proc.php?font=Bradley Hand ITC TT Bold.ttf&text=Your Name Here&size='+nameSize+'&case=mixed'+textColor+'&textAngle='+cssProperty);
							//phone
							$('.dil_name_phoneHidden').attr('src','fontTool/fonts_proc.php?font=Bradley Hand ITC TT Bold.ttf&text=212-555-5555&size='+phoneSize+'&case=mixed'+textColor+'&textAngle='+cssProperty);
							//email
							$('.dil_name_emailHidden').attr('src','fontTool/fonts_proc.php?font=Bradley Hand ITC TT Bold.ttf&text=email@reproductions.com&size='+emailSize+'&case=mixed'+textColor+'&textAngle='+cssProperty);
							
						}
						else
						{
							if((pId==5)||(pId==4))
							{//phone
								
								$('.dil_name_phone').attr('src','fontTool/fonts_proc.php?font=Bradley Hand ITC TT Bold.ttf&text=212-555-5555&size='+emailSize+'&case=mixed'+textColor);
								//email
								$('.dil_name_email').attr('src','fontTool/fonts_proc.php?font=Bradley Hand ITC TT Bold.ttf&text=email@reproductions.com&size='+emailSize+'&case=mixed'+textColor);
							}
							if(cssName=="float")
							{//centering text
								if(cssValue=="center")
								{
									cssName="float";
									cssValue="none";
									cssObject[cssName] = cssValue;
									$('.dil_name').css(cssObject);
								}
								else
								{
									cssObject[cssName] = cssValue;
									$('.dil_name').css(cssObject);
								}
								
							}
							else
							{
								cssObject[cssName] = cssValue;
								$('.dil_name').css(cssObject);
							}
							//set the width of the container
							//$('.dil_name_container').css({"width":""+prodLayArray[layoutChoice]['DIL']['imageCont']["width"]});
							
						
						}
					}
				}//end or loop
			}//end if exists
			
			//alert($('.dil_name_container').css("margin-top"));
		}//end name on border placement
		/* **********************************************************************************  BEGIN IMAGE PLACEMENT *******************************************************/
		if(prodLayArray[layoutChoice]['DIL']['imageCont']!="")
		{//an image property exists
		//alert(layoutChoice);
			for(var z in prodLayArray[layoutChoice]['DIL']['imageCont'])
			{//loop through all properties for this layout choice
			//alert(prodLayArray[layoutChoice]['DIL']['imageCont'][z]);
				var cssProperty=prodLayArray[layoutChoice]['DIL']['imageCont'][z];
				var cssObject = Object();
				if(z=="url")
				{
					var key="background-image";
					var value="url(images_interface/wizard/DIL_base/"+cssProperty+")";
					//alert(value);
				}
				else
				{
					var key=z;
					var value=cssProperty;
				}
				var cssName = key;
				var cssValue = value;
				cssObject[cssName] = cssValue;
				
				if(z=="margin-top")
				{//apply top margin to a container div
					//alert(z);
					$('.dil_container2').css({"height":""+cssValue});
				}
				else
				{//otherwise apply to image container
					$('.dil_image_container').css(cssObject);
				}
			}//end for
		}
		
		/* **********************************************************************************  BEGIN PRODUCT/LAYOUT SPECIFIC *******************************************************/
		if(pId==3)
		{//specific DIL
			
			if(layoutChoice==155)
			{//horizontal on veritcal bleed, remove left right border
			
				$('.dil_image_container').css({"border-right":"0px solid #000000"});
				$('.dil_image_container').css({"border-left":"0px solid #000000"});
			}
		}
		if(pId==5)
		{//specific DIL bc
			if(layoutChoice==152)
			{//horizontal bc
				$('.dil_name_container').hide();
				$('.dil_nameHidden').show();
				if(nameLocation==59)
				{//lower right
					$('.dil_nameHidden').css({"width":"80px","height":"210px","float":"left"});
					$('.dil_name_imageHidden').css({"margin-left":"10px"});
					$('.dil_name_phoneHidden').css({"margin-left":"15px"});
					$('.dil_name_emailHidden').css({"margin-left":"20px"});
					setTimeout("order('left')",300);
					setTimeout("align('bottom')",300);
				}//end lower right
				if(nameLocation==61)
				{//upper right
					$('.dil_nameHidden').css({"width":"80px","height":"210px","float":"left"});
					$('.dil_name_imageHidden').css({"margin-left":"10px"});
					$('.dil_name_phoneHidden').css({"margin-left":"15px"});
					$('.dil_name_emailHidden').css({"margin-left":"20px"});
					setTimeout("order('left')",300);
					setTimeout("align('top')",300);
				}//end upper right
				if(nameLocation==63)
				{//lower center name
					$('.dil_image_container').css({"float":"right","margin-right":"16px","margin-left":"0px"});
					$('.dil_nameHidden').css({"width":"80px","height":"200px","float":"left"});
					$('.dil_name_imageHidden').css({"margin-right":"10px"});
					$('.dil_name_phoneHidden').css({"margin-right":"15px"});
					$('.dil_name_emailHidden').css({"margin-right":"20px"});
					setTimeout("order('right')",300);
					setTimeout("align('center')",300);
				}//end lower center
				if(nameLocation==60)
				{//lower left
					$('.dil_image_container').css({"float":"right","margin-right":"16px","margin-left":"0px"});
					$('.dil_nameHidden').css({"width":"80px","height":"200px","float":"left"});
					$('.dil_name_imageHidden').css({"margin-right":"10px"});
					$('.dil_name_phoneHidden').css({"margin-right":"15px"});
					$('.dil_name_emailHidden').css({"margin-right":"20px"});
					setTimeout("order('right')",300);
					setTimeout("align('bottom')",300);
				}//end lower left
				if(nameLocation==62)
				{//upper left
					$('.dil_image_container').css({"float":"right","margin-right":"16px","margin-left":"0px"});
					$('.dil_nameHidden').css({"width":"80px","height":"200px","float":"left"});
					$('.dil_name_imageHidden').css({"margin-right":"10px"});
					$('.dil_name_phoneHidden').css({"margin-right":"15px"});
					$('.dil_name_emailHidden').css({"margin-right":"20px"});
					setTimeout("order('right')",300);
					setTimeout("align('top')",300);
				}//end upper left
			}
			else
			{
				$('.dil_name_container').show();
				$('.dil_nameHidden').hide();
			}
		}
		if(pId==4)
		{//postcard
			if(layoutChoice==152)
			{//horizontal w border
				//fix specific font layout
				//dil_name_email
				var cssObject = Object();
				var cssName = "width";
				var cssValue = "100%";
				cssObject[cssName] = cssValue;
				$('.dil_name').css(cssObject);
				
				
				var cssObject = Object();
				var cssName = "float";
				var cssValue = "left";
				cssObject[cssName] = cssValue;
				cssName = "width";
				cssValue = "50%";
				cssObject[cssName] = cssValue;
				cssName = "clear";
				cssValue = "none";
				cssObject[cssName] = cssValue;
				cssName = "text-align";
				cssValue = "left";
				cssObject[cssName] = cssValue;
				$('.dil_name_qual').css(cssObject);
				
				
				var cssObject = Object();
				var cssName = "float";
				var cssValue = "right";
				cssObject[cssName] = cssValue;
				cssName = "width";
				cssValue = "48%";
				cssObject[cssName] = cssValue;
				cssName = "clear";
				cssValue = "none";
				cssObject[cssName] = cssValue;
				cssName = "text-align";
				cssValue = "right";
				cssObject[cssName] = cssValue;
				cssName = "margin-top";
				cssValue = "5px";
				cssObject[cssName] = cssValue;
				$('.dil_phone_qual').css(cssObject);
				
				var cssObject = Object();
				var cssName = "float";
				var cssValue = "right";
				cssName = "width";
				cssValue = "100%";
				cssName = "clear";
				cssValue = "both";
				cssName = "text-align";
				cssValue = "right";
				
				cssObject[cssName] = cssValue;
				$('.dil_email_qual').css(cssObject);
			}
			else
			{
				//clear all that out
				
				var cssObject = Object();
				var cssName = "float";
				var cssValue = "";
				cssObject[cssName] = cssValue;
				cssName = "width";
				cssValue = "";
				cssObject[cssName] = cssValue;
				cssName = "clear";
				cssValue = "";
				cssObject[cssName] = cssValue;
				cssName = "text-align";
				cssValue = "";
				cssObject[cssName] = cssValue;
				$('.dil_name_qual').css(cssObject);
				
				
				var cssObject = Object();
				var cssName = "float";
				var cssValue = "right";
				cssObject[cssName] = cssValue;
				cssName = "width";
				cssValue = "";
				cssObject[cssName] = cssValue;
				cssName = "clear";
				cssValue = "";
				cssObject[cssName] = cssValue;
				cssName = "text-align";
				cssValue = "";
				cssObject[cssName] = cssValue;
				cssName = "margin-top";
				cssValue = "";
				cssObject[cssName] = cssValue;
				$('.dil_phone_qual').css(cssObject);
				
				var cssObject = Object();
				var cssName = "float";
				var cssValue = "";
				cssName = "width";
				cssValue = "";
				cssName = "clear";
				cssValue = "";
				cssName = "text-align";
				cssValue = "";
				
				cssObject[cssName] = cssValue;
				$('.dil_email_qual').css(cssObject);	
			}//end else
			
			//don't show border around image if selected
			if($("input[name='id[25]']").getValue()==47)
			{
				$('.dil_image_container').css({"border":"0px solid #000000"});
			}
		}//end is postcard exceptions
	}//end all other products
}//end DIL setup

function align (value) {
	var images = $('.dil_nameHidden img')
	switch (value) {
		case 'bottom':
			for (var i = 0, l = images.length; i < l; i++) {
				images[i].style.bottom = '0px'
				images[i].style.top = ''
			}
			break
		case 'top':
			for (var i = 0, l = images.length; i < l; i++) {
				images[i].style.top = '0px'
				images[i].style.bottom = ''
			}
			break
		case 'center':
			var height = $('.dil_nameHidden')[0].clientHeight
			for (var i = 0, l = images.length; i < l; i++) {
				images[i].style.top = (height - images[i].offsetHeight) / 2 + 'px'
				images[i].style.bottom = ''
			}
			break
	}
}

function order (value) {
	var images = $('.dil_nameHidden img')
	var offset = 0
	if (value == 'left')
		for (var i = 0, l = images.length; i < l; i++) {
			images[i].style.left = offset + 'px'
			images[i].style.right = ''
			offset += images[i].offsetWidth
		}
	else//'right'
		for (var i = 0, l = images.length; i < l; i++) {
			images[i].style.right = offset + 'px'
			images[i].style.left = ''
			offset += images[i].offsetWidth
		}
}



function goHome()
{//send the page back to the beginning
	newURL = window.location.protocol + "//" + window.location.host + window.location.pathname;
	window.location=newURL;
}
function prepareDILform()
{/*
	This function is called on page load, and also from validation of the layout page,it sets up the form to reflect the layout choice and runs the setupDIL function

*/
	if((currentLayoutChoice==$("input[name='id[52]']").getValue())&&(currentLayoutChoice!=false))
	{//if the choice is the same, don't do anything
	
	}//end if layoutchoice hasn't changed
	else
	{
		
		if(DILdefault!="test")
		{//don't set default if there is session information
		
		
			var headshots_layoutChoice=$("input[name='id[52]']").getValue();
			if(pId==3)
			{//headshots
				if((headshots_layoutChoice==151)||(headshots_layoutChoice==153))
				{
					$("#wizard_3_2_placment").hide();
					$("#attrib-14-64").removeAttr("checked");
					$("#attrib-14-65").attr("checked", "checked");//check 'on image'
					$("#wizard_3_2_borderColor").hide();
					$("#attrib-10-49").removeAttr("checked");
					$("#attrib-10-50").removeAttr("checked");
					$("#wizard_3_2_lineColor").hide();
					$("#attrib-11-52").removeAttr("checked");
					$("#attrib-11-53").removeAttr("checked");
					$("#attrib-11-54").removeAttr("checked");
					//wizard_3_2_convertBlack
					$("#wizard_3_2_convertBlack").addClass("item6");
					$("#wizard_3_2_convertBlack").removeClass("item9");
					//set border color and background to nothing
					$('.dil_image_container').css({"border":"0px solid #ffffff"});
					$('.wizard_product_imageContainer').css({"background-color":"transparent"});
				}
				else
				{
					$("#wizard_3_2_borderColor").show();
					$("#attrib-14-64").attr("checked", "checked");
					$("#attrib-14-65").removeAttr("checked");
					$("#wizard_3_2_placment").show();
					$("#attrib-10-49").attr("checked", "checked");
					$("#wizard_3_2_lineColor").show();
					$("#attrib-11-52").attr("checked", "checked");
					$("#wizard_3_2_convertBlack").removeClass("item6");
					$("#wizard_3_2_convertBlack").addClass("item9");
				}
			}//end is headshots
			else if((pId==5)||(pId==4))
			{//business cards or post cards
				
				if((headshots_layoutChoice==151)||(headshots_layoutChoice==153))
				{// 151 vertical borderless 153 horizontal borderless
					$("#attrib-14-64").removeAttr("checked");//remove the checked button
					
					$("#attrib-14-65").attr("checked", "checked");//check 'on image'
					
					$("#wizard_3_2_placment").hide();//hide the name placement div
					$("#wizard_3_2_borderColor").hide();
					$("#attrib-10-49").removeAttr("checked");
					$("#attrib-10-50").removeAttr("checked");
					$("#wizard_3_2_lineColor").hide();
					$("#attrib-11-52").removeAttr("checked");
					$("#attrib-11-53").removeAttr("checked");
					$("#attrib-11-54").removeAttr("checked");
					//wizard_3_2_convertBlack
					$("#wizard_3_2_convertBlack").addClass("item6");
					$("#wizard_3_2_convertBlack").removeClass("item9");
					//set border color and background to nothing
					$('.dil_image_container').css({"border":"0px solid #ffffff"});
					$('.wizard_product_imageContainer').css({"background-color":"transparent"});
					
					if($("#attrib-26-22"))
					{//postcard no line
						$("#attrib-26-22").removeAttr("checked");
						$("#attrib-26-21").attr("checked", "checked");//check 'on image'
					}
					$("#wizard_3_2_moveName").show();
					
				}
				else
				{
					$("#wizard_3_2_borderColor").show();
					$("#attrib-14-64").attr("checked", "checked");
					$("#attrib-14-65").removeAttr("checked");
					$("#wizard_3_2_placment").hide();
					$("#attrib-10-49").attr("checked", "checked");
					$("#wizard_3_2_lineColor").show();
					$("#attrib-11-52").attr("checked", "checked");
					$("#wizard_3_2_convertBlack").removeClass("item6");
					$("#wizard_3_2_convertBlack").addClass("item9");
					if($("#attrib-26-22"))
					{//postcard no line
						$("#attrib-26-22").removeAttr("checked");
						$("#attrib-26-21").attr("checked", "checked");//check 'on image'
					}
					if((headshots_layoutChoice==152)&&(pId==4))
					{//horizontal with borders only has one move name choice, so hide it
						$("#wizard_3_2_moveName").hide();
					}
					else
					{
						$("#wizard_3_2_moveName").show();
					}
				}
			}//end is biz cards
			
			
		}//end use defalt DIL
		else
		{//set this back to true for rest of session
			DILdefault=true;	
		}
		setupDIL();
	}//end else new layout
	//save the layout choice
	currentLayoutChoice=$("input[name='id[52]']").getValue();
	
	
}//end prepareDILform





