/*
 NOTE:
 
 the functions and codes below require further development - making them into plugins, etc

*/


/*
|---------------------------------------------------------------
| MEMBER PROFILE FUNCTIONS
|---------------------------------------------------------------
|
*/

this.reset_element_image_profile = function(load){
	
	$('.image-profile img').each(function(){
		
		/* set the variable and store the value */
		var $this = $(this);
		
		/* the img element is 0x0 wide until the image is loaded. you should wait until the image is entirely loaded. 
		to ensure images are loaded, use the image's load event or the window load event. jQuery ready happens a lot earlier than that.
		
		So this should work:
		
		$(window).bind('load', function() {
			var img = $("#theimage");
			log("Width: " + img.width());
			log("Height: " + img.height());
		});
		
		or
		
		$(document).ready(function() {
			$("#theimage").bind('load', function() { // BUT SEE NOTE BELOW
				var img = $(this);
				log("Width: " + img.width());
				log("Height: " + img.height());
			});
		});
		
		*/
		
		/* must use $(window) otherwise it only works in chrome but not firefox, etc */
		$(window).bind('load', function() {
		//$this.bind('load', function() { 
				
			/* now grab the height of the image after the image is loaded */
			var $this_parentheight = $this.parent().parent().height();
			var $this_height = $this.height();
			//alert($this_height);
			
			/* change the margin top */
			$this.parent().css({
				marginTop: ($this_parentheight-$this_height)/2 + 'px'
			});
		});

	});
}

this.toggle_see_more_profile = function(){

	$('.button-more-profile').click(function(){
		
		/* set the variable and store the value */
		var $this = $(this);
		var $this_text = $this.text();
		var $this_parent = $this.parents('.info-profile');
		//alert($(this).text());
		
		/* toggle the target */
		$(".more-profile",$this_parent).slideToggle("slow", function(){
			
			/* change the text in the button */
			if( $this_text == 'See More')
				$this.text('See Less');
			else $this.text('See More');
			
		});
		
		return false;
		
	});
}

this.get_button_change_picture_profile = function(){

	/* The short version is just to toggle here: */
	//$('.image-profile').live('hover',function(){
	$('.image-profile').hover(function () {
		$('.button-change-picture-profile',this).toggle();
	});
	
	/* To have it available in each handler (as a more general solution) define it outside when looping (using .each() for example), like this: 
	
	$('.image-profile').each(function() {
		var target = $('.button-change-picture-profile',this);
		$(this).hover(function () {
			target.show();
			
		},function () {
			target.hide();
			alert('1');
		});
	});
	*/
}

this.get_menu_profile_picture = function(){

	/* bind the click event to the .button-change-picture-profile */
	$('.button-change-picture-profile').click(function(){
	
		/* set the variable */
		var $this = $(this).hide();
		var target_menu = $('.menu-profile-picture').show();
		var target_profile = $('.image-profile').unbind('mouseenter mouseleave');
		//var target_profile = $('.image-profile').die("hover")
		//target_profile.unbind('mouseenter mouseleave'); $("#theone").die("click", aClick)
		
		/* when the .button-close is clicked */
		$('.button-close').click(function(){
			
			/* hide the menu, show the button of .button-change-picture-profile again */
			target_menu.hide();
			$this.show();

			/* bind the event of mouseleave and mouseenter to the profile picture when the mouse leaves the profile picture immediately */
			target_profile.mouseleave(function(){
				$this.hide();
				target_profile.mouseenter(function(){
					$this.show();
				});
			});
			
			return false;
			
		});
		
		return false;
		
	});
}

this.load_edit_profile_infomation = function(){
	
	$('.edit-profile').click(function(){
		
		/* set the variable and store the value */
		var $this = $(this);
		var $this_path = $this.attr('rel');

		var target = $('.item-member');
		var target_menu = $('.menu-profile-picture').hide();
		var target_html = target.html();

		//alert(target_html);
		//alert('1');
		
		/* display the loading */
		target.html('<img src="'+http_root+rp_global_image+img_loader+'" style="float:none; border:0px solid #000; margin:0px;"/> loading');
		
		target.load($this_path, function(){
			
			target.hide().slideDown('fast');
			replace_element_input_password();
			tooltip_form();
			
			$('form *[title]',$(this)).inputHint();
			
			/* when you click the cancel button if there is any cancel button */
			$("input[type=button][name=cancel]").click(function(){

				$('html, body').animate({scrollTop:0}, 'slow', function(){
					
					$('.tooltip').remove();
					target.html(target_html).hide().slideDown('fast');
					
					toggle_see_more_profile();
					
					load_edit_profile_picture();
					load_edit_profile_infomation();
					
					get_button_change_picture_profile();
					get_menu_profile_picture();

				});

			});
		});
		
		
		return false;
		
	});
	
}


