
// =================================== AJAX FILE UPLOAD - for image upload  =============================================
	
function ajaxFileUpload()
	{
		
		var frmPersonID = $("#imgPerson").val();
		var frmTitle = $("#newImageTitle").val();
		var frmDate = $("#newDate").val();
		var frmDesc = $("#newDesc").val();
		
		$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		
		
		
		.ajaxComplete(function(){
						$("div#imageUpload").html("<div id='message' style='width:300px;margin:10px 0 0 100px; background-color:#ECECEC; border:1px solid #E4E4E4; padding:20px;'></div>");
						$('#message').html("<h2>The Image</h2>")
						.append("<p>was successfully uploaded</p>")
						.hide()
						.fadeIn(1500, function() {
						 // $('#message').append("<img id='checkmark' src='../images/icon_tick.gif' />");
						  $('#message').append("<a href='index.php?cID=28&func=edit&person=" + frmPersonID + "'>Insert another image</a>");
						});			
		});
		


		$.ajaxFileUpload
		(
			{
				url:'../includes/jQueryPassthru.php?func=insert&sn=imageUpload',
				secureuri:false,
				fileElementId:'userfile',
				dataType: 'json',
				data:{frmTitle:frmTitle, frmDesc:frmDesc, frmDate:frmDate, frmPersonID:frmPersonID},
				success: function (data, status)
				{
					
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							alert(data.error);
						}else
						{
							//alert(data.msg);
						}
					} 
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)
		
		return false;

	}

function finishAjax(id, response) {
	  $('#loader').hide();
	  $('#'+id).html(unescape(response));
	  $('#'+id).fadeIn();
}

function finishAjax2(id, response) {
	  $('#loadername').hide();
	  $('#'+id).html(unescape(response));
	  $('#'+id).fadeIn();
}


