function updateAccount(form)
{
     if (validateAccountForm(form)==false)
          return false;

	var newsletter = form.newsletter.checked == true ? 1 : 0;

     var url='modules.php?mod=account&req=update'+
               '&first='+encodeURIComponent(form.first.value)+
               '&last='+encodeURIComponent(form.last.value)+
               '&email='+encodeURIComponent(form.email.value)+
               '&addr1='+encodeURIComponent(form.addr1.value)+
               '&addr2='+encodeURIComponent(form.addr2.value)+
               '&city='+encodeURIComponent(form.city.value)+
               '&state='+encodeURIComponent(form.state.value)+
               '&zip='+encodeURIComponent(form.zip.value)+
               '&phone='+encodeURIComponent(form.phone.value)+
			'&newsletter='+encodeURIComponent(newsletter)+
               '&user_pass1='+encodeURIComponent(form.user_pass1.value);

	// add any volunteer check boxes.
	if (document.getElementById('norows'))
		{
		var norows = document.getElementById('norows').value;
		for (x = 0, i = 0; x < norows; x++)
			{
			if (document.getElementById('volunteer'+x).checked)
				{
				url = url + '&volid'+i+'='+document.getElementById('volunteer'+x).value;
				i++;
				}
			}
		url = url + '&novolrows='+i;
		}

     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=ajax&req=homepage');
     return false;
}



function validateAccountForm(form)
{    
     var error_message = "The following required fields are missing:";
     var errors=0;
// alert('validateAccountForm');

     var pass1=form.user_pass1.value;
     var pass2=form.user_pass2.value;     

// alert(pass1+','+pass2);

     if (isEmpty(form.first))
          {
          error_message = error_message + "\nFirst Name";
          errors=1;
          }
     if (isEmpty(form.last))
          {
          error_message = error_message + "\nLast Name";
          errors=1;
          }
     if (isEmpty(form.email))
          {
          error_message = error_message + "\nEmail";
          errors=1;
          }     
	 if (pass1.length > 0)
		{        
		if (pass1.length < 5 || pass2.length < 5)
			{
			error_message = error_message + "\nPassword must be minimum 5 characters.";
			errors=1;
			}
		if (pass1 != pass2)
			{
			error_message = error_message + "\nPassword entries do not match.";
			errors=1;
			}
         }           
     if (errors==0)
          return true;
     alert(error_message);
     return false;       
}
function validateClientRegistrationForm(form)
{
   var error_message = "The following errors occurred:";
   var errors=0;
   if (isEmpty(form.first))
          {
          error_message = error_message + "\n\tFirst name is missing";
          errors=1;
          }
   if (isEmpty(form.last))
          {
          error_message = error_message + "\n\tLast name is missing";
          errors=1;
          }  
     if (isEmpty(form.email))
          {
          error_message = error_message + "\n\tEmail is missing";
          errors=1;
          }
     else if (!validateEmail(form.email.value))
          {
          error_message = error_message + "\n\tEmail address is incorrectly formatted";
          errors=1;
          }

     else if ( ! checkEmailAddress(form.email.value))
          {
          error_message = error_message + "\n\tEmail address is already in use.";
          errors=1;
          }

  if (isEmpty(form.pass1))
          {
          error_message = error_message + "\n\tPassword 1 is missing";
          errors=1;
          }
     if (isEmpty(form.pass2))
          {
          error_message = error_message + "\n\tPassword 2 is missing";
          errors=1;
          }
     if (form.pass1.textLength < 5 || form.pass2.textLength < 5)
          {
          error_message = error_message + "\n\tPassword must be minimum 5 characters.";
          errors=1;
          } 
     if (form.pass1.value != form.pass2.value)
          {
          error_message = error_message + "\n\tPassword entries do not match.";
          errors=1;
          }   
     if (isEmpty(form.company))
          {
          error_message = error_message + "\n\tCompany is missing";
          errors=1;
          }  
     if (isEmpty(form.addr1))
          {
          error_message = error_message + "\n\tAddress 1 is missing";
          errors=1;
          }  
     if (isEmpty(form.city))
          {
          error_message = error_message + "\n\tCity is missing";
          errors=1;
          }  
     if (form.state.value == 0)
          {
          error_message = error_message + "\n\tState is missing";
          errors=1;
          }  
     if (isEmpty(form.zip))
          {
          error_message = error_message + "\n\tZip is missing";
          errors=1;
          }  
     if (isEmpty(form.phone))
          {
          error_message = error_message + "\n\tPhone is missing";
          errors=1;
          } 
	if (isEmpty(form.url))
          {
          error_message = error_message + "\n\tURL is missing";
          errors=1;
          }  

	  if ( ! checkURL(form.url.value))
          {
          error_message = error_message + "\n\tURL is already in use";
          errors=1;
          }
	  
     if ( ! validateCaptcha())
          {
          error_message = error_message + "\n\tThe CAPTCHA is incorrect.";
          errors=1;
          }
     
     if (errors==0) {
	  $('#submit_button_id').html("<img src='/images/busy.gif'>");
          return true;
	}

	document.getElementById('submit_registration').style.background = 'white';
     alert(error_message);
     return false;       
}

function validateClientData(form)
{
 
     var error_message = "The following errors occurred:";
     var errors=0;
  
     if (isEmpty(form.company))
          {
          error_message = error_message + "\n\tCompany is missing";
          errors=1;
          }  
     if (isEmpty(form.addr1))
          {
          error_message = error_message + "\n\tAddress 1 is missing";
          errors=1;
          }  
     if (isEmpty(form.city))
          {
          error_message = error_message + "\n\tCity is missing";
          errors=1;
          }  
     if (form.state.value == 0)
          {
          error_message = error_message + "\n\tState is missing";
          errors=1;
          }  
     if (isEmpty(form.zip))
          {
          error_message = error_message + "\n\tZip is missing";
          errors=1;
          }  
     if (isEmpty(form.phone))
          {
          error_message = error_message + "\n\tPhone is missing";
          errors=1;
          }  
	  
     if ( ! validateCaptcha())
          {
          error_message = error_message + "\n\tThe CAPTCHA is incorrect.";
          errors=1;
          }
    
     if (errors==0)
          return true;

	document.getElementById('submit_registration').style.background = 'white';
     alert(error_message);
     return false;       
}


function validateCaptcha() 
{
	var captcha = document.getElementById('captcha-form').value;
	var url = 'modules.php?mod=addsite&req=valcap'+
			'&captcha='+encodeURIComponent(captcha);
	var ret = serverFunction(url);
	return trim(ret) == '1' ? true : false;
}


function checkURL(url)
{
     // build the URL to call to check if user name is already in use.
     var url="modules.php?mod=addsite&req=checkurl&url="+encodeURIComponent(url);
     ret=serverFunction(url);
     return trim(ret) == '1' ? true : false;
}

function displayActors()
{
     var url='modules.php?mod=adminactors';
     displayText('maincontent',url);           
     return false;
}

function displayRoles(show)
{
     if (typeof show == 'undefined') show = 0;

     var url='modules.php?mod=adminactors&req=roles&show='+show;
     displayText('maincontent',url);           
     return false;
}

function displayReports()
{
     var url='modules.php?mod=adminactors&req=reports';
     displayText('maincontent',url);           
     return false;
}

function deleteRole(id)
{
     var show = document.getElementById('show').value;

     if (confirm("Are you sure you want to delete this record?"))
          {
          url='modules.php?mod=adminactors&req=deleterole&id='+id;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=adminactors&req=roles&show='+show);
          }
     return false;
}

function editRole(roleid)
{
     var url='modules.php?mod=adminactors&req=editrole&roleid='+roleid;

     displayText('maincontent',url);
     return false;
}

function auditionReport(show)
{
     var url='modules.php?mod=adminactors&req=showreport&show='+show+'&reporttype=audition';
     displayText('maincontent',url);           
     return false;
}

function emailActors(show)
{
     var email = document.getElementById('email_text').value;

     var url='modules.php?mod=adminactors&req=email&show='+show+'&email='+email;
     displayText('maincontent',url);           
     return false;
}

function castReport(show)
{
     var url='modules.php?mod=adminactors&req=showreport&show='+show+'&reporttype=cast';
     displayText('maincontent',url);           
     return false;
}

function setShowButtons()
{
    var show = document.getElementById('show').value;

    var url = 'modules.php?mod=adminactors&req=reports&show='+show;
    displayText('maincontent',url);
}

function setShow()
{
    var show = document.getElementById('show').value;

    var url = 'modules.php?mod=adminactors&req=roles&show='+show;
    displayText('maincontent',url);
}

function addRole(show)
{
    var url = 'modules.php?mod=adminactors&req=addrole&show='+show;
    displayText('maincontent',url);
}

function displayActorsPage(pageno)
{
     var age = document.getElementById('age_txt');
     var ageRange = document.getElementById('age_select');
     var ageCheck = (document.getElementById('age_chk').checked==true ? 1 : 0);
     var zipCheck = (document.getElementById('zip_chk').checked==true ? 1 : 0);
     var headCheck = (document.getElementById('head_chk').checked==true ? 1 : 0);
     var zip = document.getElementById('zip_txt');

     var url = 'modules.php?mod=adminactors&pageno='+pageno+'&age='+encodeURIComponent(age.value)+'&agerange='+encodeURIComponent(ageRange.value)+'&zip='+encodeURIComponent(zip.value)+
			'&headshot='+encodeURIComponent(headCheck)+'&agechk='+encodeURIComponent(ageCheck)+'&zipchk='+encodeURIComponent(zipCheck)+userFilterURL('members',0);
     displayText('maincontent',url);
} 

function addActor()
{
	// check for super user and count selected clients.
	// only allow an add if one client site is selected.
	if (document.getElementById('multiclients'))
		{
		var obj = document.getElementById('multiclients');
		for ( x = 0, i = 0; x <  obj.options.length; x++)
			{
			if (obj.options[x].selected)
				i++;
			}
		if (i != 1)
			{
			alert('You must have only one client selected to add a record.');
			return false;
			}
		}
	
     var url='modules.php?mod=adminactors&req=add';
     displayText('maincontent',url);           
     return false;
}

function updateRole()
{
     var form = document.getElementById('roleform');

     if (!validateRoleForm(form))
          return false;

     var cast = (form.cast.checked==true ? 1 : 0);
     var suspended = (form.suspended.checked==true ? 1 : 0);
     var email;
     if (form.actor.value > 0)
        email = (confirm('Do you want to notify the actor?')==true ? 1 : 0);
     else 
	email = 0;

     var url='modules.php?mod=adminactors&req=updaterole'+
		'&title='+encodeURIComponent(form.role.value)+
		'&description='+encodeURIComponent(form.desc.value)+
		'&gender='+encodeURIComponent(form.gender.value)+
		'&age='+encodeURIComponent(form.age.value)+
		'&start='+encodeURIComponent(form.start.value)+
		'&end='+encodeURIComponent(form.end.value)+
		'&cast='+encodeURIComponent(cast)+
		'&suspended='+encodeURIComponent(suspended)+
		'&actorid='+encodeURIComponent(form.actor.value)+
		'&email='+email+
		'&roleid='+encodeURIComponent(form.roleid.value);
     ret = serverFunction(url);
     //alert(ret);
     displayRoles(form.showid.value);
     return false;
}

function insertRole()
{
     var form = document.getElementById('roleform');

     if (!validateRoleForm(form))
          return false;

     var cast = (form.cast.checked==true ? 1 : 0);
     var suspended = (form.suspended.checked==true ? 1 : 0);

     var url='modules.php?mod=adminactors&req=insertrole'+
		'&title='+encodeURIComponent(form.role.value)+
		'&description='+encodeURIComponent(form.desc.value)+
		'&gender='+encodeURIComponent(form.gender.value)+
		'&age='+encodeURIComponent(form.age.value)+
		'&start='+encodeURIComponent(form.start.value)+
		'&end='+encodeURIComponent(form.end.value)+
		'&cast='+encodeURIComponent(cast)+
		'&suspended='+encodeURIComponent(suspended)+
		'&showid='+encodeURIComponent(form.showid.value);

     ret = serverFunction(url);
     //alert(ret);
     displayRoles(form.showid.value);
     return false;
}

function insertActor()
{
     var form = document.getElementById('userform');

     if (!validateActorForm(form))
          return false;
     if (!checkActorPassword(form))
	  return false;

     var share = (form.share_info.checked==true ? 1 : 0);

     var url='modules.php?mod=adminactors&req=insert'+
		'&first='+encodeURIComponent(form.first.value)+
		'&last='+encodeURIComponent(form.last.value)+
		'&passwd='+encodeURIComponent(form.pass1.value)+
		'&addr1='+encodeURIComponent(form.addr1.value)+
		'&addr2='+encodeURIComponent(form.addr2.value)+
		'&city='+encodeURIComponent(form.city.value)+
		'&state='+encodeURIComponent(form.state.value)+
		'&zip='+encodeURIComponent(form.zip.value)+
		'&phone='+encodeURIComponent(form.phone.value)+
		'&email='+encodeURIComponent(form.email.value)+
		'&userid='+encodeURIComponent(form.userid.value)+
			'&occupation='+encodeURIComponent(form.occupation.value)+
			'&emp_school='+encodeURIComponent(form.emp_school.value)+
			'&change='+encodeURIComponent(form.change.value)+
			'&height_inches='+encodeURIComponent(form.height_inches.value)+
			'&height_feet='+encodeURIComponent(form.height_feet.value)+
			'&weight='+encodeURIComponent(form.weight.value)+
			'&age_min='+encodeURIComponent(form.age_min.value)+
			'&age_max='+encodeURIComponent(form.age_max.value)+
			'&skills='+encodeURIComponent(form.skills.value)+
			'&cellphone='+encodeURIComponent(form.cellphone.value)+
			'&share_info='+encodeURIComponent(share);

     ret = serverFunction(url);
     //alert(ret);
     displayActors();
     return false;
}

function addActor(userid)
{
     var url='modules.php?mod=adminactors&req=add&userid='+userid;
     displayText('maincontent',url);           
     return false;
}
function editActor(userid)
{
     var url='modules.php?mod=adminactors&req=edit&userid='+userid;
     displayText('maincontent',url);           
     return false;
}

function updateActor()
{
     var form = document.getElementById('userform');
     if (!validateActorForm(form))
          return false;

     var share = (form.share_info.checked==true ? 1 : 0);

     var url='modules.php?mod=adminactors&req=update'+
		'&userid='+encodeURIComponent(form.userid.value)+
		'&first='+encodeURIComponent(form.first.value)+
		'&last='+encodeURIComponent(form.last.value)+
		'&addr1='+encodeURIComponent(form.addr1.value)+
		'&addr2='+encodeURIComponent(form.addr2.value)+
		'&city='+encodeURIComponent(form.city.value)+
		'&state='+encodeURIComponent(form.state.value)+
		'&zip='+encodeURIComponent(form.zip.value)+
		'&phone='+encodeURIComponent(form.phone.value)+
		'&email='+encodeURIComponent(form.email.value)+
			'&occupation='+encodeURIComponent(form.occupation.value)+
			'&emp_school='+encodeURIComponent(form.emp_school.value)+
			'&change='+encodeURIComponent(form.change.value)+
			'&height_inches='+encodeURIComponent(form.height_inches.value)+
			'&height_feet='+encodeURIComponent(form.height_feet.value)+
			'&weight='+encodeURIComponent(form.weight.value)+
			'&age_min='+encodeURIComponent(form.age_min.value)+
			'&age_max='+encodeURIComponent(form.age_max.value)+
			'&skills='+encodeURIComponent(form.skills.value)+
			'&cellphone='+encodeURIComponent(form.cellphone.value)+
			'&share_info='+encodeURIComponent(share);

     ret = serverFunction(url);
     //alert(ret);
     displayActors();
     return false;
}

function deleteActor(id)
{
     if (confirm("Are you sure you want to delete this record?"))
          {
          url='modules.php?mod=adminactors&req=delete&id='+id;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=adminactors');         
          }
     return false;
}

function setActorSearchFilter(filtertype)
{
     var age = document.getElementById('age_txt');
     var ageRange = document.getElementById('age_select');
     var ageCheck = (document.getElementById('age_chk').checked==true ? 1 : 0);
     var zipCheck = (document.getElementById('zip_chk').checked==true ? 1 : 0);
     var headCheck = (document.getElementById('head_chk').checked==true ? 1 : 0);
     var zip = document.getElementById('zip_txt');

     var url = 'modules.php?mod=adminactors&age='+encodeURIComponent(age.value)+'&agerange='+encodeURIComponent(ageRange.value)+'&zip='+encodeURIComponent(zip.value)+
			'&headshot='+encodeURIComponent(headCheck)+'&agechk='+encodeURIComponent(ageCheck)+'&zipchk='+encodeURIComponent(zipCheck)+userFilterURL('members',0);
	
     displayText('maincontent',url);

     var filter;
     switch(filtertype)
	{
     	case 'normal':
		filter = document.getElementById('userfilter');
		break;
	case 'age':
		filter = document.getElementById('age_txt');
		break;
	case 'zip':
		filter = document.getElementById('zip_txt');
		break;
	default:
	}

     filter.focus();

     // check for IE, extra code needed to keep focus on filter field.
      if (window.ActiveXObject) {
        var txtRange = filter.createTextRange();
        txtRange.moveStart( "character", filter.value.length);
        txtRange.moveEnd( "character", 0 );
        txtRange.select();
      }		
}

function checkActorPassword(form)
{
	var error_message = "The following required fields are missing:";
	var errors=0;

	if (isEmpty(form.pass1))
               {
               error_message = error_message + "\n\tPassword 1";
               errors=1;
               }
	if (isEmpty(form.pass2))
               {
               error_message = error_message + "\n\tPassword 2";
               errors=1;
               }
        if (form.pass1.textLength < 5 || form.pass2.textLength < 5)
               {
               error_message = error_message + "\n\tPassword must be minimum 5 characters.";
               errors=1;
               } 
        if (form.pass1.value != form.pass2.value)
               {
               error_message = error_message + "\n\tPassword entries do not match.";
               errors=1;
               }
	if (errors==0)
		return true;
	alert(error_message);
	return false;
}

function validateRoleForm(form)
{
     var error_message = "The following required fields are missing:";
     var errors=0;

     var startDate = new Date(form.start.value);
     var endDate = new Date(form.end.value);
	

          if (isEmpty(form.role))
          {
          error_message = error_message + "\n\tRole Title";
          errors=1;
          }
          if (isEmpty(form.desc))
          {
          error_message = error_message + "\n\tDescription";
          errors=1;
          }
	  if (isEmpty(form.start))
          {
          error_message = error_message + "\n\tStart Date";
          errors=1;
          }
	  if (isEmpty(form.end))
          {
          error_message = error_message + "\n\tEnd Date";
          errors=1;
          }
	  if (endDate < startDate)
          {
          error_message = error_message + "\n\tStart Date must be before End Date";
          errors=1;
          }

     if (errors==0)
          return true;
     alert(error_message);
     return false;       
}
function listBlogPosts()
{
	var url = 'modules.php?mod=adminblogs';
	displayText('maincontent',url);
}

function addBlogPost()
{
	var url = 'modules.php?mod=adminblogs&req=add';
	displayText('maincontent',url);
}

function insertBlogPost()
{	
	var form = document.getElementById('blog_form');
     if (!validateBlogForm(form))
          return false;
	var image = document.getElementById('image_upload_filename').value;
	var sticky = form.sticky.value == 'on' ? 1 : 0;
	var url = 'modules.php?mod=adminblogs&req=insert'+
			'&image='+encodeURIComponent(image)+
			'&title='+encodeURIComponent(form.title.value)+
			'&leadin='+encodeURIComponent(form.leadin.value)+
			'&body='+encodeURIComponent(form.body.value)+
			'&sticky='+encodeURIComponent(sticky);
alert('url:'+url);

     ret=serverFunction(url);
alert('ret:'+ret);
     displayText('maincontent','modules.php?mod=adminblogs');         
     return false;
}

function deleteBlogPost(id)
{
	if (confirm('Sure you want to delete this post?'))
		{
		var url = 'modules.php?mod=adminblogs&req=delete&id='+id;
		ret = serverFunction(url);
		}
	listBlogPosts();
}

function deleteBlogPostPhoto(id)
{
     if (confirm('Are you sure you want to remove the photo?'))
          {
          var url='modules.php?mod=adminblogs&req=deletephoto&id='+id;
          ret=serverFunction(url);
          document.getElementById('postimage').src='images/noimage.jpg';
          }
     return false;
}

function editBlogPost(id)
{
	var url = 'modules.php?mod=adminblogs&req=edit&id='+id;
	displayText('maincontent',url);
}

function updateBlogPost()
{
	var form = document.getElementById('blog_form');
     if (!validateBlogForm(form))
          return false;

	var image = document.getElementById('image_upload_filename').value;
	var sticky = form.sticky.checked == true ? 1 : 0;
	var url = 'modules.php?mod=adminblogs&req=update'+
			'&postid='+encodeURIComponent(form.postid.value)+
			'&image='+encodeURIComponent(image)+
			'&title='+encodeURIComponent(form.title.value)+
			'&leadin='+encodeURIComponent(form.leadin.value)+
			'&body='+encodeURIComponent(form.body.value)+
			'&sticky='+encodeURIComponent(sticky);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminblogs');         
     return false;
}

function loadBlogConfig()
{
	var url = 'modules.php?mod=adminblogs&req=config';
	displayText('maincontent',url);
}

function saveBlogConfig()
{
	var form = document.getElementById('blog_config_form');
	if (isEmpty(form.title))
		{
		alert('You must supply a title for your blog.');
		return false;
		}
	var allowcomments		= (form.allowcomments.checked==true) ? 1:0;
	var moderatecomments	= (form.moderatecomments.checked==true) ? 1:0;
	var commentnotify		= (form.commentnotify.checked==true) ? 1:0;

	var url = 'modules.php?mod=adminblogs&req=save'+
			'&title='+encodeURIComponent(form.title.value)+
			'&allow_comments='+encodeURIComponent(allowcomments)+
			'&moderate_comments='+encodeURIComponent(moderatecomments)+
			'&comment_notification='+encodeURIComponent(+commentnotify);
	serverFunction(url);
	listBlogPosts();
}

function listBlogPostComents(id)
{
	var url = 'modules.php?mod=adminblogs&req=listcomments&id='+id;
	displayText('maincontent',url);
}

function setBlogCommentStatus(cid,pid)
{
	var url = 'modules.php?mod=adminblogs&req=setcommentstatus'+
			'&cid='+cid+
			'&pid='+pid;
	ret = serverFunction(url);

	var obj = document.getElementById('commentstatus'+cid);
	if (ret.indexOf('1') != -1)
		obj.checked = true;
	else
		obj.checked = false;

	return false;
}

function deleteBlogComment(cid,pid)
{
	if (confirm('Are you sure you want to delete this comment?'))
		{
		var url = 'modules.php?mod=adminblogs&req=deletecomment&id='+cid;
		serverFunction(url);
		listBlogPostComents(pid);
		}
	return false;
}

function validateBlogForm(form)
{
    var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.title))
          {
          error_message = error_message + "\t\nTitle is missing.";
          errors=1;
          }
     if (isEmpty(form.leadin))
          {
          error_message = error_message + "\t\nLead in is missing.";
          errors=1;
          }	
     if (errors==0)
          return true;
     alert(error_message);
     return false; 
}

function displayAllCalendarEvents()
{
     var url='modules.php?mod=admincalendar';
     displayText('maincontent',url);               
     return false; 
}

function addEvent()
{
     var url='modules.php?mod=admincalendar&req=addevent';
     displayText('maincontent',url);               
     return false; 
}

function insertEvent(form)
{
     if (!validateEventForm(form))
          return false;
     var url='modules.php?mod=admincalendar&req=insertevent'+ 
				'&group='+encodeURIComponent(form.group.value)+
                    '&event='+encodeURIComponent(form.event.value)+
                    '&startdate='+encodeURIComponent(form.start_date.value)+
                    '&enddate='+encodeURIComponent(form.end_date.value)+
                    '&starttime='+encodeURIComponent(form.starttime.value)+
                    '&endtime='+encodeURIComponent(form.endtime.value)+
                    '&location='+encodeURIComponent(form.location.value)+
				'&reg_start='+encodeURIComponent(form.reg_start.value)+
				'&reg_stop='+encodeURIComponent(form.reg_stop.value)+
				'&linktext='+encodeURIComponent(form.linktext.value)+
				'&linkurl='+encodeURIComponent(form.linkurl.value)+
                    '&description='+encodeURIComponent(form.description.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=admincalendar');         
     callCalendar();
     return false;
}

function editEvent(eventid)
{
     var url='modules.php?mod=admincalendar&req=editevent&eventid='+eventid;
     displayText('maincontent',url);                
     return false;      
}

function updateEvent(form)
{
     if (!validateEventForm(form))
          return false;
     var url='modules.php?mod=admincalendar&req=updateevent'+
				'&group='+encodeURIComponent(form.group.value)+
                    '&eventid='+encodeURIComponent(form.eventid.value)+                    
                    '&event='+encodeURIComponent(form.event.value)+
                    '&startdate='+encodeURIComponent(form.start_date.value)+
                    '&enddate='+encodeURIComponent(form.end_date.value)+
                    '&starttime='+encodeURIComponent(form.starttime.value)+
                    '&endtime='+encodeURIComponent(form.endtime.value)+
                    '&location='+encodeURIComponent(form.location.value)+
				'&reg_start='+encodeURIComponent(form.reg_start.value)+
				'&reg_stop='+encodeURIComponent(form.reg_stop.value)+
				'&linktext='+encodeURIComponent(form.linktext.value)+
				'&linkurl='+encodeURIComponent(form.linkurl.value)+
                    '&description='+encodeURIComponent(form.description.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=admincalendar');        
     callCalendar();
     return false;
}

function deleteEvent(eventid)
{
     if (confirm("Are you sure you want to delete this event?"))
          {
          var url='modules.php?mod=admincalendar&req=deleteevent&eventid='+eventid;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=admincalendar'); 
          callCalendar();   
          }
     return false; 
}

function listEventRegistrations(id,pageno)
{
	var url = 'modules.php?mod=admincalendar&req=registrations'+
			'&id='+id+
			'&pageno='+pageno;
	displayText('maincontent',url);
	return false;
}

function deleteEventRegistragion(id,pageno,eventid)
{
     if (confirm("Are you sure you want to delete this registration?"))
          {
          var url='modules.php?mod=admincalendar&req=deleteregistration&id='+id;
          ret=serverFunction(url);
		if (pageno > 0)
			pageno = pageno - 1;
		listEventRegistrations(eventid,pageno);
          }
     return false; 
}

function maintainRegistrationFees(id)
{
	var url = 'modules.php?mod=admincalendar&req=regfees&id='+id;
	displayText('maincontent',url);
	return false;
}

function insertCalendarFeeDate(id)
{
	var form = document.getElementById('feedateform');
	if (! validateFeeDateForm(form))
		return false;

	var includemembership = document.getElementById('includemembership').checked == true ? 1 : 0;
	var url = 'modules.php?mod=admincalendar&req=insertfeedate'+
		'&eventid='+encodeURIComponent(id)+
		'&whn='+encodeURIComponent(form.whn.value)+
		'&memberfee='+encodeURIComponent(form.memberfee.value)+
		'&nonmemberfee='+encodeURIComponent(form.nonmemberfee.value)+
		'&includemembership='+encodeURIComponent(includemembership)+
		'&membershiplevel='+encodeURIComponent(form.membershiplevel.value);
	ret = serverFunction(url);
	maintainRegistrationFees(id);
	return false;
}

function deleteCalendarFeeDate(id,eid)
{
	if (confirm('Sure you want to delete this fee date?'))
		{
		var url = 'modules.php?mod=admincalendar&req=deletefeedate&id='+id;
		ret = serverFunction(url);
		maintainRegistrationFees(eid);
		}
	return false;
}

function validateFeeDateForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.whn))
          {
          error_message = error_message + "\t\nDate is missing.";
          errors=1;
          }
     if (isEmpty(form.memberfee))
          {
          error_message = error_message + "\t\nMember fee is missing.";
          errors=1;
          }

     if (errors==0)
          return true;
     alert(error_message);
     return false; 
}

function validateEventForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.event))
          {
          error_message = error_message + "\t\nEvent name is missing.";
          errors=1;
          }
     if (isEmpty(form.start_date))
          {
          error_message = error_message + "\t\nStart date is missing.";
          errors=1;
          }
     if (isEmpty(form.end_date))
          {
          error_message = error_message + "\t\nEnd date is missing.";
          errors=1;
          }
     if (isEmpty(form.starttime))
          {
          error_message = error_message + "\t\nStart time is missing.";
          errors=1;
          }
     if (isEmpty(form.endtime))
          {
          error_message = error_message + "\t\nEnd time is missing.";
          errors=1;
          }
	if ( ! isEmpty(form.reg_start) && isEmpty(form.reg_stop))
          {
          error_message = error_message + "\t\nYou must supply both registration start and stop dates.";
          errors=1;
          }
     if (isEmpty(form.location))
          {
          error_message = error_message + "\t\nLocation is missing.";
          errors=1;
          }
     if (isEmpty(form.description))
          {
          error_message = error_message + "\t\nDescription is missing.";
          errors=1;
          }
     if (form.group.value == 0)
          {
          error_message = error_message + "\t\nYou must select a group.";
          errors=1;
          }
     if (errors==0)
          return true;
     alert(error_message);
     return false; 
}

function autoTab(thefield, nextfield)
{
	if (thefield.value.length == 2)
		nextfield.focus();
}
function listClasses()
{
     var url='modules.php?mod=adminclasses';
     displayText('maincontent',url);           
     return false;
}

function addClass()
{
     var url='modules.php?mod=adminclasses&req=addclass';
     displayText('maincontent',url);           
     return false;
}

function insertClass()
{
	var form = document.getElementById('classform');
	if (!validateClassForm(form))
		return false;
	
	var regoff = form.regoff.checked == true ? '1' : '0';

	var url = 'modules.php?mod=adminclasses&req=insertclass'+
			'&classname='+encodeURIComponent(form.classname.value)+
			'&maxstudents='+encodeURIComponent(form.maxstudents.value)+
			'&start_date='+encodeURIComponent(form.start_date.value)+
			'&end_date='+encodeURIComponent(form.end_date.value)+
			'&start_reg_date='+encodeURIComponent(form.start_reg_date.value)+
			'&end_reg_date='+encodeURIComponent(form.end_reg_date.value)+
			'&schedule='+encodeURIComponent(form.schedule.value)+
			'&description='+encodeURIComponent(form.description.value)+
			'&price='+encodeURIComponent(form.price.value)+
			'&regoff='+regoff;
	ret = serverFunction(url);
     url='modules.php?mod=adminclasses';
     displayText('maincontent',url);   	
}

function editClass(id)
{
     var url='modules.php?mod=adminclasses&req=editclass&id='+id;
     displayText('maincontent',url);           
     return false;
}

function updateClass()
{
	var form = document.getElementById('classform');
	if (!validateClassForm(form))
		return false;
	
	var regoff = form.regoff.checked == true ? '1' : '0';

	var url = 'modules.php?mod=adminclasses&req=updateclass'+
			'&classid='+encodeURIComponent(form.classid.value)+
			'&classname='+encodeURIComponent(form.classname.value)+
			'&maxstudents='+encodeURIComponent(form.maxstudents.value)+
			'&start_date='+encodeURIComponent(form.start_date.value)+
			'&end_date='+encodeURIComponent(form.end_date.value)+
			'&start_reg_date='+encodeURIComponent(form.start_reg_date.value)+
			'&end_reg_date='+encodeURIComponent(form.end_reg_date.value)+
			'&schedule='+encodeURIComponent(form.schedule.value)+
			'&description='+encodeURIComponent(form.description.value)+
			'&price='+encodeURIComponent(form.price.value)+
			'&regoff='+regoff;
	ret = serverFunction(url);
     url='modules.php?mod=adminclasses';
     displayText('maincontent',url);   	
}

function classConfiguration()
{
     var url='modules.php?mod=adminclasses&req=config';
     displayText('maincontent',url);           
     return false;
}

function updateClassConfiguration()
{
	var form = document.getElementById('configform');
     var url = 'modules.php?mod=adminclasses&req=updateconfig'+
			'&welcome='+encodeURIComponent(form.welcome.value);
	ret = serverFunction(url);
     url='modules.php?mod=adminclasses';
     displayText('maincontent',url);  
}

function maintainClassDates(id)
{
	var url = 'modules.php?mod=adminclasses&req=classdates&id='+id;
	displayText('maincontent',url);
}

function insertClassDate()
{
	var form = document.getElementById('classdateform');
	if (form.classdate.value == '')
		{
		alert('You must select a class date.');
		return false;
		}
	var classid = form.classid.value;
	var classdate = form.classdate.value;
	var start_time = form.start_hour.value+':'+form.start_minute.value;
	var end_time = form.end_hour.value+':'+form.end_minute.value;
	var start_ampm = (form.start_ampm[0].checked == true) ? 'AM' : 'PM';
	var end_ampm = (form.end_ampm[0].checked == true) ? 'AM' : 'PM';
	var url = 'modules.php?mod=adminclasses&req=insertclassdate'+
			'&classid='+encodeURIComponent(classid)+
			'&date='+encodeURIComponent(classdate)+
			'&starttime='+encodeURIComponent(start_time)+
			'&startampm='+encodeURIComponent(start_ampm)+
			'&endtime='+encodeURIComponent(end_time)+
			'&endampm='+encodeURIComponent(end_ampm);
alert(url);
	ret = serverFunction(url);
alert(ret);
     maintainClassDates(classid);
	return false;
}

