<!-- // JavaScript Document - internal documents

function doPanels(navId) {
	if($('#nav'+navId).is(':hidden')) { $('.nav').slideUp(); $('#nav'+navId).slideDown(); }
}

function getNewImage(newImageId,newProductId) { // GET A NEW IMAGE FROM COMPLIMENTATY PRODUCTS
	if(newProductId) { // MM
	$.ajax ({ url: serverName()+"memoriam-cards/ajaxupdate.exe.php", type: 'GET', data: "design="+newProductId+"&pricecode="+newImageId,
	success: function(result1) { $("#memoriamDisplay").html(result1); } });
	$.ajax ({ url: serverName()+"memoriam-cards/ajaxupdate.exe.php", type: 'GET', data: "images="+newProductId+"&pricecode="+newImageId,
	success: function(result2) { var images = result2.split(","); for(var i = 1; i <= images.length; i++) {
	var j = i-1; $('#largeImage'+i).attr('src',images[j]); } } });
	} else { // WS
	var largeWidth = "780px"; $.ajax ({ url: serverName()+"wedding-stationery/ajaxupdate.exe.php", type: 'GET', data: "image="+newImageId,
	success: function(result) { if(result.indexOf("lrg")==-1) { largeWidth = "300px"; }
	$("#productImg").attr('src',result.replace("lrg/","med/")); $("#largeImage1").attr('src',result).css('width',largeWidth); } }); }
}

function doImage(imageId) { // SHOW HIDDEN DIVS WITH IMAGE ENLARGEMENTS
	if(!imageId) { imageId = 1; };
	scrollTo(0,0); var posLeft = (((windowSize("width"))-800)/2)+"px"; if($('#blowupImageContainer'+imageId).is(':hidden')) {
	$('#blowupImageContainer'+imageId).css({'left':posLeft}).slideDown(500); $('#mainBackground').css({'opacity':'0'}).show().animate({'opacity':'0.8'});
	} else {
	$('#blowupImageContainer'+imageId).fadeOut().slideUp(); $('#mainBackground').css({'opacity':'0'}).hide(); }
}

function gotoImage(thisImageId,nextImageId) { // SWAP IMAGE PANELS WHEN MORE THAN ONE BLOW-UP IMAGE PANELS IS DISPLAYED
	if(thisImageId>0) { if($('#largeImage'+nextImageId).attr("src")=="") {
	nextImageId = parseInt(nextImageId); if(nextImageId>thisImageId) { nextImageId+=1; } else { nextImageId-=1; } }
	var posLeft = (((windowSize("width"))-800)/2)+"px"; $('#blowupImageContainer'+nextImageId).css({'left':posLeft}).fadeIn(500);
	$('#blowupImageContainer'+thisImageId).fadeOut(); }
}

function doSample(sampleId,siteAreaIndex,priceCodeId) { // ADD A SAMPLE REQUEST TO THE CART
	var arrSiteArea = Array("wedding-stationery","memoriam-cards");
	var url = serverName()+arrSiteArea[siteAreaIndex]+"/ajaxupdate.exe.php?sample="+sampleId;
	if(priceCodeId) { url += "&pricecode="+priceCodeId; } window.location.href = url;
}

function getPrice(rowId,minUnit,minUnitPrice,repUnit,repUnitPrice) { //VALIDATE THE PRICE OF A PRODUCT
	var price = 0; var qty = $('#qty'+rowId).val(); if(qty=="") { qty==0; } if(isNaN(qty)) { qty = 0; }
	if(qty>0) { if(qty<=minUnit) { 	qty = minUnit; price = minUnitPrice; } 
	else { price = ((Math.ceil((qty - minUnit)/repUnit))*repUnitPrice)+minUnitPrice; } }
	$('#spanProductTotal'+rowId).html(price.toFixed(2)); $('#productTotal'+rowId).val(price.toFixed(2));
}