this.load_edit_profile_picture = function(){
	
	$('.edit-profile-picture').click(function(){
		
		var timer;
		
		/* remove #popup-edit-profile-picture first if any of it exisits */
		$(".popup-outer").remove();
		$(".blackout-public").remove();
		//$(".close").remove();
		
		/* then append a fresh #popup-edit-profile-picture */
		$(document.body).prepend("<div id='popup-edit-profile-picture' class='popup-outer'><div class='popup-inner'><div class='close'><a href='#' class='close'>x close</a></div><div id='wrapper-form-upload-image-profile'></div></div></div>");
		
		/* set the variable and store the value */
		var $this = $(this);
		var $this_parent = $this.parent();
		var $this_path = $this.attr("rel");
		var $this_name = $this.attr("name");
		var $this_loading = $('.loading-reset', $this_parent);
		var target = $('#popup-edit-profile-picture').width(400).hide();
		//alert($this_path);
		
		if($this_loading.length > 0)
		{

			/* set the css for $this_loading */
			$this_loading.css({
				margin:"5px 0px 0px 0px",
				visibility:"visible"
			});
				
			/* add text to the $this_loading div and animate it */
			$this_loading.html('loading');
			$this_loading.fadeIn('fast', function(){
				timer = setInterval('animate_processing()',500);
			});
		
		}
		else
		{
			make_blackout();
		}

		/* load the form into the the form area then fade the entire wrapper in */
		$('#wrapper-form-upload-image-profile',target).load($this_path, {}, function(){

			clearInterval(timer);
			//var str = $this.serialize();
			//alert(str);
			
			if($this_loading.length > 0)
			{
				/* hide the loading */
				$this_loading.css({
					visibility:"hidden"
				});
			}
			else
			{
				global_blackout.fadeOut('slow');
				global_loading.remove();
			}
			
			/* get the pop up */
			set_center(target);
			//alert(target.height());
			
			/* fade in the pop up */
			target.fadeIn('fast', function(){
			
				$('form *[title]').inputHint();
				target.fadeIn('slow');
				closePopup(target);
				
				if($this_name == 'upload') get_ajax_upload();
				if($this_name == 'delete') post_image_delete();
				
			});
		
		});
		return false;
	});
}

this.get_ajax_upload = function(){
	
	var upload_button = $('.ajax-upload');
	var upload_path = upload_button.parent().attr("action");
	var upload_category =  upload_button.attr("name");
	var upload_status = $('.status-upload');
	//alert(path)
	
		new AjaxUpload(upload_button, {
			action: upload_path,
			name: upload_category,
			onSubmit: function(file, ext){
				if(upload_category == 'image')
				{
					if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
						
						// extension is not allowed 
						upload_status.text('Only JPG, PNG or GIF files are allowed');
						return false;
						
					}
					else
					{
						/* disable the button so that you won't click it twice while the ajax is processing the form */	
						$('input[type=button]', upload_button.parent()).attr('disabled', 'disabled').css({opacity:0.4});
						//$('.close', upload_button.parents('.popup-outer')).unbind('click');
					}
				}
				else if(upload_category == 'document')
				{
					if (! (ext && /^(doc|pdf|zip)$/.test(ext))){
						
						// extension is not allowed 
						upload_status.text('Only DOC, PDF or ZIP files are allowed');
						return false;
						
					}
					else
					{
						/* disable the button so that you won't click it twice while the ajax is processing the form */	
						$('input[type=button]', upload_button.parent()).attr('disabled', 'disabled').css({opacity:0.4});
					}
				}
				else if(upload_category == 'video')
				{
					if (! (ext && /^(avi|mov|swf)$/.test(ext))){
						
						// extension is not allowed 
						upload_status.text('Only AVI, MOV or SWF files are allowed');
						return false;
						
					}
					else
					{
						/* disable the button so that you won't click it twice while the ajax is processing the form */	
						$('input[type=button]', upload_button.parent()).attr('disabled', 'disabled').css({opacity:0.4});
					}
				}
				upload_status.html('<img src="'+http_root+rp_global_image+img_loader+'"/> processing');
				
			},
			onComplete: function(file, response){
				
				//On completion clear the status
				upload_status.text('');
				
				//Add uploaded file to list
				if(response){
				
					$("error", response).each(function(){
						var message = $(this).attr('message');
						alert(message);
						
						/* disable the button so that you won't click it twice while the ajax is processing the form */	
						$('input[type=button]', upload_button.parent()).attr('disabled', '').css({opacity:1.0});
					});
					
					$("result", response).each(function(){
						
						var itemid = $(this).attr('itemid');
						var itemcat = $(this).attr('itemcat');
						var itemtitle = $(this).attr('itemtitle');
						var itempath = $(this).attr('itempath');
						var message = $(this).attr('message');
						
						//alert(message);
						
						/* then append a fresh #popup-edit-profile-picture */
						$(document.body).prepend("<div id='popup-upload-result' class='popup-outer'><div class='popup-inner'><div class='close'><a href='#' class='close'>x close</a></div><div id='wrapper-result'>"+message+"</div></div></div>");
						
						var target_result = $('#popup-upload-result').width(400).hide();
						var target_form = $("#popup-edit-profile-picture");
						
						set_center(target_result);

						target_form.fadeOut(function(){
							$(this).remove();
							target_result.fadeIn();
						});
						
						
					});

				}
			}
	});
}

