$(document).ready(function(){


		


		//set variables


		var product = $("#prod"),


			productVal = product.val(),


			useLeafletLayout = $("#useLeafletLayout").val(),


			attributes = $("#attributes"),


			statusMsg = $("#status-message"),


			form = $("#printwizardform"),


			recalculate = $("#recalculate"),


			calc_select = $("#calc_selection"),


			templatelink = $("#download-template-link"),


			calcstouse = $("input[name='calcs_to_use']"),


			firstpageload = 1;


		


		


		function productChange(){


			attributes.html("<li class='loading'><span>Loading...</span><img src='assets/images/ajax-loader.gif' alt='loading'></li>");


			$.ajax({


				url: 'ajax.asp?action=getprodattrs&product=' + productVal,


				type: 'GET',


				success: function(data){


					var html = data; //html dropdowns


					setTimeout(function(){


						$(".loading").fadeOut(200,function(){


							


							//add dropdowns html to attriubtes div, then hide so we can do some other stuff


							attributes.html(html).hide();


							


							//set attribute defaults


							$("#attr_2 option[value='29'], #attr_3 option[value='5'], #attr_10 option[value='5']").attr("selected","selected");


							


							//bind attrChange event to dropdowns


							attributes.find('li').each(function(){


								$(this).find('select').bind('change',function(){ 


									var attr_name = $(this).attr("name"),


										attr_val = $(this).val();


									attrChange(attr_name,attr_val); 


								})


							})	


							


							//if ncr pads


							if(productVal == '14'){


								$("#attr_35, #attr_39, #attr_43").parent().hide()


								$("#attr_36, #attr_40, #attr_44").parent().hide()


								$("#attr_32").bind('change',function(){


									var attr_val = $(this).val();


									switch(attr_val){


										case '1': // 2 parts


											$("#attr_35, #attr_39, #attr_43").parent().slideUp(200) //part 3


											$("#attr_36, #attr_40, #attr_44").parent().slideUp(200) //part 4


										break;


										case '2': // 3 parts


											$("#attr_35, #attr_39, #attr_43").parent().slideDown(200) //part 3


											$("#attr_36, #attr_40, #attr_44").parent().slideUp(200) //part 4


										break;


										case '3': // 4 parts


											$("#attr_35, #attr_39, #attr_43").parent().slideDown(200) //part 3


											$("#attr_36, #attr_40, #attr_44").parent().slideDown(200) //part 4


										break;


									}


								})


							}


							


							//if wiro brochures


							if(productVal == '13'){


								$("#attr_26, #attr_28, #attr_29").parent().hide() //FRONT COVER


								$("#attr_46, #attr_47, #attr_48").parent().hide() //BACK COVER


								$("#attr_25").bind('change',function(){


									var attr_val = $(this).val(); 


									if(attr_val == '1'){


										$("#attr_26, #attr_28, #attr_29").parent().slideUp(200);


									}


									else {


										$("#attr_26, #attr_28, #attr_29").parent().slideDown(200);


									}


								})


								$("#attr_45").bind('change',function(){


									var attr_val = $(this).val(); 


									if(attr_val == '1' || attr_val == '4'){


										$("#attr_46, #attr_47, #attr_48").parent().slideUp(200)


									}


									else {


										$("#attr_46, #attr_47, #attr_48").parent().slideDown(200)


									}


								})


							}


							


							//if stiched brochures


							if(productVal == '6'){


								$("#attr_3, #attr_6, #attr_4").parent().hide();


								var attr12_opt1 = $("#attr_12 option[value='1']").clone();


								$("#attr_12 option[value='1']").remove();


								$("#attr_12 option[value='2']").attr("selected","selected");


								


								$("#attr_5").parent().after("<li id='wf_calc'><p>For a 4 page leaflet <strong><a href='index.php?p=15&pages=8'>click here</a></strong></p></li>");


							}


							


							//if perfectbound brochures


							if(productVal == '11'){


								$("#attr_3, #attr_6, #attr_4").parent().hide();


							}


							


							//if leaftlets set default options


							if((productVal == '5' || productVal == '15') && firstpageload == 1){


								$("#attr_16").find("option[value='19']").attr("selected","selected");


							}


							


							


							//if new leaflets inject images


							if(productVal == '15' && useLeafletLayout !== '1'){


								$("#attr_2").parent().after("<li><div id='colour-instructions-step1'><p>choose your finish</p></div><br class='leaflet-instruction-spacer' /></li>");


								$("#attr_17").parent().after("<li><div id='proof-instructions-step1'><p>free screen proof by email included</p></div><br class='leaflet-instruction-spacer' /></li>");


							}


							


							if(productVal == '15' && useLeafletLayout == '1'){


								$("#attr_2").parent().after("<li><div id='colour-instructions-step1'><p>choose your finishing</p></div><br class='leaflet-instruction-spacer' /></li>");


								$("#attr_17").parent().after("<li><div id='proof-instructions-step1'><p>free screen proof by email included</p></div><br class='leaflet-instruction-spacer' /></li>");


							}


							


							


							if(productVal == '15' && useLeafletLayout == '1'){


								var foldImagesHTML = "<div class='pinkgradient-box clearfix' id='folddisplay'><ul><li><img src='/assets/images/leaflets_231110/zigzagfold.png' alt='Zig Zag Fold' /><span>Zig Zag Fold</span></li><li><img src='/assets/images/leaflets_231110/rollfold.png' alt='Roll Fold' /><span>Roll Fold</span></li></ul></div>";


								


								


								$('#attr_8').prev().before(foldImagesHTML);


								


							}


							


							//bind bookletcovers function to attribute 5 change event


							$("#attr_5").bind('change',function(){ 


								var attr_val = $(this).val();


								if(attr_val == '2'){


									$("#attr_3, #attr_6, #attr_4").parent().slideDown("fast")


									$("#attr_12").prepend(attr12_opt1)


									$("#attr_12 option[value='1']").attr("selected","selected")


								}


								else {


									$("#attr_3, #attr_6, #attr_4").parent().slideUp("fast")


									$("#attr_12 option[value='1']").remove()


									$("#attr_12 option[value='2']").attr("selected","selected")


								}


							})


							


							//trigger attribute change


							if(productVal == '5' || productVal == '15'){ //if leaflets


								attrChange('attr_15','6');


							}


							else { //if any other product


								attrChange('attr_15','1');


							}


							


							


							if(productVal == '15'){


								var fold = $("#attr_8").closest('li');


								fold.hide();


								


								//if default pages


								var pd = $("#pages_default").val();


								if(pd){


									$("#attr_15").find("option[value='"+pd+"']").attr("selected","selected");


									attrChange('attr_15',pd);


								}


							}


							


							//show attribute dropdowns


							attributes.slideDown("slow");


							


							//hide status message


							statusMsg.hide();


							


							//page type indicators


							/*


							if(productVal == '4' || productVal == '5' || productVal == '9'){ //if buisness card, leaflet or menu


								$("#attr_15").parent().after("<li><div id='page-indicator'><img src='' /></div></li>");


								pageIndicator();


							}


							*/


							//fold type indicator


							/*


							$("#attr_8").parent().after("<li><div id='fold-indicator'><img src='' /></div></li>");


							$("#fold-indicator").parent().hide();


							$("#attr_8").bind('change',function(){


								foldIndicator();							 


							})


							*/


							//set template download link


							//templatelink.attr('href','/templates/index.php?p='+productVal);


						});


					},500);


				}


			});


		}


		


		//on attribute change


		function attrChange(caller,callerVal){


			


			$("#calculations-instructions-step2-leaflets").hide();


			


			/*


			if(caller == 'attr_15' && (productVal == '4' || productVal == '5' || productVal == '9')){


				pageIndicator();	


			}


			*/


			


			if(caller == 'attr_15' && parseInt(callerVal) > 8 && productVal == '15' && useLeafletLayout == '1'){


				$('#folddisplay').slideDown()	


			}


			else {


				$('#folddisplay').slideUp();	


			}


			


			$.ajax({


				url: 'ajax.asp?action=prodattrchange&product='+productVal+'&attr='+caller+'&attrval='+callerVal,


				type: 'GET',


				success: function(data){


					


					//parse json response


					response = eval(data);


					


					//loop through response and change attributes values


					if(parseInt(response.attrstochange) > 0 ){


						for(i=1; i<=parseInt(response.attrstochange); i++){


							var html = eval("response.html" + String(i));


							var target = eval("response.target" + String(i));


							$("#"+target).html(html);


							/*


							if(target == 'attr_8'){ //if fold attribute data is changed run fold indicator function


								foldIndicator();	


							}


							*/


						}


						//statusMsg.html("<img src='assets/images/change-attribute.gif' alt='Attributes Have Changed' />")


						//		 .fadeIn("fast");


					}


					else {


						//statusMsg.fadeOut("fast");	


					}


					


					//disable input for auto creasing


					var papervalues = ["22","21","15","16","17","18","23","24","25","26","27","28","29","30","31","32","33","34"],


						pagevalues = ["3","4","5","8","9","10","11","12","13","14","15","16"],


						autocreasing1,autocreasing2;


			


					for(var i=0; i<=pagevalues.length-1; i++){


						if( $("#attr_15").val() == pagevalues[i] ){


							autocreasing1 = 1;


						}


					}


					


					for(var i=0; i<=papervalues.length-1; i++){


						if( $("#attr_16").val() == papervalues[i] ){


							autocreasing2 = 1;	


						}


					}


					


					if(autocreasing1 == 1 && autocreasing2 == 1){


						$("#attr_7").find("option[text='No Crease']").remove()


						autocreasing1 = 0;


						autocreasing2 = 0;


					}


					else {


						var nocreaseopt = $("#attr_7").find("option[text='No Crease']");


						if(nocreaseopt.length == 0 && productVal !== '14' && productVal !== '7'){ //prod 14 and 7 do not want to have the no crease option


							$("#attr_7").append("<option value='3' selected='selected'>No Crease</option>");


						}


					}


					


					


					if((productVal == '5' || productVal == '15')&& firstpageload == 1){


						firstpageload = 0


						$("#attr_9").find("option[value='3']").attr("selected","selected");


					}


					


					


					if(productVal == '15'){


						var page = $("#attr_15").val()


						var fold = $("#attr_8").closest('li');


						if(page == '6' || page == '7'){


							fold.slideUp(200);	


						}


						else {


							fold.slideDown(200)	


						}


					}


					


					


					//recalculate price after attribute changes


					calculatePrice();


					


					//IF POSTERS


					/*


					if($("#prod").val() == "3"){


						if( $("#attr_9").val() == "45"){


							if($("#bespoke-dimensions").length < 1){


								$("#attr_9").parent().append("<div id='bespoke-dimensions'><label for='bd_h'>Height:</label><input type='text' name='bd_h' id='bd_h' value='100'><label for='bd_w'>Width:</label><input type='text' name='bd_w' id='bd_w' value='100'></div>")


								$("#bespoke-dimensions").hide().slideDown(100)


							}


						}


						else {


							$("#bespoke-dimensions").slideUp(100,function(){ $(this).remove() })


						}


					}


					*/





				}


			});	


		}


		


		//calculate price


		function calculatePrice(calltype){


			var pricelist,


				calltype;


			


			$("body").append("<div id='please-wait'>Loading, Please Wait...</div>");


			$("#please-wait").css({


				'position':'fixed',


				'top':'-100px',


				'padding':'5px 20px',


				'background-color':'#000000',


				'color':'#FFF',	


				'left':'45%'


			}).animate({


				top: 0


			})


			


			if(useLeafletLayout == 1){	//if using new leaflet layout code has to be run slightly differently


				if(calltype == 'buttonclick'){


					leaflets_get_custom_price();


				}


				else {


					leaflets_get_all_prices();


				}


			}


			else { 


			    //used by all products except leaflets


				//post form to get pricing list


				$.post("getprices.asp?method=getallprices", form.serialize(), function(data){


					pricelist = data;


					


					if( $(pricelist).find('input[value="digital"]').length < 1 ){


						$('#calcs_to_use_digital').attr('disabled','disabled');	


					}


					else {


						$('#calcs_to_use_digital').attr('disabled','');		


					}																	   


					


					//post form again to get selectable prices


					$.post("getprices.asp?method=getselectableprices", form.serialize(), function(data){ 


						var formula = $("#f_used").val(),


							prices = $("#prices")


					


						//if was not called via recalculate button


						if(calltype !== 'buttonclick'){


							


							$("#pricelist").fadeOut(200,function(){


								$(this).remove();


							})


							


							$(".roundedtop").fadeOut(200,function(){


								$(this).remove();


							})


						}


						


						$("#prices").fadeOut(200,function(){


							prices.html(data)


	


							prices.fadeIn(200);


							


							//if was not called via recalculate button


							if(calltype !== 'buttonclick'){


								//insert price list html before calculate button


								$("#calculate").before(pricelist) 


								


								


								


								


								//hide pricelist then fade in


								$("#pricelist").hide().fadeIn(200);		


							}


							


							


							


							//DEBUG CODE


							//var debug = $("#debug").html()


							//$("#debug").remove();


							//$("#debug-info").html(debug)


							//END DEBUG


													


							//if product is posters and formula used is wideformat


							//if(productVal == '3' && formula == 'wideformat'){


							//	$("#attr_16").html("<option value='33'>220gsm Silk</option>");


							//	statusMsg.fadeIn(200);


							//}


							


							//post to get add to basket buttons


							//$.post("pricecalculatorprocess.asp", form.serialize(), function(data){


							//	var html = data


							//	$("#add-to-basket-buttons").fadeOut(function(){


							//		$(this).html(html);


							//		$(this).fadeIn(200);											 


							//	})


							//})


						})


					});


					$("#please-wait").animate({ top: -100 },function(){ $(this).remove() });


				})


			}


		}


		


		/*


		//page indicators


		function pageIndicator(){


			var pagesdropdown = $("#attr_15");


			var pagesdropdown_parent = pagesdropdown.parent();


			var pagesdropdown_val = pagesdropdown.val();


			var indicator = $("#page-indicator");


			var image = '';


			var product = '';


			


			indicator.slideUp(200,function(){ 


				switch(productVal){


					case '4':


						product = 'businesscard';


					break;


					case '5':


						product = 'leaflet';


					break;


					case '9':


						product = 'menu';


					break;


				}


				switch(pagesdropdown_val){


					case '1':


						image = '_single_double.jpg';


					break;


					case '2':


						image = '_single_double.jpg';


					break;


					case '3':


						image = '_4page.jpg';


					break;


					case '4':


						image = '_6page.jpg';


					break;


					case '5':


						image = '_8page.jpg';


					break;


					case '6':


						image = '_single_double.jpg';


					break;


					case '7':


						image = '_single_double.jpg';


					break;


					case '8':


						image = '_4page.jpg';


					break;


					case '9':


						image = '_6page.jpg';


					break;


					case '10':


						image = '_8page.jpg';


					break;


					case '11':


						image = '_10page.jpg';


					break;


				}


				var fullimage = product + image;


				indicator.find('img').attr('src','/assets/images/page_indicators/'+fullimage);


				indicator.slideDown(200);	


			});


		}


		*/


		


		//fold indicators


		/*


		function foldIndicator(){


			var folddropdown = $("#attr_8");


			var folddropdown_parent = folddropdown.parent();


			var folddropdown_val = folddropdown.val();


			var foldindicator = $("#fold-indicator");


			var image = '';


			


			if(folddropdown_val !== '4'){ 


				foldindicator.parent().slideUp(200,function(){ 


					switch(folddropdown_val){


						case '1':


							image = 'fold-zigzag.jpg';


						break;


						case '2':


							image = 'fold-roll.jpg';


						break;


						case '3':


							image = 'fold-gate.jpg';


						break;


						case '4':


							image = 'fold-none.jpg';


						break;


						case '5':


							image = 'fold-singlefold.jpg';


						break;


						default:


							image = 'fold-none.jpg';


						break;


					}


					foldindicator.find('img').attr('src','/assets/images/fold_indicators/'+image);


					foldindicator.parent().slideDown(200);	


				});


			}


			else {


				foldindicator.parent().slideUp(200);


			}


		}


		*/


		


		//tooltips


		$(".more-info").live('mouseover mouseout',function(event){


			var parent = $(this).parent();


			var moreinfo = parent.find(".attr-desc").text();


			if(event.type == 'mouseover'){


				parent.append("<div class='tool-tip'><div class='tt-top'></div><div class='tt-mid'>"+moreinfo+"</div><div class='tt-bottom'></div></div>")


				parent.find(".tool-tip").hide().fadeIn(200);


			}


			else {


				parent.find(".tool-tip").fadeOut(200,function(){


					$(this).remove();									   


				})


			}


		})


		


		


		//bindings


		recalculate.live('click',function(){


			calculatePrice('buttonclick');


		})


		


		calc_select.find("input").bind('change',function(){


			calculatePrice();										   


		})


		


		calcstouse.bind('change',function(){


			showLoading();


			calculatePrice();							  


		})


		


		//misc functions


		function attrChangeNoRecalc(caller,callerVal,productVal){


			/*


			if(caller == 'attr_15' && (productVal == '4' || productVal == '5' || productVal == '9')){


				pageIndicator();	


			}


			*/


			$.ajax({


				url: 'ajax.asp?action=prodattrchange&product='+productVal+'&attr='+caller+'&attrval='+callerVal,


				type: 'GET',


				success: function(data){


					


					//parse json response


					response = eval(data);


					


					//loop through response and change attributes values


					if(parseInt(response.attrstochange) > 0 ){


						for(i=1; i<=parseInt(response.attrstochange); i++){


							var html = eval("response.html" + String(i));


							var target = eval("response.target" + String(i));


							$("#"+target).html(html);


						}


						//statusMsg.html("<img src='assets/images/change-attribute.gif' alt='Attributes Have Changed' />")


						//		 .fadeIn("fast");


								 


						//foldIndicator();


					}


					else {


						//statusMsg.fadeOut("fast");	


					}


					


					//disable input for auto creasing


					var papervalues = ["22","21","15","16","17","18","23","24","25","26","27","28","29","30","31","32","33","34"],


						pagevalues = ["3","4","5","8","9","10","11","12","13","14","15","16"],


						autocreasing1,autocreasing2;


			


					for(var i=0; i<=pagevalues.length-1; i++){


						if( $("#attr_15").val() == pagevalues[i] ){


							autocreasing1 = 1;


						}


					}


					


					for(var i=0; i<=papervalues.length-1; i++){


						if( $("#attr_16").val() == papervalues[i] ){


							autocreasing2 = 1;	


						}


					}


					


					if(autocreasing1 == 1 && autocreasing2 == 1){


						$("#attr_7").find("option[text='No Crease']").remove()


						autocreasing1 = 0;


						autocreasing2 = 0;


					}


					else {


						var nocreaseopt = $("#attr_7").find("option[text='No Crease']");


						if(nocreaseopt.length == 0 && productVal !== '14' && productVal !== '7'){ //prod 14 and 7 do not want to have the no crease option


							$("#attr_7").append("<option value='3' selected='selected'>No Crease</option>");


						}


					}


					


					//foldIndicator();


				}


			});	


		}


		


		//dynamic advert click


		function processAdvertInput(e){


			var input = e.attr('name').split('_');							


			var inputVal = e.val();


			$("#"+input[1]+'_'+input[2]).val(inputVal);


		}


		


		$(".calculator-advert a").bind('click',function(){


			$(this).parent().find('input').each(function(){


				processAdvertInput($(this), function(){ attrChangeNoRecalc(input[1]+'_'+input[2],inputVal,productVal) } );


			})


			calculatePrice();


			//pageIndicator();


			//foldIndicator();


			showLoading();


			return false;


		})


		


		//loading notifier


		function showLoading(){


			$("body").append("<div id='please-wait'>Loading, Please Wait...</div>");


			$("#please-wait").css({


				'position':'fixed',


				'top':'-100px',


				'padding':'5px 20px',


				'background-color':'#000000',


				'color':'#FFF',	


				'left':'45%'


			}).animate({


				top: 0


			},{


				duration:200,


				complete:function(){


					setTimeout(function(){


						$("#please-wait").animate({ top: -100 },function(){ $(this).remove() });				


					},1000);


				}


			})


		}


		


		var working = 0;


		$("#pricelist tr").live('click',function(){


			


			var tr = $(this).closest('tr'),


				klass = tr.attr('class')


				


			//if(working == 0){


				//working = 1


				$(".pricelist-active").removeClass("pricelist-active");


				if(tr.attr('id') !== 'buy-row'){


					if(tr.next().attr('id') == 'buy-row'){


						$("#buy-row div").slideUp(200,function(){


							$(this).closest('tr').remove();


							working = 0


						})


					}


					else {


						$("#buy-row div").slideUp(200,function(){


							$(this).closest('tr').remove();


						})	


						


						//post to get add to basket href


						var href,


							quantity = $(this).find("input[name='pl_quantity']").val(),


							price = $(this).find("input[name='pl_price']").val(),


							delivery = $(this).find("input[name='pl_delivery']").val(),


							formula = $(this).find("input[name='pl_formula']").val()


						


						$.post("pricecalculatorprocess.asp?quantity="+quantity+"&price="+price+"&delivery="+delivery+"&f="+formula+"", form.serialize(), function(data){


							href = data;


							tr.after(


								"<tr id='buy-row' class='"+klass+"'>"+


								"<td colspan='3'>"+


								


								"<div><a href='"+href+"' class='addtobasket_custom'><img src='assets/images/button-addtobasket2.png'  alt='add to your basket' /></a></div>"+


								


								"</td>"+


								"</tr>"


							);


							$("#buy-row div").hide().slideDown(200);


							tr.addClass('pricelist-active');


							//working = 0


						})	


					}


				}


			//}


		})


		


		$("#final-price-details").live('click',function(){


			var href,


			quantity = $("input[name='c_quantity']").val(),


			price = $("input[name='c_price']").val(),


			delivery = $("input[name='c_delivery']").val(),


			formula = $("input[name='c_formula']").val(),


			me = $(this)


			


			if( $("#final-price-details").hasClass('active') ){


				$("#addcustomtobasket").slideUp(200,function(){


					$(this).remove();


					$("#final-price-details").removeClass('active');


				})


			}


			else {


				$.post("pricecalculatorprocess.asp?quantity="+quantity+"&price="+price+"&delivery="+delivery+"&f="+formula+"", form.serialize(), function(data){


					href = data;


					me.append("<div id='addcustomtobasket'><a href='"+href+"' class='addtobasket_custom'><img src='assets/images/button-addtobasket2.png'  alt='add to your basket' /></a></div>");


					$("#addcustomtobasket").hide().slideDown(200)


					$("#final-price-details").addClass('active');


				})		


			}	


		})


		


		//on page load


		productChange(function(){ 


			//callback after productChange has done


			//foldIndicator()


		});


		


		


		


		//calculate on type on new leaflets page


		$("#custom-quantity-small").live('keyup',function(){


			clearTimeout(t);


			var t = setTimeout(function(){


				leaflets_get_custom_price();


			},800);


		});


		


		


})