function getBBPrice(rowId,minUnit,minUnitPrice,repUnit,repUnitPrice1,repUnitPrice2,repUnitPrice3,repUnitPrice4,repUnitPrice5) {
	var price = 0, varQty, qty = $('#qty'+rowId).val(); if(qty=="") { qty==0; } if(isNaN(qty)) { qty = 0; }
	if(qty>0) { price = minUnitPrice; var totalReps	= Math.ceil((qty - minUnit)/repUnit); var repsOver = Math.ceil(50 / repUnit);
	if(totalReps>0) { var reps100 = Math.ceil((100 - minUnit)/repUnit);
	if(totalReps < reps100) { price = ((Math.ceil((qty - minUnit)/repUnit))*repUnitPrice1)+minUnitPrice; totalReps = 0; } else { price = ((Math.ceil((100 - minUnit)/repUnit))*repUnitPrice1)+minUnitPrice; totalReps = totalReps - reps100; }
	if(totalReps > 0)	{ if(totalReps > repsOver) { price += repsOver * repUnitPrice2; totalReps = totalReps - repsOver; } else { price += totalReps * repUnitPrice2; totalReps = 0; } }
	if(totalReps > 0)	{ if(totalReps > repsOver) { price += repsOver * repUnitPrice3; totalReps = totalReps - repsOver; } else { price += totalReps * repUnitPrice3; totalReps = 0; } }
	if(totalReps > 0)	{ if(totalReps > repsOver) { price += repsOver * repUnitPrice4; totalReps = totalReps - repsOver; } else { price += totalReps * repUnitPrice4; totalReps = 0; } }
	if(totalReps > 0)	{ price += totalReps * repUnitPrice5; } } }
	$('#spanProductTotal'+rowId).html(price.toFixed(2)); $('#productTotal'+rowId).val(price.toFixed(2));
}

function getXMPrice(rowId,unitPrice1,unitPrice2,unitPrice3,unitPrice4,unitPrice5,unitPrice6) {
	var price = 0, varQty, qty = $('#qty'+rowId).val(); if(qty=="") { qty==0; } if(isNaN(qty)) { qty = 0; }
	if(qty>0) {
		if(qty <= 25) 		{ price = unitPrice1; }
		else if(qty <= 50)	{ price = unitPrice2; }
		else if(qty <= 75)	{ price	= unitPrice3; }
		else if(qty <= 100)	{ price = unitPrice4; }
		else if(qty <= 500)	{ varQty = Math.ceil((qty-100)/25); price = (varQty * unitPrice5) + unitPrice4; }
		else				{ varQty = Math.ceil((qty-500)/50); price = (varQty * unitPrice6) + (16 * unitPrice5) + unitPrice4; } }		
	$('#spanProductTotal'+rowId).html(price.toFixed(2)); $('#productTotal'+rowId).val(price.toFixed(2));
}

function productSelection(panelId,newImageId,product_id) {
	var l = "#produtSelectionLi"+panelId; var t = "#productSelectionTable"+panelId; if($(t).is(':hidden')) { 
	$('.productSelectionTable').slideUp(); $('.productWordingTable').slideUp(); $(t).slideDown();
	$('.productSelectionLi').css("background-image", "url("+serverName()+"/_images/icons/bullit.png)");
	$(l).css("background-image", "url("+serverName()+"/_images/icons/productSelection.png)");
	if(newImageId) { var currentImageId = $('#imageId').val(); if(currentImageId != newImageId) { 
	if(product_id) { // MM
	$('#memoriamDisplay').html('<img src="'+serverName()+'_images/icons/loadPanel.gif" alt="Please wait" /><div style="position:absolute;top:250px;left:270px;">Updateing your selection, please wait</div>');
	setTimeout('getNewImage('+newImageId+','+product_id+')',400); 
	} else { // WS
	$('#productImg').attr('src', serverName()+"_images/icons/loadImage.gif");
	$('#imageId').val(newImageId); setTimeout('getNewImage('+newImageId+')',400); 
	} } } } 
}