function validateClassForm(form)
{
	if 	(form.classname.value == '' ||
		form.start_date.value == '' ||
		form.end_date.value == '' ||
		form.start_reg_date.value == '' ||
		form.end_reg_date.value == '' ||
		form.schedule.value == '' ||
		form.description.value == '' ||
          form.price.value == '')
		{
		alert('All fields are required.');
		return false;
		}
	return true;
}function clientsDefaultDisplay()
{
     var url = 'modules.php?mod=adminclients';
     displayText('maincontent',url);
}

function displayClientsPage(pageno)
{
	var filter = document.getElementById('clientfilter').value;
     url='modules.php?mod=adminclients&pageno='+pageno+'&filter='+encodeURIComponent(filter);
     displayText('maincontent',url);
} 

function setClientSearchFilter(filter)
{
     var url = 'modules.php?mod=adminclients&filter='+encodeURIComponent(filter);
     displayText('maincontent',url);
     var filter = document.getElementById('clientfilter');
     filter.focus();

      if (window.ActiveXObject) {
        var txtRange = filter.createTextRange();
        txtRange.moveStart( "character", filter.value.length);
        txtRange.moveEnd( "character", 0 );
        txtRange.select();
      }		
}

function deleteClient(id)
{
     if (id==1)
          {
          alert('YOU CANNOT DELETE PENGUINSITES.NET');
          return;
          }
     if (confirm("Are you sure you want to delete this client?\n\nIF YOU SAY YES, THE CLIENT WILL BE REMOVED PERMANENTLY.\n"))
          {
          var url = 'modules.php?mod=adminclients&req=delete&id='+id;
          ret = serverFunction(url);
          clientsDefaultDisplay();         
          }
     return false;
}

function switchClientSite(id,server)
{
     if (confirm('Click Okay to load client site.'))
          {
          var url='modules.php?mod=adminclients&req=switch&id='+id;
          var url = trim(serverFunction(url));
          window.location = "http://"+url+"/";
          }
}function displayContacts()
{
     var url='modules.php?mod=admincontacts';
     displayText('maincontent',url);           
     return false;
}

function addContact()
{
     var url='modules.php?mod=admincontacts&req=add';
     displayText('maincontent',url); 
     return false;
}

function insertContact()
{
     var form = document.getElementById('add_edit_contact_form');
     if (!validateContactForm(form))
          return false;
     
     var url='modules.php?mod=admincontacts&req=insert'+               
               '&first='+encodeURIComponent(form.first.value)+
               '&last='+encodeURIComponent(form.last.value)+
               '&title='+encodeURIComponent(form.title.value)+
               '&email='+encodeURIComponent(form.email.value)+
               '&phone='+encodeURIComponent(form.phone.value);

     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=admincontacts');   
	contacts();
     return false;
}

function editContact(id,name)
{	       
	var url='modules.php?mod=admincontacts&req=edit&id='+id;
	displayText('maincontent',url);           
	return false;
}

function updateContact()
{	
	 var form = document.getElementById('add_edit_contact_form');

         if (!validateContactForm(form))
         return false;

	 if (!validateContactForm(form))
          return false;

     var url='modules.php?mod=admincontacts&req=update'+
               '&contactid='+encodeURIComponent(form.contactid.value)+               
               '&first='+encodeURIComponent(form.first.value)+
               '&last='+encodeURIComponent(form.last.value)+
               '&title='+encodeURIComponent(form.title.value)+
               '&email='+encodeURIComponent(form.email.value)+
               '&phone='+encodeURIComponent(form.phone.value);

     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=admincontacts');    
     contacts();
     return false;
}

function deleteContact(id,name)
{
     if (confirm('Are you sure you want to delete '+name))
          {
          var url='modules.php?mod=admincontacts&req=delete&id='+id;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=admincontacts');
          contacts();              
          }
     return false;
}

function moveContactPosition(thisrec,newpos,otherrec,otherpos)
{
     var url='modules.php?mod=admincontacts&req=movecontact'+
                         '&rec1='+thisrec+
                         '&pos1='+newpos+
                         '&rec2='+otherrec+
                         '&pos2='+otherpos;
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=admincontacts'); 
     contacts();    
}


function validateContactForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;

     if (isEmpty(form.first))
          {
          error_message = error_message + "\t\nFirst name is missing";
          errors=1;
          }
     if (isEmpty(form.last))
          {
          error_message = error_message + "\t\nLast name is missing";
          errors=1;
          }
     if (isEmpty(form.title))
          {
          error_message = error_message + "\t\nTitle is missing";
          errors=1;
          }
     if  (isEmpty(form.email))
          {
          error_message = error_message + "\t\nEmail is missing";
          errors=1;
          }


     if (errors==0)
          return true;
     alert(error_message);
     return false;    
}function displayDocuments()
{
     var url = 'modules.php?mod=admindocuments';
     displayText('maincontent',url);
}

function addDocument()
{
     var url = 'modules.php?mod=admindocuments&req=add';
     displayText('maincontent',url);
}


function insertDocument()
{
     var form = document.getElementById('documentform');
     var docname = document.getElementById('myfile').value;

     if (docname =='')
          {
          alert('You must upload a file.');
          return false;
          }

     if ( ! validateDocumentForm(form))
          return false;

     var url = 'modules.php?mod=admindocuments&req=insert'+
               '&docname='+encodeURIComponent(docname)+
               '&category='+encodeURIComponent(form.category.value)+
               '&title='+encodeURIComponent(form.title.value)+
               '&summary='+encodeURIComponent(form.summary.value);

     ret = serverFunction(url);
     var url = 'modules.php?mod=admindocuments';
     displayText('maincontent',url);
     return false;
}

function editDocument(docid)
{
     var url = 'modules.php?mod=admindocuments&req=edit&id='+docid;
     displayText('maincontent',url);
}

function updateDocument()
{
     var form = document.getElementById('documentform');
     if ( ! validateDocumentForm(form,'0'))
          return false;

     var docname = document.getElementById('myfile').value;

     var url = 'modules.php?mod=admindocuments&req=update'+
               '&docid='+encodeURIComponent(form.docid.value)+
               '&category='+encodeURIComponent(form.category.value)+  
               '&title='+encodeURIComponent(form.title.value)+
               '&summary='+encodeURIComponent(form.summary.value)+
               '&filename='+encodeURIComponent(docname);
     ret = serverFunction(url);
     var url = 'modules.php?mod=admindocuments';
     displayText('maincontent',url);
}


function deleteDocument(docid)
{
     if (confirm('Are you sure you want to delete this document?'))
          {
          var url = 'modules.php?mod=admindocuments&req=delete&id='+docid;
          serverFunction(url);
          var url = 'modules.php?mod=admindocuments';
          displayText('maincontent',url);
          }
     return false;
}

function stopDocumentUpload(success,path,tmp)
{
      if (success == 1){
         alert('Your file has been uploaded.');
      }
      else {
         alert("Your file upload resulted in error.\nPlease contact Big Sky Penguin.");
      }
}


function validateDocumentForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (form.category.value == 0)
          {
          error_message = error_message + "\t\nYou must select a category";
          errors=1;
          }
     if (isEmpty(form.title))
          {
          error_message = error_message + "\t\nTitle is missing";
          errors=1;
          }
     if (isEmpty(form.summary))
          {
          error_message = error_message + "\t\nSummary is missing";
          errors=1;
          }
     if (errors==0)
          return true;
     alert(error_message);
     return false; 
}

function displayDocumentCategories()
{
     displayText('maincontent','modules.php?mod=admindocuments&req=categories');
}

function insertDocumentCategory(form)
{
     if (!validateDocumentCategoryForm(form))
          return false;

     var url='modules.php?mod=admindocuments&req=insertcat'+
             '&category='+encodeURIComponent(form.category.value)+
             '&group='+encodeURIComponent(form.group.value)+
             '&summary='+encodeURIComponent(form.summary.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=admindocuments&req=categories');
}

function editDocumentCategory(catid)
{
     var formid=document.getElementById('news_category_form');
     formid.onsubmit=function() {
          return updateDocumentCategory(this);
     }
     var catid_field=document.getElementById('catid_field');
     catid_field.value=catid;
     
     var cat_field = document.getElementById('category');
     var sum_field = document.getElementById('summary');
     var url='modules.php?mod=admindocuments&req=editcategory&catid='+catid;
     ret = serverFunction(url);

	// return comes back as:
	// category value|summary value^group1 ID| group1 name|groupN ID|groupN name...
     var parts = ret.split('^');
	var fields = parts[0].split('|');
	
     // for some reason the cat name is coming through with a left padded space.
     // the trim function was places in functions.js.
     cat_field.value=leftTrim(fields[0]);   
     sum_field.value=leftTrim(fields[1]);

	// insert the values into the drop down selecting the current one for the category.
	var pieces = parts[1].split('|');
	var form = document.getElementById('news_category_form');
	form.group.options.length = null;
	for (i = 1,x = 0; x < (pieces.length - 2)/2; i=i+2,x++)
		{
		form.group.options[x] = new Option(pieces[i],pieces[i+1]);
		
		// check if current option is the selected one for this cat. if so set to selected.');
		if (rightTrim(pieces[i+1]) == pieces[0])
			form.group.selectedIndex = x;
		}
}

function updateDocumentCategory(form)
{
     if (!validateDocumentCategoryForm(form))
          return false;
     var url='modules.php?mod=admindocuments&req=updatecat'+
                    '&catid='+encodeURIComponent(form.catid.value)+
				'&group='+encodeURIComponent(form.group.value)+
                    '&category='+encodeURIComponent(form.category.value)+
                    '&summary='+encodeURIComponent(form.summary.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=admindocuments&req=categories');
     return false;
}

function deleteDocumentCategory(catid)
{
     if (confirm("Are you sure you want to delete this\ncategory and all documents in it?"))
          {
          var url='modules.php?mod=admindocuments&req=deletecat&catid='+catid;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=admindocuments&req=categories');
          }
     return false;
}

function validateDocumentCategoryForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.category))
          {
          error_message = error_message + "\t\nCategory is missing";
          errors=1;
          }
     if (form.group.value == 0)
          {
          error_message = error_message + "\t\nYou must select a group";
          errors=1;
          }
     if (isEmpty(form.summary))
          {
          error_message = error_message + "\t\nSummary is missing";
          errors=1;
          }
     if (errors==0)
          return true;
     alert(error_message);
     return false; 
}

function documentCategoryExportImport()
{
     var url = 'modules.php?mod=admindocuments&req=exportimport';
     displayText('maincontent',url);
}

function documentsCategoryImportExport()
{
	var url='modules.php?mod=admindocuments&req=importexport';
	displayText('maincontent',url);
	return false;
}

function documentsCategoryExportAdd(catid)
{
	if (catid == 0)
		return false;

	var url = 'modules.php?mod=admindocuments&req=exportcatadd&catid='+catid;
	var content = serverFunction(url);
	if (content.indexOf('***exported***') != -1)
		alert('Category already exported.');
	else
		document.getElementById('exported_categories').innerHTML = content;
}

function documentsCategoryExportDelete(expid)
{
	var url = 'modules.php?mod=admindocuments&req=exportcatdelete&expid='+expid;
	var content = serverFunction(url);
	document.getElementById('exported_categories').innerHTML = content;
}

function documentsCategoryImportAdd(catid)
{
	if (catid == 0)
		return false;

	var url = 'modules.php?mod=admindocuments&req=importcatadd&catid='+catid;
	var content = serverFunction(url);
	if (content.indexOf('***imported***') != -1)
		alert('Category already imported.');
	else
		document.getElementById('imported_categories').innerHTML = content;
}

function documentsCategoryImportDelete(impid)
{
	var url = 'modules.php?mod=admindocuments&req=importcatdelete&impid='+impid;
	var content = serverFunction(url);
	document.getElementById('imported_categories').innerHTML = content;
}




function displayDonationsConfig()
{
	var url = 'modules.php?mod=admindonations&req=display';
	displayText('maincontent',url);
}

function saveDonationsConfiguration()
{
	var form = document.getElementById('donations_config_form');
	if (! validateDonationsConfigurationForm(form))
		return false;
	var url = 'modules.php?mod=admindonations&req=update'+
			'&configid='+encodeURIComponent(form.configid.value)+
			'&amounts='+encodeURIComponent(form.amounts.value)+
			'&amount_desc='+encodeURIComponent(form.amount_desc.value)+
			'&default_amount='+encodeURIComponent(form.default_amount.value)+
			'&other_enable='+encodeURIComponent(((form.other_enable.checked == true) ? 1 : 0))+
			'&other_min_amount='+encodeURIComponent(form.other_min_amount.value)+
			'&headline='+encodeURIComponent(form.headline.value)+
			'&body='+encodeURIComponent(form.body.value)+
			'&taxno='+encodeURIComponent(form.taxno.value)+
			'&bank_fields='+encodeURIComponent(((form.bank_fields.checked == true) ? 1 : 0));
	ret = serverFunction(url);

	var url = 'modules.php?mod=admindonations';
	displayText('maincontent',url);
}

function displayDonations()
{
	var url = 'modules.php?mod=admindonations&req=displaydonations';
	displayText('maincontent',url);
}

function displayDonationsReport()
{
 	var start = document.getElementById('start').value;
	var end = document.getElementById('end').value;
	var category = document.getElementById('category').value;
     if (start == '' || end == '')
		{
		alert('You must supply both start and end dates.');
		return false;
		}

	var url = 'modules.php?mod=admindonations&req=displaydonations'+
			'&start='+encodeURIComponent(start)+
			'&end='+encodeURIComponent(end)+
			'&catid='+encodeURIComponent(category);
	displayText('maincontent',url);
}

function displayDonationsCategories()
{
	var url = 'modules.php?mod=admindonations&req=categories';
	displayText('maincontent',url);
}

function insertDonationCategory()
{
	var category = document.getElementById('category').value;
	if (category == '')
		return false;

	var url = 'modules.php?mod=admindonations&req=insertcat&category='+category;
	ret = serverFunction(url);
	displayDonationsCategories();
}

function deleteDonationCategory(catid)
{
	if (confirm('Sure you want to delete this category?'))
		{
		var url = 'modules.php?mod=admindonations&req=deletecat&catid='+catid;
		serverFunction(url);
		displayDonationsCategories();
		}
}

function createDonationsPDFReport()
{
	alert("The PDF report is not yet implemented.\nIt will be completed soon.");
	return false;
}

function validateDonationsConfigurationForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;

     if (isEmpty(form.amounts))
          {
          error_message = error_message + "\t\nNo amounts supplied";
          errors=1;
          }
     if (isEmpty(form.default_amount))
          {
          error_message = error_message + "\t\nNo default amount supplied";
          errors=1;
          }
     if (form.other_enable.checked == true  && isEmpty(form.other_min_amount))
          {
          error_message = error_message + "\t\nIf other amount enabled you must supply minimum amount";
          errors=1;
          }
     if (isEmpty(form.headline))
          {
          error_message = error_message + "\t\nNo headline supplied";
          errors=1;
          }
     if (isEmpty(form.body))
          {
          error_message = error_message + "\t\nNo body text supplied";
          errors=1;
          }
     if (errors==0)
          return true;
     alert(error_message);
     return false;    
}function defaultAlertsDisplay()
{
     var url='modules.php?mod=adminemailalerts';
     displayText('maincontent',url);
}

function sendAndInsertAlert()
{
     var form = document.getElementById('adminalertsform');
     if (!adminValidateAlertForm(form))
          return false;

          var url='modules.php';
		var args = 'mod=adminemailalerts&req=sendalert'+
                    '&subscribers='+encodeURIComponent(form.subscribers.checked)+
				'&newsletter='+encodeURIComponent(form.newsletter.checked)+
				'&htmlformat='+encodeURIComponent(form.htmlformat.checked)+
				'&broadcast='+encodeURIComponent(form.broadcast.value)+
                    '&group='+encodeURIComponent(form.group.value)+
				'&replytoemail='+encodeURIComponent(form.replytoemail.value)+
                    '&subject='+encodeURIComponent(form.subject.value)+
				'&attachment='+encodeURIComponent(form.attachment.value)+
                    '&alert='+encodeURIComponent(form.alert.value);

	ret = serverFunctionPOST(url,args);
	document.getElementById('maincontent').innerHTML = ret;

     return false;
}

function previewEmailAlertMessage()
{
	var htmlformat = document.getElementById('htmlformat');
     if (htmlformat.checked == false)
	  {
	  alert('You must check HTML formatting to preview your message.');
	  return false;
	  }
     var msg = document.getElementById('alert').value;
     var url='modules.php?mod=adminemailalerts'+     
	        '&req=previewalert'+
	        '&alert='+encodeURIComponent(msg);
     window.open(url,'win','left=40,top=40,width=600,height=400,menubar=1,resizable=1,scrollbars=1');
     return false;
}

function deleteCustomBroadcastList()
{
	var obj = document.getElementById('broadcast');
	if (obj.value == 0)
		{
		alert('You must select a list to delete.');
		return false;
		}
	if (! confirm('Are you sure you want to delete this list?'))
		return false;

	var url = 'modules.php?mod=adminemailalerts&req=deletebroadcastlist&id='+obj.value;
	ret = trim(serverFunction(url));
	// insert the values into the drop down selecting the current one for the category.
	var pieces = ret.split('|');
	obj.length = null;
	obj.options[0] = new Option('Select...',0);

	// check for an empty return.
	if (ret != '')
		{
		for (i = 0,x = 1; x < (pieces.length/2)+1; i=i+2,x++)
			obj.options[x] = new Option(pieces[i+1],pieces[i]);
		}
	obj.selectedIndex = 0;
	return false;
}

function adminValidateAlertForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;

    if (form.group.value == 0 && form.subscribers.checked == false && form.broadcast.value == 0 && form.newsletter.checked == false)
          {
          error_message = error_message + "\t\nYou must select at least a group, subscribers, newsletters or a custom list";
          errors=1;
          }
     if (isEmpty(form.replytoemail))
          {
          error_message = error_message + "\t\nThe reply to email is missing";
          errors=1;
          }
     if (isEmpty(form.subject))
          {
          error_message = error_message + "\t\nThe subject is missing";
          errors=1;
          }
     if (isEmpty(form.alert))
          {
          error_message = error_message + "\t\nThe alert text is missing";
          errors=1;
          }

     if (errors==0)
          return true;
     alert(error_message);
     return false;    
}


function listFamilies()
{
	var url = 'modules.php?mod=adminfamilies';
	displayText('maincontent',url);
}

function addFamily()
{
	var url = 'modules.php?mod=adminfamilies&req=add';
	displayText('maincontent',url);
}

function insertFamily()
{
	var family = document.getElementById('family').value;
	var url = 'modules.php?mod=adminfamilies'+
			'&req=insert'+
			'&family='+encodeURIComponent(family);
	displayText('maincontent',url);
}

function deleteFamily(id)
{
	if (confirm('Are you sure you want to delete this family?'))
		{
		var url = 'modules.php?mod=adminfamilies&req=delete&id='+id;
		serverFunction(url);
		listFamilies();
		}
}

function listFamilyMembers(id)
{
	var url = 'modules.php?mod=adminfamilies&req=members&id='+id;
	displayText('maincontent',url);
}

function addFamilyMember(familyid)
{
	var id = document.getElementById('new_member').value;
	var url = 'modules.php?mod=adminfamilies'+
			'&req=insertmember'+
			'&clientid='+id+
			'&familyid='+familyid;
	ret = serverFunction(url);
	listFamilyMembers(familyid);
	return false;
}

function deleteFamilyMember(clientid,familyid)
{
	if (confirm('Are you sure you want to delete this family member?'))
		{
		var url = 'modules.php?mod=adminfamilies&req=deletemember'+
				'&familyid='+familyid+
				'&clientid='+clientid;
		serverFunction(url);
		listFamilyMembers(familyid);	
		}
}/************ SOON TO BE REMOVED **************/
// these two functions will be removed when the new forms are implemented.

function selectForm(id)
{
     if (id==0)
          {
          document.getElementById('form_fields').innerHTML = '';
          return false;
          }

     var url = 'modules.php?mod=adminforms&req=load&id='+id;
     displayText('form_fields',url);
     return false;
}

function selectFieldType(ftype)
{
     return false;
}


function listForms()
{
     var url = 'modules.php?mod=adminforms';
     displayText('maincontent',url);
     return false;
}

function loadForm(id)
{
     var url = 'modules.php?mod=adminforms&req=load&id='+id;
     displayText('maincontent',url);
     return false;
}

function selectFieldType(ftype)
{
     return false;
}

function processFormField(req,fno)
{
     // req is set to either insert or update to determine server side operation.
     var fieldid = document.getElementById('fieldid'+fno).value;
     var fname = document.getElementById('fname'+fno).value;
     var ftype = document.getElementById('ftype'+fno).value;
     var fdefault = document.getElementById('default'+fno).value;
     var orderno = document.getElementById('orderno'+fno).value;
     var formid = document.getElementById('formid').value;
     if (fname == '' || ftype == 0)
          {
          alert('You must provide a field name and type.');
          return false;
          }
     if (ftype == '3' && fdefault == '')
          {
          alert('You must provide options separated by commas for a drop down.');
          return false;
          }

     var url = 'modules.php?mod=adminforms&req='+req+
               '&fieldid='+encodeURIComponent(fieldid)+
               '&fname='+encodeURIComponent(fname)+
               '&ftype='+encodeURIComponent(ftype)+
               '&fdefault='+encodeURIComponent(fdefault)+
               '&orderno='+encodeURIComponent(orderno)+
               '&formid='+encodeURIComponent(formid);

     ret = serverFunction(url);
     if (req == 'update')
          alert('Field '+fname+' has been updated.');

     displayText('maincontent','modules.php?mod=adminforms&req=load&id='+formid);     
     return false;
}

function deleteFormField(fid,formid)
{
     if ( confirm("Are you sure you want to delete this field?\n\nALL DATA IN THIS FIELD WILL BE DELETED.\n\n"))
          {
          var url = 'modules.php?mod=adminforms&req=delete&id='+fid;
          ret = serverFunction(url);
          displayText('maincontent','modules.php?mod=adminforms&req=load&id='+formid); 
          }
     return false;
}

function addForm()
{
     var url = 'modules.php?mod=adminforms&req=addform';
     displayText('maincontent',url);
     return false;
}

function insertForm()
{
	var formname = document.getElementById('formname').value;
	var parentid = document.getElementById('parent').value;
	if (formname == '')
		{
		alert('You must supply a name for the form.');
		return false
		}
	var url = 'modules.php?mod=adminforms&req=insertform'+
			'&formname='+encodeURIComponent(formname)+
			'&parentid='+encodeURIComponent(parentid);
	ret = serverFunction(url);
	listForms();
}

function editForm(id)
{
     var url = 'modules.php?mod=adminforms&req=editform&id='+id;
     displayText('maincontent',url);
     return false;
}

function updateForm()
{
	var formid = document.getElementById('formid').value;
	var formname = document.getElementById('formname').value;
	var parentid = document.getElementById('parent').value;
	if (formname == '')
		{
		alert('You must supply a name for the form.');
		return false
		}
	var url = 'modules.php?mod=adminforms&req=updateform'+
			'&formid='+encodeURIComponent(formid)+
			'&formname='+encodeURIComponent(formname)+
			'&parentid='+encodeURIComponent(parentid);
	ret = serverFunction(url);
	listForms();
}

function deleteForm(id)
{
	if (confirm('Are you sure you want to delete this form?'))
		{
		var url = 'modules.php?mod=adminforms&req=deleteform&id='+id;
		ret = serverFunction(url);
alert(ret);
		var url = 'modules.php?mod=adminforms';
		displayText('maincontent',url);
		}
	return false;
}

function listFormData(id,pageno)
{
     var url = 'modules.php?mod=adminforms&req=listformdata'+
			'&id='+id+
			'&pageno='+pageno;
     displayText('maincontent',url);
     return false;
}

function displayFormData(id,recid)
{
	var url = 'modules.php?mod=adminforms&req=displayform'+
			'&id='+id+
			'&recid='+recid;
     displayText('maincontent',url);
     return false;
}

function submitFormData(formid,recid,nextrecid)
{
	var form = document.getElementById('form_fields');

	// will return false if all fields are empty. if this is the case do not update the record.
	var fields_and_values = formFieldValues(form);
	if (fields_and_values != false)
		{
		var url = 'modules.php?mod=adminforms&req=updaterecord'+fields_and_values;
		var ret = serverFunction(url);
		}
 	else
		// nextrecid=1;
		return false;

	url = 'modules.php?mod=adminforms&req=displayform'+
		 '&id='+formid+
		 '&recid='+nextrecid;
	displayText('maincontent',url);
	return false;
}

function formFieldValues(form)
{
	// if all the fields are empty, this will stay false and be returned to that
	// the record will not be updated, resulting in an empty record being inserted.
	var fields_have_data = false;

     var nofields = form.custom_field_count.value;
     if (nofields == 0)
          return '&nocustomfields=0';

     var x;	
     var url = '&nocustomfields='+nofields;
	var recid = form.recid.value;
	url = url + '&recid='+recid;
     url = url + '&formid='+form.formid.value;
     for (x = 0; x < nofields; x++)
          {
		// check for data in the field.
		if (document.getElementById('field'+x).value!='')
			fields_have_data = true;

          var ftype = document.getElementById('field'+x).type;
          switch (ftype)
               {
               case 'text':
               case 'select-one':
               case 'textarea':
                    url = url + '&fieldid'+x+'='+encodeURIComponent(document.getElementById('fieldid'+x).value);
                    url = url + '&field'+x+'='+encodeURIComponent(document.getElementById('field'+x).value);
                    break;
               case 'checkbox':
                    url = url + '&fieldid'+x+'='+encodeURIComponent(document.getElementById('fieldid'+x).value);
                    if (document.getElementById('field'+x).checked == true)
                         url = url + '&field'+x+'=1';
                    else
                         url = url + '&field'+x+'=0';
                    break;
               }
          }
	if (fields_have_data)
		return url;
	else
		return false;
}


function loadForumsConfiguration()
{
     var url='modules.php?mod=adminforums&req=config';
     displayText('forumsmain',url);
}

function updateForumsConfiguration(form)
{
     var nonmember_posts=form.nonmember_posts.checked==true ? 1:0;
     var url='modules.php?mod=adminforums&req=updateconfig'+
          '&board_name='+form.board_name.value+
          '&posts_per_page='+form.posts_per_page.value+
          '&posts_per_thread='+form.posts_per_thread.value+
          '&nonmember_posts='+nonmember_posts;
     ret=serverFunction(url);
     loadForumsLinks();
}

function loadForumsLinks()
{     
     url='modules.php?mod=adminforums&req=loadlinks';
     displayText('forumsmain',url);
}

function loadForumsAdmin()
{
     var url='modules.php?mod=adminforums&req=forums';
     displayText('forumsmain',url);
}

function addForumAdmin()
{
     var url='modules.php?mod=adminforums&req=addforum';
     displayText('forumsmain',url);
}

function insertForumAdmin(form)
{
     orderno=form.orderno.value;
     forum=form.forum.value;
     groupid=form.groupid.value;
     archived=form.archived.checked;
     if (form.allow[0].checked)
          allow=1;
     else
          allow=0;
     var url='modules.php?mod=adminforums&req=insertforum&orderno='
                                   +orderno+'&forum='+forum+'&groupid='+groupid+'&allow='+allow+'&archived='+archived;
     serverFunction(url);
     loadForumsAdmin();
}

function deleteForumsAdmin(form)
{
     var recs='';
     for (x=0; x < form.del.length; x++)
          {
          if (form.del[x].checked==true)
               {
               if (recs=='')
                    recs=form.recno[x].value;
               else
                    recs+=','+form.recno[x].value;
               }
          }

     if (recs=='')
          {
          alert('No forums chosen for deletion.');
          return false;
          }
               
     url='modules.php?mod=adminforums&req=delete&recs='+recs;
     ret=serverFunction(url);
     loadForumsAdmin();
}

function editForumAdmin(forumid)
{
     url='modules.php?mod=adminforums&req=edit&forumid='+forumid;
     displayText('forumsmain',url);  
}

function updateForumAdmin(form)
{
     forumid=form.forumid.value;
     orderno=form.orderno.value;
     forum=form.forum.value;
     groupid=form.groupid.value;
     archived=form.archived.checked;
     if (form.allow[0].checked)
          allow=1;
     else
          allow=0;
     var url='modules.php?mod=adminforums&req=updateforum&forumid='+forumid+'&orderno='
                          +orderno+'&forum='+forum+'&groupid='+groupid+'&allow='+allow+'&archived='+archived;
     ret=serverFunction(url);
     loadForumsAdmin();
}

function loadThreadsAdmin(forumid)
{
     var url='modules.php?mod=adminforums&req=threads&forumid='+forumid;
     displayText('forumsmain',url);
}

function addThreadAdmin(forumid)
{
     var url='modules.php?mod=adminforums&req=addthread&forumid='+forumid;
     displayText('forumsmain',url);
}

function insertThreadAdmin(form)
{
     orderno=form.orderno.value;
     body=form.body.value;
     subject=form.subject.value;
     groupid=form.groupid.value;
     forumid=form.forumid.value;
     archived=form.archived.checked;
     allow=form.allow[0].checked;
     var url='modules.php?mod=adminforums&req=insertthread&orderno='
           +orderno+'&body='+body+'&subject='+subject+'&forumid='+forumid+'&groupid='+groupid+'&allow='+allow+'&archived='+archived;
     ret=serverFunction(url);
     loadThreadsAdmin(forumid);
}

function editThreadAdmin(threadid)
{
     url='modules.php?mod=adminforums&req=editthread&threadid='+threadid;
     displayText('forumsmain',url);  
}

function updateThreadAdmin(form)
{
     threadid=form.threadid.value;
     forumid=form.forumid.value;
     orderno=form.orderno.value;
     body=form.body.value;
     subject=form.subject.value;
     groupid=form.groupid.value;
     archived=form.archived.checked;
     if (form.allow[0].checked)
          allow=1;
     else
          allow=0;
     var url='modules.php?mod=adminforums&req=updatethread&forumid='+forumid+'&threadid='+threadid+'&orderno='+orderno+'&body='+body+'&subject='+subject+'&groupid='+groupid+'&allow='+allow+'&archived='+archived;
     ret=serverFunction(url);
     loadThreadsAdmin(forumid);
}

function deleteThreadsAdmin(form)
{
     var recs='';
     for (x=0; x < form.del.length; x++)
          {
          if (form.del[x].checked==true)
               {
               if (recs=='')
                    recs=form.recno[x].value;
               else
                    recs+=','+form.recno[x].value;
               }
          }
     if (recs=='')
          {
          alert('No threads chosen for deletion.');
          return false;
          }               
     url='modules.php?mod=adminforums&req=deletethreads&recs='+recs;
     ret=serverFunction(url);
     loadThreadsAdmin(form.forumid.value);
}

function loadPostsAdmin(threadid)
{
     alert('loadPostsAdmin:'+threadid);
     var url='modules.php?mod=adminforums&req=posts&threadid='+threadid;
     displayText('forumsmain',url);
}

function updateHomePages(form)
{
     var norecs=form.homepage.length;
     var url='modules.php?mod=adminhome&req=update&norecs='+norecs;
     for (x=0; x < form.homepage.length; x++)
          {
          url+='&recno'+x+'='+form.recno[x].value+'&homepage'+x+'='+form.homepage[x].value;
          }
     ret=serverFunction(url);
     alert('Home pages have been upated');
     return false;
}function updateHomePage(form)
{
     var object=document.getElementById('up1');
     var filename=object.value;

     if (validateHomePageForm(form)==false)
          return false;
     var url='modules.php?mod=adminhomepage&req=update'+
               '&headline='+form.headline.value+
               '&image='+filename+
               '&body='+encodeURIComponent(form.body.value);

     ret=serverFunction(url);
     alert('Your home page information has been updated.');
     return false;
}

function homeBottomLeft()
{
     displayText('maincontent','modules.php?mod=adminhomepage&req=bottomleft');
}

function insertBottomLeft(form)
{
     var url='modules.php?mod=adminhomepage&req=insertbottomleft'+
               '&position='+form.position.value+
               '&summary='+escape(form.summary.value)+
               '&url='+form.url.value+
               '&urltext='+form.urltext.value;

     serverFunction(url);
     displayText('maincontent','modules.php?mod=adminhomepage&req=bottomleft');
}

function deleteBottomLeft(id)
{
     if (confirm('Are you sure you want to delete this post?'))
          {
          var url='modules.php?mod=adminhomepage&req=deletebottomleft&id='+id;
          serverFunction(url);
          displayText('maincontent','modules.php?mod=adminhomepage&req=bottomleft');
          }
}

function editBottomLeft(id)
{
     displayText('maincontent','modules.php?mod=adminhomepage&req=editbottomleft&id='+id);
}

function updateBottomLeft(form)
{
     var url='modules.php?mod=adminhomepage&req=updatebottomleft'+
                    '&id='+form.id.value+
                    '&position='+form.position.value+
                    '&summary='+escape(form.summary.value)+
                    '&url='+form.url.value+
                    '&urltext='+form.urltext.value;    
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminhomepage&req=bottomleft');
}


function validateHomePageForm(form)
{    
     var error_message = "The following required fields are missing:";
     var errors=0;
     if (isEmpty(form.headline))
          {
          error_message = error_message + "\nHeadline";
          errors=1;
          }
     if (isEmpty(form.body))
          {
          error_message = error_message + "\nHome page body text";
          errors=1;
          }
  
     if (errors==0)
          return true;
     alert(error_message);
     return false;       
}

function displayImages()
{
     var url = 'modules.php?mod=adminimages';
     displayText('maincontent',url);
}