function leaflets_get_custom_price(){


	var digtpalpricesurl = 'getprices.asp?method=getselectableprices&isleafletspage=1&calcstouse=digital',


		lithopricesurl = 'getprices.asp?method=getselectableprices&isleafletspage=1&calcstouse=litho',


		sixdaydespatchpricesurl = 'getprices.asp?method=getselectableprices&isleafletspage=1&calcstouse=litho&is6day=1',


		digitalprices, 


		lithoprices, 


		sixdaydespatchprices, 


		digitalhtml = '',


		lithohtml = '', 


		sixdaydespatchhtml = '',


		form = $("#printwizardform"),


		self = $(this);


		


	$("#digital_price_ph, #litho_price_ph, #sixday_despatch_price_ph").fadeOut(200,function(){			


		$.ajax({


			type: 'POST',


			url: digtpalpricesurl, 


			data: form.serialize(), 


			dataType: 'json',


			success: function(data){ 


				digitalprices = data;


				$.ajax({


					type: 'POST',


					url: lithopricesurl, 


					data: form.serialize(), 


					dataType: 'json',


					success: function(data){ 


						lithoprices = data;


						$.ajax({


							type: 'POST',


							url: sixdaydespatchpricesurl,


							data: form.serialize(),


							dataType: 'json',


							success: function(data){


								sixdaydespatchprices = data;


								var dobj = digitalprices.price[0],


									lobj = lithoprices.price[0],


									sddobj = sixdaydespatchprices.price[0],


									digital_price_html = '';


							


								digitalhtml = '';


								lithohtml = '';


								sixdaydespatchhtml = '';


								


								digitalhtml += "<input type='hidden' name='c_quantity' value='"+dobj.c_quantity+"' />";


								digitalhtml += "<input type='hidden' name='c_price' value='"+dobj.c_price+"' />";


								digitalhtml += "<input type='hidden' name='c_delivery' value='"+dobj.c_delivery+"' />";


								digitalhtml += "<input type='hidden' name='c_formula' value='"+dobj.c_formula+"' />";


								


								sixdaydespatchhtml += "<input type='hidden' name='c_quantity' value='"+sddobj.c_quantity+"' />";


								sixdaydespatchhtml += "<input type='hidden' name='c_price' value='"+sddobj.c_price+"' />";


								sixdaydespatchhtml += "<input type='hidden' name='c_delivery' value='"+sddobj.c_delivery+"' />";


								sixdaydespatchhtml += "<input type='hidden' name='c_formula' value='"+sddobj.c_formula+"' />";


								


								lithohtml += "<input type='hidden' name='c_quantity' value='"+lobj.c_quantity+"' />";


								lithohtml += "<input type='hidden' name='c_price' value='"+lobj.c_price+"' />";


								lithohtml += "<input type='hidden' name='c_delivery' value='"+lobj.c_delivery+"' />";


								lithohtml += "<input type='hidden' name='c_formula' value='"+lobj.c_formula+"' />";


								


								if(parseFloat(dobj.c_price) > 99999999999.00){


									digital_price_html = "N/A";	


								}


								else {


									digital_price_html = "&pound;" + dobj.c_price + digitalhtml;


								}


								


								$("#digital_price_ph").html(digital_price_html);


								


								$("#digital_price_ph").parent().removeClass('sl_formula');


								if(dobj.uses_sl_formula){


									$("#digital_price_ph").parent().addClass('sl_formula');		


								}


								


								$("#litho_price_ph").html("&pound;" + lobj.c_price + lithohtml);


								//$("#sixday_despatch_price_ph").html("&pound;" + sddobj.c_price + sixdaydespatchhtml);


								$("#sixday_despatch_price_ph").html("&pound;" + lobj.c_price + lithohtml);


								$("#digital_price_ph, #litho_price_ph, #sixday_despatch_price_ph").fadeIn(200);


								$("#please-wait").animate({ top: -100 },function(){ $(this).remove() });	


							}


						});


					}


				});


			}


		});


	});	


}