function validatePrice(rowId,minUnit,repUnit,repUnit2) { // VALIDATE THE QUANTITY BEIGN REQUESTED FOR A PRODUCT
	var newQty; var msg = ""; var qty = $('#qty'+rowId).val(); if(qty=="") { qty==0; } 
	if(qty>0) { if(qty<minUnit) { newQty = minUnit; $('#qty'+rowId).val(newQty); msg = "The minimum sale quantity for this item is "+minUnit; } 
	else { if(location.href.indexOf("christmas-cards") != -1) { // WS
	if(qty>=500) { newQty = (Math.ceil((qty-500)/50))*50+500; } else { newQty = (Math.ceil(qty/25)*25); } }
	else { newQty = ((Math.ceil((qty - minUnit)/repUnit))*repUnit)+minUnit; } if(qty != newQty) {
	$('#qty'+rowId).val(newQty); msg = "This item is sold in units of "+minUnit; // ALL OTHERS
	if(repUnit2) { msg += " and " + repUnit2; } msg += " over the minimum sale unit of "+repUnit; } } } 
	if(msg !="") alert(msg+".\r\nFor this reason you quantity has been increased from "+qty+" to "+newQty+".");
}

function validateProduct() { //VALIDATE THAT A QUANTITY HAS BEEN ADDED TO THE PRODUCT TO PROCEED TO CART
	var qty = 0, totalQty = 0, msg = "", button = ""; 
	if($('#addWS').length>0) { button = '#addWS'; }
	else if($('#addMM').length>0) { button = '#addMM'; } 
	else if($('#addBB').length>0) { button = '#addBB'; }
	else if($('#addCC').length>0) { button = '#addCC'; }
	if(button=="") { qty = $('#qty1').val(); if(qty=="") { qty = 0; } if(isNaN(qty)) { qty = 0; }
	if(qty==0) { msg = "Please add the quantity to this product for your order\r\n"; } 
	if($('#product_wa_data1').length > 0)	{ if($('#product_wa_data1').val()=="") { msg += "Please complete the " + $('#product_wa_pers1').val() + "\r\n"; } }
	if($('#product_wa_data2').length != 0)	{ if($('#product_wa_data2').val()=="") { msg += "Please complete the " + $('#product_wa_pers2').val() + "\r\n"; } } }
	else { if(button.val()== "Add to Cart") { var totalTables = $('#totalCardProducts').val(); for(var i = 1; i<= totalTables; i++) { 
	qty = $('#qty'+i).val(); 
	if(qty=="") { qty = 0; } 
	totalQty += qty; 
	if((totalQty==0) && (msg=="")) { msg = "Please add quantity to one of the products you would like to order"; }
	} } } if(msg != "") { alert(msg); return false; } else { return true; }
}

function doCharity(tableId,rowId) {
	var totalRows = $('#totalCharity'+tableId).val(); var i; var check = false; if(rowId==1) { if($('#xmCharity1').not(':checked')) { 
	$('#xmCharity1').attr('checked', true); $('#charityInfo1').slideDown(); for(i = 2; i <= totalRows; i++) { 
	$('#xmCharity'+i).attr('checked', false); $('#charityInfo'+i).slideUp(); } } } else { $('#xmCharity1').attr('checked', false); $('#charityInfo1').slideUp();
	if($('#xmCharity'+rowId).is(':checked')) { $('#charityInfo'+rowId).slideDown(); } else { $('#charityInfo'+rowId).slideUp(); } }
	for(i = 1; i <= totalRows; i++) { if($('#xmCharity'+i).is(':checked')) { check = true; } } 
	if(check==false) { $('#xmCharity1').attr('checked', true); $('#charityInfo1').slideDown(); }
}

// CART
function checkCart(cellId,rowId) {
	var checkout = true; var currentCell = "#"+cellId+rowId; if(cellId == "extras") { if($(currentCell).is(":checked")) { 
	checkout = false; $('#extrasDiv'+rowId).html('Selected').css({'color':'#333'}); $('#extrasPrice'+rowId).css({'color':'#333'});
	} else { $('#extrasDiv'+rowId).html('Not Selected').css({'color':'#999'}); $('#extrasPrice'+rowId).css({'color':'#999'});
	} }  else { if($(currentCell).val() != $('#orderItemQtyOld'+rowId).val()) { checkout = false; } }
	if(checkout == true) { for(var i = 1; i <= $('#totalRows').val(); i++) { if($('#orderItemQty'+i).length == 0) { if($('#extras'+i).is(':checked')) { checkout = false; }
	} else { if($('#orderItemQty'+i).val() != $('#orderItemQtyOld'+i).val()) { checkout = false; } } } }
	if(checkout == true) { $('#checkout').show(); $('#submit').hide(); } else { $('#checkout').hide(); $('#submit').show(); }
}