function addImage()
{
     var url = 'modules.php?mod=adminimages&req=add';
     displayText('maincontent',url);
}


function insertImage()
{
     var form = document.getElementById('imageform');
     var imgname = document.getElementById('image_upload_filename').value;
     if (imgname =='')
          {
          alert('You must upload an image.');
          return false;
          }
     if ( ! validateImageForm(form))
          return false;
     var url = 'modules.php?mod=adminimages&req=insert'+
               '&imgname='+encodeURIComponent(imgname)+
               '&description='+encodeURIComponent(form.description.value);
     ret = serverFunction(url);
     var url = 'modules.php?mod=adminimages';
     displayText('maincontent',url);
     return false;
}

function editImage(imgid)
{
     var url = 'modules.php?mod=adminimages&req=edit&id='+imgid;
     displayText('maincontent',url);
}

function updateImage()
{
     var form = document.getElementById('imageform');
     if ( ! validateImageForm(form))
          return false;

     var imgname = document.getElementById('image_upload_filename').value;

     var url = 'modules.php?mod=adminimages&req=update'+
               '&imgid='+encodeURIComponent(form.imgid.value)+               
               '&imgname='+encodeURIComponent(imgname)+
               '&description='+encodeURIComponent(form.description.value);

     ret = serverFunction(url);

     var url = 'modules.php?mod=adminimages';
     displayText('maincontent',url);
}


function deleteImage(imgid)
{
     if (confirm('Are you sure you want to delete this image?'))
          {
          var url = 'modules.php?mod=adminimages&req=delete&id='+imgid;
          serverFunction(url);
          var url = 'modules.php?mod=adminimages';
          displayText('maincontent',url);
          }
     return false;
}

function image_upload_post()
{
     var str = "Your image has been uploaded to the server.\n\n"+
               "Be sure the description\nis filled in and then click Submit.";
     alert(str);
     return false;
}

function validateImageForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.description))
          {
          error_message = error_message + "\t\nDescription is missing";
          errors=1;
          }
     if (errors==0)
          return true;
     alert(error_message);
     return false;
}
function listInvCategories(storeid)
{
	if (storeid == undefined)
		storeid = 0;
	var url = 'modules.php?mod=admininventory&req=invcats&storeid='+storeid;
	displayText('maincontent',url);
}

function populateInvCategories(storeid)
{

	var obj = document.getElementById('select_category');
	obj.options.length = null;
	var url = 'modules.php?mod=admininventory&req=echocats&storeid='+storeid;
	ret = serverFunction(url);		
	var pieces = ret.split('|');
	for (i = 0,x = 0; x <= (pieces.length/2)-1; i=i+2,x++)
		{
		obj.options[x] = new Option(pieces[i+1],pieces[i]);
		}

	// also populate the size/color field because user is a super user.
	var obj = document.getElementById('size');
	obj.options.length = null;
	var url = 'modules.php?mod=admininventory&req=echosizes&storeid='+storeid;
	ret = serverFunction(url);		
	var pieces = ret.split('|');
	for (i = 0,x = 0; x <= (pieces.length/2)-1; i=i+2,x++)
		{
		obj.options[x] = new Option(pieces[i+1],pieces[i]);
		}

	var obj = document.getElementById('color');
	obj.options.length = null;
	var url = 'modules.php?mod=admininventory&req=echocolors&storeid='+storeid;
	ret = serverFunction(url);	
	var pieces = ret.split('|');
	for (i = 0,x = 0; x <= (pieces.length/2)-1; i=i+2,x++)
		{
		obj.options[x] = new Option(pieces[i+1],pieces[i]);
		}		

 	return false;
}

function addInvCategory()
{
	var url = 'modules.php?mod=admininventory&req=addinvcat';
	displayText('maincontent',url);
}

function insertInvCategory()
{
	var form = document.getElementById('invcatform');

	if (form.category.value == '')
		{
		alert('You must supply a category.');
		return false;
		}

	// storeID will come from either drop down (super user logged in) or hidden value from regular store admin.
	if (document.getElementById('store'))
		var storeid = form.store.value;
	else
		var storeid = form.storeid.value;
	var image = document.getElementById('image_upload_filename').value;
	var url = 'modules.php?mod=admininventory&req=insertinvcat'+
			'&storeid='+encodeURIComponent(storeid)+
			'&pid='+encodeURIComponent(form.pid.value)+
			'&category='+encodeURIComponent(form.category.value)+
			'&description='+encodeURIComponent(form.description.value)+			
			'&image='+encodeURIComponent(image);
	ret = serverFunction(url);
	listInvCategories(storeid);
}

function editInvCategory(catid,storeid)
{
	var url = 'modules.php?mod=admininventory&req=editinvcat'+
			'&catid='+encodeURIComponent(catid)+
			'&storeid='+encodeURIComponent(storeid);
	displayText('maincontent',url);
}

function updateInvCategory()
{
	var form = document.getElementById('invcatform');

	if (form.category.value == '')
		{
		alert('You must supply a category.');
		return false;
		}

	// storeID will come from either drop down (super user logged in) or hidden value from regular store admin.
	if (document.getElementById('store'))
		var storeid = form.store.value;
	else
		var storeid = form.storeid.value;

	var image = document.getElementById('image_upload_filename').value;
	var url = 'modules.php?mod=admininventory&req=updateinvcat'+
			'&catid='+encodeURIComponent(form.catid.value)+
			'&pid='+encodeURIComponent(form.pid.value)+
			'&storeid='+encodeURIComponent(storeid)+
			'&category='+encodeURIComponent(form.category.value)+
			'&description='+encodeURIComponent(form.description.value)+			
			'&image='+encodeURIComponent(image);
	ret = serverFunction(url);
	listInvCategories(storeid);
}

function deleteInvCatPhoto(id)
{
     if (confirm('Are you sure you want to remove the photo?'))
          {
          var url='modules.php?mod=admininventory&req=deletecatphoto&id='+id;
          ret=serverFunction(url);
          document.getElementById('imagesrc').src='images/noimage.jpg';
          }
     return false;
}

function deleteInvCategory(catid,storeid)
{
	if (confirm("Are you sure you want to delete this category?\n\nAll items in this category will be deleted as well."))
		{
		var url = 'modules.php?mod=admininventory&req=deleteinvcat&catid='+catid;
		serverFunction(url);
		listInvCategories(storeid);
		}
	return false;
}

function listInventorySizes(storeid)
{
	if (storeid == undefined)
		storeid = 0;
	var url = 'modules.php?mod=admininventory&req=sizes&storeid='+storeid;
	displayText('maincontent',url);
}

function insertInvSize()
{
	if (document.getElementById('store'))
		{
		var storeid = document.getElementById('store').value;
 		if (storeid == 0)
			{
			alert('You must select a store.');
			return false;
			}
		}
	else
		storeid = 0;

	var size = document.getElementById('size').value;
	if (size == '')
		{
		alert('You must supply a size.');
		return false;
		}

	var url = 'modules.php?mod=admininventory&req=insertsize'+
			'&storeid='+storeid+
			'&size='+size;
	ret = serverFunction(url);
	listInventorySizes(storeid);
}

function editInvSize(sizeid,storeid)
{
 	var url = 'modules.php?mod=admininventory&req=getinvsize&sizeid='+sizeid;
	ret = serverFunction(url);
	document.getElementById('size').value = trim(ret);
     document.getElementById('sizeid').value = sizeid;
     document.getElementById('addsize').value = 'Update Size';
     document.getElementById('addsize').onclick = function() { updateInvSize(); };
}

function updateInvSize()
{
	// restore default form behavior.
     document.getElementById('addsize').value = 'Add Size';
     document.getElementById('addsize').onclick = function() { insertInvSize(); };

	var size = document.getElementById('size').value;
     var sizeid = document.getElementById('sizeid').value;
 	var url = 'modules.php?mod=admininventory&req=updateinvsize'+
			'&sizeid='+encodeURIComponent(sizeid)+
			'&size='+encodeURIComponent(size);
     ret = serverFunction(url);
	var storeid = document.getElementById('store').value;
	listInventorySizes(storeid);	
}

function deleteInvSize(sizeid,storeid)
{
	if ( confirm('Are you sure you want to delete this size?'))
		{
		var url = 'modules.php?mod=admininventory&req=deletesize&sizeid='+sizeid;
		serverFunction(url);
		listInventorySizes(storeid);
		}
	return false;
}

function listInvItems(catid)
{
	var url = 'modules.php?mod=admininventory';
	url = url + (catid != 0 ? '&catid='+catid : '');
	displayText('maincontent',url);
}

function addInvItem()
{
	var url = 'modules.php?mod=admininventory&req=addinvitem';
	displayText('maincontent',url);
}

function insertInvItem()
{
	var form = document.getElementById('invitemform');
	var image = document.getElementById('image_upload_filename').value;
	if (!validateInvItemForm(form))
		return false;
	var allowbackorders = (form.backorders.checked == true) ? '1' : '0';
	var use_percent = (form.use_percent.checked == true) ? '1' : '0';
	var url = 'modules.php?mod=admininventory&req=insertinvitem'+
			'&catid='+encodeURIComponent(form.category.value)+
			'&partno='+encodeURIComponent(form.partno.value)+
			'&name='+encodeURIComponent(form.item.value)+
			'&description='+encodeURIComponent(form.description.value)+
			'&size='+encodeURIComponent(form.size.value)+
			'&color='+encodeURIComponent(form.color.value)+
			'&price='+encodeURIComponent(form.price.value)+
			'&notes='+encodeURIComponent(form.notes.value)+
			'&allowbackorders='+encodeURIComponent(allowbackorders)+
			'&nobackorders='+encodeURIComponent(form.nobackorders.value)+
			'&shipping='+encodeURIComponent(form.shipping.value)+
			'&rush='+encodeURIComponent(form.rush.value)+
			'&use_percent='+encodeURIComponent(use_percent)+
			'&image='+image;
	var ret = serverFunction(url);
     listInvItems(form.category.value);
	return false;
}

function editInvItem(id)
{
	var url = 'modules.php?mod=admininventory&req=editinvitem&id='+id;
	displayText('maincontent',url);
}

function updateInvItem()
{
	var form = document.getElementById('invitemform');
	var image = document.getElementById('image_upload_filename').value;
	if (!validateInvItemForm(form))
		return false;
	var allowbackorders = (form.backorders.checked == true) ? '1' : '0';
	var use_percent = (form.use_percent.checked == true) ? '1' : '0';
	var url = 'modules.php?mod=admininventory&req=updateinvitem'+
			'&itemid='+encodeURIComponent(form.itemid.value)+
			'&catid='+encodeURIComponent(form.category.value)+
			'&partno='+encodeURIComponent(form.partno.value)+
			'&name='+encodeURIComponent(form.item.value)+
			'&description='+encodeURIComponent(form.description.value)+
			'&size='+encodeURIComponent(form.size.value)+
			'&color='+encodeURIComponent(form.color.value)+
			'&price='+encodeURIComponent(form.price.value)+
			'&notes='+encodeURIComponent(form.notes.value)+
			'&allowbackorders='+encodeURIComponent(allowbackorders)+
			'&nobackorders='+encodeURIComponent(form.nobackorders.value)+
			'&shipping='+encodeURIComponent(form.shipping.value)+
			'&rush='+encodeURIComponent(form.rush.value)+
			'&use_percent='+encodeURIComponent(use_percent)+
			'&image='+image;
	var ret = serverFunction(url);
     listInvItems(form.category.value);
	return false;
}

function deleteInvItem(id,catid)
{
	if (confirm('Delete this item?'))
		{
		var url = 'modules.php?mod=admininventory&req=deleteinvitem&id='+id;
		var ret = serverFunction(url);
		listInvItems(catid);
		}
}

function deleteInvItemPhoto(id)
{
     if (confirm('Are you sure you want to remove the photo?'))
          {
          var url='modules.php?mod=admininventory&req=deleteitemphoto&id='+id;
          ret=serverFunction(url);
          document.getElementById('itemimage').src='images/noimage.jpg';
          }
     return false;
}

function listInventoryColors(storeid)
{
	if (storeid == undefined)
		storeid = 0;
	var url = 'modules.php?mod=admininventory&req=colors&storeid='+storeid;
	displayText('maincontent',url);
}

function insertInvColor()
{
	if (document.getElementById('store'))
		{
		var storeid = document.getElementById('store').value;
 		if (storeid == 0)
			{
			alert('You must select a store.');
			return false;
			}
		}
	else
		storeid = 0;       

	var color = document.getElementById('color').value;
	if (color == '')
		{
		alert('You must supply a color.');
		return false;
		}

	var url = 'modules.php?mod=admininventory&req=insertcolor'+
			'&storeid='+storeid+
			'&colors='+color;
	ret = serverFunction(url);
	listInventoryColors(storeid);
}

function editInvColor(colorid,storeid)
{
 	var url = 'modules.php?mod=admininventory&req=getinvcolor&colorid='+colorid;
	ret = serverFunction(url);
	document.getElementById('color').value = trim(ret);
     document.getElementById('colorid').value = colorid;
     document.getElementById('addcolor').value = 'Update Color';
     document.getElementById('addcolor').onclick = function() { updateInvColor(); };
}


function updateInvColor()
{
	// restore default form behavior.
     document.getElementById('addcolor').value = 'Add Color';
     document.getElementById('addcolor').onclick = function() { insertInvColor(); };

	var color = document.getElementById('color').value;
     var colorid = document.getElementById('colorid').value;
 	var url = 'modules.php?mod=admininventory&req=updateinvcolor'+
			'&colorid='+encodeURIComponent(colorid)+
			'&colors='+encodeURIComponent(color);
     ret = serverFunction(url);
	var storeid = document.getElementById('store').value;
	listInventoryColors(storeid);	
}

function deleteInvColor(colorid,storeid)
{
	if ( confirm('Are you sure you want to delete this color?'))
		{
		var url = 'modules.php?mod=admininventory&req=deletecolor&colorid='+colorid;
		serverFunction(url);
		listInventoryColors(storeid);
		}
	return false;
}

function inventoryConfiguration()
{
	var url = 'modules.php?mod=admininventory&req=config';
 	displayText('maincontent',url);
}

function updateInventoryConfiguration()
{



}

function validateInvItemForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
	if (form.catid == 0)
          {
          error_message = error_message + "\n\tYou must select a category";
          errors=1;
          }
	if (isEmpty(form.partno))
          {
          error_message = error_message + "\n\tPart number is missing";
          errors=1;
          }
	if (isEmpty(form.item))
          {
          error_message = error_message + "\n\tName is missing";
          errors=1;
          }
	if (isEmpty(form.description))
          {
          error_message = error_message + "\n\tDescription is missing";
          errors=1;
          }	if (isEmpty(form.price))
          {
          error_message = error_message + "\n\tPrice is missing";
          errors=1;
          }
     if (errors==0)
          return true;
     alert(error_message);
     return false;     
}	




function defaultLinksDisplay()
{
     var url='modules.php?mod=adminlinks';
     displayText('maincontent',url);
}

function addLink()
{
     var url='modules.php?mod=adminlinks&req=addlink';
     displayText('maincontent',url);           
     return false;
}

function insertLink(form)
{
     var form=document.getElementById('admin_links_form');
     if (!validateLinkForm(form))
          return false;

     var url='modules.php?mod=adminlinks&req=insertlink'+
               '&summary='+encodeURIComponent(form.summary.value)+ 
               '&url='+encodeURIComponent(form.url.value)+ 
               '&urltext='+encodeURIComponent(form.urltext.value);
               

     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminlinks');
     return false;
}

function editLink(linkid)
{
     var url='modules.php?mod=adminlinks&req=editlink&id='+linkid;
     displayText('maincontent',url);             
     return false;
}

function updateLink()
{
     var form=document.getElementById('admin_links_form');
     if (!validateLinkForm(form))
          return false;

     var url='modules.php?mod=adminlinks&req=updatelink'+
               '&id='+encodeURIComponent(form.linkid.value)+
               '&summary='+encodeURIComponent(form.summary.value)+
               '&url='+encodeURIComponent(form.url.value)+ 
               '&urltext='+encodeURIComponent(form.urltext.value);          
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminlinks&id='+form.linkid.value);    
     return false;
}

function deleteLink(linkid,urltext)
{
     if (confirm('Are you sure you want to delete '+urltext))
          {
          var url='modules.php?mod=adminlinks&req=deletelink&linkid='+linkid;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=adminlinks');    
          }
     return false;
}


function validateLinkForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.url))
          {
          error_message = error_message + "\t\nThe URL is missing";
          errors=1;
          }
     if (isEmpty(form.urltext))
          {
          error_message = error_message + "\t\nThe URL text is missing";
          errors=1;
          }
     if (isEmpty(form.summary))
          {
          error_message = error_message + "\t\nThe summary text is missing";
          errors=1;
          }

     if (errors==0)
          return true;
     alert(error_message);
     return false;    
}function displayMenuItems()
{
     var url = 'modules.php?mod=adminmainmenu';
     displayText('maincontent',url);           
     return false;
}

function insertMenuItem()
{
	var item = document.getElementById('newitem').value;
	var group = document.getElementById('group').value;
	if (item == '' || group == 0)
		{
		alert('You must supply both an item title and a group.');
		return false;
		}
	var url = 'modules.php?mod=adminmainmenu&req=insertmenuitem'+
			'&group='+encodeURIComponent(group)+
			'&item='+encodeURIComponent(item);
	ret = serverFunction(url);
	displayMenuItems();
}

function editMenuItemName(id)
{
     var url = 'modules.php?mod=adminmainmenu&req=editmenuitem&id='+id;
     displayText('maincontent',url);           
     return false;
}

function updateMenuItem()
{
	var item = document.getElementById('menuitem').value;
	var id = document.getElementById('itemid').value;
	if (item == '')
		{
		alert('You cannot save a blank item.');
		return false;
		}
	var url = 'modules.php?mod=adminmainmenu&req=updatemenuitem'+
			'&id='+encodeURIComponent(id)+
			'&item='+encodeURIComponent(item);
	ret = serverFunction(url);
	displayMenuItems();
	mainmenu();
}	

function deleteMenuItem(id)
{
	if (confirm('Are you sure you want to delete this menu item?'))
		{
		var url = 'modules.php?mod=adminmainmenu&req=deletemenuitem&id='+id;
		ret = serverFunction(url);
		displayMenuItems();
		mainmenu();          
		}
     return false;
}

function moveMenuItemPosition(thisrec,newpos,otherrec,otherpos)
{
     var url = 'modules.php?mod=adminmainmenu&req=movemenuitem'+
                         '&rec1='+thisrec+
                         '&pos1='+newpos+
                         '&rec2='+otherrec+
                         '&pos2='+otherpos;
     ret=serverFunction(url);
	displayMenuItems();
	mainmenu();
}

function toggleMenuItemHide(id)
{
	var url='modules.php?mod=adminmainmenu&req=togglehide&id='+id;
     ret=serverFunction(url);
	displayMenuItems();
	mainmenu();
}function addManualTopic()
{
     var url='modules.php?mod=adminmanual&req=addtopic';
     displayText('popup_space',url);           
     $('popup_space').show(); 
     return false;
}

function editManualTopic(topicid)
{
     var url='modules.php?mod=adminmanual&req=edittopic&topicid='+topicid;
     displayText('popup_space',url);           
     $('popup_space').show();
     return false;
}

function insertManualTopic(form)
{
     if (!validateTopicForm(form))
          return false;
     
     var url='modules.php?mod=adminmanual&req=inserttopic'+
               '&keyword='+encodeURIComponent(form.keyword.value)+
               '&headline='+encodeURIComponent(form.headline.value)+
               '&filename='+encodeURIComponent(form.filename.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminmanual');    
     $('popup_space').hide();
     return false;
}

function updateManualTopic(form)
{
     if (!validateTopicForm(form))
          return false;

     var url='modules.php?mod=adminmanual&req=updatetopic'+
               '&topicid='+encodeURIComponent(form.topicid.value)+
               '&keyword='+encodeURIComponent(form.keyword.value)+
               '&headline='+encodeURIComponent(form.headline.value)+
               '&filename='+encodeURIComponent(form.filename.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminmanual');    
     $('popup_space').hide();
     return false;
}

function deleteManualTopic(topicid,topic)
{
     if (confirm('Are you sure you want to delete '+topic))
          {
          var url='modules.php?mod=adminmanual&req=deletetopic&topicid='+topicid;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=adminmanual');    
          }
     return false;
}


function moveTopicPosition(rec0,pos0,rec1,pos1,id)
{
     var url='modules.php?mod=adminmanual&req=movetopic'+
                    '&rec0='+rec0+
                    '&pos0='+pos0+
                    '&rec1='+rec1+
                    '&pos1='+pos1;
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminmanual');    
}


function validateTopicForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;

     if (isEmpty(form.keyword))
          {
          error_message = error_message + "\t\nKeyword is missing";
          errors=1;
          }
     if (isEmpty(form.headline))
          {
          error_message = error_message + "\t\nHeadline is missing";
          errors=1;
          }
     if (isEmpty(form.filename))
          {
          error_message = error_message + "\t\nFilename is missing";
          errors=1;
          }

     if (errors==0)
          return true;
     alert(error_message);
     return false;    
}/*
 *		GENERIC SOLOMOSITES JQUERY / JAVASCRIPT FUNCTIONS
 *
 *		2010-10-19		Skip
 */

// call the menu PHP module for client presentation.
// arguments
// arr		an array of arguments to put on the URL.
//			these would be like mod=adminenu, req=insert
// -----------------------------------------------------
function slmModuleByRequest(arr,ask,target) {

	if (ask === true) {
		if (!confirm('Are you sure you want to do this?')) 
			return false;
	}
	var url = 'modules.php?';
	for (var i in arr) {
		if (typeof(arr[i]) !== 'object' && typeof(arr[i]) !== 'undefined') {
			url += (url === 'modules.php?') ? i + '=' + arr[i] : '&' + i + '=' + arr[i];
		}
	}
	
	// if a div value is passed in load the servers returned content to it.	
	// if the div is not passed displayText loads the URL contents into the 
	// main content area.
	if (typeof(target) !== 'undefined') {	
		displayText(target,url);
	}
	else {
		displayText('maincontent',url);
	}
}

// submit a form via AJAX.
// arguments
// form		the ID of the form
// mod		the PHP module to call
// req		the request value expected by the PHP module
// ret		the request value to return to the PHP module
// -----------------------------------------------------
function slmSubmitAJAXForm(o) {

	// validate the form. the form must have the 'validate' hidden variable and
	// the properly prefixed ('prompt_', 'field_') ID values in place on the form
	// elements. see /templates/adminmenu/location_add_edit_form.html for reference.
	if (! ps_ValidateForm(o.form))
		return false;	
		
	// if a preprocessor function has been passed in call it and pass the form.
	
	if (typeof(o.pre) !== 'undefined') {
		if (window[o.pre](o.form) === false) {
			return false;
		}
	}
		
	// create object and json string for validation and server call.
	var form_data = slm_FormToJSON(o.form);
	
	// check if an image was uploaded with the form.
	var img = (typeof(o.img) !== 'undefined') ? $('#'+o.img).val() : '';
		
/*	$.postJSON('modules.php?mod='+o.mod+'&req='+o.req, {form_data: form_data, img: img}, function(j) {   */
	
	$.ajax({
		type: "POST",
		url: 'modules.php?mod='+o.mod+'&req='+o.req,
		data: {form_data: form_data, img: img},
		async: false,
		dataType: "json",
		success: function(j) {		
			if (j.ret === false) {	
				$('#dialogbox').dialog({ autoOpen: false, draggable: false, width: 400, title: 'Input Errors', resizable: false, modal: true,
					overlay: {
						opacity: 0.5,
						background: "gray"
					}
				});
				$('#dialogbox').html(j.msg);
				$('#dialogbox').dialog('open');				
			} else {
				// set the request value to the return value passed in here 
				// to call a new screen after processing the form.
				o.req = o.ret;
				
				// check for a record id value passed back to be sent back to the server
				// for the next screen to use.
				if (j.id !== 'undefined') {
					o.id = j.id;
				}
				slmModuleByRequest(o);			
			}
		}});
	return false;
}

// return a JSON encoded string for all form data.
// arguments
// form			the form to process
// -----------------------------------------------------
function slm_FormToJSON(form) {

	var form_data = '{';
	var values = {};
	$.each($(form).serializeArray(), function(i, field) {
		form_data += (form_data === '{') ? '"'+field.name+'":"'+field.value+'"' : ',"'+field.name+'":"'+field.value+'"';
	});
	form_data += '}';
	return form_data;
}

// sends a message to the server to delete a photo from a record
// arguments
// o			object
// o.id			record from which to delete photo
// o.imgdiv		div on page to replace with no image holder
// -------------------------------------------------------------
function deleteSLMPhoto(o) {

	// if a record is passed in call the server to remove it.
	// if this is an add operation no record created yet so just
	// put the noimage.jpg back in place on the page.
	if (o.id !== 0) {
		
	}
	$('#'+o.imgdiv).html('<img src="images/noimage.jpg" div="'+o.imgdiv+'">');
}

// validate the time selectors for items and item categories
// arguments
// f			form containing the fields
// -------------------------------------------------------------
function  validateTimeSelectors(f) {

	var weekdays = {'mon':'Monday', 'tue':'Tuesday', 'wed':'Wednesday', 'thu':'Thursday', 'fri':'Friday', 'sat':'Saturday', 'sun':'Sunday'};
	var err_msg = '';
	for (var day in weekdays) {
		var from_time = $('#'+day+'_from_hours').val() + ':' + $('#'+day+'_from_mins').val() + ' ' + $('#'+day+'_from_ampm').val();
		var to_time = $('#'+day+'_to_hours').val() + ':' + $('#'+day+'_to_mins').val() + ' ' + $('#'+day+'_to_ampm').val();
		if ( ! compareTime(from_time,to_time)) {
			err_msg += weekdays[day]+"'s availability times are incorrectly ordered.<br/>";
		}
	}
	if (err_msg !== '') {
		$('#dialogbox').dialog({ autoOpen: false, draggable: false, width: 400, title: 'Input Errors', resizable: false, modal: true,
			overlay: {
				opacity: 0.5,
				background: "gray"
			}
		});
		$('#dialogbox').html(err_msg);
		$('#dialogbox').dialog('open');
		return false;
	}	
	return true;
}

function compareTime(start,end) {

	// times must be in format "01:00 AM" and "12:10 PM", including the space between
	// the time values and the AM PM value.
	// will return true if first time is less then second time, otherwise false.
	
	// if start and end are both 'zero' return true because this means they're basically not set.
	if (start == '00:00 AM' && end == '00:00 AM') {
		return true;
	}

	var dtStart = new Date("1/1/2011 " + start);
	var dtEnd = new Date("1/1/2011 " + end);
	difference = dtEnd - dtStart;
	return (difference > 0);
}	
function adminNewsDefaultDisplay()
{
     var url='modules.php?mod=adminnews';
     displayText('maincontent',url);           
     return false;
}

function addNewsStory()
{
     var url='modules.php?mod=adminnews&req=addstory';
     displayText('maincontent',url);           
     return false;
}

function noNewsStories()
{
     alert('You must add new categories before you add news stories.');
     return false;
}

function insertNewsStory()
{
     var form = document.getElementById('admin_news_form');
     if (!validateNewsStoryForm(form))
          return false;
     var image = document.getElementById('image_upload_filename').value;
     var url='modules.php?mod=adminnews&req=insertstory'+
                    '&category='+encodeURIComponent(form.category.value)+
                    '&storydate='+encodeURIComponent(form.storydate.value)+
                    '&headline='+encodeURIComponent(form.headline.value)+
                    '&leadin='+encodeURIComponent(form.leadin.value)+
                    '&story='+encodeURIComponent(form.story.value)+
                    '&url='+encodeURIComponent(form.url.value)+
                    '&image='+encodeURIComponent(image);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminnews');    
     return false;
}

function editNewsStory(newsid)
{
     var url='modules.php?mod=adminnews&req=editstory&newsid='+newsid;
     displayText('maincontent',url);           
     return false;     
}

function updateNewsStory()
{
     var form = document.getElementById('admin_news_form');
     if (!validateNewsStoryForm(form))
          return false;

     var image = document.getElementById('image_upload_filename').value;
     var url='modules.php?mod=adminnews&req=updatestory'+
                    '&newsid='+encodeURIComponent(form.newsid.value)+
                    '&category='+encodeURIComponent(form.category.value)+
                    '&storydate='+encodeURIComponent(form.storydate.value)+
                    '&headline='+encodeURIComponent(form.headline.value)+
                    '&leadin='+encodeURIComponent(form.leadin.value)+
                    '&story='+encodeURIComponent(form.story.value)+
                    '&url='+encodeURIComponent(form.url.value)+
                    '&image='+encodeURIComponent(image);

     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminnews');         
     return false;
}

function archiveNewsStory(newsid)
{
     if (confirm("Are you sure you want to archive this story?"))
          {
          var url='modules.php?mod=adminnews&req=archivestory&newsid='+newsid;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=adminnews');    
          }
     return false;
}

function deleteNewsPhoto(id)
{
     if (confirm('Are you sure you want to remove the photo?'))
          {
          var url='modules.php?mod=adminnews&req=deletephoto&id='+id;
          ret=serverFunction(url);
           document.getElementById('newsimage').src='images/noimage.jpg';
          }
     return false;
}

function newsCategories()
{
     displayText('maincontent','modules.php?mod=adminnews&req=categories');
     return false;
}

function newsStories()
{
     displayText('maincontent','modules.php?mod=adminnews');
     return false;
}

function addNewsCategory(form)
{
     if (isEmpty(form.category))
          {
          alert('You must enter a category');
          return false;
          }
	var familypost = (form.familypost.checked == true) ? '1' : '0';
     var url = 'modules.php?mod=adminnews&req=addnewscat'+
			'&category='+encodeURIComponent(form.category.value)+
			'&familypost='+familypost;
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminnews&req=categories');
}

function deleteNewsCagetory(catid,category)
{
     if (confirm("Are you sure you want to delete this\ncategory and all stories in it?"))
          {
          var url='modules.php?mod=adminnews&req=deletenewscat&catid='+catid;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=adminnews&req=categories');
          }
     return false;
}

function editNewsCategory(catid)
{
     var formid=document.getElementById('news_category_form');
     formid.onsubmit=function() {
          return updateNewsCategory(this);
     }
     var catid_field=document.getElementById('catid_field');
     catid_field.value=catid;
     
     var field=document.getElementById('category');
     var url='modules.php?mod=adminnews&req=catname&catid='+catid;
     ret = serverFunction(url);
	var pieces = ret.split('|');

     // for some reason the cat name is coming through with a left padded space.
     // the trim function was placed in functions.js.
     field.value = trim(pieces[0]);
	var familypost = trim(pieces[1]);
	document.getElementById('familypost').checked = (familypost == 1) ? true : false;
}

function updateNewsCategory(form)
{
	var familypost = (form.familypost.checked == true) ? '1' : '0';
     var url='modules.php?mod=adminnews&req=updatenewscategory'+
                    '&catid='+encodeURIComponent(form.catid.value)+
                    '&category='+encodeURIComponent(form.category.value)+
			'&familypost='+familypost;
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminnews&req=categories');
     return false;
}

function newsCategoryImportExport()
{
	var url='modules.php?mod=adminnews&req=importexport';
	displayText('maincontent',url);
	return false;
}

function newsCategoryExportAdd(catid)
{
	if (catid == 0)
		return false;

	var url = 'modules.php?mod=adminnews&req=exportcatadd&catid='+catid;
	var content = serverFunction(url);
	if (content.indexOf('***exported***') != -1)
		alert('Category already exported.');
	else
		document.getElementById('exported_categories').innerHTML = content;
}

function newsCategoryExportDelete(expid)
{
	var url = 'modules.php?mod=adminnews&req=exportcatdelete&expid='+expid;
	var content = serverFunction(url);
	document.getElementById('exported_categories').innerHTML = content;
}

function newsCategoryImportAdd(catid)
{
	if (catid == 0)
		return false;

	var url = 'modules.php?mod=adminnews&req=importcatadd&catid='+catid;
	var content = serverFunction(url);
	if (content.indexOf('***imported***') != -1)
		alert('Category already imported.');
	else
		document.getElementById('imported_categories').innerHTML = content;
}

function newsCategoryImportDelete(impid)
{
	var url = 'modules.php?mod=adminnews&req=importcatdelete&impid='+impid;
	var content = serverFunction(url);
	document.getElementById('imported_categories').innerHTML = content;
}



function validateNewsStoryForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.storydate))
          {
          error_message = error_message + "\t\nStory date is missing.";
          errors=1;
          }
     if (isEmpty(form.headline))
          {
          error_message = error_message + "\t\nHeadline is missing.";
          errors=1;
          }
     if (isEmpty(form.leadin))
          {
          error_message = error_message + "\t\nYou must provide at least a lead in (story is optional).";
          errors=1;
          }
     if (form.category.value==0)
          {
          error_message = error_message + "\t\nYou must select a category.";
          errors=1;
          }
     if (isDate(form.storydate.value)==false)
          {
          error_message = error_message + "\t\nStory date is not a valid date.";
          errors=1;
          }

     if (errors==0)
          return true;
     alert(error_message);
     return false; 
}function opportunityRoles()
{
	var url = 'modules.php?mod=adminopportunities&req=roles';
	displayText('maincontent',url);
}

function insertOpportunityRole()
{
	var role = document.getElementById('role').value;
	var qualifications = document.getElementById('qualifications').value;
	if (role == '')
		alert('You must supply a role.');

	var url = 'modules.php?mod=adminopportunities&req=insertrole'+
			'&role='+encodeURIComponent(role)+
			'&qualifications='+encodeURIComponent(qualifications);
	ret = serverFunction(url);
	opportunityRoles();
	return false;
}