function leaflets_get_all_prices(){


	var digtpalpricesurl = 'getprices.asp?method=getallprices&isleafletspage=1&calcstouse=digital',


		lithopricesurl = 'getprices.asp?method=getallprices&isleafletspage=1&calcstouse=litho',


		sixdaydespatchpricesurl = 'getprices.asp?method=getallprices&isleafletspage=1&calcstouse=litho&is6day=1',


		digitalprices, 


		lithoprices,


		sixdaydespatchprices,


		html = '',


		form = $("#printwizardform"),


		self = $(this);


		


	$("#prices").fadeOut(200,function(){


		$.ajax({


			type: 'POST',


			url: digtpalpricesurl, 


			data: form.serialize(),


			dataType: 'json',


			success: function(data){ 


				digitalprices = data;


				$.ajax({


					type: 'POST',


					url: lithopricesurl, 


					data: form.serialize(), 


					dataType: 'json',


					success: function(data){ 


						lithoprices = data;


						$.ajax({


							type: 'POST',


							url: sixdaydespatchpricesurl, 


							data: form.serialize(), 


							dataType: 'json',


							success: function(data){


								sixdaydespatchprices = data;


								


								if( $("#attr_14").val() !== '10' ){


									var leadtime = 5;


								}


								else {


									var leadtime = 2;


								}


								


								html += "<div id='leaflets-price-list'><table><thead><tr><td id='quantity-column-header' valign='bottom'>Quantity</td><td id='digital-column-header'><span class='type'>Digital</span><span class='description'>"+leadtime+" Day Dispatch</span></td><td id='litho-column-header'><span class='type'>Litho</span><span class='description'>6 Day Dispatch</span></td></tr></thead><tbody>";


								html += "<tr>";


								html += "<td class='quantity quantity-input'><label for='quantity' id='quantity-label'>Custom Amount</label>"


								html += "<input type='text' name='quantity' id='custom-quantity-small' value='100' /></td>";


								html += "<td class='digital-price'><span id='digital_price_ph'></span></td>";


								html += "<td class='sixday-despatch-price'><span id='sixday_despatch_price_ph'></span></td>";


								//html += "<td class='litho-price'><span id='litho_price_ph'></span></td>";


								html += "</tr>";


								


								for(var i = 0; i<=(digitalprices.pricelist.length - 1); i++){


									var dobj = digitalprices.pricelist[i],


										lobj = lithoprices.pricelist[i],


										sddobj = sixdaydespatchprices.pricelist[i];


									


									html += "<tr>";


									html += "<td class='quantity'>" + dobj.pl_quantity + "</td>";


									


									if(dobj.uses_sl_formula){


										var slclass = 'sl_formula';		


									}


									else {


										var slclass = '';


									}


									


									if(parseFloat(dobj.pl_price) > 99999999999.00){


										html += "<td class='digital-price'>N/A";	


									}


									else {


										html += "<td class='digital-price "+slclass+"'>&pound;" + dobj.pl_price ;


									}


									html += "<input type='hidden' name='pl_quantity' value='"+dobj.pl_quantity+"' />";


									html += "<input type='hidden' name='pl_price' value='"+dobj.pl_price+"' />";


									html += "<input type='hidden' name='pl_delivery' value='"+dobj.pl_delivery+"' />";


									html += "<input type='hidden' name='pl_formula' value='"+dobj.pl_formula+"' />";


									


									html += "</td>";


									


									//sddobj


									html += "<td class='sixday-despatch-price'>&pound;" + lobj.pl_price;


									html += "<input type='hidden' name='pl_quantity' value='"+lobj.pl_quantity+"' />";


									html += "<input type='hidden' name='pl_price' value='"+lobj.pl_price+"' />";


									html += "<input type='hidden' name='pl_delivery' value='"+lobj.pl_delivery+"' />";


									html += "<input type='hidden' name='pl_formula' value='"+lobj.pl_formula+"' />";


									html += "</td>";


									


									/*


									html += "</td>";


									html += "<td class='litho-price'>&pound;" + lobj.pl_price;


									html += "<input type='hidden' name='pl_quantity' value='"+lobj.pl_quantity+"' />";


									html += "<input type='hidden' name='pl_price' value='"+lobj.pl_price+"' />";


									html += "<input type='hidden' name='pl_delivery' value='"+lobj.pl_delivery+"' />";


									html += "<input type='hidden' name='pl_formula' value='"+lobj.pl_formula+"' />";


									html += "</td>";


									html += "</tr>";


									*/


								}


								


								html += "</tbody></table>";


								html += "<img id='dispatch-is-quicker'  src='../assets/images/leaflets_231110/dispatch_is_quicker.png>";


								html += "</div>";


								$("#prices").html(html);


								$("#prices").fadeIn(200);


								$("#please-wait").animate({ top: -100 },function(){ $(this).remove() });


								$("#calculations-instructions-step2-leaflets").css('visibility','visible').hide().fadeIn(200);


								leaflets_get_custom_price();


							}


						});


					}


				});


			}


		});


	});


}





