jQuery(document).ready(function($){

	 $("#loadingMessage").ajaxStart(function(){
   $(this).show();
 });

	 $("#loadingMessage").ajaxStop(function(){
   $(this).hide();
 });

	 $("#loadingMessage").live('click',function(){
   $(this).hide();
 });

	// Accordion
	$("#accordion").accordion({
		header: "h3",
		autoHeight: false
		 });

	$("#dynamicaccordion").accordion({
		active:0,
     	change: function() {
     		var active=($('.ui-state-active').attr('id'));
			var page=document.location.href;
			page=page.replace("#","");

	        $.post(page,
				{'ajaxrequest':active
				},
				function(content){
					if(active){
						var idarray=active.split(":");
						$('#' + idarray[1]).html(content);
					}
				}
			);
},
		header: "h3",
		autoHeight:false,
		collapsible:true,
		navigation:true
	});
	/*
	this section handles sorting the officers list and passing updates to the db
################################################################################
	*/

	$(function() {
		$(".sortable").sortable(
			{
				handle:'.handle',
				update:function(){
					var order=$(this).sortable('serialize');
//					$("#info").html(order);// output the content to a div for viewing when debugging
					var requesttype=$(this).attr('id');
					var page=document.location.href;
					page=page.replace("#","");

                	$.post(page,
						{'ajaxrequest':requesttype,
						'order':order
						}
					);
				}
			}

		);
		$(".sortable").disableSelection();
	});


/* end of section t handle sorting of officers list
################################################################################
*/
	// Tabs
	$('#tabs').tabs();

	// Dialog
	$('#dialog').dialog({
		autoOpen: false,
		width: 600,
		buttons: {
			"Close": function() {
				$(this).dialog("close");
			}
		}
	});

	$('.dialog_test').live('click',function(){
		var page=document.location.href;
		page=page.replace("#","");

		alert('on page ' + page);
		var requesttype=$(this).attr('id');

	   	$('#dialog').load(page,{
			'ajaxrequest':requesttype
			},
			function(data){
				$('#dialog').html(data);// add the data to the div
			}
		);
  		$('#dialog').dialog('open');
		$('#dialog').focus();

		return false;


	});

	$('.closedialog').live('click',function(){// close the dialog box
		$('#dialog').dialog("close");// close the dialog box
	});

	// Dialog Link
	$('.dialog_link').live('click',function(){
		var requesttype=$(this).attr('id');
		var attributes=$(this).attr('data');
		var title=$(this).attr('title');
		if(title!=''){
			$('#dialog').dialog('option', 'title', title);
		}
		if($(this).hasClass('modal')){
  			$('#dialog').dialog('option','modal',true);
		}
		var page=document.location.href;
		page=page.replace("#","");

    	$('#dialog').load(page,{
			'ajaxrequest':requesttype,
			'attributes':attributes
			},
			function(data){
				$('#dialog').html(data);// add the data to the div
					$('.processvaluetrigger').bind('click',function(){
						$('#processvalue').val($(this).val());
					});

                	$('.ajaxupdate').bind('click',function(){
                		var msg='';
						$.post(page,
							{'ajaxrequest':requesttype,
							'requesttype':'process',
							'value':$('#processvalue').val()},
							function(data){
								if(data>0){
									$('#dialog').dialog("close");// close the dialog box
									var idarray=requesttype.split(":");
									if(idarray[4]){$('#' + idarray[4]).html($('#processvalue').val());}// set the value of the item in the list
								}
                                else if (data.substring(7,0)=='invalid'){
                                	msg=data.split(":");
									alert(msg[1]);
								}
								else if (data.substring(7,0)=='replace'){
									// replace the value in the dialog with the new html
									msg=data.split(":");
									var id=msg[1];
									var content=msg[3];
									$('#dialog').html(content);
                                    $('.ajaxupdate2').bind('click',function(){
										$.post('#',
											{'ajaxrequest':requesttype,
											'requesttype':'process',
											'value':$('#processvalue').val()},
											function(data){
                                                if(data>0){
													$('#dialog').dialog("close");// close the dialog box
													var idarray=requesttype.split(":");
													$('#' + idarray[4]).html($('#processvalue').val());// set the value of the item in the list
												}
				                                else if (data.substring(7,0)=='invalid'){
				                                	msg=data.split(":");
													alert(msg[1]);
												}
												else{
													$('#dialog').html('We apologize, but there was a problem in processing your request.  Please notify Satori Web Design of the problem.');		}
											});
									});

								}
								else if(data.substring(3,0)=='msg'){// an option to leave everything in place but return a msg alert
									msg=data.split(":");
									alert(msg[1]);
									if(msg[2]=='reload'){location.reload();}
								}
								else if(data.substring(7,0)=='element'){// replace an element in accordion with a new value
									msg=data.split(":");
									$('#' + msg[1]).html(msg[2]);
									if(msg[4]){
										// there is a second element to replace, is it data or another element?
										if(msg[4]=='data'){
											$('#' + requesttype).attr('data',msg[5]);
										}
										else{
										$('#' + msg[4]).html(msg[5]);
										}
									}
									if(msg[3] && msg[3]!=''){// if there is a msg 3 element and it is not blank, show the message as an alert
										$('#dialog').html(msg[3]);
									}
									else {$('#dialog').dialog("close");}// close the dialog box
								}
								else if(data.substring(7,0)=='message'){
									msg=data.split(":");
									$('#dialog').html(msg[1]);
								}
								else {$('#dialog').html('We apologize, but there was a problem in processing your request.  Please notify Satori Web Design, LLC of the problem.');}
						  //
							});
					return false;
					});// end ajaxupdate function

                	$('.ajaxadd').click(function(){
						$.post(page,
							{'ajaxrequest':requesttype,
							'requesttype':'process',
							'processkey':$('#processkey').val(),
							'parentid':$('#parentid').val(),
							'value':$('#processvalue').val()},
							function(data){
								if(data==-1){
									$('#dialog').html('We apologize, but there was a problem in processing your request.  Please notify Satori Web Design, LLC of the problem.');

									}
                                else if (data.substring(7,0)=='invalid'){
                                	var msg=data.split(":");
									alert(msg[1]);
								}
								else{
                  					$('#dialog').dialog("close");// close the dialog box
									var idarray=requesttype.split(":");
									// add a new element to the list
									$('#' + $('#parentid').val()).append(data);
									$('#parentid').sortable('refresh');
								}
							});
					return false;
					});// end ajaxadd function


                	$('.ajaxdelete').click(function(){
						$.post(page,
							{'ajaxrequest':requesttype,
							'requesttype':'process',
							'value':$('#processvalue').val()},
							function(data){
								if(data>0){
									$('#dialog').dialog("close");// close the dialog box
								/*	alert('You have deleted the entry ' + requesttype);*/
									var idarray=requesttype.split(":");
									$('#' + idarray[4]).remove();// set the value of the item in the list
									}
									else {$('#dialog').html('We apologize, but there was a problem in processing your request.  Please notify Satori Web Design, LLC of the problem.');}
						  //
							});
						return false;
					});// end ajaxdelete function

				$('.ajaxreload').click(function(){
					location.reload();
				});

		});

  		$('#dialog').dialog('open');
		$('#dialog').focus();

		return false;
	});

		$('.ajaxtest').live('click',function(){
			var id=$(this).attr('id');
  			alert('testing ' + id + ' and the parameters are: ' + $('#' + id + 'parameters').html());
			return false;
		});

		$('.ajaxquickcheck').live('click',function(){
			var id=$(this).attr('id');
			var page=document.location.href;
			page=page.replace("#","");

			$.post(page,
				{
					'ajaxrequest':id
				},
				function (data){
					msg=data.split(":");
					if(msg[0]=="msg"){alert(msg[1]);}
				}
			);
		});// end ajaxquickcheck

		$('.ajaxchecktodb').live('click',function(){
			var id=$(this).attr('id');
			var value=$(this).val();
			var boxchecked=0;

			if($('#' + id).is(':checked')){
				boxchecked=1;
			}

  	   		var parameters=$('#' + id + 'parameters').html();
			if(value=="test"){alert("Debugging returns " + id + ' as the id and the value of ' + value + ' boxchecked equals ' + boxchecked + ' and parameters of ' + parameters);}


			var page=document.location.href;
			$.post(page,
				{
					'ajaxrequest':parameters,
					'id':id,
					'boxchecked':boxchecked,
					'value':value
				},
				function (data){
					msg=data.split(":");
					if(msg[0]=="msg"){alert(msg[1]);}
					if(msg[0]=="element"){$('#' + msg[1]).html(msg[2]);}// change out an element on the page
				}
			);
		});// end ajaxchecktodb

		$('.ajaxradiotoelement').live('click',function(){
			// change the attributes of an element on screen
			var data=$(this).attr('data');
			da=data.split(',');
			$('#' + da[0]).attr(da[1],da[2]);

		});

   		$('.ajaxradiotodb').live('click',function(){
			var id=$(this).attr('id');
			var radioname=$(this).attr('name');
			var value=$(this).val();
			var boxchecked=0;

			if($('#' + id).is(':checked')){
				boxchecked=1;
			}

  	   		var parameters=$('#' + radioname + 'parameters').html();
			if(value=="test"){alert("Debugging returns " + id + ' as the id and the value of ' + value + ' boxchecked equals ' + boxchecked + ' and parameters of ' + parameters);}


			var page=document.location.href;
			$.post(page,
				{
					'ajaxrequest':parameters,
					'id':id,
					'boxchecked':boxchecked,
					'value':value
				},
				function (data){
					msg=data.split(":");
					if(msg[0]=="msg"){alert(msg[1]);}
					if(msg[0]=="element"){$('#' + msg[1]).html(msg[2]);}// change out an element on the page
					if(msg[3]=="close"){$('#dialog').dialog('close');}
					if(msg[4]){
						// there is a second element to replace, is it data or another element?
						if(msg[4]=='data'){
							$('#' + requesttype).attr('data',msg[5]);
						}
						else{
						$('#' + msg[4]).html(msg[5]);
						}
					}
				}
			);
		});// end ajaxradiotodb


		// this function uses a parameter element to provide details about the transaction that cannot be provided in the id because jquery will not process correctly if there are : in the id.  Also, use a underscore in the id
		$('.ajaxcheckboxprocess').live('click',function() {
			var id=$(this).attr('id');
			var boxchecked=0;

			if($('#' + id).is(':checked')){
				boxchecked=1;
			}
  	   		var requesttype=$('#' + id + 'parameters').html();

			var page=document.location.href;
            $.post(page,
				{'ajaxrequest':requesttype + ':boxchecked=' + boxchecked
				},
				function(data){
					$('#' + id + 'content').html(data);
				}
			);

			});

		$('.hiddenmessage').live('click',function(){
				var hmname=$(this).attr('name');
				var hiddenmessageid=$(this).attr('name') + 'hiddenmessage';
				alert($("#" + hiddenmessageid).html());
				$('.' + hmname).removeClass('hiddenmessage');

			}); // end send hidden message

		$('.onetimemessage').live('click',function(){
			var hmname=$(this).attr('name');
			var hiddenmessageid=$(this).attr('name') + 'onetimemessage';
			alert($("#" + hiddenmessageid).html());
			$('.onetimemessage').removeClass('onetimemessage');
		});// END onetimemessage


		$('.ajaxformprocess').live('click',function(){
			// process a form
			var id=$(this).attr('id');
			var i=0;
			var datalist='';
			var page=document.location.href;
			page=page.replace("#","");
			var editorname='';
			var attributes=$(this).attr('data');
			// find the passed in data parameters
			if(attributes!='' && attributes!=null){
				aa=attributes.split(",");
				for(x in aa){
					if(aa[x].substr(0,10)=='editorname'){
						editorname=aa[x].substr(11);
					}
				}
			}

			if(editorname.length>0){
			if(WPro.editors[editorname] )
			{// get the text editor if it exists
				datalist=editorname + '=' + WPro.editors[editorname].getValue();
			}
			}

			$('.formfield').each(function(){
			   	datalist=datalist + '%%' + $(this).attr('name') + '=' + $(this).val();
			}); // end each statement

			// get the radio buttons
			$("input:radio:checked").each(function(){
				datalist=datalist + '%%' + $(this).attr('name') + '=' + $(this).val();
			});// end radio button section

			// get the checkboxes - untested, but should work as does radio buttons
			$("input:checkbox:checked").each(function(){
				datalist=datalist + '%%' + $(this).attr('name') + '=' + $(this).val();
			});// end checkbox section

			if(id=='test'){alert('in test mode.  Datalist is ' + datalist);}

            $.post(page,{
			   'ajaxrequest':id,
			   'datalist':datalist
			   },
			   function(data){
				var msgarray=data.split(':');
				if(msgarray[0]=='msg'){
					alert(msgarray[1]);
					if(msgarray[2]){
					}
				}

				if(msgarray[0]=='dialog'){// display the dialog box with the message
					newmsg=msgarray[1].replace(/\%\+\%/g,':');
					$('#dialog').dialog('open').html(newmsg).focus();// add the data to the div

				}

				if(msgarray[0]=="refresh"){
					alert(msgarray[1]);

					$("#dynamicaccordion").accordion('destroy').accordion({
						active: 0,
				     	change: function() {
				     		var active=($('.ui-state-active').attr('id'));
					        $.post('#',
								{'ajaxrequest':active
								},
								function(content){
									if(active){
										var idarray=active.split(":");
										$('#' + idarray[1]).html(content);
									}
								}
							);
				},
						header: "h3",
						autoHeight:false,
						collapsible:true,
						navigation:true
					});

				};

				if(msgarray[0]=="reload"){
					alert(msgarray[1]);
					location.reload();
				};// end reload

				if(msgarray[0]=="postback"){
					var pbid=msgarray[1];
					var targetid=msgarray[2];
					var pbdata=msgarray[3];
					// use this option to post back to a processing file that will reload a major section of the page without reloading the whole page
		            $.post(page,{
					   'ajaxrequest':pbid,
					   'datalist':pbdata
					   },
					   function(data){
							$('#' + targetid).html(data);// post the data back to the target
						});

				}

				if(msgarray[0]=="replace"){
					// replace the html in the element
					var content=msgarray[1];
					contentarray=content.split("=");
					$('#' + contentarray[0]).html(contentarray[1]);
					if(msgarray[2]){
						var content2=msgarray[2];
						contentarray2=content2.split("=");
						$('#' + contentarray2[0]).html(contentarray2[1]);
					}

				}

				if(msgarray[0]=="replacemultiple"){
					// replace a number of elements on the page.  all must be html
					var elements=msgarray[1];
					var contents=msgarray[2];
					earray=elements.split("%%");
					carray=contents.split("%%");
					ealength=earray.length;
					for(x=0;x<ealength;x++){
						$('#' + earray[x]).html(carray[x]);
					}
				}

				if(msgarray[0]=="confirm"){
					if(confirm(msgarray[1])){// show a confirm box
						requesttypearray=msgarray[2].split("=");
						var requesttype=requesttypearray[1];
						$.post('#',
							{
								'ajaxrequest':requesttype,
								'datalist':msgarray[3]
							},
							function(data){
								if(data=="reload"){location.reload();}
							}
					);// use a post to execute the action
				return false;
				}
			}// end the confirm option

			if(msgarray[2]=="msg"){
				alert(msgarray[3]);
			}

			if(msgarray[0]!='dialog'){$('#dialog').dialog("close");}// close the dialog box
			});

			return false;

		});// end ajaxformprocess

		$('.helphint').live('click',function(){
			var title=$(this).html();
			if(title.substring(0,4)=='Open'){
				$(this).html('Hide ' + title.substring(4));
			}
			else if(title.substring(0,4)=='Hide'){
				$(this).html('Open' + title.substring(4));
			}
			var datastring=$(this).attr('data');
			var dataarray=datastring.split(":*:");
			$('#' + dataarray[0]).html(dataarray[1]);
			$('#' + dataarray[0]).toggle('slow');
			return false;
		});

		$('.displaycontent').live('click',function() {
			var id=$(this).attr('id');
			var page=document.location.href;
			var requesttype=$('#' + id + 'parameters').html();
			if(id.substring(4,0)=='test'){alert('test and requesttype is ' + requesttype);}
            $.post(page,
				{'ajaxrequest':requesttype
				},
				function(data){
                	if(id.substring(4,0)=='test'){alert('returned data is ' + data);}

					$('#' + id + 'content').html(data);
				}
			);

			$('#' + id + 'content').toggle('slow');
			return false;
			});

		$('.slidefile').live('click',function(){
   			var parameters=$(this).attr('data');
			var name=$(this).attr('name');
			// split the parameters up to get the elements
			// elements are given by : separated list= request type:destination id:attributes
 			pa=parameters.split(':');

			if(pa[0]=="test"){
				alert(pa[1]);
			}// diagnostic step for testing
			var attributes='';
			var page=document.location.href;
			page=page.replace("#","");
			var setfocus=null;

			// the data to be passed to the php processing page
			if(pa[2]!='undefined'){attributes=pa[2];}

			if(name=='modal'){
				//Get the screen height and width
				var maskHeight = $(document).height();
				var maskWidth = $(window).width();

				//Set height and width to mask to fill up the whole screen
				$('#mask').css({'width':maskWidth,'height':maskHeight});

				//transition effect
				$('#mask').fadeIn(1000);
				$('#mask').fadeTo("slow",0.8);
			}

            $.post(page,
				{'ajaxrequest':pa[0],
				'destination_id':pa[1],
				'id':$(this).attr('id'),
				'attributes':attributes
				},
				function(data){
					da=data.split("::");// the returned data is a :: delinated list that includes the success/fail indicator, the destination id, content, and the duration of the slidedown
					if(da[0]=='success'){// this is the success option
			 			$('#' + da[3]).removeClass('slidefile').addClass('slideupfile');
						$('#' + da[1]).html(da[2]).slideDown('1000').focus();
						if($('#' + da[3]).hasClass('menu')){$('#' + da[3]).addClass('menu-active').removeClass('menu-over');}// if this is a menu item, set the menu item to active

						$('.adddatepicker').addClass('datepicker').removeClass('adddatepicker');
						$('.datepicker').datepicker({
							inline:true,
							dateFormat: 'yy-mm-dd',
							altField:'#alternate',
							altFormat: 'DD, d MM, yy',
							changeYear:true,
							changeMonth:true

							}
						);
						if($('#' + da[3]).hasClass('addbuttons'))
							{
								$('.needbutton').each(function(){
									$(this).switchClass('needbutton','hasbutton','1000').button();
								});
							}
					}
					else{
						alert('There has been an error and it has been reported to Satori Web Design.  We apologize for the inconvenience.');
					}
				}
			);

  	   		return false;
   			});// end slidefile

		$('.slideupfile').live('click',function(){
			var id=$(this).attr('id');
			var array=$(this).attr('data').split(":");// the data field must contain the slidedown action, so we need to ignore it
			var destination_id=array[1];
			$('#' + destination_id).slideUp('1000');
			$(this).removeClass('slideupfile').addClass('slidefile');
			if($(this).hasClass('menu')){$(this).addClass('menu-normal').removeClass('menu-active');}// if this is a menu item, set the menu item to active
			if($(this).hasClass('nocontents')){// there should be no contents in this div when rolled up
				$('#' + destination_id).empty();
			}

			return false;
		});// end slideupfile

		$('.div-slide').live('click',function(){
			var data=$(this).attr('data');
			darray=data.split(':');
			var id=darray[1];
			if(($('#' + darray[2])).hasClass('ui-icon-plus'))
			{
				$('#' + darray[2]).switchClass('ui-icon-plus', 'ui-icon-minus', 1000);
			}
			else if($('#' + darray[2]).hasClass('ui-icon-minus'))
			{
				$('#' + darray[2]).switchClass('ui-icon-minus', 'ui-icon-plus', 1000);
			}
			if($(this).hasClass('down')){
				$('#' + id).slideUp('1000');
				$(this).removeClass('down');// if this is a menu item, set the menu item to active
			}
			else{
				$('#' + id).slideDown('1000');
				$(this).addClass('down');// if this is a menu item, set the menu item to active
			}
		});

		$('.menu-slide').live('click',function(){
			var data=$(this).attr('data');
			darray=data.split(':');
			var id=darray[1];
			if($(this).hasClass('down')){
				$('#' + id).slideUp('1000');
				$(this).removeClass('down').addClass('menu-over').removeClass('menu-active');// if this is a menu item, set the menu item to active
			}
			else{
				$('#' + id).slideDown('1000');
				$(this).addClass('down').addClass('menu-active').removeClass('menu-over');// if this is a menu item, set the menu item to active
			}
		});


		$('.menu-normal').live('mouseover',function(){
			$(this).addClass('menu-over').removeClass('menu-normal');
		});// end menu-normal

		$('.menu-over').live('mouseout',function(){
			$(this).addClass('menu-normal').removeClass('menu-over');
		});// end menu-over

		$('.placefile').live('click',function() {
			var id=$(this).attr('id');
			var requesttype=$('#' + id + 'parameters').html();
			var idarray=requesttype.split(":");
			var placeid=idarray[1];
			var page=document.location.href;
			page=page.replace("#","");

            $.post(page,
				{'ajaxrequest':requesttype
				},
				function(data){
					$('#' + placeid).html(data);
				}
			);

			$('#' + placeid).show('slow');
			return false;
			});

		$('.userdisplay').live('click',function(){
			// use this function to obtain results from user input, much like suggest except operates only after the button is clicked
			var v2key='';// initialize the variable
			var v2val=''; // initialize the variable
			var id=$(this).attr('id');// get the id of the submit button
			var attributes=$('#' + id).attr('data');// get the data element from the input element
  			var atts=attributes.split(",");// split the attributes so we can extract the name of the target area, which will be the first element
			var v1key=atts[0];
   			var v1val=$('#' + v1key).val();// assign the id of the entry field
			// get the radio buttons if there are any (this can use one set of radio buttons)

			if(atts[2]=='radio'){
	 	  		$("input:radio:checked").each(function(){
					v2key=$(this).attr('name');
					v2val=$(this).val();
					attributes=attributes + ',' + v2key + '=' + v2val;
				});// end radio button section
			};

  			var target=atts[1];// assign the target name to a variable
			// post the results to a file
			var page=document.location.href;
			page=page.replace("#","");

            $.post(page,
				{'ajaxrequest':id,
				'attributes':attributes,
				'value':v1val

				},
				function(data){
					$('#' + target).html(data);// place the results into a div or span element
				});// close the post block
			return false;
		});// close the function and userdisplay block

		$('.showfile').live('click',function() {
			// the construction for the id is php-request-action_next-action_id-where-file-to-be-placed_parameters-if-needed
			var id=$(this).attr('id');
			var idarray=id.split("_");
			var requesttype=idarray[0];
			var nextaction=idarray[1];
			var placeid=idarray[2];
			var parameters='';

			if(idarray[3]){// added on 2010/03/22 to enable scrolling
				parameters=idarray[3];
				}

			var attributes=$(this).attr('data');
			var page=document.location.href;
			page=page.replace("#","");

            $.post(page,
				{'ajaxrequest':id,
				'attributes':attributes
				},
				function(data){
					$('#' + placeid).html(data);
					$('.adddatepicker').addClass('datepicker').removeClass('adddatepicker');
					$('.datepicker').datepicker({
						inline:true,
						dateFormat: 'yy-mm-dd',
						altField:'#alternate',
						altFormat: 'DD, d MM, yy',
						changeYear:true,
						changeMonth:true

						}
					);

				}
			);

			$('#' + placeid).show('slow');
			if(parameters=='scroll'){$('html, body').animate({scrollTop:0}, 'fast');}
			return false;
			});

		$(".opensection").live('click',function(){
			var id=$(this).attr('id');
			var title=$(this).html();
			title=title.substring(4);
			var idarray=id.split("_");
			var requesttype=idarray[0];
			var placeid=idarray[1];
			var page=document.location.href;
			page=page.replace("#","");

			var attributes=$(this).attr('data');
			$('#' + id + '_boxcontrol').html('Hide Options');

			$(this).html('Hide ' + title);
			$(this).addClass('closesection').removeClass('opensection');
            $.post(page,
				{'ajaxrequest':id,
				'attributes':attributes
				},
				function(data){
					$('#' + placeid).html(data);
				}
			);

			$('#' + placeid).show('slow');
			return false;

		});

		$(".closesection").live('click',function(){
			var id=$(this).attr('id');
			var idarray=id.split("_");
			var requesttype=idarray[0];
			var placeid=idarray[1];
			var title=$(this).html();
			title=title.substring(4);
			$('#' + placeid).hide('slow');
			$(this).html('Show ' + title);
			$(this).addClass('opensection').removeClass('closesection');
			return false;
		});

		$(".showhelp").live('click',function(){
			var id=$(this).attr('id');
			var q=$(this).attr('data');
			$.post("http://satoricontentmanager.net/filelib/jquery/gethelp.php",{
				'q':q
				},function(data){
					$('#' + id).after("<span class='helpbox'>" + data + "</span>");
					$('#' + id).show('slow');
				}

			);

		});

		$(".helpbox").live('click',function(){
			$(this).hide('slow').empty();
		});

		// checkall function to check all boxes (or uncheck)
		$(".checkall").live('click', function(){
			var boxclass=$(this).attr('data');// get the class for the boxes to be checked
			var id=$(this).attr('id');
			var status='';
			if(boxclass=='test'){alert('Testing check all function for id ' + id);}
			if($('#' + id).is(':checked')){// get the status of the checkall checkbox
				status='checked';
				$('#checkallstatus').html('Uncheck All');
			}
			else {
				status='';
				$('#checkallstatus').html('Check All');
			}

			// set the status for the other checkboxes
				$('.' + boxclass).attr('checked', status);
			});// end checkall function
/* ########################### LIVE SORT ##################################### */
    	$(".livesort").live('mousedown',function() {
		$(".livesort").sortable(
			{
				handle:'.handle',
				update:function(event,ui){
					var order=$(this).sortable('serialize');
//					$("#info").html(order);// output the content to a div for viewing when debugging
					var requesttype=$(this).attr('id');
					var page=document.location.href;
					page=page.replace("#","");

                	$.post(page,
						{'ajaxrequest':requesttype,
						'order':order
						}
					);
				}
			}

		);
		$(".livesort").disableSelection();
	});

//############################## LIVE PREPEND ##################################

       	$('.ajaxprepend').live('click',function(){

       		var requesttype=$(this).attr('id');
			var idarray=requesttype.split(":");
			var parentid=$('#parentid').val();
			var value=$('#processvalue').val();
			var processkey=$('#processkey').val();
			var page=document.location.href;
			page=page.replace("#","");

			$.post(page,
				{'ajaxrequest':requesttype,
				'requesttype':'process',
				'processkey':processkey,
				'parentid':parentid,
				'value':value},
				function(data){
					if(data==-1){
						$('#dialog').html('We apologize, but there was a problem in processing your request.  Please notify Satori Web Design, LLC of the problem.');

						}
                             else if (data.substring(7,0)=='invalid'){
                             	var msg=data.split(":");
						alert(msg[1]);
alert('failure');
					}
					else{
						// data is returned from the post as a string. split the string using : to get the id, which will be the first element
						var dataarray=data.split("%%%");
						var newelementid=dataarray[0];
						var newcontent=dataarray[1];

       					$('#dialog').dialog("close");// close the dialog box
						// add a new element to the list
				   		$('#newelements').after("<div id='" + newelementid + "'></div>");
						// add the content to the element
				 		$('#' + newelementid).html(newcontent);
                        $('#dynamicaccordion').accordion('destroy').accordion({
			  				active:0,
					     	change: function() {
					     		var active=($('.ui-state-active').attr('id'));

						        $.post('#',
									{'ajaxrequest':active
									},
									function(content){
										var idarray=active.split(":");
										$('#' + idarray[1]).html(content);
									}
								);

							},
							header: "h3",
							autoHeight:false,
							collapsible:true,
							navigation:true
						});


					}
				});
		});// end ajaxadd function

	$('.clickalert').live('click',function(){
		// allow the message to be turned on or off
		var msg=$(this).attr('data');
		msgarray=msg.split(':');
		var status='';
		if(msgarray[0]=='on'){
			status='off';
			alert(msgarray[1]);// display the message
		}
		else{
			status='on';
		}
		// now reset the data attribute in case the element is clicked again
		$(this).attr('data',status + ":" + msgarray[1]);

	});

// ############################################################################
	// cleardate
	$('.cleardate').live('click',function(){
		var targetarray=$(this).attr('name').split(":");// get the attributes from the name tag, which can be delineated by :
		var the_target=targetarray[0];// define the field to be updated
		if(targetarray[1]!='undefined'){// if there is a value provided, use it
			var the_value=targetarray[1];
		}
		else {the_value='0000-00-00';}// otherwise, set it to 0000-00-00
		$('#' + the_target).val(the_value);// set the value
		return false;// prevent the link from taking the default action
	});// end cleardate


	// datepicker class
	$('.datepicker').datepicker(
		{
			inline:true,
			dateFormat: 'yy-mm-dd',
			changeYear:true,
			changeMonth:true
		}
	);

	// Datepicker
	$('#datepicker').datepicker({
		inline: true
	});

	// Slider
	$('.slider').slider({
		range: true,
		values: [17, 67]
	});

	// Progressbar
	$("#progressbar").progressbar({
		value: 20
	});

	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); },
		function() { $(this).removeClass('ui-state-hover'); }
	);

	// display the wysiwygPro text editor
	$('.wproshow').live('click',function(){
		var d=$(this).attr('data');
		darray=d.split(',');
		var ID=darray[0];
		var editorName=darray[1];
		var message='';
		if(darray[2]!=null){
			 message=darray[2];
		}

	    /* check if the editor has already been displayed */
		// changelog: 2010/07/25 modified this from previous "name="+editorName to deal with passed through messages
	    if (typeof(WPro) == 'undefined' || typeof(WPro.editors[editorName]) == 'undefined')
		{
			$("#"+ID).load('/editor.php', {"name":editorName,"message":message});
		}
	});


	$('.ckeditorshow').live('click',function()
{
	var config = {
		toolbar:
		[
			['Source','Save','Cut','Copy','PasteFromWord','-','Print', 'SpellChecker'],
    ['Bold','Italic','Underline'],
    ['NumberedList','BulletedList','-','Outdent','Indent'],
    ['Link','Unlink'],
    ['Image','Table','Smiley','SpecialChar'],
    '/',
    ['Styles','Format','Font','FontSize'],
    ['TextColor','BGColor'],
    ['Maximize','-','About']

		]

	};

	// Initialize the editor.
	// Callback function can be passed and executed after full instance creation.
	$('.jquery_ckeditor').ckeditor(config);
});

});