function editOpportunityRole(id)
{
	var url = 'modules.php?mod=adminopportunities&req=editrole&id='+id;
 	displayText('maincontent',url);
}

function updateOpportunityRole()
{
	var id = document.getElementById('roleid').value;
	var role = document.getElementById('role').value;
	var qualifications = document.getElementById('qualifications').value;
	if (role == '')
		alert('You must supply a role.');

	var url = 'modules.php?mod=adminopportunities&req=updatetrole'+
			'&id='+encodeURIComponent(id)+
			'&role='+encodeURIComponent(role)+
			'&qualifications='+encodeURIComponent(qualifications);
	ret = serverFunction(url);
	opportunityRoles();
	return false;
}

function deleteOpportunityRole(id)
{
	if (confirm('Sure you want to delete this role?'))
		{
		var url = 'modules.php?mod=adminopportunities&req=deleterole&id='+id;
		serverFunction(url);
		opportunityRoles();
		}
	return false;
}

function listOpportunities()
{
	// get the value for the checkbox that determines if archived records are displayed.
	if (document.getElementById('showarchived'))
		var archived = document.getElementById('showarchived').checked == true ? 1 : 0;
	else
		var archived = 0;
	var url = 'modules.php?mod=adminopportunities&archived='+archived;
	displayText('maincontent',url);
}

function addOpportunity()
{
	var url = 'modules.php?mod=adminopportunities&req=addopp';
 	displayText('maincontent',url);
}

function insertOpportunity()
{
	var form = document.getElementById('oppform');
	if (form.opportunity.value == '' || form.description.value == '' || form.oppdate.value == '' || form.emails.value == '')
		{
		alert('You must supply a name, date, description and emails');
		return false;
		}

	var start_ampm = (form.start_ampm[0].checked == true) ? 'AM' : 'PM';
	var end_ampm = (form.end_ampm[0].checked == true) ? 'AM' : 'PM';

	var url = 'modules.php?mod=adminopportunities&req=insertopp'+
			'&name='+encodeURIComponent(form.opportunity.value)+
			'&oppdate='+encodeURIComponent(form.oppdate.value)+
			'&start_hour='+encodeURIComponent(form.start_hour.value)+
			'&start_minute='+encodeURIComponent(form.start_minute.value)+
			'&start_ampm='+encodeURIComponent(start_ampm)+
			'&end_hour='+encodeURIComponent(form.end_hour.value)+
			'&end_minute='+encodeURIComponent(form.end_minute.value)+
			'&end_ampm='+encodeURIComponent(end_ampm)+
			'&description='+encodeURIComponent(form.description.value)+
			'&emails='+encodeURIComponent(form.emails.value);
	ret = serverFunction(url);
     listOpportunities();
	return false;
}

function editOpportunity(id)
{
	var url = 'modules.php?mod=adminopportunities&req=editopp&id='+id;
 	displayText('maincontent',url);
}

function updateOpportunity()
{
	var form = document.getElementById('oppform');
	if (form.opportunity.value == '' || form.description.value == '' || form.oppdate.value == '' || form.emails.value == '')
		{
		alert('You must supply a name, date, description and emails');
		return false;
		}

	var start_ampm = (form.start_ampm[0].checked == true) ? 'AM' : 'PM';
	var end_ampm = (form.end_ampm[0].checked == true) ? 'AM' : 'PM';

	var url = 'modules.php?mod=adminopportunities&req=updateopp'+
			'&oppid='+encodeURIComponent(form.oppid.value)+
			'&name='+encodeURIComponent(form.opportunity.value)+
			'&oppdate='+encodeURIComponent(form.oppdate.value)+
			'&start_hour='+encodeURIComponent(form.start_hour.value)+
			'&start_minute='+encodeURIComponent(form.start_minute.value)+
			'&start_ampm='+encodeURIComponent(start_ampm)+
			'&end_hour='+encodeURIComponent(form.end_hour.value)+
			'&end_minute='+encodeURIComponent(form.end_minute.value)+
			'&end_ampm='+encodeURIComponent(end_ampm)+
			'&description='+encodeURIComponent(form.description.value)+
			'&emails='+encodeURIComponent(form.emails.value);
	ret = serverFunction(url);
     listOpportunities();
	return false;
}

function archiveVolunteerOpportunity(id)
{
	if (confirm('Sure you want to archive this opportunity?'))
		{
		var url = 'modules.php?mod=adminopportunities&req=archiveopp&id='+id;
		ret = serverFunction(url);
		listOpportunities();
		}
	return false;
}

function maintainOpportunityShifts(id)
{
	var url = 'modules.php?mod=adminopportunities&req=shifts&id='+id;
 	displayText('maincontent',url);
}

function insertOpportunityShift(id)
{
	var form = document.getElementById('shiftform');
	if (form.role.value == 0)
		{
		alert('You must select a role for this shift.');
		return false;
		}
	var start_ampm = (form.start_ampm[0].checked == true) ? 'AM' : 'PM';
	var end_ampm = (form.end_ampm[0].checked == true) ? 'AM' : 'PM';
	var url = 'modules.php?mod=adminopportunities&req=insertshift'+
			'&oppid='+id+
			'&start_hour='+encodeURIComponent(form.start_hour.value)+
			'&start_minute='+encodeURIComponent(form.start_minute.value)+
			'&start_ampm='+encodeURIComponent(start_ampm)+
			'&end_hour='+encodeURIComponent(form.end_hour.value)+
			'&end_minute='+encodeURIComponent(form.end_minute.value)+
			'&end_ampm='+encodeURIComponent(end_ampm)+
			'&howmany='+encodeURIComponent(form.howmany.value)+
			'&role='+encodeURIComponent(form.role.value);
	ret = serverFunction(url);
	maintainOpportunityShifts(id);
}

function deleteOpportunityShift(id,oppid)
{
	if (confirm('Sure you want to archive this shift?'))
		{
		var url = 'modules.php?mod=adminopportunities&req=deleteshift&id='+id;
		ret = serverFunction(url);
		maintainOpportunityShifts(oppid);
		}
	return false;
}

function opportunitiesConfig()
{
	var url = 'modules.php?mod=adminopportunities&req=config';
 	displayText('maincontent',url);
}

function updateOpportunitiesConfig()
{
     var form = document.getElementById('configform');
	var url = 'modules.php?mod=adminopportunities&req=updateconfig'+
			'&heading='+encodeURIComponent(form.heading.value)+
			'&thanks_email='+encodeURIComponent(form.thanks_email.value)+
			'&unvolunteer_email='+encodeURIComponent(form.unvolunteer_email.value)+
			'&reminder_email='+encodeURIComponent(form.reminder_email.value)+
			'&reject_email='+encodeURIComponent(form.reject_email.value);
 	ret = serverFunction(url);
	listOpportunities();
}

function volunteerOpportunityReport(id)
{
	var url = 'modules.php?mod=adminopportunities&req=oppreport&id='+id;
	window.open(url,'win','left=40,top=40,width=900,height=700,toolbar=0,resizable=1,scrollbars=1');
}

function recordOpportunityHours(id)
{
	var url = 'modules.php?mod=adminopportunities&req=enterhours&id='+id;
 	displayText('maincontent',url);
}

function updateVolunteerHours()
{
	var form = document.getElementById('hoursform');             
	var url = 'modules.php?mod=adminopportunities&req=updatehours';
     for(i = 0, total_hours = 0, norecs = 0; i < form.elements.length; i++)
		{
          if (form.elements[i].name == 'hours[]')
			{
     		url = url + '&rec' + norecs + '=' + form.elements[i+1].value + '&hours' + norecs + '=' + form.elements[i].value;
			norecs++;
			}
          }
	url = url + '&norecs='+norecs;
	ret = serverFunction(url);
	listOpportunities();
	return false;
}

function recalculateOpportunityHours()
{
	var form = document.getElementById('hoursform');             
     for(i = 0, total_hours = 0; i < form.elements.length; i++)
		{
		if (form.elements[i].name == 'hours[]')
			total_hours += parseFloat(form.elements[i].value);
		}
    document.getElementById('totalhours').value = total_hours;
}

function deleteVolunteerUserRecord(id,oppid)
{
	if (confirm('Sure you want to delete this record?'))
		{
          var url = 'modules.php?mod=adminopportunities&req=deleteoppuser&id='+id;
          displayText('maincontent',url);
		}
	return false;	
}

function sendRejectionEmail(oppid)
{
	var form = document.getElementById('emailform');
	var url = 'modules.php';
	var args = 'mod=adminopportunities'+
			'&req=rejectemail'+
			'&shiftid='+encodeURIComponent(document.getElementById('shiftid').value)+
			'&email='+encodeURIComponent(document.getElementById('email').value)+
			'&subject='+encodeURIComponent(document.getElementById('subject').value)+
			'&message='+encodeURIComponent(document.getElementById('message').value);

	ret = serverFunctionPOST(url,args);
	recordOpportunityHours(oppid);
}

function displayOpportunityEmailReminders(id)
{
	var url = 'modules.php?mod=adminopportunities&req=displayreminder&id='+id;
	displayText('maincontent',url);
}


function sendOpportunityEmailReminders()
{
	var form = document.getElementById('emailform');
	var url = 'modules.php';
	var args = 'mod=adminopportunities'+
			'&req=sendreminder'+
			'&oppid='+encodeURIComponent(document.getElementById('oppid').value)+
			'&subject='+encodeURIComponent(document.getElementById('subject').value)+
			'&message='+encodeURIComponent(document.getElementById('message').value);

	ret = serverFunctionPOST(url,args);
	document.getElementById('maincontent').innerHTML = ret;
}

function agencyAdministrators()
{
	var url = 'modules.php?mod=adminopportunities&req=agencies';
     displayText('maincontent',url);
}

function insertAgencyAdmin()
{
	var agency = document.getElementById('agency').value;
	var admin =  document.getElementById('admin').value;
	if (agency == '' || admin == 0)
		{
		alert('You must supply both agency and an administrator.');
		return false;
		}
	var url = 'modules.php?mod=adminopportunities&req=insertagencyadmin'+
			'&agency='+encodeURIComponent(agency)+
			'&admin='+encodeURIComponent(admin);
	ret = serverFunction(url);
	agencyAdministrators();
}
                   
function deleteAgencyAdmin(id)
{
	if (confirm('Sure you want to delete this agency?'))
		{
		var url = 'modules.php?mod=adminopportunities&req=deleteagencyadmin&id='+id;
          ret = serverFunction(url);
		agencyAdministrators();
		}
	return false;
}

function opportunitiesReports()
{
	var url = 'modules.php?mod=adminopportunities&req=reports';
     displayText('maincontent',url);
}

function opportunitiesHoursReport()
{
	if (document.getElementById('start'))
		{
		var start = document.getElementById('start').value;
		var end = document.getElementById('end').value;
		}
	else
		{
		var start = '';
		var end = '';
		}	
	var url = 'modules.php?mod=adminopportunities&req=hoursreport'+
			'&start='+encodeURIComponent(start)+
			'&end='+encodeURIComponent(end);
     displayText('maincontent',url);
}
function updatePaidMembershipConfig()
{
	var form = document.getElementById('paidmembership');
	var status = form.status.value;
	var amounts = form.amounts.value;
	var descriptions = form.descriptions.value;
	var periods = form.periods.value;

	// make sure all fields are filled in.
	if (amounts == '' || descriptions == '' || periods == '')
		{
		alert('You must supply all fields.');
		return false;
		}

	// make sure that the number of amounts, descriptions and periods match.
	var arr_amounts = amounts.split(',');
	var arr_descriptions = descriptions.split(',');
	var arr_periods = periods.split(',');

	if (arr_amounts.length == arr_descriptions.length &&  arr_descriptions.length == arr_periods.length)
		{
		var url = 'modules.php?mod=adminpaidmembers&req=update'+
				'&status='+encodeURIComponent(status)+
				'&amounts='+encodeURIComponent(amounts)+
				'&descriptions='+encodeURIComponent(descriptions)+
				'&periods='+encodeURIComponent(periods);
		ret = serverFunction(url);
		alert('Paid membership configuration updated.');
		}
	else
		{
		alert('You must enter the same number of amounts, descriptions and periods.');
		}
	return false;
}function loadPhotosCats()
{
     var url='modules.php?mod=adminphotos&req=displaycats';
     displayText('maincontent',url);     
}

function insertPhotoCategory(form)
{
     if (! validatePhotoCategoryForm(form))
          return false;

     var url='modules.php?mod=adminphotos&req=insertcat'+
               '&category='+form.category.value+
               '&body='+escape(form.body.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminphotos&req=displaycats');
     return false;
}

function editPhotoCategory(catid)
{
     displayText('maincontent','modules.php?mod=adminphotos&req=editcat&catid='+catid);
     
}

function updatePhotoCategory(form)
{
     if (! validatePhotoCategoryForm(form))
          return false;

     var url='modules.php?mod=adminphotos&req=updatecat'+
               '&catid='+form.catid.value+
               '&category='+form.category.value+
               '&body='+escape(form.body.value);

     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminphotos&req=displaycats');
     return false;     
}

function deletePhotoCategory(catid)
{
     if (confirm("Are you sure you want to delete this category\nand all its associated photos?"))
          {          
          var url='modules.php?mod=adminphotos&req=deletecat&id='+catid;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=adminphotos&req=displaycats');
          }
}

function maintainPhotos()
{
     displayText('maincontent','modules.php?mod=adminphotos&req=photosmain');
}

function selectPhotoCategory()
{
     var object=document.getElementById('category');
     var catid=object.value;
     if (catid==0)
          return false;
     var url='modules.php?mod=adminphotos&req=catcontent&catid='+catid;
     ret=serverFunction(url);
     var object=document.getElementById('catphotos');
     object.innerHTML=ret;
}

function insertPhotoInCat(form)
{
     var object=document.getElementById('up1');
     var filename=object.value;
     var url='modules.php?mod=adminphotos&req=insertphoto'+
               '&filename='+filename+
               '&catid='+form.photocat.value+
               '&caption='+form.photocaption.value+
               '&body='+escape(form.photobody.value);

     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminphotos&req=photosmain&catid='+ret);
     return false;
}

function editPhotoDetails(pid,cid)
{
     var url='modules.php?mod=adminphotos&req=editphoto'+
                    '&pid='+pid+
                    '&cid='+cid;
     displayText('maincontent',url);
}


function updatePhotoDetails(form)
{
     var object=document.getElementById('up1');
     var filename=object.value;
     var url='modules.php?mod=adminphotos&req=updatephoto'+
               '&pid='+form.pid.value+
               '&filename='+filename+
               '&catid='+form.photocat.value+
               '&caption='+form.photocaption.value+
               '&body='+escape(form.photobody.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminphotos&req=photosmain&catid='+form.cid.value);
     return false;
}

function deletePhoto(pid,cid)
{
     if (confirm('Are you sure you want to delete this photo?'))
          {
          var url='modules.php?mod=adminphotos&req=deletephoto&id='+pid;
          serverFunction(url);
          displayText('maincontent','modules.php?mod=adminphotos&req=photosmain&catid='+cid);
          }
}

function validatePhotoCategoryForm(form)
{



     return true;
}

function insertQuote(id,quote)
{
	var form = document.getElementById('add_quote_form');

	if (!validateQuoteForm(form))
	return false;

	
     var url='modules.php?mod=adminquotes&req=insert'+
                    '&who='+encodeURIComponent(form.who.value)+
                    '&quote='+encodeURIComponent(form.quote.value);
     var ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminquotes');
}

function deleteQuote(id)
{
     if (confirm("Are you sure you want to delete this quote?"))
          {          
          var url='modules.php?mod=adminquotes&req=delete&id='+id;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=adminquotes');
          }
}

function editQuote(id)
{
     displayText('maincontent','modules.php?mod=adminquotes&req=edit&id='+id);     
}

function updateQuote()
{
	var form = document.getElementById('add_quote_form');
	if (!validateQuoteForm(form))
	return false;
     var url='modules.php?mod=adminquotes&req=update'+
                    '&quoteid='+encodeURIComponent(form.quoteid.value)+
                    '&who='+encodeURIComponent(form.who.value)+
                    '&quote='+encodeURIComponent(form.quote.value);
     ret = serverFunction(url);
     displayText('maincontent','modules.php?mod=adminquotes');
}


function validateQuoteForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;

     if (isEmpty(form.who))
          {
          error_message = error_message + "\t\nYou did not specify the author of the quote";
          errors=1;
          }
     if (isEmpty(form.quote))
          {
          error_message = error_message + "\t\nQuote text is missing";
          errors=1;
          }

     if (errors==0)
          return true;
     alert(error_message);
     return false;    
}function listShows()
{
	var url = 'modules.php?mod=adminshows';
	displayText('maincontent',url);
}

function addShow()
{
	var url = 'modules.php?mod=adminshows&req=addshow';
	displayText('maincontent',url);
}

function insertShow()
{
	var form = document.getElementById('showform');
	if (!validateShowForm(form))
		return false;
	var image = document.getElementById('image_upload_filename').value;
	var enable_volunteers = (form.enable_volunteers.checked == true ? 1 : 0);
	var display_show = (form.display_show.checked == true ? 1 : 0);
	var enable_reservations = (form.enable_reservations.checked == true ? 1 : 0);
	var enable_tickets = (form.enable_tickets.checked == true ? 1 : 0);
	var showcompcode = (form.showcompcode.checked == true ? 1 : 0);
	var url = 'modules.php?mod=adminshows&req=insertshow'+
			'&showname='+encodeURIComponent(form.showname.value)+
			'&company='+encodeURIComponent(form.company.value)+
			'&companyid='+encodeURIComponent(form.companyid.value)+
			'&playwright='+encodeURIComponent(form.playwright.value)+
			'&location='+encodeURIComponent(form.location.value)+
			'&director='+encodeURIComponent(form.director.value)+
			'&description='+encodeURIComponent(form.description.value)+
			'&ticket_prices='+encodeURIComponent(form.ticket_prices.value)+
			'&total_tickets='+encodeURIComponent(form.total_tickets.value)+
			'&max_tickets='+encodeURIComponent(form.max_tickets.value)+
			'&cutoff='+encodeURIComponent(form.cutoff.value)+
			'&enable_volunteers='+encodeURIComponent(enable_volunteers)+
			'&display_show='+encodeURIComponent(display_show)+
			'&enable_reservations='+encodeURIComponent(enable_reservations)+
			'&enable_tickets='+encodeURIComponent(enable_tickets)+
			'&showcompcode='+encodeURIComponent(showcompcode)+
			'&compcode='+encodeURIComponent(form.compcode.value)+
			'&seatingchart='+encodeURIComponent(form.seatingchart.value)+
			'&image='+encodeURIComponent(image);
	ret = serverFunction(url);
	listShows();
	return false;
}

function editShow(id)
{
	var url = 'modules.php?mod=adminshows&req=editshow&id='+id;
	displayText('maincontent',url);
}

function updateShow(id)
{
	var form = document.getElementById('showform');
	if (!validateShowForm(form))
		return false;
	var image = document.getElementById('image_upload_filename').value;
	var enable_volunteers = (form.enable_volunteers.checked == true ? 1 : 0);
	var display_show = (form.display_show.checked == true ? 1 : 0);
	var enable_reservations = (form.enable_reservations.checked == true ? 1 : 0);
	var enable_tickets = (form.enable_tickets.checked == true ? 1 : 0);
	var showcompcode = (form.showcompcode.checked == true ? 1 : 0);
	var url='modules.php';
	var args = 'mod=adminshows&req=updateshow'+
			'&showid='+encodeURIComponent(form.showid.value)+
			'&showname='+encodeURIComponent(form.showname.value)+
			'&companyid='+encodeURIComponent(form.companyid.value)+
			'&company='+encodeURIComponent(form.company.value)+
			'&playwright='+encodeURIComponent(form.playwright.value)+
			'&location='+encodeURIComponent(form.location.value)+
			'&director='+encodeURIComponent(form.director.value)+
			'&description='+encodeURIComponent(form.description.value)+
			'&ticket_prices='+encodeURIComponent(form.ticket_prices.value)+
			'&total_tickets='+encodeURIComponent(form.total_tickets.value)+
			'&max_tickets='+encodeURIComponent(form.max_tickets.value)+
			'&cutoff='+encodeURIComponent(form.cutoff.value)+
			'&enable_volunteers='+encodeURIComponent(enable_volunteers)+
			'&display_show='+encodeURIComponent(display_show)+
			'&enable_reservations='+encodeURIComponent(enable_reservations)+
			'&enable_tickets='+encodeURIComponent(enable_tickets)+
			'&showcompcode='+encodeURIComponent(showcompcode)+
			'&compcode='+encodeURIComponent(form.compcode.value)+
			'&seatingchart='+encodeURIComponent(form.seatingchart.value)+
			'&image='+encodeURIComponent(image);
	ret = serverFunctionPOST(url,args);
	listShows();
	return false;
}

function deleteShow(id)
{
	if (confirm('Are you sure you want to delete this show?'))
		{
		var url = 'modules.php?mod=adminshows&req=deleteshow&id='+id;
		displayText('maincontent',url);
		}
	listShows();
	return false;
}

function deleteShowPhoto(id)
{
     if (confirm('Are you sure you want to remove the photo?'))
          {
          var url='modules.php?mod=adminshows&req=deletephoto&id='+id;
          ret=serverFunction(url);
           document.getElementById('newsimage').src='images/noimage.jpg';
          }
     return false;
}

function maintainShowDates(id)
{
	var url = 'modules.php?mod=adminshows&req=showdates&id='+id;
	displayText('maincontent',url);
}

function insertShowDate()
{
	var form = document.getElementById('showdateform');
	if (form.showdate.value == '')
		{
		alert('You must select a show date.');
		return false;
		}
	if (form.ticketstructure.value == 0)
		{
		alert('You must select a ticket structure.');
		return false;
		}

	if (form.ampm[0].checked == true)
		var ampm='AM';
	else
		var ampm='PM';
	var url = 'modules.php?mod=adminshows&req=insertshowdate'+
			'&showid='+encodeURIComponent(form.showid.value)+
			'&date='+encodeURIComponent(form.showdate.value)+
			'&structure='+encodeURIComponent(form.ticketstructure.value)+
			'&time='+form.hour.value+':'+form.minute.value+
			'&ampm='+ampm;
	ret = serverFunction(url);
	maintainShowDates(form.showid.value);
	return false;
}

function deleteShowDate(id,showid)
{
	if (confirm('Are you sure you want to delete this show date?'))
		{
		var url = 'modules.php?mod=adminshows&req=deleteshowdate&id='+id;
		ret = serverFunction(url);
		maintainShowDates(showid);
		}
	return false;
}

function showsConfiguration()
{
	var url = 'modules.php?mod=adminshows&req=showconfig';
	displayText('maincontent',url);
}

function updateShowsConfiguration()
{
	var form = document.getElementById('showsconfiguration');
	var url = 'modules.php?mod=adminshows&req=updateshowconfig'+
			'&fields='+encodeURIComponent(form.fields.value)+
			'&optout='+encodeURIComponent(form.optout.value)+
			'&reservationpopup='+encodeURIComponent(form.reservationpopup.value)+
			'&ticketpopup='+encodeURIComponent(form.ticketpopup.value)+
			'&page_summary_code='+encodeURIComponent(form.page_summary_code.value)+
			'&purchase_button_msg='+encodeURIComponent(form.purchase_button_msg.value)+
			'&email_text='+encodeURIComponent(form.email_text.value);
	ret = serverFunction(url);
	listShows();
	return false;
}

function unlockSummaryCode()
{
	var ischecked = document.getElementById('unlocksummary').checked;
	if (ischecked == true)
		{
           document.getElementById('page_summary_code').readOnly = false;
		}
	else
		{
           document.getElementById('page_summary_code').readOnly = true;
		}

	return false;
}

function viewShowReservations(id)
{
	var url = 'modules.php?mod=adminshows&req=reservations&id='+id;
	displayText('maincontent',url);
}

function viewShowReservationsDate(id)
{
	var url = 'modules.php?mod=adminshows&req=reservationsdate&id='+id;
	displayText('maincontent',url);
}

function deleteShowReservation(id,no,dateid,showid)
{
	if (confirm('Are you sure you want to delete this reservation?'))
		{
		var url = 'modules.php?mod=adminshows&req=deletereservation'+
				'&id='+id+
				'&no='+no+
				'&dateid='+dateid;
		ret = serverFunction(url);
		viewShowReservationsDate(dateid);
		}
	return false;
}

function deleteShowCompTicket(id,no,dateid,showid)
{
	if (confirm('Are you sure you want to delete this ticket?'))
		{
		var url = 'modules.php?mod=adminshows&req=deletecompticket'+
				'&id='+id+
				'&no='+no+
				'&dateid='+dateid;
		ret = serverFunction(url);
		viewShowReservationsDate(dateid);
		}
	return false;
}

function ticketStructure()
{
	var url = 'modules.php?mod=adminshows&req=structure';
	displayText('maincontent',url);
}

function insertTicketStructure()
{
	if (!validateStructureForm())
		return false;

	var structure = document.getElementById('structure').value;
	var prices = document.getElementById('prices').value;
	var tags = document.getElementById('tags').value;
	var url = 'modules.php?mod=adminshows&req=insertstructure'+
			'&structure='+encodeURIComponent(structure)+
			'&prices='+encodeURIComponent(prices)+
			'&tags='+encodeURIComponent(tags);
	ret = serverFunction(url);
	displayText('maincontent','modules.php?mod=adminshows&req=structure');
	return false;
}

function editTicketStructure(id)
{
	var url = 'modules.php?mod=adminshows&req=editstructure&id='+encodeURIComponent(id);
	displayText('maincontent',url);
}

function updateTicketStructure(id)
{
	if (!validateStructureForm())
		return false;

	var structure = document.getElementById('structure').value;
	var prices = document.getElementById('prices').value;
	var tags = document.getElementById('tags').value;
	var url = 'modules.php?mod=adminshows&req=updatestructure&id='+encodeURIComponent(id)+
			'&structure='+encodeURIComponent(structure)+
			'&prices='+encodeURIComponent(prices)+
			'&tags='+encodeURIComponent(tags);
	ret = serverFunction(url);
	displayText('maincontent','modules.php?mod=adminshows&req=structure');
	return false;
}

function deleteTicketStructure(id)
{
	if (confirm('Are you sure you want to delete this ticket structure?'))
		{
		var url = 'modules.php?mod=adminshows&req=deletestructure&id='+encodeURIComponent(id);
		serverFunction(url);
		displayText('maincontent','modules.php?mod=adminshows&req=structure');
		}
	return false;
}

function validateStructureForm()
{
	var structure = document.getElementById('structure').value;
	var prices = document.getElementById('prices').value;
	var tags = document.getElementById('tags').value;
	if (structure == '' || prices == '' || tags == '')
		{
		alert('You must fill out all three fields.');
		return false;
		}

	// make sure the numbers of prices and tags match.
	var l_prices = prices.split(',');
	var l_tags = tags.split(',');
	if (l_prices.length != l_tags.length)
		{
		alert('Number of prices must match the number of tags.');
		return false;
		}
	return true;
}

function showReports()
{
	var url = 'modules.php?mod=adminshows&req=reports';
	displayText('maincontent',url);
	return false;
}

function showscsvreport()
{
	var url = 'modules.php?mod=adminshows&req=csvreport';
	displayText('maincontent',url);
	return false;
}

function populateshowdatesdoor(whichprompt)
{
	var showid = document.getElementById('show').value;
	if (showid == 0)
		return false;
	var url = 'modules.php?mod=adminshows&req=showdateoptions'+
			'&showid='+encodeURIComponent(showid);
	var ret = serverFunction(url);
	var pieces = ret.split('|');
	var obj = document.getElementById('showdate');
	obj.options.length = null;
	if (whichprompt == 0)
		obj.options[0] = new Option('Select Date...','0');
	else
		obj.options[0] = new Option('All Dates...','0');

	for (i = 0,y = 0,x = 1; x <= (pieces.length/2) - y; i=i+2,x++)
		obj.options[x] = new Option(trim(pieces[i+1]),trim(pieces[i]));
	return false;
}

function populatePricesForDoorTickets(dateid)
{
	var url = 'modules.php?mod=tickets&req=datestructure&id='+dateid;
	ret = serverFunction(url);
	var obj = document.getElementById('select_price');
	obj.options.length = null;
	var pieces = ret.split('|');
	obj.options[0] = new Option('Select price','0');
	for (i = 0,x = 1; x <= (pieces.length/2); i=i+2,x++)
		{
		obj.options[x] = new Option(pieces[i] + ' - $' + parseFloat(pieces[i+1]).toFixed(2),pieces[i+1]);
		}
	return false;
}

function createShowCVSFile()
{
	var showid = document.getElementById('show').value;
	var dateid = document.getElementById('showdate').value;
	var url = 'modules.php?mod=adminshows&req=createshowcsv'+
			'&showid='+encodeURIComponent(showid)+
			'&dateid='+encodeURIComponent(dateid);
	displayText('maincontent',url);
	return false;
}

function processDoorTickets()
{
	var url = 'modules.php?mod=adminshows&req=doortickets';
	displayText('maincontent',url);
}

function addDoorTicketRecords()
{
	var showid = document.getElementById('show').value;
	var dateid = document.getElementById('showdate').value;
	var price  = document.getElementById('select_price').value;
	var no_tickets = document.getElementById('no_tickets').value;
	if (no_tickets != '')
		var no_tickets = parseFloat(no_tickets);
	else
		var no_tickets = 0;
	if (showid == 0 || dateid == 0 || price == 0 || no_tickets == 0)
		{
		var str = 'You must supply all three fields.';
		if (no_tickets < 1)
			str = str + "\n\nNumber of tickets must be at least 1.";
		alert(str);
		return false;
		}
	var url = 'modules.php?mod=adminshows&req=insertdoortickets'+
			'&showid='+encodeURIComponent(showid)+
			'&dateid='+encodeURIComponent(dateid)+
			'&price='+encodeURIComponent(price)+
			'&no_tickets='+encodeURIComponent(no_tickets);
	if (confirm('Press OK to add the '+no_tickets+' tickets to this show or Cancel to return to the page.'))
		displayText('maincontent',url);

	return false;
}

function surchargeReport()
{
	if (document.getElementById('start'))
		{
		var start = document.getElementById('start').value;
		var end = document.getElementById('end').value;
		}
	else
		{
		var start = '';
		var end = '';
		}
	var url = 'modules.php?mod=adminshows&req=surcharge'+
			'&start='+encodeURIComponent(start)+
			'&end='+encodeURIComponent(end);
	displayText('maincontent',url);
	return false;
}

function addShowAdmin(showid,userid)
{
	var url = 'modules.php?mod=adminshows&req=insertshowadmin'+
			'&showid='+showid+
			'&userid='+userid;
	document.getElementById('this_shows_admins').innerHTML = trim(serverFunction(url));
	return false;
}

function deleteShowAdmin(showid,userid)
{
	var url = 'modules.php?mod=adminshows&req=deleteshowadmin'+
			'&showid='+showid+
			'&userid='+userid;
	document.getElementById('this_shows_admins').innerHTML = trim(serverFunction(url));
	return false;
}

function processAdvancedTickets()
{
	var url = 'modules.php?mod=adminshows&req=advanced';
	displayText('maincontent',url);
}

function populateAdvancedTicketsRows(dateid)
{
	var obj = document.getElementById('advancedrows');
	var url = 'modules.php?mod=adminshows&req=advancedrows&dateid='+dateid;	
	ret = serverFunction(url);
	obj.innerHTML = ret;

	// blank out the form fields.
	var form = document.getElementById('advancedticketsform');
	form.email.value = '';
	form.first.value = '';
	form.last.value = '';
	form.addr1.value = '';
	form.addr2.value = '';
	form.city.value = '';
	form.state.value = 0;
	form.zip.value = '';
	form.phone.value = '';
	form.no_tickets.value = '';
	form.price.value = '';
	form.notes.value = '';
}

function insertAdvancedTicket()
{
	var form = document.getElementById('advancedticketsform');
	if ( ! validateAdvancedTicketForm(form))
		return false;

	var url = 'modules.php?mod=adminshows&req=insertadvanced'+
			'&showid='+encodeURIComponent(form.show.value)+
			'&dateid='+encodeURIComponent(form.showdate.value)+
			'&email='+encodeURIComponent(form.email.value)+
			'&first='+encodeURIComponent(form.first.value)+
			'&last='+encodeURIComponent(form.last.value)+
			'&addr1='+encodeURIComponent(form.addr1.value)+
			'&addr2='+encodeURIComponent(form.addr2.value)+
			'&city='+encodeURIComponent(form.city.value)+
			'&state='+encodeURIComponent(form.state.value)+
			'&zip='+encodeURIComponent(form.zip.value)+
			'&phone='+encodeURIComponent(form.phone.value)+
			'&no_tickets='+encodeURIComponent(form.no_tickets.value)+
			'&price='+encodeURIComponent(form.price.value)+
			'&notes='+encodeURIComponent(form.notes.value);

	ret = serverFunction(url);
	populateAdvancedTicketsRows(form.showdate.value);
	return false;
}

function deleteAdvancedTicket(ticketid,dateid)
{
	if (confirm('Are you sure you want to delete this ticket?'))
		{
		var url = 'modules.php?mod=adminshows&req=deleteadvanced&ticketid='+ticketid;
		ret = serverFunction(url);
		populateAdvancedTicketsRows(dateid);
		}
	return false;	
}

function populateAdvancedTicket(email)
{
	var url = 'modules.php?mod=adminshows&req=lookupadvanced&email='+email;
	ret = serverFunction(url);
	if (ret.indexOf('email-not-found') > -1)
		return false;

	// populate the form fields.
	var form = document.getElementById('advancedticketsform');
     var fields = ret.split('|');
	form.first.value = trim(fields[0]);
	form.last.value = trim(fields[1]);
	form.addr1.value = trim(fields[2]);
	form.addr2.value = trim(fields[3]);
	form.city.value = trim(fields[4]);
	form.state.value = trim(fields[5]);
	form.zip.value = trim(fields[6]);
	form.phone.value = trim(fields[7]);		

	return false;
}

function showsincomereport()
{
	if (document.getElementById('start'))
		{
		var start = document.getElementById('start').value;
		var end = document.getElementById('end').value;
		}
	else
		{
		var start = '';
		var end = '';
		}
	var url = 'modules.php?mod=adminshows&req=incomereport'+
			'&start='+encodeURIComponent(start)+
			'&end='+encodeURIComponent(end);
	displayText('maincontent',url);
	return false;
}

function showsTheaterCompanies()
{
	if (!document.getElementById('allcompanies'))
		var all = 0;
	else
		var all = (document.getElementById('allcompanies').checked == true) ? 1 : 0;

	var url = 'modules.php?mod=adminshows&req=companies&all='+all;
	displayText('maincontent',url);
}

function addShowCompany()
{
	var url = 'modules.php?mod=adminshows&req=addcompany';
	displayText('maincontent',url);
}

function insertShowCompany()
{
	var form = document.getElementById('companyform');
     if (!validateShowCompanyForm(form))
		return false;
	var url = 'modules.php?mod=adminshows&req=insertcompany'+
			'&name='+encodeURIComponent(form.company.value)+
			'&addr1='+encodeURIComponent(form.addr1.value)+
			'&addr2='+encodeURIComponent(form.addr2.value)+
			'&city='+encodeURIComponent(form.city.value)+
			'&state='+encodeURIComponent(form.state.value)+
			'&zip='+encodeURIComponent(form.zip.value)+
			'&phone='+encodeURIComponent(form.phone.value)+
			'&fax='+encodeURIComponent(form.fax.value)+
			'&email='+encodeURIComponent(form.email.value)+
			'&url='+encodeURIComponent(form.url.value)+
			'&gw_username='+encodeURIComponent(form.gw_username.value)+
			'&gw_password='+encodeURIComponent(form.gw_password.value)+
			'&policy='+encodeURIComponent(form.policy.value);
	ret = serverFunction(url);
	showsTheaterCompanies();
}

function editShowCompany(id)
{
	var url = 'modules.php?mod=adminshows&req=editcompany&id='+id;
	displayText('maincontent',url);
}

function updateShowCompany()
{
	var form = document.getElementById('companyform');
     if (!validateShowCompanyForm(form))
		return false;

	// compare payment gateway values and warn if they've been changed.
	// give the user the chance to cancel if the values have been changed.
	if (form.gw_username.value != form.current_gw_username.value || form.gw_password.value != form.current_gw_password.value)
		{                                                                                                                           
          if (!confirm("THE PAYMENT GATEWAY VALUES HAVE BEEN CHANGED!\n\n"+
				   "If you did not mean to change these values click\n"+
				   "cancel below. If these values are changed to\n"+
				   "invalid values credit card processing will fail.\n\n"+
				   "If you meant to change these values click OK."))
			{
			showsTheaterCompanies();
			return false;
			}
		}

	var url = 'modules.php?mod=adminshows&req=updatecompany'+
			'&companyid='+encodeURIComponent(form.companyid.value)+
			'&name='+encodeURIComponent(form.company.value)+
			'&addr1='+encodeURIComponent(form.addr1.value)+
			'&addr2='+encodeURIComponent(form.addr2.value)+
			'&city='+encodeURIComponent(form.city.value)+
			'&state='+encodeURIComponent(form.state.value)+
			'&zip='+encodeURIComponent(form.zip.value)+
			'&phone='+encodeURIComponent(form.phone.value)+
			'&fax='+encodeURIComponent(form.fax.value)+
			'&email='+encodeURIComponent(form.email.value)+
			'&url='+encodeURIComponent(form.url.value)+
			'&gw_username='+encodeURIComponent(form.gw_username.value)+
			'&gw_password='+encodeURIComponent(form.gw_password.value)+
			'&policy='+encodeURIComponent(form.policy.value);
	ret = serverFunction(url);
	showsTheaterCompanies();
}

function deleteShowCompany(id)
{
	if (confirm('Delete this company?'))
		{
		var url = 'modules.php?mod=adminshows&req=deletecompany&id='+id;
		ret = serverFunction(url);
		showsTheaterCompanies();
		}
}


function toggleTheaterCompanyActive(id)
{
	var active = (document.getElementById('active'+id).checked == true) ? 1 : 0;
	var url = 'modules.php?mod=adminshows&req=togglecompany'+
			'&id='+id+
			'&active='+active;
	ret = serverFunction(url);
	showsTheaterCompanies();
}

function validateShowCompanyForm(form)
{
	var errors = 0;
	if (trim(form.company.value) == '' || trim(form.gw_username.value) == '' || trim(form.gw_password.value) == '')
		{
		alert("You must supply the company's name and both gateway fields.");
		return false;
		}
	return true;
}


function deleteShowTicket(ticketid,dateid)
{
	if (confirm('Sure you want to delete this ticket?'))
		{
		var url = 'modules.php?mod=adminshows&req=deleteticket&id='+ticketid;	
		ret = serverFunction(url);
		viewShowReservationsDate(dateid);
		}
}



function validateAdvancedTicketForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
	if (form.show.value == 0)
          {
          error_message = error_message + "\t\nYou must select a show.";
          errors=1;
          }
	if (form.showdate.value == 0)
          {
          error_message = error_message + "\t\nYou must select a show date.";
          errors=1;
          }
     if (isEmpty(form.email))
          {
          error_message = error_message + "\t\nSupply the email address.";
          errors=1;
          }
     if (isEmpty(form.first))
          {
          error_message = error_message + "\t\nSupply the first name.";
          errors=1;
          }
     if (isEmpty(form.last))
          {
          error_message = error_message + "\t\nSupply the last name.";
          errors=1;
          }
     if (isEmpty(form.no_tickets))
          {
          error_message = error_message + "\t\nSupply the number of tickets.";
          errors=1;
          }
     if (isEmpty(form.price))
          {
          error_message = error_message + "\t\nSupply the price of the ticket(s).";
          errors=1;
          }
     if (errors==0)
		{
          return true;
		}
     alert(error_message);
     return false; 
}

function validateShowForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.showname))
          {
          error_message = error_message + "\t\nField 1 is missing.";
          errors=1;
          }
     if (form.companyid.value == 0)
          {
          error_message = error_message + "\t\nProduction company is missing.";
          errors=1;
          }
     if (isEmpty(form.description))
          {
          error_message = error_message + "\t\nText area, description, is missing.";
          errors=1;
          }
	if (form.showcompcode.checked == true && isEmpty(form.compcode))
          {
          error_message = error_message + "\t\nIf show comp code checked supply comp code.";
          errors=1;
          }

     if (errors==0)
          return true;
     alert(error_message);
     return false; 
}

function viewShowParts(id) 
{
	var url = 'modules.php?mod=adminshows&req=viewparts&id='+id;
	displayText('maincontent',url);
}

function addPart(id)
{
	var url = 'modules.php?mod=adminshows&req=addpart&id='+id;
	displayText('maincontent',url);
}

function insertPart(id)
{
    var form = document.getElementById('partform');
	
	var url = 'modules.php?mod=adminshows&req=insertpart&id='+id+
			'&part='+encodeURIComponent(form.part.value)+
			'&cutoff='+encodeURIComponent(form.cutoff.value)+
			'&active='+encodeURIComponent(form.active.value)+
			'&notes='+encodeURIComponent(form.notes.value);
	ret = serverFunction(url);
	viewShowParts(id);
	return false;
}

function deletePart(partid, showid)
{
    var url = 'modules.php?mod=adminshows&req=deletepart&partid='+partid;
    ret = serverFunction(url);
	viewShowParts(showid);
	return false;
}

function createShowDateLabels(dateid)
{	
	if ( ! confirm("You've selected to print mailing labels.\nLoad Avery 5160/8160 labels into you printer\nand then select Print from the window menu."))
		return false;
	var url = 'modules.php?mod=adminshows&req=labels&id='+dateid;
	ret = serverFunction(url);	
	var win = window.open('modules.php?mod=adminusers&req=labels','win','left=40,top=40,width=980,height=600,menubar=1,resizable=1,scrollbars=1'); 
}
function displaySitePagesMain()
{
     var url = 'modules.php?mod=adminsitepages';
     displayText('maincontent',url);
     return false;
}

function selectSitePagesCat(cat)
{
     if (cat == 0)
          {
          document.getElementById('site_pages_rows').innerHTML = "";
          return false;
          }
	var pieces = cat.split('|');
	var cat_or_item = trim(pieces[0]);
	if (cat_or_item == 0)
		{
		category = trim(pieces[1]);
		var itemid = 0;
		var parentid = 0;
		}
	else if (cat_or_item == 1)
		{
		category = 0;
		var parentid = 0;
		var itemid = trim(pieces[1]);
		}
	else
		{
		category = 0;
		var parentid = trim(pieces[1]);
		var itemid = 0;
		}
     
     var url = 'modules.php?mod=adminsitepages&req=listpages'+
			'&catid='+category+
			'&itemid='+itemid+
			'&parentid='+parentid;

     displayText('site_pages_rows',url);
     return false;
}

function moveSitePagePosition(rec0,pos0,rec1,pos1,catid,itemid,parentid)
{
     var url='modules.php?mod=adminsitepages&req=movesitepage'+
                    '&rec0='+rec0+
                    '&pos0='+pos0+
                    '&rec1='+rec1+
                    '&pos1='+pos1;
     ret=serverFunction(url);
     var url = 'modules.php?mod=adminsitepages&req=listpages'+
			'&catid='+catid+
			'&itemid='+itemid+
			'&parentid='+parentid;
     displayText('site_pages_rows',url);
	mainmenu();	
     return false;    
}

function addSitePage()
{
	var url='modules.php?mod=adminsitepages&req=addpage';
	displayText('maincontent',url);
	return false;
}

function insertSitePage(process)
{
	var pagename = document.getElementById('pagename').value;
	var category = document.getElementById('category').value;
	var summary = document.getElementById('summary').value;
	var headline = document.getElementById('headline').value;
	var putonmenu = document.getElementById('putonmenu').checked == true ? 1 : 0;
	var body = FCKeditorAPI.GetInstance('FCKeditor1').GetHTML();

	if (pagename == '' || category == '')
		{
          alert('You must supply both a category and a page name');
		return false;
		}

	var pieces = category.split('|');
	var cat_or_item = trim(pieces[0]);
	if (cat_or_item == 0)
		{
		category = trim(pieces[1]);
		var itemid = 0;
		var parentid = 0;
		}
	else if (cat_or_item == 1)
		{
		category = 0;
		var parentid = 0;
		var itemid = trim(pieces[1]);
		}
	else
		{
		category = 0;
		var parentid = trim(pieces[1]);
		var itemid = 0;
		}
	
     if (process)
          {          
          if (pagename=='' || body=='')
			{
			alert('You must supply both a page name and a page body');
               return false;
			}
		if (category == 0 && itemid == 0 && parentid == 0)
			{
			alert('You must select a page location');
               return false;
			}
     
          var url='modules.php';
		var args =	'mod=adminsitepages'+     
					'&req=insertpage'+
                         '&pagename='+encodeURIComponent(pagename)+
					'&mainmenu='+encodeURIComponent(putonmenu)+
                         '&category='+encodeURIComponent(category)+
					'&itemid='+encodeURIComponent(itemid)+
					'&parentid='+encodeURIComponent(parentid)+
                         '&summary='+encodeURIComponent(summary)+
                         '&headline='+encodeURIComponent(headline)+
                         '&body='+encodeURIComponent(body);

          ret = serverFunctionPOST(url,args);
          }
     var url='modules.php?mod=adminsitepages';
     displayText('maincontent',url);
     mainmenu();		
     return false;
}

function editSitePage(pageid)
{
	var url='modules.php?mod=adminsitepages&req=editpage&id='+pageid;
	displayText('maincontent',url);
	return false;
}

function updateSitePage(process)
{
	var pageid = document.getElementById('pageid').value;
	var category = document.getElementById('category').value;
	var pagename = document.getElementById('pagename').value;
	var category = document.getElementById('category').value;
	var summary = document.getElementById('summary').value;
	var headline = document.getElementById('headline').value;
	var putonmenu = document.getElementById('putonmenu').checked == true ? 1 : 0;
	var body = FCKeditorAPI.GetInstance('FCKeditor1').GetHTML();

	var pieces = category.split('|');
	var cat_or_item = trim(pieces[0]);
	if (cat_or_item == 0)
		{
		category = trim(pieces[1]);
		var itemid = 0;
		var parentid = 0;
		}
	else if (cat_or_item == 1)
		{
		category = 0;
		var parentid = 0;
		var itemid = trim(pieces[1]);
		}
	else
		{
		category = 0;
		var parentid = trim(pieces[1]);
		var itemid = 0;
		}

     if (process)
          {
          if (pagename=='' || body=='')
			{
			alert('You must supply both a page name and a page body');
               return false;
			}
		if (category == 0 && itemid == 0 && parentid == 0)
			{
			alert('You must select a page location');
               return false;
			}

          var url='modules.php';
		var args =	'mod=adminsitepages'+     
					'&req=updatepage'+
					'&category='+encodeURIComponent(category)+
					'&mainmenu='+encodeURIComponent(putonmenu)+
					'&itemid='+encodeURIComponent(itemid)+
					'&pageid='+encodeURIComponent(pageid)+
					'&parentid='+encodeURIComponent(parentid)+
                         '&pagename='+encodeURIComponent(pagename)+
                         '&category='+encodeURIComponent(category)+
                         '&summary='+encodeURIComponent(summary)+
                         '&headline='+encodeURIComponent(headline)+
                         '&body='+encodeURIComponent(body);
          ret = serverFunctionPOST(url,args);
          }

	// process is set to 2 for a preivew.
	if (process == 2)
		{
		url = 'modules.php?mod=sitepages&req=displaypage&pageid='+pageid;
		window.open(url,'win','left=3,top=3,width=900,height=600,menubar=1,resizable=1,scrollbars=1');
          return false;
		}

	var url = 'modules.php?mod=adminsitepages&id='+category;
	displayText('maincontent',url);	
     var url = 'modules.php?mod=adminsitepages&req=listpages'+
			'&catid='+category+
			'&itemid='+itemid+
			'&parentid='+parentid;
     displayText('site_pages_rows',url);		
	return false;
}

function deleteSitePage(pageid,catid,itemid,parentid)
{
	if (confirm('Sure you want to delete this page?'))
		{
		var url='modules.php?mod=adminsitepages&req=deletepage&id='+pageid;
		ret = serverFunction(url);
		var url = 'modules.php?mod=adminsitepages&id='+catid;
		displayText('maincontent',url);	
     var url = 'modules.php?mod=adminsitepages&req=listpages'+
			'&catid='+catid+
			'&itemid='+itemid+
			'&parentid='+parentid;
       	displayText('site_pages_rows',url);	
	
		//displayText('maincontent','modules.php?mod=adminsitepages');
                mainmenu();		
		}
		
	return false;

}

function insertSitePagesCategory(form)
{
	// warn and return if the form is empty.
	if (form.category.value.length==0 || form.group.value==0)
		{
		alert('You must enter a category and select a group.')
		return false;
		}
		
	// check if this is an update, not an insert, and if so pass it to the update function.
	if (document.getElementById('cat_submit_button').value == 'Update Category')
		return updateSitePagesCategory(form);		

	var url = 'modules.php?mod=adminsitepages&req=insertcat'+
			  '&category='+encodeURIComponent(form.category.value)+
			  '&group='+encodeURIComponent(form.group.value);
	ret = serverFunction(url);
	displayText('maincontent','modules.php?mod=adminsitepages');
        mainmenu();	
}

function editSitePagesCategory(main,catid)
{
        if (main > 0)
               {
               alert("You can't edit the Main Menu or Site Pages category");
               return false;
               }
	var url='modules.php?mod=adminsitepages&req=editcat&id='+catid;
	var str = serverFunction(url);
	
	// string returned contains category name | selected gID value | category 1 | cat id 1 | category n | cat id n	
	document.getElementById('catid').value=catid;
	document.getElementById('cat_submit_button').value = 'Update Category';
	var pieces = str.split('|');
	document.getElementById('category_field').value = leftTrim(pieces[0]);
	
	// insert the values into the drop down selecting the current one for the category.
	var form = document.getElementById('category_form');
	form.group.options.length = null;
	for (i = 2,x = 0; x < (pieces.length - 2)/2; i=i+2,x++)
		{
		// alert("x:"+i+" "+pieces[i]+","+pieces[i+1]);
		form.group.options[x] = new Option(pieces[i],pieces[i+1]);
		
		// check if current option is the selected one for this cat. if so set to selected.
		if (pieces[i+1] == pieces[1])
			form.group.selectedIndex = x;
		
		}

	return false;
}

function updateSitePagesCategory(form)
{
	var url = 'modules.php?mod=adminsitepages&req=updatecat'+
				'&catid='+form.catid.value+
				'&category='+form.category.value+
				'&groupid='+form.group.value;
				
	ret = serverFunction(url);
        // displayText('site_pages_categories','modules.php?mod=adminsitepages&req=categoryrows');
        // displayText('categories_form','modules.php?mod=adminsitepages&req=categoryform');
        displayText('maincontent','modules.php?mod=adminsitepages');
        mainmenu();  
	return false;
}

function deleteSitePagesCategory(main,catid)
{
        if (main > 0)
               {
               alert("You can't delete the Main Menu or Site Pages category");
               return false;
               }
	if (confirm('Sure you want to delete this category?'))
		{
		var url='modules.php?mod=adminsitepages&req=deletecat&id='+catid;
		ret = serverFunction(url);
		displayText('maincontent','modules.php?mod=adminsitepages');
                mainmenu();			
		}
	return false;
}

function validateSitePage(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     
     if (form.category.value == 0 && form.itemid.value == 0)
          {
          error_message = error_message + "\t\nYou must select a page location";
          errors=1;
          } 
     if (form.category.value != 0 && form.itemid.value != 0)
          {
          error_message = error_message + "\t\nYou must select only one page location";
          errors=1;
          }       
     if (isEmpty(form.pagename))
          {
          error_message = error_message + "\t\nPage name is missing";
          errors=1;
          }
     if (isEmpty(form.body))
          {
          error_message = error_message + "\t\nPage Text is missing";
          errors=1;
          }
     if (errors==0)
          return true;
     alert(error_message);
     return false;    
}function listSponsors()
{
	var url = 'modules.php?mod=adminsponsors';
	displayText('maincontent',url);
}

function addSponsor()
{
	var url = 'modules.php?mod=adminsponsors&req=add';
	displayText('maincontent',url);
}

function insertSponsor()
{
     var form = document.getElementById('sponsor_form');
	var image = document.getElementById('image_upload_filename').value;
     if (!validateSponsorForm(form,image,'insert'))
          return false;
	var url = 'modules.php?mod=adminsponsors&req=insert'+
			'&sponsor='+encodeURIComponent(form.sponsor.value)+
			'&description='+encodeURIComponent(form.description.value)+
			'&url='+encodeURIComponent(form.url.value)+
			'&url_text='+encodeURIComponent(form.url_text.value)+
			'&image='+encodeURIComponent(image);
	ret = serverFunction(url);
	listSponsors();
	return false;
}

function editSponsor(id)
{
	var url = 'modules.php?mod=adminsponsors&req=edit&id='+id;
	displayText('maincontent',url);
}

function updateSponsor()
{
     var form = document.getElementById('sponsor_form');
	var image = document.getElementById('image_upload_filename').value;
     if (!validateSponsorForm(form,image,'update'))
          return false;
	var url = 'modules.php?mod=adminsponsors&req=update'+
			'&sponsorid='+encodeURIComponent(form.sponsorid.value)+
			'&sponsor='+encodeURIComponent(form.sponsor.value)+
			'&description='+encodeURIComponent(form.description.value)+
			'&url='+encodeURIComponent(form.url.value)+
			'&url_text='+encodeURIComponent(form.url_text.value)+
			'&image='+encodeURIComponent(image);
	ret = serverFunction(url);
	listSponsors();
	return false;
}

function deleteSponsor(id)
{
	if (confirm('Are you sure you want to delete this sponsor?'))
		{
		var url = 'modules.php?mod=adminsponsors&req=delete&id='+id;
		serverFunction(url);
		}
	listSponsors();
	return false;
}

function clickThroughToSponsor(id)
{
	var url = 'modules.php?mod=ajax&req=sponsorclick&id='+id;
	url = serverFunction(url);
	window.open(url,'win','left=40,top=40,width=980,height=600,menubar=1,resizable=1,scrollbars=1'); 
	return false;
}

function viewSponsorStats(id)
{
	var url = 'modules.php?mod=adminsponsors&req=listmonthsclicks&id='+id;
	displayText('maincontent',url);
}

function clicksForSingleMonth(id,month)
{
	var url = 'modules.php?mod=adminsponsors&req=clicksformonth'+
			'&id='+id+
			'&month='+month;
	displayText('maincontent',url);
}

function validateSponsorForm(form,image,mode)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.sponsor))
          {
          error_message = error_message + "\t\nSponsor is missing.";
          errors=1;
          }
     if (isEmpty(form.description))
          {
          error_message = error_message + "\t\nDescription is missing.";
          errors=1;
          }
     if (isEmpty(form.url))
          {
          error_message = error_message + "\t\nURL is missing.";
          errors=1;
          }
     if (isEmpty(form.url_text))
          {
          error_message = error_message + "\t\nURL text is missing.";
          errors=1;
          }
	if (image == '' && mode == 'insert')
          {
          error_message = error_message + "\t\nImage has not been uploaded.";
          errors=1;
          }
     if (errors==0)
          return true;
     alert(error_message);
     return false; 
}function displayStores()
{
	var url = 'modules.php?mod=adminstores';
	displayText('maincontent',url);
}


function addStore()
{
	var url = 'modules.php?mod=adminstores&req=addstore';
	displayText('maincontent',url);
}

function insertStore()
{
	var form = document.getElementById('storeform');
	if ( ! validateStoreForm(form))
		return false;

	var url = 'modules.php?mod=adminstores&req=insertstore'+
			'&name='+encodeURIComponent(form.store.value)+
			'&addr1='+encodeURIComponent(form.addr1.value)+
			'&addr2='+encodeURIComponent(form.addr2.value)+
			'&city='+encodeURIComponent(form.city.value)+
			'&state='+encodeURIComponent(form.state.value)+
			'&zip='+encodeURIComponent(form.zip.value)+
			'&phone='+encodeURIComponent(form.phone.value)+
			'&cell='+encodeURIComponent(form.cell.value)+
			'&fax='+encodeURIComponent(form.fax.value)+
			'&email='+encodeURIComponent(form.email.value)+
			'&paypal_email='+encodeURIComponent(form.paypal_email.value)+
			'&gateway='+encodeURIComponent(form.gateway.value)+
			'&gw_username='+encodeURIComponent(form.gw_username.value)+
			'&gw_password='+encodeURIComponent(form.gw_password.value);
	ret = serverFunction(url);
	displayStores();
}

function editStore(id)
{
	var url = 'modules.php?mod=adminstores&req=editstore&storeid='+id;
	displayText('maincontent',url);
}

function updateStore()
{
	var form = document.getElementById('storeform');
	if ( ! validateStoreForm(form))
		return false;

	var url = 'modules.php?mod=adminstores&req=updatestore'+
			'&storeid='+encodeURIComponent(form.storeid.value)+
			'&name='+encodeURIComponent(form.store.value)+
			'&addr1='+encodeURIComponent(form.addr1.value)+
			'&addr2='+encodeURIComponent(form.addr2.value)+
			'&city='+encodeURIComponent(form.city.value)+
			'&state='+encodeURIComponent(form.state.value)+
			'&zip='+encodeURIComponent(form.zip.value)+
			'&phone='+encodeURIComponent(form.phone.value)+
			'&cell='+encodeURIComponent(form.cell.value)+
			'&fax='+encodeURIComponent(form.fax.value)+
			'&email='+encodeURIComponent(form.email.value)+
			'&paypal_email='+encodeURIComponent(form.paypal_email.value)+
			'&gateway='+encodeURIComponent(form.gateway.value)+
			'&gw_username='+encodeURIComponent(form.gw_username.value)+
			'&gw_password='+encodeURIComponent(form.gw_password.value);
	ret = serverFunction(url);
	displayStores();
}

function deleteStore(id)
{
	if (confirm('Are you sure you want to delete this store?'))
		{
		var url = 'modules.php?mod=adminstores&req=deletestore&storeid='+id;
		ret = serverFunction(url);
		displayStores();
		}
	return false;
}

function addStoreAdmin(storeid,userid)
{
	var url = 'modules.php?mod=adminstores&req=insertstoreadmin'+
			'&storeid='+storeid+
			'&userid='+userid;
	document.getElementById('this_store_admins').innerHTML = trim(serverFunction(url));
	return false;
}

function deleteStoreAdmin(storeid,userid)
{
	var url = 'modules.php?mod=adminstores&req=deletestoreadmin'+
			'&storeid='+storeid+
			'&userid='+userid;
	document.getElementById('this_store_admins').innerHTML = trim(serverFunction(url));
	return false;
}

function validateStoreForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.store))
          {
          error_message = error_message + "\t\nStore name is missing.";
          errors=1;
          }
     if (isEmpty(form.addr1))
          {
          error_message = error_message + "\t\nAddress 1 is missing.";
          errors=1;
          }
     if (isEmpty(form.city))
          {
          error_message = error_message + "\t\nCity is missing.";
          errors=1;
          }
     if (form.state.value == 0)
          {
          error_message = error_message + "\t\nState is not selected.";
          errors=1;
          }
     if (isEmpty(form.zip))
          {
          error_message = error_message + "\t\nZip is missing.";
          errors=1;
          }
     if (isEmpty(form.phone))
          {
          error_message = error_message + "\t\nPhone is missing.";
          errors=1;
          }
     if (isEmpty(form.email))
          {
          error_message = error_message + "\t\nEmail address is missing.";
          errors=1;
          }
     if (errors==0)
          return true;
     alert(error_message);
     return false; 
}function surveysDefaultDisplay()
{
	var url='modules.php?mod=adminsurveys';
	displayText('maincontent',url);
}

function displaySurveys()
{
	var url='modules.php?mod=adminsurveys&req=listsurveys';
	displayText('maincontent',url);
}

function addSurvey()
{
	var url='modules.php?mod=adminsurveys&req=addsurvey';
	displayText('maincontent',url);
}

function insertSurvey()
{
	var form = document.getElementById('survey_form');

     // prepend '0' if only a single digit entered.
     if (form.start_mm.value.length==1)  form.start_mm.value = '0' + form.start_mm.value;
     if (form.start_dd.value.length==1)  form.start_dd.value = '0' + form.start_dd.value;
     if (form.start_yy.value.length==1)  form.start_yy.value = '0' + form.start_yy.value;

     // if the end date is empty use the start date.
     if (form.end_mm.value.length==0 && form.end_dd.value.length==0 && form.end_yy.value.length==0)
          {
          form.end_mm.value = form.start_mm.value;
          form.end_dd.value = form.start_dd.value;
          form.end_yy.value = form.start_yy.value;
          }
     else
          {
          if (form.end_mm.value.length==1)  form.end_mm.value = '0' + form.end_mm.value;
          if (form.end_dd.value.length==1)  form.end_dd.value = '0' + form.end_dd.value;
          }
          if (form.end_yy.value.length==1)  form.end_yy.value = '0' + form.end_yy.value;

     var startdate = form.start_mm.value + '/' + form.start_dd.value + '/' + form.start_yy.value;
     var enddate = form.end_mm.value + '/' + form.end_dd.value + '/' + form.end_yy.value;

	var active = (form.active.checked == true) ? 1 : 0;

     if (!validateSurveyForm(form,startdate,enddate))
          return false;

	var url = 'modules.php?mod=adminsurveys&req=insertsurvey'+
			'&title='+encodeURIComponent(form.title.value)+
			'&group='+encodeURIComponent(form.group.value)+
			'&body='+encodeURIComponent(form.body.value)+
			'&startdate='+encodeURIComponent(startdate)+
			'&enddate='+encodeURIComponent(enddate)+
			'&active='+active;

	ret = serverFunction(url);
	alert('Your survey has been added.');
	surveysDefaultDisplay();
}

function editSurvey(id)
{
	var url = 'modules.php?mod=adminsurveys&req=editsurvey&id='+id;
	displayText('maincontent',url);
}

function updateSurvey()
{
	var form = document.getElementById('survey_form');

     // prepend '0' if only a single digit entered.
     if (form.start_mm.value.length==1)  form.start_mm.value = '0' + form.start_mm.value;
     if (form.start_dd.value.length==1)  form.start_dd.value = '0' + form.start_dd.value;
     if (form.start_yy.value.length==1)  form.start_yy.value = '0' + form.start_yy.value;

     // if the end date is empty use the start date.
     if (form.end_mm.value.length==0 && form.end_dd.value.length==0 && form.end_yy.value.length==0)
          {
          form.end_mm.value = form.start_mm.value;
          form.end_dd.value = form.start_dd.value;
          form.end_yy.value = form.start_yy.value;
          }
     else
          {
          if (form.end_mm.value.length==1)  form.end_mm.value = '0' + form.end_mm.value;
          if (form.end_dd.value.length==1)  form.end_dd.value = '0' + form.end_dd.value;
          }
          if (form.end_yy.value.length==1)  form.end_yy.value = '0' + form.end_yy.value;

     var startdate = form.start_mm.value + '/' + form.start_dd.value + '/' + form.start_yy.value;
     var enddate = form.end_mm.value + '/' + form.end_dd.value + '/' + form.end_yy.value;

	var active = (form.active.checked == true) ? 1 : 0;

     if (!validateSurveyForm(form,startdate,enddate))
          return false;

	var url = 'modules.php?mod=adminsurveys&req=updatesurvey'+
			'&surveyid='+encodeURIComponent(form.surveyid.value)+
			'&title='+encodeURIComponent(form.title.value)+
			'&group='+encodeURIComponent(form.group.value)+
			'&body='+encodeURIComponent(form.body.value)+
			'&startdate='+encodeURIComponent(startdate)+
			'&enddate='+encodeURIComponent(enddate)+
			'&active='+active;
	ret = serverFunction(url);
	alert('Your survey has been updated.');
	surveysDefaultDisplay();
}

function deleteSurvey(id)
{
	if (confirm('Do you want to delete this survey?'))
		{
		var url = 'modules.php?mod=adminsurveys&req=deletesurvey&id='+id;
		serverFunction(url);
		}
	displaySurveys();
}

function toggleSurveyActive(id)
{
	var url = 'modules.php?mod=adminsurveys&req=toggleactive&id='+id;
	ret = serverFunction(url);
	if (ret.indexOf("0") != -1)
		alert("The survey has been deactivated.\nIt will not be accessible.");
	else
		alert("The survey has been activated.\nIt will now be accessible.");
	return false;
}

function displaySurveyQuestions(id)
{
	var url = 'modules.php?mod=adminsurveys&req=displayquestions&id='+id;
	displayText('maincontent',url);
}

function insertSurveyQuestion()
{
	var form = document.getElementById('question_form');
	var sid = form.surveyid.value;
	if (thisSurveyActive(sid))
		return false;
	if (isEmpty(form.question) && isEmpty(form.answers) && isEmpty(form.essay))
		{
		alert('You must supply either a multiple choice question with answers or an essay question.');
		return false;
		}

	// check if this is an update and not an insert.
	if (document.getElementById('submit').value == 'Update Question')
		{
		document.getElementById('submit').value = 'Insert Question';
		var url = 'modules.php?mod=adminsurveys&req=updatequestion'+
			'&questionid='+encodeURIComponent(form.questionid.value)+
			'&question='+encodeURIComponent(form.question.value)+
			'&answers='+encodeURIComponent(form.answers.value)+
			'&essay='+encodeURIComponent(form.essay.value);
		}
	else
		{
		var url = 'modules.php?mod=adminsurveys&req=insertquestion'+
			'&surveyid='+encodeURIComponent(form.surveyid.value)+
			'&question='+encodeURIComponent(form.question.value)+
			'&answers='+encodeURIComponent(form.answers.value)+
			'&essay='+encodeURIComponent(form.essay.value);
		}
	ret = serverFunction(url);
	displaySurveyQuestions(form.surveyid.value);
	return false;
}

function deleteSurveyQuestion(id,sid)
{
	if (thisSurveyActive(sid))
		return false;
	if (confirm('Delete this question?'))
		{
		var url = 'modules.php?mod=adminsurveys&req=deletequestion'+
				'&id='+id+
				'&sid='+sid;
		ret = serverFunction(url);
		displaySurveyQuestions(sid);
		}
	return false;
}

function moveSurveyQuestion(thisrec,newpos,otherrec,otherpos,sid)
{
	if (thisSurveyActive(sid))
		return false;
     var url='modules.php?mod=adminsurveys&req=movequestion'+
                         '&rec1='+thisrec+
                         '&pos1='+newpos+
                         '&rec2='+otherrec+
                         '&pos2='+otherpos;
     ret=serverFunction(url);
	displaySurveyQuestions(sid);
}