this.post_image_delete = function(){
	
	$(".form-public").submit(function(){
		
		/* set the variable */
		var $this = $(this);
		var $this_path = $this.attr('action');
		//alert($this.serialize());
		
		/* disable the button so that you won't click it twice */	
		$('input[type=button],input[type=submit]', $this).attr('disabled', 'disabled').css({opacity:0.4});
		
		/* post the form */
		$.post($this_path, $this.serialize(), function(xml){
			
			if($(xml).find("result").length > 0)
			{
				var message = $("result", xml).attr('message');
				var path_image = $("result", xml).attr('pathimage');
				//alert(path_image);
				
				/* then append a fresh popup */
				$(document.body).prepend("<div id='popup-delete-result' class='popup-outer'><div class='popup-inner'><div class='close'><a href='#' class='close'>x close</a></div><div id='wrapper-result'>"+message+"</div></div></div>");
				
				var target_result = $('#popup-delete-result').width(400).hide();
				var target_form = $("#popup-edit-profile-picture");
				
				set_center(target_result);

				target_form.fadeOut(function(){
					
					$(this).remove();
					
					target_result.fadeIn(function(){
					
						/* remove the button of Delete this picture which has a delete in its name attribute */
						$('.menu-profile-picture-right a[name="delete"]').remove();
						
						/* remove profile picture on the screen and replace it with the path sent from the xml result */
						$('.image-profile img').fadeOut(function(){
							
							/* set the variable */
							var $this = $(this);
							$this.attr("src", path_image).fadeIn(function(){

								/* now grab the height of the image after the image is loaded */
								var $this_parentheight = $this.parent().parent().height();
								var $this_height = $this.height();
								//alert($this_height);
								
								/* change the margin top */
								$this.parent().css({
									marginTop: ($this_parentheight-$this_height)/2 + 'px'
								});
							})
						});
					
					});
				});
				
			}
			
		});
				
		return false;
	});
}

/*
|---------------------------------------------------------------
| HANDY FUNCTIONS
|---------------------------------------------------------------
|
*/

/**************************************

 --- function set_center() ---
 
 to set a popup to the center of 
 the page verticaly and horizontally
 
**************************************/

this.set_center = function(target){
	
	/* set the pop up variable */
	var width = target.width();
	var height = target.height();
	var windowHeight = $(window).height();
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var scrollHeight = $("body").attr("scrollHeight");
	
	/* do the calculation */
	var scrollBottom = scrollTop + windowHeight;
	var top = (windowHeight/2)-(height/2) - 5;
	var marginLeft = "-"+((scrollLeft + width)/2);
	
	$(".popup").each(function(){
		//alert($(this).css("zIndex"));
		var myindex = $(this).css("zIndex");
	});
	
	var index_poppup = parseInt($(".popup").css("zIndex"));
	//alert(index_poppup);
	
	if(index_poppup > 0) index_poppup = index_poppup + 1;
	else index_poppup = 21;
	
	target.css({
		top:(scrollTop + top) + "px", 
		left:"50%",
		marginLeft:marginLeft + "px",
		width:width + "px",
		zIndex:index_poppup,
		display:"none"
	});
	
	target.fadeIn('slow', function(){
		closePopup_public(target);
		//make_boxshadow_ie(target);
	});
	
}

