	var standarderror="There was a problem processing your request. If this continues, please notify Satori Web Design.";
	var webmastererror="There was a problem processing your request. If this continues, please contact your webmaster for assistance.";

	function showOK(id){
		// inserts an ok checkmark after an element	
		$('#' + id).after("<img id='" + id + "ok'" + " src='http://satoricontentmanager.net/filelib/icons/ok.png'>");
	//	alert('added ok after ' + id);
		
	}

	function splitClass(classtosplit,classes){
		// when used with dialog boxes, this function must be called afterwards. However, if the dialog has a modal class, this will be useless if trying to update the dom on the page
		var carray=classes.split(" ");
		var clength=carray.length;
		var ctslength=classtosplit.length + 1;
		for(x=0;x<clength;x++){
			// iterate through each field that is named by classtosplit-
			if(carray[x].substring(0,ctslength)==classtosplit + "-"){
				pair=carray[x].split("-");
				value=pair[1];
			}
		}
		return value;

	}

	function fixSafeString(string){
		newstring=string.replace(/&/g,'-');// replace the & with a -
		newstring=newstring.replace(/#/g,'_');// replace the # with an _
		return newstring;
	}

	function getDialogId(data)
	{
		var classes=data.split("id-");// split the classes based on the id-
		if(classes.length==2){
			var ids=classes[1].split(" ");// split the remainder based on a space
			thisid='#' + ids[0];
		}
		else{
			thisid='#dialog';
		}
		return thisid;
	}

	function makeShadowBox(elementid,boxid,newclass,title){
		// add a header and formatting
		// implementation note: when setting this up, the elementid is the id of the clicked element and the boxid is the id of the created element. Use the most basic form of the name for the boxid, i.e., rfscratchpad, so that the last step can just add 'link' to enable the remote feature of the reveal class. Also, the content to be put inside of the shadowbox must be in a div with a fixed with to avoid having resizing issues
		if(!$('#' + boxid).is('div')){
			$('#' + elementid).after("<div id='" + boxid + "' class='draggable shadowbox' style='position:absolute;top:0'></div>");
			$('.draggable').draggable();
		}

		$('#' + boxid).addClass('dialog-support-body').html("<div class='dialog-support-top-corners dialog-support ' style='text-align:left;'><a href='#' class='" + newclass + "' id='close" + boxid + "' style='font-weight:normal;color:#FFFFFF;float:right;padding-right:10px'>close</a>" + title + "</div><div id='" + boxid + "content' style='padding:10px;text-align:left'></div>");
		
		if($('#' + elementid).hasClass('callapp')){$('#close' + boxid).addClass(' callapp ');}
		
		$('#close' + boxid).addClass('remote remotetarget-' + boxid + 'link');
	}

	function makeForm(thisdata,id){
		atts=thisdata.split(",");// get the array
		attlen=atts.length;
		var buttonid=''; // Also used in public-optin-golf-registration.php
		var buttonvalue='';
		var buttondata='';
		var buttonclass='';
		var buttontype='button';
		var formintro='';
		var formid='';
		var formclass='';
		var formdata='';
		var currentformdialogid='';
		var diagnostics='';
		var formreplacements='';
		var actionswap='';
		var addactionswap=0;
		var closedialog='';

		for(al=0;al<attlen;al++){
			pair=atts[al].split("=");
			if(pair[0]=='buttonclass'){
				buttonclass=pair[1];
			}
			else if(pair[0]=='formid'){
				formid=pair[1];
				buttonid=formid + 'button';
			}
			else if(pair[0]=='buttonvalue'){
				buttonvalue=pair[1];
			}
			else if(pair[0]=='buttondata'){
				buttondata=decodeString(pair[1]);// if using optin-do-submit, this includes the formid %% ajaxrequest, i.e., orderform%%callfile_public-optin-golf-registration_process.
			}
			else if(pair[0]=='buttontype'){
				buttontype=pair[1];
			}
			else if(pair[0]=='formintro'){
				formintro=decodeString(pair[1]);
			}
			else if(pair[0]=='formclass'){
				formclass=pair[1];
			}
			else if(pair[0]=='formdata'){
				formdata=pair[1];
			}
			else if(pair[0]=='debug'){
				diagnostics="<div id='validationresults'>Diagnostics on from test class!<br></div>";
			}
			else if(pair[0]=='formreplacements'){
				formreplacements=decodeString(pair[1]);// can be used to pass in replacements for the form elements
				farray=formreplacements.split(",");// this gives us key=value pairs
				fcount=farray.length;
			}
			else if(pair[0]=='actionswap'){
				// this means we're going to replace the button data with something from the form.  We can swap two actions
				actions=pair[1].split("-");
				if(actions.length==2){
					// there are two actions to swap, so do the check
					var ta = new RegExp(actions[0],"g");
					if(ta.test(buttondata)){
						// there is a match for the first action, so replace with the second
						var newtext = buttondata.replace(actions[0],actions[1]);
						buttondata=buttondata.replace(actions[0],actions[1]);
					}
					else{
						buttondata.replace(actions[1],actions[0]);// otherwise replace the second with the first.
					}

				}
			}
			else if(pair[0]=='addactionswap'){
				// this is to add the actionswap action when a form is called from a link and the actionswap should be delayed one step
				addactionswap=1;
			}
		}

		formcontent="<span id='currentformdialogid' style='display:none'>" + id + "</span><form class='" + formclass + "' id='" + formid + "' name='" + formid + "' method='post' action='#' data='" + formdata + "' >" + diagnostics + formintro + content + "<p><input type='" + buttontype + "' class=' " + closedialog + " " + buttonclass + " ' id='" + buttonid + "' value='" + buttonvalue + "' data='" + buttondata + "'></p></form>";
		if(formreplacements!=''){
			// this means that there are attributes to replace, so iterate through and make changes
			for(x=0;x<fcount;x++){
				fpair=farray[x].split("=");
				fpairkey=fpair[0];
				fpairval=fpair[1];
				formcontent=formcontent.replace('##' + fpairkey + '##',fpairval);
			}
			// we also need to replace the formreplacements tag with the full thisdata string so that this can bubble up  through multiple screens
			formcontent=formcontent.replace('##formreplacements##',thisdata);
		}
		if(addactionswap==1){formcontent=formcontent.replace('addactionswap','actionswap');}
		return formcontent;
	}


	// display a tool tip or cloud
	function createTip(target,xpos,ypos,content,title){
		if(title==''){title="Tip";}
		tip="<div class='cloud corners-10 shadows-10 dialog-support-body draggable' id='" + target + "' style='width:200px;position:absolute;top:" + ypos + "px;left:" + xpos + "px;background-color:#FFF;display:none'>" + "<div class='dialog-support-top-corners dialog-support' style='padding:5px'><img class='closecloud' src='http://satoricontentmanager.net/filelib/icons/cancel.png' style='float:right;height:12px;width:12px;padding-left:10px;padding-bottom:10px;'>" + title + "</div><div style='padding:10px'>" + content + "</div></div>";
		return tip;
	}

	// find the x and y position for the cursor and return values within the window
	function setXpos(x){
		// determine the x coordinate.  if x is < 400 pixels, reverse the display by adding to the x position
		if(x<400){
			xpos=x+50;
		}
		else{
			xpos=x-250;
		}
		return xpos;
	}

	function setYpos(y){
		// determine the y coordinate.  if y is < 400 pixels, reverse the display by adding to the y position
		var theheight=$(document).height();
		var thelimit=theheight-y;
		if(y<400){
			ypos=y+50;
		}
		else if(thelimit<100){
			ypos=y-200;
		}
		else{
			ypos=y-100;
		}
		return ypos;
	}

	function decodeString(data){
		// the string must be encoded with urlrawurlencode in PHP and can be decoded with the exception of the asterisk and plus signs
		var decoded=unescape(data);
		decoded=decoded.replace(/%2A/g, "*");
		decoded=decoded.replace(/%2B/g, "+");
		return decoded;
	}

	function resetElements(data){
		// replace multiple elements, all must be html
		// the elements must be passed in as an escaped datastring, such as thiselementid=x.  Elements of the datastring must be separated by a comma
		// this is new as of 2011/01/27 and is used with config-home-page-slide-show-description.php successfully
		var elements=data.split(',');// this gives us an array of elements, each of which is a pair and is escaped
		ealength=elements.length;
		for(x=0;x<ealength;x++){
			// unescape the element then split the element into its key and value
			thisone=decodeString(elements[x]);
			pair=thisone.split("=");
			$('#' + pair[0]).html(pair[1]);
		}
	}

	function updateElements(data){
		// update page elements based on passed in data.  Each element must be passed in as a key=>value pair that have been urlencoded (each element is urlencoded) on the php page.  Elements are separated by a comma.
		earray=data.split(",");// assign the data to an array
		ealength=earray.length;// how many elements are in the array?
		var display='';
		var value='';
		var buttonid='';
		var dialogid='';
		var icount=0;
		var ecount=0;
		var ilist='';// used for diagnostics with ie only
		var elist='';// used for diagnostics with ie only
		for(x=0;x<ealength;x++){// iterate through
			display=earray[x].split("=");// split out the element id and the value
			value=decodeString(display[1]);// unencode the value
			// assign the value to the element
			if(display[0].substring(0,7)=='button-'){
				buttonid=display[0].substring(7);
				if(value=='disabled'){
			  		$('#' + buttonid).attr('disabled','disabled');
				}
				else{
					$('#' + buttonid).removeAttr('disabled');
				}
			}
			else if(display[0].substring(0,7)=='dialog-'){
				// this is a dialog box, so update the title of the box
				dialogid=display[0].substring(7);
				$('#' + dialogid).dialog('option','title',display[1]);
			}
			else if (display[0].substring(0,9)=='addimage-'){
				// this is a designation to add an to the element
				elementid=display[0].substring(9);
				$('#' + elementid).html("<img src='http://satoricontentmanager.net/filelib/" + display[1] + "'>");
			}
			else if($('#' + display[0]).is('input')){
				$('#' + display[0]).val(value);
				icount=icount+1;
				ilist='added ' + display[0] + ',';
			}
			else if($('#' + display[0]).is('select')){
				$('#' + display[0]).val(value);
				icount=icount+1;
				ilist='added ' + display[0] + ',';
 			}
			else{
				if($('#' + display[0]).length===0){
					$('#loadingMessage').after("<div id='" + display[0] + "' style='display:none'></div>");// if there is no element, create one that is not visible
				}
				$('#' + display[0]).html(value);
				ecount=ecount+1;
				elist=elist+ ' added ' + display[0] + ',';
			}
		}
//		if(document.domain=="kiwaniswebsites.org"){alert(icount + ' is icount and ilist is ' + ilist + ' and ecount is ' + ecount + ' and elist is ' + elist);}
	}

	function makeDialog(id,thiselement){
		/* this function:
			1) looks for a div with the id of "id"
			2) uses the element's title attribute to set the title of the dialog
			3) if the element has a class of target-"x" in the classes, it sets a target for the dialog box, otherwise the dialog goes after loadingMessage
			4) it constructs the dialog, but does not add content
		*/
		var thiselement="#" + thiselement;
		if(!$('#' + id).is('div')){
			if($(thiselement).hasClass('target')){
				// set the location of the dialog box, which will be either after an element specified by target-id name or the default of loadingMessage
				testclasses=$(thiselement).attr('class');
				tca=testclasses.split("target-");
				tca2=tca[1].split(" ");
				targetid=tca2[0];
			}
			else{
				targetid='loadingMessage';
			}
			$('#' + targetid).after("<div class='defaulttext' id='" + id + "' style='text-align:left'></div>");
		}

		var title=$(thiselement).attr('title');

	 	$('#' + id).dialog({
			autoOpen: false,
			width: 600,
			modal:true,
			show:'blind',
			hide:'blind',
			title:title,
			buttons: {
				"Close": function() {
					$(this).dialog("close");
				}
			}
		});
//		if(document.domain=="kiwaniswebsites.org"){alert('creating dialog with id ' + id + ' after element ' + targetid);}

	}

	function setDatePicker(){
		$('.datepicker').datepicker(// added 2011/08/07 
		{
			inline:true,
			dateFormat: 'yy-mm-dd',
			changeYear:true,
			changeMonth:true,
			altField:'#alternate',
			altFormat: 'DD, d MM, yy'			
		}
		);
		if($('.datepicker').hasClass('historic')){$(".datepicker" ).datepicker( "option", "yearRange", '-70:+2' );
		}
	}

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);
/* end image preloader script  call this with a script that references the full path to each image file:
<script>
jQuery.preLoadImages("/home/scmadmin/public_html/filelib/CM13%20Files/images/SSBut.png", "/home/scmadmin/public_html/filelib/CM13%20Files/images/SSHover.png","/home/scmadmin/public_html/filelib/CM13%20Files/images/contactbut.png", "/home/scmadmin/public_html/filelib/CM13%20Files/images/ContactHover.png");
</script>
// changelog 2011/01/09 added toggleelement function, which can work in conjunction with displaycloud
// changelog: 2010/12/22 added displayhelp, displaycloud, and displaycloudlock functions
// changelog: 2010/12/21 modified ajaxquickcheck function to allow for use of data element and pass additional values to processing file via post
// changelog: 2010/11/01 in ajaxupdate function, changed first return value to >=0 from >0.  Value echoed by process-common.php is -1 if failure
*/
jQuery(document).ready(function($){

	var page=document.location.href;
	page=page.replace("#","");

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

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

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

	$('.standardbutton').live('mouseover',function(){
		$(this).addClass('standardbutton-hover').removeClass('standardbutton-normal');
	});

	$('.standardbutton').live('mouseout',function(){
		$(this).removeClass('standardbutton-hover').addClass('standardbutton-normal');
	});

	$('.updatepageelements').live('click',function(){
		// send elements to this page as key=rawurlencoded(value) pairs separated by commas ","
		var id=$(this).attr('id');
		var attributes=$(this).attr('data');
		 $.post(page,
			{'ajaxrequest':id,
			'attributes':attributes
			},
			function(data){
				msg=data.split("_");
				if(msg[0]=="msg"){alert(msg[1]);}//this would mean there was an error
				if(msg[0]=="updates"){
					content=decodeString(msg[1]);
					updateElements(content);
				}
			});
		
	});// end updatepageelements

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

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

	        $.post(page,
				{'ajaxrequest':active
				},
				function(content){
					if(active){
						var idarray=active.split(":");
						$('#' + idarray[1]).html(content);
					}
				}
			);
},
		header: "h3",
		autoHeight:false,
		collapsible:true,
		navigation:true
	});

	$("*[class^='reveal']").live('click',function(e){
		// Implementation Note 1: THIS CLASS MUST BE FIRST, IT CANNOT BE PRECEDED BY ANY OTHER CLASS!
		// the calling element must have 4 parameters, the class prefix, an id for the action, the action, and a duration. The id must already exist and be populated with content.  This function will also install its opposite, the hide option, to enable the user to close the opened section.  this can also have a fifth parameter of post that will cause the function to post to a file to retrieve content.  A sixth parameter can be used to pass along parameters to a processing file.  the sixth parameter should take the form of a rawurlencoded string that includes: callfile or callscript,the target post file,the ajax instruction,any additional parameters

// Implementation Note:  THE LINK ID MUST MATCH THE SECOND REVEAL CLASS ELEMENT + "LINK" FOR SHADOWBOX when using the post option, the file name must have hyphens replaced by & (ampersand) and the class should be like: <a id="instructionslink" class="reveal-instructions-slideDown-2000-post-admin&optin&edit&golf&options&form_instructions " href="#">Click here</a> to insert a link that opens a dialog, use $readyfile=MakeSafeString("public-optin-login-form-for-reveal"); <a href='#' class='reveal-userlogin-slide-slow-post-" . $readyfile . " isdialog isform ' id='userlogin' title='Member Login'>click here</a>;
		
		if($(this).hasClass('setposition')){
			xpos=setXpos(e.pageX);
			ypos=setYpos(e.pageY);
		}

		function returnNewClass(action,id,duration,returnclass){
			if(action=='slideDown'){
				newaction="-slideUp-";			}
			else if(action=="slideUp"){
				newaction="-slideDown-";
			}
			else if(action=="slide"){
				// this is used with dialog boxes
				newaction="-slide-";
				duration="slow";
			}
			else if(action=="show"){
				newaction="-hide-";
				duration='slow';
			}
			else if(action=="hide"){
				newaction='-show-';
				duration='slow';
			}
			else if(action=="fadeIn"){
				newaction="-fadeOut-";
			}
			else if(action=="fadeOut"){
				newaction="-fadeIn-";
			}
			else if(action=="dialog"){
				newaction="-dialog-";
			}
			newclass="reveal-" + id + newaction + duration + returnclass;
			return newclass;
		}

		if($(this).hasClass('test')){debug=1;}
		else {debug=0;}
		classes=$(this).attr('class');// get all of the classes
		thiselement=$(this).attr('id');
		var thisdata='';
		if($(this).attr('data')){thisdata=$(this).attr('data');}

		if($(this).hasClass('noprint')){
			doprint=0;
		}
		else{
			doprint=1;
		}

		if($(this).hasClass('remote')){
			// get the target, which will be class=remotetarget-addgolferbutton. this option allows for use of a remote contol submit button that submits the form and returns the proper class to the originating element.  syntax for the button class is class='reveal-addgolfer-hide-slow{$returnclass} remote remotetarget-addgolferbutton optin-form-submission updatecart v3-final-check' : note that the slow parameter is followed immediately by the return class, which must be passed in via post and is $returnclass=$_POST['returnclass'];
			classarray=classes.split(' ');
			classlen=classarray.length;
			for(c=0;c<classlen;c++){
				if(classarray[c].substring(0,13)=='remotetarget-'){
					thisid=classarray[c].substring(13);
					if(debug==1){alert(thisid + ' is the remote target');}
					break;
				}
			}

		}
		else {
			thisid=$(this).attr('id');
		}

		ca=classes.split(' ');// split them into an array
		var calength=ca.length;// get the number of classes and then iterate through
		for(x=0;x<calength;x++){
			if(ca[x].substring(0,7)=="reveal-"){
				// select the one that begins with show-
				var thisclass=ca[x];
			}
		}

		thisca=thisclass.split('-');// split that class by the -
		var id=thisca[1];// set the id using the 2nd parameter
		var action=thisca[2];// set the action using the 3rd parameter
		var duration=thisca[3];// set a duration using the 4th parameter
		var returnclass='';
		var attributes='';
		var buttonclass='';// Used successfully in public-optin-golf-registration.php. Example for this implementation that implements the reveal of the box as well as passing of variables to process form
		/*
		// buttonatts becomes the parameters (part 3) of the string separated by _
		$formintro=rawurlencode("Your contact information should be listed below.  If any of this information is incorrect, please make your changes here.");

		$buttondata=rawurlencode("orderform%%callfile_public-optin-golf-registration_process");
		$buttonatts="formintro=" . $formintro . ",buttonclass=optin-do-submit v3-final-check,formid=orderform,buttonvalue=Submit,buttondata=" . $buttondata;

		$editbuyerparameters="productid=" . $productid . ",mid=" . $mid . ",cid=" . $cid . $buyeratts . "," . $buttonatts;// we can remove $buyeratts if not needed
		$form="<span style='float:right'><a href='#' class='" . $revealclass . " isdialog isform ' id='editbuyer' title='Buyer Contact Info' data='" .  $editbuyerparameters . "'>edit</a>		*/

		if(debug==1){
			alert('Testing on.  Classes are ' + classes + ' for id ' + thisid + ' and the target id is ' + id + '.  The clicked element is ' + thiselement + ' and the action is ' + action);
		}
		if(thisca[4]!='undefined'){
			// this part of the class includes some options
			if(thisca[4]=='post'){
				returnclass="-post";// we're creating the last elements of the return class here.  The beginning part, which includes the action, will be constructed below
				if(thisca[5]!='undefined'){// see if there are parameters to pass along to the file.  this includes a target file for processing such as public&optin&golf&registration_form (note the safe string use of & instead of hyphen)
					decodedparameters=decodeString(thisca[5]);
					parameters=fixSafeString(decodedparameters);// parameters include the processing file and directive for $explode.  This is encoded for safe transport and does have ampersands instead of - to avoid conflicts with the class

					safereturnclass=returnclass + "-" + thisca[5];
					returnclass=returnclass + "-" + parameters;

					if(thisdata!=''){
						attributes=fixSafeString(thisdata);
					}
				}

				if($(this).hasClass('callapp')){
					ajaxrequest='callapp_' + parameters;
				}
				else{
					ajaxrequest='callfile_' + parameters;
				}
					
				$.post(page,{
				   'ajaxrequest':ajaxrequest,
				   'attributes':attributes,
				   'returnclass':returnclass,
   				   'id':id,
				   'doprint':doprint
				   },
				   function(data){
				   	content=decodeString(data);// defines the content to be added to dom
			  //		if(debug==1)alert('returned content ' + content.substring(0,100));
					if($('#' + thiselement).hasClass('isdialog')){// if the clicked element has a class of isdialog
						makeDialog(id,thiselement);// this only creates dialog, content added at end of this condition
						if(debug==1)alert('Created dialog box with id ' + id);
						if($('#' + thiselement).hasClass('isform')){
							if(debug==1){
								// add the diagnostic div to the form
								thisdata=thisdata + ",debug=1";
							}
							content=makeForm(thisdata,id);
						}

						$('#' + id).html(content).dialog("open");// content added to dialog
						setDatePicker();
					}
					else if($('#' + thiselement).hasClass('isshadowbox')){// if the clicked element has a class of isshadowbox
						var title=$('#' + thiselement).attr('title');// get the title from the clicked element
						newclass=returnNewClass(action,id,duration,safereturnclass);
						makeShadowBox(thisid,id,newclass,title);// create a shadowbox using the id of the element provided in the class (id - the second element in the class) and inserted after thisid (the clicked element)

						if($('#' + thiselement).hasClass('setposition')){

								$('#' + id).css({'top':ypos,'left':ypos});
						
						}

						if($('#' + thiselement).hasClass('isform')){
							formcontent=makeForm(content);
						}
						else{
							formcontent=content;
						}

						if(debug==1){
							targetclasses=$('#' + thiselement).attr('class');
						 //	alert('Testing on: Shadowbox exists in the clicked element ' + thiselement + ' with class ' + targetclasses + ', newclass of ' + newclass + ', title of ' + title + ' and the target id is shadowbox' + id + 'and adding HTML ' + formcontent);
						}

						$('#' + id + 'content').html(formcontent);
						setDatePicker();
						
					}
					else{
						if(debug==1){
							alert('Testing on: adding HTML to ' + content + ' to ' + id);
						}
						$('#' + id).html(content);
						setDatePicker();
					}
				   }
				);
			}
		}

		newclass=returnNewClass(action,id,duration,safereturnclass);

		if(action=='slideDown'){
			$('#' + id).slideDown(duration);// do the action
		}
		else if(action=="slideUp"){
			$('#' + id).slideUp(duration);
		}
		else if(action=="show"){
			$('#' + id).show('slow');
		}
		else if(action=="hide"){
			$('#' + id).hide('slow');
		}
		else if(action=="fadeIn"){
			$('#' + id).fadeIn(duration);
		}
		else if(action=="fadeOut"){
			$('#' + id).fadeIn(duration);
		}

		$('#' + thisid).removeClass(thisclass);// we need to remove the old class and apply a new one, but it needs to go at the beginning of the classes, so we need to do this
		var elementclass=$('#' + thisid).attr('class');/// this gets us the list of classes
			
		$('#' + thisid).removeClass(elementclass).addClass(newclass + ' ' + elementclass);// remove the old elementclass (all classes) and add the new classes

		if(debug==1){
			var newclasses=$('#' + thisid).attr('class');
			alert('Testing on.  At end of function, the class to be replaced is ' + thisclass + ' and the new class is  ' + newclass + ' for id ' + thisid + ' and the current element is  ' + thiselement + ' and action was ' + action + ' with new classes of ' + newclasses);
		}

		if($('#' + thiselement).is('a')){return false;}
	});

	/*
	this section handles sorting the officers list and passing updates to the db
################################################################################
	*/

	$(function() {
		$(".sortable").sortable(// remember that items must have an id like item_1!
			{
				handle:'.handle',
				update:function(){
					var order=$(this).sortable('serialize');
				//	if(document.domain=='kiwaniswebsites.org'){$("#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').dialog({// anything to be used as a dialog must have this class
		autoOpen: false,
		width: 600,
		show: 'slide',
		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
		var dialogid=$(this).closest('.ui-dialog-content').attr('id');
		$('#' + dialogid).dialog("close");// close the dialog box
	});

	// Dialog Link
	$('.dialog_link').live('click',function(){
		var requesttype=$(this).attr('id');
		var attributes=$(this).attr('data');
		var theclasses=$(this).attr('class');
		var title=$(this).attr('title');
		var swapid='';
		thisid=getDialogId($(this).attr('class'));// allows the use of a custom dialog id that will be prefixed by id-
		if(title!=''){
			$(thisid).dialog('option', 'title', title);
		}
		if($(this).hasClass('modal')){
  			$(thisid).dialog('option','modal',true);
		}
	
	if($(this).hasClass('test'))alert('dialog id is ' + thisid);
	  	if($(this).hasClass('swapindicator')){
			// get the class that begins with swapid-
			var carray=theclasses.split(" ");
			var clength=carray.length;
			for(x=0;x<clength;x++){
				// iterate through each field that is named by classtosplit-
				if(carray[x].substring(0,5)== "swap-"){
					swapid=carray[x].substring(5);
				}
				if(carray[x].substring(0,9)== "swapicon-"){
					swapicon=carray[x].substring(9);
				}
			}
			$('#' + swapid).html("<img src='http://satoricontentmanager.net/filelib/" + swapicon + "'>");
		}
	
    	$(thisid).load(page,{
			'ajaxrequest':requesttype,
			'attributes':attributes
			},
			function(data){
				if(document.domain!='kiwaniswebsites.org')$(thisid).html(data);// add the data to the div

				// add the select list contents
				fillselectid=$('.fillselect').attr('id');// get the id of the element
				fillselectmatch=$('#' + fillselectid).attr('data');// find the value that will be the match
				var filloptionsid=fillselectid + 'data';// set the id of the element with the data (will be the id + 'data')
				filloptions=$('#' + filloptionsid).html();// get the options
				filloptions=decodeString(filloptions);// decode
				$('#' + fillselectid).html(filloptions);// fill the select list
				$('#' + fillselectid).val(fillselectmatch)// set the value of the matched element

				$('.adddatepicker').addClass('datepicker').removeClass('adddatepicker');
				setDatePicker();

				$('.draggable').draggable({});
				$('.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){
									$(thisid).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];
									$(thisid).html(content);
                                    $('.ajaxupdate2').bind('click',function(){
										$.post('#',
											{'ajaxrequest':requesttype,
											'requesttype':'process',
											'value':$('#processvalue').val()},
											function(data){
                                                if(data>0){
													$(thisid).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{
													$(thisid).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.  values passed in are [0]=>element,[1]=>the element to be replaced,[2]=>the value to be inserted,[3]=>if not blank, show an alert in the dialog box,[4]=>if set to data,change the data element value,[5]=>the new data element 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
										$(thisid).html(msg[3]);
									}
									else {$(thisid).dialog("close");}// close the dialog box
								}
								else if(data.substring(7,0)=='message'){
									msg=data.split(":");
									$(thisid).html(msg[1]);
								}
								else {$(thisid).html('We apologize, but there was a problem in processing your request.  Please notify Satori Web Design 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){
									$(thisid).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{
                  					$(thisid).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){
									$(thisid).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 {$(thisid).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();
				});

		});

  		$(thisid).dialog('open').dialog('option','minHeight',300).focus();// changelog 2011/10/25 added minHeight option to dialog
  		
		return false;
	});

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

		$('body').delegate('.ajaxquickselect','change',function(){
			var id=$(this).attr('id');
			var attributes=$(this).attr('data');
			var value=$(this).val();// initialize the variable with no value
			var name=$(this).attr('name');

			$.post(page,
				{
					'ajaxrequest':id,
					'attributes':attributes,
					'value':value,
					'name':name
				},
				function (data){
					msg=data.split(":");
					if(msg[0]=="msg"){alert(msg[1]);}
					else if(msg[0]=="friendlymsg"){$('#' + msg[1]).html(msg[2]).dialog('open');}
					else if(msg[0]=="reset"){// elements and data passed in must be separated by %!%
						resetElements(msg[1]);
						if(msg[2]=="close"){$('#dialog').dialog('close');}
					}
				}
			);
		});// end ajaxquickselect

		$('.ajaxquickcheck').live('click',function(){
			var id=$(this).attr('id');
			var attributes=$(this).attr('data');
			var value=0;// initialize the variable with no value
			var name=$(this).attr('name');
   			if($(this).is(':checked')){
				value=$(this).val();
			}

			$.post(page,
				{
					'ajaxrequest':id,
					'attributes':attributes,
					'value':value,
					'name':name
				},
				function (data){
					msg=data.split(":");
					if(msg[0]=="msg"){alert(msg[1]);}
					else if(msg[0]=="friendlymsg"){$('#' + msg[1]).html(msg[2]).dialog('open');}
					if(msg[3]!='undefined')$('#' + msg[1]).dialog('option','title',msg[3]);

				}
			);
		});// 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(!parameters)parameters=$('#' + id).attr('data');

			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[0]=="updates"){
						content=decodeString(msg[1]);
						updateElements(content);
					}	
				}
			);
		});// 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(){
   		//	if(document.domain=="kiwaniswebsites.org"){alert('testing for ' + $(this).attr('name'));}
			var id=$(this).attr('id');
			var radioname=$(this).attr('name');
			var value=$(this).val();
			var boxchecked=0;
			var title=$(this).attr('title');

			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);}

			$.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[0]=="elements"){// insert "none" for msg[1]
					//	if(document.domain=="kiwaniswebsites.org"){alert('testing for ' + msg[2].substring(0,50));}
						updateElements(msg[2]);
					}
					if(msg[3]=="close"){$('#dialog').dialog('close');}
						else if(msg[3].substring(0,6)=="close-"){
							// close a dialog box with the id contained in the second half
							dialogid=msg[3].substring(6);
							$('#' + dialogid).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();

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

			});

		// toggleelement can be used in conjunction with displaycloud to display a help tip on hover and change out an element and process data on click.  This is being used successfully in admin-committees-set-committee-lock-status.php along with displaycloud
   		$('.toggleelement').live('click',function(){
			var id=$(this).attr('id');
			var elementclass=$(this).attr('class');
			var title=$(this).attr('title');
			var d=$(this).attr('data');
			darray=d.split('_');
			var target=darray[0];
			var file=darray[1];
			var attributes=darray[2];// the data to be passed to the php processing page
			$.post(page,
				{'ajaxrequest':'callfile_' + file + "_process",
				'attributes':attributes,
				'id':id,
				'class':elementclass
				},
				function (data){
					msg=data.split("%%");
					if(msg[0]=="msg"){
						alert(msg[1]);
					}
					else{
						for(x in msg){
							y=msg[x].split('|');
							$('#' + id).attr(y[0],y[1]);
						}
					}
				}); // end post
		});// end toggleelement


		$('.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 editorname='';
			
			var isjson=0;// initialize a variable to test for new processing
			if($(this).hasClass('isjson')){
				isjson=1;// set the variable if the class is set
			}

			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){
			   	if(isjson==1){
			   		resp=JSON.parse(data);// data is a json encoded string. This will return vars accessible as resp.var1, etc.
			   		processResponse(data);// use the function in swd-js-core to process
			   		var msgarray=new Array();
			   		msgarray[0]='';// now we shouldn't execute anything below
			   		
			   	}
			   	else{
					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,':');// replace %% with a :
					$('#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=unescape(msgarray[2]);
					earray=elements.split("%%");
					carray=contents.split("%%");
					ealength=earray.length;
					for(x=0;x<ealength;x++){
						$('#' + earray[x]).html(carray[x]);
					}
				}
				else if(msgarray[0]=="reset"){// elements and data passed in must be separated by %!%
					resetElements(msgarray[1]);
					if(msgarray[2]=="close"){$('#dialog').dialog('close');}
				}

				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');
			var elementid=$(this).attr('id');
			
			// 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();
							});
						}
					//	if($('#' + elementid).hasClass('addeditor')){$('.ckeditor').ckeditor();}
					}
					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($(this).hasClass('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);
			}

			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
			}
		});

		// close a cloud balloon
		$('.closecloud').live('click',function(){
			$('.cloud').fadeOut('slow',function(){$('.cloud').remove();});
		});

		// used to display a simple help hint that is contained in the data element.  Data element includes a first section that is the id of the target and a second section that is the message to be displayed
		$('.displaycloudhelp').hover(
			function(e){
				xpos=setXpos(e.pageX);
				ypos=setYpos(e.pageY);
				var data=$(this).attr('data');
				var title=$(this).attr('title');
				darray=data.split('_');
				var target=darray[0];
				var content=darray[1];
				if(title!=''){content=title + "<br>" + content;}
				tip=createTip(target,xpos,ypos,content,title);
				$(this).before(tip);
				$('#' + target).fadeIn('slow').delay('1000');
			},
			function(){
				var data=$(this).attr('data');
				darray=data.split('_');
				var target=darray[0];
				$('#' + target).fadeOut('slow',function(){$('#' + target).remove();});
			}
		);

		$('.displaycloudlock').live('click',function(e){
			xpos=setXpos(e.pageX);
			ypos=setYpos(e.pageY);
			var id=$(this).attr('id');
			var title=$(this).attr('title');
			var data=$(this).attr('data');
			darray=data.split('_');
			var target=darray[0];
			var file=darray[1];
			var attributes=darray[2];// the data to be passed to the php processing page
			$.post(page,
				{'ajaxrequest':'callfile_' + file,
				'attributes':attributes
				},
				function(data){
//					$('#' + target).fadeIn('slow').html(data);// if the php processing fails the returned data will be an error message
					if(title!=''){data=title + "<br>" + data;}
					tip=createTip(target,xpos,ypos,data,title);
					$('#' + id).before(tip);
					$('#' + target).fadeIn('slow');
					$('.draggable').draggable({});
				});
			return false;
		})

		$('.displaycloud').hover(
			function(e){
				xpos=setXpos(e.pageX);
				ypos=setYpos(e.pageY);
				var id=$(this).attr('id');
				var title=$(this).attr('title');
				var d=$(this).attr('data');
				darray=d.split('_');
				var target=darray[0];
				var file=darray[1];
				var attributes=darray[2];// the data to be passed to the php processing page
				$.post(page,
					{'ajaxrequest':'callfile_' + file,
					'attributes':attributes
					},
					function(data){
						if(title!=''){data=title + "<br>" + data;}
						tip=createTip(target,xpos,ypos,data,title);
						$('#' + id).before(tip);
						$('#' + target).fadeIn('slow').delay('1000');
					});

			},
			function(){
				var data=$(this).attr('data');
				darray=data.split('_');
				var target=darray[0];
				$('#' + target).fadeOut('slow',function(){$('#' + target).remove();});
			}
			);

		$('.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

		$('.loadfile').live('click',function(){
			var id=$(this).attr('id');
			var attributes=$(this).attr('data');
			atts=attributes.split("%|%");// the attributes can include two separators.  This one will get us the first element, which is used for the placement of the file.  The second element is then passed along to the processing page.
	    	$('#' + atts[0]).load(page,{
				'ajaxrequest':id,
				'attributes':atts[1]
				},
				function(data){
					$('#'+atts[0]).html(decodeString(data));// add the data to the div
				});

		});

		$('.loadcontent').fadeIn(function(){
			var id=$(this).attr('id');
			var attributes=$(this).attr('data');
			atts=attributes.split("%|%");// the attributes can include two separators.  This one will get us the first element, which is used for the placement of the file.  The second element is then passed along to the processing page.
	    	$.post(page,{
				'ajaxrequest':'callfile_' + atts[0],
				'attributes':atts[1]
				},
				function(data){
					$('#'+ id).html(decodeString(data));// add the data to the div
				});

		});


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

            $.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(page,{
				'ajaxrequest':'gethelpcontent',
				'q':q
				},function(data){
					darray=data.split("::");
					$('#showHelp').html(darray[1]).dialog('option','title',darray[0]).dialog('open');
				}

			);

		});

		$('.updatescratchpad').live('click',function(){
			// this function updates the scratchpad note. the scratchpad requires three elements and an optional fourth. required: entrytype=148 is most cases, chartype=the name of the scratchpad, i.e., rfscratchpad, and the text to be updated. optional element is scratchpadmid, which is inttype in the db sitecodes where the notes are held
			// on 8/7/2011 added ability to send scratchpad notes via email reminders using the email class
			var attributes=$(this).attr('data');
			var scratchpadmid='';
			darray=attributes.split(":");
			var entrytype=darray[0];
			var chartype=darray[1];
			if(darray.length==3){scratchpadmid=darray[2];}
			var scratchpadtext=$('#' + chartype + 'text').val();
			var scratchpademail='';
			var scratchpadsubject='';
			var scratchpaddate='';
			
			// check to see if the remind me checkbox is checked, if so, get the email info
			if($('#' + chartype + 'remindme').is(':checked')){
				scratchpademail=$('#' + chartype + 'email').val();
				scratchpadsubject=$('#' + chartype + 'subject').val();
				scratchpaddate=$('#' + chartype + 'date').val();
			}
			
			$.post(page,{
				'ajaxrequest':'callapp_scratchpad/scratchpad_updatescratchpad',
				'entrytype':entrytype,
				'chartype':chartype,
				'scratchpadtext':scratchpadtext,
				'scratchpadmid':scratchpadmid,
				'scratchpademail':scratchpademail,
				'scratchpadsubject':scratchpadsubject,
				'scratchpaddate':scratchpaddate
				},
				function(data){
					$('#' + chartype + 'text').css({'border':'2px solid green'});
				}
			);
			
		});// end updatescratchpad
		
		$(".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('focus mousedown',function() {// 10/7/2011 this is used in link admin to sort links.
		$(".livesort").sortable(
			{
			
				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

	$('.highlight').live('mouseover',function(){
		$(this).addClass('highlight-hover');
	});

	$('.highlight-hover').live('mouseout',function(){
		$(this).removeClass('highlight-hover');
	});

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

	if($('.datepicker').hasClass('historic')){$(".datepicker" ).datepicker( "option", "yearRange", '-70:+2' );}

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

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

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

	// draggable
	$('.draggable').draggable({
		stack:'.bringtofront'
	});

	//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 subject=$(this).val();
		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});
		}
		$(this).val(subject);// added on 2011/02/22 to restore value typed in before load begins
	});


	$('.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);
});

	function showTime(timestring){
		var d=new Date(timestring);
		var hours=d.getHours();
		if(hours==0){
			hours=12;
			ampm="am";
		}
		else if(hours>12){
			hours=hours-12;
			ampm="pm";
		}
		else{
			ampm="am";
		}
		var minutes=d.getMinutes();
		if(minutes<10){minutes="0" + minutes;}
		thetime=hours + ":" + minutes  + " " + ampm;
		$('#serverclock').html(thetime);
	}

	$('body').delegate('.startserverclock','click',function(){
	$.post(page,{
	   'ajaxrequest':'callfile:get-server-time'
		},
		function(data){
			showTime(data);
	   });
	});



	if($('.customslideshow').is('.customslideshow')){
		function onAfter() {
			thealt=decodeString(this.alt);
			$('#customslidedescription').html(thealt);

			var slideid=$('.activeSlide').index();
			var containeroffset=$('#snavcontainer').offset();
					
			// get a count of how many slides
			var snavcount=$("#snav > a").size();
			var maxcount=snavcount-20;
			if(maxcount>0){
				if(slideid==snavcount-1){
					// this is the last slide, so reset the navigation
					$('#snav').offset({top:containeroffset.top,left:containeroffset.left});
				}
				else if(slideid>5){
					var offset=$('#snav').offset();
					var newleft=offset.left-20;
					$('#snav').offset({top:offset.top,left:newleft});
					$('#snavcontainer').offset({top:containeroffset.top,left:containeroffset.left});
				}
			}

		}	

		$('.customslideshow').fadeIn('slow').before("<div id='snavcontainer'><div id='snav'>").cycle({
			after:onAfter,
			fx: 'fade',
			randomizeEffects:1,
			autostop:0,
			pause:1,
			delay:0,
			pager:'#snav'

		});
	};

	$('.replaceelements').live('click',function(){
		var attributes=$(this).attr('data');
		alert('clicked');
		//updateElements(attributes);
	});// end replaceelement

	$('.showok').live('click',function(){
		var id=$(this).attr('id');
		if($('#' + id + 'ok').length>0){$('#' + id + 'ok').remove();}
	
	});
//	$('.ckeditor').ckeditor();
});