$(document).ready(function(){
	
// =================================== SUBMIT FORM TO UPDATE PERSONAL DETAILS  =============================================
	
		$('form.updPersDetails').submit(function(e) {
							e.preventDefault();
			
			var frmName = $("#frmName").val();
			var frmSurname = $("#frmSurname").val();
			
			dataString = $(this).serialize();
			sendData = encodeURI(dataString);
			
		
			$.ajax({
					type: "POST",
					url: "../includes/jQueryPassthru.php?func=update&sn=persDetails",
					//data: dataString,
					data: sendData,
					success: function() {
						
						$("div#updpersonalDetails").html("<div id='message'  style='width:300px;margin:10px 0 0 100px;'></div>");
						$('#message').html("<h2>" + frmName + " " + frmSurname + "</h2>")
						.append("<p>has been updated</p>")
						.hide()
						.fadeIn(1500, function() {
						  $('#message').append("<img id='checkmark' src='../images/icon_tick.gif' />");
						});
					}
			});
								
								return false;
		}); 


// =================================== SUBMIT FORM TO INSERT NEW PERSON  =============================================
	
		$('form.insPersDetails').submit(function(e) {
							e.preventDefault();
			
			var frmName 	= $("#frmName").val();
			var frmSurname 	= $("#frmSurname").val();
			var Name		= frmName + " " + frmSurname;
			
			dataString 		= $(this).serialize();
			sendData 		= encodeURI(dataString);
			
			//alert(sendData);
		
			$.ajax({
					type: "POST",
					url: "../includes/jQueryPassthru.php?func=insert&sn=persDetails",
					//data: dataString,
					data: sendData,
					success: function(result) {
						
						$("div#inspersonalDetails").html("<div id='message'  style='width:300px;margin:10px 0 0 100px;'></div>");
						$('#message').html("<h2>" + Name + "</h2>")
						.append("<p>has been updated</p>")
						.hide()
						.fadeIn(1500, function() {
						  $('#message').append("<u><li><a href='index.php?cID=28&func=edit&person=" + result + "'>Insert information for this person</a></li><li><a href='index.php?cID=28'>Insert another person</a></li>");
						});
					}
			});
								
								return false;
		}); 

// =================================== SUBMIT FORM TO UPDATE PARTNERSHIP  =============================================
		$('form.updPersMarriage').submit(function(e) {
							e.preventDefault();
			
			var currentId = $(this).attr('id');
			//var personName = $("form#1 input#testname").val();
			var messageclass = "message-" + currentId;
			var personName = $("#frmSpouse-" + currentId + " option:selected").text();
			
		//	 alert($(this).serialize());
		
			$.ajax({
					type: "POST",
					url: "../includes/jQueryPassthru.php?func=update&sn=marriageDetails",
					data: $(this).serialize(),
					success: function() {
			
						$("div#" + currentId).html("<div id='" + messageclass + "'  style='width:300px;margin:10px 0 0 100px;'></div>");
						$('#' + messageclass ).html("<h2>" + personName + "</h2>")
						.append("<p>has been updated</p>")
						.hide()
						.fadeIn(1500, function() {
						  $('#' + messageclass).append("<img id='checkmark' src='../images/icon_tick.gif' />");
						});
					}
			});
								
								return false;
		}); 
	
// =================================== SUBMIT FORM TO INSERT NEW PARTNERSHIP  =============================================
		$('form.insPersMarriage').submit(function(e) {
							e.preventDefault();
			
			var personName 	= $("#frmSpouse :selected").text();
			
			// alert($(this).serialize());
		
			$.ajax({
					type: "POST",
					url: "../includes/jQueryPassthru.php?func=insert&sn=marriageDetails",
					data: $(this).serialize(),
					success: function() {
			
						$("div#newPartner").html("<div id='message' style='width:300px;margin:10px 0 0 100px;'></div>");
						$('#message').html("<h2>" + personName + "</h2>")
						.append("<p>has been inserted as a new partner</p>")
						.hide()
						.fadeIn(1500, function() {
						  $('#message').append("<img id='checkmark' src='../images/icon_tick.gif' />");
						});
					}
			});
								
								return false;
		}); 	


// =================================== SUBMIT FORM TO INSERT NEW LINKS  =============================================
		$('form.newWebLinks').submit(function(e) {
							e.preventDefault();
			
			var newWebTitle = $("#newTitle").val();
			
		
			dataString = $(this).serialize();
			sendData = encodeURI(dataString);

			// alert(sendData);
		
			$.ajax({
					type: "POST",
					url: "../includes/jQueryPassthru.php?func=inset&sn=webDetails",
					data: sendData,
					success: function() {
			
						$("div#newWebDetails").html("<div id='message' style='width:300px;margin:10px 0 0 100px;'></div>");
						$('#message').html("<h2>" + newWebTitle + "</h2>")
						.append("<p>has been inserted</p>")
						.hide()
						.fadeIn(1500, function() {
						  $('#message').append("<img id='checkmark' src='../images/icon_tick.gif' />");
						});
					}
			});
								
								return false;
		}); 	
	
// =================================== SUBMIT FORM TO UPDATE EXISTING WEB DETAILS  =============================================
		$('form.updWebLinks').submit(function(e) {
							e.preventDefault();
			
			var currentId = $(this).attr('id');
			//var personName = $("form#1 input#testname").val();
			var messageclass = "message-" + currentId;
			var WebTitle = $("#frmTitle-" + currentId).val();
			// alert(currentId);
			
		
			dataString = $(this).serialize();
			sendData = encodeURI(dataString);
		
			$.ajax({
					type: "POST",
					url: "../includes/jQueryPassthru.php?func=update&sn=webDetails",
					data: sendData,
					success: function() {
			
						$("div#" + currentId).html("<div id='" + messageclass + "'  style='width:300px;margin:10px 0 0 100px;'></div>");
						$('#' + messageclass ).html("<h2>" + WebTitle + "</h2>")
						.append("<p>has been updated</p>")
						.hide()
						.fadeIn(1500, function() {
						  $('#' + messageclass).append("<img id='checkmark' src='../images/icon_tick.gif' />");
						});
					}
			});
								
								return false;
		}); 	

// =================================== SUBMIT FORM TO UPDATE EXISTING IMAGE DETAILS  =============================================
		$('form.updImageDetails').submit(function(e) {
							e.preventDefault();
			
			var currentId = $(this).attr('id');
			var messageclass = "message-" + currentId;
			var imageTitle = $("#frmTitle-" + currentId).val();
		
			dataString = $(this).serialize();
			sendData = encodeURI(dataString);
			// alert(sendData);
		
			$.ajax({
					type: "POST",
					url:  "../includes/jQueryPassthru.php?func=update&sn=imageDetails",
					data: sendData,
					success: function() {
			
						$("div#" + currentId).html("<div id='" + messageclass + "'  style='width:300px;margin:10px 0 0 100px;'></div>");
						$('#' + messageclass ).html("<h2>" + imageTitle + "</h2>")
						.append("<p>has been updated</p>")
						.hide()
						.fadeIn(1500, function() {
						  $('#' + messageclass).append("<img id='checkmark' src='../images/icon_tick.gif' />");
						});
					}
			});
								
				return false;
		}); 	

	

// ================================================ SUBMIT CONTACT FORM - PERSON CONTACT =====================================
		$('form.personContact').submit(function(e) {
							e.preventDefault();
			
			//var sendTo = $("#sendTo").val();
			
		
			dataString = $(this).serialize();
			sendData = encodeURI(dataString);

			// alert(sendData);
		
			$.ajax({
					type: "POST",
					url: "i_messageSend.php",
					data: sendData,
					success: function(result) {
						$("div#perscontact").html("<div id='message'>" + result + "</div>");
						$('#message').html("<h2></h2>")
						.append("<p></p>")
						.hide();
					}
			});
								
								return false;

		}); 
		
// ================================================ SUBMIT CONTACT FORM - SITE CONTACT =====================================
		$('form.siteContact').submit(function(e) {
							e.preventDefault();
			
			//var sendTo = $("#sendTo").val();
			
		
			dataString = $(this).serialize();
			sendData = encodeURI(dataString);

			// alert(sendData);
		
			$.ajax({
					type: "POST",
					url: "includes/i_messageSend.php",
					data: sendData,
					success: function(result) {
						$("div#sitecontact").html("<div id='message'>" + result + "</div>");
						$('#message').html("<h2></h2>")
						.append("<p></p>")
						.hide();
					}
			});
								
								return false;

		}); 			
// ================================================ GET PASSWORD RESET TOKEN =====================================
		$('form.obtainToken').submit(function(e) {
							e.preventDefault();
	
			dataString = $(this).serialize();
			sendData = encodeURI(dataString);

			// alert(sendData);
		
			$.ajax({
					type: "POST",
					url: "includes/jQueryPassthru.php?func=update&sn=resetToken",
					data: sendData,
					success: function(result) {
						$("div#resetToken").html("<div id='message'></div>");
						$('#message').html("<h2>A Reset Token</h2>")
						.append("<p>has been sent to the email address provided</p>")
						.hide()
						.fadeIn(1500, function() {
						  $('#message').append("<img id='checkmark' src='../images/icon_tick.gif' />");
						});

					}
			});
								
								return false;
		}); 	


// ============================================= LOGIN TO SITE ====================================================
		$('form#loginform').submit(function(e) {
							e.preventDefault();

			$.post('includes/jQueryPassthru.php?func=login', {curURL: $('[name=curURL]').val(), pwdPassword: $('[name=pwdPassword]').val(), pwdUser: $('[name=pwdUser]').val()},
			function(data) {
				if(data.success)
				{
					location.href=data.redirect;
				}
				else
				{
					$('#loginError').html(data.message);
				}
				
			},'json');
				return false;
		}); 	

// ======================================= CHECK USERNAME AVAILABILITY ============================================
	$("#username_box").blur(function() { // when focus out

		$("#messageAvail").html('<span>checking username...</span>'); //before AJAX response

		var form_data = {
			action: 'check_username',
			username: $(this).val()
		};

		$.ajax({
			type: "POST",
			url: "includes/user_availability.php",
			data: form_data,
			success: function(result) {
				$("#messageAvail").html(result);
			}
		});

	});
	
// ======================================= CHECK EMAIL AVAILABILITY ============================================
	$("#email").blur(function() { // when focus out

		$("#messageEmail").html('<span>checking email...</span>'); //before AJAX response

		var form_data = {
			action: 'check_email',
			email: $(this).val()
		};

		$.ajax({
			type: "POST",
			url: "includes/user_availability.php",
			data: form_data,
			success: function(result) {
				$("#messageEmail").html(result);
			}
		});

	});
	
// =========================================  FANCY BOX================================================
		$("#viewAncestry").fancybox({ // show person's ancestry chart
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe'
		});
		
		$("#viewDescendancy-129").fancybox({ // show chart for Cheong
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe'
		});		

		$("#viewDescendancy-770").fancybox({ // show chart for Cordeiro
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe'
		});	
		
		$("#viewDescendancy-870").fancybox({ // show chart for Hockenjos
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe'
		});	

		$("#viewDescendancy-912").fancybox({ // show chart for Hendriks
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe'
		});

		$("#viewDescendancy-949").fancybox({ // show chart for Corkhill
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe'
		});	

		$("#fredrickAncestry").fancybox({ // show image for Ludovico descendants
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
		
		$("#earlyAncestry").fancybox({ // show image for early ancestors
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'none'
		});	

		$("#relTable").fancybox({  // relationship table
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});	

		$("#dispersal").fancybox({ // show Google Earth map
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});	

		$("#contactPerson").fancybox({ // show contact form for contacting a user
			'width'				: '70%',
			'height'			: '70%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});	
		
		$("#contactAdmin").fancybox({ // show contact form for contacting admin person
			'width'				: '70%',
			'height'			: '70%',
			'autoScale'			: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});	

		$("a[rel=image_group]").fancybox({ // show family member images
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'autoScale'			: false,
			'changeFade'		: 'slow',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
		
		$("a[rel=article_group]").fancybox({ // show family member images
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'autoScale'			: false,
			'changeFade'		: 'slow',
			'titlePosition' 	: 'over',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Article ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});
		
		
		$("#photoAlbum1").fancybox({
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});

		$("#photoAlbum2").fancybox({
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
		
		$("#photoAlbum5").fancybox({
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});		
		
		$("#photoAlbum6").fancybox({
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
		
		$("#photoAlbum7").fancybox({
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});		
		
		$("#photoAlbum8").fancybox({
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});
		
		$("#photoAlbum10").fancybox({
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});		
		
		$("#photoAlbum11").fancybox({
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});	

		$("#photoAlbum12").fancybox({
			'width'				: '95%',
			'height'			: '95%',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
		});	


//==================== SHOW HIDE ITEMS INDEPENDENTLY ================================//
// choose text for the show/hide link - can contain HTML (e.g. an image)
		var showText='<img class="toggleImg" src="http://www.cordeiros.net/images/icon_expand.gif">';
		var hideText='<img class="toggleImg" src="http://www.cordeiros.net/images/icon_collapse.gif">';
		
		// initialise the visibility check
		var is_visible = false;
		
		// append show/hide links to the element directly preceding the element with a class of "toggle"
		$('.toggle').prev().append(' <a href="#" title="Edit Details" class="toggleLink">'+showText+'</a>');
		
		// hide all of the elements with a class of 'toggle'
		$('.toggle').hide();
		
		// capture clicks on the toggle links
		$('a.toggleLink').click(function() {
		
		// switch visibility
		is_visible = !is_visible;
		
		// change the link depending on whether the element is shown or hidden
		$(this).html( (!is_visible) ? showText : hideText);
		
		// toggle the display - uncomment the next line for a basic "accordion" style
		//$('.toggle').hide();$('a.toggleLink').html(showText);
		$(this).parent().next('.toggle').toggle('slow');
		
		// return false so any link destination is not followed
		return false;
		
		});


//================================= FAQs =======================================//
		
	$('.faqs dd').hide(); // Hide all DDs inside .faqs
	$('.faqs dt').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')}).click(function(){ // Add class "hover" on dt when hover
	$(this).next().slideToggle('normal'); // Toggle dd when the respective dt is clicked
	}); 


//================================ INLINE EDIT ==========================================//
	// update back end question
	$('.edit_email').editable('includes/jQueryPassthru.php?func=update&sn=personEmail', { 
		 onblur    : 'submit',
         tooltip   : '',
		 submitdata: {field: "email"}
     });
		
//========================= SHOW INFO TIPS  - TIPSY TOOLTIP =============================//

		$(".helpTip").tipTip({
				maxWidth: "200px", 
				defaultPosition:top,
				fadeIn:800,
				fadeOut: 1000,
				edgeOffset: 10
		});
		
		$(".Tip").tipTip({
				maxWidth: "200px", 
				defaultPosition:top,
				fadeIn:800,
				fadeOut: 1000,
				edgeOffset: 10
		});

//================================= TOGGLE BOX =======================================//

	$(".articlebox").hide(); 
		//slide up and down when hover over heading
		$("div#showArticle").click(function(){
		// slide toggle effect set to slow you can set it to fast too.
		$(this).next(".articlebox").slideToggle("slow");
		return true;
	});

 //============================ SLIDE DOWN/UP LOGIN PANEL ===============================//
	$("#open").click(function(){
		$("div#panel").slideDown("slow");
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});		

// ************************************* DOM TRIGGER FOR WEB LINKS DELETE (FLAG UPDATE)  **************************
	$(".delbuttonA").click(function(){

	var del_id =  $(this).attr('id');
	
	//alert(del_id);

	var info = 'id=' + del_id;
	 if(confirm("Are you sure you wish to remove this web link?"))
			  {
	 $.ajax({
	   type: "GET",
	   url: "../includes/jQueryPassthru.php?func=del&sn=webDetails",
	   data: info,
	   success: function(){
		   
	   }
	 });
				 $(this).parents(".recordA").animate({ backgroundColor: "#fbc7c7" }, "fast")
				.animate({ opacity: "hide" }, "slow");
				
				
	 }
	return false;
	});		
	
// ************************************* DOM TRIGGER FOR MARRIAGE DELETE (FLAG UPDATE)  **************************
	$(".delbuttonB").click(function(){

	var del_id =  $(this).attr('id');
	
	//alert(del_id);

	var info = 'id=' + del_id;
	 if(confirm("Are you sure you wish to remove this partner?"))
			  {
	 $.ajax({
	   type: "GET",
	   url: "../includes/jQueryPassthru.php?func=delMarriage",
	   data: info,
	   success: function(){
		   
	   }
	 });
				 $(this).parents(".recordB").animate({ backgroundColor: "#fbc7c7" }, "fast")
				.animate({ opacity: "hide" }, "slow");
				
				
	 }
	return false;
	});		

// ************************************* DOM TRIGGER FOR IMAGE DELETE (FLAG UPDATE)  **************************
	$(".delbuttonC").click(function(){

	var del_id =  $(this).attr('id');
	
	//alert(del_id);

	var info = 'id=' + del_id;
	 if(confirm("Are you sure you wish to remove this image?"))
			  {
	 $.ajax({
	   type: "GET",
	   url: "../includes/jQueryPassthru.php?func=del&sn=imageDetails",
	   data: info,
	   success: function(){
		   
	   }
	 });
				 $(this).parents(".recordC").animate({ backgroundColor: "#fbc7c7" }, "fast")
				.animate({ opacity: "hide" }, "slow");
				
	 }
	return false;
	});		


// ============================  CHAINED SELECT FOR FAMILY MEMBERS =============================

	$('#loader').hide();
	$('#firstNameSelect').change(function(){
	  $('#loader').show();
	  $('#lastNameSelect').hide();
      $.get("includes/i_chainSelect.php", {
		func: "firstNameSelect",
		drop_var: $('#firstNameSelect').val()
      }, function(response){
        $('#lastNameSelect').fadeOut();
        setTimeout("finishAjax('lastNameSelect', '"+escape(response)+"')", 400);
      });
    	return false;
	});


// ============================  CHAINED SELECT FOR FAMILY MEMBERS IN MYACCOUNT =============================

	$('#loadername').hide();
	$('#FNameSelect').change(function(){
	  $('#loadername').show();
	  $('#LNameSelect').hide();
      $.get("includes/i_chainSelect.php", {
		func: "firstNameSelect",
		drop_var: $('#FNameSelect').val()
      }, function(response){
        $('#lastNameSelect').fadeOut();
        setTimeout("finishAjax2('LNameSelect', '"+escape(response)+"')", 400);
      });
    	return false;
	});


// =================================  VALIDATE REGISTRATION FORM ==============================

		jQuery("#registrationForm").validationEngine({
                  onValidationComplete: function(form, status){
					  if (status == true) {
		
					//dataString = $(this).serialize();
					
					var firstname	= $("#firstname").val();
					var username	= $("#username_box").val();
					var password	= $("#password").val();
					var email		= $("#email").val();

					var sendData = 'firstname=' + firstname + '&username=' + username + '&password=' + password + '&email=' + email;
					// alert(sendData);
				
					$.ajax({
							type: "POST",
							url: "includes/jQueryPassthru.php?func=insert&sn=newRegistration",
							data: sendData,
							success: function(result) {
								$("div#register").html("<div id='message'>" + result + "</div>");
								$('#message').html("<h2>Registration</h2>").append("<p>" + result + "</p>").hide()
								.fadeIn(1500, function() {
								$('#message').append("");
								});
		
							}
					});
					return false;
				}
			}
		});

		
		
		
		jQuery("#persDetails").validationEngine();
		
		jQuery("#insPersImage").validationEngine();

		jQuery("#newWebLinks").validationEngine();

		jQuery("#insPersMarriage").validationEngine();
		
		//jQuery("#resetPwd").validationEngine();
		
		jQuery("#resetPwd").validationEngine({
                  onValidationComplete: function(form, status){
					  if (status == true) {
                   // alert("The form status is: " +status+", it will never submit");
				   
				           var password1 	= $("#pwdPassword1").val();
						   var resToken		= $("#resToken").val();

			
							var sendData = 'password1=' + password1 + '&resToken=' + resToken;
							
							//alert (sendData);
							
							$.ajax({
									type: "POST",
									url:  "includes/jQueryPassthru.php?func=update&sn=resetPwd",
									data:  sendData,
									success: function(result) {
							
										$("div#resetPwdDetails").html("<div id='message' style='width:300px;margin:10px 0 0 100px;'></div>");
										$('#message').html("<h2>Your Password</h2>")
										.append("<p>" + result + "</p>")
										.hide()
										.fadeIn(1500, function() {
										  $('#message').append("");
										});
									
									}
							});	
							
							return false;				
					
					  }
                  }
                }); 


// =======================================  VALIDATE PASSWORDS ==========================================
       jQuery("form#changePwd").validationEngine({
                  onValidationComplete: function(form, status){
					  if (status == true) {
				
					var passwordVal = $("#password1").val();
			
					var sendData = 'password1=' + passwordVal;
					
					$.ajax({
							type: "POST",
							url:  "includes/jQueryPassthru.php?func=update&sn=pwd",
							data:  sendData,
							success: function() {
					
								$("div#updPwdDetails").html("<div id='message' style='width:300px;margin:10px 0 0 100px;'></div>");
								$('#message').html("<h2>Password</h2>")
								.append("<p>has been changed</p>")
								.hide()
								.fadeIn(1500, function() {
								  $('#message').append("<img id='checkmark' src='../images/icon_tick.gif' />");
								});
							}
					});
				}
			} 
		
    });
	
//================== TOGGLE CONTAINER - USED TO REVEAL NAMES UNDER SURNAME =============================//

$(".toggle_container").hide(); 

//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
$("div.trigger").click(function(){
	$(this).toggleClass("active").next().slideToggle("slow");
	return false; //Prevent the browser jump to the link anchor
});
	
	
// =================================  TRIGGER TO CHECK PASSWORD STRENGTH ==============================
		$('input[name="changePwd1"]').passwordStrength();
		
		$('input[name="pwdPassword1"]').passwordStrength();


// =================================== END DOM CALLS =====================================//
						   
 });