function editSurveyQuestion(id,sid)
{
	if (thisSurveyActive(sid))
		return false;
	var url = 'modules.php?mod=adminsurveys&req=questiondata&id='+id;
	var question_data = serverFunction(url);
	question_data = ltrim(question_data);
	var question_parts = question_data.split('~');
	document.getElementById('question').value = question_parts[0];
	document.getElementById('answers').value = question_parts[1];
	document.getElementById('essay').value = question_parts[2];
	document.getElementById('questionid').value = id;

	// button value also used in insertQuestion function to signal this is an update.
	document.getElementById('submit').value = 'Update Question';
	return false;
}

function displaySurveyResults(id)
{
	var url = 'modules.php?mod=adminsurveys&req=results&id='+id;
	displayText('maincontent',url);
}

function thisSurveyActive(id)
{
	var sql = 'modules.php?mod=adminsurveys&req=isactive&id='+id;
	ret = serverFunction(sql);
	if (ret.indexOf('***active_survey***') != -1)
		{
		alert('This survey is active. Active surveys cannot be modified');
		return true;
		}
	return false;
}

function essayQuestionResponses(id)
{
	 window.open('modules.php?mod=adminsurveys&req=responses&id='+id,'win',
                              'left=40,top=40,width=500,height=400,toolbar=0,resizable=1,scrollbars=1');

}

function validateSurveyForm(form,startdate,enddate)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.title))
          {
          error_message = error_message + "\t\nTitle is missing.";
          errors=1;
          }
     if (isEmpty(form.body))
          {
          error_message = error_message + "\t\nDescription is missing.";
          errors=1;
          }
     if (form.group.value == 0)
          {
          error_message = error_message + "\t\nGroup is not selected.";
          errors=1;
          }
     if (startdate=='//')
          {
          error_message = error_message + "\t\nStart date is missing.";
          errors=1;
          }
     else
          {
          if (!isDate(startdate))
               {
               error_message = error_message + "\t\nStart date is invalid.";
               errors=1;
               }
          }
     if (enddate=='//')
          {
          error_message = error_message + "\t\nEnd date is missing.";
          errors=1;
          }
     else
          {
          if (!isDate(enddate))
               {
               error_message = error_message + "\t\nEnd date is invalid.";
               errors=1;
               }
          }
     if (errors==0)
          return true;
     alert(error_message);
     return false; 
}function displayUsers()
{
     var url='modules.php?mod=adminusers';
     displayText('maincontent',url);           
     return false;
}
function displayMembersView()
{
     var url='modules.php?mod=adminusers&mvt=members';
     displayText('maincontent',url);           
     return false;
}


function displayVolunteersView()
{
     var url='modules.php?mod=adminusers&mvt=volunteers';
     displayText('maincontent',url);           
     return false;
}

function displayUsersPage(pageno)
{
     url='modules.php?mod=adminusers&pageno='+pageno+userFilterURL();
     displayText('maincontent',url);
} 

function addUser()
{
	// check for super user and count selected clients.
	// only allow an add if one client site is selected.
	if (document.getElementById('multiclients'))
		{
		var obj = document.getElementById('multiclients');
		for ( x = 0, i = 0; x <  obj.options.length; x++)
			{
			if (obj.options[x].selected)
				i++;
			}
		if (i != 1)
			{
			alert('You must have only one client selected to add a record.');
			return false;
			}
		}
	
     var url='modules.php?mod=adminusers&req=add';
     displayText('maincontent',url);           
     return false;
}

function insertUser()
{
     var form = document.getElementById('userform');

     if (!validateUserForm(form))
          return false;

	var blog = (form.blog.checked==true ? 1 : 0);
	var unsubscribe = (form.unsubscribe.checked==true ? 1 : 0);
     var url='modules.php?mod=adminusers&req=insert'+
               '&first='+encodeURIComponent(form.first.value)+
               '&last='+encodeURIComponent(form.last.value)+
               '&company='+encodeURIComponent(form.company.value)+
               '&title='+encodeURIComponent(form.title.value)+
               '&passwd='+encodeURIComponent(form.pass1.value)+
               '&addr1='+encodeURIComponent(form.addr1.value)+
               '&addr2='+encodeURIComponent(form.addr2.value)+
               '&city='+encodeURIComponent(form.city.value)+
               '&state='+encodeURIComponent(form.state.value)+
               '&zip='+encodeURIComponent(form.zip.value)+
               '&phone='+encodeURIComponent(form.phone.value)+
               '&fax='+encodeURIComponent(form.fax.value)+
               '&joindate='+encodeURIComponent(form.joindate.value)+
               '&expiredate='+encodeURIComponent(form.expiredate.value)+
			'&paydate='+encodeURIComponent(form.paydate.value)+
			'&lastactivity='+encodeURIComponent(form.lastactivity.value)+
               '&email='+encodeURIComponent(form.email.value)+
			'&blog='+encodeURIComponent(blog)+
			'&unsubscribe='+encodeURIComponent(unsubscribe)+
               '&group='+encodeURIComponent(form.group.value);
     url = url + addCheckboxesURL() + customFieldValues(form);

	// add any volunteer check boxes.
	if (document.getElementById('norows'))
		{
		if (document.getElementById('norows'))
			{
			var norows = document.getElementById('norows').value;
			for (x = 0, i = 0; x < norows; x++)
				{
				if (document.getElementById('volunteer'+x).checked)
					{
					url = url + '&volid'+i+'='+document.getElementById('volunteer'+x).value;
					i++;
					}
				}
			url = url + '&novolrows='+i;
			}
		}

     ret = serverFunction(url);
     displayUsers();
     return false;
}

function customFieldValues(form)
{
     var nofields = form.custom_field_count.value;
     if (nofields == 0)
          return '&nocustomfields=0';

     var x;
     var url = '&nocustomfields='+nofields;
     url = url + '&formid='+form.formid.value;
     for (x = 0; x < nofields; x++)
          {
          var ftype = document.getElementById('field'+x).type;
          switch (ftype)
               {
               case 'text':
               case 'select-one':
               case 'textarea':
                    url = url + '&fieldid'+x+'='+encodeURIComponent(document.getElementById('fieldid'+x).value);
                    url = url + '&field'+x+'='+encodeURIComponent(document.getElementById('field'+x).value);
                    break;
               case 'checkbox':
                    url = url + '&fieldid'+x+'='+encodeURIComponent(document.getElementById('fieldid'+x).value);
                    if (document.getElementById('field'+x).checked == true)
                         url = url + '&field'+x+'=1';
                    else
                         url = url + '&field'+x+'=0';
                    break;
               }
          }
// alert(url);
     return url;
}

function editUser(userid)
{
     var url='modules.php?mod=adminusers&req=edit&userid='+userid;
     displayText('maincontent',url);           
     return false;
}

function updateUser()
{
     var form = document.getElementById('userform');
     if (!validateUserForm(form))
          return false;
	var blog = (form.blog.checked==true ? 1 : 0);
	var unsubscribe = (form.unsubscribe.checked==true ? 1 : 0);
     var url='modules.php?mod=adminusers&req=update'+
			'&userid='+encodeURIComponent(form.userid.value)+
               '&first='+encodeURIComponent(form.first.value)+
               '&last='+encodeURIComponent(form.last.value)+
               '&company='+encodeURIComponent(form.company.value)+
			'&title='+encodeURIComponent(form.title.value)+
               '&passwd='+encodeURIComponent(form.pass1.value)+
               '&addr1='+encodeURIComponent(form.addr1.value)+
               '&addr2='+encodeURIComponent(form.addr2.value)+
               '&city='+encodeURIComponent(form.city.value)+
               '&state='+encodeURIComponent(form.state.value)+
               '&zip='+encodeURIComponent(form.zip.value)+
               '&phone='+encodeURIComponent(form.phone.value)+
               '&fax='+encodeURIComponent(form.fax.value)+
               '&joindate='+encodeURIComponent(form.joindate.value)+
               '&expiredate='+encodeURIComponent(form.expiredate.value)+
			'&paydate='+encodeURIComponent(form.paydate.value)+
			'&lastactivity='+encodeURIComponent(form.lastactivity.value)+
               '&email='+encodeURIComponent(form.email.value)+
			'&blog='+encodeURIComponent(blog)+
			'&unsubscribe='+encodeURIComponent(unsubscribe)+
               '&group='+encodeURIComponent(form.group.value);

     url = url + addCheckboxesURL() + customFieldValues(form);

	// add any volunteer check boxes.
	if (document.getElementById('norows'))
		{
		var norows = document.getElementById('norows').value;
		for (x = 0, i = 0; x < norows; x++)
			{
			if (document.getElementById('volunteer'+x).checked)
				{
				url = url + '&volid'+i+'='+document.getElementById('volunteer'+x).value;
				i++;
				}
			}
		url = url + '&novolrows='+i;
		}
     ret = serverFunction(url);
     displayUsers();
     return false;
}

function deleteUser(id,who)
{
     if (id == who)
          {
          alert('You cannot delete your own account.');
          return false;
          }
     if (id==1)
          {
          alert('You cannot delete a root user.');
          return false;
          }
	url = 'modules.php?mod=adminusers&req=tickets&userid='+id;
	ret = serverFunction(url);
	if (ret.indexOf('true') > -1)
		{
          alert("This person has bought show tickets. To maintain database integrity\n"+
			  "users who have purchased tickets cannot be deleted. If you must delete\n"+
			  "this record contact your site administrator for assistance.");
		return false;
		}

     if (confirm("Are you sure you want to delete this record"))
          {
          url='modules.php?mod=adminusers&req=delete&id='+id;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=adminusers');         
          }
     return false;
}

function setUserSearchFilter()
{
     var url = 'modules.php?mod=adminusers'+userFilterURL('members',0);
     displayText('maincontent',url);
     var filter = document.getElementById('userfilter');
     filter.focus();

     // check for IE, extra code needed to keep focus on filter field.
      if (window.ActiveXObject) {
        var txtRange = filter.createTextRange();
        txtRange.moveStart( "character", filter.value.length);
        txtRange.moveEnd( "character", 0 );
        txtRange.select();
      }		
}

function setVolunteerSearchFilter(rowno)
{
     var url = 'modules.php?mod=adminusers'+userFilterURL('volunteers',rowno);
     displayText('maincontent',url);
     var filter = document.getElementById('userfilter');
     filter.focus();

     // check for IE, extra code needed to keep focus on filter field.
      if (window.ActiveXObject) {
        var txtRange = filter.createTextRange();
        txtRange.moveStart( "character", filter.value.length);
        txtRange.moveEnd( "character", 0 );
        txtRange.select();
      }
}

function userFilterURL(view_type,rowno)
{
     var filterdata = document.getElementById('userfilter').value;
     var field = document.getElementById('filterfield').value;

     var url='&filter='+encodeURIComponent(filterdata)+
             '&field='+encodeURIComponent(field);

     // put check box values for any optional field check boxes from bsp_users
	if (view_type == 'members')
		url = url + addCheckboxesURL();
	else 
		url = url + addVolunteersCheckboxesURL(rowno);

	// add clientID values if a super user is logged in and viewing multiple sites.
	url = url + familyClientIDValues();
     return url;
}

function addCheckboxesURL()   
{
     var url='';
     for (x = 1; x <= 5; x++)
          {
          if (document.getElementById('chkbox'+x))
               {
               if (document.getElementById('chkbox'+x).checked == true)
                    url = url + '&chkbox'+x+'=1';
               else
                    url = url + '&chkbox'+x+'=0';
               }
          else
               url = url + '&chkbox'+x+'=0';
          }
     return url;
}


function addVolunteersCheckboxesURL(rowno)
{
	if (! document.getElementById('norows'))
		return '';
	var url='';
	var norows = document.getElementById('norows').value;
	for (x = 0, i = 0; x < norows; x++)
		{

		if (document.getElementById('volunteer'+x).checked)
			{
			url = url + '&chkbox'+x+'=1';
			url = url + '&volid'+x+'='+document.getElementById('volunteer'+x).value;
			i++;
			}
		}
	url = url + '&novolrows='+norows;
	return url;
}

function familyClientIDValues()
{
	// super user client select might not be present. 
	if ( ! document.getElementById('multiclients'))
		return '';

	var ids = '';
	var i = 0;
	var obj = document.getElementById('multiclients');
	for ( x = 0; x <  obj.options.length; x++)
		{
		if (obj.options[x].selected)
			{
			ids = ids + '&clientidval'+i+'='+obj.options[x].value;
			i++;
			}
		}
	ids = ids + '&noclientids='+i;
	return ids;
}


function printUserReport(report)
{
     if (report == 0)
          return false;

     switch (report)
          {
          case 'labels':
               var url = 'modules.php?mod=adminusers&req=labels';
               if ( ! confirm("You've selected to print mailing labels.\nLoad Avery 5160/8160 labels into you printer\nand then select Print from the window menu."))
                    return false;
               break;
          case 'list':
               var url = 'modules.php?mod=adminusers&req=list';
               if ( ! confirm("You've selected to print a members list. Press OK to print or Cancel.\nWhen the window with your list appear select Print from the window menu."))
                    return false;
               break;
          case 'export':
               var url = 'modules.php?mod=adminusers&req=export';
               if ( ! confirm("You've selected to export a members list. Press OK to export or Cancel."))
                    return false;
               ret = trim(serverFunction(url));
			// confirm('Your file has been created. You may now either open or save your file.');
			window.location.href = '/system/user_download_utility.php?filename='+encodeURIComponent(ret);
			return false;
          }
     var win = window.open(url,'win','left=40,top=40,width=980,height=600,menubar=1,resizable=1,scrollbars=1'); 
     //win.print();
}

function setValueTodaysDate(id)
{
	var date = new Date();
	var d  = date.getDate();
	var day = (d < 10) ? '0' + d : d;
	var m = date.getMonth() + 1;
	var month = (m < 10) ? '0' + m : m;
	var yy = Date().substring(13,15);
	document.getElementById(id).value = month + "/" + day + "/" + yy;
}

function validateUserForm(form)
{
     var error_message = "The following required fields are missing:";
     var errors=0;

     // if this is an update only check password if they entered data.
     if (form.userid.value==0 || (form.userid.value > 0 && ! isEmpty(form.pass1)) )
          {
           if (form.group.value == 0)
          {
          error_message = error_message + "\n\n\tYou must select a group";
          errors=1;
          }
          if (isEmpty(form.first))
          {
          error_message = error_message + "\n\tFirst Name";
          errors=1;
          }
           if (isEmpty(form.last))
          {
          error_message = error_message + "\n\tLast Name";
          errors=1;
          }
          if (isEmpty(form.pass1))
               {
               error_message = error_message + "\n\tPassword 1";
               errors=1;
               }

          if (isEmpty(form.pass2))
               {
               error_message = error_message + "\n\tPassword 2";
               errors=1;
               }
          if (form.pass1.textLength < 5 || form.pass2.textLength < 5)
               {
               error_message = error_message + "\n\tPassword must be minimum 5 characters.";
               errors=1;
               } 
          if (form.pass1.value != form.pass2.value)
               {
               error_message = error_message + "\n\tPassword entries do not match.";
               errors=1;
               }
          if (isEmpty(form.addr1))
               {
               error_message = error_message + "\n\tAddress 1";
               errors=1;
               }
         if (isEmpty(form.city))
               {
               error_message = error_message + "\n\tCity";
              errors=1;
             }
           if (form.state.value == 0)
             {
          	error_message = error_message + "\n\tState is missing";
         	 errors=1;
             }  
          if (isEmpty(form.zip))
               {
               error_message = error_message + "\n\tzip";
               errors=1;
               }
          } 

	if (form.group.value == 0)
		{
		error_message = error_message + "\n\n\tYou must select a group";
		errors=1;
		}
/*
     if (!validEmail(form.email.value) && !isEmpty(form.email))
          {
          error_message = error_message + "\t\nEmail is formatted incorrectly";
          errors=1;
          }
*/
     if (errors==0)
          return true;
     alert(error_message);
     return false;       
}

// ************** CONFIGURATION FUNCTIONS **************

function usersConfiguration()
{
     var url='modules.php?mod=adminusers&req=config';
     displayText('maincontent',url);           
     return false;
}

function saveUserConfiguration()
{
	var form = document.getElementById('userconfigform');
	var url = 'modules.php?mod=adminusers&req=saveconfig'+
			'&addr_or_company='+form.addr_or_company.value;
	ret = serverFunction(url);
	displayUsers();
}

// ************** USER NOTES **************

function displayUserNotes(id)
{
	var url = 'modules.php?mod=adminusers&req=usernotes&id='+id;
	displayText('maincontent',url);
}

function saveUserNote(id)
{
	var newnote = document.getElementById('newnote').value;
	var url = 'modules.php?mod=adminusers&req=insertnote'+
			'&note='+encodeURIComponent(newnote)+
			'&id='+id;
	ret = serverFunction(url);
	displayUserNotes(id);
}

// ************** BROADCAST EMAILS FROM THE DATABASE **************
function createCustomEmailAlert()
{
	var broadcast = document.getElementById('emailalert').value;
	if (broadcast == '')
		{
		alert('You must supply a name for your broadcast list');
		return false;
		}
	var url = 'modules.php?mod=adminusers&req=broadcast&name='+encodeURIComponent(broadcast);
	ret = serverFunction(url);
	if (confirm("A list for email broadcast has been created form the current data set.\nPress OK below to go to the email alert module and send\nthe emails, or Cancel to remain here."))
		{
		menuclick('u','0','adminemailalerts',2);
		}
	return false;
}
function volunteerCategories()
{
     displayText('maincontent','modules.php?mod=adminvolunteercats');
     return false;
}

function addVolunteerCategory(form)
{
     if (isEmpty(form.category))
          {
          alert('You must enter a category');
          return false;
          }
     var url='modules.php?mod=adminvolunteercats&req=insertcat&category='+encodeURIComponent(form.category.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminvolunteercats&req=categories');
}

function deleteVolunteerCagetory(catid,category)
{
     if (confirm("Are you sure you want to delete this category?"))
          {
          var url='modules.php?mod=adminvolunteercats&req=deletecat&catid='+catid;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=adminvolunteercats');
          }
     return false;
}

function editVolunteerCategory(catid)
{
     var formid=document.getElementById('volunteer_category_form');
     formid.onsubmit=function() {
          return updateVolunteerCategory(this);
     }
     var catid_field=document.getElementById('catid_field');
     catid_field.value=catid;
     
     var field=document.getElementById('category');
     var url='modules.php?mod=adminvolunteercats&req=catname&catid='+catid;
     ret=serverFunction(url);

     // for some reason the cat name is coming through with a left padded space.
     // the trim function was places in functions.js.
     field.value=leftTrim(ret);
}

function updateVolunteerCategory(form)
{
     var url='modules.php?mod=adminvolunteercats&req=updatecat'+
                    '&catid='+encodeURIComponent(form.catid.value)+
                    '&category='+encodeURIComponent(form.category.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=adminvolunteercats');
     return false;
}function listVolunteers()
{
     displayText('maincontent','modules.php?mod=adminvolunteers');
     return false;
}

function  AboutDisplay()
{
     var url='modules.php?mod=ajax&req=About';
     displayText('maincontent',url);
     return false
}

function emailContact(contactid)
{
     var url='modules.php?mod=ajax&req=contactemailform&id='+contactid;
     displayText('maincontent',url);           
     // $('popup_space').show();

     // hide 'sent' message.
     var email_contact_sent = document.getElementById('email_contact_sent'); 
     email_contact_sent.style.display='none';
     return false;
}

function sendContactEmail(form)
{
     if (!validateContactEmailForm(form))
          return false;

	var url='modules.php';
	var args =	'mod=ajax'+     
				'&req=sendcontactemail'+
				'&contactid='+encodeURIComponent(form.contactid.value)+
				'&from='+encodeURIComponent(form.from.value)+
				'&subject='+encodeURIComponent(form.subject.value)+
				'&message='+encodeURIComponent(form.message.value);
	
	ret = serverFunctionPOST(url,args);
          
     // show 'sent' message and hide the form.
     var email_contact_form = document.getElementById('email_contact_form'); 
     var email_contact_sent = document.getElementById('email_contact_sent'); 
     email_contact_sent.style.display='';
     email_contact_form.style.display='none';
     return false;
}



function validateContactEmailForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;

     if (isEmpty(form.subject))
          {
          error_message = error_message + "\t\nSubject is missing";
          errors=1;
          }
     if (isEmpty(form.from))
          {
          error_message = error_message + "\t\nYour email is missing";
          errors=1;
          }

     if (isEmpty(form.message))
          {
          error_message = error_message + "\t\nMessage is missing";
          errors=1;
          }


     if (errors==0)
          return true;
     alert(error_message);
     return false;    
}
function displayAnnouncements()
{
     var url='modules.php?mod=announcements';
     displayText('maincontent',url);           
     return false;

}
function addAnnouncement()
{
     var url='modules.php?mod=announcements&req=add';
     displayText('maincontent',url);               
     return false;
}

function insertAnnouncement(form)
{
     if (!validateAnnouncementForm(form))
          return false;

     var url='modules.php?mod=announcements&req=insert'+              
               '&headline='+encodeURIComponent(form.headline.value)+
               '&body='+encodeURIComponent(form.body.value)+
               '&link_text='+encodeURIComponent(form.link_text.value)+
               '&link_url='+encodeURIComponent(form.link_url.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=announcements'); 
     announcements();   
     return false;
}

function editAnnouncement(annid)
{
     var url='modules.php?mod=announcements&req=edit&annid='+annid;
     displayText('maincontent',url);           
     return false;
}

function updateAnnouncement(form)
{
     if (!validateAnnouncementForm(form))
          return false;
     var url='modules.php?mod=announcements&req=update'+
               '&annid='+encodeURIComponent(form.annid.value)+                  
               '&headline='+encodeURIComponent(form.headline.value)+
               '&body='+encodeURIComponent(form.body.value)+
               '&link_text='+encodeURIComponent(form.link_text.value)+
               '&link_url='+encodeURIComponent(form.link_url.value);
     ret=serverFunction(url);
     displayText('maincontent','modules.php?mod=announcements');
     announcements();    
     return false;
}

function deleteAnnouncement(annid)
{
     if (confirm('Are you sure you want to delete this announcement?'))
          {
          var url='modules.php?mod=announcements&req=delete&annid='+annid;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=announcements'); 
          // refresh the block.
          announcements();   
          }
     return false;
}


function validateAnnouncementForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;

     if (isEmpty(form.headline))
          {
          error_message = error_message + "\t\nHeadline is missing";
          errors=1;
          }
     if (isEmpty(form.body))
          {
          error_message = error_message + "\t\nThe accouncement is missing";
          errors=1;
          }

     if (errors==0)
          return true;
     alert(error_message);
     return false;    

}
function validateActorForm(form)
{
	var error_message = "The following required fields are missing:";
	var errors=0;
	
	if (isEmpty(form.first))
		{
		error_message = error_message + "\nFirst Name";
		errors=1;
		}
	if (isEmpty(form.last))
		{
		error_message = error_message + "\nLast Name";
		errors=1;
		}
	if (isEmpty(form.addr1))
		{
		error_message = error_message + "\nStreet Address";
		errors=1;
		}
	if (isEmpty(form.city))
		{
		error_message = error_message + "\nCity";
		errors=1;
		}
	if (form.state.value==0)
		{
		error_message = error_message + "\nState";
		errors=1;
		}
	if (isEmpty(form.zip))
		{
		error_message = error_message + "\nZip Code";
		errors=1;
		}
	else if (form.zip.textLength < 5)
		{
		error_message = error_message + "\nZip Code must be minimum 5 characters.";
		errors=1;
		}
	if (isEmpty(form.phone))
		{
		error_message = error_message + "\nHome Phone";
		errors=1;
		}
	else if (form.phone.textLength < 7)
		{
		error_message = error_message + "\nHome Phone must be minimum 7 characters.";
		errors=1;
		}
	if (isEmpty(form.email))
		{
		error_message = error_message + "\nEmail Address";
		errors=1;
		}
	else if (!validateEmail(form.email.value))
		{
		error_message = error_message + "\n\tEmail address is incorrectly formatted";
		errors=1;
		}
	else if (form.email.value != form.email_cache.value)
		{
		if (!checkEmailAddress(form.email.value))
			{
			error_message = error_message + "\n\tEmail address is already in use.";
			errors=1;
			}
		}
	if (isEmpty(form.age_min))
		{
		error_message = error_message + "\nAge Min";
		errors=1;
		}
	if (isEmpty(form.age_max))
		{
		error_message = error_message + "\nAge Max";
		errors=1;
		}
	else if (Number(form.age_max.value) < Number(form.age_min.value))
		{
		error_message = error_message + "\nAge Max must not be less than Age Min";
		errors=1;
		}
	if (isNaN(Number(form.age_min.value)))
		{
		error_message = error_message + "\nAge Min must be numeric";
		errors=1;
		}
	if (isNaN(Number(form.age_max.value)))
		{
		error_message = error_message + "\nAge Max must be numeric";
		errors=1;
		}
	if (form.height_feet.value==0)
		{
		error_message = error_message + "\nHeight Feet";
		errors=1;
		}
	if (isEmpty(form.weight))
		{
		error_message = error_message + "\nWeight";
		errors=1;
		}
	if (isNaN(Number(form.weight.value)))
		{
		error_message = error_message + "\nWeight must be numeric";
		errors=1;
		}

	if (errors==0)
		return true;
	alert(error_message);
	return false;
}

function validateRole(form)
{
	var error_message = "The following required fields are missing:";
	var errors=0;

	if (isEmpty(form.show))
		{
		error_message = error_message + "\nShow";
		errors=1;
		}
	if (isEmpty(form.company))
		{
		error_message = error_message + "\nCompany";
		errors=1;
		}
	if (isEmpty(form.date))
		{
		error_message = error_message + "\nDate";
		errors=1;
		}
	if (isEmpty(form.role))
		{
		error_message = error_message + "\nRole";
		errors=1;
		}

	if (errors==0)
		return true;
	alert(error_message);
	return false;
}

/*function emailAuditionConfirmation()
{
	if (confirm("Do you want to send an email confirmation?"))
		{
		url='modules.php?mod=audition&req=email';
		displayText('maincontent','url');         
		}
     	return false;
}*/function displayBlogMainPage(id,pageno)
{
	var url = 'modules.php?mod=blogs'+
			'&id='+id+
			'&pageno='+pageno;
	displayText('maincontent',url);
}

function displayBlogPost(id,pageno)
{
	var url = 'modules.php?mod=blogs&req=post'+
			'&id='+id+
			'&pageno='+pageno;
	displayText('maincontent',url);
}

function insertBlogComment(id,pageno)
{
	var form = document.getElementById('commentform');
	if (isEmpty(form.commentname) || isEmpty(form.commentemail) || isEmpty(form.commentbody))
		{
		alert('You must supply all three fields.');
		return false;
		}
	var url = 'modules.php?mod=blogs&req=insertcomment'+
			'&postid='+id+
			'&name='+encodeURIComponent(form.commentname.value)+
			'&email='+encodeURIComponent(form.commentemail.value)+
			'&body='+encodeURIComponent(form.commentbody.value);
	ret = serverFunction(url);
	if (ret.indexOf('pending') != -1)
		alert("Thank you for your comment.\nIt's been queued for approval.");
	else
		alert("Thank you for your comment.\nIt's now posted to the blog.");
	displayBlogPost(id,pageno);
}function displayCalendarPage(pageno, mode)
{
	
	url="modules.php?mod=calendarfulldisplay&pageno=" + pageno + "&dm=" + mode;
	displayText('maincontent',url);
	
}function displayLinks(kind)
{
	return;
	
     // make sure the right column is displayed. it might be off if an admin was updating tables.
     // var rc=document.getElementById('rightcontent');
     // rc.style.display='';
	 // RIGHT COLUMN ALWAYS DISPLAYED -- THIS IS VERY OLD

     // displays what kind of links passed in, i.e. boosters, sponsors or links.
     var url='modules.php?mod=schoolcontent&req='+kind;
     ret=displayText('maincontent',url);    
}

function popUpURL(url)
{
     window.open(url,'win','left=40,top=40,width=800,height=700,toolbar=0,resizable=1,scrollbars=1');

}


function displayRoster(sportid)
{
     var url='modules.php?mod=schoolcontent&req=roster&sportid='+sportid;
     ret=displayText('maincontent',url); 

}

function playerPopUp(playerid)
{
     var url='modules.php?mod=schoolcontent&req=playerpopup&playerid='+playerid;
     displayText('popup_space',url);           
     $('popup_space').show();  
     return false;

}

function displayEvents()
{
     var url='modules.php?mod=schoolcontent&req=events';
     ret=displayText('maincontent',url); 
}

function displayAlumni()
{
     var url='modules.php?mod=schoolcontent&req=alumni';
     ret=displayText('maincontent',url); 
}

function welcomeMessageForSport()
{
     var url='modules.php?mod=schoolcontent&req=welcome';
     ret=displayText('maincontent',url); 
}

function displayNewsArchives()
{
     var url='modules.php?mod=schoolcontent&req=archives';
     ret=displayText('maincontent',url); 
}

function displayArchivedStory(id)
{
     var url='modules.php?mod=schoolcontent&req=newsstory&newsid='+id+'&archived=1';
     ret=displayText('maincontent',url); 
}

function displayCoaches(id)
{
     var url='modules.php?mod=schoolcontent&req=coaches&id='+id;
     ret=displayText('maincontent',url); 
}function updateClientInfo()
{
     var form = document.getElementById('clientinfo');
     if (validateClientInfoForm(form)==false)
          return false;

     var url='modules.php?mod=clientinfo&req=update'+
               '&client='+encodeURIComponent(form.client.value)+
               '&addr1='+encodeURIComponent(form.addr1.value)+
               '&addr2='+encodeURIComponent(form.addr2.value)+
               '&city='+encodeURIComponent(form.city.value)+
               '&state='+encodeURIComponent(form.state.value)+
               '&zip='+encodeURIComponent(form.zip.value)+
               '&phone='+encodeURIComponent(form.phone.value)+
               '&fax='+encodeURIComponent(form.fax.value)+
               '&title='+encodeURIComponent(form.title.value)+
               '&description='+encodeURIComponent(form.description.value)+
               '&keywords='+encodeURIComponent(form.keywords.value);
     ret=serverFunction(url);

     displayText('maincontent','modules.php?mod=ajax&req=homepage');
     return false;
}



function validateClientInfoForm(form)
{    
     var error_message = "The following errors occurred";
     var errors=0;

     if (isEmpty(form.client))
          {
          error_message = error_message + "\nClient is missing";
          errors=1;
          }
     if (isEmpty(form.addr1))
          {
          error_message = error_message + "\nAddress 1 is missing";
          errors=1;
          }
     if (isEmpty(form.city))
          {
          error_message = error_message + "\nCity is missing";
          errors=1;
          }
     if (form.state.value==0)
          {
          error_message = error_message + "\nYou must select a state";
          errors=1;
          }
     if (isEmpty(form.zip))
          {
          error_message = error_message + "\nZip code is missing";
          errors=1;
          }    
     if (isEmpty(form.phone))
          {
          error_message = error_message + "\nPhone is missing";
          errors=1;
          }


            
     if (errors==0)
          return true;
     alert(error_message);
     return false;       
}
function loadConfigurationForm(form_name)
{
     var url ='modules.php?mod=configuration&req=load&form='+form_name;
     displayText('maincontent',url);
}

function updateSiteConfiguration(form)
{
     var url='modules.php?mod=configuration&req=update';
     for(i=0; i<form.elements.length-1; i++)
          url += '&'+form.elements[i].name+'='+form.elements[i].value;
     ret=serverFunction(url);
     url='modules.php?mod=configuration';
     displayText('maincontent',url);
     
     // update the quotes block if that's been changed.
     if (form.elements[0].name == 'quotes_block_title')
          displayText('quotes_block_title','modules.php?mod=ajax&req=quotestitle');
}function display_dsp_issues()
{
      var url='modules.php?mod=display_issues&req=insert';
      ret = serverFunction(url);
      document.getElementById('maincontent').innerHTML = ret;	     
}


   //  alert(error_message);
   
function deleteissue(issueid)
{
     if (confirm('Are you sure you want to delete this issue?'))
          {
          var url='modules.php?mod=display_issues&req=deleteissue&issueid='+issueid;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=display_issues');    
          }
     return false;
}

function displayIssuesPage(pageno)
{
     url='modules.php?mod=display_issues&pageno='+pageno;
     displayText('maincontent',url);
} 




function displayDocumentCategoriesForUsers()
{
     var url = 'modules.php?mod=documents';
     displayText('maincontent',url);
}

function displayDocumentsByCategory(catid)
{
     var url = 'modules.php?mod=documents&req=document&catid='+catid;
     displayText('maincontent',url);
}function displayDonationPage()
{
	var url = 'modules.php?mod=donations';
	displayText('maincontent',url);
}

function validateDonationForm()
{
	var donation = 0;
	var form = document.getElementById('donationform');
	
	// if buttons are present see if one is selected
	var buttons = document.getElementById('preset_donation');
	if (buttons)
		{
          for (var i = 0; i < form.preset_donation.length; i++)
			{
			// check for the other amount field containing a value, and if so check it.
			// this prevents people from entering an 'other' amount, but forgetting to check the button.
			if (form.other_amount.value != '' && form.preset_donation[i].value == 'other')
				{
				form.preset_donation[i].checked = true;
				form.preset_donation[i].value = form.other_amount.value;
				}
			}	

		for (var i = 0; i < form.preset_donation.length; i++)
			{
			if (form.preset_donation[i].checked == true)
				{
				if (form.preset_donation[i].value == 'other')
					{
					var other_amount = parseInt(form.other_amount.value);

					var other_min_amount = parseInt(document.getElementById('other_min_amount').value);
					if (other_amount < other_min_amount || form.other_amount.value == '')
						{
						alert('Your donatation amount must be at least $'+other_min_amount);
						document.getElementById('submit_button').style.background = 'white';
						return false;
						}
					donation = form.other_amount.value;
					}
				else
					{
					donation = form.preset_donation[i].value;
					}
				}
			}
		}

	// set the donation flag value if the field is displayed. it is turned off for PayPal.
	if (document.getElementById('start_date'))
		{
		start_date = document.getElementById('start_date').value;
		no_donations = document.getElementById('no_donations').value;
		if ( (start_date != '' && no_donations == '') || (start_date == '' && no_donations != '') )
			{
               alert("If you wish to make recurring donations you must\nsupply both start date and number the of donations.\nIf you wish to make only a one time donation leave both\nthese fields blank.");
			document.getElementById('submit_button').style.background = 'white';
			return false;
			}

		// check if bank account fields are displayed and a bank account is used. also check that at least one field is filled out
		// so that we also make sure both are filled out. if both bank account fields are empty drop down to check credit card fields.
		if ( document.getElementById('routing') )
          	{
               if ( (! isEmpty(form.routing) && isEmpty(form.account)) || (isEmpty(form.account) && !isEmpty(form.account)) )
				{				
				alert('You must supply both routing and account numbers to use a bank account.');
				document.getElementById('submit_button').style.background = 'white';
				return false;
				}
			else
				{
				if ( ! isEmpty(form.routing) && ! isEmpty(form.account) )
					return true;
				}
			}

		if (isEmpty(form.cardnumber) || isEmpty(form.cardname) || isEmpty(form.security) || form.exp_month.value==0 || form.exp_year.value==0)
			{
			alert('You must supply all credit card information.');
			document.getElementById('submit_button').style.background = 'white';
			return false;
			}

		var cardtype = form.cardtype[0].checked == true ? form.cardtype[0].value : form.cardtype[1].value;

		if ( ! isValidCreditCardNumber(form.cardnumber.value, cardtype))
			{
			if (cardtype == 'VISA')
				alert("\n\t** Card number is not a valid VISA number\n\t** Check the number and the type");
			else
				alert("\n\t** Card number is not a valid MASTERCARD number\n\t** Check the number and the type");
			document.getElementById('submit_button').style.background = 'white';
			return false;
			}
		} 		
	return true;
}

function resetDonationOtherAmount()
{
	document.getElementById('other_amount').value='';
	return false;
}function processAlertForm(form)
{
	
       if (!validateAlertForm(form))
       return false;

	var url='modules.php?mod=emailalerts&req=process'+
			'&email='+encodeURIComponent(form.email.value)+
			'&unsubscribe='+encodeURIComponent(form.unsubscribe.checked);
	displayText('maincontent',url);

	return false;
}

function validateAlertForm(form)
{ 
     var error_message = "The following errors occurred:\n";
     var errors=0;

     if (isEmpty(form.email))
          {
          error_message = error_message + "\t\nYou must supply an email address.";
          errors=1;
          }

     if (!validateEmail(form.email.value))
          {
          error_message = error_message + "\t\nEmail address is not formatted correctly.";
          errors=1;
          }

     if (errors==0)
          return true;
     alert(error_message);
     return false;    
}function event_registration(id)
{
	// default initial registration screen. 

	// close the pop up and call the server with the event ID.
	hideddrivetip();
	var url = 'modules.php?mod=eventregistration&id='+id;
	displayText('maincontent',url);
	return false;
}

function submit_event_registration(id)
{
	
	if (document.getElementById('paideventform'))
		var form = document.getElementById('paideventform');
	else
		form = 0;
	// put registration record in database and the server side will determine
	// if the event has a fee and determine CC processor.
	var url = 'modules.php?mod=eventregistration&req=submit&id='+id;

	// if the event is free register them now.
	if (form == 0)
		{
		ret = serverFunction(url);
		ret = trimAll(ret);
		url = 'modules.php?mod=eventregistration&req=resultpage&id='+id;
		displayText('maincontent',url);
		return false;
		}

	// append the user form if it is displayed.
	if (document.getElementById('userid').value == 0)
		{
		// user is not logged in so check email address to see if already in use.
		// if it is in the system they must either log in or contact client for help.
		if ( ! checkEmailAddress(form.email.value) && ! isEmpty(form.email))
			{
			alert("This email address is already in the database.\n\nIf you already have an account on the system log in using that account and register for the event.\n\nIf you do not have an account and this is your email address please contact us for help.");
			document.getElementById('submit').style.background = 'white';
			return false;
			}
		if ( ! validateEventRegistrationForm(form))
			{
			document.getElementById('submit').style.background = 'white';
			return false;
			}
		var newsletter = document.getElementById('newsletter').checked == true ? '1' : '0';
		url +=	'&first='+encodeURIComponent(form.first.value)+
				'&last='+encodeURIComponent(form.last.value)+
				'&email='+encodeURIComponent(form.email.value)+
				'&pass1='+encodeURIComponent(form.pass1.value)+
				'&addr1='+encodeURIComponent(form.addr1.value)+
				'&addr2='+encodeURIComponent(form.addr2.value)+
				'&city='+encodeURIComponent(form.city.value)+
				'&state='+encodeURIComponent(form.state.value)+
				'&zip='+encodeURIComponent(form.zip.value)+
				'&phone='+encodeURIComponent(form.phone.value)+
				'&newsletter='+encodeURIComponent(newsletter);
		}
	alert(	"If your registration fee on this screen is $0.00\n"+
               "your registration is complete.\n\n"+
			"If there is a fee for your registration the PayPal\n"+
			" window will appear when you click OK below.");
	ret = serverFunction(url);
	ret = trimAll(ret);
	var pieces = ret.split('|');
	switch (pieces[0])
		{
		case 'paypal':		// paypal comes back 'paypal|(url to paypal to process)
			window.open(pieces[1],'win','left=40,top=40,width=980,height=600,toolbar=0,resizable=1,scrollbars=1');
			var result = 'paypal';
			break;
		case 'display':	// sent back to server command to display results of processing on the server side.
			var result = pieces[1];
			break;
		default:
			document.getElementById('maincontent').innerHTML = ret;
		}
	if (document.getElementById('submit'))
		{
		document.getElementById('submit').style.background = 'white';
		}
	
	// display the result page based on what was returned from the server and processed above.
	url = 'modules.php?mod=eventregistration&req=resultpage&id='+id;
	displayText('maincontent',url);
	return false;
}

function validateEventRegistrationForm(form)
{

     var error_message = "The following errors occurred:";
     var errors=0;
     if (isEmpty(form.first))
          {
          error_message = error_message + "\n\tFirst name is missing";
          errors=1;
          }
     if (isEmpty(form.last))
          {
          error_message = error_message + "\n\tLast name is missing";
          errors=1;
          }  
     if (isEmpty(form.email))
          {
          error_message = error_message + "\n\tEmail is missing";
          errors=1;
          }
     else if (!validateEmail(form.email.value))
          {
          error_message = error_message + "\n\tEmail address is incorrectly formatted";
          errors=1;
          }
	if (document.getElementById('pass1'))
		{
		if (isEmpty(form.pass1))
			{
			error_message = error_message + "\n\tPassword 1 is missing";
			errors=1;
			}
		if (isEmpty(form.pass2))
			{
			error_message = error_message + "\n\tPassword 2 is missing";
			errors=1;
			}
		if (form.pass1.textLength < 5 || form.pass2.textLength < 5)
			{
			error_message = error_message + "\n\tPassword must be minimum 5 characters.";
			errors=1;
			} 
		if (form.pass1.value != form.pass2.value)
			{
			error_message = error_message + "\n\tPassword entries do not match.";
			errors=1;
			}   
		}
     if (errors==0)
          return true;
     alert(error_message);
     return false;  
}
function loadForums()
{
     var url='modules.php?mod=forums&req=loadforums';
     displayText('forumsmain',url);
}

function loadThreads(forumid)
{
     var url='modules.php?mod=forums&req=loadthreads&forumid='+forumid;
     displayText('forumsmain',url);
}

function loadPosts(threadid)
{
     var url='modules.php?mod=forums&req=loadposts&threadid='+threadid;
     displayText('forumsmain',url);
}

function addThread(forumid)
{
     // check permissions for to create a thread in this forum.
     var ret=serverFunction('modules.php?mod=forums&req=threadpermission&forumid='+forumid);
     if (ret!='')
          {
          alert(ret);
          }
     else
          {
          var url='modules.php?mod=forums&req=addthread&forumid='+forumid;
          displayText('forumsmain',url);
          }
}

function insertThread(form)
{
     var subject=form.subject.value;
     var body=escape(form.body.value);
     var forumid=form.forumid.value;
     if (subject=='' || body=='')
          {
          alert('You must supply both subject and body.');
          return false;
          }
     var url='modules.php?mod=forums&req=insertthread&forumid='+forumid+'&subject='+subject+'&body='+body;
     ret=serverFunction(url);
     loadThreads(forumid);
}

function addPost(threadid)
{
     // check permissions for to create a thread in this forum.
     var ret=serverFunction('modules.php?mod=forums&req=postpermission&threadid='+threadid);
     if (ret!='')
          {
          alert(ret);
          }
     else
          {
          var url='modules.php?mod=forums&req=addpost&threadid='+threadid;
          displayText('forumsmain',url);
          }
}

function insertPost(form)
{
     var body=escape(form.body.value);
     var threadid=form.threadid.value;
     if (body=='')
          {
          alert('You must supply the text of the post.');
          return false;
          }
     var url='modules.php?mod=forums&req=insertpost&threadid='+threadid+'&body='+body;
     ret=serverFunction(url);
     loadPosts(threadid);
}
function displayGallery()
{
     var url='modules.php?mod=gallery';
     displayText('maincontent',url);
}

function selectGalleryPhotos(id)
{
     // make sure an event was selected.
     if (id==0)
          return false;

     var url='modules.php?mod=gallery&req=displayphotos&eventid='+id;
     ret=serverFunction(url);

     if (ret.indexOf('No photos') != -1)
          {
          alert('There are no photos for this event.');
          displayText('maincontent','modules.php?mod=gallery');
          return false;
          } 

     // first display the drop down with the event that had the photo just added selected.
     displayText('maincontent','modules.php?mod=gallery&req=default&eventid='+id);  
   
     // display the photos for this event below the drop down.
     var photos=document.getElementById('photos');
     photos.innerHTML=ret;

     // reinitialize light box settings (image pop ups) for newly displayed images.
     initLightbox();
}

function addGalleryPhoto()
{
     var url='modules.php?mod=gallery&req=addphoto';
     displayText('maincontent',url);
     return false;     
}

function insertGalleryPhoto()
{
     var form = document.getElementById('galleryform');
     var image = document.getElementById('image_upload_filename').value;
     if ( ! checkImageExtension(image))
          {
          alert('You must upload only a JPG or GIF image');
          return false;
          }
     if (!validateGalleryPhotoForm(form,true))
          return false;
     var eventid=form.event.value;
     

     var url='modules.php?mod=gallery&req=insertphoto'+
                    '&eventid='+encodeURIComponent(eventid)+                    
                    '&title='+encodeURIComponent(form.title.value)+
                    '&caption='+encodeURIComponent(form.caption.value)+
                    '&image='+image;                                      
     ret=serverFunction(url);

     // first display the drop down with the event that had the photo just added selected.
     displayText('maincontent','modules.php?mod=gallery&req=default&eventid='+eventid); 
   
     // display the photos for this event below the drop down.
     displayText('photos','modules.php?mod=gallery&req=displayphotos&js=1&eventid='+eventid); 

     initLightbox();
     return false;
}

function hideGalleryPopUp()
{
     $('popup_container').hide();
     return false;

}


function editGalleryPhoto(galleryid)
{
     var url='modules.php?mod=gallery&req=editphoto&galleryid='+galleryid;
     ret=serverFunction(url);
     var maincontent=document.getElementById('maincontent');
     maincontent.innerHTML=ret;
     return false;
}

function updateGalleryPhoto()
{
     var form = document.getElementById('galleryform');
     if (!validateGalleryPhotoForm(form,false))
          return false;
     
     var eventid=form.event.value;
     var image = document.getElementById('image_upload_filename').value;
     var url='modules.php?mod=gallery&req=updatephoto'+
                    '&galleryid='+encodeURIComponent(form.galleryid.value)+
                    '&eventid='+encodeURIComponent(eventid)+                    
                    '&title='+encodeURIComponent(form.title.value)+
                    '&caption='+encodeURIComponent(form.caption.value)+
                    '&image='+image;
     ret=serverFunction(url);

     // first display the drop down with the event that had the photo just added selected.
     displayText('maincontent','modules.php?mod=gallery&req=default&eventid='+eventid);

    // display the photos for this event below the drop down.
     displayText('photos','modules.php?mod=gallery&req=displayphotos&js=1&eventid='+eventid);   
     initLightbox();
     return false;     
}

function deleteGalleryPhoto(galleryid,eventid)
{
     if (confirm('Are you sure you want to delete this photo?'))
          {
          var url='modules.php?mod=gallery&req=deletephoto&galleryid='+galleryid;
          ret=serverFunction(url);
          displayText('maincontent','modules.php?mod=gallery');    
          }
     // first display the drop down with the event that had the photo just deleted. 
     displayText('maincontent','modules.php?mod=gallery&req=default&eventid='+eventid); 
   
     // display the photos for this event below the drop down.
     displayText('photos','modules.php?mod=gallery&req=displayphotos&js=1&eventid='+eventid);

     // reinitialize light box settings (image pop ups) for newly displayed images.
     initLightbox();    
}

function displayLargePhoto(e,galleryid)
{
     var coords = getMousePosition(e);
     var left=parseInt(coords[0]);
     var top=parseInt(coords[1]);

     var IE = document.all?true:false;

     var image_dimensions=serverFunction('modules.php?mod=gallery&req=dimensions&galleryid='+galleryid);
     var dimensions = image_dimensions.split(',');
     var height = parseInt(dimensions[0]);
     var width = parseInt(dimensions[1]);              

     // get the pop with photo.
     var url='modules.php?mod=gallery&req=largeview&galleryid='+galleryid;
     displayText('popup_space',url);        

     // set the position of the pop up in the browser.
     var popup=document.getElementById('popup_panel');

     if (!IE)
          {
          left=left-width/2;
          top=top+height;
          }
     else
          {
          left=left-width/2;
          top=top-50;
          }
     
     popup.style.top=top+'px';
     popup.style.left=left+'px';

     // set the width of the pop up to match the photo width.
     var container=document.getElementById('popup_panel');
     image_width=parseInt(width)+10;
     container.style.width=image_width+'px'; 
       
     $('popup_space').show();
     return false;
}


function validateGalleryPhotoForm(form,image)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;

      if (isEmpty(form.title))
          {
          error_message = error_message + "\t\nYou must provide a title";
          errors=1;
          }
     // make sure only event OR sport selected, not both or none.
     if (form.event.value==0)
          {
          error_message = error_message + "\t\nYou must select an event.";
          errors=1;
          }


     // make sure an image has been uploaded if it is an add.
     if (image)
          {
          var image=document.getElementById('image_upload_filename');
          if (image.value=='')
               {
               error_message = error_message + "\t\nYou must upload an image";
               errors=1;
               }
          }
          

     if (errors==0)
          return true;
     alert(error_message);
     return false;  
}function insertIssue(form)
{
     if (! validateIssueForm(form))
          return false;

     var url='modules.php?mod=issues&req=insert'+
               '&summary='+encodeURIComponent(form.summary.value)+
               '&body='+encodeURIComponent(form.body.value);
     ret = serverFunction(url);
//alert(ret);
      document.getElementById('maincontent').innerHTML = ret;	
     // displayText('maincontent',url);       
}



function validateIssueForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;

     if (isEmpty(form.summary))
          {
          error_message = error_message + "\t\nSummary is missing";
          errors=1;
          }
     if (isEmpty(form.body))
          {
          error_message = error_message + "\t\nDescription is missing";
          errors=1;
          }
     if (errors==0)
          return true;
     alert(error_message);
     return false;   
}function displayLinkWindow(url)
{
     window.open('http://'+url,'win','left=40,top=40,width=900,height=700,toolbar=0,resizable=1,scrollbars=1');
}function displaymanualpage(filename)
{
     displayText('maincontent','modules.php?mod=manual&req=page&filename='+filename);    
}

function manualTOC()
{
     displayText('maincontent','modules.php?mod=manual');    
}

function updateMenu(form)
{
     var norecs=form.del.length;
     var url='modules.php?mod=menuedit&req=update&norecs='+norecs;

     // add each record in the loop to the URL.
     for (x=0; x < norecs; x++)
          {
          url+='&del'+x+'='+form.del[x].checked+
          '&parentid'+x+'='+form.parentid[x].value+
          '&group'+x+'='+form.group[x].value+
          '&title'+x+'='+form.title[x].value+
         // '&url'+x+'='+form.url[x].value+
          '&func'+x+'='+form.func[x].value+
          '&divno'+x+'='+form.divno[x].value+
          '&urlstr'+x+'='+form.urlstr[x].value+
          '&rightcolumn'+x+'='+form.rightcolumn[x].value+

          '&li'+x+'='+form.li[x].checked+
          '&lo'+x+'='+form.lo[x].checked+
          '&orderno'+x+'='+form.orderno[x].value+
          '&recno'+x+'='+form.recno[x].value;

          }
     // add the form fields at the bottom for a new record.
     url+='&x_parentid='+form.x_parentid.value+
     '&x_group='+form.x_group.value+
     '&x_title='+form.x_title.value+
     // '&x_url='+form.x_url.value+

          '&x_func'+x+'='+form.x_func.value+
          '&x_divno'+x+'='+form.x_divno.value+
          '&x_urlstr'+x+'='+form.x_urlstr.value+
          '&x_rightcolumn'+x+'='+form.x_rightcolumn.value+

     '&x_li='+form.x_li.checked+
     '&x_lo='+form.x_lo.checked+
     '&x_orderno='+form.x_orderno.value;

     // post the URL to the server.
     ret=serverFunction(url);

     // refresh the menu and the edit screen after the update to reflect changes.
     mainmenu();
     displayText('maincontent','modules.php?mod=menuedit');
     alert('The menu configuration has been upated.');
     return false;
}function displayNewsFrontPage()
{
     // make sure the right column is displayed. it might be off if an admin was updating tables.
     var rc=document.getElementById('rightcontent');
     rc.style.display='';

     var url='modules.php?mod=news';
     displayText('maincontent',url);
}

function displayNewsByCat(catid)
{
     // make sure the right column is displayed. it might be off if an admin was updating tables.
     var rc=document.getElementById('rightcontent');
     rc.style.display='';
     var url='modules.php?mod=news&catid='+catid;
     displayText('maincontent',url);
}

function displayNewsStory(newsid,catid)
{
     var url='modules.php?mod=news&req=newsstory'+
			'&newsid='+newsid+
			'&catid='+catid;
			
     ret=displayText('maincontent',url); 
}

function displayNewsArchives(pageno)
{
     var url='modules.php?mod=newsarchives&pageno='+pageno;
     displayText('maincontent',url); 
}

function displayArchivedStory(id,pageno)
{
	hideddrivetip();
     var url='modules.php?mod=newsarchives&req=story'+
			'&id='+id+
			'&pageno='+pageno;
     displayText('maincontent',url); 
}

function searchNewsArchives(fld)
{
	var fld = document.getElementById('search_field').value;
	var url='modules.php?mod=newsarchives&search='+fld;
	displayText('maincontent',url); 
}function toggleOpportunityShiftRole(id)
{
	var ischecked = document.getElementById('rolecheckbox'+id).checked;
	if (ischecked == true)
		alert("Thank you for volunteering with us.\n\nYou'll receive an email confirmation in your inbox shortly.");
	else
	     alert("You have been removed from volunteering for this role.\n\nYou'll receive an email confirmation in your inbox shortly.");

	var url = 'modules.php?mod=opportunities&req=toggleshift'+
			'&id='+id+
			'&insert='+ischecked;
	ret = serverFunction(url);
	return ischecked;
}function emailpassword(form)
{
     if (form.email.value=='')
          {
          alert('You must enter your email address.');
          return false;
          }
     var url='modules.php?mod=password&req=sendemail'+
               '&email='+form.email.value;
     //ret=serverFunction(url);
     displayText('maincontent',url);
     return false;
} 
function loadRegistrationForm(id)
{
     var url = 'modules.php?mod=register&form='+id;
     displayText('registration_form',url);
     return false;
}


function registerMember(form)
{
     if (!validateMemberRegistrationForm(form))
          return false;


	var newsletter = form.newsletter.checked == true ? 1 : 0;

	// check for a paid membership level.
	if (document.getElementById('membershiplevel'))
		{
		alert('When the PayPal window appears, if you wish to use your credit card click'+
		 ' the link under the text "Don\'t have a PayPal account?", and then continue your payment.');
		var membershiplevel = document.getElementById('membershiplevel').value;
		}
	else
		{
		var membershiplevel = -1;
		}

     var url = 'modules.php?mod=register&req=member'+
               '&gid='+encodeURIComponent(form.gid.value)+
               '&first='+encodeURIComponent(form.first.value)+    
               '&last='+encodeURIComponent(form.last.value)+ 
			'&company='+encodeURIComponent(form.company.value)+       
               '&email='+encodeURIComponent(form.email.value)+    
               '&pass1='+encodeURIComponent(form.pass1.value)+        
               '&addr1='+encodeURIComponent(form.addr1.value)+    
               '&addr2='+encodeURIComponent(form.addr2.value)+    
               '&city='+encodeURIComponent(form.city.value)+    
               '&state='+encodeURIComponent(form.state.value)+    
               '&zip='+encodeURIComponent(form.zip.value)+    
               '&phone='+encodeURIComponent(form.phone.value)+
			'&newsletter='+encodeURIComponent(newsletter)+
			'&regnotes='+encodeURIComponent(form.regnotes.value)+
			'&membershiplevel='+encodeURIComponent(membershiplevel);

	// check for volunteers. if they came from the volunteer button, at least
	// one category must be checked.
	if (form.norows.value > 0)
		{
		var vurl = '';
		for (x = 0, i = 0; x < form.norows.value; x++)
			{
			var volid = document.getElementById('volunteer'+x);
			if (volid.checked == true)
				{
				vurl = vurl + '&volid'+i+'='+volid.value;
				i++;
				}
			}
		// check if volunteering was required.
		if (form.volunteer.value == '1' && i == 0)
			{
			alert("You elected to volunteer but did not select a category.\nSelect your category and then resubmit.");
			return false;
			}
		vurl = vurl + '&norows='+i;
		url = url + vurl;
		}
	displayText('maincontent',url);
	if (membershiplevel != -1)
		{
		url = 'modules.php?mod=register&req=paypalurl&email='+encodeURIComponent(form.email.value);
		url = trim(serverFunction(url));
		window.open(url,'win','left=40,top=40,width=980,height=600,toolbar=0,resizable=1,scrollbars=1');
		}
     return false;
}


function validateMemberRegistrationForm(form)
{

     var error_message = "The following errors occurred:";
     var errors=0;
     if (isEmpty(form.first))
          {
          error_message = error_message + "\n\tFirst name is missing";
          errors=1;
          }
     if (isEmpty(form.last))
          {
          error_message = error_message + "\n\tLast name is missing";
          errors=1;
          }  
     if (isEmpty(form.email))
          {
          error_message = error_message + "\n\tEmail is missing";
          errors=1;
          }
     else if (!validateEmail(form.email.value))
          {
          error_message = error_message + "\n\tEmail address is incorrectly formatted";
          errors=1;
          }

     else if ( ! checkEmailAddress(form.email.value))
          {
          error_message = error_message + "\n\tEmail address is already in use.";
          errors=1;
          }
/*
     if (isEmpty(form.phone))
          {
          error_message = error_message + "\n\tPhone number is missing";
          errors=1;
          }
*/
     if (isEmpty(form.pass1))
          {
          error_message = error_message + "\n\tPassword 1 is missing";
          errors=1;
          }
     if (isEmpty(form.pass2))
          {
          error_message = error_message + "\n\tPassword 2 is missing";
          errors=1;
          }
     if (form.pass1.textLength < 5 || form.pass2.textLength < 5)
          {
          error_message = error_message + "\n\tPassword must be minimum 5 characters.";
          errors=1;
          } 
     if (form.pass1.value != form.pass2.value)
          {
          error_message = error_message + "\n\tPassword entries do not match.";
          errors=1;
          }
/*
     if (!checkCaptcha(form.captcha.value) || isEmpty(form.captcha))
          {
          error_message = error_message + "\n\tSecurity code must match displayed letters.";
          errors=1;
          }     
*/
     if (errors==0)
          return true;
     alert(error_message);
     return false;  
}

function checkEmailAddress(email)
{
     // build the URL to call to check if user name is already in use.
     var url="modules.php?mod=register&req=checkemail&email="+encodeURIComponent(email);
     ret=trim(serverFunction(url));
     if (ret.indexOf('false') != -1)
          {
          return false;
          }
     return true;
}

function checkCaptcha(captcha)
{
     var url="modules.php?mod=register&req=checkcaptcha&captcha="+captcha;
     ret=trim(serverFunction(url));
     if (ret=='false')
          {
          return false;
          }
     return true;
}
function createVirtualHostingFile()
{
    var url = 'modules.php?mod=rootutilities&req=vhost';
    if (trim(serverFunction(url)) == 'false')
        alert('Error creating virtual hosting file.');
    else
        alert('Virtual hosting file created');
    return false;
}function displayCurrentShows()
{
	var url='modules.php?mod=shows';
	displayText('maincontent',url);
}

function showTicketReservations(id)
{
	hideddrivetip();
	var url='modules.php?mod=shows&req=reservations&id='+id;
	displayText('maincontent',url);
	return false;
}

function populateTicketPricesForShowDate(dateid)
{

	// check for setting the date selector back to 'Select show date'.
	if (dateid == 0)
		{
          document.getElementById('ticket_price_block').innerHTML 
				= '<strong><font color="green">Select the show date to the left first. After you may select your tickets here.</font></strong>';
		return false;
		}

	// check the number of tickets available for this date.
	// warn if they are sold out, or if the tickets letft is less than max per person.
	var url = 'modules.php?mod=tickets&req=ticketsleft&id='+dateid;
	var ret = serverFunction(url);

	// check for past cutoff time for ticket sales, but tickets left.
	if (ret.indexOf('cutoff') != -1)
		{
//		var obj = document.getElementById('no_tickets');
//		obj.options.length = null;
//		obj.options[0] = new Option(0,0);
		alert("Tickets are no longer available on line, but may still be purchased at the box office.");
		return false;
		}

	var tickets = ret.split('|');
	if (tickets[1] < 1)
		{
//		var obj = document.getElementById('no_tickets');
//		obj.options.length = null;
//		obj.options[0] = new Option(0,0);
		alert("This date for this show is sold out.\n\nThere are no tickets available. You may choose another date.");
		return false;
		}

	// THIS IF ELSE BLOCK WILL SET THE NUMBER OF TICKETS AVAILABLE FOR SELECTION.
	if (parseInt(tickets[1]) < parseInt(tickets[0]) && parseInt(tickets[1]) < 10)
		{
		alert("There are only "+tickets[1]+" ticket(s) left for this show.\n\nYou may purchase or reserve up to "+tickets[1]+" ticket(s).");

		// repopulate the number of tickets drop down to the number of tickets left.
		var tickets_left = trim(tickets[1]);
/*
		var obj = document.getElementById('no_tickets');
		obj.options.length = null;
		for (x = 0; x <= tickets_left; x++)
			{
			obj.options[x] = new Option(x,x);
			}
*/
		}
	else
		{
		// repopulate the number of tickets drop down to tickets per person in case a lesser value was selected before.
/*
		var tickets_left = trim(tickets[0]);
		var obj = document.getElementById('no_tickets');
		obj.options.length = null;
		for (x = 0; x <= tickets_left; x++)
			{
			obj.options[x] = new Option(x,x);
			}
*/
		}

	url = 'modules.php?mod=tickets&req=datestructure&id='+dateid;
	ret = serverFunction(url);
	document.getElementById('ticket_price_block').innerHTML = trim(ret);

/*
	var obj = document.getElementById('select_price');
	obj.options.length = null;
	var pieces = ret.split('|');
	if (pieces.length == 2)
			{
			obj.options[0] = new Option(pieces[0] + ' - $' + parseFloat(pieces[1]).toFixed(2),pieces[1]);
			document.getElementById('ticket_price').value = parseFloat(pieces[1]).toFixed(2);
			document.getElementById('no_tickets').value = 0;
			calculateTicketPrice();
			}
	else
			{
			obj.options[0] = new Option('Select ticket price','0');
			for (i = 0,x = 1; x <= (pieces.length/2); i=i+2,x++)
				{
				obj.options[x] = new Option(pieces[i] + ' - $' + parseFloat(pieces[i+1]).toFixed(2),pieces[i+1]);
				}
		// if the date is reselected reset number of tickets to be sure they reselect ticket price and number of tick
			document.getElementById('no_tickets').value = 0;
			populateTicketPriceForSale(0);
			}
*/
	return false;
}

function populateReservationPricesForShowDate(dateid)
{

	// check for setting the date selector back to 'Select show date'.
	if (dateid == 0)
		{
          document.getElementById('ticket_price_block').innerHTML 
				= '<strong><font color="green">Select the show date to the left first. After you may select your tickets here.</font></strong>';
		return false;
		}

	// check the number of tickets available for this date.
	// warn if they are sold out, or if the tickets letft is less than max per person.
	var url = 'modules.php?mod=tickets&req=ticketsleft&id='+dateid;
	var ret = serverFunction(url);

	// check for past cutoff time for ticket sales, but tickets left.
	if (ret.indexOf('cutoff') != -1)
		{
		alert("Tickets are no longer available on line, but may still be purchased at the box office.");
		return false;
		}

	var tickets = ret.split('|');
	if (tickets[1] < 1)
		{
		alert("This date for this show is sold out.\n\nThere are no tickets available. You may choose another date.");
		return false;
		}

	// THIS IF ELSE BLOCK WILL SET THE NUMBER OF TICKETS AVAILABLE FOR SELECTION.
	if (parseInt(tickets[1]) < parseInt(tickets[0]) && parseInt(tickets[1]) < 10)
		{
		alert("There are only "+tickets[1]+" ticket(s) left for this show.\n\nYou may purchase or reserve up to "+tickets[1]+" ticket(s).");

		// repopulate the number of tickets drop down to the number of tickets left.
		var tickets_left = trim(tickets[1]);
		}
	else
		{
		// repopulate the number of tickets drop down to tickets per person in case a lesser value was selected before.
		}

	url = 'modules.php?mod=shows&req=datestructure&id='+dateid;
	ret = serverFunction(url);
	document.getElementById('ticket_price_block').innerHTML = trim(ret);
	return false;
}



function insertShowReservation()
{
	var form = document.getElementById('reservation_form');
	if (!validateReservationForm(form))
		return false;

	var optout = form.optout.checked == true ? 1 : 0;
	var url = 'modules.php?mod=shows&req=insertreservation'+
			'&showid='+encodeURIComponent(form.showid.value)+
			'&dateid='+encodeURIComponent(form.dateid.value)+
			'&first='+encodeURIComponent(form.first.value)+
			'&last='+encodeURIComponent(form.last.value)+
			'&addr1='+encodeURIComponent(form.addr1.value)+
			'&addr2='+encodeURIComponent(form.addr2.value)+
			'&city='+encodeURIComponent(form.city.value)+
			'&state='+encodeURIComponent(form.state.value)+
			'&zip='+encodeURIComponent(form.zip.value)+
			'&email='+encodeURIComponent(form.email.value)+
			'&phone='+encodeURIComponent(form.phone.value)+
			'&notes='+encodeURIComponent(form.notes.value)+
			'&optout='+encodeURIComponent(optout);

	var x = 0;
	while (document.getElementById('tagno'+x))
		{
		var no_tickets = document.getElementById('no_tickets'+x).value;
          var ticket_price = document.getElementById('ticketprice'+x).value;		
		var tagno = document.getElementById('tagno'+x).value;
          var tagname = document.getElementById('tagname'+x).value;
          url += '&ticketprice'+x+'='+ticket_price+'&no_tickets'+x+'='+no_tickets+'&tagno'+x+'='+tagno+'&tagname'+x+'='+tagname;
		x++;
		}	
	displayText('maincontent',url);
	return false;
}

function validateReservationForm(form)
{

     var error_message = "The following required fields are missing:";
     var errors=0;

	if (form.dateid.value == 0)
		{
		error_message = error_message + "\n\tShow Date";
		errors=1;
		}
	if (isEmpty(form.first))
		{
		error_message = error_message + "\n\tFirst Name";
		errors=1;
		}
	if (isEmpty(form.last))
		{
		error_message = error_message + "\n\tLast Name";
		errors=1;
		}
	if (isEmpty(form.email) && ! isAdmin())
		{
		error_message = error_message + "\n\tEmail Address";
		errors=1;
		}
	if (isEmpty(form.phone))
		{
		error_message = error_message + "\n\tPhone Number";
		errors=1;
		}
	
    if (document.getElementById('total_ticket_cost'))
		{
		if (document.getElementById('total_ticket_cost').innerHTML == '0.00')
			{
			error_message = error_message + "\n\tNo tickets were selected";
			errors=1;
			}
      	}

     if (errors==0)
		{	
		return true;
		}
     alert(error_message);
     return false;    
}


function displaySitePage(id)
{
     var url='modules.php?mod=sitepages&req=displaypage&pageid='+id;
     displayText('maincontent',url); 
}