function doDelivery(countrySelect) { //SWAP FROM DELIVERY TO COLLECTION IN THE CART
	if(countrySelect) { window.location = getSelectedIndex(countrySelect); } else {
	var i = 0; var hide; var show; var deliveryId = getSelectedIndex('deliveryMethod');
	var arrDelivery		= Array("#deliveryCountrySpan","#priceDelivery","#cartTotalDelivery","#cartTotalSaleDelivery");
	var arrCollection	= Array("#priceCollection","#cartTotalCollection","#cartTotalSaleCollection");
	if(deliveryId == 0) { hide = arrDelivery; show = arrCollection; } else { hide = arrCollection; show = arrDelivery; }
	for(i = 0; i <= 5; i++) { $(hide[i]).hide(); $(show[i]).show(); }
	$.ajax ({ url: serverName()+"/cart/ajaxupdate.exe.php", type: 'GET', data: "delivery="+deliveryId,
 	success: function(result) { } }); }
}

function doForm(formIdTag) { // SHOW HIDDEN DIVS WITH IMAGE ENLARGEMENTS
	scrollTo(0,0); var posLeft = (((windowSize("width"))-800)/2)+"px";  var formId = "#"+formIdTag+"Form";
	if($(formId).is(':hidden')) {
	$(formId).css({'left':posLeft}).slideDown(500); $('#mainBackground').css({'opacity':'0'}).show().animate({'opacity':'0.8'});
	} else {
	$(formId).fadeOut().slideUp(); $('.smallFormCell').val(''); $('#'+formIdTag+'Result').html('&nbsp;');
	$('.error').hide(); $('#mainBackground').css({'opacity':'0'}).hide(); }
}
			
//$('#memoriamBrochureSubmit').click(function() { // MEMORIAM FORM VALIDATION AND SUBMISSION

function submitSmallFrom() {
	$('#memoriamBrochureLoading').show(); 
	var submitForm	= true; var data = Array(); var arrCells = Array('mmName','mmAddress','mmPhone','mmEmail');
	var spamCode	= $('#mmSpamcode').val();	var confirmCode	= $('#mmSpamcodeConfirm').val();
	for(var i = 0; i <= 3; i++) { data[i] = $('#'+arrCells[i]).val();
	if(data[i] == "")	{	$('#'+arrCells[i]+'Error').show(); submitForm = false; }
	else				{	$('#'+arrCells[i]+'Error').hide(); } }
	if(spamCode != confirmCode)	{	$('#errormmSpamcode').show(); submitForm = false; }
	else						{	$('#errormmSpamcode').hide(); }
	if(submitForm == true) { $.ajax({ url: serverName()+"memoriam-cards/ajaxupdate.exe.php", type: 'POST',  
	data: 'submitForm=true&name='+data[0]+'&address='+data[1]+'&phone='+data[2]+'&email='+data[3],
	success: function(result) { $('#memoriamBrochureResult').html(result); setTimeout('doForm(\'memoriamBrochure\')',4000); } }); 
	} else { $('#memoriamBrochureResult').html('Please amend the details in your form to submit your request'); } 
	$('#memoriamBrochureLoading').hide(); return false;
}

