// JavaScript Document
function doNav(theUrl) {
	document.location.href = theUrl;
}
var loader = new Image();
loader.src = 'images/loader_green.gif';
function pleaseWait(table,row,cell) {
	//var button = document.getElementById('submitbutton');
	var x=document.getElementById(table).rows[row].cells;
	x[cell].innerHTML='<div id="pleaseWaitLoading"><img src="images/loader_green.gif" align="absbottom"> Please Wait...</div>';
	//button.style.color="#999999";
	//button.disabled=true;
}
function hidePleaseWait() {
	$('pleaseWaitLoading').hide();
}
function deleteAskRabbi(id) {
	if(confirm('Are you sure you want to permanently delete this posting?')) {
		doNav('admin_askrabbi.php?action=process&section=delete&id='+id);
	}
	return false;
}
function deleteCommentary(id) {
	if(confirm('Are you sure you want to permanently delete this commentary?')) {
		doNav('admin_commentaries.php?action=process&section=delete&id='+id);
	}
	return false;
}
function deleteMedia(id) {
	if(confirm('Are you sure you want to permanently delete this media file?')) {
		doNav('admin_media.php?action=process&section=delete&id='+id);
	}
	return false;
}
function deleteProduct(id) {
	if(confirm('Are you sure you want to permanently delete this product and all associated reviews?')) {
		doNav('admin_products.php?action=process&section=delete&id='+id);
	}
	return false;
}
function deleteReview(rid,id) {
	if(confirm('Are you sure you want to permanently delete this product review?')) {
		doNav('admin_products.php?action=process&section=deletereview&id='+id+'&reviewid='+rid);
	}
	return false;
}
function approveReview(rid,id) {
	if(confirm('This action will cause this review to be visible on this product\'s profile page.  Are you sure you want to approve this product review?')) {
		doNav('admin_products.php?action=process&section=approvereview&id='+id+'&reviewid='+rid);
	}
	return false;
}
function deleteSpeakingEngagement(id) {
	if(confirm('Are you sure you want to permanently delete this speaking engagement?')) {
		doNav('admin_speaking.php?action=process&section=delete&id='+id);
	}
	return false;
}
function deletePage(id) {
	if(confirm('Are you sure you want to permanently delete this page?')) {
		doNav('admin_pages.php?action=process&section=delete&id='+id);
	}
	return false;
}
function deleteThoughtTools(id) {
	if(confirm('Are you sure you want to permanently delete this Thought Tools archive?')) {
		doNav('admin_thoughttools.php?action=process&section=delete&id='+id);
	}
	return false;
}
function deleteFAQ(id) {
	if(confirm('Are you sure you want to permanently delete this FAQ?')) {
		doNav('admin_faq.php?action=process&section=delete&id='+id);
	}
	return false;
}
function deleteThis(id,type) {
	if(confirm('Are you sure you want to completely remove this '+type+'?')) {
		var url = $(id).href;
		doNav(url);
	}
	return false;
}
function getDDCal(id,month,year) {
	if(document.getElementById('cal'+id).style.display == 'none') {
		new Effect.Appear('cal'+id,{duration:.2});
	}
	document.getElementById('cal'+id).innerHTML = '<div id="contentLoading" style="display:none;" align="center"><br>Loading...<br /><br /><img src="images/gray_loader.gif" width="24" height="24" /></div>';
	new Effect.Appear('contentLoading',{duration:.1});
	new Ajax.Request('dd_cal.php?month='+month+'&year='+year+'&id='+id,
		 {
			method:'get',
			onComplete: function(transport){
				new Effect.Fade('contentLoading',{duration:.1});
				var response = transport.responseText || "no response text";
				document.getElementById('cal'+id).innerHTML = response;
				$('innercal'+id).hide();
			  	new Effect.Appear('innercal'+id, { duration:.3, queue: 'end' });
			},
			onFailure: function(){ alert('Something went wrong...Please select a date again.') }
		  });
}
function closeDDCal(id) {
	new Effect.Fade('cal'+id,{duration:.2});
}
function selectDay(id,month,day,year) {
	
	new Effect.Fade('cal'+id,{duration:.2});
	document.getElementById('caldate'+id).value = month+'/'+day+'/'+year;
}
function showDropDownMenu(id,parent) {
	$(id).show();
	$(parent).className = 'highlighttab';
}
function hideDropDownMenu(id,parent) {
	$(id).hide();
	$(parent).className = '';
}
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=0,width=600,height=700');");
}
function printAskRabbi(id) {
	popUp('print_ask_rabbi.php?id='+id);
	return false;
}
function relatedPopup(url) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=1024,height=600');");
	return false;
}
function loadMedia(id) {
	$('media').innerHTML = '<div id="contentLoading" style="display:block;"><img src="images/loader_gray.gif" width="24" height="24" border="0" /></div>';
	//new Effect.Appear('contentLoading');
	new Ajax.Request('ajax_media.php?id='+id,
		{
			method:'get',
			onSuccess: function(transport) {
				//new Effect.Fade('contentLoading');
				var response = transport.responseText || "no response text";
				$('media').innerHTML = response;
				showMedia();
			},
			onFailure: function() { alert('Something went wrong...Please try again.') }
		});
	return false;
}
function showMedia() {
	if(Object.isElement($('mediaFile'))) {
		new Effect.Appear('mediaFile');
	} else {
		setTimeout('showMedia();',1000);
	}
}
function openPopup(url) {
	window.open(url,'','width=400,height=400,toolbar=no,status=no,titlebar=no,menubar=no,location=no');
	return false;
}
function showStoreClosure(dates,title,message) {
	var viewport = document.viewport.getDimensions();
	var page = $(document.body).getDimensions();
	var width, height;
	if(viewport.width < page.width) {
		width = page.width;
	} else {
		width = viewport.width;
	}
	if(viewport.height < page.height) {
		height = page.height;
	} else {
		height = viewport.height;
	}
	doNav('#');
	$(document.body).insert('<div id="popupMessage" class="popupMessage"><div class="closed">Our Store Will Be Closed<br />'+dates+'</div><h1>'+title+'</h1>'+message+'<br /><br /><div align="center"><a href="store.php">Browse the Online Bookstore</a></div></div>');
	$(document.body).insert('<div id="overlay" class="overlay" style="width:'+width+'px;height:'+(height+60)+'px"></div>');
	new Event.observe(window,'resize',function() {
		adjustOverlay();
	});
}
function adjustOverlay() {
	var viewport = document.viewport.getDimensions();
	var page = $(document.body).getDimensions();
	var width, height;
	if(viewport.width < page.width) {
		width = page.width;
	} else {
		width = viewport.width;
	}
	if(viewport.height < page.height) {
		height = page.height;
	} else {
		height = viewport.height;
	}
	$('overlay').setStyle({width:width+'px',height:(height+60)+'px'});
}
function showLightBox(title,message) {
	var viewport = document.viewport.getDimensions();
	var page = $(document.body).getDimensions();
	var width, height;
	if(viewport.width < page.width) {
		width = page.width;
	} else {
		width = viewport.width;
	}
	if(viewport.height < page.height) {
		height = page.height;
	} else {
		height = viewport.height;
	}
	doNav('#');
	$(document.body).insert('<div id="popupMessage" class="popupMessage"><div style="float:right;"><a href="#" onclick="return closeLightBox();"><img src="images/icons/close.gif" border="0" alt="Close Window" /></a></div><h1>'+title+'</h1>'+message+'<br /><br /></div>');
	$(document.body).insert('<div id="overlay" class="overlay" style="width:'+width+'px;height:'+(height+60)+'px"></div>');
	new Event.observe(window,'resize',function() {
		adjustOverlay();
	});
}
function closeLightBox() {
	if(Object.isElement($('popupMessage'))) {
		$('popupMessage').remove();
	}
	if(Object.isElement($('overlay'))) {
		$('overlay').remove();
	}
}
function updateCart() {
	$('shoppingCartForm').action = 'cart.php?action=update_cart';
	$('shoppingCartForm').submit();
}
function continueCheckout() {
/*	showLightBox('Error','An unknown error has occured.');
	return false;*/
	new Ajax.Request('ajax_checkcart.php',{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			if(response != '') {
				showLightBox('You Can Save More!','<div>We noticed that some of the products in your shopping cart belong to a set of products.  Buying the set instead of each individual product will save you money!<br /><br />Would you like us to remove the products and add the set to your shopping cart?<br /><br /><div><input type="button" name="cancel" value="Continue With Purchase" onclick="continueCheckout2();" />&nbsp;&nbsp;<input type="button" name="Go" value="Buy The Set Instead" onclick="switchProductsInCart(\''+response+'\');" /></div></div>');
			} else {
				continueCheckout2();
			}
		},
		onFailure:function() { alert('We encountered an error. Please refresh and try again.'); }
	});
}
function continueCheckout2() {
	closeLightBox();
	new Ajax.Request('ajax_checkcart.php?action=duplicates',{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			if(response != '') {
				showLightBox('Duplicate Products',response);
			} else {
				continueCheckout3();
			}
		},
		onFailure:function() { alert('We encountered an error. Please refresh and try again.'); }
	});
}
function continueCheckout3() {
	closeLightBox();
	new Ajax.Request('ajax_checkcart.php?action=downloads',{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			if(response != '') {
				showLightBox('Instant Downloads',response);
			} else {
				continueCheckout4();
			}
		},
		onFailure:function() { alert('We encountered an error. Please refresh and try again.'); }
	});
	
}
function continueCheckout4() {
	closeLightBox();
	continueCheckout5();
	/*new Ajax.Request('ajax_checkcart.php?action=setdownloads',{
			method:'get',
			onSuccess:function(transport) {
				var response = transport.responseText;
				if(response != '') {
					showLightBox('Instant Downloads',response);
				} else {
					$('shoppingCartForm').action = 'cart.php?action=checkout';
					$('shoppingCartForm').submit();
				}
			},
			onFailure:function() { alert('We encountered an error. Please refresh and try again.'); }
		});*/
}
function continueCheckout5() {
	$('shoppingCartForm').action = 'https://www.rabbidaniellapin.com/cart.php?action=checkout';
	$('shoppingCartForm').submit();
}
function switchProductsInCart(response) {
	doNav('cart.php?action=switchset&response='+response);
}
function switchToDownloadsInCart(p) {
	doNav('cart.php?action=switchdownloads&products='+p);
}
function switchSetsToDownloadsInCart(p) {
	doNav('cart.php?action=switchsetdownloads&products='+p);
}
function removeDuplicates(p) {
	doNav('cart.php?action=removeduplicates&products='+p);
}
var applyingCode;
function applyPromoCode() {
	if(applyingCode || CartRequest) {
		return false;
	}
	var promo = $('PROMOCODE').value;
	new Ajax.Request('cart.php?action=addpromo&promo='+promo,{
		method:'get',
		onCreate:function(request) {
			applyingCode = request;
		},
		onSuccess:function(transport) {
			var response = transport.responseText;
			if(response != '') {
				showLightBox('Error:','<div id="message">'+response+'</div>');
			}
			loadShoppingCart();
			applyingCode = false;
		}
	});
	return false;
}
function removePromo(id) {
	if(confirm('Are you sure you want to remove this promo code from your shopping cart?')) {
		new Ajax.Request('cart.php?action=removepromo&promo='+id,{
			method:'get',
			onSuccess:function(transport) {
				var response = transport.responseText;
				if(response != '') {
					showLightBox('Error:',response);
				}
				loadShoppingCart();
			}
		});
	}
	return false;
}
function removeProduct(id,type) {
	if(confirm('Are you sure you want to remove this product from your shopping cart?')) {
		new Ajax.Request('cart.php?action=removeproduct&product='+id+'&type='+type,{
			method:'get',
			onSuccess:function(transport) {
				var response = transport.responseText;
				if(response != '') {
					showLightBox('Error:',response);
				}
				loadShoppingCart();
			}
		});
	}
	return false;
}
function checkIfEnter() {
	new Event.observe(document,'keypress',function(event) {
		if(event.keyCode == Event.KEY_RETURN) {
			updateShoppingCart(t);
		}
	});
}
var AjaxRequest;
function calculateShipping() {
	if(AjaxRequest) {
		AjaxRequest.transport.abort();
	}
	var subtotal = $('subTotal').value;
	$('shippingDisplay').innerHTML = '<img src="images/loader_small.gif" border="0" alt="Loading"/>';
	var ship = $('shippingSelection').selectedIndex;
	ship = $('shippingSelection').options[ship].value;
	var zip = escape($('zipCode').value);
	var weight = $('shippingWeight').value;
	new Ajax.Request('ajax_ups.php?ship='+ship+'&zip='+zip+'&weight='+weight+'&total='+subtotal,{
		method:'get',
		onCreate:function(request) { AjaxRequest = request; },
		onComplete:function(transport) {
			var response = transport.responseText;
			if(response.match('international') || response.match('domestic')) {
				updateShippingOptions();
				calculateShipping();
			} else if(response != '') {
				if(response.search('Error:') == '-1') {
					if(response == '0.00') {
						$('shippingDisplay').innerHTML = 'FREE';
					} else {
						$('shippingDisplay').innerHTML = '$'+(response*1).toFixed(2);
					}
					$('shippingValue').value = response;
					calculateSalesTax(zip);
					updateShippingOptions();
					/*var newtotal = (subtotal*1)+(response*1);
										var tax = $('salesTax').value;
										if(tax != '') {
											newtotal = newtotal+(tax*1);
										}
										$('totalDisplay').innerHTML = '$'+newtotal.toFixed(2);*/
				} else if(response.search('Error: The requested service is invalid from the selected origin.') != '-1') {
					alert('We cannot ship to the zip code you have specified.  If you are in the US, please select a shipping method that does not say "International".  If you are in Canada, please select an International shipping method.');
					$('shippingDisplay').innerHTML = '-';
					calculateSalesTax(zip);
					//$('totalDisplay').innerHTML = '$'+subtotal.toFixed(2);
				} else {
					alert(response);
					$('shippingDisplay').innerHTML = '-';
					calculateSalesTax(zip);
					//$('totalDisplay').innerHTML = '$'+subtotal.toFixed(2);
				}
			} else {
				$('shippingDisplay').innerHTML = '-';
			}
		},
		onFailure:function() { alert('There was a problem retrieving shipping information.'); }
	});
}
function updateShippingOptions() {
	var subtotal = $('subTotal').value;
	var weight = $('shippingWeight').value;
	var zip = $('zipCode').value;
	new Ajax.Request('ajax_ups.php?action=options&zip='+zip+'&total='+subtotal+'&weight='+weight,{
		method:'get',
		onComplete:function(transport) {
			var response = transport.responseText;
			$('shippingOptions').innerHTML = response;
			if($('shippingDisplay').innerHTML == '-') {
				calculateShipping();
			}
		}
	});
}
var isCalculating = false;
function calculateShippingFinal() {
	$('shippingDisplay').innerHTML = '<img src="images/loader_small.gif" border="0" alt="Loading" align="absmiddle"/> Retrieving shipping rates.';
	var country = $('country').options[$('country').selectedIndex].value;
	var subtotal = escape($('subTotal').value);
	var address = escape($('address').value);
	var address2 = escape($('address2').value);
	var city = escape($('city').value);
	var state = escape($('state').value);
	var zip = escape($('zip').value);
	var weight = $('shippingWeight').value;
	new Ajax.Request('ajax_ups.php?action=final&address='+address+'&address2='+address2+'&city='+city+'&state='+state+'&zip='+zip+'&country='+country+'&weight='+weight+'&total='+subtotal,{
		method:'get',
		onCreate:function(request) { isCalculating = request; },
		onComplete:function(transport) {
			var response = transport.responseText;
			if(response != '') {
				$('shippingDisplay').innerHTML = response;
			} else {
				$('shippingDisplay').innerHTML = 'Error: We could not find rates based on the information you entered.';
			}
			isCalculating = false;
		},
		onFailure:function() { alert('There was a problem retrieving shipping information.'); }
	});
}
function allowShipping() {
	if(isCalculating) {
		$('pleaseWaitLoading').update('Please wait for the shipping rates to finish loading and then click continue.');
		return false;
	} else {
		return lookupCityStateFinal('shippingInfo');
	}
}
function calculateSalesTax(zip) {
	zip = escape(zip);
	var subtotal = $F('subTotal');
	new Ajax.Request('ajax_taxes.php?zip='+zip+'&subtotal='+subtotal,{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			if(response != '') {
				$('taxDisplay').update('$'+response+'<input type="hidden" name="salesTax" id="salesTax" value="'+response+'" />');
				$('taxRow').show();
			} else {
				$('taxDisplay').update('$0.00<input type="hidden" name="salesTax" id="salesTax" value="0.00" />');
				$('taxRow').hide();
			}
			updateTotal();
		},
		onFailure:function() { alert('There was a problem communicating with the server. Please hit refresh.'); }
	});
}
function updateTotal() {
	var subtotal = $F('subTotal');
	var tax = $F('salesTax');
	var ship = $F('shippingValue');
	var total = '0.00';
	total = total*1;
	if(subtotal != '') {
		total = total+(subtotal*1);
	}
	if(ship != '') {
		total = total+(ship*1);
	}
	if(tax != '') {
		total = total+(tax*1);
	}
	$('totalDisplay').update('$'+total.toFixed(2));
}
function focusField(id,def) {
	if($(id).value == def) {
		$(id).value = '';
		$(id).setStyle({
			color:'#333'
		});
	}
}
function blurField(id,def) {
	if($(id).value == '') {
		$(id).setStyle({
			color:'#CCC'
		});
		$(id).value = def;
	}
}
function lookupEmail() {
	if(AjaxRequest) {
		AjaxRequest.transport.abort();
	}
	var email = $('email').value;
	$('loadingEmail').innerHTML = '<img src="images/loader_small.gif" border="0" align="absbottom" /> <span class="dkgray">Looking for previous orders. Please wait.</span>';
	new Ajax.Request('ajax_billing.php?email='+email,{
		method:'get',
		onCreate:function(request) { AjaxRequest = request; },
		onComplete:function(transport) {
			var response = transport.responseText;
			if(response != '') {
				response = response.split('+');
				$('loadingEmail').innerHTML = '<span class="green">Some of your information was filled in from a previous order.</span>';
				$('first').value = response[0];
				$('last').value = response[1];
				$('address').value = response[2];
				$('address2').value = response[3];
				$('city').value = response[4];
				$('state').value = response[5];
				$('zip').value = response[6];
				var country = $('country');
				for(var x=0;x<country.options.length;x++) {
					if(country.options[x].value == response[7]) {
						country.selectedIndex = x;
					}
				}
				$('phone').value = response[8];
				/*
				var hear = $('hear');
								for(var x=0;x<=hear.options.length;x++) {
									if(hear.options[x].text == response[9]) {
										hear.selectedIndex = x;
									}
								}*/
				
			} else {
				$('loadingEmail').innerHTML = 'Please fill in your billing information below.';
			}
		},
		onFailure:function() { alert('There was a problem retrieving your information.'); }
	});
}
var lookup = false;
function lookupCityState() {
	if(lookup) {
		lookup.transport.abort();
	}
	var country = $('country').options[$('country').selectedIndex].value;
	if(country == 'US' || country == 'CA') {
		var zip = $F('zip');
		var city = $F('city');
		var state = $F('state');
		new Ajax.Request('ajax_billing.php?action=citystate&zip='+zip+'&city='+city+'&state='+state,{
			method:'get',
			onCreate:function(request) { lookup = request; },
			onComplete:function(transport) {
				var response = transport.responseText;
				if(response != '') {
					showLightBox('Zip Code / City Error','<div>The zip code you entered, '+zip+', doesn\'t match the city/state combination of '+city+', '+state+' that you entered.  We can correct the city and state for you or if you entered the wrong zip code, you can change it manually.  Which would you like to do?<br /><br /><div><input type="button" name="cancel" value="Let Me Change the Zip Code" onclick="changeZipCode();" />&nbsp;&nbsp;<input type="button" name="Go" value="Change the City/State For Me" onclick="changeCityState(\''+response+'\');" /></div></div>');
				}
				lookup = false;
			},
			onFailure:function() { alert('There was a problem retrieving your information.'); }
		});
	}
}
function lookupCityStateFinal(form) {
	if(lookup) {
		lookup.transport.abort();
	}
	var country = $('country').options[$('country').selectedIndex].value;
	if(country == 'US' || country == 'CA') {
		var zip = $F('zip');
		var city = $F('city');
		var state = $F('state');
		new Ajax.Request('ajax_billing.php?action=citystate&zip='+zip+'&city='+city+'&state='+state,{
			method:'get',
			onCreate:function(request) { lookupCityState = request; },
			onComplete:function(transport) {
				var response = transport.responseText;
				if(response != '') {
					showLightBox('Zip Code / City Error','<div>The zip code you entered, '+zip+', doesn\'t match the city/state combination of '+city+', '+state+' that you entered.  We can correct the city and state for you or if you entered the wrong zip code, you can change it manually.  Which would you like to do?<br /><br /><div><input type="button" name="cancel" value="Let Me Change the Zip Code" onclick="changeZipCode();" />&nbsp;&nbsp;<input type="button" name="Go" value="Change the City/State For Me" onclick="changeCityState(\''+response+'\',\''+form+'\');" /></div></div>');
					hidePleaseWait();
				} else {
					continueSubmission(form);
				}
				lookup = false;
			},
			onFailure:function() { alert('There was a problem retrieving your information.'); }
		});
		return false;
	}
}
function changeZipCode() {
	new Ajax.Request('ajax_billing.php?action=changemanually',{
		method:'get',
		onComplete:function(transport) {
			var response = transport.responseText;
			if(response != '') {
				alert(response);
			}
			closeLightBox();
			$('zip').select();
		}
	});
}
function changeCityState(response,go) {
	closeLightBox();
	response = response.split('+');
	$('city').value = response[0];
	$('state').value = response[1];
	$('zip').value = response[2];
	if(go) {
		continueSubmission(go);
	}
}
function continueSubmission(form) {
	$(form).submit();
}
var delayid;
function paymentSelection() {
	if($('echeck').checked) {
		$('paypalDiv').hide();
		$('creditcardDiv').hide();
		$('echeckDiv').show();
		$('paymentConfirmForm').action = 'checkout_payment.php?action=process&section=echeck';
	} else if($('paypal').checked) {
		$('echeckDiv').hide();
		$('creditcardDiv').hide();
		$('paypalDiv').show();
		$('paymentConfirmForm').action = 'https://www.paypal.com/cgi-bin/webscr';
		showLightBox('Pay with Paypal','<div>By selecting Paypal as your payment option, you will be redirected to the Paypal website.  Don\'t worry, your shopping cart will make the trip with you.<br /><br />Please click the cancel button if this is not how you want to pay.<br /><br /><input type="button" name="cancel" onclick="cancelPaypal();" value="Cancel" /> Transferring in <span id="countDown">12</span> seconds</div>');
		delayid = setTimeout(function() { $('paymentConfirmForm').submit(); },12000);
		var timer = setTimeout(countDownTimer,1000);
	} else if($('creditcard').checked) {
		$('paypalDiv').hide();
		$('echeckDiv').hide();
		$('creditcardDiv').show();
		$('paymentConfirmForm').action = 'checkout_payment.php?action=process&section=cc';
	}
}
function countDownTimer() {
	var t = $('countDown').innerHTML;
	if(t != 0) {
		$('countDown').innerHTML = (t*1)-1;
		var timer = setTimeout(countDownTimer,1000);
	}
}
function cancelPaypal() {
	clearTimeout(delayid);
	closeLightBox();
	$('echeckDiv').hide();
	$('creditcardDiv').hide();
	$('paypalDiv').hide();
	$('paypal').checked = false;
}
function displaySecurityCodeBox() {
	showLightBox('Security Code','A security code helps us to verify that you are the holder of this credit card.  Take a look at the image below to find the security code on your credit card.<br /><br /><div align="center"><img src="thumb_gen.php?s=images/cv_card.jpg&w=280" /></div>');
	return false;
}
function openPrintableReceipt(url) {
	window.open(url,'','width=750,toolbar=no,status=no,titlebar=no,menubar=no,location=no');
	return false;
}
function refundOrder(id) {
	if(confirm('Are you sure you want to refund the total amount of this order to the customer?')) {
		doNav('admin_orders.php?action=process&section=refund&id='+id);
	}
	closeLightBox();
	return false;
}
function refundPartialOrder(id) {
	var amount = prompt('Please enter the total amount you want to refund for this order:');
	if(amount) {
		doNav('admin_orders.php?action=process&section=partialrefund&id='+id+'&amount='+amount);
	} else {
		closeLightBox();
	}
	return false;
}
function refundPopup(id) {
	showLightBox('Refund Order','<div>Which would you like to do?<br /><br /><input type="button" onclick="refundOrder(\''+id+'\');" value="Refund Full Amount" />&nbsp;&nbsp;&nbsp;<input type="button" onclick="refundPartialOrder(\''+id+'\');" value="Refund Partial Amount" /></div>')
}
function loadShoppingCart(foc) {
	new Ajax.Request('ajax_cart.php',{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			$('shoppingCart').innerHTML = response;
			loadTopShoppingCart();
			calculateShipping();
			if(Object.isElement($(foc))) {
				$(foc).focus();
			}
		},
		onFailure:function() { alert('There was a problem loading your shopping cart. Please refresh the page and we\'ll try again.'); }
	});
	return true;
}
function loadTopShoppingCart() {
	new Ajax.Request('ajax_cart.php?action=topdisplay',{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			$('topShoppingCartDisplay').innerHTML = response;
		}
	});
}
var CartRequest;
function updateShoppingCart(element) {
	if(Object.isElement($(element))) {
		var foc = $(element).identify();
	} else {
		var foc = '';
	}
	if(CartRequest) {
		CartRequest.transport.abort();
	}
	var action = $('shoppingCartForm').action;
	var form = $('shoppingCartForm');
	if(action == '') {
		var product = form['product[]'];
		var qty = form['qty[]'];
		var type = form['type[]'];
		var p = new Array();
		var q = new Array();
		var t = new Array();
		if(product.length) {
			for(var i=0;i<product.length;i++) {
				p[i] = $F(product[i]);
				q[i] = $F(qty[i]);
				if(q[i] == '0') {
					if(!confirm('Changing the quantity to 0 will remove the product from your shopping cart.  Are you sure you want to continue?')) {
						loadShoppingCart(foc);
						return false;
					}
				} else if(q[i] == '') {
					return false;
				}
				t[i] = $F(type[i]);
			}
		} else {
			p[0] = product.value;
			q[0] = qty.value;
			t[0] = type.value;
			if(q[0] == '0') {
				if(!confirm('Changing the quantity to 0 will remove the product from your shopping cart.  Are you sure you want to continue?')) {
					loadShoppingCart(foc);
					return false;
				}
			} else if(q[0] == '') {
				return false;
			}
		}
		var params = new Hash();
		params.set('qty',q.join('+'));
		params.set('product',p.join('+'));
		params.set('type',t.join('+'));
		params.set('PROMOCODE',$F('PROMOCODE'));
		$('PROMOCODE').value = '';
		new Ajax.Request('cart.php?action=update_cart',{
			method:'post',
			parameters:params,
			onCreate:function(request) { CartRequest = request; },
			onSuccess:function(transport) {
				var response = transport.responseText;
				if(response != '') {
					showLightBox('Error:',response);
				}
				loadShoppingCart(foc);
			},
			onFailure:function() { alert('There was a problem updating the shopping cart. Please try again.'); }
		});
		return false;
	}
}
function removeOrderCookie() {
	closeLightBox();
	new Ajax.Request('ajax_orders.php?action=remove',{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			if(response != '') {
				alert(response);
			}
		},
		onFailure:function() { alert('There was a problem communicating with the server. Please click refresh in your browser.'); }
	});
}
function confirmOrder(id) {
	closeLightBox();
	new Ajax.Request('ajax_orders.php?action=confirm&id='+id,{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			showLightBox('Order Confirmation',response);
		},
		onFailure:function() { alert('There was a problem communicating with the server. Please click refresh in your browser and try again.'); }
	});
}
function resendOrderConfirmation(id) {
	closeLightBox();
	new Ajax.Request('ajax_orders.php?action=resend&id='+id,{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			showLightBox('Email Resent',response);
		},
		onFailure:function() { alert('There was a problem communicating with the server. Please click refresh in your browser and try again.'); }
	});
}
function searchFAQ() {
	var search = $('faqsearch').value;
	new Ajax.Updater('faqDisplay','ajax_faq.php?search='+search);
	return false;
}
function resetFAQSearch() {
	doNav('popup_faq.php');
}
function searchAskRabbi() {
	var search = $('rabbisearch').value;
	new Ajax.Updater('rabbiDisplay','ajax_askrabbi.php?search='+search);
	return false;
}
function resetAskRabbiSearch() {
	doNav('ask_rabbi.php');
}
function correspondanceBox(info) {
	var viewport = document.viewport.getDimensions();
	var page = $(document.body).getDimensions();
	var width, height;
	if(viewport.width < page.width) {
		width = page.width;
	} else {
		width = viewport.width;
	}
	if(viewport.height < page.height) {
		height = page.height;
	} else {
		height = viewport.height;
	}
	$(document.body).insert('<div id="popupMessage" class="popupMessage" style="position:fixed;width:600px;height:'+(viewport.height-200)+'px;margin-left:-300px;margin-top:100px;"><div style="float:right;"><a href="#" onclick="return closeLightBox();"><img src="images/icons/close.gif" border="0" alt="Close Window" /></a></div><h1>Ask the Rabbi Email Correspondance</h1><div style="height:'+(viewport.height-250)+'px;overflow:auto;">'+info+'</div></div>');
	$(document.body).insert('<div id="overlay" class="overlay" style="position:fixed;width:'+width+'px;height:'+(height+60)+'px"></div>');
	return false;
}
function toggleQuestion() {
	new Effect.toggle('originalQuestion','slide',{duration:.3});
	return false;
}
function emailAsker(id) {
	closeLightBox();
	new Ajax.Request('ajax_askrabbi.php?action=emailAsker&id='+id,{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			correspondanceBox(response);
		},
		onFailure:function() { alert('There was a problem communicating with the server. Please try again.'); }
	});
	return false;
}
function sendAskRabbiEmail(id) {
	var text = $F('text');
	new Ajax.Request('ajax_askrabbi.php?action=sendEmail&id='+id+'&text='+text,{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			closeLightBox();
			alert(response);
		},
		onFailure:function() { alert('There was a problem communicating with the server. Please try again.'); }
	});
	return false;
}
function viewCorrespondance(id) {
	closeLightBox();
	new Ajax.Request('ajax_askrabbi.php?action=correspondance&id='+id,{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			correspondanceBox(response);
		},
		onFailure:function() { alert('There was a problem communicating with the server. Please try again.'); }
	});
	return false;
}
function toggleSlide(id) {
	new Effect.toggle(id,'slide',{duration:.5});
	return false;
}
function markAsReadAskRabbi(el,id) {
	var el = $(el).identify();
	new Ajax.Request('ajax_askrabbi.php?action=markAsRead&id='+id);
	$(el).setStyle({fontWeight:'normal'});
	return false;
}
function addEmailClosureNotification() {
	var vars = $('closureNotificationForm').serialize();
	new Ajax.Request('closure_notifications.php?'+vars,{
		method:'get',
		onSuccess:function(transport) {
			var response = transport.responseText;
			alert(response);
			$('email').value = '';
		}
	});
	return false;
}
function askQuestion() {
	closeLightBox();
	new Ajax.Request('ajax_askrabbi.php?action=askQuestion',{
		method:'get',
		onSuccess:function(transport) {
			var r = transport.responseText;
			showLightBox('Ask the Rabbi',r);
		},
		onFailure:function() {
			alert('There was a problem communicating with the server. Please try again.');
		}
	});
	return false;
}
function searchQuestions() {
	closeLightBox();
	$('rabbisearch').focus();
	setTimeout("new Effect.Highlight('rabbisearch',{duration:1.5})",200);
	return false;
}
function continueAskQuestion() {
	new Ajax.Request('ajax_askrabbi.php?action=askQuestionForm',{
		method:'get',
		onSuccess:function(transport) {
			var r = transport.responseText;
			closeLightBox();
			showLightBox('Ask the Rabbi',r);
		},
		onFailure:function() {
			alert('There was a problem communicating with the server. Please try again.');
		}
	});
	return false;
}
function addOtherImage(i,el) {
	var el = $(el).identify();
	var newi = i;
	new Ajax.Request('ajax_products.php?action=addOtherImage&i='+i,{
		method:'get',
		onSuccess:function(transport) {
			var r = transport.responseText;
			$('otherImagesContainer').insert(r);
		},
		onFailure:function() {
			alert('There was a problem communicating with the server. Please try again.');
		}
	});
	newi++;
	$(el).onclick = function() { return addOtherImage(newi,el); }
	return false;
}
function removeOtherImage(i) {
	$('otherImage'+i).remove();
	return false;
}
function showDownloadPopup() {
	showLightBox('Download is Starting','Please do not close this page until the download is complete.');
}
function checkForInstantDownload(id) {
	showLightBox('Instant Download','<div>This product is also available as an instant download.  Would you like to add the instant download version to your cart instead?<br /><br /><input type="button" value="No, I would like the physical product." onclick="doNav(\'cart.php?action=add&id='+id+'\');" /><br /><br /><input type="button" value="Yes, I would like to download this product instantly." onclick="doNav(\'cart.php?action=add&id='+id+'&type=download\');" /></div>');
	return false;
}