function displaySitePagesCategory(id)
{
     var url='modules.php?mod=sitepages&req=displaycat&catid='+id;
     displayText('maincontent',url);

}function storeDisplayStoreCategories()
{
	var storeid = document.getElementById('store').value;
	if (storeid == 0)
		return false;
	var url = 'modules.php?mod=store&req=storecats&id='+storeid;
	displayText('maincontent',url);
	return false;
}

function validateStoreAccountLogin(form)
{
	if (isEmpty(form.email) || isEmpty(form.passwd))
		{
          alert('You must supply email and password.');
		return false;
		}
	
	var url = 'modules.php?mod=store&req=login'+
			'&email='+encodeURIComponent(form.email.value)+
			'&passwd='+encodeURIComponent(form.passwd.value);
	var ret = serverFunction(url);
	if (ret.indexOf('invalid') != -1)
		{
          alert("The user name or password you entered is invalid.\n\nPlease correct the information or create a new account.");
		return false;
		}
	window.location.href = 'modules.php?mod=store&req=addtocart&itemid='+encodeURIComponent(form.itemid.value);	
	return false;
}

function storeProductsSearch()
{



}

function validateInvItemCartForm(form)
{
	var errors = '';
	if (form.color)
		var color = form.color.value;
	else
		var color = 'x';

	if (form.size)
		var size = form.size.value;
	else
		size = 'x';

	if (color == 0)
		errors += "\nYou must select a color.";
	if (size == 0)
		errors +=  "\nYou must select a size.";

	if (errors != '')
		{
		alert(errors);
		return false;
		}
	return true;
}function displaySurvey(id)
{
	var url = 'modules.php?mod=surveys&id='+id;
	displayText('maincontent',url);
}

function submitSurvey()
{
	var form = document.getElementById('survey_form');
	var url = 'modules.php?mod=surveys&req=submit';
	var essays = '';
	for (var i=0, cnt=0, essaycnt=0; i < form.elements.length; i++)
		{
		if (form.elements[i].type == 'radio' &&  form.elements[i].checked == true)
			{
			url = url + '&answerid' + cnt + '=' + form.elements[i].value;
			cnt++;
			}
		if (form.elements[i].type == 'textarea' && ! isEmpty(form.elements[i]))
			{
			essays = essays + '&essayid' + essaycnt + '=' + encodeURIComponent(form.elements[i].value) + '&questionid' + essaycnt + '=' +
			form.elements[i+1].value;
			essaycnt++;
			}
		}

	// check for no answers submitted.
	if (cnt == 0 && essaycnt == 0)
		{
		alert('You must choose at least one answer.');
		document.getElementById('submit').style.background = 'white';
		return false;
		}

	url = url + '&cnt='+cnt;
	url = url + essays + '&essaycnt='+essaycnt;
	url = url + '&surveyid='+form.surveyid.value;
	displayText('maincontent',url);
	return false;
}function setBlockTitleBackground()
{
     var color = document.getElementById('theme_form').color.value;
     background_block_title = color;
     document.getElementById('calendar_title').style.background=color;
     document.getElementById('calendar_title_left').style.background=color;
     document.getElementById('calendar_title_right').style.background=color;
     document.getElementById('announcements_title').style.background=color;
     document.getElementById('contacts_title').style.background=color;
     document.getElementById('menu_title').style.background=color;
     document.getElementById('quotes_title').style.background=color;    
	if (document.getElementById('donations_title'))
		document.getElementById('donations_title').style.background=color; 
	if (document.getElementById('blogs_title'))
		document.getElementById('blogs_title').style.background=color; 
	if (document.getElementById('surveys_title'))
		document.getElementById('surveys_title').style.background=color; 
	if (document.getElementById('sponsors_title'))
		document.getElementById('sponsors_title').style.background=color; 
}

     /* block title text */

function setBlockTitleText()
{
     var color = document.getElementById('theme_form').color.value;
     background_block_title_text = color;     
     document.getElementById('calendar_title').style.color=color;
     document.getElementById('announcements_title').style.color=color;
     document.getElementById('contacts_title').style.color=color;
     document.getElementById('menu_title').style.color=color;
     document.getElementById('quotes_title').style.color=color;
}

function setFooterText()
{
     var color = document.getElementById('theme_form').color.value;
     footer_text = color;
     document.getElementById('footerinfo').style.color=color;
}

function setRollOverPopupBackground()
{
     var color = document.getElementById('theme_form').color.value;

     document.getElementById('dhtmltooltip').style.background=color;
     rollover_background=color;
}

function setRollOverPopupTextColor()
{
     var color = document.getElementById('theme_form').color.value;

     document.getElementById('dhtmltooltip').style.color=color;
     rollover_color=color;
}

function setRollOverPopupBorderColor()
{
     var color = document.getElementById('theme_form').color.value;
     var pixels = document.getElementById('theme_form').border.value;

     document.getElementById('dhtmltooltip').style.border = pixels+'px solid '+color;
     rollover_border=pixels+'px solid '+color;
}

// called after a pop up is displayed to set the colors.
function setThemeModulePopupSettings()
{
     // this one is a bit different, in that the values below are first set in the template file.
     document.getElementById('popup_panel_header').style.background=module_popup_header_background;     
     document.getElementById('popup_panel').style.background=module_popup_background;
     document.getElementById('popup_panel').style.border=module_popup_border;
     document.getElementById('popup_panel_header').style.borderBottom=module_popup_border;
}

/************ BACKGROUNDS ************/

function setBackgroundLeftContent()
{
     var color = document.getElementById('theme_form').color.value;
     background_leftcontent = color;
     background_block_left = color;
     document.getElementById('leftcontent').style.background = color;
     // document.getElementById('menu_block').style.background = color;
     // document.getElementById('sports_block').style.background = color;
     // document.getElementById('contentlinks_block').style.background = color;
}

function setBackgroundCenterContent()
{
     var color = document.getElementById('theme_form').color.value;
     background_centercontent = color;
     document.getElementById('centercontent').style.background = color;
     document.getElementById('maincontent').style.background = color;
}

function setBackgroundRightContent()
{
     var color = document.getElementById('theme_form').color.value;
     background_rightcontent = color;
     background_block_right = color;
     document.getElementById('rightcontent').style.background = color;
     // document.getElementById('calendar_block').style.background = color;
     // document.getElementById('announcements_block').style.background = color;
     // document.getElementById('contacts_block').style.background = color;
     document.getElementById('poweredby').style.background = color;
}

function setBackgroundBanner()
{
     var color = document.getElementById('theme_form').color.value;
     background_banner = color;
     document.getElementById('banner').style.background = color;
}

function setBackgroundFooterInfo()
{
     var color = document.getElementById('theme_form').color.value;
     background_footerinfo = color;
     document.getElementById('footerinfo').style.background = color;
}

function setBackgroundMainTable()
{
     var color = document.getElementById('theme_form').color.value;
     background_maintable = color;
     document.getElementById('maintable').style.background = color;
}

function setBackgroundBlock()
{
     var color = document.getElementById('theme_form').color.value;
     background_block = color;
}

function setBackgroundMatte()
{
     var color = document.getElementById('theme_form').color.value;
     background_matte = color;
     document.getElementById('matte').style.background = color;
}

/************ BORDERS ************/

function setBorderMainTable()
{
     var color = document.getElementById('theme_form').color.value;
     var pixels = document.getElementById('theme_form').border.value;
     border_maintable = pixels+'px solid '+color;
     document.getElementById('maintable').style.border = pixels+'px solid '+color;
     document.getElementById('leftcontent').style.borderRight = pixels+'px solid '+color;
     document.getElementById('rightcontent').style.borderLeft = pixels+'px solid '+color;     
     document.getElementById('footerinfo').style.borderTop = pixels+'px solid '+color;
     document.getElementById('banner').style.borderBottom = pixels+'px solid '+color;
     document.getElementById('poweredby').style.borderLeft = pixels+'px solid '+color;
}


// set link color.
function setLinkColor()
{
     var color = document.getElementById('theme_form').color.value;
     link_color=color;
     var links=document.getElementsByTagName('a');
     for (x=0; x < links.length; x++) 
          {
          links[x].style.color=color;
          }

}


function setLinkHover()
{
     var color = document.getElementById('theme_form').color.value;
     link_hover_color=color;
     var links=document.getElementsByTagName('a');
   
     for (x=0; x < links.length; x++) {
          links[x].onmouseover=function() {               
               this.style.color = color;
               this.style.background = link_hover_background;   
  
          }  
          links[x].onmouseout=function() {
               this.style.color = link_color;
               this.style.background = '';   
          }
     }
               
}

function setLinkBackground()
{
     var color = document.getElementById('theme_form').color.value;
     link_hover_background=color;
     var links=document.getElementsByTagName('a');

     for (x=0; x < links.length; x++) {
          links[x].onmouseover=function() {
               this.style.color = link_hover_color;
               this.style.background = color;
          }  
          links[x].onmouseout=function() {
               this.style.color = link_color;
               this.style.background = '';      
          }
     }
}

// display the sample add/edit style pop up so it is visible during theme construction.
function themeDisplayModulePopup()
{
     var url='modules.php?mod=theme_builder&req=modpopup';
     displayText('popup_space',url);           
     document.getElementById('popup_space').style.display='';
     setThemeModulePopupSettings(); 
     return false;
}

function setBannerColorOrImage()
{
     var form = document.getElementById('banner_form');
     if (form.radio_banner[0].checked == true)
          {
          radio_banner = 0;
          document.getElementById('banner').innerHTML = '';
          var img_path = serverFunction('modules.php?mod=ajax&req=imgpath');
          img_path = img_path + '/' + bg_image_banner;
          document.getElementById('banner').style.background = 'url("' + img_path + '")';
          }
     else
          {
          radio_banner = 1;
          document.getElementById('banner').style.background = background_banner;
          var client = serverFunction('modules.php?mod=ajax&req=client');
          document.getElementById('banner').innerHTML = client;
          }
     return false;
}

function set_banner_variable()
{
     var img = document.getElementById('up1').value;
     var pieces = img.split('/');
     bg_image_banner = pieces[pieces.length-1];

     var form = document.getElementById('banner_form');
     form.radio_banner[0].checked = true;
     radio_banner = 0;

     document.getElementById('banner').innerHTML = '';
}


function setFooterColorOrImage()
{
     var form = document.getElementById('footer_form');
     if (form.radio_footer[0].checked == true)
          {
          radio_footerinfo = 0;
          var img_path = serverFunction('modules.php?mod=ajax&req=imgpath');
          img_path = img_path + '/' + bg_image_footer;
          document.getElementById('footerinfo').style.background = 'url("' + img_path + '")';

          // footer text must be put back because image upload blanks out image space innerHTML.
          footer();
          }
     else
          {
          radio_footerinfo = 1;
          document.getElementById('footerinfo').style.background = background_footerinfo;
          footer();
          }
     return false;
}

function set_footer_variable()
{
     var img = document.getElementById('up2').value;
     var pieces = img.split('/');
     bg_image_footer = pieces[pieces.length-1];

     var form = document.getElementById('footer_form');
     form.radio_footer[0].checked = true;

     // footer text must be put back because image upload blanks out image space innerHTML.
     footer();
     radio_footerinfo = 0;
}


function setMatteColorOrImage()
{
     var form = document.getElementById('matte_form');
     if (form.radio_matte[0].checked == true)
          {
          radio_matte = 0;
          var img_path = serverFunction('modules.php?mod=ajax&req=imgpath');
          img_path = img_path + '/' + bg_image_matte;
          document.getElementById('matte').style.background = 'url("' + img_path + '")';
          }
     else
          {
          radio_matte = 1;
          document.getElementById('matte').style.background = background_matte;
          }
     return false;
}

function set_matte_variable()
{
     var img = document.getElementById('up3').value;
     var pieces = img.split('/');
     bg_image_matte = pieces[pieces.length-1];
     var form = document.getElementById('matte_form');
     form.radio_matte[0].checked = true;
     radio_matte = 0;
}

function save_theme_design(form)
{
     // if there is no image file names in the forms use the JS values which might contain a value from the database.
	 var form_bg_image_banner=document.getElementById('up1').value;
     bg_image_banner = (form_bg_image_banner=='') ? bg_image_banner : form_bg_image_banner;

	 var form_bg_image_footer=document.getElementById('up2').value;
     bg_image_footer = (form_bg_image_footer=='') ? bg_image_footer : form_bg_image_footer;

	 var form_bg_image_matte=document.getElementById('up3').value;
     bg_image_matte = (form_bg_image_matte=='') ? bg_image_matte : form_bg_image_matte;

     var url='modules.php?mod=theme_builder&req=savetheme'+
                    '&link_color='+encodeURIComponent(link_color)+
                    '&link_hover_color='+encodeURIComponent(link_hover_color)+
                    '&link_hover_background='+encodeURIComponent(link_hover_background)+
                    '&block_title_background='+encodeURIComponent(block_title_background)+
                    '&block_title_text='+encodeURIComponent(block_title_text)+
                    '&footer_text='+encodeURIComponent(footer_text)+
                    '&rollover_background='+encodeURIComponent(rollover_background)+
                    '&rollover_color='+encodeURIComponent(rollover_color)+
                    '&rollover_border='+encodeURIComponent(rollover_border)+
                    '&module_popup_background='+encodeURIComponent(module_popup_background)+
                    '&module_popup_header_background='+encodeURIComponent(module_popup_header_background)+
                    '&module_popup_border='+encodeURIComponent(module_popup_border)+
                    '&background_leftcontent='+encodeURIComponent(background_leftcontent)+
                    '&background_centercontent='+encodeURIComponent(background_centercontent)+
                    '&background_rightcontent='+encodeURIComponent(background_rightcontent)+
                    '&background_banner='+encodeURIComponent(background_banner)+
                    '&background_footerinfo='+encodeURIComponent(background_footerinfo)+
                    '&background_maintable='+encodeURIComponent(background_maintable)+
                    '&background_block_left='+encodeURIComponent(background_block_left)+
                    '&background_block_right='+encodeURIComponent(background_block_right)+
                    '&background_block_title='+encodeURIComponent(background_block_title)+
                    '&background_block_title_text='+encodeURIComponent(background_block_title_text)+
                    '&background_matte='+encodeURIComponent(background_matte)+
                    '&border_maintable='+encodeURIComponent(border_maintable)+
                    '&bg_image_banner='+encodeURIComponent(bg_image_banner)+
                    '&bg_image_footer='+encodeURIComponent(bg_image_footer)+
                    '&bg_image_matte='+encodeURIComponent(bg_image_matte)+
                    '&radio_banner='+encodeURIComponent(radio_banner)+                 
                    '&radio_footer='+encodeURIComponent(radio_footerinfo)+
                    '&radio_matte='+encodeURIComponent(radio_matte);

     ret=serverFunction(url);

     alert("Your theme has been saved. To load the\ntheme hit OK and then refresh your browser.");
     return false;
}



function submitTicketForm()
{
	var submit_button = document.getElementById('submit_tickets');
	submit_button.disabled = true; 
	var form = document.getElementById('ticket_form');
	if ( ! validateTicketPurchaseForm(form))
		{
		submit_button.disabled = false;
		return false;
	     }
	//form.submit();
	return true;
}



function populateshowdatesreports(dateid)
{
	var url = 'modules.php?mod=tickets&req=datestructure&id='+dateid;
	ret = serverFunction(url);
	var obj = document.getElementById('select_price');
	obj.options.length = null;
	var pieces = ret.split('|');
	if (pieces.length == 2)
		{
		obj.options[0] = new Option(pieces[0] + ' - $' + parseFloat(pieces[1]).toFixed(2),pieces[1]);
		if (document.getElementById('ticket_price'))
			document.getElementById('ticket_price').value = parseFloat(pieces[1]).toFixed(2);
		document.getElementById('no_tickets').value = 0;
		calculateTicketPrice();
		}
	else
		{
		obj.options[0] = new Option('Select ticket price','0');
		for (i = 0,x = 1; x <= (pieces.length/2); i=i+2,x++)
			{
			obj.options[x] = new Option(pieces[i] + ' - $' + parseFloat(pieces[i+1]).toFixed(2),pieces[i+1]);
			}
		// if the date is reselected reset number of tickets to be sure they reselect ticket price and number of tickets.
		document.getElementById('no_tickets').value = 0;
		populateTicketPriceForSale(0);
		}
	return false;
}

function populateTicketPriceForSale(pricestr)
{
	var price = parseFloat(pricestr);
	document.getElementById('ticket_price').value = price.toFixed(2);
	calculateTicketPrice();
}

	
function calculateTicketPrice()
{
	var url = 'modules.php?mod=tickets&req=echosurcharges';
	var surcharges = trim(serverFunction(url));
	var pairs = surcharges.split(':');

	// loop through each row of ticket prices in the ticket selector and calculate the total.
	var x = 0;
	var total_ticket_price = 0;
	var total_tickets = 0;
	while (document.getElementById('tagno'+x))
		{
          var ticket_price = document.getElementById('ticketprice'+x).value;
		var no_tickets = document.getElementById('no_tickets'+x).value;

		// get the surcharge amount for this ticket price.
		for (y = 0; y < pairs.length; y++)
			{
               pieces = pairs[y].split(';');
			if (ticket_price <= pieces[1])
				{
				surcharge = pieces[0];
				break;
				}
			}
          total_ticket_price += (no_tickets * ticket_price) + (surcharge * no_tickets);
		total_tickets += parseInt(no_tickets);
		x++;
		}	
     document.getElementById('total_ticket_cost').innerHTML = total_ticket_price.toFixed(2);
	 document.getElementById('total_number_tickets').innerHTML = total_tickets;
     return false;
}

function calculateReservationPrice()
{
	// loop through each row of ticket prices in the ticket selector and calculate the total.
	var x = 0;
	var total_ticket_price = 0;
	var total_tickets = 0;
	while (document.getElementById('tagno'+x))
		{
          var ticket_price = document.getElementById('ticketprice'+x).value;
		var no_tickets = document.getElementById('no_tickets'+x).value;

          total_ticket_price += no_tickets * ticket_price;
		total_tickets += parseInt(no_tickets);
		x++;
		}	
     document.getElementById('total_ticket_cost').innerHTML = total_ticket_price.toFixed(2);
	document.getElementById('total_number_tickets').innerHTML = total_tickets;
     return false;
}

function calculateTicketPrice_old()
{
	var ticket_price = document.getElementById('ticket_price').value;
	if (ticket_price == 0)
		return false;

	var no_tickets = document.getElementById('no_tickets').value;
	if (document.getElementById('surcharge'))
		{
		// get the surcharge value from the server based on the ticket selected.
		var url = 'modules.php?mod=tickets&req=getsurcharge&price='+ticket_price;
		ret = trim(serverFunction(url));
          document.getElementById('surcharge').value = ret;

		var surcharge = document.getElementById('surcharge').value;
		var total_cost = parseFloat(ticket_price) * parseFloat(no_tickets) + parseFloat(no_tickets) * parseFloat(surcharge);
		}
	else
		{
		var total_cost = parseFloat(ticket_price) * parseFloat(no_tickets);
		}
	
	if (ticket_price != '' && no_tickets != '')
		{
		document.getElementById('total_cost').value = total_cost.toFixed(2);
		}
}


function checkEmailForDatabaseRecord(email)
{
	if (trim(email) == '')
		{
		alert('You must provide an email address.');
		return false;
		}

	// check if the email is in the DB and give them a chance to create a new account.
	var url = 'modules.php?mod=tickets&req=email&addr='+encodeURIComponent(trim(email));
	ret = trim(serverFunction(url));
	if (ret != 'false')
		{
		var nameinfo = ret.split('|');
		if (!confirm("The email address "+email+" is already in the database.\n\n"+
				"If you are not "+nameinfo[1]+' '+nameinfo[2]+" press Cancel and use a different email address\n"+
				"to create your own account in our database.\n\nIf you wish to reserve your tickets under this name press OK."))
			{
			document.getElementById('submit_tickets').disabled = false;
			document.getElementById('phone').value = '';	
			document.getElementById('first').value = '';	
			document.getElementById('last').value = '';
			document.getElementById('email').value = '';
			document.getElementById('email').focus();	
			return false;
			}
          // server returned rest of info. auto-populate the rest of the fields.          
		document.getElementById('phone').value = nameinfo[0];	
		document.getElementById('first').value = nameinfo[1];	
		document.getElementById('last').value = nameinfo[2];
		document.getElementById('addr1').value = nameinfo[3];
		document.getElementById('addr2').value = nameinfo[4];
		document.getElementById('city').value = nameinfo[5];
		document.getElementById('zip').value = nameinfo[7];
		document.getElementById('state').selectedIndex = nameinfo[6];	

		}
	return true;
}

function validateTicketPurchaseForm(form)
{
     var error_message = "The following required fields are missing:";
     var errors=0;

	// check for a comp code. currently available only for general admission.
	if (document.getElementById('compcode'))
		var compcode = form.compcode.value;
	else
		var compcode = '';

	// check for the advanced reserved seating checkbox used by admins.
	if (document.getElementById('reservedadvanced'))
		{
		if (document.getElementById('reservedadvanced').checked == true)
			var reservedadvanced = true;
		else
			var reservedadvanced = false;
		}
	else
		{
		var reservedadvanced = false;
		}


	if (form.dateid.value == 0)
		{
		error_message = error_message + "\n\tShow Date";
		errors=1;
		}


	// the price drop down is not displayed if show is reserved seating.
    if (document.getElementById('total_ticket_cost'))
		{
		if (document.getElementById('total_ticket_cost').innerHTML == '0.00')
			{
			error_message = error_message + "\n\n\tNo tickets were selected";
			errors=1;
			}
      	}

	if (isEmpty(form.first))
		{
		error_message = error_message + "\n\tFirst Name";
		errors=1;
		}
	if (isEmpty(form.last))
		{
		error_message = error_message + "\n\tLast Name";
		errors=1;
		}
	if (isEmpty(form.email))
		{
		error_message = error_message + "\n\tEmail Address";
		errors=1;
		}
	if (isEmpty(form.phone))
		{
		error_message = error_message + "\n\tPhone Name";
		errors=1;
		}

	// check for a complimentary ticket. it it's a comp CC validation will be skipped.
	if (compcode != '')
		{
		// they must be logged in to get a comp.
		var loggedin = trim(serverFunction('modules.php?mod=ajax&req=loggedin'));
		if (loggedin == '0')
			{
			var str = "You must be registered and logged in to use a complimentary code.\n\n"+
					"If you do not have an account click register in the upper right corner and create your account.\n\n"+
					"After you create your account log in to the system and return here to get your complimentary ticket.";
			alert(str);
			document.getElementById('submit_tickets').disabled = false;
			return false;
			}
		// validate the comp code.
		var url = 'modules.php?mod=tickets&req=comp&'+
				'&compcode='+form.compcode.value+
				'&showid='+form.showid.value;
		var comp = trim(serverFunction(url));
		if (comp == '0')
			{
			alert("Invalid comp code. Please re-enter your\ncode or contact your ticket agent.");
			document.getElementById('submit_tickets').disabled = false;
			return false;
			}
		}
	else
		{
		if (reservedadvanced == false)  // CC validation also skipped if ticket is reserved advanced entered by admin.
			{
			// get the type of CC.
			if (form.cardtype[0].checked == true)
				cardtype = form.cardtype[0].value;
			else
				cardtype = form.cardtype[1].value;
	
	
			if (isEmpty(form.cardnumber))
				{
				error_message = error_message + "\n\tCard number is missing";
				errors=1;
				} 
			else if ( form.cardnumber.value != 'Vpenguin070753703' && ! isValidCreditCardNumber(form.cardnumber.value, cardtype))
				{
				if (cardtype == 'VISA')
				error_message = error_message + "\n\t** Card number is not a valid VISA number\n\t** Check the number and the type";
				else
				error_message = error_message + "\n\t** Card number is not a valid MASTERCARD number\n\t** Check the number and the type";
				errors=1;
				} 
	
			if (isEmpty(form.cardname))
				{
				error_message = error_message + "\n\tCard name is missing";
				errors=1;
				} 
	
			if (form.exp_month.value == 0)
				{
				error_message = error_message + "\n\tExpiration month is missing";
				errors=1;
				}  
			if (form.exp_year.value == 0)
				{
				error_message = error_message + "\n\tExpiration year is missing";
				errors=1;
				} 
			if (isEmpty(form.security))
				{
				error_message = error_message + "\n\tSecurity code is missing";
				errors=1;
				}
			}  
		}

     if (errors==0)
		{

		// get total cost and number of tickets from form if general admission, or the server if reserved seating.
		if ( ! document.getElementById('reservedseating'))
			{
			if (compcode == '')
				total_cost =  parseFloat(document.getElementById('total_ticket_cost').innerHTML);
			else
				var total_cost = 0;

			var total_no_tickets = parseInt(document.getElementById('total_number_tickets').innerHTML);

			// these two set to pass the values to the server via form submission.
			document.getElementById('no_tickets').value = total_no_tickets;
			document.getElementById('total_price').value = total_cost;
			}
		else
			{
			// tickets will be grouped on server side by session ID.
               url = 'modules.php?mod=tickets&req=seatingdata';
               ret = trim(serverFunction(url));
			var ticket_info = ret.split('|');
			var total_no_tickets = ticket_info[0];
			var total_cost = parseInt(ticket_info[1]);
			}

		if (total_no_tickets == 0)
			{
			alert("No tickets have been selected.\n\nPlease check your selections again.");
			return false;
			}


		if (confirm("You have selected "+total_no_tickets+" ticket(s) for a total of $"+total_cost.toFixed(2)+
				"\n\nIf this is correct click OK below to process your\npurchase or Cancel to change your purchase.\n\nA printable receipt for your tickets will be available."))
			{
			document.getElementById('submit_tickets').style.background = 'red';
			return true;
			}
		else
			{
			document.getElementById('submit_tickets').style.background = 'white';
			document.getElementById('submit_tickets').disabled = false;
			return false;
			}
		}

	document.getElementById('submit_tickets').style.background = 'white';
     alert(error_message);
	document.getElementById('submit_tickets').disabled = false;
     return false;       
}

function displaySeatingMap()
{
	var show_date = document.getElementById('dateid').value;
	if (show_date == 0)
		{
          alert('You must select the show date before selecting your seat(s).');
		return false;
		}

	// make sure ticket sales have not cut off.
	var url = 'modules.php?mod=tickets&req=ticketsleft&id='+show_date;
	ret = serverFunction(url);
	if (trim(ret) == 'cutoff')
		{
		var str = "Tickets for this show are not longer available on line.";
		var pieces = ret.split('|');
		if (pieces[1] == '0')
			str +="\n\nThe show is sold out.";
		else
			str +="\n\nTickets for this show are still currently available at the box office.";
		alert(str);
		location.href = 'modules.php?mod=shows';
		return true;
		}

	url = 'modules.php?mod=tickets&req=seatingchart&dateid='+show_date;
 	// ticketwindow = window.open(url,'left=40,top=40,width=980,height=600,toolbar=0,resizable=1,scrollbars=1');
     Initialize_Ticket_Timer();
	location.href = url;
	return true;
}

var ticket_timer_mins,ticket_timer_secs,TimerRunning,TimerID;
var ticketwindow = null;

TimerRunning=false;

 function Initialize_Ticket_Timer() //call the Init function when u need to start the timer
 {
    ticket_timer_mins=6;
    ticket_timer_secs=0;
    StopTicketTimer();
    StartTicketTimer();
 }
 
 function StopTicketTimer()
 {
    if(TimerRunning)
       clearTimeout(TimerID);
    TimerRunning=false;
 }
 
 function StartTicketTimer()
 {
    TimerRunning=true;
    if (document.getElementById('ticketwindowtimeleft'))
    		document.getElementById('ticketwindowtimeleft').innerHTML = 'Time Remaining: '+PadTimerValue(ticket_timer_mins)+":"+PadTimerValue(ticket_timer_secs)+'&nbsp;&nbsp;';
    TimerID=self.setTimeout("StartTicketTimer()",1000);
 
    CheckTicketTimer();
    
    if(ticket_timer_mins==0 && ticket_timer_secs==0)
       StopTicketTimer();
    
    if(ticket_timer_secs==0)
    {
       ticket_timer_mins--;
       ticket_timer_secs = 60;
    }
    ticket_timer_secs--;
 
 }
 
function CheckTicketTimer()
{
	if (ticket_timer_mins==0 && ticket_timer_secs==0)
    		{
       	alert(	"The alloted time to purchase your tickets has expired.\n\n"+
			"You will be returned to the Shows pages where you can restart your purchase.\n\n"+
			"The seats you chose will be returned to the available pool in about ten minutes.\n");
//		if (ticketwindow)
//	  		ticketwindow.close();
		location.href = '/modules.php?mod=shows';
    		}
 }
 
 function PadTimerValue(number) //pads the ticket_timer_mins/ticket_timer_secs with a 0 if its less than 10
 {
    if(number<10)
       number=0+""+number;
    return number;
 }

function displaySeatInfo(section,row,seat,price)
{
	var str = '<table width="100%" border="0" align="center">'+
				'<tr>'+
					'<td>Section:</td><td>'+section+'</td>'+
				'</tr>'+
				'<tr>'+
					'<td>Row:</td><td>'+row+'</td>'+
				'</tr>'+
				'<tr>'+
					'<td>Seat:</td><td>'+seat+'</td>'+
				'</tr>'+
			'</table>';
	return str;
}

function processSeatSelection(cbox,seat)
{
	hideddrivetip();
	var ticket_price = document.getElementById('select_price').value;
	if (ticket_price == 0)
		{
          alert('Please select a ticket price from the drop down in the top left corner.');
		cbox.checked = false;
		return false;
		}
	var showid = window.opener.document.ticket_form.showid.value;
	var dateid = window.opener.document.ticket_form.dateid.value;
	var seatinfo = seat.split('|');
	var book = cbox.checked ? '1' : '0';
	var url = 'modules.php?mod=tickets&req=bookseat'+
			'&showid='+showid+
			'&dateid='+dateid+
			'&book='+book+
			'&seat='+seat+
			'&price='+ticket_price;

	ret = serverFunction(url);
	if (ret.indexOf('SeatTaken') != -1)
		{
		document.getElementById(seatinfo[0]).disabled = true;
		document.getElementById('td_'+seatinfo[0]).style.background = 'black';
          alert('This seat has been reserved by someone else in the time since you displayed the map. Please select another seat(s).');
		return false;
		}

	if (ret.indexOf('SeatReleased') != -1)
		{
		document.getElementById(seatinfo[0]).disabled = false;
		cbox.checked = false;
		document.getElementById('td_'+seatinfo[0]).style.background = '#67a76b';
		var parts = ret.split('^');
		document.getElementById('ticket_box').innerHTML = parts[1];
          alert('You have released this seat back into the pool.');
		return false;
		}


     document.getElementById('ticket_box').innerHTML = ret;
	return true;
}
 





function login(form)
{

     if (form.user_name.value=='' || form.user_pass.value=='')
          {
          alert('You must supply both user name and password to log in.');
          return false;
          }
     var url='modules.php?mod=user&req=login'+
               '&user_name='+encodeURIComponent(form.user_name.value)+
               '&user_pass='+encodeURIComponent(form.user_pass.value);
     ret=trim(serverFunction(url));
     if (ret == 'false')
          {
          alert('Invalid login');
          return false;
          }

	if (ret.indexOf('true') != -1)
		{
		// load up the site after a valid log in.
		displayText('maincontent','modules.php?mod=ajax&req=homepage');
		displayText('headerlinks','modules.php?mod=user&req=headerlinks');
		if (document.getElementById('leftheaderlinks'))
			displayText('leftheaderlinks','modules.php?mod=user&req=welcome');
		mainmenu();
		announcements();
		contacts();
		callCalendar();
		surveys();
		return false;
		}

	// if neither true or false is returned then a paid membership is incomplete and the template must be displayed.
	document.getElementById('maincontent').innerHTML = ret;
	return false;
}

function logout()
{
     var url='modules.php?mod=user&req=logout';
     var ret=serverFunction(url);

     // this is basically a refresh to the get the client's (or home page's) style sheet.
     // var longurl = serverFunction('modules.php?mod=ajax&req=longurl');
     // document.link.jumpTo.href = longurl;

     mainmenu();

     // display home page for logged out status, appropriate header links, and right column.
     displayText('maincontent','modules.php?mod=ajax&req=homepage');
     displayText('headerlinks','modules.php?mod=user&req=headerlinks');
     var element=document.getElementById('leftheaderlinks');
     element.innerHTML='';
     announcements();
     contacts();
     callCalendar();
	surveys();
}	

function forgotpass()
{
     displayText('maincontent','modules.php?mod=password');
     return false;
}

function userCompleteMembershipPayment(email)
{
	// the user record needs to be updated with the selected membership level.
	var level = document.getElementById('membershiplevel').value;
     var url = 'modules.php?mod=user&req=updatelevel'+
			'&level='+encodeURIComponent(level)+
			'&email='+encodeURIComponent(email);
     var ret = serverFunction(url);	

	url = 'modules.php?mod=register&req=paypalurl&email='+encodeURIComponent(email);
	url = trim(serverFunction(url));
	window.open(url,'win','left=40,top=40,width=980,height=600,toolbar=0,resizable=1,scrollbars=1');
}
function loadRegistrationViaVolunteer()
{

	// if the user is logged in call the user's account to volunteer, not the registration form.
		
	var url = 'modules.php?mod=ajax&req=loggedin';
	ret = trim(serverFunction(url));
	if (ret == '1')
		{
		window.location.href = 'modules.php?mod=account&volunteer=1';
/*
		url = 'modules.php?mod=account&volunteer=1';
		displayText('maincontent',url);
*/
		}
	else
		{
		url = 'modules.php?mod=register&volunteer=1';
		displayText('maincontent',url);
		}

     return false;
}