/**************************************

 --- function make_blackout() ---
 
 to get/ create a black out element 
 over the page
 
**************************************/

this.make_blackout = function(){

	$(document.body).append("<div class='blackout-public'></div>");
	$(document.body).prepend("<div class='loading'>loading</div>");

	/* set global blacout and global loading */
	global_blackout = $('.blackout-public');
	global_loading = $('.loading');

	/* set the variable and get the value for .loading */
	var width_loading = global_loading.width();
	var height_loading = global_loading.height();
	var windowHeight = $(window).height();
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var scrollHeight = $("body").attr("scrollHeight");

	/* do the calculation for .loading */
	var scrollBottom = scrollTop + windowHeight;
	var top_loading = (windowHeight/2)-(height_loading/2);
	var marginLeft_loading = "-"+((scrollLeft + width_loading)/2);

	/* set the variable and get the value for the blackout */
	var height_document = $(document).height();

	/* set the css for blackout */
	global_blackout.css({
		height:height_document,
		zIndex:'100',
		opacity: 0.3,
		display:'none'
	});
			
	/* set the css for .loading */
	global_loading.css({
		top: scrollTop + top_loading + "px",
		width: width_loading + "px",
		height: height_loading + "px",
		marginLeft:marginLeft_loading + "px",
		color:"#ffffff",			
		zIndex:"101",
		display: 'none'
	});

	/* fade in the blackout */
	global_blackout.fadeIn('fast', function(){
		//setInterval('animate_processing()',500);
	});

	/* fade in the loading and animate it */
	global_loading.fadeIn('fast', function(){
		timer = setInterval('animate_processing()',500);
	});

}

/**************************************

 --- function make_boxshadow_ie() ---
 
 to make/ create a box shadow element 
 for ie below version 9
 
**************************************/

this.make_boxshadow_ie = function(target){
	
	/**
	check if it is IE first
	**/
	if ($.browser.msie && parseInt($.browser.version) < 9) 
	{
		/**
		check which version it is.
		Often you only care about the "major number," the whole number. 
		This can be accomplished with JavaScript's built-in parseInt() function.	
		**/
		if ($.browser.msie && parseInt($.browser.version) < 9) {
			//alert($.browser.version);
			//alert(parseInt($.browser.version));
		}
		
		var width = target.width();
		var height = target.height();
		var windowHeight = $(window).height();
		var scrollTop = $(window).scrollTop();
		var scrollLeft = $(window).scrollLeft();
		var scrollHeight = $("body").attr("scrollHeight");
		//alert(height);

		/* do the calculation */
		var scrollBottom = scrollTop + windowHeight;
		var top = (windowHeight/2)-(height/2) - 30;
		var marginLeft_shadow = ((scrollLeft + width)/2);
		var marginTop_shadow = ((scrollLeft + height)/2);
		
		top_shadow = top + scrollTop;
		marginLeft_shadow = "-"+(marginLeft_shadow + 10);
		marginTop_shadow = "-"+(marginTop_shadow + 35);

		/**
		create a div for ie-shadow
		place the #pop-out after the .ie-shadow
		set the css of .ie-shadow
		**/
		target.after("<div class='"+ieShadowClass+"'></div>");
		$("."+ieShadowClass+"").width(target.width()+40).height(target.height()+40).css({
			top:top_shadow + "px",	
			marginLeft:marginLeft_shadow + "px",
			//marginTop:marginTop_shadow + "px",					
			zIndex:ieShadowzIndex
		});
	}
}

/**************************************

 --- function clear_form() ---
 
 to clear all the form element
 
**************************************/

this.clear_form = function(target){ //  ==  function clear_form_elements(target) {
    $(target).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
		$('form *[title]').inputHint();
    });
}