$(document).ready(function(){


	


	$('.digital-price, .litho-price, .sixday-despatch-price').live('click',function(){


		var tr = $(this).closest('tr'),


				klass = tr.attr('class'),


				self = $(this)


		


		if( self.text() !== 'N/A' ){ 


		


			//add active class


			$('.digital-price.active, .litho-price.active, .sixday-despatch-price.active').removeClass('active');


			self.addClass('active');


			


			//slide up current active row


			$("#buy-row div").slideUp(200,function(){


				$(this).closest('tr').remove();


			})


	


					


			//post to get add to basket href


			var href;


			if( $(this).find("input[name='pl_quantity']").length > 0 ){


				var	quantity = $(this).find("input[name='pl_quantity']").val(),


					price = $(this).find("input[name='pl_price']").val(),


					delivery = $(this).find("input[name='pl_delivery']").val(),


					formula = $(this).find("input[name='pl_formula']").val()


			}


			else {


				var	quantity = $(this).find("input[name='c_quantity']").val(),


					price = $(this).find("input[name='c_price']").val(),


					delivery = $(this).find("input[name='c_delivery']").val(),


					formula = $(this).find("input[name='c_formula']").val()	


			}


			


			var form = $('#printwizardform'),


				url = "pricecalculatorprocess.asp?quantity="+quantity+"&price="+price+"&delivery="+delivery+"&f="+formula+"";


			


			$.post(url, form.serialize(), function(data){


				href = data;


				tr.after(


					"<tr id='buy-row' class='"+klass+"'>"+


					"<td colspan='4'>"+


					"<div><a href='"+href+"' class='addtobasket_custom'><img src='assets/images/button-addtobasket2.png'  alt='add to your basket' /></a></div>"+


					"</td>"+


					"</tr>"


				);


				$("#buy-row div").hide().slideDown(200);


				tr.addClass('pricelist-active');


			});	


		}


				


	});


	


	


	/*


	$("#leaflets-table-header-img").live('mousemove',function(e){


		var digitaltooltip = $("#attr-desc-digital").text();


		var lithotooltip = $("#attr-desc-litho").text();


		


		if( (e.pageX > 793 && e.pageX < (793 + 16)) && (e.pageY > 469 && e.pageY < (469 + 16))){ //lith0 bubble


			if( !$('.tool-tip').length ){


				$(this).parent().append("<div class='tool-tip'><div class='tt-top'></div><div class='tt-mid'>"+lithotooltip+"</div><div class='tt-bottom'></div></div>")


				$('.tool-tip').css({ 


					'top' : '0',


					'right' : '-180px'  


				}).hide().fadeIn(200);


			}


		}


		else if((e.pageX > 868 && e.pageX < (868 + 16)) && (e.pageY > 469 && e.pageY < (469 + 16))){  //digital bubble


			if( !$('.tool-tip').length ){


				$(this).parent().append("<div class='tool-tip'><div class='tt-top'></div><div class='tt-mid'>"+digitaltooltip+"</div><div class='tt-bottom'></div></div>")


				$('.tool-tip').css({ 


					'top' : '0',


					'right' : '-255px'


				}).hide().fadeIn(200);


			}	


		}


		else {


			$('.tool-tip').fadeOut(200,function(){


				$(this).remove();


			})


		}


	});


	


	$('.tool-tip').live('mouseout',function(){


		$(this).fadeOut(200,function(){


			$(this).remove();


		})


	})


	*/


	


	$('form').bind("keypress", function (e) {


    	if (e.keyCode == 13) return false;


    });





	


	


	


});