function copyBilling() { // MONITOR AND COPIES BILLING ADDRESS TO DELIVERY ADDRESS IN THE CHECKOUT
	var pass = ""; if(doc.getElementById("copyDetails").checked == true) {
	doc.getElementById("order_detail_delivery_address1").value = doc.getElementById("order_detail_billing_address1").value;
	if(doc.getElementById("order_detail_billing_address1").value == "") { pass = "first line of"; }
	doc.getElementById("order_detail_delivery_address2").value = doc.getElementById("order_detail_billing_address2").value; 
	doc.getElementById("order_detail_delivery_postcode").value = doc.getElementById("order_detail_billing_postcode").value; 
	if(doc.getElementById("order_detail_billing_postcode").value == "")	{ pass = "postcode for"; }
	doc.getElementById("order_detail_delivery_city").value = doc.getElementById("order_detail_billing_city").value; 
	if(doc.getElementById("order_detail_billing_city").value == "") { pass = "city or county in"; }
	//this line only for customer accounts
	if(doc.getElementById("order_detail_delivery_country_id")) { var bilValue = getSelectedIndex("order_detail_billing_country_id");
	for(var i = 1; i <= 300; i++) { if(doc.getElementById("order_detail_delivery_country_id").options[i]) {
	if(bilValue == doc.getElementById("order_detail_delivery_country_id").options[i].value) { var newIndex = i; }}}
	if(newIndex) { doc.getElementById("order_detail_delivery_country_id").selectedIndex = newIndex; } 
	else { alert('The billing country you have selected is not available as a country where we can deliver to.'); }}}
	else { doc.getElementById("order_detail_delivery_address1").value = doc.getElementById("order_detail_delivery_address2").value = doc.getElementById("order_detail_delivery_postcode").value = doc.getElementById("order_detail_delivery_city").value = "";  }
}

function verifyNow(account) { // WARNING JS POPUP THAT T&C HAS NOT BEED CHECKED AND CARD DETAILS ARE INCORRECT
	var pass = true; 
	var msg = "Please complete the following data\r\n-------------------------------------\r\n";
	if(doc.getElementById("verifyOrder").checked != true) { 
	alert("Please click the check box to confirm that\r\n - You accept our terms and conditions of sale\r\n - You have read our privacy statement\r\n - You accept the value on your payment card"); pass = false; 
 	} else { 
	var ccType 	= getSelectedIndex('credit_card_type'); var ccMonth = getSelectedIndex('credit_card_month')-1;
	var ccYear 	= parseInt(getSelectedIndex('credit_card_year')) + 2000; var ccCvv 	= $('#credit_card_cvv').val();
	var ccNo	= $('#credit_card_number').val(); var today = new Date(); var cardDate=new Date(); 
	cardDate.setFullYear(ccYear,ccMonth,daysInMonth(ccMonth,ccYear));		
	if($('#credit_card_name').val() == ""){ msg = msg + "Please complete the name on the payment card\r\n"; pass = false; }
	if((ccNo == "")	|| (ccNo.length < 16))				{ msg = msg + "Please complete your payment card number\r\n"; pass = false; }
	if(cardDate < today) 								{ msg = msg + "The card expiriation date is invalid\r\n"; pass = false; }
	if(((ccType != 'LASER') && (ccCvv.length != 3)) || (isNaN(ccCvv)==true)) { msg = msg + "Please complete your CVV number\r\n"; pass = false; }
	if(pass == false) { alert(msg); } } 
	if((!account) && (pass == true)) {
	scrollTo(0,0); var posLeft = (((windowSize("width"))-400)/2)+"px"; 
	$('#pleaseWait').css({'left':posLeft}).show(); $('#mainBackground').css({'opacity':'0'}).show().animate({'opacity':'0.8'}); }	
	return pass;
}

function daysInMonth(iMonth, iYear) { //number of days in a month for verifyNow()
	return 32 - new Date(iYear, iMonth, 32).getDate();
}

function ccType() { //ACVTIVE CVV BOX BY SELECTED PAYMENT CARD TYPE
	var i = getSelectedIndex('credit_card_type'); var j = doc.getElementById('credit_card_cvv'); 
	if(i == "LASER") { j.value = ""; j.disabled = true; } else { j.disabled = false; }
}

function doCheckout() { // CLOSES THE CHECKOUT PANEL
	$('#checkoutDetails').fadeOut().slideUp(); $('#mainBackground').css({'opacity':0}).hide();
}

function viewTerms(id) {
	window.open(serverName()+"checkout/terms.php?id="+id,"Terms &amp; Conditions","width=700,height=600,location=0,scrollbars=1");
}