/*
|---------------------------------------------------------------
| GENERAL FUNCTIONS
|---------------------------------------------------------------
|
| apply to the comment in a blog or a forum
|
*/

this.closePopup_public = function(target){

	$(".close",target).click(function(){
		
		if($(this).hasClass('ie-box-shadow'))
		{
			alert('ie-drop-shadow');
			/**
			if it is IE and older than version 9, run this code
			**/
			if ($.browser.msie && parseInt($.browser.version) < 9) 
			{	
				$('.ie-shadow-1').remove();
				$('.ie-shadow-2').remove();
			}
		
		}
		
		if ($.browser.msie && parseInt($.browser.version) < 9) 
		{	
			$('.ie-shadow-1').remove();
			$('.ie-shadow-2').remove();
			//$('.ie-shadow-3').remove();
		}
		
		target.fadeOut('fast', function(){
			target.remove();
		});
		
		/**
		enable the submit button again after processing the xml output
		**/	
		$('input[type=submit]').attr('disabled', '').css({opacity:1});
		
	return false;
	
	});
	
}

/*****************/

this.scrollToBottom = function(){
	
	$('.scroll-to-bottom').click(function(){
        $('html, body').animate({scrollTop:$('html, body').height()}, 'slow', function(){
		   /**
		   cannot put the jquery highlight here or it will highlight the element twice
		   **/
		});
		
		/** 
		highlight the form
		**/
		$('#form-comment').effect("highlight",{color:"#ffff99"}, 3000);
		
        return false;
    });
}

/*****************/

