// JavaScript Document
//google.setOnLoadCallback(function(){
    $(function(){
		$('.tellFriendClientside').attr('href', '/rpc/tellaFriend.aspx')
		    
		// ---- UI Events ----														
		$(".tellFriendClientside").click(
			function(objEvent) {
				objEvent.preventDefault();	
				$('#ModalTellFriend').modal({onOpen: modalOpen, onClose: modalClose, width: 500});
				
			}
		); //End Click



		$("#formSubmit").click(
			function(objEvent) {
				
				// ---- Ajax Event listeners ----
				$("#loading2").ajaxStart(function(){$("#loading2").html('<img src="/img/ajax-loader.gif" />')});
				$("#loading2").ajaxStop(function(){$("#loading2").html('')});				
				$("#loading2").ajaxComplete(function(){$("#loading2").html('')});	
		
				objEvent.preventDefault();	
				var senderName = $('#senderName').val();
				var recipientEmail = $('#recipientEmail').val();
				var comment = $('#comment').val();
				var productName = $('#productName').val();
				var productUrl = $('#productUrl').val();
				
				$.ajax(
					{
						url: "/rpc/tellaFriend.aspx",
						type: "post",
						datatype: "text",
						data:{'ProductID': iProdID, 'senderName': senderName, 'recipientEmail': recipientEmail, 'comment': comment, 'productName': productName, 'productUrl': productUrl},												
						success: function(sResponse)
						{	
							if(sResponse == 'success')
							{
								$("#formSubmit").hide();
								$('.msg').html('<div class="note">Your email has been sent</div>')
							} else if(sResponse == 'invalid') {
								$('.msg').html('<div class="error">The email you supplied was invalid. Please try again</div>')	
							} else if(sResponse == 'error') {
								$('.msg').html('<div class="error">There was an error sending your email. Please try again later</div>')
							} else if(sResponse == 'missingValues') {
								$('.msg').html('<div class="error">Please fill in all fields</div>')
							}
						},
						complete: function() {}
					}				
				); //End ajax	
				$('#ModalTellFriend').modal({onOpen: modalOpen, onClose: modalClose, width: 500});
			}
		); //End Click
		
		function modalOpen(dialog) {
			dialog.overlay.fadeIn('slow', function () {
				dialog.container.slideDown('slow', function () {
					dialog.data.show().fadeIn('slow', function(){
					});	 
				});
			});
		}
		function modalClose(dialog) { 
			dialog.data.fadeOut('slow', function() {
				dialog.container.fadeOut('slow', function () {
					dialog.overlay.fadeOut('slow', function () {
						$.modal.close();
					});
				});						
			});
		}	
		function displayDebugLine(sDebugLine) {
			$("#debug").append(sDebugLine + "<br />")
		}
    }); // End Document Load
//}); // End Google JQuery API Load