this.scroll_to_top = function(){
	$('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });
}

/*****************/

this.scrollbar = function(){	
$('#pane1').jScrollPane();
$('.scrollbar').bind('scroll',function(event){
	console.log(event.target);
	});
};


this.scrollbarImg_option = function(){
$('#content-shop').jScrollPane({
	showArrows:false, 
	scrollbarWidth: 10,
	reinitialiseOnImageLoad: true
	});
}

/**************************************/
/*** Blog and Q&A  Shared Functions ***/
/**************************************/

this.loadRegister = function(){	
$(".register").click(function(){

	/**
	remove the popup-member-register
	**/
	$("#popup-member-register").remove();
	
	
	/**
	append a div of popup-mmember
	**/
	$(document.body).append("<div id=\"popup-member-register\" class=\"popup-outer-public\"></div>");
	
	
	/**
	set variables and get or calculate the data of variable
	**/
	var width = 380;
	var top = 220;
	
	var path = $(this).attr("href");
	var target = $('#popup-member-register');
	
	var scrollTop = $(window).scrollTop();
	var scrollLeft = $(window).scrollLeft();
	var marginLeft = "-"+ ((scrollLeft + width  + 75)/2);
	
	/**
	set the css for the popup
	**/
	target.css({
		top:(scrollTop + top) + "px", 
		left:"50%",
		marginLeft:marginLeft + "px",
		width: width + "px",
		color:"#333333", 
		zIndex:"20"
	});
	
	target.html('<div class="ajaxloader"><img src="'+http_root+rp_global_image+img_loader+'"/> loading</div>');
	
	$('.ajaxloader').css({
		padding:"20px",
		background:'#ffffff',
		textAlign:"center"
	});
			
	target.fadeIn('fast', function(){		
		
		target.load( path, {}, function(){
			target.hide();
			target.fadeIn('slow');
			closePopup_public(target);
			postRegister();
			});	
		})
		
	return false;
	});
}

/**************************************/

this.postRegister = function(){

	var target = $("#form-member-register").find('form');
	
	target.submit(function(){
	
		$('#popup-result-member').remove();
		
		var path = $(this).attr('action');
		var processing = $('.processing',target);
		
		processing.css({
			margin:"5px 0px 0px 10px",
			position:"absolute",
			visibility:"visible"
		});
			
		processing.html('<div><p><img src="'+http_root+rp_global_image+img_loader+'"/> processing</p></div>');
	
		$.post(path, target.serialize(),function(xml){
			
			$("label").removeClass('error');
			$("form img").css({visibility:'hidden'});
			
			processing.css({
				visibility:"hidden"
			});
			
			processRegister(xml);
		});
		
		/**
		disable the submit button so that you won't click it twice while the ajax is processing the form
		**/	
		$('input[type=submit]',target).attr('disabled', 'disabled').css({opacity:0.4});
			
		return false;
		
	});
}

this.processRegister = function(xml){ //  ==  function addMessages(xml) { 	
	
	/**
	append a poppup for displaying the result
	**/
	$(document.body).append("<div id='popup-result-member' class='popup-outer-public'><div class='popup-inner-public'><div class='close'><a href='#' class='close'>x close</a></div><div class='result'></div><div class='form-confirm'></div></div></div>");
	
	var target_form = $("#form-member-register").find('form');
	var target_result = $('#popup-result-member');
	
	$("error", xml).each(function(){
		
		/**
		set the local variable
		**/
		var elementid = $(this).attr('elementid');
		var message = $(this).attr('message');
		
		/**
		add an error class to each error element
		**/
		$("#"+elementid+"_label").addClass('error');
		$("#"+elementid+"_img").css({visibility:'visible'});
		
		/**
		append the message to the .result class
		**/
		$(".result").append("<img src='"+http_root+rp_global_image+"attention.png' /> <b>" + message + "</b> <br />");		
	});	
	
	$("confirm", xml).each(function(){
		
		/**
		set the local variable
		**/
		var message = $(this).attr('message');
		path = $(this).attr('path');
		//alert(message);
		
		/**
		append the message to the .result class
		**/
		$(".result").append("<img src='"+http_root+rp_global_image+"attention.png' />  <b>" + message + "</b>");
	});
		
	$("result", xml).each(function(){
		var message = $(this).attr('message');
		//alert(message);
		
		/**
		append the message to the .result class
		**/
		$(".result").append("<img src='"+http_root+rp_global_image+"info.png' /> <b>" + message + "</b> <br />");	
	});
		
		
	if($(xml).find("error").length > 0)
	{

		//alert('error'); 
		showFormResult_public(target_result,250);
		
		/**
		enable the submit button again after processing the xml output
		**/	
		$('input[type=submit]',target_form).attr('disabled', '').css({opacity:1});
	}
	
	else if($(xml).find("confirm").length > 0)
	{
		//alert('confirm');
		
		/**
		load the confirmation form and attach the postForm_confirm() function
		**/
		$(".form-confirm",target_result).load(http_root+rp_local_layout+"form_confirm.php?path_return="+path, {}, function(){
	
			//alert(target.height());
			showFormResult_public(target_result,210);
			
			/**
			target_form is the <form>
			target_result is the <div> popup
			**/
			postForm_confirmRegister(target_form,target_result);
			
		});	
	}
	else
	{	
		//alert('result');
		
		showFormResult_public(target_result,250);
		$('#popup-member-register').fadeOut();
		
		/**
		enable the submit button again after processing the xml output
		**/	
		$('input[type=submit]',target_form).attr('disabled', '').css({opacity:1});
	}
}

this.postForm_confirmRegister = function(target_form,target_result){
	
	//var target_respond = $(".respond-contact");
	//var target_form = $("#form-contact");
	
	$("input[name=yes]",target_result).click(function(){
	
		target_result.find('form').submit(function(){
			var path_return = $(this).attr('action');
			var processing = $('#form-confirm .processing',target_result);
			//alert(path_return);
			
			/**
			set the css for processing
			**/
			processing.css({
				margin:"5px 0px 0px 10px",
				border: '0px solid #0066FF'
			});
			
			/**
			add text to the processing div and animate it
			**/
			processing.html('<div><img src="'+http_root+rp_global_image+img_loader+'"/> processing</div>');
			
			$.post(path_return, target_form.serialize(),function(xml){
				//var str = target_form.serialize();
				//alert(str);
				
				target_result.remove();
				//processForm_public(xml);
				processRegister(xml);
				clear_form(target_form);
			});
			
			/**
			disable the submit button so that you won't click it twice while the ajax is processing the form
			**/	
			$('input[type=submit]',target_result).attr('disabled', 'disabled').css({opacity:0.4});
			
			return false;
		});
	});	
	
	$("input[name=no]",target_result).click(function(){
		
		$("#form-confirm",target_result).submit(function(){
			target_result.fadeOut('fast', function(){
				//target_result.empty().show();
				target_result.remove();
				//clear_form(target_form);
				
				/**
				enable the submit button again after processing the xml output
				**/	
				$('input[type=submit]',target_form).attr('disabled', '').css({opacity:1});
				
			});
			return false;
		})	
	});
	
}
