Adding files for their old registration system.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 7 Sep 2017 14:39:27 +0000 (10:39 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 7 Sep 2017 14:39:27 +0000 (10:39 -0400)
It goes through dev mode for donation form.
Need to test with other event registrations.

23 files changed:
functions.php
lib/registrations.php [new file with mode: 0644]
registrations/Views/Default/admin.html [new file with mode: 0644]
registrations/Views/Default/form_edit_test.html [new file with mode: 0644]
registrations/Views/Default/form_edit_test_result.html [new file with mode: 0644]
registrations/Views/Default/index.html [new file with mode: 0755]
registrations/Views/Default/registration_price_guide.html [new file with mode: 0644]
registrations/Views/Default/registrations_cc_confirmation.html [new file with mode: 0644]
registrations/Views/Default/registrations_confirmation.html [new file with mode: 0644]
registrations/Views/Default/registrations_intro.html [new file with mode: 0644]
registrations/Views/Default/registrations_step1.html [new file with mode: 0644]
registrations/Views/Default/registrations_step2.html [new file with mode: 0644]
registrations/Views/Default/registrations_step3.html [new file with mode: 0644]
registrations/Views/Default/registrations_store.html [new file with mode: 0644]
registrations/Views/Default/registrations_summary.html [new file with mode: 0644]
registrations/Views/Default/reports_csv.html [new file with mode: 0644]
registrations/Views/Default/reports_print.html [new file with mode: 0644]
registrations/Views/Default/style.css [new file with mode: 0644]
registrations/Views/index.html [new file with mode: 0755]
registrations/functions.php [new file with mode: 0644]
registrations/registrations.php [new file with mode: 0644]
registrations/setup.php [new file with mode: 0644]
registrations/siteinfo.php [new file with mode: 0644]

index f659f8f..cf931f3 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 require_once 'lib/menu-walker.php';
 require_once 'lib/navigation.php';
+require_once 'lib/registrations.php';
 
 $ancestorId   = null;
 $includePages = array();
diff --git a/lib/registrations.php b/lib/registrations.php
new file mode 100644 (file)
index 0000000..b0f1e1c
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+$_ENV['GLM_HOST_ID'] = 'DEVELOPMENT';
+add_shortcode( 'glm-event-registrations', function( $atts ){
+    extract( $_REQUEST );
+    if ( !isset( $Action ) || !$Action ) {
+        $Action = 'Step1';
+    }
+    include_once get_template_directory() . '/registrations/setup.php';
+    include_once get_template_directory() . '/registrations/siteinfo.php';
+    include_once get_template_directory() . '/registrations/functions.php';
+    include_once get_template_directory() . '/registrations/registrations.php';
+} );
+
+add_action( 'init', function(){
+    // for session start
+} );
+add_action( 'admin_bar_menu', function( $wp_admin_bar ){
+    $args = array(
+        'id'    => 'eventregistrations',
+        'title' => 'Event Registrations',
+        'href'  => 'http://admin',
+        'meta'  => array(
+            'class'  => 'eventregistrations',
+            'title'  => 'Event Registrations',
+            'target' => '_blank',
+        )
+    );
+    $wp_admin_bar->add_node( $args );
+}, 999 );
diff --git a/registrations/Views/Default/admin.html b/registrations/Views/Default/admin.html
new file mode 100644 (file)
index 0000000..d5d1d6a
--- /dev/null
@@ -0,0 +1,40 @@
+<html>
+  <head>
+    <title>'.SI_CUSTOMER_NAME.' Administration</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+    <META NAME="Author" CONTENT="Gaslight Media">
+    <META http-equiv="Pragma" content="no-cache">
+
+<!--{exclude}-->
+    <link rel="stylesheet" href="../../style.css">
+<!--{/exclude}-->
+<!--{include}
+    <link rel="stylesheet" href="{stylesheet}">
+{/include}-->
+<!--{exclude}-->
+    <script SRC="../../java_functions.js"></script>
+<!--{/exclude}-->
+<!--{include}
+    <script src="../../java_functions.js"></script>
+{/include}-->
+  </head>
+  <body onLoad="defaultFieldFocus( '{field_focus}' );">
+    <center>
+   
+      <span class="title1">Magic Form Builder</span><br>
+      <p>
+      <span class="navlink">{menu}</span>
+  <!--{if:message}-->
+      <p>
+      <table border="1" width="80%"><tr><td>{message}</td></tr></table>
+      <p>
+  <!--{/if:message}-->
+  
+      {body}
+      
+    </center>
+    <p>&nbsp;<p>
+    <hr>
+    <center><p class="copyright">Copyright &copy; {copyright_years} <a href="http://www.gaslightmedia.com" target="blank">Gaslight Media</a> All Rights Reserved</p></center>
+  </body>
+</html>
\ No newline at end of file
diff --git a/registrations/Views/Default/form_edit_test.html b/registrations/Views/Default/form_edit_test.html
new file mode 100644 (file)
index 0000000..5aa9879
--- /dev/null
@@ -0,0 +1,43 @@
+<html>
+  <head>
+    <title>'.SI_CUSTOMER_NAME.' Administration</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+    <META NAME="Author" CONTENT="Gaslight Media">
+    <META http-equiv="Pragma" content="no-cache">
+
+<!--{exclude}-->
+    <link rel="stylesheet" href="../../style.css">
+<!--{/exclude}-->
+<!--{include}
+    <link rel="stylesheet" href="{stylesheet}">
+{/include}-->
+<!--{exclude}-->
+    <script SRC="../../java_functions.js"></script>
+<!--{/exclude}-->
+<!--{include}
+    <script src="../java_functions.js"></script>
+{/include}-->
+  </head>
+  <body onLoad="defaultFieldFocus( '{field_focus}' );">
+    <center>
+      <div class="standout">{cust_name}</div>
+      <span class="title1">Magic Form Builder</span><br>
+      <p>
+    </center>
+
+  <!--{if:problem}--><P>The form submission was invalid because:<p><dl>{problem}</dl><p><!--{/if:problem}-->
+    <p>  
+    <form enctype="multipart/form-data" action="{this_script}" method="post">
+      <input type="hidden" name="Action" value="Eve_For_Edi_Tes_Sub">
+      {form_data}
+      {magic_form}
+      <p>
+    <!--{if:required=Yes}--><font color="red">*</font> Required fields<p><!--{/if:required}-->
+      <input type="submit" name="Submit Form" value="Submit Form">
+    </form>
+      
+    <p>&nbsp;<p>
+    <hr>
+    <center><p class="copyright">Copyright &copy; {copyright_years} <a href="http://www.gaslightmedia.com" target="blank">Gaslight Media</a> All Rights Reserved</p></center>
+  </body>
+</html>
\ No newline at end of file
diff --git a/registrations/Views/Default/form_edit_test_result.html b/registrations/Views/Default/form_edit_test_result.html
new file mode 100644 (file)
index 0000000..61b0247
--- /dev/null
@@ -0,0 +1,41 @@
+<html>
+  <head>
+    <title>'.SI_CUSTOMER_NAME.' Administration</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+    <META NAME="Author" CONTENT="Gaslight Media">
+    <META http-equiv="Pragma" content="no-cache">
+
+<!--{exclude}-->
+    <link rel="stylesheet" href="../../style.css">
+<!--{/exclude}-->
+<!--{include}
+    <link rel="stylesheet" href="{stylesheet}">
+{/include}-->
+<!--{exclude}-->
+    <script SRC="../../java_functions.js"></script>
+<!--{/exclude}-->
+<!--{include}
+    <script src="../java_functions.js"></script>
+{/include}-->
+  </head>
+  <body onLoad="defaultFieldFocus( '{field_focus}' );">
+    <center>
+      <div class="standout">{cust_name}</div>
+      <span class="title1">Magic Form Builder</span><br>
+      <p>
+    </center>
+  <!--{if:problem}--><P>The form submission was invalid because:<p><dl>{problem}</dl><p><!--{else:problem}The form submission was successful.<p>{/if:problem}-->
+    <p><form action="{this_script}">{return_data}{form_data}<input type="submit" name="Return" value="Return to Form"></FORM>
+    <p>&nbsp;<p>
+    <p><span class="standout">Results</span><br><hr><pre>{html}</pre><P>
+  <!--{if:total_value}-->
+    Total value of selected options = {total_value}<p>
+  <!--{/if:total_value}-->
+    <hr>
+    <p>&nbsp;<p>
+    <span class="standout">CSV export</span><br><hr><pre>{csv}</pre><hr>
+    <p>&nbsp;<p>
+    <hr>
+    <center><p class="copyright">Copyright &copy; {copyright_years} <a href="http://www.gaslightmedia.com" target="blank">Gaslight Media</a> All Rights Reserved</p></center>
+  </body>
+</html>
\ No newline at end of file
diff --git a/registrations/Views/Default/index.html b/registrations/Views/Default/index.html
new file mode 100755 (executable)
index 0000000..33e41fd
--- /dev/null
@@ -0,0 +1,5 @@
+<HTML>
+  <BODY>
+  
+  </BODY>
+</HTML>
\ No newline at end of file
diff --git a/registrations/Views/Default/registration_price_guide.html b/registrations/Views/Default/registration_price_guide.html
new file mode 100644 (file)
index 0000000..8cf0ca1
--- /dev/null
@@ -0,0 +1,103 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+"http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<title>Price Guide</title>
+<meta http-equiv="content-type" content="text/html;charset=utf-8">
+<meta http-equiv="imagetoolbar" content="no">
+<meta http-equiv="imagetoolbar" content="false">
+<link rel="stylesheet" type="text/css" href="../styles.css">
+
+<script type="text/javascript">
+<!--
+function close_popup()
+       {
+       self.close();
+       }
+-->
+</script>    
+<style type="text/css">
+<!-- 
+table {
+       background-color: white;
+       margin: 0 5%;
+       } 
+-->
+</style>
+
+</head>
+
+
+<body>
+
+<h1>{reg_term_cap} Date and Price Guide</h1>
+<h2>{convention_name}</h2>
+<p>{start_date} through {end_date}</p>
+  <p><A HREF="javascript:void close_popup();">Close Window</A></p>
+  <!--{if:reason}-->
+    <h2>Unable to display price guide</h2>
+    {reason}
+  <!--{else:reason}
+   <!--{if:cutoff_date}-->
+      <p>If {reg_term_act} before {cutoff_date}</p>
+        <table border="1">
+        <!--{if:have_rates_1}-->
+          <tr><th>&nbsp;</th><th>Base Rate</th><th>Attendees Included</th><th>Per additional Attendee</th></tr>
+          <!--{list:rate_list_1}-->
+            <tr><td>{rate_class}</td><td>{base_rate}&nbsp;</td><td>{attendee_credits}&nbsp;</td><td>{attendee_rate}&nbsp;</td></tr>
+          <!--{/list:rate_list_1}-->
+        <!--{else:have_rates_1}
+          <tr><th>No charge for {reg_term}. Other charges may apply.</th></tr>
+        {/if:have_rates_1}-->
+        </table>
+        
+    <!--{if:cutoff_date2}-->
+      <p>If {reg_term_act} on or after {cutoff_date} and before {cutoff_date2}</p>
+        <table border="1">
+        <!--{if:have_rates_2}-->
+          <tr><th>&nbsp;</th><th>Base Rate</th><th>Attendees Included</th><th>Per additional Attendee</th></tr>
+          <!--{list:rate_list_2}-->
+            <tr><td>{rate_class}</td><td>{base_rate}&nbsp;</td><td>{attendee_credits}&nbsp;</td><td>{attendee_rate}&nbsp;</td></tr>
+          <!--{/list:rate_list_2}-->
+        <!--{else:have_rates_2}
+          <tr><th>No charge for {reg_term}. Other charges may apply.</th></tr>
+        {/if:have_rates_2}-->
+        </table>
+    
+     <!--{if:cutoff_date3}-->
+      <p>If {reg_term_act} on or after {cutoff_date2} and before {cutoff_date3}</p>
+        <table border="1">
+        <!--{if:have_rates_3}-->
+          <tr><th>&nbsp;</th><th>Base Rate</th><th>Attendees Included</th><th>Per additional Attendee</th></tr>
+          <!--{list:rate_list_3}-->
+            <tr><td>{rate_class}</td><td>{base_rate}&nbsp;</td><td>{attendee_credits}&nbsp;</td><td>{attendee_rate}&nbsp;</td></tr>
+          <!--{/list:rate_list_3}-->
+        <!--{else:have_rates_3}
+          <tr><th>No charge for {reg_term}. Other charges may apply.</th></tr>
+        {/if:have_rates_3}-->
+        </table>
+    
+       <!--{if:cutoff_date4}-->
+      <p>If {reg_term_act} on or after {cutoff_date3} and before {cutoff_date4}</p>
+        <table border="1">
+        <!--{if:have_rates_4}-->
+          <tr><th>&nbsp;</th><th>Base Rate</th><th>Attendees Included</th><th>Per additional Attendee</th></tr>
+          <!--{list:rate_list_4}-->
+            <tr><td>{rate_class}</td><td>{base_rate}&nbsp;</td><td>{attendee_credits}&nbsp;</td><td>{attendee_rate}&nbsp;</td></tr>
+          <!--{/list:rate_list_4}-->
+        <!--{else:have_rates_4}
+          <tr><th>No charge for {reg_term}. Other charges may apply.</th></tr>
+        {/if:have_rates_4}-->
+        </table>
+    
+       <!--{/if:cutoff_date4}-->
+     <!--{/if:cutoff_date3}-->
+    <!--{/if:cutoff_date2}-->
+   <!--{/if:cutoff_date}-->
+  
+  <p>No {reg_term_plur} accepted after last date above.</p>
+
+  {/if:reason}-->
+
+</body>
+</html>
diff --git a/registrations/Views/Default/registrations_cc_confirmation.html b/registrations/Views/Default/registrations_cc_confirmation.html
new file mode 100644 (file)
index 0000000..bbb56fc
--- /dev/null
@@ -0,0 +1,92 @@
+<HTML>
+  <HEAD>
+    <LINK REL="stylesheet" HREF="../Views/Default/style.css">
+  </head>
+  <body bgcolor="FFFFFF">
+    <table width="750" border="0" cellspacing="0" cellpadding="0">
+      <tr>
+        <td align="center">
+            <table border="0" width="100%" cellspacing="0" cellpadding="5">
+              <tr><td colspan="2" align="center"><font class="headertitle">{reg_term_cap}: {checkout_type}</font></td></tr>
+              <tr><td colspan="2" align="center"><h3>{reg_term_act_cap} for: <font color="blue">{reg_name}</font></h3></td></tr>
+              <TR><TD COLSPAN="2" ALIGN="center">{reg_term_cap} Tracking #:&nbsp;&nbsp;{request_numb}</TD></TR>
+              <tr>
+                <td colspan="2" align="center">
+                  Thank you for your {reg_term}.<br>
+                  This confirms payment. Please print this page.
+               </td>
+              </tr>
+        <!--{if:checkout_type=Request}-->
+              <tr>
+                <td colspan="2" align="center">
+                  <FONT COLOR="blue">
+                    This is a REQUEST only.<br>
+                    You will be contacted shortly to confirm that your payment has been processed.<br>
+                    Please contact us if you do not receive a confirmation within 48 hours.
+                  </FONT>
+               </td>
+       <!--{/if:checkout_type}-->
+              </tr>
+              <TR><TD COLSPAN="2">&nbsp;<P></TD></TR>
+              <tr>
+                <td align="center" width="50%" valign="top">
+                  <table border="0">
+                    <TR>
+     <!--{if:free_reg=Yes}-->
+                      <TH ALIGN="right" valign="top"><NOBR>Contact Information:&nbsp;</NOBR></TH>
+     <!--{else:free_reg}
+                      <TH ALIGN="right" valign="top"><NOBR>Bill to:&nbsp;</NOBR></TH>
+     {/if:free_reg}-->
+                      <TD>
+                        {fname} {lname}
+                        <br><!--{if:title}-->{title}, <!--{/if:title}-->
+                        <!--{if:org}-->{org}<!--{/if:org}-->
+                        <br>{addr1}
+                        <!--{if:addr2}--><br>{addr2}<!--{/if:addr2}-->
+                        <br>{city}, {state} {zip} {country}
+                      </TD>
+                    </TR>
+                  </table>
+                </td>
+                <td valign="top" width="50%" valign="top">
+                  <table border="0" cellspacing="0" cellpadding="0" width="100%">
+                    <TR><TH ALIGN="right">Phone:&nbsp;</TH><TD>{phone}</TD></TR>
+                    <TR><TH ALIGN="right">FAX:&nbsp;</TH><TD>{fax}</TD></TR>
+                    <TR><TH ALIGN="right">E-Mail:&nbsp;</TH><TD>{email}</TD></TR>
+                  </table>
+                </TD>
+              </TR>
+              <TR><TD COLSPAN="2">&nbsp;<P></TD></TR>
+              <tr>
+                <td colspan="2" align="center">
+                  <table border="0" cellspacing="0" cellpadding="0" valign="top">
+  <!--{if:rate_name}-->
+                    <tr><th align="right">{reg_term_cap} Level:&nbsp;</th><td>{rate_name}</font></td></tr>
+  <!--{/if:rate_name}-->
+  <!--{if:attendees}-->
+                    <tr><th align="right">Number of Attendees:&nbsp;</th><td><font color="blue">{numb_attendees}</font> at <font color="blue">{rate}</font> each</font></td></tr>
+                    <TR><TD ALIGN="center" valign="top" COLSPAN="2">{attendees}</TD></TR>
+  <!--{/if:attendees}-->
+                    <TR><TD colspan="2">&nbsp;</TD></TR>
+                    <TR><TH ALIGN="right">Name on Card:&nbsp;</TH><TD>{cc_name}</TD></TR>
+                    <TR><TH ALIGN="right">Credit Card:&nbsp;</TH><TD>{cc_type} {cc_numb} exp: {cc_exp}</TD></TR>
+                    <TR><TH ALIGN="right">Authorization Code:&nbsp;</TH><TD>{cc_conf}</TD></TR>
+                    <TR><TD colspan="2">&nbsp;</TD></TR>
+                    <tr><th align="right">Amount:&nbsp;</th><td>{total}</td></tr>
+                  </table>
+                </td>
+              </tr>
+             <TR><TD COLSPAN="3">&nbsp;</TD></TR>
+             <TR><TD COLSPAN="3"><hr width="90%"></TD></TR>
+             <tr><td colspan="3" align="center"><a href="{base_url}">{cust_name}</a></td></tr>
+             <tr><td colspan="3" align="center">{cust_address}</td></tr>
+             <tr><td colspan="3" align="center">{cust_city}, {cust_state} {cust_zip}</td></tr>
+             <tr><td colspan="3" align="center">{cust_phone}</td></tr>
+            </TABLE>
+        </TD>
+      </TR>
+    </table>
+  </BODY>
+</HTML>
+
+
diff --git a/registrations/Views/Default/registrations_confirmation.html b/registrations/Views/Default/registrations_confirmation.html
new file mode 100644 (file)
index 0000000..45e9bb5
--- /dev/null
@@ -0,0 +1,129 @@
+<HTML>
+  <HEAD>
+    <LINK REL="stylesheet" HREF="../Views/Default/style.css">
+  </head>
+  <body bgcolor="FFFFFF">
+    <table width="750" border="0" cellspacing="0" cellpadding="0">
+      <tr>
+        <td align="center">
+                 <table width="100%" border="0" cellspacing="0" cellpadding="0">
+                   <tr> 
+              <td><font class="headertitle">{reg_term_cap}: {checkout_type}</font></td>
+                       </tr>
+                 </table>      
+            <table border="0" width="100%" cellspacing="0" cellpadding="5">
+              <tr><td colspan="2" align="center"><h3>{reg_termp_act_cap} for: <font color="blue">{reg_name}</font></h3></td></tr>
+              <TR><TD COLSPAN="2" ALIGN="center">{reg_term_cap} Tracking #:&nbsp;&nbsp;{request_numb}</TD></TR>
+              <tr>
+                <td colspan="2" align="center">
+                  Thank you for your {reg_term}.<br>
+                  Please print this page.
+               </td>
+              </tr>
+        <!--{if:checkout_type=Request}-->
+              <tr>
+                <td colspan="2" align="center">
+                  <FONT COLOR="blue">
+                    This is a REQUEST only.<br>
+                    You will be contacted shortly to confirm that your payment has been processed.<br>
+                    Please contact us if you do not receive a confirmation within 48 hours.
+                  </FONT>
+               </td>
+       <!--{/if:checkout_type}-->
+              </tr>
+              <TR><TD COLSPAN="2">&nbsp;<P></TD></TR>
+              <tr>
+                <td align="center" width="50%" valign="top">
+                  <table border="0">
+                    <TR>
+     <!--{if:free_reg=Yes}-->
+                      <TH ALIGN="right" valign="top"><NOBR>Contact Information:&nbsp;</NOBR></TH>
+     <!--{else:free_reg}
+                      <TH ALIGN="right" valign="top"><NOBR>Bill to:&nbsp;</NOBR></TH>
+     {/if:free_reg}-->
+                      <TD>
+                        {fname} {lname}
+                        <br><!--{if:title}-->{title}, <!--{/if:title}-->
+                        <!--{if:org}-->{org}<!--{/if:org}-->
+                        <br>{addr1}
+                        <!--{if:addr2}--><br>{addr2}<!--{/if:addr2}-->
+                        <br>{city}, {state} {zip} {country}
+                      </TD>
+                    </TR>
+                  </table>
+                </td>
+                <td valign="top" width="50%" valign="top">
+                  <table border="0" cellspacing="0" cellpadding="0" width="100%">
+                    <TR><TH ALIGN="right">Phone:&nbsp;</TH><TD>{phone}</TD></TR>
+                    <TR><TH ALIGN="right">FAX:&nbsp;</TH><TD>{fax}</TD></TR>
+                    <TR><TH ALIGN="right">E-Mail:&nbsp;</TH><TD>{email}</TD></TR>
+                    <TR><TD colspan="2">&nbsp;</TD></TR>
+     <!--{if:free_reg=No}-->
+                <!--{if:pay_code}-->
+<!--
+                    <TR><TH ALIGN="right">Payment Comp Code:&nbsp;</TH><TD>{pay_code} </TD></TR>
+-->                    
+                    <TR><TD ALIGN="center" COLSPAN="2"><FONT COLOR="blue">Comp Code accepted - No payment required. </TD></TR>
+                <!--{else:pay_code}
+                    <TR><TH ALIGN="right">Credit Card:&nbsp;</TH><TD>{cctype} {ccnum} exp: {ccmonth}/{ccyear}</TD></TR>
+                    <TR><TH ALIGN="right">Name on Card:&nbsp;</TH><TD>{ccname}</TD></TR>
+                    <TR><TH ALIGN="right">Authorization Code:&nbsp;</TH><TD>{auth_code}</TD></TR>
+                {/if:pay_code}-->
+     <!--{/if:free_reg}-->
+                  </table>
+                </TD>
+              </TR>
+              <TR><TD COLSPAN="2">&nbsp;<P></TD></TR>
+              <tr>
+                <td colspan="2" align="center">
+                  <table border="0" cellspacing="0" cellpadding="0" valign="top">
+  <!--{if:rate_classes}-->
+                    <tr><th align="center" colspan="2">{reg_term_cap} Level:&nbsp;<font color="blue">{rate_name}</font></td></tr>
+  <!--{/if:rate_classes}-->
+  <!--{if:ask_attendees=Yes}-->
+
+                    <tr><th align="right">Number of Attendees:&nbsp;</th><td><font color="blue">{numb_attendees}</font> at <font color="blue">{rate}</font> each</font></td></tr>
+                    <TR><TD ALIGN="center" valign="top" COLSPAN="2">{attendees}</TD></TR>
+  <!--{/if:ask_attendees}-->
+                  </table>
+                  <P>&nbsp;<P>
+                  <table border="0" cellspacing="0" cellpadding="3" valign="top">
+                    <tr><th align="left">Charges</th><th align="right">Per Attendee</th><th align="right">Total</th></tr>
+                  <!--{list:charges}-->
+                    <tr><td align="left">{charge_title}&nbsp;&nbsp;</td><td align="right">{charge}</td><td align="right">&nbsp;&nbsp;{extend}</td></tr>
+                  <!--{sep:charges}-->
+                  <!--{/sep:charges}-->
+                    <tr><td align="left">{charge_title}&nbsp;&nbsp;</td><td align="right">{charge}</td><td align="right">&nbsp;&nbsp;{extend}</td></tr>
+                  <!--{/list:charges}-->
+                    <tr><th align="right">Total</th><td>&nbsp;</td><td align="right"><font color="blue">{total_charges}</font></td></tr>
+                  </table>
+                </td>
+              </tr>
+             <TR><TD COLSPAN="3">&nbsp;</TD></TR>
+             <TR> 
+               <TD COLSPAN="3"> 
+                 <table width="95%" border="1" cellspacing="1" cellpadding="6" class="tblblck" align="center">
+                   <tr class="termstd"> 
+                     <td> <a name="terms"></a><span class="termshead"><CENTER><B>{reg_term_cap} Terms and Conditions</B></CENTER></span><br>
+                       <span class="termsingress"> 
+                       <P>{regterms}
+                       </span>
+                     </td>
+                   </tr>
+                 </table>
+               </TD>
+             </TR>
+             <TR><TD COLSPAN="3">&nbsp;</TD></TR>
+             <TR><TD COLSPAN="3"><hr width="90%"></TD></TR>
+             <tr><td colspan="3" align="center"><a href="{base_url}">{customer_long_name}</a></td></tr>
+             <tr><td colspan="3" align="center">{customer_address}</td></tr>
+             <tr><td colspan="3" align="center">{customer_city}, {customer_state} {customer_zip}</td></tr>
+             <tr><td colspan="3" align="center">{customer_phone}</td></tr>
+            </TABLE>
+        </TD>
+      </TR>
+    </table>
+  </BODY>
+</HTML>
+
+
diff --git a/registrations/Views/Default/registrations_intro.html b/registrations/Views/Default/registrations_intro.html
new file mode 100644 (file)
index 0000000..057dbbe
--- /dev/null
@@ -0,0 +1,51 @@
+<HTML>
+       <HEAD>
+               <META NAME="description" CONTENT="C.S. Lewis Festival - Event Registrations">
+               <title>{registrations_title}</title>
+               <META http-equiv="Pragma" content="no-cache">
+               <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+               <LINK REL="stylesheet" HREF="../Views/Default/style.css">
+        <script>       
+function fix_height( f )
+       {
+       
+       ( document.getElementById && !document.all ) ? msie = false : msie = true;
+       s = top.document.getElementById(f).style;
+       if( msie )
+               {
+               s.height = document.body.scrollHeight;
+               scroll(0,0);
+               }
+         else
+               {
+               var spaceAtBottom = 30;
+               s.height = document.height + spaceAtBottom + 'px';
+               }
+       top.scroll(0,0);
+       }
+        </script>
+       </head>
+       <body bgcolor="FFFFFF" onLoad="fix_height('f1');">
+
+                                       <TABLE WIDTH="600" border="0" cellspacing="0" cellpadding="0" background="../images/mid_sides.gif">
+                                               <TR><TD>&nbsp;<P></TD></TR>
+                                               <TR>
+                                                       <TD ALIGN="center">REGISTRATION INTRO PAGE - INTRO TEXT GOES HERE</TD>
+                                               </TR>
+                                               <TR><TD>&nbsp;<P></TD></TR>
+                                               <TR>
+                                                       <TD ALIGN="center">
+<!--{exclude}-->
+                                                               <A HREF="registrationss_step1.html">Continue to step 1</A> - Select
+<!--{/exclude}-->
+<!--{include}
+                                                               <A HREF="{this_script}?Action=Step1">Continue to step 1</A> - Select
+{/include}-->
+                                                       </TD>
+                                               </TR>
+                                       </TABLE>
+
+<!-- footer -->
+<!-- footer end -->
+  </BODY>
+</HTML>
diff --git a/registrations/Views/Default/registrations_step1.html b/registrations/Views/Default/registrations_step1.html
new file mode 100644 (file)
index 0000000..73e42ac
--- /dev/null
@@ -0,0 +1,79 @@
+<div id="registrations">
+       <h1>Online Registration</h1>
+       <div id="ingress">
+               <p>{regbulletin}</p>
+       </div>
+  <!--{if:special_bulletin}-->
+       <p>{special_bulletin}</p>
+  <!--{/if:special_bulletin}-->
+<!--{if:have_registrations=TRUE}-->
+       <!--{if:RegSelect=List}-->
+               <!-- <p>Click on name to select</p> -->
+               <!--{list:RegistrationList}-->
+                       <div class="item">
+                               <!--{exclude}-->
+                                       <h2><a href="view._step2.html">{name}</a></h2>
+                               <!--{/exclude}-->
+                               <!--{include}
+                                       <!--{if:too_late}-->
+                                       <h2>{name}</h2>
+                                       <p>Too for on-line {reg_term}. - Please call.</p>
+                                       <!--{else:too_late}
+                                               <!--{if:limited=YES}-->
+                                                       <!--{if:full=YES}-->
+                                                               <h2>{name}</h2>
+                                                               <p>Sorry, currently sold out.</p>
+                                                       <!--{else:full}
+                                                               <h2><a href="{base_secure_url}?Action=Step2&registration={id}{link_data}">{name}</a></h2>
+                                                       {/if:full}-->
+                                               <!--{else:limited}
+                                                       <h2><a href="{base_secure_url}?Action=Step2&registration={id}{link_data}" CLASS="pac_link">{name}</a></h2>
+                                               {/if:limited}-->
+                                       {/if:too_late}-->
+                               {/include}-->
+                       <div class="item-description">
+                                       <!--{if:image}--><img src="{base_url}/images/thumb/{image}" alt=""><!--{/if:image}-->{descr}
+                               </div>
+                               <div class="item-dates">
+                                       From {start_date} through {end_date}
+                               </div>
+<!--
+                               <div class="item-info">
+                                       <a href="{base_url}/registrations/registrations_price_guide.phtml?registration={id}" target="pricing" onClick="w=window.open('registrations_price_guide.phtml?registration={id}','pricing','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=500,height=400');">
+                                               Click here for dates and rates
+                                       </a>
+                               </div>
+-->
+                       <!--{if:limited}-->
+                       <div class="item-limitation">
+                                       <!--{if:full=YES}-->
+               A maximum number of {attendee_count} attendees have already {reg_term_past}. Currently sold out.
+                                       <!--{else:full}
+               {attendee_count} registered out of a maximum of {attendee_max} attendees. {attendee_left} more attendees may still register.
+                                       {/if:full}-->
+                               </div>
+                       <!--{/if:limited}-->
+                       </div><!-- /.item -->
+               <!--{/list:RegistrationList}-->
+               <!--{else:RegSelect}
+                       <!--{exclude}-->
+                               <form action="view.registrations_step2.html">
+                       <!--{/exclude}-->
+                       <!--{include}
+                               <form actionON="{base_secure_url}" name="step2" method="post">
+                       {/include}-->
+                                       <input type="hidden" name="catid" value="{category_id}">
+                                       <input type="hidden" name="Action" value="{next_step}">
+                       <!--{include}
+                       {form_data}
+                       {/include}-->
+                                       <p>Select:</p>
+                                       <p>{RegPicklist}</p>
+                                       <input type="submit" name="continue" value="Continue">
+                               </form>
+                       {/if:RegSelect}-->
+               <!--{else:have_registrations}
+    <p>Sorry, there are no registrations at this time.</p>
+               {/if:have_registrations}-->
+               <p>{regterms}</p>
+       </div>
diff --git a/registrations/Views/Default/registrations_step2.html b/registrations/Views/Default/registrations_step2.html
new file mode 100644 (file)
index 0000000..91c429d
--- /dev/null
@@ -0,0 +1,56 @@
+<div id="registrations">
+       <!-- <h1>Online Registration</h1> -->
+  <!--{if:have_reason=YES}-->
+               <div class="warning">
+                       Your request was not processed because:<br>
+       <ul>
+       <!--{list:reason}-->
+                       <li>{text}</li>
+       <!--{/list:reason}-->
+       </ul>
+               </div>
+  <!--{/if:have_reason}-->
+       <div class="item">
+       <h2>{reg_term_cap}: {reg_name}</h2>
+       <!--{if:image}--><img src="{base_secure_url}/images/thumb/{image}" alt=""><!--{/if:image}-->
+       <!--{if:reg_descr}-->
+               <p>{reg_descr}</p>
+       <!--{/if:reg_descr}-->
+               <p>Runs from {start_date} through {end_date}</p></div>
+       <!--{if:rate_classes}-->
+       <!--{if:rates_descr}-->
+               <p>{rates_descr}</p>
+       <!--{/if:rates_descr}-->
+
+       <form action="{base_secure_url}" name="step3" method="post" enctype="multipart/form-data">
+               <input type="hidden" name="Action" value="{next_step}">
+               {form_data}
+       <!--{list:rate_class_list}-->
+               <div class="registration-rate">
+                       <input type="radio" name="rate_class" value="{rate_class}" {rate_class_selected}> {rate_class_name} - <!--{if:rate_class_base}-->{rate_class_base}<!--{/if:rate_class_base}-->
+               </div>
+       <!--{if:rate_class_rate}-->
+       <!--{if:attendee_credits>0}-->, includes {attendee_credits} attendees, {rate_class_rate}/additional attendee<!--{else:attendee_credits} plus {rate_class_rate}/attendee{/if:attendee_credits}-->
+       <!--{/if:rate_class_rate}-->
+       <!--{/list:rate_class_list}-->
+  <!--{else:rate_classes}
+               <input type="hidden" name="rate_class" value="-1">
+       {/if:rate_classes}-->
+       <!--{if:ask_attendees=Yes}-->
+       <script type="text/javascript" src="{base_secure_url}/java_functions.js"></script>
+       <h3>Attendees</h3>
+       <p>Please enter all attendees names, using one box per attendee. Additional boxes will be created as needed.</p>
+       <p>All attendees will be {reg_term_past} at the level selected above.  Each attendee must have a first and last name.</p>
+       <p>Please use your tab key to create a new attendee field.</p>
+       <h4>Attendees Names:</h4>
+       <p>{attendees}</p>
+       <!--{/if:ask_attendees}-->
+       {magic_form}
+       <!--{if:required}-->
+       <!--{if:required=Yes}-->
+       <p>Fields marked with a star (*) are required fields.</p>
+       <!--{/if:required}-->
+      <!--{/if:required}-->
+       <input type="submit" name="continue" value="Continue">
+</form>
+</div>
diff --git a/registrations/Views/Default/registrations_step3.html b/registrations/Views/Default/registrations_step3.html
new file mode 100644 (file)
index 0000000..b7d765b
--- /dev/null
@@ -0,0 +1,118 @@
+<form action="{base_secure_url}" name="step3" method="post">
+    <input type="hidden" name="catid" value="{category_id}">
+    <input type="hidden" name="Action" value="{next_step}">
+    {form_data}
+<div id="registrations">
+
+<div class="item">
+       <!--{if:reg_image}--><img src="{base_secure_url}/images/thumb/{reg_image}" alt=""><!--{/if:reg_image}-->
+       <h2>{reg_name}</h2>
+               <!--{if:rate_classes}-->
+               <p>{reg_term_cap} Level: {rate_name}</p>
+<!--{/if:rate_classes}-->
+<!--{if:ask_attendees=Yes}-->
+               <p>Number of Attendees: {numb_attendees}</p>
+               {attendees}
+<!--{/if:ask_attendees}-->
+<!--{if:free_reg=Yes}-->
+               <p>There are no charges or fees associated with this {reg_term}.</p>
+<!--{else:free_reg}
+</div>
+<!--{if:ask_attendees=Yes}-->
+<div id="contact">
+                  <table border="1">
+                    <tr><th>Charges</th><th>Per Attendee</th><th>Total</th></tr>
+                  <!--{list:charges}-->
+                    <tr><td>{charge_title}</td><td>{charge}</td><td>{extend}</td></tr>
+                  <!--{sep:charges}-->
+                  <!--{/sep:charges}-->
+                    <tr><td>{charge_title}</td><td>{charge}</td><td>{extend}</td></tr>
+                  <!--{/list:charges}-->
+                    <tr><th>Total</th><td></td><td>{total_charges}</td></tr>
+                  </table>
+</div>
+<!--{else:ask_attendees}
+
+                  <table>
+                    <tr><th>Charges</th><th>&nbsp;</th><th>Total</th></tr>
+                  <!--{list:charges}-->
+                    <tr><td>{charge_title}</td><td></td><td>{extend}</td></tr>
+                  <!--{sep:charges}-->
+                  <!--{/sep:charges}-->
+                    <tr><td>{charge_title}</td><td></td><td>{extend}</td></tr>
+                  <!--{/list:charges}-->
+                    <tr><th>Total</th><td></td><td>{total_charges}</td></tr>
+                  </table>
+
+{/if:ask_attendees}-->
+{/if:free_reg}-->
+  <!--{if:have_reason=YES}-->
+
+                <div class="warning">
+       <ul>
+       <!--{list:reason}-->
+                       <li>{text}</li>
+       <!--{/list:reason}-->
+       </ul>
+                </div>
+  <!--{/if:have_reason}-->
+<!--{if:free_reg=Yes}-->
+                       <h3>Contact Information</h3>
+<!--{else:free_reg}
+               <h3>Billing Information</h3>
+{/if:free_reg}-->
+               <p>Fields marked with a star (*) are required fields.</p>
+
+     <!--{if:free_reg=Yes}-->
+     <!--{else:free_reg}
+
+     {/if:free_reg}-->
+                  <table border="0">
+                    <TR><TD class="labelcell">* First Name:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="fname" VALUE="{fname}"></TD></TR>
+                    <TR><TD class="labelcell">* Last Name:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="lname" VALUE="{lname}"></TD></TR>
+                    <TR><TD class="labelcell">Company/Organization:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="org" VALUE="{org}"></TD></TR>
+                    <TR><TD class="labelcell">Title:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="c_title" VALUE="{title}"></TD></TR>
+                    <TR><TD class="labelcell">* Address:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="addr1" VALUE="{addr1}"></TD></TR>
+                    <TR><TD class="labelcell">Address 2:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="addr2" VALUE="{addr2}"></TD></TR>
+                    <TR><TD class="labelcell">* City:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="city" VALUE="{city}"></TD></TR>
+                    <TR><TD class="labelcell">* State/Prov.:</TD><TD class="fieldcell">{state}</TD></TR>
+                    <TR><TD class="labelcell">* Country:</TD><TD class="fieldcell">{country}</TD></TR>
+                    <TR><TD class="labelcell">* ZIP/Postal Code:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="zip" SIZE="10" VALUE="{zip}"></TD></TR>
+                    <TR><TD class="labelcell">* Phone:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="phone" VALUE="{phone}"></TD></TR>
+                    <TR><TD class="labelcell">FAX:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="fax" VALUE="{fax}"></TD></TR>
+                    <TR><TD class="labelcell">* E-Mail:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="email" VALUE="{email}"></TD></TR>
+                  </table>
+
+     <!--{if:free_reg=No}-->
+
+<p>If you received a "Payment Comp Code", please enter it here and leave the credit card information blank.</p>
+<p>Payment Comp Code: <INPUT TYPE="text" NAME="pay_code" SIZE="10" VALUE="{pay_code}"></p>
+<p>If you do not have a Payment Comp Code, pay by credit card below.</p>
+<p>The fees totaled above will be charged to your credit card once this form is submitted</p>
+
+<table border="0">
+<TR><TD class="labelcell">* Card Type:</TD><TD class="fieldcell">{cctype}</TD></TR>
+<TR><TD class="labelcell">* Name on Credit Card:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="ccname" VALUE="{ccname}"></TD></TR>
+<TR><TD class="labelcell">* Card #:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="ccnum" VALUE="{ccnum}"></TD></TR>
+<TR><TD class="labelcell">* Expiration Date:</TD><TD class="fieldcell">Month {ccmonth} Year {ccyear}</TD></TR>
+<TR><TD class="labelcell">CVV #:</TD><TD class="fieldcell"><INPUT TYPE="text" NAME="cccode" SIZE="5" VALUE="{cccode}"></TD></TR>
+<TR><TD class="labelcell" COLSPAN="2" style="font-size: 11px;">CVV is the three digit number on the<BR>signature side of your credit card.</TD></TR>
+</table>
+    <!--{/if:free_reg}-->
+
+                  Please send me future offers by email:
+                  <input type="checkbox" NAME="email_ok" VALUE="t" <!--{if:email_ok=t}-->CHECKED<!--{/if:email_ok}--> >
+                                                                       <INPUT TYPE="submit" NAME="continue" VALUE="Continue">
+
+<!--{if:regterms}-->
+                                                                       <h3>{reg_term_cap} Terms and Conditions</h3>
+                                                                       {regterms}
+<!--{/if:regterms}-->
+
+<!--{if:regterms_2}-->
+                                                                       <h3>Terms and Conditions specific to this {reg_term}</h3>
+                                                                       {regterms_2}
+<!--{/if:regterms_2}-->
+</div>
+</div><!-- /#registrations -->
+</form>
diff --git a/registrations/Views/Default/registrations_store.html b/registrations/Views/Default/registrations_store.html
new file mode 100644 (file)
index 0000000..77dbff1
--- /dev/null
@@ -0,0 +1,93 @@
+            <table border="1" background="../images/mid_sides.gif" cellspacing="0" cellpadding="5">
+              <tr><td colspan="2" align="center"><h3>{reg_term_act_cap} for: <font color="blue">{reg_name}</font></h3></td></tr>
+              <tr>
+                <td align="center" width="50%" valign="top">
+                  <table border="0" cellspacing="0" cellpadding="0">
+                    <TR>
+     <!--{if:free_reg=Yes}-->
+                      <TH ALIGN="right" valign="top"><NOBR>Contact Information:&nbsp;</NOBR></TH>
+     <!--{else:free_reg}
+                      <TH ALIGN="right" valign="top"><NOBR>Bill to:&nbsp;</NOBR></TH>
+     {/if:free_reg}-->
+                      <TD>
+                        {fname} {lname}
+                        <!--{if:title}--><br>{title}, <!--{/if:title}-->
+                        <!--{if:org}-->{org}<!--{/if:org}-->
+                        <br>{addr1}
+                        <!--{if:addr2}--><br>{addr2}<!--{/if:addr2}-->
+                        <br>{city}, {state} {zip} {country}
+                      </TD>
+                    </TR>
+                  </table>
+                </td>
+                <td valign="top" width="50%" valign="top">
+                  <table border="0" cellspacing="0" cellpadding="0" width="100%">
+                    <TR><TH ALIGN="right">Phone:&nbsp;</TH><TD>{phone}</TD></TR>
+                    <TR><TH ALIGN="right">FAX:&nbsp;</TH><TD>{fax}</TD></TR>
+                    <TR><TH ALIGN="right">E-Mail:&nbsp;</TH><TD>{email}</TD></TR>
+     <!--{if:free_reg=No}-->
+                    <TR><TD colspan="2">&nbsp;</TD></TR>
+                <!--{if:pay_code}-->
+                    <TR><TH ALIGN="right">Payment Code:&nbsp;</TH><TD>{pay_code}</TD></TR>
+                <!--{else:pay_code}
+                    <TR><TH ALIGN="right" valign="top">Credit Card:&nbsp;</TH><TD>{cctype} {ccnum}<br>exp: {ccmonth}/{ccyear}</TD></TR>
+                    <TR><TH ALIGN="right">Name on Card:&nbsp;</TH><TD>{ccname}</TD></TR>
+                    <TR><TH ALIGN="right">Auth Code:&nbsp;</TH><TD>{auth_code}</TD></TR>
+                {/if:pay_code}-->
+    <!--{/if:free_reg}-->
+                  </table>
+                </TD>
+              </TR>
+              <tr>
+                <td colspan="2" align="center">
+                  <table border="0" cellspacing="0" cellpadding="0" valign="top">
+  <!--{if:rate_classes}-->
+                    <tr><th align="center">{reg_term_cap} Level:&nbsp;</td><td><font color="blue">{rate_name}</font></td></tr>
+  <!--{/if:rate_classes}-->
+  <!--{if:ask_attendees=Yes}-->
+                    <tr><th align="right">Number of Attendees:&nbsp;</th><td><font color="blue">{numb_attendees}</font>
+                      <!--{if:free_reg=Yes}--> <!--{else:free_reg} at <font color="blue">{rate}</font> each</font> {/if:free_reg}-->
+                    </td></tr>
+                    <TR><TD ALIGN="center" valign="top" COLSPAN="2">{attendees}</TD></TR>
+  <!--{/if:ask_attendees}-->
+                  </table>
+                  <P>
+     <!--{if:free_reg=Yes}-->
+                  There are no fees or charges associated with this {reg_term}.
+     <!--{else:free_reg}                   
+                  <table border="0" cellspacing="0" cellpadding="0" valign="top">
+                    <tr><th align="left">Charges</th><th align="right">Per Attendee</th><th align="right">Total</th></tr>
+                  <!--{list:charges}-->
+                    <tr><td align="left">{charge_title}&nbsp;&nbsp;</td><td align="right">{charge}</td><td align="right">&nbsp;&nbsp;{extend}</td></tr>
+                  <!--{sep:charges}-->
+                  <!--{/sep:charges}-->
+                    <tr><td align="left">{charge_title}&nbsp;&nbsp;</td><td align="right">{charge}</td><td align="right">&nbsp;&nbsp;{extend}</td></tr>
+                  <!--{/list:charges}-->
+                    <tr><th align="right">Total</th><td>&nbsp;</td><td align="right"><font color="blue">{total_charges}</font></td></tr>
+                  </table>
+     {/if:free_reg}-->                  
+                </td>
+              </tr>
+              <tr><td colspan="2" align="center"><H3>Other {reg_term_cap} Data</H3></td></tr>
+              <tr>
+                <td colspan="2" align="center">
+                  <table border="0" cellspacing="0" cellpadding="0">
+                    <tr><th align="left">Field</th><th align="left">Value</th><th align="right" width="10%">Charges</th></tr>
+                  <!--{list:field_values}-->
+                    <tr>
+                      <td align="left" valign="top">{field_title}&nbsp;</td>
+                      <td align="left" valign="top">{field_value}&nbsp;</td>
+                      <td align="right" valign="top" width="10%">{field_charge}&nbsp;</td>
+                    </tr>
+                  <!--{sep:field_values}-->
+                  <!--{/sep:field_values}-->
+                    <tr>
+                      <td align="left" valign="top">{field_title}&nbsp;</td>
+                      <td align="left" valign="top">{field_value}&nbsp;</td>
+                      <td align="right" valign="top" width="10%">{field_charge}&nbsp;</td>
+                    </tr>
+                  <!--{/list:field_values}-->
+                  </table>
+                </td>
+              </tr>
+            </TABLE>
diff --git a/registrations/Views/Default/registrations_summary.html b/registrations/Views/Default/registrations_summary.html
new file mode 100644 (file)
index 0000000..97c6157
--- /dev/null
@@ -0,0 +1,92 @@
+<div id="registrations">
+
+<h3>{reg_term_act_cap} for:  {reg_name}</h3>
+<!--{if:duplicate!TRUE}-->
+<p>{reg_term_cap} Tracking #:&nbsp;&nbsp;{request_numb}</p>
+<p>Thank you for your {reg_term}. Please print this page.</p>
+<!--{if:have_reason==YES}-->
+<p>Your request was not processed because: {reason}</p>
+<!--{else:have_reason}
+
+<!--{if:free_reg=Yes}-->
+       <h3>Contact Information:</h3>
+<!--{else:free_reg}
+Bill to:
+{/if:free_reg}-->
+{fname} {lname}
+<!--{if:title}-->
+       <h3>{title},
+<!--{/if:title}-->
+<!--{if:org}-->{org}<!--{/if:org}-->
+</h3>
+{addr1}
+<!--{if:addr2}--><br>{addr2}<!--{/if:addr2}-->
+<br>{city}, {state} {zip} {country}
+
+<table>
+  <TR><TH class="labelcell">Phone:</TH><TD class="fieldcell">{phone}</TD></TR>
+  <TR><TH class="labelcell">FAX:</TH><TD class="fieldcell">{fax}</TD></TR>
+  <TR><TH class="labelcell">E-Mail:</TH><TD class="fieldcell">{email}</TD></TR>
+        <!--{if:free_reg=No}-->                    
+                <!--{if:pay_code}-->
+<!--                
+<TR><TH class="labelcell">Payment Comp Code:</TH><TD class="fieldcell">{pay_code}</TD></TR>
+-->
+<TR><TD colspan="2">Comp Code accepted - No payment required. </TD></TR>
+                <!--{else:pay_code}
+<TR><TH class="labelcell">Credit Card:&nbsp;</TH><TD class="fieldcell">{cctype} {ccnum} exp: {ccmonth}/{ccyear}</TD></TR>
+<TR><TH class="labelcell">Name on Card:&nbsp;</TH><TD class="fieldcell">{ccname}</TD></TR>
+<TR><TH class="labelcell">Authorization Code:&nbsp;</TH><TD class="fieldcell">{auth_code}</TD></TR>
+                {/if:pay_code}-->
+        <!--{/if:free_reg}-->
+                  </table>
+
+                  <table>
+  <!--{if:rate_classes}-->
+                    <tr><th class="labelcell">{reg_term_cap} Level:</th><td class="fieldcell">{rate_name}</td></tr>
+  <!--{/if:rate_classes}-->
+  <!--{if:ask_attendees=Yes}-->
+                    <tr><th class="labelcell">Number of Attendees:</th><td class="fieldcell">{numb_attendees}
+                        <!--{if:free_reg=Yes}--> <!--{else:free_reg} at {rate}  each  {/if:free_reg}-->
+                    </td></tr> 
+                    <TR><TD class="labelcell" colspan="2">{attendees}</TD></TR>
+  <!--{/if:ask_attendees}-->
+                  </table>
+        <!--{if:free_reg=Yes}-->
+                  <p>There are no fees or charges associated with this {reg_term}.</p>
+        <!--{else:free_reg}
+                  <table>
+                    <tr><th class="labelcell">Charges</th><th class="labelcell">Per Attendee</th><th  class="labelcell">Total</th></tr>
+                  <!--{list:charges}-->
+                    <tr><td class="labelcell">{charge_title}</td><td class="labelcell">{charge}</td><td class="labelcell">{extend}</td></tr>
+                  <!--{sep:charges}-->
+                  <!--{/sep:charges}-->
+                    <tr><td class="labelcell">{charge_title}</td><td class="labelcell">{charge}</td><td class="labelcell">{extend}</td></tr>
+                  <!--{/list:charges}-->
+                    <tr><th class="labelcell">Total</th><td></td><td class="labelcell">{total_charges}</td></tr>
+                  </table>
+        {/if:free_reg}-->
+
+  {/if:have_reason}-->
+  <!--{else:duplicate}
+
+<h3>NOTE:</h3>
+<p>It appears that you have already submitted this request.</p>
+<p>
+This could happen if you clicked the "Continue" button 
+more than one, or you used the "Back" button on your browser
+and resubmitted this request.
+</P>
+<p>
+You should receive a message via E-Mail indicating that we have 
+received your {reg_term}. If you do not receive that message within
+24 hours, please contact the {customer_name} at {customer_phone}<!--{if:customer_tollfree}--> or toll free at {customer_tollfree}<!--{/if:customer_tollfree}-->.
+</p>
+  {/if:duplicate}-->
+
+<h3>{reg_term_cap} Terms and Conditions</h3>
+<p>{regterms}</p>
+<h3>Terms and Conditions specific to this {reg_term}</h3>
+<p>{regterms_2}</p>
+
+</div><!-- /#registrations -->
diff --git a/registrations/Views/Default/reports_csv.html b/registrations/Views/Default/reports_csv.html
new file mode 100644 (file)
index 0000000..eee8a40
--- /dev/null
@@ -0,0 +1 @@
+{body}
diff --git a/registrations/Views/Default/reports_print.html b/registrations/Views/Default/reports_print.html
new file mode 100644 (file)
index 0000000..2ce494c
--- /dev/null
@@ -0,0 +1,23 @@
+<html>
+  <head>
+    <title>Registration Reports</title>
+    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+    <META NAME="Author" CONTENT="Gaslight Media">
+    <META http-equiv="Pragma" content="no-cache">
+
+<!--{exclude}-->
+    <link rel="stylesheet" href="../../style.css">
+<!--{/exclude}-->
+<!--{include}
+    <link rel="stylesheet" href="{stylesheet}">
+{/include}-->
+  </head>
+  <body">
+    <center>
+      <div class="standout">{cust_name}</div>
+  
+      {body}
+      
+    </center>
+  </body>
+</html>
\ No newline at end of file
diff --git a/registrations/Views/Default/style.css b/registrations/Views/Default/style.css
new file mode 100644 (file)
index 0000000..1644e4c
--- /dev/null
@@ -0,0 +1,621 @@
+.pseudo_link
+       {
+    FONT-SIZE: 11px;
+    COLOR: #006bb7;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: none
+       }
+A:link
+       {
+    FONT-SIZE: 11px;
+    COLOR: #006bb7;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: none
+       }
+A:visited
+       {
+    FONT-SIZE: 11px;
+    COLOR: #666666;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+A:active
+       {
+    FONT-SIZE: 11px;
+    COLOR: #ee3a42;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+A:hover
+       {
+    FONT-SIZE: 11px;
+    COLOR: #006bb7;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+P
+       {
+    FONT-SIZE: 11px;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+.detailtitle
+       {
+    FONT-WEIGHT: bold;
+    FONT-SIZE: 13px;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+.places
+       {
+    FONT-WEIGHT: bold;
+    FONT-SIZE: 13px;
+    COLOR: #969696;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }       
+.featuretitle
+       {
+    FONT-WEIGHT: bold;
+    FONT-SIZE: 13px;
+    COLOR: #2e629b;
+    FONT-FAMILY: Verdana, Arial, Helvetica
+       }
+.headertitle
+       {
+    BORDER-RIGHT: medium none;
+    BORDER-TOP: medium none;
+    MARGIN-TOP: 0px;
+    FONT-WEIGHT: bolder;
+    FONT-SIZE: 16pt;
+    MARGIN-BOTTOM: 0px;
+    PADDING-BOTTOM: 0px;
+    TEXT-TRANSFORM: none;
+    BORDER-LEFT: medium none;
+    COLOR: #093250;
+    PADDING-TOP: 0px;
+    BORDER-BOTTOM: medium none;
+    FONT-STYLE: normal;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+.subtitle
+       {
+    BORDER-RIGHT: medium none;
+    BORDER-TOP: medium none;
+    MARGIN-TOP: 0px;
+    FONT-WEIGHT: bolder;
+    FONT-SIZE: 12pt;
+    MARGIN-BOTTOM: 0px;
+    PADDING-BOTTOM: 0px;
+    TEXT-TRANSFORM: none;
+    BORDER-LEFT: medium none;
+    COLOR: #093250;
+    PADDING-TOP: 0px;
+    BORDER-BOTTOM: medium none;
+    FONT-STYLE: normal;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }phpinfo();exit;
+echo $_PUT['Action'];
+
+
+.terttitle
+       {
+    BORDER-RIGHT: medium none;
+    BORDER-TOP: medium none;
+    MARGIN-TOP: 0px;
+    FONT-WEIGHT: lighter;
+    FONT-SIZE: 10pt;
+    MARGIN-BOTTOM: 0px;
+    PADDING-BOTTOM: 0px;
+    TEXT-TRANSFORM: none;
+    BORDER-LEFT: medium none;
+    COLOR: #093250;
+    PADDING-TOP: 0px;
+    BORDER-BOTTOM: medium none;
+    FONT-STYLE: normal;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+H1
+       {
+    FONT-SIZE: 16pt;
+    FONT-FAMILY: 'Arial, Verdana, Helvetica'
+       }
+H2
+       {
+    FONT-SIZE: 15pt;
+    FONT-FAMILY: 'Arial, Verdana, Helvetica'
+       }
+H3
+       {
+    FONT-SIZE: 14pt;
+    PADDING-BOTTOM: 0px;
+    FONT-FAMILY: 'Arial, Verdana, Helvetica'
+       }
+H4
+       {
+    FONT-SIZE: 13pt;
+    PADDING-BOTTOM: 0px;
+    FONT-FAMILY: 'Arial, Verdana, Helvetica'
+       }
+B
+       {
+    FONT-WEIGHT: bold;
+    FONT-SIZE: 10pt;
+    FONT-FAMILY: Arial, Verdana, Helvetica
+       }
+A
+       {
+    FONT-FAMILY: Arial, Verdana, Helvetica;
+    TEXT-DECORATION: underline
+       }
+TH 
+       {
+    font-size: 12px; font-family:  Verdana, arial,helvetica; font-weight: bold; 
+       }
+TD
+       {
+    FONT-SIZE: 10px;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+TD.small
+       {
+    FONT-SIZE: 9px;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+.pos_rel
+       {
+    POSITION: relative;
+    HEIGHT: 20px
+       }
+.pos_abs
+       {
+    FONT-WEIGHT: bold;
+    FONT-SIZE: 8pt;
+    Z-INDEX: 90;
+    PADDING-TOP: 0px;
+    POSITION: absolute;
+    HEIGHT: 20px
+       }
+#dmenu1
+       {
+    Z-INDEX: 100
+       }
+#dmenu2
+       {
+    Z-INDEX: 100
+       }
+#dmenu3
+       {
+    Z-INDEX: 100
+       }
+#dmenu4
+       {
+    Z-INDEX: 100
+       }
+#dmenu5
+       {
+    Z-INDEX: 100
+       }
+#dmenu6
+       {
+    Z-INDEX: 100
+       }
+A.menu
+       {
+    FONT-WEIGHT: bold;
+    FONT-SIZE: 8pt;
+    COLOR: #000000;
+    FONT-FAMILY: Arial, Verdana, Helvetica;
+    TEXT-DECORATION: none
+       }
+A.menuitem
+       {
+    FONT-SIZE: 8pt;
+    COLOR: #000000;
+    TEXT-DECORATION: none
+       }
+A.menuitem:link
+       {
+    FONT-SIZE: 8pt;
+    COLOR: #000000;
+    TEXT-DECORATION: none
+       }
+A.menuitem
+       {
+    FONT-SIZE: 8pt;
+    TEXT-DECORATION: none
+       }
+.menutop
+       {
+    BORDER-RIGHT: black 1px solid;
+    BORDER-TOP: black 1px solid;
+    FONT-WEIGHT: bold;
+    FONT-SIZE: 8pt;
+    BORDER-LEFT: black 1px solid;
+    COLOR: #ffffff;
+    BORDER-BOTTOM: black 1px solid;
+    FONT-FAMILY: Arial, Verdana, Helvetica;
+    TEXT-DECORATION: none
+       }
+A.menutop:hover
+       {
+    BORDER-RIGHT: black 1px solid;
+    BORDER-TOP: black 1px solid;
+    FONT-WEIGHT: bold;
+    FONT-SIZE: 8pt;
+    BORDER-LEFT: black 1px solid;
+    COLOR: #ffffff;
+    BORDER-BOTTOM: black 1px solid;
+    FONT-FAMILY: Arial, Verdana, Helvetica;
+    TEXT-DECORATION: none
+       }
+.copyright
+       {
+    FONT-SIZE: 8pt;
+    FONT-FAMILY: Arial, Verdana, Helvetica
+       }
+.navlink 
+       {
+    FONT-SIZE: 11px;
+    COLOR: black;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+A.subnav:active
+       {
+    FONT-WEIGHT: bolder;
+    FONT-SIZE: 10px;
+    COLOR: #ffffff;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: none;
+       }
+A.subnav:link
+       {
+    FONT-WEIGHT: bolder;
+    FONT-SIZE: 10px;
+    COLOR: #ffffff;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: none;
+       }
+A.subnav:visited
+       {
+    FONT-WEIGHT: bolder;
+    FONT-SIZE: 10px;
+    COLOR: #ffffff;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: none;
+       }
+A.subnav:hover
+       {
+    FONT-SIZE: 10px;
+    COLOR: #0066cc;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    BACKGROUND-COLOR: #ffffff;
+    TEXT-DECORATION: underline;
+       }
+INPUT.btn
+       {
+    BORDER-RIGHT: black 1px groove;
+    BORDER-TOP: black 1px groove;
+    FONT-WEIGHT: bolder;
+    FONT-SIZE: 12px;
+    BORDER-LEFT: black 1px groove;
+    COLOR: #ffffff;
+    BORDER-BOTTOM: black 1px groove;
+    FONT-FAMILY: Arial;
+    BACKGROUND-COLOR: #999999;
+       }
+A.image:hover
+       {
+    FONT-SIZE: 11px;
+    COLOR: #0066cc;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: underline
+       }
+.checkout
+       {
+    FONT-WEIGHT: bold;
+    FONT-SIZE: 13px;
+    COLOR: #e93244;
+    FONT-FAMILY: Verdana, Arial, Helvetica
+       }
+A.criteria:active
+       {
+    FONT-SIZE: 11px;
+    COLOR: #e3413c;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: underline
+       }
+A.criteria:link
+       {
+    FONT-SIZE: 11px;
+    COLOR: #0067cd;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: underline
+       }
+A.criteria:visited
+       {
+    FONT-SIZE: 11px;
+    COLOR: #76a4d3;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: underline
+       }
+A.criteria:hover
+       {
+    FONT-SIZE: 11px;
+    COLOR: #0067cd;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: underline
+       }phpinfo();exit;
+echo $_PUT['Action'];
+
+
+A.tab-nav-text:active
+       {
+    FONT-WEIGHT: bolder;
+    FONT-SIZE: 12px;
+    COLOR: #ffffff;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: none
+       }
+A.tab-nav-text:link
+       {
+    FONT-WEIGHT: bolder;
+    FONT-SIZE: 12px;
+    COLOR: #ffffff;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: none
+       }
+A.tab-nav-text:visited
+       {
+    FONT-WEIGHT: bolder;
+    FONT-SIZE: 12px;
+    COLOR: #ffffff;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: none
+       }
+A.tab-nav-text:hover
+       {
+    FONT-SIZE: 12px;
+    COLOR: white;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    BACKGROUND-COLOR: transparent;
+    TEXT-DECORATION: underline
+       }
+.nonnav
+       {
+    FONT-SIZE: 11px;
+    COLOR: black;
+    FONT-FAMILY: Arial, Verdana
+       }
+LI
+       {
+    FONT-SIZE: 11px;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+A.criteria2:link
+       {
+    FONT-SIZE: 11px;
+    COLOR: #0067cd;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    TEXT-DECORATION: underline
+       }
+DIV
+       {
+    FONT-SIZE: 11px;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+INPUT
+       {
+    FONT-SIZE: 11px;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+TEXTAREA
+       {
+    FONT-SIZE: 11px;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }       
+SELECT
+       {
+    FONT-SIZE: 11px;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+OPTION
+       {
+    FONT-SIZE: 11px;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
+       }
+.std_textphpinfo();exit;
+echo $_PUT['Action'];
+
+
+       {
+       padding-left: .25cm
+       }
+.bold_text
+       {
+       font-weight: bold; 
+       padding-left: .25cm
+       }
+.stepdescr
+       {
+       font-weight: bold
+       }
+.redtext
+       {
+       font-size: 12px; 
+       color: #CC0000;
+       font-family: Arial, Helvetica, sans-serif; 
+       font-weight: normal; 
+       }
+.redhead 
+       {
+       font-size: 12px; 
+       font-weight: bold; 
+       color: #CC0000; 
+       font-family: Arial, Helvetica, sans-serif; 
+       }
+A.link
+       {
+       font-size: 16px;
+       }
+A.link:visited
+       {
+       font-size: 16px;
+       }
+A.link:active
+       {
+       font-size: 16px; 
+       }
+A.link:hover
+       {
+       font-size: 16px;
+       }
+.standout
+       {
+       COLOR: #006bb7; 
+       font-size: 16px;
+       }
+.standout_small
+       {
+       COLOR: #006bb7; 
+       font-size: 11px;
+       }
+.theader
+       {
+       font-size: 120%; 
+       font-family: arial,helvetica; 
+       color: #FFFFFF; 
+       }
+.text
+       {
+       font-size: 100%; 
+       font-family: 
+       arial,helvetica; 
+       color: #000000;
+       }
+.small_text
+       {
+    FONT-SIZE: 8px;
+    FONT-FAMILY: Arial, Helvetica;
+       }
+.title1
+       {
+       font-size: 22px;
+       font-weight: bold; color: #006bb7;
+       font-family: Arial, Helvetica, sans-serif;
+       }
+.title2
+       {
+       font-size: 22px; 
+       font-weight: bold; 
+       color: black; 
+       font-family: Arial, Helvetica, sans-serif; 
+       }
+.menu_normal 
+       {
+    FONT-SIZE: 11px;
+    COLOR: black;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    BACKGROUND-COLOR: $FFFFFF;
+       }
+.menu_title
+       {
+    FONT-SIZE: 11px;
+    COLOR: black;
+       font-weight: bold; 
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    BACKGROUND-COLOR: $FFFFFF;
+       }
+.menu_active
+       {
+    FONT-SIZE: 11px;
+    COLOR: white;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    BACKGROUND-COLOR: #3399EE;
+       }
+.menu_unavailable
+       {
+    FONT-SIZE: 11px;
+    COLOR: gray;
+    FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
+    BACKGROUND-COLOR: $FFFFFF;
+       }
+
+
+
+.quicktip                      { text-align: left; position: absolute; top: 0; left: 0; width: 410px; visibility: hidden; z-index: 100;
+                                               font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; border: 1px solid #000; }
+.quicktip-prompt       { cursor: help; }
+.quicktip-titlebar     { background-color: #87CEFA;    }
+.quicktip-title        { font-weight: bold; color: black; padding: 3px;        }
+.quicktip-close        { font-weight: bold; color: white;  text-decoration: none;      float: right; position: relative; display: block; padding: 3px;}
+.quicktip-body                 { background-color: #FDF5E6; color: black; padding: 8px; font-weight: normal;}
+.quicktip-fieldname { font-weight: bold; margin-bottom: 0.5em; border-bottom: 1px solid #333;}
+.quicktip-prompt       { cursor: help; border-bottom: 1px dashed #ccc;} 
+.quicktip-prompt2      { cursor: help; } 
+
+.quickedit                     { text-align: left; position: absolute; top: 0; left: 0; width: 550px; visibility: hidden; z-index: 100;
+                                               font-family: verdana, arial, helvetica, sans-serif; font-size: 12px; border: 1px solid #000; }
+.quickedit-prompt      { cursor: help; }
+.quickedit-titlebar { background-color: #87CEFA;       }
+.quickedit-title       { font-weight: bold; color: black; padding: 3px;        }
+.quickedit-close       { font-weight: bold; color: white;  text-decoration: none;      float: right; position: relative; display: block; padding: 3px;}
+.quickedit-body        { background-color: #FDF5E6; color: black; padding: 8px; font-weight: normal;}
+.quickedit-fieldname { font-weight: bold; margin-bottom: 0.5em; border-bottom: 1px solid #333;}
+.quickedit-prompt      { cursor: help; border-bottom: 1px dashed #ccc;} 
+.quickedit-prompt2     { cursor: help; } 
+
+
+
+textarea:focus, input:focus, select:focus
+       {
+               background-color: #FFFFEE;
+       }
+
+
+#tdleft {background-color: #88aed8;}
+
+/* GENERAL STYLES */
+body {         background-color: #fff;         padding: 0;     margin: 0; }
+/*font*/
+body, td, table {
+       font-family: Arial, Helvetica, sans-serif; 
+       color: #213884;
+       font-size: 12px;
+       }
+div.toplogos
+{
+       width: 755px;
+       height:  50px;
+       background-color: #fff;
+       margin: 0;
+       padding: 0;
+       }
+
+div.top
+{
+       background-color: #4e73a9;
+       width:100%;
+       height: 32px;
+}
+
+div.mid
+{
+       background-color: #becfe4;
+       width: 100%;
+       height: 130px;
+}
+
+div.mid img {margin: 0 0 0 17px;}
+div.intrologos { margin: 25px 0 0 25px; }
+div.contentintro               { margin: 0 10px 0 61px; }
+/* div.contentintro    img     { float: right; margin: 0 0 0 10px; } */
+div.contentintro p     { margin: 0 0 7px 0; color: #000; }
+
+.pac_std_text{font-family: Arial, Helvetica, sans-serif; padding-left: .25cm}
+.pac_bold_text{font-family: Arial, Helvetica, sans-serif; font-weight: bold; padding-left: .25cm}
+.pac_stepdescr{font-family: Arial, Helvetica, sans-serif; font-weight: bold}
+.pac_redhead{color: #990000}
+A.pac_link { font-size: 16px; }
+A.pac_link:visited { font-size: 16px; }
+A.pac_link:active { font-size: 16px; }
+A.pac_link:hover { font-size: 16px; }
+
+.pac_standout { COLOR: #006bb7; font-size: 16px; }
+.pac_standout_small { COLOR: #006bb7; font-size: 12px; }
+
+
diff --git a/registrations/Views/index.html b/registrations/Views/index.html
new file mode 100755 (executable)
index 0000000..33e41fd
--- /dev/null
@@ -0,0 +1,5 @@
+<HTML>
+  <BODY>
+  
+  </BODY>
+</HTML>
\ No newline at end of file
diff --git a/registrations/functions.php b/registrations/functions.php
new file mode 100644 (file)
index 0000000..c63634f
--- /dev/null
@@ -0,0 +1,10265 @@
+<?php
+/************************************************************************
+$Id: functions.inc,v 1.7 2010/05/09 15:19:56 cscott Exp $
+       Gaslight Media Standard Function Library
+
+       Copyright (c) 2000-2004 by Gaslight Media Inc.
+
+       FILE:           functions.inc
+       VERSION:        1.3
+
+       ---------------------------------------------------------
+       SEE functions_docs.txt FOR INFORMATION ON THESE FUNCTIONS
+       ---------------------------------------------------------
+
+
+************************************************************************/
+
+/***********************************************************************
+*                                                                      *
+*                       DEBUG FUNCTIONS                                *
+*                                                                             *
+***********************************************************************/
+
+       // Display E-Mail if debug level > 0
+
+function debug_mail( $to, $subject, $message, $headers = '', $parameters = '' )
+       {
+
+       if( SI_DEBUG_MAIL )
+               {
+               echo '<p>
+                               <table border="1">
+                                       <tr><th align="center">MAIL DEBUG</th></tr>
+                                       <tr><td align="left"> Recipient(s): '.$to.'</td></tr>
+                                       <tr><td align="left"> Subject: '.$subject.'</td></tr>
+                                       <tr><td align="left"> Headers:<br><pre>'.$headers.'</pre></td></tr>
+                                       <tr><td align="left"> Parameters:<br><pre>'.$parameters.'</pre></td></tr>
+                                       <tr><td align="left"> <pre>'.$message.'</pre></td></tr>
+                               </table>
+                         <p>
+                       ';
+               return( true );
+               }
+         else
+               return( mail( $to, $subject, $message, $headers, $parameters ) );
+
+       }
+
+
+
+/***********************************************************************
+*                                                                      *
+*                       GENERAL FUNCTIONS                              *
+*                                                                             *
+***********************************************************************/
+
+       // Check for a valid credit card number doing Luhn check
+/*
+function CreditVal($Num, $Name = '')
+       {
+       $GoodCard = 1;
+    $Num = ereg_replace("[^[:digit:]]", "", $Num);
+    switch ($Name) {
+
+    case "mastercard" :
+      $GoodCard = ereg("^5[1-5].{14}$", $Num);
+    break;
+
+    case "visa" :
+      $GoodCard = ereg("^4.{15}$|^4.{12}$", $Num);
+    break;
+
+    case "americanexpress" :
+      $GoodCard = ereg("^3[47].{13}$", $Num);
+    break;
+
+    case "discover" :
+      $GoodCard = ereg("^6011.{12}$", $Num);
+    break;
+
+    case "dinnerscard" :
+      $GoodCard = ereg("^30[0-5].{11}$|^3[68].{12}$", $Num);
+    break;
+    }
+
+    $Num = strrev($Num);
+
+    $Total = 0;
+
+    for ($x=0; $x<strlen($Num); $x++)
+       {
+       $digit = substr($Num,$x,1);
+       if ($x/2 != floor($x/2))
+               {
+               $digit *= 2;
+               if (strlen($digit) == 2)
+                       $digit = substr($digit,0,1) + substr($digit,1,1);
+               }
+       $Total += $digit;
+               }
+    if( $GoodCard && $Total % 10 == 0 )
+               return( true );
+       else
+               return( false );
+}
+*/
+       // Alternative strong credit card check function.
+       // NOTE: The $si_cc_verify stuff SHOULD be passed rather than use a global to avoid issues with changes in the global values
+
+function credit_card_check( $Num, $accepted = SI_CC_ACCEPTS )
+{
+       global          $si_cc_verify;
+
+       $Num = ereg_replace("[^[:digit:]]", "", $Num);
+
+               // Check for Accepted Card List
+
+       if( !is_int($accepted) || $accepted == 0 )
+               {
+               echo "<P>ERROR: credit_card_check() requires SI_CC_ACCCEPTS parameter!<P>";
+               exit;
+               }
+
+               // Permit secret test code
+
+       if( $Num == "0011001100110011" )
+               return( "Test" );
+         else
+               {
+                       // Check each selected card type for a pattern match
+               $Name = "";
+               reset( $si_cc_verify );
+               $i = 0;
+               while( list($k, $v) = each($si_cc_verify) )
+                       if( ( $accepted & pow(2,$i++) ) && preg_match( "/$v/", $Num ) )
+                               {
+                               $Name = $k;
+                               break;
+                               }
+               }
+
+           // Fail if nothing matched
+
+       if( $Name == "" )
+           return( FALSE );
+
+               // Now do strong test
+
+       $Num = strrev($Num);
+
+       $Total = 0;
+
+       for ($x=0; $x<strlen($Num); $x++)
+           {
+           $digit = substr($Num,$x,1);
+           if ($x/2 != floor($x/2))
+                   {
+                   $digit *= 2;
+                   if (strlen($digit) == 2)
+                           $digit = substr($digit,0,1) + substr($digit,1,1);
+                   }
+           $Total += $digit;
+           }
+
+       if( $Total % 10 == 0 )
+               return( $Name );
+         else
+               return( FALSE );
+
+}
+
+/***********************************************************************
+*                                                                      *
+*                     GEOGRAPHIC FUNCTIONS                             *
+*                                                                             *
+***********************************************************************/
+
+
+       // Calculate the distance between a pair of lat/lon coordinates.
+
+function geo_distance( $lat1, $lon1, $lat2, $lon2, $units = 'Miles' )
+{
+
+       $d = 3963.0 * acos( sin($lat1/57.2958) * sin($lat2/57.2958) + cos($lat1/57.2958) * cos($lat2/57.2958) *  cos($lon2/57.2958 -$lon1/57.2958) );
+
+       switch( $units )
+               {
+
+                       // Add units conversions here
+
+               case "Inches":
+                       $d = $d * 5280 * 12;
+                       break;
+
+               case "Feet":
+                       $d = $d * 5280;
+                       break;
+
+               case "Yards":
+                       $d = $d * ( 5280 / 3 );
+                       break;
+
+               case "Miles":
+               default:
+                               // This is the default calculated above
+                       break;
+
+               case "Nautical Miles":
+                       $d = $d / 1.15078;
+                       break;
+
+               case "Meters":
+                       $d = $d * 1609.344;
+                       break;
+
+               case "Kilometers":
+                       $d = $d * 1.609344;
+                       break;
+
+               }
+
+       return( $d );
+}
+
+/***********************************************************************
+*                                                                      *
+*                DATABASE ABSTRACTION FUNCTIONS                        *
+*                                                                             *
+***********************************************************************/
+
+       // Create a connection to database specified $conn_str,
+/*
+function db_connect( $conn_str, $fail_mode )
+{
+
+       static $last_connect = '';
+       static $ret = 0;
+
+               // If we're using static connections, check to see if this is trying to open the same connection again
+
+       if( SI_DB_STATIC )
+               {
+
+                       // Check to see if this is trying to open the same connection again
+
+               if( $last_connect == $conn_str )
+                       {
+                               // If so just use the current connection
+
+                       if( SI_DEBUG >= 3 ) echo "<PRE>db_connect() - Using existing connection - \$conn_str = ".$conn_str."</PRE><BR>";
+                       return( $ret );
+                       }
+
+                       // If we need to open a different connection, close the current one first
+
+               if( $ret != 0 )
+                       db_close( $ret );
+
+               $last_connect = $conn_str;
+
+               }
+
+       if( SI_DEBUG >= 3 ) echo "<PRE>db_connect()[".__LINE__."]: \$conn_str = ".$conn_str."</PRE><BR>";
+
+       switch( SI_DB_TYPE )
+               {
+               case "postgres":
+                       $ret = pg_connect( $conn_str );
+                       break;
+               default:
+                       return( 0 );
+               }
+
+       if( !$ret && $fail_mode )
+               html_error( DB_ERROR_MSG, 1 );
+
+       return( $ret );
+
+}
+*/
+       // Close the connection to database specified by the handle dbd
+/*
+function db_close( $dbd )
+{
+
+               // IF we're using static connections, don't actually close it
+
+       if( SI_DB_STATIC == TRUE )
+               return( TRUE );
+
+       switch( SI_DB_TYPE )
+               {
+               case "postgres":
+                       $ret = pg_close( $dbd );
+                       break;
+               default:
+                       return( 0 );
+               }
+
+       return( $ret );
+}
+*/
+       // Create a persistant connection to database specified in $conn_str
+/*
+function db_pconnect( $conn_str )
+{
+
+       if( SI_DEBUG >= 3 ) echo "<PRE>db_cponnect()[".__LINE__."]: \$conn_str = ".$conn_str."</PRE><BR>";
+
+       switch( SI_DB_TYPE )
+               {
+               case "postgres":
+                       $ret = pg_pconnect( SI_CONN_STR );
+                       break;
+               default:
+                       return( 0 );
+               }
+
+       return( $ret );
+}
+*/
+
+       // Execute an SQL query
+/*
+function db_exec( $dbd, $qs )
+{
+
+       if( SI_DEBUG >= 3 ) echo "<PRE>db_exec()[".__LINE__."]: \$qs = ".$qs."</PRE><BR>";
+
+       switch( SI_DB_TYPE )
+               {
+               case "postgres":
+                       $ret = pg_exec( $dbd, $qs );
+                       break;
+
+               default:
+                       return( 0 );
+               }
+
+       return( $ret );
+}
+*/
+       // Get data and store in associative indices, using the field names as keys.
+/*
+function db_fetch_row( $res, $i )
+{
+
+       if( SI_DEBUG >= 3 ) echo "<PRE>db_fetch()[".__LINE__."]: Row = ".$i."</PRE><BR>";
+
+       if( db_numrows($res) == 0 )
+               return( FALSE );
+
+       switch( SI_DB_TYPE )
+               {
+               case "postgres":
+                       $row = pg_fetch_array( $res, $i, PGSQL_ASSOC );
+                       break;
+
+               default:
+                       return( FALSE );
+               }
+
+       return( $row );
+
+}
+*/
+       // Free result memory.
+/*
+function db_freeresult( $res )
+{
+
+       switch( SI_DB_TYPE )
+               {
+               case "postgres":
+                       $ret = pg_freeresult( $res );
+                       break;
+
+               default:
+                       return( 0 );
+               }
+
+       return( $ret );
+}
+*/
+       // Determine number of rows in a result index
+/*
+function db_numrows( $res )
+{
+
+       switch( SI_DB_TYPE )
+               {
+               case "postgres":
+                       $ret = pg_numrows( $res );
+                       break;
+
+               default:
+                       return( -1 );
+               }
+
+       return( $ret );
+}
+*/
+/***********************************************************************
+ *
+ * BEGIN Auto functions
+ *
+ ***********************************************************************/
+
+       // Retrieve a result as an array based soley on a query
+
+function db_auto_get_row( $qs, $i = 0, $conn_str = SI_CONN_STR, $fail_mode = 'FALSE' )
+{
+
+       if( SI_DEBUG >= 2 ) echo "<PRE>db_auto_get_row()[".__LINE__."]: \$qs = $qs, Row = $i</PRE><BR>";
+
+       if( !($dbd = db_connect( $conn_str, $fail_mode )) )
+               return( FALSE );
+
+       if( ($res = db_exec($dbd, SI_DB_SET_DATE_STYLE_STRING.$qs)) )
+               {
+               $row = db_fetch_row( $res, $i );
+               db_freeresult( $res );
+               }
+
+       db_close( $dbd );
+       return( $row );
+}
+
+
+       // Retrieve a set of results based soley on a query
+/*
+function db_auto_get_data( $qs, $conn_str = SI_CONN_STR, $fail_mode = FALSE, $rows = 500, $start = 0 )
+{
+
+       if( SI_DEBUG >= 2 ) echo "<PRE>db_auto_get_data()[".__LINE__."]: \$qs = $qs, \$rows = $rows, \$start = $start</PRE><BR>";
+
+       if( !($dbd = db_connect( $conn_str, $fail_mode)) )
+               return( FALSE );
+
+       if( ($res = db_exec($dbd, SI_DB_SET_DATE_STYLE_STRING.$qs)) )
+               {
+               $totalrows = pg_NumRows( $res );
+               $stop = $start + $rows;
+               if( $stop > $totalrows )
+                       $stop = $totalrows;
+
+               for( $i=$start ; $i<$stop ; $i++ )
+                       {
+                       $data["$i|$totalrows"] = db_fetch_row( $res, $i );
+                       }
+               }
+       db_close( $dbd );
+
+       return( $data );
+}
+*/
+       // Execute a query.
+/*
+function db_auto_exec( $qs, $conn_str = SI_CONN_STR, $fail_mode = 'FALSE' )
+{
+
+       if( SI_DEBUG >= 2 ) echo "<PRE>db_auto_exec()[".__LINE__."]: \$qs = $qs, \$conn_str = $conn_str</PRE><BR>";
+
+       $dbd = db_connect( $conn_str, $fail_mode );
+       if( !$dbd )
+               return( 0 );
+
+       if( !( $result = db_exec($dbd, $qs)) )
+               {
+               db_close( $dbd );
+               return( 0 );
+               }
+         else
+               {
+               $oid = pg_getlastoid( $result );
+               db_close( $dbd );
+               if( empty($oid) || $oid == -1 )
+                       return( 1 );
+                 else
+                       return( $oid );
+               }
+}
+*/
+       // Get information on database fields
+
+function db_data_fields( $conn_str, $table )
+{
+       $dbd = db_connect( $conn_str, FALSE );
+       if( !$dbd )
+               return( 0 );
+
+       $qs = "SELECT * FROM $table LIMIT 1;";
+    $res = db_exec( $dbd, $qs );
+       for( $i=0 ; $i<pg_numfields($res) ; $i++ )
+               {
+               $n                                      = pg_fieldname( $res, $i );
+               $f[$n]['size']          = pg_fieldsize( $res, $i );
+               $f[$n]['type']          = pg_fieldtype( $res, $i );
+        }
+
+        return $f;
+}
+
+
+/***********************************************************************
+*                                                                      *
+*                          FILE FUNCTIONS                              *
+*                                                                             *
+***********************************************************************/
+
+       // Store away an uploaded file
+/*
+function file_upload( $form_field, $file_name, $base_path = SI_BASE_FILE_PATH )
+{
+
+       if( SI_DEBUG > 0 )
+               echo "file_upload(): temp file = $form_field, file name = $file_name";
+
+               // Get rid of screwy characters in file names
+
+       if( ereg( '[!@#$%^&()+={};: ]', $file_name ) )
+               $file_name = ereg_replace( "[!@#$%^&()+={};: ]", "x", $file_name );
+
+               // Check if destination path is valid
+
+       if( !is_dir( $base_path ) )
+               die( $base_path." not a directory" );
+
+               // Check if file name is in use
+
+       $new_file_name = $file_name;
+       if( file_exists( $base_path."/".$file_name ) )  // If so
+               $new_file_name = mktime()."_".$file_name;               // Prefix with timestamp
+
+               // Save file to destination directory
+
+       $new_file_location = $base_path."/".$new_file_name;
+
+       if( SI_DEBUG > 0 )
+               echo ", new file name = $new_file_location<br>";
+
+       copy( $form_field, $new_file_location );
+       chmod( $new_file_location, 0664 );
+
+               // Return where it was stored
+
+       return( $new_file_name );
+}
+*/
+       // Duplicate a file
+
+function file_duplicate( $file_name, $base_path = SI_BASE_FILE_PATH )
+{
+
+       if( empty($file_name) )
+               return( "" );
+
+               // Check to see if specified file exists
+
+       if( !is_file($base_path."/".$file_name) )
+               return( "" );
+
+               // Create new file name
+
+       for( $i=1 ; $i<1000 ; $i++ )
+               {
+               if( !is_file($base_path."/"."c".$i."_".$file_name) )
+                       break;
+               }
+
+       if( $i == 1000 )
+               return( "" );
+
+       $new_file_name = "c".$i."_".$file_name;
+
+       copy( $base_path."/".$file_name, $base_path."/".$new_file_name );
+
+       return( $new_file_name );
+}
+
+
+
+       // Delete a stored File
+
+function file_delete( $file_name, $base_path = SI_BASE_FILE_PATH )
+{
+
+       if( !is_writable ( $base_path."/".$file_name ) )
+               return( FALSE );
+
+       if( !is_file($base_path."/".$file_name) || !unlink($base_path."/".$file_name)  )
+               return( FALSE );
+
+       return( TRUE );
+}
+
+
+       // Read the specified file and return the results
+
+function file_get( $file_name, $max_size = 0, $base_path = SI_BASE_PATH )
+{
+
+       if( !is_readable ( $base_path."/".$file_name ) )
+               return( FALSE );
+
+       $f = fopen( $base_path."/".$file_name, "r" );
+       $s = filesize($base_path."/".$file_name);
+       if( $max_size == 0 || $s <= $max_size )
+               $file_contents = fread( $f, $s );
+         else
+               return( FALSE );
+
+       return( $file_contents );
+}
+
+
+
+/***********************************************************************
+*                                                                      *
+*                        GRAPHICS FUNCTIONS                            *
+*                                                                             *
+***********************************************************************/
+
+
+       // Graphics conversion programs
+
+define( "DJPEG",               "/usr/bin/djpeg ");
+define( "CJPEG",               "/usr/bin/cjpeg ");
+define( "PNMSCALE",    "/usr/bin/pnmscale ");
+define( "GIFTOPNM",    "/usr/bin/giftopnm ");
+define( "PPMTOGIF",    "/usr/bin/ppmtogif ");
+define( "PPMQUANT",    "/usr/bin/ppmquant ");
+
+
+       // Return information about an image
+
+function img_info( $path2image )
+{
+
+       $type = array
+               (
+               1 => 'GIF',
+               2 => 'JPG',
+               3 => 'PNG',
+               4 => 'SWF',
+               5 => 'PSD',
+               6 => 'BMP',
+               7 => 'TIFF(intel byte order)',
+               8 => 'TIFF(motorola byte order)',
+               9 => 'JPC',
+               10 => 'JP2',
+               11 => 'JPX',
+               12 => 'JB2',
+               13 => 'SWC',
+               14 => 'IFF',
+               15 => 'WBMP',
+               16 => 'XBM'
+               );
+
+       if( file_exists($path2image) )
+               {
+               $i = GetImageSize(  $path2image );
+               $r['width'] = $i[0];
+               $r['height'] = $i[1];
+               $r['type_num'] = $i[2];
+               $r['type'] = $type[$i[2]];
+               $r['size'] = $i[3];
+               $r['bits'] = $i[4];
+               $r['channels'] = $i[5];
+
+               return( $r );
+               }
+         else
+               return( FALSE );
+}
+
+
+       // Create a thumbnail image based on a full scale jpeg or gif
+
+function graphic_thumb($img, $timg, $type)
+{
+       switch( $type )
+               {
+               case "image/gif":
+                       $cmd = GIFTOPNM." $img | ".PNMSCALE." -height ".SI_THEIGHT." | ".PPMQUANT." 256 | ".PPMTOGIF." -interlace > $timg";
+                       break;
+
+               case "image/jpeg":
+                       $cmd = DJPEG." $img | ".PNMSCALE." -height ".SI_THEIGHT." | ".CJPEG." -outfile $timg";
+                       break;
+
+               default:
+                       echo "<h1>Graphic type not defined: type $type</h1>\n";
+
+                               /* we can only do gifs and jpegs at this point.
+                                * png would be a nice addition
+                                */
+
+                       return( 0 );
+               }
+       exec( $cmd );
+       return( 1 );
+}
+
+
+       // Creates a resized image based on a full scale jpeg or gif
+
+function graphic_resize( $img, $timg, $type, $w, $h )
+{
+       switch ( $type )
+               {
+               case "image/gif":
+                       $cmd = GIFTOPNM." $img | ";
+
+                       if( $w && $h )
+                               $cmd .= PNMSCALE." -width $w -height $h |";
+                         elseif( $h )
+                               $cmd .= PNMSCALE." -height $h |";
+                         elseif( $w )
+                               $cmd .= PNMSCALE." -width $w |";
+                       $cmd .= PPMQUANT." 256 | ".PPMTOGIF." -interlace > $timg";
+                       break;
+
+               case "image/jpeg":
+                       $cmd = DJPEG." $img | ";
+                       if( $w && $h )
+                               $cmd .= PNMSCALE." -width $w -height $h |";
+                         elseif( $h )
+                               $cmd .= PNMSCALE." -height $h |";
+                         elseif( $w )
+                               $cmd .= PNMSCALE." -width $w |";
+                       $cmd .= CJPEG." -outfile $timg";
+
+                       break;
+
+               case "image/pjpeg":
+                       $cmd = DJPEG." $img | ";
+
+                       if( $w && $h )
+                               $cmd .= PNMSCALE." -width $w -height $h |";
+                         elseif( $h )
+                               $cmd .= PNMSCALE." -height $h |";
+                         elseif( $w )
+                               $cmd .= PNMSCALE." -width $w |";
+                       $cmd .= CJPEG." -outfile $timg";
+
+                       break;
+
+               default:
+                       echo "<h1>Graphic type not defined: type $type</h1>\n";
+                       /* we can only do gifs and jpegs at this point.
+                        * png would be a nice addition
+                        */
+                       return( 0 );
+               }
+       exec( $cmd );
+       return( 1 );
+}
+
+       // Resize an image based on a full scale jpeg or gif
+/*
+function img_resize( $path2image, $path2thumb, $axis, $size )
+{
+       $imageName = basename( $path2image );
+       $thumbName = basename( $path2thumb );
+
+       if( TRUE )              // Not testing submitted file type at this time
+               {
+               $imageAttributes = GetImageSize( $path2image );
+               $imageWidth = $imageAttributes[0];
+               $imageHeight = $imageAttributes[1];
+               if( $imageWidth < $size && $imageHeight < $size )
+                       {
+                       exec( "cp $path2image $path2thumb" );
+                       chmod( $path2thumb, 0664 );
+                       }
+             else
+               {
+                       if( ($axis == "h" || $axis == "a") && ($imageHeight > $imageWidth) )
+                               {
+                       exec( SI_PATH_TO_GRAPHICS_TOOLS."/convert -geometry $size $path2image $path2thumb" );
+                       }
+                       if( ($axis == "w" || $axis == "a") && ($imageWidth >= $imageHeight) )
+                               {
+                               exec( SI_PATH_TO_GRAPHICS_TOOLS."/convert -geometry $size $path2image $path2thumb" );
+                       }
+                       }
+
+               $img_resize_array = array( "$imageName", "$path2image", "$thumbName", "$path2thumb" );
+               return( $img_resize_array );
+               }
+         else
+               {
+       echo '<FONT SIZE=4>'
+               .'Unable to complete Resize Function, The file being processed is not an acceptable image file. Please use only .GIF or .JPG files'
+               .'<BR CLEAR=ALL>'
+               .'</FONT>'
+               ."Hit your browser's back button to continue"
+               .'<P>';
+       $error[0] = "ERROR";
+               return( $error );
+               }
+}
+*/
+       // Upload an image
+/*
+function img_upload( $form_field,$img_name,$destination_path )
+{
+       if (ereg('[!@#$%^&()+={};:\'\\ ]', $img_name))
+               {
+               $img_name = ereg_replace("[!@#$%^&()+={};:'\\ ]", "x", $img_name);
+               $dumb = "dumber";
+               }
+
+       if( TRUE )                      // Huh? - Oh, need to check for legal image type at some point
+               {
+               $i = "0";
+
+                       // Check for valid destination path
+
+               if( !is_dir($destination_path) )
+                       die( $destination_path." not a directory" );            // This is totally fatal
+
+                       // Get entries in that directory and check if the supplied name is in use
+
+               $d = dir( $destination_path );
+               $img_name_in_use = "FALSE";
+               while ($entry = $d->read())
+                       {
+                       if ($entry == $img_name)
+                               {
+                               $img_name_in_use = "TRUE";
+                               }
+                       ++ $i;
+                       }
+
+               $d->close();
+
+                       // If the name is in use, give it a name that can't match anything
+
+               if( $img_name_in_use == "TRUE" )
+                       {
+                       $new_img_name = mktime().$img_name;
+                       $new_img_location = $destination_path.'/'.$new_img_name;
+
+                               // And store the image in the destination
+
+                       copy( $form_field, $new_img_location );
+                       chmod( $new_img_location, 0664 );
+                       $img_upload_array = array( "$new_img_name", "$new_img_location" );
+                       }
+                 else
+                       {
+                               // Otherwise, supplied name is fine
+
+                       $new_img_name = $img_name;
+                       $new_img_location = $destination_path.'/'.$new_img_name;
+
+                       copy( $form_field, $new_img_location );
+                       chmod( $new_img_location, 0664 );
+                       $img_upload_array = array( "$new_img_name", "$new_img_location" );
+                       }
+               }
+         else  // Can't get here right now
+               {
+               echo '<FONT SIZE=4>'.'The file you uploaded was of an incorrect type, please only upload .GIF or .JPG files'.'<BR CLEAR=ALL>'.'</FONT>'."Hit your browser's back button to continue".'<P>';
+               $error[0] = "ERROR";
+               return ($error);
+               }
+
+       return( $img_upload_array );
+}
+*/
+       // Main image processing function
+/*
+function process_image( $image, $image_name, $resized_size = SI_RESIZED_SIZE,
+                                                       $midsized_size = SI_MIDSIZED_SIZE, $thumb_size = SI_THUMB_SIZE )
+{
+
+       if( !defined("SI_IMG_ORIGINAL_PATH") )
+               html_error( "this not defined original_path", 1 );
+       if( !defined("SI_IMG_RESIZED_PATH") )
+               html_error( "this not defined resized_path", 1 );
+       if( !defined("SI_IMG_MIDSIZED_PATH") )
+               html_error( "this not defined midsized_path",1 );
+       if( !defined("SI_IMG_THUMB_PATH") )
+               html_error( "this not defined thumb_path",1 );
+
+       if( !($image_upload_array = img_upload($image, $image_name, SI_IMG_ORIGINAL_PATH)) )
+               html_error( "image could not be uploaded", 1 );
+
+               // Resize image using progressively smaller images as the source to minimize work
+
+       img_resize( $image_upload_array[1], SI_IMG_RESIZED_PATH."/".$image_upload_array[0], 'a', SI_RESIZED_SIZE );
+       img_resize( SI_IMG_RESIZED_PATH."/".$image_upload_array[0], SI_IMG_MIDSIZED_PATH."/".$image_upload_array[0], 'a', SI_MIDSIZED_SIZE );
+       img_resize( SI_IMG_MIDSIZED_PATH."/".$image_upload_array[0], SI_IMG_THUMB_PATH."/".$image_upload_array[0], 'a', SI_THUMB_SIZE );
+       $image_name = $image_upload_array[0];
+
+       return( $image_name );
+}
+*/
+       // Delete an image
+
+function delete_image( $image_name )
+{
+       $ok = TRUE;
+       if( !is_file(SI_IMG_ORIGINAL_PATH."/".$image_name)      || !unlink(SI_IMG_ORIGINAL_PATH."/".$image_name)  )
+               $ok = FALSE;
+       if( !is_file(SI_IMG_RESIZED_PATH."/".$image_name) || !unlink(SI_IMG_RESIZED_PATH."/".$image_name) )
+               $ok = FALSE;
+       if( !is_file(SI_IMG_MIDSIZED_PATH."/".$image_name) || !unlink(SI_IMG_MIDSIZED_PATH."/".$image_name)     )
+               $ok = FALSE;
+       if( !is_file(SI_IMG_THUMB_PATH."/".$image_name) || !unlink(SI_IMG_THUMB_PATH."/".$image_name) )
+               $ok = FALSE;
+
+       return( $ok );
+}
+
+       // Duplicate an image
+
+function duplicate_image( $image_name )
+{
+
+       if( empty($image_name) )
+               return( "" );
+
+               // Check to see if specified image exists
+
+       if( !is_file(SI_IMG_ORIGINAL_PATH."/".$image_name)      )
+               return( "" );
+
+               // Create new file name using "copy_" and timestamp
+
+       for( $i=1 ; $i<100 ; $i++ )
+               {
+               if( !is_file(SI_IMG_ORIGINAL_PATH."/"."p".$i."_".$image_name) )
+                       break;
+               }
+
+       if( $i == 100 )
+               return( "" );
+
+       $new_image_name = "p".$i."_".$image_name;
+
+       copy( SI_IMG_ORIGINAL_PATH."/".$image_name,     SI_IMG_ORIGINAL_PATH."/".$new_image_name );
+       copy( SI_IMG_RESIZED_PATH."/".$image_name,      SI_IMG_RESIZED_PATH."/".$new_image_name );
+       copy( SI_IMG_MIDSIZED_PATH."/".$image_name,     SI_IMG_MIDSIZED_PATH."/".$new_image_name );
+       copy( SI_IMG_THUMB_PATH."/".$image_name,                SI_IMG_THUMB_PATH."/".$new_image_name );
+
+       return( $new_image_name );
+}
+
+
+/***********************************************************************
+*                                                                      *
+*               GENERAL SUPPORT FUNCTIONS / CLASSES                    *
+*                                                                             *
+***********************************************************************/
+
+class timestampfunc
+{
+
+    function newdate( $timestamp )
+       {
+        $z = date( "m:Y", $timestamp );
+        $z = split( ":", $z );
+        return $z;
+       }
+
+    function first_of_month( $timestamp )
+       {
+        $z = $this->newdate( $timestamp );
+        $first_of_month = $z[0]."/1/".$z[1];
+        return strtotime( $first_of_month );
+               }
+
+    function first_last_month( $timestamp )
+       {
+        $z = $this->newdate( $timestamp );
+               $z[0]--;
+        if( $z[0] <= 0 )
+                       {
+            $z[0] = 12;
+            $z[1]--;
+               }
+        $first_of_month = ($z[0])."/1/".$z[1];
+        return strtotime( $first_of_month );
+       }
+
+    function first_next_month( $timestamp )
+       {
+        $z = $this->newdate( $timestamp );
+               $z[0]++;
+        if( $z[0] > 12 )
+                       {
+               $z[0] = 1;
+               $z[1]++;
+               }
+        $first_of_month = ($z[0])."/1/".$z[1];
+        return strtotime( $first_of_month );
+       }
+
+    function first_of_Xmonth( $timestamp, $x )
+       {
+        $z = $this->newdate( $timestamp );
+        $r = mktime( 0,0,0, ($z[0]+$x), 1, $z[1] );
+        return $r;
+       }
+
+}
+
+
+       // Return Positive values only, otherwise 0
+
+function pos_value( $value )
+{
+
+       if( $value > 0 )
+               return( $value );
+       return( 0 );
+}
+
+
+       // Format a number as US Dollars
+
+function money( $value, $option = "" )
+{
+
+       if( $option == "NOPREFIX" )
+               $prefix = "";
+         else
+               $prefix = "$";
+
+               // Do value sanity check
+
+       if( !is_numeric( $value ) )
+               return( $prefix."0.00" );
+
+       return( $prefix.number_format($value, 2, ".", "," ) );
+}
+
+
+       // Convert "key^value~key^value" string to an array
+
+function strtoarray( $s )
+{
+
+       $a = array();
+
+               // Create array of entries - If there's less than 2 entries, fail
+
+       if( count($ea = explode( '~', $s )) < 2 )
+               return( FALSE );
+
+       foreach( $ea as $e )
+               {
+                       // Each entry must have exactly 2 parts
+
+               if( count($d = explode( "^", $e )) != 2 )
+                       return( FALSE );
+
+               $a[trim($d[0])] = trim($d[1]);
+               }
+
+       return( $a );
+}
+
+
+       // Convert array to a "key^value~key^value" string
+
+function arraytostr( $a )
+{
+
+       $s = '';
+
+               // Supplied value must be array of 2 or more entries
+
+       if( !is_array($a) || count($a) < 2 )
+               return( FALSE );
+
+       $sep = "";
+
+       while( list($k,$v) = each($a) )
+               {
+               $s .= $sep."$k^$v";
+               $sep = '~';
+               }
+
+       return( $s );
+}
+
+
+       // Replace {tokens}
+
+function replace_tokens( $s, $tokens )
+{
+
+       if( !is_array($tokens) )
+               {
+               echo '<P>ERROR: replace_tokens() - Parameter 2 ($tokens) is not an array<P>';
+               exit;
+               }
+
+       while( list($k,$v) = each($tokens) )
+               {
+               $s = str_replace( "{".$k."}", $v, $s );                 // Non ereg version - faster, case must match
+//             $s = eregi_replace( "\\{".$k."\\}", $v, $s );   // Ereg version
+               }
+
+       return( $s );
+
+}
+
+
+       // Conditionally replace tokens
+
+function cond_replace_tokens( $s, $tokens, $x="cond" )
+{
+
+       if( !is_array($tokens) )
+               {
+               echo '<P>ERROR: cond_replace_tokens() - Parameter 2 ($tokens) is not an array<P>';
+               exit;
+               }
+
+       while( list($k,$v) = each($tokens) )
+               {
+               $p0 = 0;        // Reset starting pointer position
+
+               while( ($start = strpos( $s, "<!--{if:".$k, $p0 )) !== false )
+                       {
+
+                       if( strcspn( substr($s,$start+8+strlen($k)), "=!><}" ) == 0 )    // Check to make sure it's not a substring of another token
+                               {
+
+                               if( !($if_end = strpos( $s, "}-->", $start )) )                                                 // Find end of {if:} tag
+                                       return( "ERROR: cond_replace_tokens() - Can't find end of {if:} tag at $start.<P><PRE>\n\n".htmlentities(substr($s,$start,500))."</PRE>" );
+
+                               $p = $start + 8 + strlen($k);                                                                                   // Set position where "=" should be if it's used
+                               $cond = substr($s,$p,1);
+                               switch( $cond )
+                                       {
+                                       case "=":
+                                       case "!":
+                                       case ">":
+                                       case "<":
+                                               $if_val_test = TRUE;                                                                                    // If valid comparison character?
+                                               $if_val = substr( $s, $p+1, $if_end-$p-1 );
+                                               break;
+                                       default:
+                                               $if_val_test = FALSE;
+                                               break;
+                                       }
+
+                                       // Separate out strings for both yes and no conditions
+
+                               $yes_start = $if_end + 4;                                                                                               // Point past tag
+                               $ci = "";                                                                                                                               // Closed {/if} take intro only if there's no {else}
+                               $else_if = strpos( $s, "<!--{else:$k}", $yes_start );
+                               $slash_if = strpos( $s, "<!--{/if:$k}-->", $yes_start );
+                               if( $else_if && ( !$slash_if || ($else_if < $slash_if) )  )                             // If there's an {else}
+                                       {
+                                       $yes_string = substr( $s, $yes_start, $else_if-$yes_start );
+                                       $no_start = $else_if + 11 + strlen($k);                                                                                         // Point past tag
+                                       if( !($no_end = strpos( $s, "{/if:$k}-->", $no_start )) )                                       // If there's no --> end of cond tag
+                                               return( "ERROR: cond_replace_tokens() - Matching {/if:} tag not found after {else:} at $start for \"$k\".<P><PRE>\n\n".htmlentities(substr($s,$start,500))."</PRE>" );
+
+                                       $end = $no_end + 9 + strlen($k);
+
+                                       $no_string = substr( $s, $no_start, $no_end-$no_start );
+                                       }
+                                 else
+                                       {
+                                       $no_string = "";
+                                       if( !($slash_if = strpos( $s, "<!--{/if:$k}-->", $yes_start )) )                                        // If there's no end of cond tag
+                                               return( "ERROR: cond_replace_tokens() - Matching {/if} tag not found at $start for \"$k\".<P><PRE>\n\n".htmlentities(substr($s,$start,500))."</PRE>" );
+                                       $end = $slash_if + 13 + strlen($k);
+                                       $yes_string = substr( $s, $yes_start, $slash_if-$yes_start );
+                                       }
+
+                               if( $if_val_test != FALSE )                                                                                             // If there's a compare value, test with that
+                                       switch( $cond )
+                                               {
+                                               case "=":
+                                                       $t = ( trim($v) == trim($if_val) );
+                                                       break;
+                                               case "!":
+                                                       $t = ( trim($v) != trim($if_val) );
+                                                       break;
+                                               case ">":
+                                                       $t = ( trim($v) > trim($if_val) );
+                                                       break;
+                                               case "<":
+                                                       $t = ( trim($v) < trim($if_val) );
+                                                       break;
+                                               default:
+                                                       return( "ERROR: cond_replace_tokens() - Internal unknown conditional operator error ($cond)- Code Bad, fix code!" );
+                                               }
+                                 else                                                                                                                                  // otherwise just use token value
+                                       $t = ( trim($v) != "" );                                                                                        //   if it's not empty use yes_string
+
+                               if( $t )                                                                                                                                // Replace with appropriate string
+                                       $s = substr_replace( $s, $yes_string, $start, $end-$start );
+                                 else
+                                       $s = substr_replace( $s, $no_string, $start, $end-$start );
+                               }
+                         else
+                               $p0 = $start + 1;
+                       }
+                       $p0 = $start;
+               }
+
+       return( $s );
+
+}
+
+       // Replace {file:xxx} token with a file
+
+function replace_file_tokens( $s )
+{
+
+       $p0 = 0;        // Reset starting pointer position
+
+       while( $p0 < strlen($s) && ($start = strpos( $s, "<!--{file:", $p0 )) )
+               {
+               if( !($file_end = strpos( $s, "}-->", $start )) )                                               // Find end of {file:} tag
+                       return( "ERROR: replace_file_tokens() - Can't find end of {file:} tag at $start.<P><PRE>\n\n".htmlentities(substr($s,$start,500))."</PRE>" );
+
+               $filename = substr( $s, $start+10, $file_end-$start-10 );                               // Get file name
+                       // Check for a matching <!--{/file}--> tag
+
+               if( ($slash_file = strpos( $s, "<!--{/file}-->", $file_end))                    // If there's a {/file} tag
+                       && !($next_file = strpos( $s, "<!--{file:", $file_end))                         // and there's not another {file:} tag
+                       || ( $next_file && $slash_file < $next_file ) )                                         // or it's beyond our {/file} tag
+                       {
+                       $file_end = $slash_file + 10;                                                           // Point to "}-->"
+                       }
+
+               $end = $file_end + 4;
+
+                       // Check if file name is valid
+
+               if( ($file_contents = file_get( $filename )) == FALSE )
+                       return( "ERROR: replace_file_tokens() - Can't load specified file '$filename' for {file:} tag.<P><PRE>\n\n".htmlentities(substr($s,$start,500))."</PRE>" );
+
+               $s = substr_replace( $s, $file_contents, $start, $end-$start );
+
+               $p0 = $end;
+               }
+
+       return( $s );
+
+}
+
+
+       // Convert an array of data to an HTML table
+
+function tableize_array($arr, $len=100 )
+{
+               // Verify that parameter is actually an array
+
+       if( !is_array($arr) )
+               {
+               $return = "Error: Variable not an array";
+               return $return;
+               }
+
+               // If everything's going fine so far, build out the table
+
+       $return = '<P><table width="100%" bordercolor="black" border="1">';
+
+       foreach( $arr as $key=>$val )
+               {
+               $return .= '<tr><td align="left" valign="top" width="10%" nowrap>'.$key.'</td> <td align="left" valign="top" width="90%">';
+               if( is_array($val) )
+                       $return .= tableize_array( $val );
+                 else
+                       {
+                       if( strlen($val) > $len )
+                               $x = substr( $val, 0, $len ).".......";
+                         else
+                               $x = $val;
+                       $return .= "<PRE>".htmlentities( $x )."</PRE>";
+                       }
+
+        $return .= "</td></tr>\n";
+        }
+
+       $return .= "</table>";
+
+       return  $return;
+}
+
+
+       // Select field data from an array based on which function it will be used for
+       // returning a string suitable for the admin_ functions
+
+function admin_field_select( $fields, $filter )
+{
+
+       $r = '';
+       $sep = '';
+
+       if( ! is_array($fields) || trim($filter) == '' )
+               {
+               echo "<P>ERROR: admin_field_select() - No Field or Filter data supplied!<P>";
+               return( FALSE );
+               }
+
+       foreach( $fields as $f )
+               {
+               $x = explode( ',', $f );
+               if( strstr( $x[5], $filter ) )
+                       {
+                       if( $filter == 'f' )    // List filters require slight difference in fields
+                               $r .= $sep.$x[0].','.$x[1].','.$x[2].','.$x[4];
+                         else
+                               $r .= $sep.$x[0].','.$x[1].','.$x[2].','.$x[3].','.$x[4];
+                       $sep = '|';
+                       }
+               }
+
+       return( $r );
+}
+
+       // Select field data from an array based on which function it will be used for
+       // returning an array of arrays of data.
+
+function admin_fields_select_array( $fields, $filter )
+{
+
+       $r = array();
+
+       if( ! is_array($fields) || trim($filter) == '' )
+               {
+               echo "<P>ERROR: admin_field_select_array() - No Field or Filter data supplied!<P>";
+               return( FALSE );
+               }
+
+       while( list($key, $val) = each($fields) )
+               {
+               $x = explode( ',', $val );
+               if( strstr( $x[5], $filter ) )
+                       {
+                       $r[$key]['name'] = trim($x[0]);
+                       $y = explode( '.', trim($x[1]) );
+                       foreach( $y as $z )
+                               $r[$key]['type'][] = trim($z);
+                       $r[$key]['title'] = trim($x[2]);
+                       $r[$key]['required'] = trim($x[3]);
+                       $r[$key]['variable'] = trim($x[4]);
+                       $r[$key]['sample'] = trim($x[6]);
+                       }
+               }
+
+       return( $r );
+}
+
+       // Generate standard admin low-level menu
+
+       // New version using standard HTML (<div>'s) for admin sections
+function admin_menu_std( $action, $a_title, $id, $opt, $options = 'lveda', $add_menu = '', $params = '' )
+{
+
+       $m = '';
+       $nl = "\n";
+
+//     if( $a_title != '' )
+//             $m .= '<span class="submenu_title">'.$a_title.':</span>';
+
+       $link = SI_THIS_SCRIPT.'?Action='.urlencode($action);
+       if( trim($params) != '' )
+               $link .= '&'.$params;
+
+       if( strstr($options,'l') )
+               {
+               if( $opt == "List" )
+                       $m .= '<li class="active">[List]</li>'.$nl;
+                 else
+                       $m .= '<li class="inactive" id="current"><a href="'.$link.'&Option=List">[List]</A></li>'.$nl;
+               }
+
+       if( strstr($options,'v') )
+               {
+               if( $opt == "View" )
+                       $m .= '<li class="active">[View]</li>'.$nl;
+                 elseif( empty($id) )
+                       $m .= '<li class="unavailable">[View]</li>'.$nl;
+                 else
+                       $m .= '<li class="inactive"><a href="'.$link.'&Option=View&id='.$id.'">[View]</a></li>'.$nl;
+               }
+
+       if( strstr($options,'e') )
+               {
+               if( $opt == "Edit" )
+                       $m .= '<li class="active">[Edit]</li>'.$nl;
+                 elseif( empty($id) )
+                       $m .= '<li class="unavailable">[Edit]</li>'.$nl;
+                 else
+                       $m .= '<li class="inactive"><a href="'.$link.'&Option=Edit&id='.$id.'">[Edit]</A></li>'.$nl;
+               }
+
+       if( strstr($options,'d') )
+               {
+               if( $opt == "Delete" )
+                       $m .= '<li class="active">[Delete]<</li>'.$nl;
+                 elseif( empty($id) )
+                       $m .= '<li class="unavailable">[Delete]</li>'.$nl;
+                 else
+                       $m .= '<li class="inactive"><a href="'.$link.'&Option=Delete&id='.$id.'">[Delete]</a></li>'.$nl;
+               }
+
+       if( strstr($options,'a') )
+               {
+               if( $opt == "Add" )
+                       $m .= '<li class="active">[Add]</li>'.$nl;
+                 else
+                       $m .= '<li class="inactive"><a href="'.$link.'&Option=Add">[Add]</A></li>'.$nl;
+               }
+
+       if( $add_menu != '' )
+               $m .= " - $add_menu".$nl;
+
+       return( $m );
+}
+       // Standard version
+function admin_menu( $action, $a_title, $id, $opt, $options = 'lveda', $add_menu = '', $params = '' )
+{
+
+       $m = '<SPAN CLASS="menu_title">'.$a_title.':</SPAN>&nbsp;</B>';
+
+       $link = SI_THIS_SCRIPT.'?Action='.urlencode($action);
+       if( trim($params) != '' )
+               $link .= '&'.$params;
+
+       if( strstr($options,'l') )
+               {
+               if( $opt == "List" )
+                       $m .= '<SPAN CLASS="menu_active">[List]</SPAN>&nbsp;';
+                 else
+                       $m .= '<A HREF="'.$link.'&Option=List">[List]</A>&nbsp;';
+               }
+
+       if( strstr($options,'v') )
+               {
+               if( $opt == "View" )
+                       $m .= '<SPAN CLASS="menu_active">[View]</SPAN>&nbsp;';
+                 elseif( empty($id) )
+                       $m .= '[View]&nbsp;';
+                 else
+                       $m .= '<A HREF="'.$link.'&Option=View&id='.$id.'">[View]</A>&nbsp;';
+               }
+
+       if( strstr($options,'e') )
+               {
+               if( $opt == "Edit" )
+                       $m .= '<SPAN CLASS="menu_active">[Edit]</SPAN>&nbsp;';
+                 elseif( empty($id) )
+                       $m .= '[Edit]&nbsp;';
+                 else
+                       $m .= '<A HREF="'.$link.'&Option=Edit&id='.$id.'">[Edit]</A>&nbsp;';
+               }
+
+       if( strstr($options,'d') )
+               {
+               if( $opt == "Delete" )
+                       $m .= '<SPAN CLASS="menu_active">[Delete]</SPAN>&nbsp;';
+                 elseif( empty($id) )
+                       $m .= '[Delete]&nbsp;';
+                 else
+                       $m .= '<A HREF="'.$link.'&Option=Delete&id='.$id.'">[Delete]</A>&nbsp;';
+               }
+
+       if( strstr($options,'a') )
+               {
+               if( $opt == "Add" )
+                       $m .= '<SPAN CLASS="menu_active">[Add]</SPAN>&nbsp;';
+                 else
+                       $m .= '<A HREF="'.$link.'&Option=Add">[Add]</A>&nbsp;';
+               }
+
+       if( $add_menu != '' )
+               $m .= " - $add_menu";
+
+       return( $m );
+}
+
+
+       // Clean up input parameters and test them for proper type of data
+
+function clean_input( $var_name, $type = 'text', $required = false )
+{
+
+       $reason  = '';                  // If problems, indicates reason here
+
+               // Trim whitespace, slashes, and stupid characters
+
+       $in = stripslashes( trim( $GLOBALS[$var_name] ) );
+
+       if( $in != '' )
+               {
+               switch( $type )
+                       {
+
+                       case 'int':
+                               if( !is_numeric($in) )
+                                       $reason = 'not an integer';
+                                 else
+                                       $in = intval( $in );
+                               break;
+
+                       case 'float':
+                               $in = preg_replace( "/^(\\$)?(.*)$/i", "\\2", $in );
+                               if( !is_numeric( $in ) )
+                                       $reason = 'not a valid number';
+                                 else
+                                       $in = (float) $in;
+                               break;
+
+                       case 'phone':
+                               if( preg_match( "/^((\([0-9]{3}\))[ ]*|([0-9]{3}) *-* *)?[0-9]{3} *-* *[0-9]{4} *.{0,10}$/i", $in ) == 0 )
+                                       $reason = 'not a valid phone number';
+                                 else  // Reformat as we want it
+                                       $in = preg_replace( "/^((\(([0-9]{3})\))[ ]*|(([0-9]{3}))[ -]*)?([0-9]{3}) *-* *([0-9]{4}) *(.{0,10})$/i", "\\3\\4-\\6-\\7 \\8", $in );
+                               break;
+
+                       case 'zip':
+                                       // Check if it's a US ZIP
+                               if( preg_match( "/^(([0-9]{5})([ -+]?([0-9]{4}))?)$/i", $in ) != 0 )
+                                       {
+                                       $in = preg_replace( "/^([0-9]{5})[ -+]?([0-9]{4})$/i", "\\1-\\2", $in );
+                                       if( strlen($in) < 8 )
+                                               {
+                                               $in = preg_replace( "/^([0-9]{5}).*/i", "\\1", $in );
+                                               }
+                                       }
+                                 elseif( preg_match( "/^[a-zA-Z]\d[a-zA-Z][ -]?\d[a-zA-Z]\d$/i", $in ) != 0 )
+                                       {
+                                       $in = preg_replace( "/^([a-zA-Z]\d[a-zA-Z])[ -]?(\d[a-zA-Z]\d)$/i", "\\1 \\2" ,$in );
+                                       }
+                                 else
+                                       $reason = 'not a valid ZIP or Postal Code';
+                               break;
+
+                       case 'state':
+                               global $si_states_array;
+                               if( !isset($si_states_array[$in]) )
+                                       $reason = 'not a valid state code';
+                               break;
+
+                       case 'country':
+                               global $si_countries_array;
+                               if( !isset($si_countries_array[$in]) )
+                                       $reason = 'not a valid country code';
+                               break;
+
+                       case 'email':
+                               if( preg_match( "/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$/i", $in ) == 0 )
+                                       $reason = 'not a valid E-Mail address';
+                               break;
+
+                       case 'creditcard':
+                               global $si_cc_verify;
+                               $match = FALSE;
+                               reset( $si_cc_verify );
+                               while( list($k, $v) = each($si_cc_verify) )
+                                       {
+                                       if( preg_match( "/".$v."/i", $in ) != 0 )
+                                               {
+                                               $match = TRUE;
+                                               break;
+                                               }
+                                       }
+                               if( !$match )
+                                       $reason = 'not a valid credit card number';
+                               break;
+
+                       case 'date':
+                               if( ($t = strtotime($in)) === -1 )
+                                       $reason = 'not a valid date';
+                                 else
+                                   $in = date( 'n/j/Y', $t );
+                               break;
+
+                       case 'text':
+                               break;
+
+                       case 'inet':
+                               if( preg_match( "/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i", $in ) == 0 )
+                                       $reason = 'not a valid IP address or netmask';
+                               break;
+
+                       default:
+                               break;
+
+                       }
+               }
+
+               // Check for a required field
+
+       if( $required && $in == '' )
+               $reason .= ($reason != '' ? ' and is ':'' ).'required';
+
+       $GLOBALS[$var_name] = $in;
+       return( $reason );
+
+}
+
+       // Convert data to search engine friendly URL
+
+function data_to_url( $prefix = '' )
+{
+
+       $url = $prefix;
+
+               // Make sure we have at least a prefix and one parameter
+
+       if( ($args = func_get_args()) == 0 || count($args) < 2 )
+               return( false );
+
+       for( $i=1 ; $i<count($args) ; $i++ )
+               $url .= '/'.urlencode(trim($args[$i]));
+
+       return( $url );
+}
+
+
+       // Convert Search Engine Friendly URL to Data
+
+function url_to_data( $url, $start_key )       // Expects additional parameters that define the name of each url parameter
+{
+
+               // Make sure we have valid data
+
+       $args = func_get_args();
+       if( count($args) < 3 )
+               return( false );
+
+       if( ($url=trim($url)) == '' )
+               return( false );
+
+               // If start_key is null, assume key is found and start with first parameter in URL
+
+       $key_found = ( ($start_key=trim($start_key)) == '' );
+
+               // Break out incoming URL and search for start key
+
+       $in = explode( '/', $url );
+       for( $u=0 ; $u<=count($in) ; )
+               if( ($key_found = ( $in[$u++] == $start_key )) )
+                       break;
+
+       if( !$key_found )
+               return( false );
+
+               // Stuff remaing data into return array
+
+       if( count($in) < $u )
+               return( false );
+
+       $data = array();
+       $data_found = false;
+       for( $i=2 ; $i<count($args) ; $i++, $u++ )
+               {
+                       // Check to see if there's any data supplied at all - It's hard to check otherwise
+               if( $in[$u] != '' )
+                       $data_found = true;
+               $data[$args[$i]] = urldecode($in[$u]);
+               }
+
+       if( $data_found )
+               return( $data );
+         else
+               return( false );
+
+}
+
+
+       // Returns Title text with QuickTip Pop-Up support
+
+function quick_tip( $title, $message )
+{
+
+       if( trim($title) == '' || trim($message) == '' )
+               return( false );
+
+       $t = strip_tags( $title );              // Get rid of any HTML tags in title
+
+       $key = md5($title);     // Used as the ID of this QuickTip
+
+       return( '<div id="QuickTip_'.$key.'" class="quicktip">
+                         <div class="quicktip-titlebar">
+                           <a href="javascript:hide_QuickTip(\'QuickTip_'.$key.'\')"><span class="quicktip-close">Close</span></a>
+                           <div class="quicktip-title">QuickTip</div>
+                         </div>
+                         <div class="quicktip-body">
+                           <div class="quicktip-fieldname">'.$t.'</div>
+                           '.$message.'
+                         </div>
+                       </div>
+                       <iframe id="Shim_QuickTip_'.$key.'" src="javascript:false;" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; display:none;"></iframe>
+                       <span onClick="show_QuickTip(\'QuickTip_'.$key.'\',event);" class="quicktip-prompt2">'.$title.'</span>' );
+
+}
+
+       // Returns Title text with QuickEdit Pop-Up support - Uses QuickTip Java functions
+
+function quick_edit( $key, $prompt, $form )
+{
+       if( trim($prompt) == '' || trim($form) == '' )
+               return( false );
+
+       $t = strip_tags( $prompt );             // Get rid of any HTML tags in title
+
+       return( '<div id="QuickEdit_'.$key.'" class="quickedit">
+                         <div class="quicktip-titlebar">
+                           <a href="javascript:hide_QuickTip(\'QuickEdit_'.$key.'\')"><span class="quickedit-close">Close</span></a>
+                           <div class="quickedit-title">QuickEdit</div>
+                         </div>
+                         <div class="quickedit-body">
+                           '.$form.'
+                         </div>
+                       </div>
+                       <iframe id="Shim_QuickEdit_'.$key.'" src="javascript:false;" scrolling="no" frameborder="0" style="position:absolute; top:0px; left:0px; display:none;"></iframe>
+                       <span onClick="show_QuickTip(\'QuickEdit_'.$key.'\',event);" class="quickedit-prompt2">'.$prompt.'</span>' );
+
+}
+
+
+/*=======================================================================
+
+                          CATEGORY SUPPORT FUNCTIONS
+
+=======================================================================*/
+
+       // Returns PL/pgSQL category_path support function for specified data table
+
+function category_path_func( $table_name )
+{
+
+               // Stick table name in function
+
+       return( str_replace ( '{TABLE_NAME}', $table_name, "
+
+               /*
+                       Function category_path( int )
+
+               Returns a ~ delimited string containing...
+                       A string to use for sorting by category, sub-cat, sub-sub-cat, ...
+                       A | delimited string of the names of the category hierarchy
+                       A | delimited string of the id of each step in the category hierarchy
+
+               Use in a query like...
+
+                       SELECT *, cateogory_path(id) FROM table_name;
+
+               */
+
+               CREATE OR REPLACE FUNCTION category_path( int ) RETURNS text AS '
+
+               DECLARE
+                       this_node ALIAS FOR $1;
+                       node RECORD;
+                       sort text := '''';
+                       path TEXT := '''';
+                       ids TEXT := '''';
+                       level INT := 0;
+                               children RECORD;
+                               child_count INT := 0;
+                       sort_fix int := 100000;         -- Added to sort numbers to make sure sort is pseudo-numeric
+
+               BEGIN
+                       SELECT INTO node * FROM {TABLE_NAME} WHERE id = this_node;
+                       sort := node.sort + sort_fix || ''_'' || this_node;                     -- Makes sure sort is numeric
+                       path := node.name;
+                       ids  := node.id;
+                               SELECT INTO children COUNT(id) FROM {TABLE_NAME} WHERE parent = this_node;
+                               child_count := children.count;
+                       IF FOUND THEN
+                               WHILE node.parent > 0 LOOP
+                                       SELECT INTO node * FROM {TABLE_NAME} WHERE id = node.parent;
+                                       sort := node.sort + sort_fix || ''_'' || node.id || ''_'' || sort;
+                                       path := node.name || ''|'' || path;
+                                       ids  := node.id || ''|'' || ids;
+                                       level := level + 1;
+                                       END LOOP;
+                               END IF;
+
+                       -- Note: 0 below is to enforce proper ordering by sort field
+                       RETURN sort || ''_0~'' || path || ''~'' || ids || ''~'' || level || ''~'' || child_count;
+
+               END;
+
+               ' LANGUAGE plpgsql;
+
+                       " ) );
+
+}
+
+       // Get category node
+
+function cat_get_node( $table, $qs = '' )
+{
+
+               // Get specified nodes list
+
+       $query = category_path_func( $table )
+                        ."SELECT *, category_path(id) AS cat_path_data FROM $table ".(trim($qs)!=''?" WHERE $qs":"").";";
+
+       if( !($r = db_auto_get_row( $query, 0, SI_CONN_STR, FALSE ) ) )
+               return FALSE;
+
+               // Process node paths into useable arrays
+
+       $p = explode( "~", $r['cat_path_data'] );
+       $r['cat_fullpath'] = $p[1];
+       $r['cat_names'] = explode( "|", $p[1] );
+       $r['cat_id_path'] = $p[2];
+       $r['cat_ids'] = explode( "|", $p[2] );
+       $r['cat_level'] = $p[3];
+
+       return( $r );
+
+}
+
+       // Get array of selected category nodes
+
+function cat_get_nodes( $table, $qs = '', $order = 'cat_path_data' )
+{
+
+               // Get specified nodes list
+
+       $query = category_path_func( $table )
+                        ."SELECT *, category_path(id) AS cat_path_data FROM $table ".($qs!=''?" WHERE $qs":"")." ORDER BY $order;";
+
+       if( !($r = db_auto_get_data( $query, SI_CONN_STR, FALSE) ) )
+               return( FALSE );
+
+               // Process node paths into useable arrays
+
+       $num = count( $r );
+
+       while( list($key, $val) = each($r) )
+               {
+               $p = explode( "~", $r[$key]['cat_path_data'] );
+               $r[$key]['cat_fullpath'] = $p[1];
+               $r[$key]['cat_names'] = explode( "|", $p[1] );
+               $r[$key]['cat_id_path'] = $p[2];
+               $r[$key]['cat_ids'] = explode( "|", $p[2] );
+               $r[$key]['cat_level'] = $p[3];
+               }
+
+
+       return( $r );
+
+}
+
+       // Get array of expanded node hierarchy for menus
+
+function cat_get_expanded_nodes( $table, $id )
+{
+
+               // Always get all top level nodes
+
+       $q = 'parent = 0';
+
+               // If target supplied, get siblings and siblings of all parents
+
+       $expanded = array();
+       if( $id > 0 )
+               {
+               $r = cat_get_node( $table, "id = $id" );
+
+                       // For each level up, add to query to get all siblings
+
+               if( $r )
+                       foreach( $r['cat_ids'] as $c )
+                               {
+                               $q .= " OR parent = $c";
+                               $expanded[$c] = TRUE;
+                               }
+               }
+
+               // Get all selected nodes
+
+       if( !($nodes = cat_get_nodes( $table, $q ) ) )
+               return( FALSE );                // If there's no top level nodes, then quit.
+
+               // Set expanded flags for nodes with expanded children
+
+       reset($nodes);
+       while( list($key, $val) = each($nodes) )
+               $nodes[$key]['expanded'] = $expanded[$val['id']] == TRUE;
+
+               // Make array keys the path data string to sort on
+
+       foreach( $nodes as $n )
+               $list[$n['cat_path_data']] = $n;
+
+               // Sort on those keys
+
+       ksort( $list );
+
+       return( $list );
+
+}
+
+       // Resequence category node siblings
+
+function cat_resequence_siblings( $table, $parent )
+{
+
+               // Get all siblings
+
+       if( !($nodes = db_auto_get_data( "SELECT id, sort FROM $table WHERE parent = $parent ORDER BY sort;", SI_CONN_STR, FALSE ) ) )
+               return( FALSE );
+
+       $query = 'BEGIN;';
+
+       $sort = 10;
+
+       foreach( $nodes as $n )
+               {
+               $query .= "UPDATE $table SET sort = $sort WHERE id = ".$n['id'].";";
+               $sort += 10;
+               }
+
+       $query .= 'COMMIT;';
+
+       if( !db_auto_exec( $query, SI_CONN_STR, FALSE ) )
+               return( FALSE );
+
+       return( TRUE );
+
+}
+
+       // Move a category node
+
+/*
+function cat_move_node( $table, $parent )
+{
+
+ NOT WRITTEN YET
+
+}
+*/
+
+
+/*=======================================================================
+
+                          HIGH LEVEL FUNCTIONS
+
+=======================================================================*/
+
+       // Build a numeric picklist
+
+function build_numeric_picklist( $fieldname, $starting, $ending, $selected="", $option="" )
+{
+       if( $starting > $ending )
+               return( "*** Picklist generation error: build_numeric_piclist() ***" );
+
+       $r = '<SELECT NAME="'.$fieldname.'">
+            ';
+
+       if( strstr( $option, 'blank') )
+               $r .= '<OPTION VALUE=""'.(trim($selected)==''?" SELECTED":"").'>';
+
+       for( $i=$starting ; $i<=$ending ; $i++ )
+               $r .= '<OPTION VALUE="'.$i.'"'
+                       .( $i==$selected ? " selected" : "" )
+                       .'> '.$i.'</OPTION>
+                     ';
+
+       $r .= '</SELECT>';
+
+       return( $r );
+
+}
+
+       // Build a picklist
+
+function build_a_picklist( $fieldname, $data, $selected, $type = "standard", $options = "" )
+{
+
+       if( !is_array($data) )
+               return( "<FONT COLOR=\"red\">ERROR: build_picklist() data supplied is not an array for field $fieldname.</FONT>\n" );
+
+               // Set default option status
+
+       $option_blank = $option_order = $option_numeric = $option_descending = $option_multi = FALSE;
+
+               // Scan for supplied options
+
+       if( !empty($options) )
+               {
+               $opt_array = explode_trim( "~", $options );
+               foreach( $opt_array as $opt )
+                       {
+                       switch( $opt )
+                               {
+                               case "blank":
+                                       $option_blank = TRUE;
+                                       break;
+
+                               case "numeric":
+                                       $option_numeric = TRUE;
+                                       $option_order = TRUE;
+                                       break;
+
+                               case "alpha":
+                                       $option_numeric = FALSE;        // If it's not numeric, it's alpha
+                                       $option_order = TRUE;
+                                       break;
+
+                               case "descending":
+                                       $option_descending = TRUE;
+                                       break;
+
+                               case "ascending":
+                                       $option_descending = FALSE;     // If it's not descending, it's ascending
+                                       break;
+
+                               case "multi":
+                                       $option_multi = TRUE;   // Permit multiple select with CTRL or SHIFT
+                                       break;
+
+                               default:
+                                       return( "<FONT COLOR=\"red\">Illegal build_picklist() option</FONT>\n" );
+                                       break;
+                               }
+                       }
+               }
+
+       if( $option_order )
+               {
+               if( $option_descending )
+                       {                       // Sort Descending
+                       if( $option_numeric )
+                               arsort( $data, SORT_NUMERIC );
+                           else
+                               arsort( $data, SORT_STRING );
+                       }
+                   else
+                       {                       // Sort Ascending
+                       if( $option_numeric )
+                               asort( $data, SORT_NUMERIC );
+                           else
+                               asort( $data, SORT_STRING );
+                       }
+               }
+
+       if( $option_multi )
+               $str = '<SELECT NAME="'.$fieldname.'[]" MULTIPLE SIZE="4">';
+         else
+               $str = '<SELECT NAME="'.$fieldname.'">';
+
+       if( $option_blank )
+               $str .= "       <OPTION VALUE=\"\">\n";
+
+       switch( $type )
+               {
+               case "simple":
+                       for( $i=0 ; $i<count($data) ; $i++ )
+                               {
+                               if( $option_multi )
+                                       {
+                                       $sel = FALSE;
+                                       if( is_array($selected) )
+                                               {
+                                               reset( $selected );
+                                               foreach( $selected as $s )
+                                                       if( $s == $data[$i] )
+                                                               $sel = TRUE;
+                                               }
+                                       $str .= "       <OPTION VALUE=\"".$data[$i]."\"".($sel?" SELECTED ":"").">".$data[$i]."\n";
+                                       }
+                                 else
+                                       $str .= "       <OPTION VALUE=\"".$data[$i]."\"".($data[$i]==$selected?" SELECTED ":"").">".$data[$i]."\n";
+                               }
+                       break;
+
+               case "standard":
+               default:
+                       while( list($key, $val) = each($data) )
+                               if( $option_multi )
+                                       {
+                                       $sel = FALSE;
+                                       if( is_array($selected) )
+                                               {
+                                               reset( $selected );
+                                               foreach( $selected as $s )
+                                                       if( $s == $key )
+                                                               $sel = TRUE;
+                                               }
+                                       $str .= "       <OPTION VALUE=\"$key\"".($sel?" SELECTED ":"").">$val\n";
+                                       }
+                                 else
+                                       $str .= "       <OPTION VALUE=\"$key\"".($key==$selected?" SELECTED ":"").">$val\n";
+                       break;
+               }
+       $str .= "</SELECT>";
+
+       return( $str );
+
+}
+
+       // Build Radio Buttons
+
+function build_radio_buttons( $fieldname, $data, $selected, $separator = "&nbsp;&nbsp;", $type = "standard", $options = "" )
+{
+
+               // if $data is neither proper array or data string
+
+       if( !is_array($data) )
+               if( ($data = strtoarray($data)) == FALSE )
+                       return( "<FONT COLOR=\"red\">ERROR: build_radio_buttons() Improper data supplied for field \"$fieldname\".</FONT>\n" );
+
+               // Set default option status
+
+       $option_blank = $option_order = $option_numeric = $option_descending = $option_after = FALSE;
+
+               // Scan for supplied options
+
+       if( !empty($options) )
+               {
+               $opt_array = explode_trim( "~", $options );
+               foreach( $opt_array as $opt )
+                       {
+                       switch( $opt )
+                               {
+                               case 'numeric':
+                                       $option_numeric = TRUE;
+                                       $option_order = TRUE;
+                                       break;
+
+                               case 'alpha':
+                                       $option_numeric = FALSE;        // If it's not numeric, it's alpha
+                                       $option_order = TRUE;
+                                       break;
+
+                               case 'descending':
+                                       $option_descending = TRUE;
+                                       break;
+
+                               case 'ascending':
+                                       $option_descending = FALSE;     // If it's not descending, it's ascending
+                                       break;
+
+                               case 'after':
+                                       $option_after = TRUE;
+                                       break;
+
+                               default:
+//                                     return( "<FONT COLOR=\"red\">ERROR: build_radio_buttons() Illegal option \"$opt\".</FONT>\n" );
+                                       break;
+                               }
+                       }
+               }
+
+       if( $option_order )
+               {
+               if( $option_descending )
+                       {                       // Sort Descending
+                       if( $option_numeric )
+                               arsort( $data, SORT_NUMERIC );
+                           else
+                               arsort( $data, SORT_STRING );
+                       }
+                   else
+                       {                       // Sort Ascending
+                       if( $option_numeric )
+                               asort( $data, SORT_NUMERIC );
+                           else
+                               asort( $data, SORT_STRING );
+                       }
+               }
+
+       $str = $sep = '';
+       while( list($key, $val) = each($data) )
+               {
+               $str .= $sep;
+
+               if( !$after )
+                       $str .= $val.' ';
+
+               switch( $type )
+                       {
+                       case "simple":
+                               $str .= '<INPUT TYPE="radio" NAME="'.$fieldname.'" VALUE="'.$val.'" '.($val==$selected?" CHECKED ":"").'>';
+                               break;
+                       case "standard":
+                               $str .= '<INPUT TYPE="radio" NAME="'.$fieldname.'" VALUE="'.$key.'" '.($key==$selected?" CHECKED ":"").'>';
+                               break;
+                       default:
+                               break;
+                       }
+
+               if( $after )
+                       $str .= ' '.$val;
+
+               $sep = $separator;
+               }
+       return( $str );
+}
+
+       // Create a date input form with a link to a pop-up calendar
+
+function calendar_date_select( $default_value, $selected_date, $start_date,
+                       $end_date, $form_name, $field_name, $options = "",
+                       $no_earlier = "" )
+{
+
+       GLOBAL  $si_month_array;
+
+       $months = array( 1=>"Jan",2=>"Feb",3=>"Mar",4=>"Apr",5=>"May",6=>"Jun",7=>"Jul",8=>"Aug",9=>"Sep",10=>"Oct",11=>"Nov",12=>"Dec" );
+
+       $start = getdate( $start_date );
+       $end   = getdate( $end_date );
+
+       $form = "<script language=\"JavaScript1.2\">
+                       <!--
+                               // Detect if the browser is IE or not.
+                               // If it is not IE, we assume that the browser is NS.
+
+                       var IE = document.all?true:false
+
+                               // If NS -- that is, !IE -- then set up for mouse capture
+
+//                     if (!IE) document.captureEvents(Event.MOUSEMOVE)
+
+                               // Set-up to use getMouseXY function onMouseMove
+
+//                     document.onmousemove = getMouseXY;
+
+                               // Temporary variables to hold mouse x-y pos.s
+
+                       var tempX = 0
+                       var tempY = 0
+
+                               // Main function to retrieve mouse x-y pos.s
+
+                       function getMouseXY(e)
+                               {
+                               if (IE)
+                                       { // grab the x-y pos.s if browser is IE
+                                       tempX = event.clientX //+ document.body.scrollLeft
+                                       tempY = event.clientY //+ document.body.scrollTop
+                                       }
+                                   else
+                                       {  // grab the x-y pos.s if browser is NS
+                                       tempX = e.pageX
+                                       tempY = e.pageY
+                                       }
+
+                                       // catch possible negative values in NS4
+
+                               if (tempX < 0){tempX = 0}
+                               if (tempY < 0){tempY = 0}
+
+                                       // show the position values in the form named Show
+                                       // in the text fields named MouseX and MouseY
+                                       //  document.Show.MouseX.value = tempX
+                                       //  document.Show.MouseY.value = tempY
+
+                               return true;
+                               }
+
+                       function calWin_".$field_name."()
+                               {
+                                       // Pass values to the calendar
+
+                               tempX = 400
+                               tempY = 300
+               ";
+       if( preg_match( "/PICK/", $options ) )
+               $form .= "      sd = this.document.$form_name.".$field_name."_month.value + '/' + this.document.$form_name.".$field_name."_day.value + '/' + this.document.$form_name.".$field_name."_year.value;
+                        ";
+         else
+               $form .= "  sd = this.document.$form_name.$field_name.value;
+                        ";
+
+       $form .= "      var theUrl='".SI_BASE_URL."/glm_apps/calendar.phtml?selected_date=' + sd + '&start_date=$start_date&end_date=$end_date&form_name=$form_name&field_name=$field_name';
+               ";
+
+               // If a "no_earlier" field is specified, have the script check for a date from other specified field and pass it in the URL
+
+       if( $no_earlier != "" )
+               $form .= "
+                               theUrl = theUrl + '&no_earlier=' + this.document.$form_name.$no_earlier.value
+                       ";
+       $form .= "
+                               tempX = tempX - 90;
+                               //tempY = tempY - 170;
+
+                               if (navigator.appName == 'Netscape')
+                                       {
+                                       calWind = window.open (theUrl, 'Calendar','scrollbars=no,toolbar=no,resizable=no,width=170,height=180,screenx=' + tempX +',screeny=' + tempY,1);
+                                       }
+                                   else
+                                       {
+                                       calWind = window.open (theUrl, 'Calendar','scrollbars=no,toolbar=no,resizable=no,width=170,height=180, top=' + tempY +', left=' + tempX,1);
+                                       }
+
+                               calWind.focus();
+                               }
+                       -->
+               </script>
+               ";
+
+               // Handle default date whether it's a string date or a timestamp
+
+       if( is_numeric($default_value) )
+               {
+               $default_timestamp = $default_value;
+               $default_value = date( 'n/j/Y', $default_value );
+               }
+         else
+               $default_timestamp = strtotime( $default_value );
+
+       $default_month = date( "n", $default_timestamp );
+       $default_day = date( "j", $default_timestamp );
+       $default_year = date( "Y", $default_timestamp );
+
+       if( preg_match( "/PICK/", $options ) )
+               {
+               $form .= build_a_picklist( $field_name."_month", $months, $default_month );
+               $form .= build_numeric_picklist( $field_name."_day", 1, 31, $default_day );
+               if( preg_match( "/HIDE_YEAR/", $options ) )
+                       $form .= '<INPUT TYPE="hidden" NAME="'.$field_name.'_year" VALUE="'.$default_year.'">';
+                   else
+                       $form .= build_numeric_picklist( $field_name."_year", date("Y"), date("Y",$end_date), $default_year );
+               $form .= '<INPUT TYPE="hidden" NAME="'.$field_name.'">';
+               }
+         else
+               $form .= '<INPUT TYPE="text" NAME="'.$field_name.'" SIZE="10" VALUE="'.$default_value.'">';
+
+       if( !preg_match( "/NO_PROMPT/", $options ) )
+               $form .= " (month/day/year) ";
+       $form .= '      <SCRIPT LANGUAGE="javascript">
+                               <!--
+                               document.write(\'<a href="javascript:calWin_'.$field_name.'()\"><IMG SRC="'.SI_BASE_URL.'/assets/calendar.gif" BORDER="0" ALT="Calendar"></A>\');
+                               -->
+                       </SCRIPT>
+                ';
+
+       return($form);
+}
+
+       // Build an HTML calendar with data from the array in each date
+
+function calendar_display( $month, $year, $date_data, $headerinfo='', $monthinfo='' )
+{
+       $MonthNames = array(1=>'January','February','March','April','May','June','July','August','September','October','November','December');
+
+/* This seems to be unnecessary
+
+       $calendar ='<script language="javascript">
+                       <!--
+                               function winMsger(msg)
+                                       {
+                                       calWind = window.open (\'\', \'Calendar\',\'scrollbars=no,toolbar=no,resizable=no,width=230,height=230\',1);
+                                       calWind.document.write("<HTML><TITLE>Calendar</TITLE></HTML>")
+                                       calWind.document.write("<body bgcolor=\'#FFFFFF\' leftmargin=\'0\' topmargin=\'0\' marginwidth=\'0\' marginheight=\'0\'>")
+                                       calWind.document.write(msg)
+                                       calWind.document.write("</BODY></HTML>")
+
+                                       calWind.focus()
+                                       }
+                       -->
+               </script>
+*/
+
+       $calendar = '
+               <STYLE TYPE="text/css">
+                       <!--
+                       th {   font-size: 12px; background-color: '. SI_CAL_DATE.'; font-weight: bold; }
+                       td.h { font-size: 12px; background-color: '. SI_CAL_HEAD.'; }
+                       td.n { font-size: 12px; background-color: '. SI_CAL_NODATE.'; }
+                       td.d { font-size: 12px; background-color: '. SI_CAL_TODAY.'; }
+//                     td.t { font-size: 12px; background-color: '. SI_CAL_DATE .'; }
+                       td.t { font-size: 12px; }
+                       td.z { font-size: 16px; background-color: '. SI_CAL_TABLE .'; }
+                       td.f {}
+                       //-->
+               </STYLE>
+
+               <TABLE BORDER="1" CELLPADDING="1" CELLSPACING="0" ALIGN="center" BGCOLOR="'. SI_CAL_TABLE.'" WIDTH="98%" HEIGHT="40%">
+                       <TR HEIGHT="20">
+                               <TD CLASS="z" COLSPAN="7" ALIGN="center"><B>'.(empty($monthinfo)?$MonthNames[$month].' '.$year:$monthinfo).'</B><br>
+                               </TD>
+                       </TR>
+               ';
+
+         if( !empty($headerinfo) )
+               {
+               $calendar.= '<TR><TD COLSPAN="7">'.$headerinfo.'
+                               </TD></TR>
+                               ';
+               }
+
+       $calendar.='<TR ALIGN="center" HEIGHT="15">
+                       <TH CLASS="h" width="14%">Sun</TH>
+                       <TH CLASS="h" width="14%">Mon</TH>
+                       <TH CLASS="h" width="14%">Tue</TH>
+                       <TH CLASS="h" width="14%">Wed</TH>
+                       <TH CLASS="h" width="14%">Thu</TH>
+                       <TH CLASS="h" width="14%">Fri</TH>
+                       <TH CLASS="h" width="14%">Sat</TH>
+               </TR>
+               <TR ALIGN="left">
+               ';
+
+               // Display blanks up to first day of the month
+
+       $offset = date( "w", mktime( 0, 0, 0, $month, 1, $year )  );
+       if( $offset > 0 )
+               $calendar .= str_repeat( "<TD CLASS=\"n\">&nbsp;</TD>\n",$offset );
+
+               // For each day of the month
+
+       $NumberOfDays = date( "t", mktime( 0, 0, 0, $month, 1, $year ) );
+       for( $i=1 ; $i<=$NumberOfDays ; $i++ )
+               {
+               $this_date = mktime( 0, 0, 0, $month, $i, $year );
+               $DayOfWeek = date( "w", $this_date );
+
+                       // Start a new row each Sunday, unless it's the 1st of the month
+
+               if( $DayOfWeek == 0 && $i != 1 )
+                       {
+                       $calendar .= '</TR><TR>';
+                       }
+
+               if( !empty($date_data[$i]["color"]) )
+                       $color = $date_data[$i]["color"];
+                   else
+                       $color = SI_CAL_DATE;
+
+               $calendar .= '<TD CLASS="t" ALIGN="left" VALIGN="top" BGCOLOR="'.$color.'">';
+
+               if( !empty($date_data[$i]["link"]) )
+                       $calendar .= '<A HREF="'.$date_data[$i]["link"].'">'.$i.'</A>';
+                   else
+                       $calendar .= $i;
+
+               $calendar .= '<BR>';
+
+               if( !empty($date_data[$i]["cell"]) )
+                       $calendar .= $date_data[$i]["cell"];
+
+               $calendar .= "</TD>\n";
+               }
+
+
+       if( ( ($offset == 5) && ($NumberOfDays > 30) ) || ( ($offset == 6) && ($NumberOfDays > 29) ) )
+               {
+               if( 42-$NumberOfDays-$offset > 0 )
+                       {
+                       $calendar .= str_repeat( "<TD CLASS=\"n\">&nbsp;</TD>\n",42-$NumberOfDays-$offset );
+                       }
+               $calendar .= "</TR>\n";
+               }
+           elseif( ($NumberOfDays != 28) || ($offset > 0) )
+               {
+               if (35-$NumberOfDays-$offset > 0)
+                       {
+                       $calendar .= str_repeat("<TD CLASS=\"n\">&nbsp;</TD>\n",35-$NumberOfDays-$offset);
+                       $calendar .= "</TR>\n";
+                       }
+               }
+
+       $calendar .= "</TABLE>\n";
+       return $calendar;
+}
+
+
+       // Get list of counties in a state
+
+function get_us_counties( $state, $fail_mode, $include_any=FALSE )
+{
+
+       $data = db_auto_get_data( "SELECT county FROM county_state WHERE state_code = '$state' ORDER by county;",
+                                     "host=ds4.gaslightmedia.com dbname=county user=".SI_DB_USER,
+                                     $fail_mode, 500 );
+
+       if( isset($include_any) && $include_any == TRUE )
+               $counties[""] = "(Any)";
+
+       if( count($data) )
+               {
+               while( list($key, $val) = each($data) )
+                       $counties[$val["county"]] = $val["county"];
+               }
+           else
+               $counties = array( "" => "(none)" );
+
+       return( $counties );
+
+}
+
+       // Parse a "view" file to merge in supplied data
+
+function parse_view( $file_name, $tokens, $show_unused = TRUE )
+       {
+       if( !($f = file_get( $file_name ) ) )
+               {
+               if( trim($file_name) == '' )
+                       return( "ERROR: No view file name supplied." );
+                 else
+                       return( "ERROR: View file '$file_name' not found or unreadable." );
+               }
+       $out = parse_string_view( $f, $tokens, $show_unsued );
+       return( $out );
+       }
+
+       // Process Lists
+
+function process_view_lists( $f, $tokens, $pvl_level = 0, $pvl_require_list_data = false )
+       {
+
+               // Process list sections
+
+       $out = "";
+
+       $p = 0;
+       while( !(($p2 = strpos( $f, "<!--{list:", $p )) === FALSE ))                    // While there are still lists
+               {
+                       // Start of a list has been found
+
+               $out .= substr( $f, $p, $p2-$p );                                                                               // Add portion up to start of list to output
+               $p = $p2 + 10;                                                                                                                  // Get past list token
+               if( !($p2 = strpos( $f, "}-->", $p )) || $p2 == $p )                                    // If there's no }--> following it, then something's wrong
+                       return( "ERROR: parse_view() - Missing name of {list:name} tag at $p.<P><PRE>".htmlentities(substr($f,$p,500))."</PRE>" );
+               $listname = substr( $f, $p, $p2-$p );                                                                   // Get name of this list
+
+                       // If list data is required (no empty lists) and we don't have any
+
+               if( $pvl_require_list_data && ( !isset($tokens[$listname]) || !is_array($tokens[$listname]) ) )
+                       {
+                       $out = "ERROR: parse_view() - No data supplied for list name \"$listname\".";
+                       if( SI_DEBUG_VIEW )
+                               $out .= "<P>&nbsp;<P><HR><P>Tags supplied to parse_view() function<P>".tableize_array( $tokens );
+                       return( $out );
+                       }
+
+               $p = $p2 + 4;                                                                                                                   // Move pointer to start of list
+               if( !($end = strpos( $f, "<!--{/list:".$listname."}-->", $p )) )                                                // Find end of this list section
+                       return( "ERROR: parse_view() - Matching {/list} tag not found at $p.<P><PRE>".htmlentities(substr($f,$p,500))."</PRE>" );
+
+                       // Break up list
+
+               unset( $list );
+               $sections = 0;
+               $sep = "";
+               while( ($p2 = strpos( $f, "<!--{sep:".$listname."}-->", $p )) && $p2 < $end )                   // While there's still separators in this list
+                       {
+                       $list[$sections] = substr( $f, $p, $p2-$p );                                            // Save this segment
+                       $p = $p2 + 13 + strlen($listname);                                                                      // Point past start of separator
+                       if( !($p2 = strpos( $f, "<!--{/sep:".$listname."}-->", $p )) || $p2 > $end )            // Find matching {/sep} tag
+                               return( "ERROR: parse_view() - Matching {/sep} tag not found at $p.<P><PRE>".htmlentities(substr($f,$p,500))."</PRE>" );
+                       if( empty($sep) )                                                                                                       // Only use the first separator
+                               $sep = substr( $f, $p, $p2-$p );
+                       $p = $p2 + 14 + strlen($listname);                                                                      // Point past end of {/sep} tag
+                       $sections++;                                                                                                            // Bump section count
+                       }
+
+               $list[$sections] = substr( $f, $p, $end-$p );                                                   // Store last section of list
+               $p = $end + 15 + strlen($listname);                                                                             // Point past this list
+               $sections++;                                                                                                                    // Bump section count
+
+                       // For each token expected in this list - Compile output
+
+               if( !empty( $tokens[$listname] ) )              // That is if there's any data for the list
+                       {
+                       $t = count($tokens[$listname]);                                                                         // Get number of blocks of data
+                       $j = 0;
+                       foreach( $tokens[$listname] as $to )                                                            // For each block of data supplied
+                               {
+                               if( !is_array($to) || count($to) == 0 )
+                                       {
+                                       $out = "ERROR: parse_view() - List data contains an empty token array for list $listname.";
+                                       if( SI_DEBUG_VIEW )
+                                               $out .= "<P>&nbsp;<P><HR><P>Tags supplied to parse_view() function<P>".tableize_array( $tokens );
+                                       return( $out );
+                                       }
+                               $x = replace_tokens( $list[$j%$sections], $to );                                // Replace tokens in appropriate section
+                               $x = process_view_lists( $x, $to, $pvl_level+1, $pvl_require_list_data );                               // Process any sub-lists
+                               $out .= cond_replace_tokens( $x, $to );                                                 // Do conditional replacements also
+
+                               if( ++$j < $t )                                                                                                 // If there's more data, output sep
+                                       $out .= $sep;
+                               }
+                       }
+               }
+
+       $out .= substr( $f, $p );                       // Now add remainder of page
+       return( $out );
+       }
+
+
+       // Parse a "view" string to mearge in supplied data
+
+function parse_string_view( $f, $tokens, $show_unused = TRUE )
+       {
+
+       if( empty($f) )
+               return( "ERROR: View string not provided." );
+
+               // Replace all {include:filename}
+
+       while( !( ($p2 = strpos( $f, '<!--{include:' )) == FALSE ) )            // While there's file includes
+               {
+
+               $p = $p2 + 13;          // Save the position of the start of the filename
+
+                       // Look for the end of this tag
+
+               if( !( $p2 = strpos($f, "}-->", $p)) || $p2 == $p ) // If there's no }--> following it, then something's wrong
+                       return ("ERROR: parse_view() - Missing name of {include:filename} tag at $p.<P><PRE>".htmlentities(substr($f, $p, 500))."</PRE>");
+
+                       // Read in the specified file
+
+               $filename = substr($f, $p, $p2 - $p); // Get name of the specified file
+               if( !($inc_file = file_get( SI_BASE_PATH.'/'.$filename)) )
+                       return ("ERROR: parse_view() - Target of {include:filename} tag does not exist or is unreadable at $p.<P><PRE>".htmlentities(substr($f, $p-13, 500))."</PRE>");
+
+                       // Replace the tag with the file contents
+
+               $f = str_replace( '<!--{include:'.$filename.'}-->', $inc_file, $f );
+
+               }
+
+               // Tear out {exclude} ... {/exclude} regions
+
+       $f = preg_replace( "/<!--\\{exclude\\}-->.*?<!--\\{\/exclude\\}-->/s", "", $f );
+
+               // Remove comments from around any {INCLUDE ... /INCLUDE} regions
+
+       $f = str_replace( "<!--{include}", "", $f );
+       $f = str_replace( "{/include}-->", "", $f );
+
+               // Insert any specified files
+       $f = replace_file_tokens( $f );
+
+               // Replace all global tokens
+       $f = replace_tokens( $f, $tokens["global"] );
+
+               // Do conditional replacements for global tokens
+
+       $f = cond_replace_tokens( $f, $tokens["global"] );
+
+       $out = process_view_lists( $f, $tokens );
+
+       if( $show_unused )
+               $out = preg_replace( "/(\\{\S*?\\})/", "<FONT COLOR=\"red\"><BLINK>\\1</BLINK></FONT>", $out );
+
+       if( SI_DEBUG_VIEW )
+               $out .= "<P>&nbsp;<P><HR><P>Tags supplied to parse_view() function<P>".tableize_array( $tokens );
+
+       return( $out );
+
+}
+
+
+       // MagicForm - Edit Form
+
+function magic_form_edit( $mf_id, $mf_format, $mf_level = 0 )
+       {
+//
+// Needed Enhancements
+//
+// Calculated fields - based on results from other fields
+//
+
+/*     data1 field description
+ *
+ *     {title}~{subform_id}~{misc_data}|{title}~{subform_id}~{misc_data}|...
+ *
+ */
+
+
+       global  $mf_field_id, $mf_action, $mf_position, $mf_field_id, $mf_field_option, $mf_option_id, $mf_option_name, $mf_option_value, $mf_option_value_type, $mf_position, $mf_position_num,
+                       $mf_field_text, $mf_field_image, $mf_field_image_name, $mf_field_image_delete, $mf_field_imagesize, $mf_field_title, $mf_field_descr, $form_data, $link_data, $mf_type, $mf_style, $mf_styles, $mf_action_id,
+                       $mf_field_cols, $mf_field_rows, $mf_custom_id, $mf_field_file, $mf_field_file_name, $mf_field_file_delete,
+                       $mf_formats, $mf_format_type, $mf_format_char, $mf_format_dec, $mf_format_min, $mf_format_max, $mf_def_val;
+
+               // Always pass along the current form/sub-form with any action requests
+
+       $mf_form_data = '<input type="hidden" name="mf_action_id" value="'.$mf_id.'">';
+       $mf_link_data = '&mf_action_id='.$mf_id;
+
+       $r['success'] = false;          // Assume a failed return
+       $r['modified'] = false;         // Assume we're not modifying the form - This is set to true for anything that changes the form in a way that old form results can't be used anymore.
+       $r['text'] = '';                        // With no text
+
+               // If we have a field ID then get data for that too
+
+       if( !empty($mf_field_id) && ($mf_field_data = db_auto_get_row( "SELECT * FROM ".MF_TABLE." WHERE id = $mf_field_id;", 0, SI_CONN_STR, FALSE )) )
+               $mf_field_data1 = $mf_field_data['data1'];
+         else
+               $mf_field_data1 = '';
+
+       $mf_normalize = false;
+       $mf_custom_id_update_message = '';
+
+               //
+               // Process Actions
+               //
+
+  if( $mf_action_id == $mf_id )
+       switch( $mf_action )
+               {
+
+               case "Add Field":
+
+                               // Add new field with default data
+
+                       // $r['modified'] = true;
+                       $oid = db_auto_exec( "INSERT INTO ".MF_TABLE." ( form_id, title, type, active, required, sort, expanded, style, format, file, cols, rows )
+                                                       VALUES ( '$mf_id', '', 0, 't', 'f', $mf_position, 't', 'Default', '', '', 20, 4 );", SI_CONN_STR, FALSE );
+                       $f = db_auto_get_row( "SELECT id FROM ".MF_TABLE." WHERE OID = $oid;", 0, SI_CONN_STR, FALSE );                 // Get new field ID
+                       $mf_field_id = $f['id'];
+                       $mf_normalize = true;
+                       break;
+
+               case "Set Type":
+
+                       // $r['modified'] = true;
+
+                               // Determine default style format for this type - First format that can be used for this type
+
+                       reset( $mf_styles );
+                       while( list($key, $val) = each($mf_styles) )
+                               if( strstr( $val['types'], ' '.$mf_type.' ' ) )
+                                       {
+                                       $mf_style .= $key;
+                                       break;
+                                       }
+
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET type = $mf_type, style = '$mf_style' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       if( $mf_type == 1 )     // IF checkbox
+                               db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = 'Yes~~~|No~~~' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Set Style":
+
+                       // $r['modified'] = true;
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET style = '$mf_style' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Set Field Format":
+
+                       // $r['modified'] = true;
+                       $x = $mf_format_type.'~'.$mf_format_char.'~'.$mf_format_dec.'~'.$mf_format_min.'~'.$mf_format_max;
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET format = '$x' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Add Option":
+
+                       // $r['modified'] = true;
+                       if( trim($mf_field_option) == '' )
+                                       break;
+
+                       if( !empty($mf_field_data1) )
+                                       $x = $mf_field_data1."|".$mf_field_option."~~";
+                                 else
+                                       $x = $mf_field_option."~~";
+
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($x)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Add Subform":
+
+                       // $r['modified'] = true;
+                       $x = explode( "|", $mf_field_data1 );                                                                                           // Separate data into options
+                       $y = explode( "~", $x[$mf_option_id-1] );                                                                                               // Separate specified option parameters
+                       $x[$mf_option_id-1] = $y[0]."~$mf_id.$mf_field_id.".time().'~'.$y[2].'~'.$y[3];
+                       $mf_field_data1 = implode( "|", $x );
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Delete Subform":
+
+                       // $r['modified'] = true;
+                       $x = explode( "|", $mf_field_data1 );
+                       $y = explode( "~", $x[$mf_option_id-1] );
+                       $x[$mf_option_id-1] = $y[0].'~~'.$y[2].'~'.$y[3];
+                       $mf_field_data1 = implode( "|", $x );
+
+                               // Delete any Images or Files associated with these fields
+
+                       if( ($del_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id LIKE '".$y[1]."%';" )) )
+                               {
+                               foreach( $del_fields as $d )
+                                       {
+                                       switch( $d['type'] )
+                                               {
+                                               case 24:        // Image
+                                                       delete_image( $d['file'] );
+                                                       break;
+                                               case 25:        // File
+                                                       file_delete( $d['file'] );
+                                                       break;
+                                               default:
+                                                       break;
+                                               }
+                                       }
+                               }
+
+                       db_auto_exec( "DELETE FROM ".MF_TABLE." WHERE form_id LIKE '".$y[1]."%'; UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Edit Option Name":
+
+                       // $r['modified'] = true;
+                       $x = explode( "|", $mf_field_data1 );
+                       $y = explode( "~", $x[$mf_option_id-1] );
+                       $x[$mf_option_id-1] = $mf_option_name.'~'.$y[1].'~'.$y[2].'~'.$y[3];
+                       $mf_field_data1 = implode( "|", $x );
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Edit Option Value":
+
+                       // $r['modified'] = true;
+                       if( ($err = clean_input( 'mf_option_value', 'float', 'true' )) != '' )                  // Validate input value as floating point
+                               $mf_option_value = 0;
+                       $x = explode( "|", $mf_field_data1 );
+                       $y = explode( "~", $x[$mf_option_id-1] );
+                       $x[$mf_option_id-1] = $y[0].'~'.$y[1].'~'.$mf_option_value.'~'.$mf_option_value_type;
+                       $mf_field_data1 = implode( "|", $x );
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Delete Option":
+
+                       $r['modified'] = true;
+                       $x = explode( "|", $mf_field_data1 );
+                       $y = explode( "~", $x[$mf_option_id-1] );
+                       array_splice( $x, $mf_option_id-1, 1 );
+                       $mf_field_data1 = implode( "|", $x );
+
+                               // Delete any Images or Files associated with these fields
+
+                       if( ($del_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id LIKE '".$y[1].".%';" )) )
+                               {
+                               foreach( $del_fields as $d )
+                                       {
+                                       switch( $d['type'] )
+                                               {
+                                               case 24:        // Image
+                                                       delete_image( $d['file'] );
+                                                       break;
+                                               case 25:        // File
+                                                       file_delete( $d['file'] );
+                                                       break;
+                                               default:
+                                                       break;
+                                               }
+                                       }
+                               }
+
+                               // Delete any sub-forms and update this field data
+
+                       db_auto_exec( "DELETE FROM ".MF_TABLE." WHERE form_id LIKE '".$y[1].".%'; UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Move Option Up":
+
+                               // If option position isn't already at the top
+                       if( $mf_option_id-1 != 0 )
+                               {
+                               $r['modified'] = true;
+                               $x = explode( "|", $mf_field_data1 );
+                               $y = array();
+                               for( $i=0 ; $i<count($x) ; $i++ )
+                                       {
+                                       if( $i == $mf_option_id-1 )
+                                               $y[$i*10-15] = $x[$i];
+                                         else
+                                               $y[$i*10] = $x[$i];
+                                       }
+                               ksort($y);
+                               $mf_field_data1 = implode( "|", $y );
+                               db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                               }
+                       break;
+
+               case "Move Option Down":
+                       $x = explode( "|", $mf_field_data1 );
+                               // If option position isn't already at the bottom
+                       if( $$mf_option_id-1 != count($x)-1 )
+                               {
+                               $r['modified'] = true;
+                               $y = array();
+                               for( $i=0 ; $i<count($x) ; $i++ )
+                                       {
+                                       if( $i == $mf_option_id-1 )
+                                               $y[$i*10+15] = $x[$i];
+                                         else
+                                               $y[$i*10] = $x[$i];
+                                       }
+                               ksort($y);
+                               $mf_field_data1 = implode( "|", $y );
+                               db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_data1)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                               }
+                       break;
+
+               case "Toggle Active":
+
+                       // $r['modified'] = true;
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET active = '".($mf_field_data['active']=='t'?'f':'t')."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Toggle Required":
+
+                       // $r['modified'] = true;
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET required = '".($mf_field_data['required']=='t'?'f':'t')."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Toggle Expanded":
+
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET expanded = '".($mf_field_data['expanded']=='t'?'f':'t')."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Expand All":
+
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET expanded = 't' WHERE form_id = '$mf_id';", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Contract All":
+
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET expanded = 'f' WHERE form_id = '$mf_id';", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Reposition":
+
+                       if( !empty( $mf_position_num ) )
+                               {
+                               if( clean_input( 'mf_position_num', 'int', true ) == '' )
+                                       {
+                                       $mf_position = $mf_position_num * 10;
+                                       if( $mf_position > $mf_field_data['sort'] )
+                                               $mf_position += 1;
+                                         else
+                                               $mf_position -= 1;
+                                       }
+                                 else
+                                       break;
+                               }
+
+                       // $r['modified'] = true;
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET sort = $mf_position WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       $mf_normalize = true;
+                       break;
+
+               case "Update Text":
+
+                       // $r['modified'] = true;
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET data1 = '".addslashes($mf_field_text)."' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Update Field":
+
+                       // $r['modified'] = true;
+                       $other_fields = '';
+                       if( $mf_field_data['type'] >= 2 && $mf_field_data['type'] <= 4 )        $other_fields .= ', cols = '.$mf_field_cols;
+                       if( $mf_field_data['type'] == 4 )                                                                       $other_fields .= ', rows = '.$mf_field_rows;
+                       if( $mf_field_data['type'] == 2 || $mf_field_data['type'] == 3 )        $other_fields .= ", default_val = '$mf_def_val'";
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET title = '".addslashes($mf_field_title)."', descr = '".addslashes($mf_field_descr)."'$other_fields WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               case "Update Image":
+
+                       // $r['modified'] = true;
+                       $new_image = '';
+                       $image_update = false;
+
+                               // if there's an existing image and we're either deleting or replacing it
+                       if( $mf_field_data['file'] != '' && ( $mf_field_image_delete == 'on' || $mf_field_image_name != '' ) )
+                               {
+                               delete_image( $mf_field_data['file'] );
+                               $image_update = true;
+                               }
+
+                               // If there's an image supplied
+                       if( $mf_field_image_name != '' )
+                               {
+                               $new_image = process_image( $mf_field_image, $mf_field_image_name );
+                               $image_update = true;
+                               }
+
+                       if( $image_update )
+                               db_auto_exec( "UPDATE ".MF_TABLE." SET file = '".addslashes($new_image)."', size = '$mf_field_imagesize' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+                         else
+                               db_auto_exec( "UPDATE ".MF_TABLE." SET size = '$mf_field_imagesize' WHERE id = $mf_field_id;", SI_CONN_STR, FALSE );
+
+
+                       break;
+
+               case "Update File":
+
+                       $existing_filename = $mf_field_data['file'];
+
+                       $new_filename = trim($mf_field_file_name);
+
+                               // If delete is requested or there's a new file upload AND there's an existing file, then delete the old one
+
+                       if( ( $mf_field_file_delete == 'on' || $new_filename != '' ) && $existing_filename != '' )
+                               {
+                               file_delete( $existing_filename );
+                               $existing_filename ='';
+                               }
+
+                       if( $mf_field_file != '' )
+                               {
+                               if( !($new_filename = file_upload( $mf_field_file, $new_filename )) )
+                                       $new_filename = '';
+                               }
+                         else
+                               $new_filename = $existing_filename;
+
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET file = '".addslashes($new_filename)."' WHERE id= $mf_field_id;" );
+
+                       break;
+
+               case "Set Custom ID":
+
+                       // $r['modified'] = true;
+                       $mf_custom_id = trim($mf_custom_id);
+
+                       if( $mf_custom_id != '' && db_auto_get_row( "SELECT id FROM ".MF_TABLE." WHERE form_id = '$mf_id' AND custom_id = '$mf_custom_id';" ) )
+                               $mf_custom_id_update_message = 'ID in Use.';
+                         else
+                               db_auto_exec( "UPDATE ".MF_TABLE." SET custom_id = '".trim($mf_custom_id)."' WHERE id = $mf_field_id;" );
+
+                       break;
+
+               case "Set Default":
+
+                       db_auto_exec( "UPDATE ".MF_TABLE." SET default_val = '".$mf_def_val."' WHERE id = $mf_field_id;" );
+
+                       break;
+
+               case "Delete":
+
+                       // $r['modified'] = true;
+
+                               // Delete any Images or Files associated with these fields
+
+                       if( ($del_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id LIKE '$mf_id.%' OR id = $mf_field_id;" )) )
+                               {
+                               foreach( $del_fields as $d )
+                                       {
+                                       switch( $d['type'] )
+                                               {
+                                               case 24:        // Image
+                                                       delete_image( $d['file'] );
+                                                       break;
+                                               case 25:        // File
+                                                       file_delete( $d['file'] );
+                                                       break;
+                                               default:
+                                                       break;
+                                               }
+                                       }
+                               }
+
+                       db_auto_exec( "DELETE FROM ".MF_TABLE." WHERE form_id LIKE '$mf_id.$mf_field_id.%' OR id = $mf_field_id;", SI_CONN_STR, FALSE );
+                       break;
+
+               default:
+                       break;
+               }
+
+               // If we need to normalize the sort numbers
+
+       if( $mf_normalize )
+               {
+               $mf_data = db_auto_get_data( "SELECT id, sort FROM ".MF_TABLE." WHERE form_id = '$mf_id' ORDER BY sort;", SI_CONN_STR, FALSE );
+               $qs = 'BEGIN;'.$nl;
+               $i = 10;
+               foreach( $mf_data as $mf )
+                       {
+                       $qs .= "UPDATE ".MF_TABLE." SET sort = ".$i." WHERE ID = ".$mf['id'].";\n";
+                       $i += 10;
+                       }
+               db_auto_exec( $qs."COMMIT;", SI_CONN_STR, FALSE );
+               }
+
+               //
+               // Display current form status
+               //
+
+       $font_size = '100%';            // Font size percentage to use for form elements
+
+       $mf_bgcolor = ($mf_level % 2);
+
+       $r['text'] .= '<TABLE BORDER="4" RULES="GROUPS" CELLPADDING="2" CELLSPACING="0" width="95%" BGCOLOR="'.($mf_bgcolor == 1?'#D1F1F1':'#ffffff').'">'.$nl;
+
+       if( ($mf_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id = '$mf_id' ORDER BY sort;", SI_CONN_STR, FALSE )) )
+               {
+
+               foreach( $mf_fields as $mf )
+                       {
+
+                       $base_form_data = '<FORM ACTION="'.SI_THIS_SCRIPT.'"  ENCTYPE="multipart/form-data" METHOD="post" >
+                                       '.$form_data.$mf_form_data.'
+                                       <INPUT TYPE="hidden" NAME="mf_field_id" VALUE="'.$mf['id'].'">
+                                       ';
+
+                       $mf_data = $mf_text = $mf_type_text = '';
+
+                       $mf_title_req = false;
+
+                       switch( $mf['type'] )
+                               {
+                                       // Checkbox
+
+                               case 1:
+                                       $mf_data .= '<BR>';
+                                       $mf_type_text = 'Checkbox';
+                                       $mf_data .= '<TABLE BORDER="0" WIDTH="100%" CELLPADDING="2" CELLSPACING="0" RULES="GROUPS">';
+                                       if( !empty($mf['data1']) )
+                                               {
+
+                                               $mf_data1 = explode( "|", $mf['data1'] );
+                                               for( $i=1 ; $i<=count($mf_data1) ; $i++ )
+                                                       {
+
+                                                       $x = explode( "~", $mf_data1[$i-1] );
+
+                                                               // Set option value output format
+
+                                                       if( trim($x[2]) != '' )
+                                                               switch( $x[3] )
+                                                                       {
+                                                                       case 1:         $xv = money($x[2]);             break;
+                                                                       default:        $xv = $x[2];                    break;
+                                                                       }
+                                                         else
+                                                               $xv = '(no value)';
+
+                                                       $mf_data .= '<TR>
+                                                                                       <TD ALIGN="left" VALIGN="top" CLASS="standout">Option: '.$x[0].'</TD>
+                                                                                       <TD ALIGN="right" VALIGN="top" CLASS="standout">Value: '
+                                                                                               .quick_edit( $mf['id'].'.'.$i, $xv,
+                                                                                               '<CENTER>'.$base_form_data.'
+                                                                                                       <INPUT TYPE="hidden" NAME="mf_option_id" VALUE="'.$i.'">
+                                                                                                       NOTE: Option value must be a number. Do not include a $ for monetary values.<p>
+                                                                                                       Option value: <INPUT TYPE="text" NAME="mf_option_value" STYLE="font-size: '.$font_size.';" VALUE="'.$x[2].'" SIZE="10">
+                                                                                                       Value Type: <SELECT NAME="mf_option_value_type"><OPTION VALUE="0"'.($x[3]==0?' SELECTED':'').'>Number</OPTION><OPTION VALUE="1"'.($x[3]==1?' SELECTED':'').'>Money</OPTION></SELECT><br>
+                                                                                                       <INPUT TYPE="submit" NAME="mf_action" VALUE="Edit Option Value" STYLE="font-size: '.$font_size.';">
+                                                                                               </FORM></CENTER>' )
+                                                                                       .'</TD>
+                                                                                       <TD ALIGN="right">
+                                                                                               '.( $x[1] == '' ?
+                                                                                                               '<A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Add+Subform&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'">[Sub-Form]</A>'
+                                                                                                               :
+                                                                                                               '<A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Delete+Subform&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'">[Delete Sub-Form]</A>'
+                                                                                                               ).'
+                                                                                               <A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Move+Option+Up&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'" ><b>&uarr;</b></A>
+                                                                                               <A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Move+Option+Down&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'"><b>&darr;</b></A>
+                                                                               ';
+
+                                                       $mf_data .= '</TD>
+                                                                               </TR>';
+                                                       if( $i == $mf['default_val'] )
+                                                               $mf_data .= '<TR><TD ALIGN="left" VALIGN="top" CLASS="standout_small" COLSPAN="3">Default Selection</TD></TR>';
+                                                         else
+                                                               $mf_data .= '<TR><TD ALIGN="left" VALIGN="top" CLASS="standout_small" COLSPAN="3"><A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Set+Default&mf_field_id='.$mf['id'].'&mf_def_val='.$i.'">Set as default selection</A></TD></TR>';
+
+                                                       if( $x[1] != '' )
+                                                               {
+                                                               $rs = magic_form_edit( $x[1], $mf_format, $mf_level+1 );
+                                                               if( $rs['success'] )
+                                                                       $mf_data .= '<TR><TD COLSPAN="3" ALIGN="right">'.$rs['text'].'</TD></TR>';
+                                                               if( $rs['modified'] )
+                                                                       $r['modified'] = true;
+                                                               }
+                                                       $mf_data .= ''.$nl;
+                                                       }
+                                               }
+                                       $mf_data .= '</TABLE>';
+                                       $mf_title_req = true;
+                                       break;
+
+                                       // Number
+
+                               case 2:
+                                       $mf_type_text = 'Number';
+                                       $mf_title_req = true;
+                                       break;
+
+                                       // Text field
+
+                               case 3:
+                                       $mf_type_text = 'Text';
+                                       $mf_title_req = true;
+                                       break;
+
+                                       // Text Box
+
+                               case 4:
+                                       $mf_type_text = 'Text Box';
+                                       $mf_title_req = true;
+                                       break;
+
+                                       // Picklist
+
+                               case 5:
+
+                                       // Radio Buttons
+
+                               case 6:
+
+                                       switch( $mf['type'] )
+                                               {
+                                               case 5:         $mf_type_text = 'Picklist';                     break;
+                                               case 6:         $mf_type_text = 'Radio Buttons';                break;
+                                               }
+
+                                       $mf_data .= '<TABLE BORDER="0" WIDTH="100%" CELLPADDING="2" CELLSPACING="0" RULES="GROUPS">';
+                                       if( !empty($mf['data1']) )
+                                               {
+                                               $mf_data1 = explode( "|", $mf['data1'] );
+                                               for( $i=1 ; $i<=count($mf_data1) ; $i++ )
+                                                       {
+                                                       $x = explode( "~", $mf_data1[$i-1] );
+
+                                                               // Set option value output format
+
+                                                       if( trim($x[2]) != '' )
+                                                               switch( $x[3] )
+                                                                       {
+                                                                       case 1:         $xv = money($x[2]);             break;
+                                                                       default:        $xv = $x[2];                    break;
+                                                                       }
+                                                         else
+                                                               $xv = '(no value)';
+
+                                                       $mf_data .= '<TR>
+                                                                                       <TD ALIGN="left" VALIGN="top" CLASS="standout">'
+                                                                                               .quick_edit( $mf['id'].'.'.$i, 'Option: '.stripslashes($x[0]),
+                                                                                               '<CENTER>'.$base_form_data.'
+                                                                                                       <INPUT TYPE="hidden" NAME="mf_option_id" VALUE="'.$i.'">
+                                                                                                       <INPUT TYPE="text" NAME="mf_option_name" STYLE="font-size: '.$font_size.';" VALUE="'.stripslashes($x[0]).'" SIZE="50"><BR>
+                                                                                                       <INPUT TYPE="submit" NAME="mf_action" VALUE="Edit Option Name" STYLE="font-size: '.$font_size.';">
+                                                                                               </FORM></CENTER>' )
+                                                                                       .'</TD>
+                                                                                       <TD ALIGN="right" VALIGN="top" CLASS="standout">Value: '
+                                                                                               .quick_edit( $mf['id'].'.'.$i."_value", $xv,
+                                                                                               '<CENTER>'.$base_form_data.'
+                                                                                                       <INPUT TYPE="hidden" NAME="mf_option_id" VALUE="'.$i.'">
+                                                                                                       NOTE: Option value must be a number. Do not include a $ for monetary values.<p>
+                                                                                                       Option value: <INPUT TYPE="text" NAME="mf_option_value" STYLE="font-size: '.$font_size.';" VALUE="'.$x[2].'" SIZE="10">
+                                                                                                       Value Type: <SELECT NAME="mf_option_value_type"><OPTION VALUE="0"'.($x[3]==0?' SELECTED':'').'>Number</OPTION><OPTION VALUE="1"'.($x[3]==1?' SELECTED':'').'>Money</OPTION></SELECT><br>
+                                                                                                       <INPUT TYPE="submit" NAME="mf_action" VALUE="Edit Option Value" STYLE="font-size: '.$font_size.';">
+                                                                                               </FORM></CENTER>' )
+                                                                                       .'</TD>
+                                                                                       <TD ALIGN="right">
+                                                                                               '.( $x[1] == '' ?
+                                                                                                               '<A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Add+Subform&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'">[Sub-Form]</A>'
+                                                                                                               :
+                                                                                                               '<A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Delete+Subform&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'">[Delete Sub-Form]</A>'
+                                                                                                               ).'
+                                                                                               <A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Delete+Option&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'">[delete]</A>
+                                                                                               <A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Move+Option+Up&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'" ><b>&uarr;</b></A>
+                                                                                               <A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Move+Option+Down&mf_field_id='.$mf['id'].'&mf_option_id='.$i.'"><b>&darr;</b></A>
+                                                                               ';
+
+                                                       $mf_data .= '</TD>
+                                                                               </TR>';
+
+                                                       if( $i == $mf['default_val'] )
+                                                               $mf_data .= '<TR><TD ALIGN="left" VALIGN="top" CLASS="standout_small" COLSPAN="3">Default Selection</TD></TR>';
+                                                         else
+                                                               $mf_data .= '<TR><TD ALIGN="left" VALIGN="top" CLASS="standout_small" COLSPAN="3"><A HREF="'.SI_THIS_SCRIPT.'?Action=Ref_Edi&'.$link_data.$mf_link_data.'&mf_action=Set+Default&mf_field_id='.$mf['id'].'&mf_def_val='.$i.'">Set as default selection</A></TD></TR>';
+
+                                                       if( $x[1] != '' )
+                                                               {
+                                                               $rs = magic_form_edit( $x[1], $mf_format, $mf_level+1 );
+                                                               if( $rs['success'] )
+                                                                       $mf_data .= '<TR><TD COLSPAN="3" ALIGN="right">'.$rs['text'].'</TD></TR>';
+                                                               if( $rs['modified'] )
+                                                                       $r['modified'] = true;
+
+                                                               }
+                                                       $mf_data .= ''.$nl;
+                                                       }
+                                               }
+                                         else
+                                               $mf_data .= '<TR><TD COLSPAN="3" ALIGN="left"><FONT COLOR="red">No options selected yet.</FONT></TD></TR>'.$nl;
+
+                                       $mf_data .= '<TR>
+                                                                       <TD COLSPAN="3" ALIGN="right">'
+                                                                       .quick_edit( '_add_option_'.$mf['id'],
+                                                                                               '<span class="pseudo_link">[Add Option]</a>',
+                                                                                               '<CENTER>'.$base_form_data.'
+                                                                                               <INPUT TYPE="text" NAME="mf_field_option" STYLE="font-size: '.$font_size.';">
+                                                                                               <INPUT TYPE="submit" NAME="mf_action" VALUE="Add Option" STYLE="font-size: '.$font_size.';">
+                                                                                               </FORM></CENTER>' )
+                                                                       .'</TD><TR>
+                                                               </TABLE>';
+                                       $mf_title_req = true;
+                                       break;
+
+                                       // File Upload
+
+                               case 7:
+                                       $mf_type_text = 'File Upload';
+                                       $mf_title_req = true;
+                                       break;
+
+
+                                       // Section Title
+
+                               case 20:
+                                       $mf_type_text = 'Section Title';
+                                       $mf_text .= quick_edit( $mf['id'],
+                                                                                       '<SPAN CLASS="standout">'.($mf['data1']!=''?stripslashes($mf['data1']):'(Section title not set)').'</span>',
+                                                                                       $base_form_data.'<TABLE BORDER="0">
+                                                                                               <TR>
+                                                                                                       <TD>&nbsp;</TD>
+                                                                                                       <TD ALIGN="right" VALIGN="top">Title:</TD>
+                                                                                                       <TD ALIGN="left" COLSPAN="3" VALIGN="top"><INPUT TYPE="text" NAME="mf_field_text" VALUE="'.$mf['data1'].'" STYLE="font-size: '.$font_size.';" SIZE="80"></TD>
+                                                                                               </TR>
+                                                                                       </TABLE>
+                                                                                       <CENTER><INPUT TYPE="submit" NAME="mf_action" VALUE="Update Text" STYLE="font-size: '.$font_size.';"></CENTER>
+                                                                                       </FORM>
+                                                                               ' );
+
+
+                                       break;
+
+                                       // Misc. Text
+
+                               case 21:
+                                       $mf_type_text = 'Misc. Text';
+                                       $mf_text .= quick_edit( $mf['id'],
+                                                                                       ( $mf['data1'] != '' ?
+                                                                                               ( $mf['expanded'] == 't' ?
+                                                                                                       stripslashes($mf['data1'])
+                                                                                               :
+                                                                                                       substr( stripslashes($mf['data1']), 0, 225 ).' ...'
+                                                                                               )
+                                                                                       :
+                                                                                               '<SPAN CLASS="standout">(Misc. text not set)</SPAN>'
+                                                                                       ),
+                                                                                       $base_form_data.'<TABLE BORDER="0">
+                                                                                               <TR>
+                                                                                                       <TD>&nbsp;</TD>
+                                                                                                       <TD ALIGN="right" VALIGN="top">Misc. Text:</TD>
+                                                                                                       <TD ALIGN="left" COLSPAN="3" VALIGN="top"><TEXTAREA NAME="mf_field_text" STYLE="font-size: '.$font_size.';" COLS="60" ROWS="4">'.$mf['data1'].'</TEXTAREA></TD>
+                                                                                               </TR>
+                                                                                       </TABLE>
+                                                                                       <CENTER><INPUT TYPE="submit" NAME="mf_action" VALUE="Update Text" STYLE="font-size: '.$font_size.';"></CENTER>
+                                                                                       </FORM>
+                                                                               ' );
+                                       break;
+
+                                       // Horizontal Line
+
+                               case 22:
+                                       $mf_type_text = 'Horiz Line';
+                                       $mf_text = '<hr>';
+                                       break;
+
+                                       // Blank Line
+
+                               case 23:
+                                       $mf_type_text = 'Blank Line';
+                                       $mf_text .= '(a blank line)';
+                                       break;
+
+                                       // Display Image
+
+                               case 24:
+                                       $mf_type_text = 'Image';
+                                       switch( $mf['size'] )
+                                               {
+                                               case 'original':        $image_size_url = SI_IMG_ORIGINAL_URL;  break;
+                                               case 'resized':         $image_size_url = SI_IMG_RESIZED_URL;   break;
+                                               case 'midsized':        $image_size_url = SI_IMG_MIDSIZED_URL;  break;
+                                               default:
+                                               case 'thumb':           $image_size_url = SI_IMG_THUMB_URL;             break;
+                                               }
+
+                                       $mf_data .= quick_edit( $mf['id'].'_image',
+                                                                                       ( $mf['file'] != '' ?
+                                                                                                       '<img src="'.$image_size_url.'/'.$mf['file'].'">'
+                                                                                       :
+                                                                                               '<SPAN CLASS="standout">(Image not set)</SPAN>'
+                                                                                       ),
+                                                                                       $base_form_data.'<TABLE BORDER="0" width="100%">
+                                                                                               <TR>
+                                                                                                       <TD COLSPAN="2" align="center">'.( $mf['file'] != '' ? '<img src="'.SI_IMG_THUMB_URL.'/'.$mf['file'].'">':'(no image)').'</TD>
+                                                                                               </TR>
+                                                                                               <TR>
+                                                                                                       <TD ALIGN="right">Delete existing Image:</TD>
+                                                                                                       <TD ALIGN="left"><INPUT TYPE="checkbox" NAME="mf_field_image_delete"></TD>
+                                                                                               </TR>
+                                                                                               <TR>
+                                                                                                       <TD ALIGN="right">Image Size:</TD>
+                                                                                                       <TD ALIGN="left">
+                                                                                                               <SELECT NAME="mf_field_imagesize">
+                                                                                                                       <OPTION VALUE="original"'.($mf['size']=='original'?' SELECTED':'').'>Original</OPTION>
+                                                                                                                       <OPTION VALUE="resized"'.($mf['size']=='resized'?' SELECTED':'').'>Resized</OPTION>
+                                                                                                                       <OPTION VALUE="midsized"'.($mf['size']=='midsized'?' SELECTED':'').'>Midsized</OPTION>
+                                                                                                                       <OPTION VALUE="thumb"'.($mf['size']=='thumb'?' SELECTED':'').'>Thumbnail</OPTION>
+                                                                                                               </SELECT>
+                                                                                                       </TD>
+                                                                                               </TR>
+                                                                                               <TR>
+                                                                                                       <TD ALIGN="right">Select Image:</TD>
+                                                                                                       <TD ALIGN="left"><INPUT TYPE="file" NAME="mf_field_image"></TD>
+                                                                                               </TR>
+                                                                                       </TABLE>
+                                                                                       <CENTER><INPUT TYPE="submit" NAME="mf_action" VALUE="Update Image" STYLE="font-size: '.$font_size.';"></CENTER>
+                                                                                       </FORM>
+                                                                               ' );
+                                       break;
+
+                                       // File Download
+
+                               case 25:
+
+                                       $mf_type_text = 'File Download';
+                                       $mf_data .= quick_edit( $mf['id']."_file",
+                                                                                       ( $mf['file'] != '' ?
+                                                                                                       '<SPAN CLASS="standout">File: '.$mf['file'].'</SPAN>'
+                                                                                       :
+                                                                                               '<SPAN CLASS="standout">(File not provided)</SPAN>'
+                                                                                       ),
+                                                                                       $base_form_data.'<TABLE BORDER="0" width="100%">'
+                                                                                       .( $mf['file'] != '' ?
+                                                                                               '<TR>
+                                                                                                       <TD ALIGN="right" VALIGN="top">Current File:</TD>
+                                                                                                       <TD ALIGN="left" COLSPAN="2">
+                                                                                                               <a href="'.SI_BASE_FILE_URL.'/'.$mf['file'].'" target="file_page">'.$mf['file'].'</a>
+                                                                                                               <INPUT TYPE="checkbox" NAME="mf_field_file_delete"> Delete this file
+                                                                                                       </TD>
+                                                                                                </TR>
+                                                                                                <TR><TD COLSPAN="2">&nbsp;</TD></TR>
+                                                                                       ' : '' ).'
+                                                                                                <TR>
+                                                                                                       <TD ALIGN="right" VALIGN="top">Upload/Replace File:</TD>
+                                                                                                       <TD ALIGN="left" COLSPAN="2" VALIGN="top"><INPUT TYPE="file" NAME="mf_field_file"></TD>
+                                                                                               </TR>
+                                                                                       </TABLE>
+                                                                                       <CENTER><INPUT TYPE="submit" NAME="mf_action" VALUE="Update File" STYLE="font-size: '.$font_size.';"></CENTER>
+                                                                                       </FORM>
+                                                                               ' );
+
+                                       break;
+
+                                       // Calculated field
+
+                               case 31:
+                                               // Not yet implimented
+                                       break;
+
+                               case 0:
+                               default:
+                                       $mf_data = '&nbsp;';
+
+                                       break;
+                               }
+
+                               // Build list of available styles for this field
+
+                       $mf_style_list = '';
+                       reset( $mf_styles );
+                       while( list($key, $val) = each($mf_styles) )
+                               if( strstr( $val['types'], ' '.$mf['type'].' ' ) )
+                                       $mf_style_list .= '<option value="'.$key.'"'.($mf['style']==$key?' SELECTED':'').'>'.$key.'</option>';
+
+                               // Extract current format info and build list of possible formats for this field
+
+                       $mf_cf = explode( '~', $mf['format'] );
+                       $mf_format_list = '';
+                       reset( $mf_formats );
+                       while( list($key, $val) = each($mf_formats) )
+                               if( strstr( $val['types'], ' '.$mf['type'].' ' ) )
+                                       $mf_format_list .= '<option value="'.$key.'"'.($mf_cf[0]==$key?' SELECTED':'').'>'.$key.'</option>';
+
+                               // Display Title, descr, and optionally size with QuickEdit pop-up
+
+                       if( $mf['type'] > 0 && ( $mf['type'] < 20 || $mf['type'] == 24 || $mf['type'] == 25 ) )
+                               $mf_text .= quick_edit( $mf['id'],
+                                                                                       '<SPAN CLASS="standout">Title: '.stripslashes($mf['title']).'</SPAN>'
+                                                                                       .( $mf['expanded'] == 't' ?
+                                                                                               '<BR>
+                                                                                               <SPAN CLASS="standout_small">Descr: '.stripslashes($mf['descr'])
+                                                                                               .( $mf['type'] >= 2 && $mf['type'] <= 4 ?
+                                                                                                               '<BR>Columns: '.$mf['cols']
+                                                                                                       .( $mf['type'] == 4 ?
+                                                                                                               '<BR>Rows: '.$mf['rows']
+                                                                                                       : '' )
+                                                                                               : '' )
+                                                                                               .( $mf['type'] >= 2 && $mf['type'] <= 3 ?
+                                                                                                               '<BR>Default Value: '.$mf['default_val']
+                                                                                               : '' )
+                                                                                       : '' ),
+                                                                                       $base_form_data.'<TABLE BORDER="0">
+                                                                                               <TR>
+                                                                                                       <TD>&nbsp;</TD>
+                                                                                                       <TD ALIGN="right" VALIGN="top">Title:</TD>
+                                                                                                       <TD ALIGN="left" COLSPAN="3" VALIGN="top"><INPUT TYPE="text" NAME="mf_field_title" VALUE="'.stripslashes($mf['title']).'" STYLE="font-size: '.$font_size.';" SIZE="70"></TD>
+                                                                                               </TR>
+                                                                                               <TR>
+                                                                                                       <TD>&nbsp;</TD>
+                                                                                                       <TD ALIGN="right" VALIGN="top">Descr:</TD>
+                                                                                                       <TD ALIGN="left" COLSPAN="3" VALIGN="top"><TEXTAREA NAME="mf_field_descr" STYLE="font-size: '.$font_size.';" COLS="67" ROWS="3">'.stripslashes($mf['descr']).'</TEXTAREA></TD></TR>
+                                                                                               </TR>
+                                                                               '.( $mf['type'] >= 2 && $mf['type'] <= 4 ? '
+                                                                                               <TR>
+                                                                                                       <TD>&nbsp;</TD>
+                                                                                                       <TD ALIGN="right" VALIGN="top">Columns:</TD>
+                                                                                                       <TD ALIGN="left" COLSPAN="3" VALIGN="top"><INPUT TYPE="text" NAME="mf_field_cols" VALUE="'.$mf['cols'].'" STYLE="font-size: '.$font_size.';" SIZE="6"> </TD></TR>
+                                                                                               </TR>
+                                                                                       '.( $mf['type'] == 4 ? '
+                                                                                               <TR>
+                                                                                                       <TD>&nbsp;</TD>
+                                                                                                       <TD ALIGN="right" VALIGN="top">Rows:</TD>
+                                                                                                       <TD ALIGN="left" COLSPAN="3" VALIGN="top"><INPUT TYPE="text" NAME="mf_field_rows" VALUE="'.$mf['rows'].'" STYLE="font-size: '.$font_size.';" SIZE="6"> </TD></TR>
+                                                                                               </TR>
+                                                                                       ' : '' ).'
+                                                                               ' : '' ).'
+                                                                               '.( $mf['type'] >= 2 && $mf['type'] <= 3 ? '
+                                                                                               <TR>
+                                                                                                       <TD>&nbsp;</TD>
+                                                                                                       <TD ALIGN="right" VALIGN="top">Default Value:</TD>
+                                                                                                       <TD ALIGN="left" COLSPAN="3" VALIGN="top"><INPUT TYPE="text" NAME="mf_def_val" VALUE="'.$mf['default_val'].'" STYLE="font-size: '.$font_size.';" SIZE="30"> </TD></TR>
+                                                                                               </TR>
+                                                                               ' : '' ).'
+                                                                                       </TABLE>
+                                                                                       <CENTER><INPUT TYPE="submit" NAME="mf_action" VALUE="Update Field" STYLE="font-size: '.$font_size.';"></CENTER>
+                                                                                       </FORM>
+                                                                               ' );
+
+
+                       $r['text'] .= '<TBODY>
+                                                               <TR>
+                                                                       <TD VALIGN="top" WIDTH="100" ROWSPAN="2">'
+                                                                               .'<form action="'.SI_THIS_SCRIPT.'"'.$form_data.$mf_form_data.'
+                                                                                       <input type="hidden" name="mf_action" value="Reposition">
+                                                                                       <input type="hidden" name="mf_field_id" value="'.$mf['id'].'">
+                                                                                       <INPUT TYPE="text" NAME="mf_position_num" ID="mf_field_'.$mf['id'].'" VALUE="'.($mf['sort']/10).'" SIZE="5" onChange="submit();" >&nbsp;'
+                                                                                       .'<A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Reposition&mf_field_id='.$mf['id'].'&mf_position='.( $mf['sort'] - 15 ).'">&uarr;</A>&nbsp;'
+                                                                                       .'<A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Reposition&mf_field_id='.$mf['id'].'&mf_position='.( $mf['sort'] + 15 ).'">&darr;</A>&nbsp;
+                                                ';
+                       if( $mf['expanded'] == 't' )
+                               {
+                               $r['text'] .= '         <BR>
+                                                                               <span class="standout_small">'
+                                                               .( $mf_type_text != '' ?
+                                                                                       $mf_type_text
+                                                                               .'</span><BR>
+                                                                               <span class="standout_small">'
+                                                                                       .quick_edit( $mf['id']."_style",
+                                                                                       $mf_styles[$mf['style']]['short_name'],
+                                                                                       '<CENTER>
+                                                                                               <FORM NAME="set_style" ACTION="'.SI_THIS_SCRIPT.'">
+                                                                                                       '.$form_data.$mf_form_data.'
+                                                                                                       Set style For this field:
+                                                                                                       <input type="hidden" name="mf_field_id" value="'.$mf['id'].'">
+                                                                                                       <SELECT NAME="mf_style">
+                                                                                                               '.$mf_style_list.'
+                                                                                                       </SELECT>
+                                                                                                       <INPUT TYPE="submit" NAME="mf_action" VALUE="Set Style">
+                                                                                                       </form>
+                                                                                       </CENTER>' ).'
+                                                                               </span><BR>
+                                                                       '.( $mf_format_list != '' ? '
+                                                                               <span class="standout_small">'
+                                                                                       .quick_edit( $mf['id']."_format",
+                                                                                       ( $mf_cf[0] != '' ? $mf_formats[$mf_cf[0]]['short_name'] : 'Default Format' ),
+                                                                                       '<CENTER>
+                                                                                               <FORM NAME="set_format" ACTION="'.SI_THIS_SCRIPT.'">
+                                                                                                       '.$form_data.$mf_form_data.'
+                                                                                                       <table border="0">
+                                                                                                         <tr>
+                                                                                                               <td align="right">Format Type: </td>
+                                                                                                               <td align="left"><input type="hidden" name="mf_field_id" value="'.$mf['id'].'">
+                                                                                                                       <SELECT NAME="mf_format_type">
+                                                                                                                               '.$mf_format_list.'
+                                                                                                                       </SELECT>
+                                                                                                               </td>
+                                                                                                         </tr>
+                                                                                                         <tr>
+                                                                                                               <td align="right">Maximum Characters/Digits to left of decimal point: </td>
+                                                                                                               <td align="left"><INPUT TYPE="text" NAME="mf_format_char" VALUE="'.$mf_cf[1].'" SIZE="6"></td>
+                                                                                                         </tr>
+                                                                                                         <tr>
+                                                                                                               <td align="right">Digits after Decimal Point: </td>
+                                                                                                               <td align="left"><INPUT TYPE="text" NAME="mf_format_dec" VALUE="'.$mf_cf[2].'" SIZE="6"></td>
+                                                                                                         </tr>
+                                                                                                         <tr>
+                                                                                                               <td align="right">Number Range: </td>
+                                                                                                               <td align="left"><INPUT TYPE="text" NAME="mf_format_min" VALUE="'.$mf_cf[3].'" SIZE="6"> Min <INPUT TYPE="text" NAME="mf_format_max" VALUE="'.$mf_cf[4].'" SIZE="6"> Max</td>
+                                                                                                         </tr>
+                                                                                                         <tr><td colspan="2" align="center">(Note: Not all fields used for all format types.)</td></tr>
+                                                                                                         <tr><td colspan="2" align="center"><INPUT TYPE="submit" NAME="mf_action" VALUE="Set Field Format"></td></tr>
+                                                                                                       </table>
+                                                                                                       </form>
+                                                                                       </CENTER>' ).'
+                                                                               </span><BR>
+                                                                       ' : '' ).'
+                                                                               <span class="standout_small"><nobr>ID: '
+                                                                                       .quick_edit( $mf['id']."_id",
+                                                                                       ( $mf['custom_id'] != '' ? $mf['custom_id'] : 'mf_'.$mf['id'] ),
+                                                                                       '<CENTER>
+                                                                                               <FORM NAME="set_style" ACTION="'.SI_THIS_SCRIPT.'">
+                                                                                                       '.$form_data.$mf_form_data.'
+                                                                                                       Custom ID:
+                                                                                                       <input type="hidden" name="mf_field_id" value="'.$mf['id'].'">
+                                                                                                       <input type="text" name="mf_custom_id" value="'.$mf['custom_id'].'" size="15"><br>
+                                                                                                       Clear to reset to default ID.<P>
+                                                                                                       <INPUT TYPE="submit" NAME="mf_action" VALUE="Set Custom ID">
+                                                                                                       </form>
+                                                                                       </CENTER>' ).'
+                                                                               </nobr></span><BR>'.( $mf_custom_id_update_message != '' ? '<font color="red">'.$mf_custom_id_update_message.'</font><br>' : '' ).'
+                                                               ' :
+                                                                                       quick_edit( $mf['id'],
+                                                                                       '<font color="red">Type Not Set</font>',
+                                                                                       '<CENTER>
+                                                                                               <FORM NAME="add_field" ACTION="'.SI_THIS_SCRIPT.'">
+                                                                                                       '.$form_data.$mf_form_data.'
+                                                                                                       <font color="red">Set field type: </font>
+                                                                                                       <input type="hidden" name="mf_field_id" value="'.$mf['id'].'">
+                                                                                                       <SELECT NAME="mf_type">
+                                                                                                               <OPTION VALUE="1">Checkbox
+                                                                                                               <OPTION VALUE="2">Number
+                                                                                                               <OPTION VALUE="3">Text
+                                                                                                               <OPTION VALUE="4">Text Box
+                                                                                                               <OPTION VALUE="5">Picklist
+                                                                                                               <OPTION VALUE="6">Radio Buttons
+                                                                                                               <OPTION VALUE="7">File Upload
+                                                                                                               <OPTION VALUE="20">Section Title
+                                                                                                               <OPTION VALUE="21">Misc. Text
+                                                                                                               <OPTION VALUE="22">Horizontal Line
+                                                                                                               <OPTION VALUE="23">Blank Line
+                                                                                                               <OPTION VALUE="24">Display Image
+                                                                                                               <OPTION VALUE="25">Download File
+                                                                                                               <!-- <OPTION VALUE="31">Calculated Field (currently dissabled) -->
+                                                                                                       </SELECT>
+                                                                                                       <INPUT TYPE="submit" NAME="mf_action" VALUE="Set Type">
+                                                                                                       </form>
+                                                                                       </CENTER>' ).'<br>
+                                                                       <font color="red">Field Style Not Set</font>'
+                                                               ).'<br>
+
+                                                                               <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Toggle+Active&mf_field_id='.$mf['id'].'">'.( $mf['active'] == 't' ? 'Active' : '<FONT COLOR="#c0c0c0">Active</FONT>' ).'&nbsp;&nbsp;</A><br>
+                                                                               '.( $mf['type'] > 1 && $mf['type'] < 20 ? '<A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Toggle+Required&mf_field_id='.$mf['id'].'">'.($mf['required']=='t'?'Required':'<FONT COLOR="#c0c0c0">Required</FONT>').'</A>&nbsp;&nbsp;':'&nbsp;').'
+
+                                                        ';
+                               }
+
+                       $r['text'] .= '</TD>
+                                                       ';
+
+                       if( !empty($mf_text) )
+                               $r['text'] .= ' <TD ALIGN="left" VALIGN="top">'.$mf_text.'</TD>';
+                         else
+                               $r['text'] .= ' <TD>&nbsp;</TD>';
+
+                       $r['text'] .= '         <TD VALIGN="top" ALIGN="right">
+                                                               '.( $mf['expanded'] == 't' ?
+                                                                       '<A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Toggle+Expanded&mf_field_id='.$mf['id'].'">[Contract]</A><BR>
+                                                                       <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Delete&mf_field_id='.$mf['id'].'">[Delete]</A>&nbsp;<BR>
+                                                                       <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Add+Field&mf_position='.( $mf['sort'] - 5 ).'"><nobr>[Add Above]</nobr></A>&nbsp;'
+                                                               :
+                                                                       '<A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Toggle+Expanded&mf_field_id='.$mf['id'].'">[Expand]</A>'
+                                                               ).'
+                                                         </TD>
+                                                       </TR>
+                                                       '.( $mf['expanded'] == 't' ? '<TR><TD VALIGN="top" COLSPAN="3">'.$mf_data.'</TD></TR>' : '<TR><TD COLSPAN="3"></TD></TR>' ).'
+                                                       </TBODY>
+                                                ';
+                       }
+               }
+
+
+       $r['text'] .= '<TR><TD COLSPAN="3" ALIGN="right">
+                                       <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Add+Field&mf_position=9999">[Add New Field]</A>
+                                       <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Expand+All">[Expand All]</A>
+                                       <A HREF="'.SI_THIS_SCRIPT.'?'.$link_data.$mf_link_data.'&mf_action=Contract+All">[Contract All]</A>
+                                 </TD></TR></TABLE>
+                                ';
+       $r['success'] = true;
+
+       return( $r );
+
+       }
+
+       // MagicForm - Display Form
+
+function magic_form_display( $mf_id, $mf_styles, $mf_fiid = null,  $mf_def_data = array(), $mf_level = 0 )
+       {
+
+       global $mf_formats;
+
+               // Get the fields specifications for the specified form
+
+       $mf_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id = '$mf_id' ORDER BY sort;", SI_CONN_STR, FALSE );
+
+               // If this is level 0, get any data supplied from earlier form submissions, if level > 0 then use data we already have
+
+       if( $mf_fiid != null  )
+               $mf_data = db_auto_get_data( "SELECT * FROM ".MF_DATA_TABLE." WHERE fiid = '$mf_fiid' ORDER BY sort;", SI_CONN_STR, FALSE );
+         else
+           $mf_data = &$mf_def_data;
+
+           // Initialize results array
+
+       $r = array( 'success' => true, 'text' => '', 'required' => false );
+
+       $mf_level++;            // Incriment MagicForm recurse level (not shure why we're doing this though)
+       $problem = '';
+       $current_style = '';
+       $current_collumn = 1;
+
+       if( is_array($mf_fields) )
+               {
+
+               reset( $mf_fields );
+               foreach( $mf_fields as $mf )
+                       {
+
+                       if( $mf['active'] == 't' )
+                               {
+
+                                       //
+                                       // Style/Layout Stuff
+                                       //
+
+                                       // Determine format spec
+
+                               $f = $mf_styles[$mf['style']];          // just use default for now and assume 1 col/row
+
+                                       // Check if we're switching styles and handle accordingly
+
+                               if( $current_style != $mf['style'] )
+                                       {
+                                               // If this is not the first style
+                                       if( $current_style != '' )
+                                               {
+                                                       // If not at the last column, fill with blank cells
+                                               if( $current_column < $mf_styles[$current_style]['cols'] )
+                                                       for( $i=$current_column ; $i<=$mf_styles[$current_style]['cols'] ; $i++ )
+                                                               $r['text'] .= $mf_styles[$current_style]['col_empty'];
+                                               $r['text'] .= $mf_styles[$current_style]['row_end'].$mf_styles[$current_style]['end'];
+                                               }
+
+                                               // Set new style and output start and row headder
+                                       $current_style = $mf['style'];
+                                       $r['text'] .= $f['start'].$f['row_start'];
+                                       $current_collumn = 1;
+                                       }
+
+                                       // Check if we need to start a new row
+
+                               if( $current_collumn++ > $f['cols'] )
+                                       {
+                                       $r['text'] .= $f['row_end'].$f['row_start'];
+                                       $current_collumn = 1;
+                                       }
+
+                                       //
+                                       // End of Style/Layout stuff
+                                       //
+
+                               $view_tags = array ( "global"   => array() );
+                               $v = &$view_tags["global"];
+
+                               $field_name = 'mf_'.$mf['id'];                                                                                                          // Name we're going to use for this field
+                               $v['title']     = stripslashes($mf['title']);
+                               $v['descr']     = stripslashes($mf['descr']);
+                               $v['required'] = '';
+                               if( $mf['type'] > 1 && $mf['type'] < 20 && $mf['required'] == 't' )                                     // if field is required, display in red
+                                       {
+                                       $v['required'] = 'Yes';
+                                       $r['required'] = true;
+                                       }
+                               $v['image'] = $v['file'] = $v['input'] = '';
+
+                               $GLOBALS['mf_'.$mf['id']] = stripslashes($GLOBALS['mf_'.$mf['id']]);                            // get current field input data
+
+                               $v['sub_forms'] = '';                                                                                                                           // Start with no sub-forms
+
+                                       // Check for default data for this field and use either opt_num or value depending on type
+
+                               if( is_array($x=$mf_def_data[$mf['id']]) )
+                                       switch( $mf['type'] )
+                                               {
+                                               case 1:         // Checkbox
+                                               case 5:         // Picklist
+                                               case 6:         // Radio Buttons
+                                                       $inp = $x['opt_num'];
+                                                       break;
+                                               default:
+                                                       $inp = $x['value'];
+                                                       break;
+                                               }
+                                 else
+                                       $inp = $mf['default_val'];              // Otherwise use defaut data
+
+                                       // Extract field format specs and replace occurances of {chars} and {prec}
+
+                               $mf_cf = explode( '~', $mf['format'] );
+                               $mf_cf_size = $mf_cf[1] + ($mf_cf[2]>0?1:0) + $mf_cf[2];
+                               $mf_cf_out = str_replace( '{chars}', $mf_cf[1], $mf_formats[$mf_cf[0]]['format'] );
+                               $mf_cf_out = str_replace( '{prec}', $mf_cf[2], $mf_cf_out );
+
+                               if( $mf_cf_out == '' )  // If nothing specified, default to simple string out
+                                       $mf_cf_out = '%s';
+
+                               switch( $mf['type'] )
+                                       {
+
+                                       case 1:         // Checkbox
+
+                                                       // Build most of checkbox input tag but leave open for rest of JAVAscript onChange text
+
+                                               $v['input'] = '<INPUT TYPE="checkbox" NAME="'.$field_name.'" id="'.$field_name.'" '.($inp=='1'?' CHECKED':'').' onClick="';
+                                               $ans = explode( "|", $mf['data1'] );                                    // Separate answers
+
+                                               if( $inp == '' ) $inp = 0;      // Default to false
+                                               $xv = '';
+
+                                                       // Check response for subform ($i=1 - Yes, $i=2 - No)
+                                               for( $i=1 ; $i<=2 ; $i++ )
+                                                       {
+                                                       $an = explode( '~', $ans[$i-1] );
+
+                                                               // Check for a sub-form
+
+                                                       if( !empty($an[1]) )
+                                                               {
+                                                               $sub = magic_form_display( $an[1], $mf_styles, null, $mf_def_data, $mf_level );
+                                                               if( $sub['success'] )
+                                                                       {
+                                                                       $v['sub_forms'] .= '<div id="'.$field_name.'_'.$i.'" style="display: '.($inp==$i?'block':'none').';"> '.str_replace( "{sub_form}", $f['sub_form'], $sub['text'] ).'</div>';
+                                                                       $v['input'] .= "document.getElementById('".$field_name."_$i').style.display = document.getElementById('".$field_name."').checked == ".($i==1?'true':'false')." ? 'block' : 'none'; ";
+                                                                       }
+                                                                 else
+                                                                       $v['sub_forms'] .= '<p><font color="red">FORM ERROR</font>: Unable to process sub-form for checkbox: '.$mf['title'].'<p>';
+                                                               }
+
+                                                               // Optionally set value if this is the "Yes" option
+
+                                                       if( $i==0 && $an[2] != '' )
+                                                               switch( $an[3] )
+                                                                       {
+                                                                       case 1:         $xv .= " ".money($an[2]);               break;
+                                                                       default:        $xv .= " ".$an[2];                              break;
+                                                                       }
+
+                                                       }
+
+                                               $v['input'] .= '"> '.$xv;               // Close onChange string
+
+                                               break;
+
+                                       case 2:         // Number
+                                       case 3:         // Text
+                                               $inp = trim( str_replace( array( '|', '~' ), '', $inp ) );
+                                               $v['input'] = '<INPUT TYPE="text" NAME="mf_'.$mf['id'].'" VALUE="'.trim(sprintf( $mf_cf_out, $inp )).'" SIZE="'.$mf['cols'].'" '.($mf_cf_size>0?' maxlength="'.$mf_cf_size.'"':'').'>';
+                                               break;
+
+                                       case 4:         // Text Box
+                                               $inp = trim( str_replace( array( '|', '~' ), '', $inp ) );
+                                               $v['input'] = '<TEXTAREA NAME="mf_'.$mf['id'].'" COLS="'.$mf['cols'].'" rows="'.$mf['rows'].'">'.$inp.'</TEXTAREA>';
+                                               break;
+
+                                       case 5:         // Picklist
+                                               $opts = explode( "|", $mf['data1'] );
+                                               $sel = '<SELECT NAME="mf_'.$mf['id'].'" id="'.$field_name.'" onChange="';
+                                               $sel_opts = '<OPTION VALUE="" '.($inp==''?'SELECTED':'').'>';
+                                               $n = 1;
+                                               foreach( $opts as $opt )
+                                                       {
+                                                       $an = explode( "~", $opt );
+
+                                                       $sel_opts .= '<OPTION VALUE="'.$n.'"';
+                                                       if( $inp == $n )
+                                                               $sel_opts .= ' SELECTED';
+                                                       if( !empty($an[1]) )
+                                                               {
+                                                               $sub = magic_form_display( $an[1], $mf_styles, null, $mf_def_data, $mf_level );
+                                                               if( $sub['success'] )
+                                                                       {
+                                                                       $v['sub_forms'] .= '<div id="'.$field_name.'_'.$n.'" style="display: '.($n==$inp?'block':'none').';"> '.str_replace( "{sub_form}", $f['sub_form'], $sub['text'] ).'</div>';
+                                                                       $sel .= "document.getElementById('".$field_name."_$n').style.display = document.getElementById('".$field_name."').value == '".$n."' ? 'block' : 'none'; ";
+                                                                       }
+                                                                 else
+                                                                       $v['sub_forms'] .= '<p><font color="red">FORM ERROR</font>: Unable to process sub-form for picklist: '.$mf['title'].'<p>';
+                                                               }
+                                                       $n++;
+                                                       $sel_opts .= '> '.$an[0];
+
+                                                               // Optionally set value if this is the "Yes" option
+
+                                                       if( $an[2] != '' )
+                                                               switch( $an[3] )
+                                                                       {
+                                                                       case 1:         $sel_opts .= " - ".money($an[2]);               break;
+                                                                       default:        $sel_opts .= " - ".$an[2];                              break;
+                                                                       }
+
+                                                       }
+                                               $v['input'] .= $sel.'">'.$sel_opts.'</SELECT>';
+                                               break;
+
+                                       case 6:         // Radio Buttons
+                                               $opts = explode( "|", $mf['data1'] );
+                                               $sel  = '';
+                                               $n = 1;
+                                               $sub_func = ' <script language="JavaScript1.2"> function f_'.$field_name.'(v){ ';
+                                               foreach( $opts as $opt )
+                                                       {
+                                                       $an = explode( "~", $opt );
+                                                       $sel .= '<NOBR><INPUT TYPE="radio" NAME="mf_'.$mf['id'].'" VALUE="'.$n.'"';
+                                                       if( $inp == $n )
+                                                               $sel .= ' CHECKED';
+                                                       $sel .= ' onClick="f_'.$field_name."('".$n."'); \"";
+                                                       if( !empty($an[1]) )
+                                                               {
+                                                               $sub_func .= " document.getElementById('".$field_name.'_'.$n."').style.display = v == '".$n."' ? 'block': 'none'; ";
+                                                               $sub = magic_form_display( $an[1], $mf_styles, null, $mf_def_data, $mf_level );
+                                                               if( $sub['success'] )
+                                                                       $v['sub_forms'] .= '<div id="'.$field_name.'_'.$n.'" style="display: '.($n==$inp?'block':'none').';"> '.str_replace( "{sub_form}", $f['sub_form'], $sub['text'] ).'</div>';
+                                                                 else
+                                                                       $v['sub_forms'] .= '<p><font color="red">FORM ERROR</font>: Unable to process sub-form for radio buttons: '.$mf['title'].'<p>';
+                                                               }
+                                                       $n++;
+                                                       $sel .= '>'.$an[0];
+
+                                                               // Optionally set value if this is the "Yes" option
+
+                                                       if( $an[2] != '' )
+                                                               switch( $an[3] )
+                                                                       {
+                                                                       case 1:         $sel .= " - ".money($an[2]);            break;
+                                                                       default:        $sel .= " - ".$an[2];                           break;
+                                                                       }
+
+                                                       $sel .= '</nobr>';
+
+                                                       }
+                                               $sub_func .= ' } </script>';
+                                               $v['input'] = $sub_func.$sel;
+                                               break;
+
+                                       case 7:         // File Upload
+                                               $inp = trim( str_replace( array( '|', '~' ), '', $inp ) );
+                                               $v['input'] = '<INPUT TYPE="hidden" NAME="exist_mf_'.$mf['id'].'" value="'.$inp.'">
+                                                                               <table border="1">
+                                                                         ';
+                                               if( $inp != '' )
+                                                       $v['input'] .= '<tr><td><a href="'.SI_BASE_FILE_URL.'/'.$inp.'" target="file_page">'.$inp.'</a></td><td><input type="checkbox" name="delete_mf_'.$mf['id'].'"> Delete</td></tr>
+                                                                                       ';
+                                               $v['input'] .= '<tr><td colspan="2"><INPUT TYPE="file" NAME="mf_'.$mf['id'].'" VALUE="'.$inp.'" SIZE="'.$mf['cols'].'"></td></tr>
+                                                                               </table>';
+                                               break;
+
+                                       case 20:        // Section Title
+                                               $v['title'] = stripslashes($mf['data1']);
+                                               $v['input'] = '';
+                                               break;
+
+                                       case 21:        // Misc. Text
+                                               $v['title'] = '';
+                                               $v['input'] = stripslashes($mf['data1']);
+                                               break;
+
+                                       case 24:        // Image
+                                       switch( $mf['size'] )
+                                               {
+                                               case 'original':        $image_size_url = SI_IMG_ORIGINAL_URL;  break;
+                                               case 'resized':         $image_size_url = SI_IMG_RESIZED_URL;   break;
+                                               case 'midsized':        $image_size_url = SI_IMG_MIDSIZED_URL;  break;
+                                               default:
+                                               case 'thumb':           $image_size_url = SI_IMG_THUMB_URL;             break;
+                                               }
+
+                                               $v['image'] = '<u><img src="'.$image_size_url.'/'.$mf['file'].'"></u>';
+                                               break;
+
+                                       case 25:        // File
+                                               $v['title'] = '<a href="'.SI_BASE_FILE_URL.'/'.$mf['file'].'" target="file_page">'.(trim($mf['title'])!=''?$mf['title']:$mf['file']).'</a>';
+                                               break;
+
+                                       case 22:        // Horizontal Line
+                                       case 23:        // Blank Line (space)
+                                       default:
+                                               $v['title'] = '';
+                                               $v['input'] = '';
+                                               break;
+
+                                       }       // Type
+
+                               $r['text'] .= parse_string_view( $f['body'], $view_tags );
+
+                               }       // Active
+                       }       // Each field
+
+                       // If not at the last column, fill with blank cells before closing
+               if( $current_column < $mf_styles[$current_style]['cols'] )
+                       for( $i=$current_column ; $i<=$mf_styles[$current_style]['cols'] ; $i++ )
+                               $r['text'] .= $mf_styles[$current_style]['col_empty'];
+               $r['text'] .= $mf_styles[$current_style]['row_end'].$mf_styles[$current_style]['end'];
+               }
+
+       if( !empty($problem) )
+               echo "Problems processing this form.<p>$problem<p>";
+
+       return( $r );
+
+       }
+
+       // MagicForm - Submit Form
+
+function magic_form_submit( $mf_id, $mf_fiid = null, $mf_def_data = null, $mf_level = 0 )
+       {
+
+       global $mf_formats;
+
+       $mf_level++;            // Incriment MagicForm recurse level (not shure why we're doing this though)
+
+               // Get form field specifications
+
+       $mf_fields = db_auto_get_data( "SELECT * FROM ".MF_TABLE." WHERE form_id = '$mf_id' ORDER BY sort;", SI_CONN_STR, FALSE );
+
+               // Initialize result array
+
+       $mf_results = array( 'success' => true, 'data' => array(), 'total_value' => 0, 'html' => '', 'csv' => ($mf_level==1?'"ID","Sub Form Level","Title","Type","Data","Value","Valid","Required","Notes"'."\n":''), 'problem' => '' );
+
+       $problem = '';
+       $current_collumn = 1;
+
+       $mf_total_value = 0;            // Accumulates a total of the optional value data for checkboxes, picklists, and radio buttons
+
+       if( is_array($mf_fields) )
+               {
+
+               reset( $mf_fields );
+               foreach( $mf_fields as $mf )
+                       {
+
+                               // If it's a supplied data field and it's active
+
+                       if( $mf['type'] < 20 && $mf['active'] == 't' )
+                               {
+
+                                       // Determine Field ID
+
+                               $mf_field_id = ( $mf['custom_id'] != '' ? $mf['custom_id'] : 'mf_'.$mf['id'] );
+
+                                       // If we didn't get previously submitted data
+
+                               if( $mf_def_data == null )
+                                       $inp = stripslashes(trim($GLOBALS['mf_'.$mf['id']]));           // Get form input value
+                                 else
+                                       $inp = $mf_def_data[$mf_field_id];                      // Get value from supplied array
+
+                               $res = array
+                                       (
+                                       'id'            => $mf_field_id,
+                                       'level'         => $mf_level,
+                                       'title'         => $mf['title'],
+                                       'type'          => $mf['type'],
+                                       'txt_typ'       => '',
+                                       'value'         => '',
+                                       'txt_val'       => '',
+                                       'opt_num'       => '',
+                                       'valid'         => true,
+                                       'required'      => false,
+                                       'numb_val'      => '',
+                                       'failure'       => ''
+                                       );
+
+                                       // Set text for field type
+
+                               switch( $mf['type'] )
+                                       {
+                                       case 1:         $res['txt_typ'] = 'Checkbox';           break;
+                                       case 2:         $res['txt_typ'] = 'Number';                     break;
+                                       case 3:         $res['txt_typ'] = 'Text';                       break;
+                                       case 4:         $res['txt_typ'] = 'Text Box';           break;
+                                       case 5:         $res['txt_typ'] = 'Pick List';          break;
+                                       case 6:         $res['txt_typ'] = 'Radio Buttons';      break;
+                                       case 7:         $res['txt_typ'] = 'File Upload';        break;
+                                       default:                                                                                break;
+                                       }
+
+                               $sub = '';                                                                                                                                      // Assume no sub-form
+
+                               // *** SHOULD PROBABLY CHECK DATA INPUT INTEGRITY HERE
+
+                                       // Check if a required field is not populated
+
+                               if( $mf['type'] > 1 && $mf['type'] < 20 && $mf['required'] == 't' )
+                                       {
+                                       $res['required'] = true;
+                                       if( $inp == '' || ($mf_type['type']==7 && $inp=='none') )       // if field is required and not provided
+                                               {
+                                               $res['valid'] = false;
+                                               $res['failure'] = 'Required response not provided.';
+                                               $mf_results['problem'] .= '<li>"'.$mf['title'].'" requires a response that was not provided.</li>'."\n";
+                                               }
+                                       }
+
+                               switch( $mf['type'] )
+                                       {
+
+                                       case 1:         // Checkbox
+
+                                               $ans = explode( "|", $mf['data1'] );                                    // Separate possible answers
+
+                                               $sub_id = '';
+
+                                               if( $inp == 'on' )
+                                                       {
+                                                       $res['value'] = 't';
+                                                       $res['txt_val'] = 'Yes';
+                                                       $res['opt_num'] = '1';
+                                                       $an = explode( '~', $ans[0] );
+                                                       $sub_id = $an[1];
+                                                       if( $an[2] != '' )
+                                                               $res['numb_val'] = $an[2];
+
+                                                       }
+                                                 else
+                                                       {
+                                                       $res['value'] = 'f';
+                                                       $res['txt_val'] = 'No';
+                                                       $res['opt_num'] = '2';
+                                                       $an = explode( '~', $ans[1] );
+                                                       $sub_id = $an[1];
+                                                       if( $an[2] != '' )
+                                                               $res['numb_val'] = $an[2];
+                                                       }
+
+                                               if( $sub_id != '' )
+                                                       {
+                                                       $sub = magic_form_submit( $sub_id, $mf_fiid, $mf_def_data, $mf_level );
+                                                       if( !$sub['success'] )
+                                                               $mf_results['problem'] .= $sub['problem'];
+                                                         else
+                                                               $mf_total_value += $sub['total_value'];
+                                                       }
+
+                                               break;
+
+                                       case 2:         // Number
+
+                                               $inp = ereg_replace( "[\$,]", "", $inp );
+
+                                       case 3:         // Text
+                                       case 4:         // Text Box
+
+                                                       // Extract field format specs
+
+                                               $mf_cf = explode( '~', $mf['format'] );
+                                               $mf_cf_size = $mf_cf[1] + ($mf_cf[2]>0?1:0) + $mf_cf[2];
+                                               $mf_cf_out = str_replace( '{chars}', $mf_cf[1], $mf_formats[$mf_cf[0]]['format'] );
+                                               $mf_cf_out = str_replace( '{prec}', $mf_cf[2], $mf_cf_out );
+
+                                               if( trim($inp) != '' )
+                                                       {
+                                                       if( $mf_cf[3] != '' && $inp < $mf_cf[3] )
+                                                               {
+                                                               $res['valid'] = false;
+                                                               $res['failure'] .= 'Value not in range';
+                                                               $mf_results['problem'] .= '<li>"'.$mf['title'].'" requires a value greater than or equal to '.$mf_cf[3].'.</li>'."\n";
+                                                               }
+
+                                                       if( $mf_cf[4] != '' && $inp > $mf_cf[4] )
+                                                               {
+                                                               $res['valid'] = false;
+                                                               $res['failure'] .= 'Value not in range';
+                                                               $mf_results['problem'] .= '<li>"'.$mf['title'].'" requires a value less than or equal to '.$mf_cf[4].'.</li>'."\n";
+                                                               }
+
+                                                       if( $mf_formats[$mf_cf[0]]['regex'] != '' && preg_match( '/^'.$mf_formats[$mf_cf[0]]['regex'].'$/', $inp ) == 0 )
+                                                               {
+                                                               $res['valid'] = false;
+                                                               $res['failure'] .= 'Input format not valid';
+                                                               $mf_results['problem'] .= '<li>"Value supplied to '.$mf['title'].'" was not valid. Must be '.$mf_cf['0'].' (i.e. '.$mf_formats[$mf_cf[0]]['sample'].').</li>'."\n";
+                                                               }
+                                                       }
+
+                                               $res['value'] = ( $mf_cf_out != '' ? sprintf( $mf_cf_out, $inp ) : $inp );
+
+                                               break;
+
+                                       case 5:         // Picklist
+
+                                               $res['opt_num'] = $inp;
+                                               $opts = explode( "|", $mf['data1'] );           // Separate Options
+                                               if( $inp != '' )                                                        // If an options is selected
+                                                       {
+                                                       $x = explode( "~", $opts[$inp-1] );             // Separate data for selected option
+                                                       $res['value'] = $x[0];                                  // Use option name
+                                                       if( $x[2] != '' )
+                                                               $res['numb_val'] = $x[2];
+                                                       }
+                                                 else
+                                                       $res['value'] = '';
+
+                                                       // Check selected option for Sub-Form
+
+                                               $n = 1;
+                                               foreach( $opts as $opt )
+                                                       {
+                                                       $an = explode( "~", $opt );
+                                                       if( $inp == $n && !empty($an[1]) )
+                                                               {
+                                                               $sub = magic_form_submit( $an[1], $mf_fiid, $mf_def_data, $mf_level );
+
+                                                               if( !$sub['success'] )
+                                                                   $mf_results['problem'] .= $sub['problem'];
+                                                                 else
+                                                                       $mf_total_value += $sub['total_value'];
+                                                               }
+                                                       $n++;
+                                                       }
+
+                                               break;
+
+                                       case 6:         // Radio Buttons
+
+                                               $res['opt_num'] = $inp;
+                                               $opts = explode( "|", $mf['data1'] );           // Separate Options
+                                               if( $inp != '' )                                                        // If an options is selected
+                                                       {
+                                                       $x = explode( "~", $opts[$inp-1] );             // Separate data for selected option
+                                                       $res['value'] = $x[0];                                  // Use option name
+                                                       if( $x[2] != '' )
+                                                               $res['numb_val'] = $x[2];
+
+                                                       }
+                                                 else
+                                                       $res['value'] = '';
+
+                                               $opts = explode( "|", $mf['data1'] );
+
+                                                       // Check selected button for Sub-Form
+
+                                               $n = 1;
+                                               foreach( $opts as $opt )
+                                                       {
+                                                       $an = explode( "~", $opt );
+                                                       if( $inp == $n && !empty($an[1]) )
+                                                               {
+                                                               $sub = magic_form_submit( $an[1], $mf_fiid, $mf_def_data, $mf_level );
+
+                                                               if( !$sub['success'] )
+                                                                   $mf_results['problem'] .= $sub['problem'];
+                                                                 else
+                                                                       $mf_total_value += $sub['total_value'];
+                                                               }
+                                                       $n++;
+                                                       }
+
+                                               break;
+
+                                       case 7:         // File Upload
+
+                                                       // Note that $inp is the /temp file name for the uploaded file
+
+                                               $existing_filename = trim($GLOBALS['exist_mf_'.$mf['id']]);
+                                               $new_filename = trim($GLOBALS['mf_'.$mf['id'].'_name']);
+                            // force input to be the supplied temp file
+                        $inp = stripslashes(trim($_FILES['mf_'.$mf['id']]['tmp_name']));
+
+                            // If there's an existing file AND delete is requested or there's a new file names coming in
+                        $existing_filename = stripslashes($GLOBALS['exist_mf_'.$mf['id']]);
+                        $new_filename = trim(stripslashes($GLOBALS['mf_'.$mf['id'].'_name']));
+                        if( $existing_filename != '' && ( $GLOBALS['delete_mf_'.$mf['id']] == 'on' || $new_filename != '' ) )
+                                                       {
+                                                       file_delete( $existing_filename );
+                                                       $existing_filename ='';
+                                                       }
+
+                                       if( $new_filename != '' )
+                                           {
+                                                       if( !($new_filename = file_upload( $inp, $new_filename )) )
+                                                                       {
+                                                                       $mf_results['problem'] .= '<li>Unable to upload file for "'.$mf['title'].'".</li>'."\n";
+                                                                       $new_filename = '';
+                                                                       }
+                                                       }
+                                                 else
+                                                       $new_filename = $existing_filename;
+
+                                                       // Need to handle required separately for type file
+                        if( $mf['type'] > 1 && $mf['type'] < 20 && $mf['required'] == 't' )
+                            {
+                            if( $new_filename == '' )   // if field is required and not provided
+                                {
+                                $res['valid'] = false;
+                                $res['failure'] = 'Required response not provided.';
+                                $mf_results['problem'] .= '<li>"'.$mf['title'].'" requires a response that was not provided.</li>'."\n";
+                                }
+                            }
+
+                                               $res['value'] = $new_filename;
+                                               $res['txt_val'] = '<a href="'.SI_BASE_FILE_URL.'/'.$new_filename.'" target="file_page">'.$new_filename.'</a>';
+
+
+                                               break;
+
+                                       default:
+                                               break;
+
+                                       }       // Type
+
+                                       // Push the current result and any sub-form results onto the end of the result array.
+
+                               $mf_results['data'][$mf['id']] = $res;
+                               $mf_results['csv'] .= '"'.$res['id'].'","'.$res['level'].'","'.$res['title'].'","'.$res['txt_typ'].'","'.$res['value'].'","'.$res['numb_val'].'","'.($res['valid']?'t':'f').'","'.($res['required']?'t':'f').'","'.$res['failure'].'"'."\n";
+                               $x = ''; for( $i=0 ; $i<$mf_level ; $i++ ) $x .= '&nbsp;&nbsp;';
+                               $mf_results['html'] .= '<tr><td align="left">'.$res['id'].'</td><td align="left">'.$x.$res['title'].'&nbsp;</td><td align="left">'.$res['txt_typ'].'&nbsp;</td><td align="left">'.( $res['txt_val'] != '' ? $res['txt_val'] : $res['value'] ).'&nbsp;</td><td align="left">'.$res['numb_val'].'&nbsp;</td><td align="left">'.($res['valid']?'Yes':'No').'</td><td align="left">'.($res['required']?'Yes':'No').'</td><td align="left">'.$res['failure'].'&nbsp;</td></tr>'."\n";
+
+                                       // If there's a sub-form
+
+                               if( is_array($sub) )
+                                       {
+
+                                               // Add data from sub-form
+
+                                       $mf_results['html'] .= $sub['html'];
+                                       $mf_results['csv'] .= $sub['csv'];
+                                       while( list($key, $val) = each($sub['data']) )
+                                               $mf_results['data'][$key] = $val;
+                                       }
+
+                               }       // Active
+
+                       }       // Each field
+
+               }
+
+       if( $mf_level == 1 )
+               $mf_results['html'] = '<table border="1" cellpadding="2" cellspacing="0"><tr><th align="left">Field ID</th><th align="left">Title</th><th align="left">Type</th><th align="left">Data</th><th align="left">Value</th><th align="left">Data Valid</th><th align="left">Required</th><th align="left">Failure</th></tr>'."\n".$mf_results['html']."</table>\n";
+
+       if( $mf_results['problem'] != '' )
+               $mf_results['success'] = false;
+
+       $mf_results['total_value'] = $mf_total_value;
+       return( $mf_results );
+
+       }
+
+       // MagicForm - Store Data
+
+function magic_form_store_data( $mf_id, $mf_fiid, $mf_def_data )
+       {
+
+               // Delete previous entries using the supplied form instance id ($mf_fiid)
+
+       $qs = "BEGIN;\nDELETE FROM ".MF_DATA_TABLE." WHERE fiid = $mf_fiid;\n";
+
+               // Store new data
+
+       foreach( $mf_def_data as $mf )
+               {
+               $qs .= "INSERT INTO ".MF_DATA_TABLE." ( fiid, form_id, field_id, level, title, type, txt_type, value, numb_value, txt_value, opt_num, valid, required, failure )
+                                               VALUES ( $mf_fiid, $mf_id, '".addslashes($mf['id'])."', ".(empty($mf['level'])?'NULL':$mf['level']).", '".addslashes($mf['title'])."',
+                                                               ".(empty($mf['type'])?'NULL':$mf['type']).", '".addslashes($mf['txt_type'])."', '".addslashes($mf['value'])."',
+                                                               ".($mf['numb_val']!=''?$mf['numb_val']:'NULL').", '".addslashes($mf['txt_value'])."', ".($mf['opt_num']>0?$mf['opt_num']:'NULL').",
+                                                               '".($mf['valid']?'t':'f')."', '".($mf['required']?'t':'f')."', '".addslashes($mf['failure'])."' );\n";
+               }
+       $qs .= "COMMIT;\n";
+
+       if( !db_auto_exec($qs) )
+               return( false );
+         else
+               return( true );
+
+       }
+
+
+/***********************************************************************
+*                                                                      *
+*      Support funtions for High Level Admin Functions                 *
+*                                                                             *
+***********************************************************************/
+
+
+       // Explode a string into pieces and trims whitespace from ends of each piece.
+
+function explode_trim( $separator, $string )
+{
+
+       $a = explode( $separator, $string );
+
+       foreach( $a as $key => $data )
+               $a[$key] = trim($data);
+
+       return( $a );
+
+}
+
+
+/***********************************************************************
+*                                                                      *
+*                   High Level Admin Functions                         *
+*                                                                             *
+***********************************************************************/
+
+       // The "JFDI" function - Fully process a data table
+
+function admin_process_records_r( $table, $where, $order, $conn_str, $id, $fields,
+       $options, $rows, $url, $action, $params, $a_title, $view, $Option, $start, $other_options = '', $a_title_view = '', $quick_tip = '', $id_field = '' )
+{
+
+       $a_title_view = ereg_replace( "\\{action\\}", $Option, $a_title_view );
+
+       switch( $Option )
+               {
+
+               case "Add":
+
+                       return( admin_new_record_r
+                                       (
+                                       $table,
+                                       $conn_str,
+                                       admin_field_select( $fields, 'n' ),
+                                       $url,
+                                       $action,
+                                       $params,
+                                       (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">New $a_title</SPAN><P>":$a_title_view),
+                                       $view['Add'],
+                                       $other_options,
+                                       $quick_tip
+                                       )
+                               );
+
+                       break;
+
+               case "Add New":
+
+                       $r = admin_add_new_record_r
+                               (
+                               $table,
+                               $conn_str,
+                               admin_field_select( $fields, 'a' ),
+                               $url,
+                               $action,
+                               $params,
+                               (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">Add New $a_title</SPAN><P>":$a_title_view),
+                               $view['Add New'],
+                               $quick_tip
+                               );
+
+                               // If successfull see if we can get the new record ID and view it
+/* Don't do this right now...
+ *
+                       if( $r['status'] )
+                               {
+                                       // On success Add New returns the OID of the new record - get ID for next call
+
+                               if( ($d = db_auto_get_row( "SELECT id FROM $table WHERE oid = ".$r['status'].";" )) )
+                                       $id = $d['id'];
+                                 else
+                                       return( $r );           // If we can't get ID then just give up and return
+
+                                       // If all is OK, then call again to do a View
+
+                               $r = admin_process_records_r( $table, $where, $order, $conn_str, $id, $fields, $options, $rows, $url, $action, $params, $a_title, $view, 'View', $start, $other_options, $a_title_view, $quick_tip );
+                               }
+*/
+
+                       return( $r );
+
+                       break;
+
+               case "Edit":
+
+                       return( admin_edit_record_r
+                                       (
+                                       $table,
+                                       $conn_str,
+                                       $id,
+                                       admin_field_select( $fields, 'e' ),
+                                       $url,
+                                       $action,
+                                       $params,
+                                       (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">Edit $a_title</SPAN><P>":$a_title_view),
+                                       $view['Edit'],
+                                       $other_options,
+                                       $quick_tip
+                                       )
+                               );
+
+                       break;
+
+               case "Update":
+
+                       $r = admin_update_record_r
+                               (
+                               $table,
+                               $conn_str,
+                               $id,
+                               admin_field_select( $fields, 'u' ),
+                               $url,
+                               $action,
+                               $params,
+                               (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">Update $a_title</SPAN><P>":$a_title_view),
+                               $view['Update'],
+                               $quick_tip
+                               );
+
+                               // If successful update then call again to do a View of the updated record
+
+                       if( $r['status'] )
+                               return( admin_process_records_r( $table, $where, $order, $conn_str, $id, $fields, $options, $rows, $url, $action, $params, $a_title, $view, 'View', $start, $other_options, $a_title_view, $quick_tip ) );
+
+                       return( $r );
+
+                       break;
+
+               case "Delete":
+
+                       return( admin_delete_record_r
+                                       (
+                                       $table,
+                                       $conn_str,
+                                       $id,
+                                       admin_field_select( $fields, 'd' ),
+                                       $options,
+                                       $url,
+                                       $action,
+                                       $params,
+                                       (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">Delete $a_title</SPAN><P>":$a_title_view),
+                                       $view['Delete'],
+                                       $quick_tip
+                                       )
+                               );
+
+                       break;
+
+               case "Confirm Delete":
+
+                       $r = admin_confirm_delete_record_r
+                               (
+                               $table,
+                               $conn_str,
+                               $id,
+                               admin_field_select( $fields, 'c' ),
+                               $url,
+                               $action,
+                               $params,
+                               (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">Confirm Delete $a_title</SPAN><P>":$a_title_view),
+                               $view['Confirm Delete'],
+                               $quick_tip
+                               );
+
+                               // If successful delete then call again to do a List
+
+                       if( $r['status'] )
+                               return( admin_process_records_r( $table, $where, $order, $conn_str, $id, $fields, $options, $rows, $url, $action, $params, $a_title, $view, 'List', $start, $other_options, $a_title_view, $quick_tip ) );
+
+                       return( $r );
+
+                       break;
+
+               case "View":
+
+                       return( admin_view_record_r
+                                       (
+                                       $table,
+                                       $conn_str,
+                                       $id,
+                                       admin_field_select( $fields, 'v' ),
+                                       $url,
+                                       $action,
+                                       $params,
+                                       (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">View $a_title</SPAN><P>":$a_title_view),
+                                       $view['View'],
+                                       $other_options,
+                                       $quick_tip,
+                                       $id_field
+                                       )
+                               );
+
+                       break;
+
+               default:
+
+                       return( admin_list_records_r
+                                       (
+                                       $table,
+                                       $where,
+                                       $order,
+                                       $conn_str,
+                                       admin_field_select( $fields, 'l' ),
+                                       $options,
+                                       FALSE,
+                                       $rows,
+                                       $start,
+                                       $url,
+                                       $action,
+                                       $params,
+                                       admin_field_select( $fields, 'f' ),
+                                       (empty($a_title_view)?"<P><SPAN CLASS=\"title1\">List $a_title</SPAN><P>":$a_title_view),
+                                       $view['List'],
+                                       $id_field,
+                                       $quick_tip
+                                       )
+                               );
+
+                       break;
+
+               } // switch( $Option )
+
+}
+
+function admin_process_records( $table, $where, $order, $conn_str, $id, $fields,
+       $options, $rows, $url, $action, $params, $a_title, $view, $Option, $start, $other_options = '', $a_title_view = '', $quick_tip = '' )
+{
+       $r = admin_process_records_r( $table, $where, $order, $conn_str, $id, $fields,
+                               $options, $rows, $url, $action, $params, $a_title, $view, $Option, $start, $other_options, $a_title_view, $quick_tip );
+       echo $r['text'];
+       return( $r['status'] );
+}
+
+
+       // List records from a table
+
+function admin_list_records_r( $table, $where, $order, $conn_str, $fields,
+                               $options, $fail_mode, $rows = 20, $start = 0,
+                               $url, $action, $params, $filters, $a_title, $view = "", $id_field = "", $quick_tip = '' )
+{
+
+       $ret = '';
+
+               // Make all submitted parameters available
+
+//     extract($GLOBALS[HTTP_GET_VARS]);
+//     extract($GLOBALS[HTTP_POST_VARS]);
+
+               // Make sure we have something rational for rows and start
+
+       if( $rows == '' ) $rows = 20;
+       if( $start == '' ) $start = 0;
+
+               // Break out configuration data
+
+       $field_table = explode_trim( "|", $fields );
+
+               // Don't be surprised if last field is blank
+
+       if( trim($field_table[count($field_table)-1]) == "" )
+               array_pop( $field_table );
+
+       foreach( $field_table as $key => $r )
+               {
+               $field_table[$key] = explode_trim( ",", $r );
+               $hidden[$key] = preg_match( "/HIDDEN/", $field_table[$key][3] );
+               }
+
+       $operation_column = $option_new = $option_view = $option_edit = $option_delete = $option_duplicate = $option_filter = $option_nopaging = $option_noborder = FALSE;
+
+       if( ! empty($options) )
+               {
+               $option_table = explode_trim( ",", $options );
+               foreach( $option_table as $option )
+                       {
+                       switch( $option )
+                               {
+                               case "new":
+                                       $option_new = TRUE;
+                                       break;
+
+                               case "view":
+                                       $option_view = TRUE;
+                                       $operation_column = TRUE;
+                                       break;
+
+                               case "edit":
+                                       $option_edit = TRUE;
+                                       $operation_column = TRUE;
+                                       break;
+
+                               case "delete":
+                                       $option_delete = TRUE;
+                                       $operation_column = TRUE;
+                                       break;
+
+                               case "duplicate":
+                                       $option_duplicate = TRUE;
+                                       $operation_column = TRUE;
+                                       break;
+
+                               case "filter":
+                                       $option_filter = TRUE;
+                                       break;
+
+                               case "sortlinks":
+                                       $option_sortlinks = TRUE;
+                                       break;
+
+                               case "nopaging":
+                                       $option_nopaging = TRUE;
+                                       break;
+
+                               case "noborder":
+                                       $option_noborder = TRUE;
+                                       break;
+
+                               default:
+//                                     $ret .=  '<H2><FONT COLOR="red">ERROR: Illegal Option Specified: -'.$option.'-</FONT></H2>';
+                                       break;
+                               }
+                       }
+               }
+
+               // Check for additional parameters that are passed
+
+       $link_params = $form_params = "";
+       if( !empty($params) )
+               {
+               $param = explode_trim( "|", $params );  // Separate parameters
+               foreach( $param as $p )
+                       {
+                       $x = explode_trim( ".", $p );   // Separate Names from Values
+                       $link_params .= "&".$x[0]."=".urlencode($x[1]);
+                       $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+                       }
+               }
+
+               // Check if a column lable has been clicked to cause a sort of that column
+
+       if( !empty($GLOBALS['sortclicked_new']) )
+               {
+
+                       // Clicking the same column title toggles between ascending and descending sort
+
+               if( $GLOBALS['list_sort_direction'] == 'Forward'  )
+                       $list_sort_direction = "Backward";
+                 else
+                       $list_sort_direction = 'Forward';
+
+               $sortclicked = $GLOBALS['sortclicked_new'];
+               $link_params .= '&sortclicked='.$sortclicked."&list_sort_direction=$list_sort_direction";
+               $form_params .= '<INPUT TYPE="hidden" NAME="sortclicked" VALUE="'.$sortclicked.'">';
+               $form_params .= '<INPUT TYPE="hidden" NAME="list_sort_direction" VALUE="'.$list_sort_direction.'">';
+               }
+         elseif( !empty($GLOBALS['sortclicked']) )
+               {
+               $sortclicked = $GLOBALS['sortclicked'];
+               $list_sort_direction = $GLOBALS['list_sort_direction'];
+               $link_params .= '&sortclicked='.$sortclicked."&list_sort_direction=$list_sort_direction";
+               $form_params .= '<INPUT TYPE="hidden" NAME="sortclicked" VALUE="'.$sortclicked.'">';
+               $form_params .= '<INPUT TYPE="hidden" NAME="list_sort_direction" VALUE="'.$list_sort_direction.'">';
+               }
+
+               // Display optional filter search fields and build query string
+
+       $qs = empty($where) ? "WHERE TRUE " : "WHERE ".$where ;
+
+       if( $option_filter )
+               {
+               $filter_out = '
+                       <FORM ACTION="'.$url.'">
+                               <INPUT TYPE="hidden" NAME="Option" VALUE="List">
+                               <B>Select items to list</B><BR>
+                               <TABLE BORDER="0">
+                    ';
+
+               $filter_link = "";                                      // Added to link to pass on filter data
+               $filter = explode_trim( "|", $filters );
+               foreach( $filter as $filter_field )
+                       {
+                       $f = explode_trim( ",", $filter_field );        // Split field specs
+                       $ft = explode_trim( "~", $f[2] );                       // Separate QuickTips from titles
+                       $w = explode_trim( "`", $f[1] );                        // Separate out any format spec
+                       $x = explode_trim( ".", $w[0] );                        // Split type specs
+                       $option = $x[1]!="" ? $x[1] : "none" ;
+                       $filter_value = $GLOBALS[$f[3]];
+
+                               // Display Filter Title - With QuickTip if specified
+
+                       if( count($ft) > 1 )
+                               $filter_out .= '<TR><TH ALIGN="right" VALIGN="top">'.quick_tip( $ft[0], $ft[1] ).'</TH><TD ALIGN="left">';
+                         else
+                               $filter_out .= '<TR><TH ALIGN="right" VALIGN="top">'.$ft[0].'</TH><TD ALIGN="left">';
+
+                               // Add any filter value to $filter_link
+
+                       if( !empty($filter_value) )
+                               {
+                               if( is_array($filter_value) )
+                                       {
+                                       $fvc = 0;
+                                       foreach( $filter_value as $fv )
+                                               if( trim($fv) != '' )
+                                                       {
+                                                       $filter_link .= "&".$f[0]."[$fvc]=".$fv;
+                                                       $fvc++;
+                                                       }
+                                       }
+                                 else
+                                       $filter_link .= "&".$f[0]."=".$filter_value;
+                               }
+
+                               // Display filter field
+
+                       switch( $x[0] )                         // Handle different field types
+                               {
+                               case "url":
+                               case "text":
+                               case "textbox":
+                               case "inet":
+                                       $filter_out .= '<INPUT TYPE="text" NAME="'.$f[0].'" VALUE="'.$filter_value.'">';
+                                       if( !empty($filter_value) )             // If a value is passed, add to query
+                                               switch( $option )
+                                                       {
+                                                       case "like":
+                                                               $qs .= " AND ".$f[0]." LIKE '%".$filter_value."%'";
+                                                               break;
+                                                       case "begin":
+                                                               $qs .= " AND ".$f[0]." ~* '^".$filter_value."'";
+                                                               break;
+                                                       case "any":
+                                                       default:
+                                                               $qs .= " AND ".$f[0]." ~* '".$filter_value."'";
+                                                               break;
+                                                       }
+                                       break;
+
+                               case "state":
+                                       $filter_out .= build_a_picklist( $f[0], $GLOBALS['si_states_array'], $filter_value, 'standard', 'blank' );
+                                       if( $filter_value != '' )
+                                               $qs .= ' AND '.$f[0]." = '".$filter_value."'";
+                                       break;
+
+                               case "country":
+                                       $filter_out .= build_a_picklist( $f[0], $GLOBALS['si_countries_array'], $filter_value, 'standard', 'blank' );
+                                       if( $filter_value != '' )
+                                               $qs .= ' AND '.$f[0]." = '".$filter_value."'";
+                                       break;
+
+                               case "date":
+                                       $filter_out .= '<INPUT TYPE="text" NAME="'.$f[0].'" VALUE="'.$filter_value.'">';
+                                       if( !empty($filter_value) )             // If a value is passed, add to query
+                                               switch( $option )
+                                                       {
+                                                       default:                // Options are not used for date at this time
+                                                               $qs .= " AND ".$f[0]." = '".$filter_value."'";
+                                                               break;
+                                                       }
+                                       break;
+
+                               case "daterange":
+                                               // Clean up dates
+                                       if( trim($GLOBALS[$f[3].'_FROM'] ) != '' )      $GLOBALS[$f[3].'_FROM'] = date( 'n/j/Y', strtotime($GLOBALS[$f[3].'_FROM']) );
+                                       if( trim($GLOBALS[$f[3].'_TO'] ) != '' )        $GLOBALS[$f[3].'_TO'] = date( 'n/j/Y', strtotime($GLOBALS[$f[3].'_TO']) );
+                                       $filter_out .= 'From <INPUT TYPE="text" NAME="'.$f[0].'_FROM" VALUE="'.$GLOBALS[$f[3].'_FROM'].'"> To <INPUT TYPE="text" NAME="'.$f[0].'_TO" VALUE="'.$GLOBALS[$f[3].'_TO'].'">';
+                                               // If Dates are not valid
+                                       if( ( trim($GLOBALS[$f[3].'_FROM']) != '' && strtotime($GLOBALS[$f[3].'_FROM']) === -1 ) ||
+                                               ( trim($GLOBALS[$f[3].'_TO']) != '' && strtotime($GLOBALS[$f[3].'_TO']) === -1 ) )
+                                               {
+                                               $filter_out .= '<BR>(<FONT COLOR="red">Note:</FONT> Invalid date specified)';
+                                               break;
+                                               }
+                                         else
+                                               {
+                                                       // If we have both dates of a range
+                                               if( !empty($GLOBALS[$f[3].'_FROM']) && !empty($GLOBALS[$f[3].'_TO']) )          // If a value is passed, add to query
+                                                       switch( $option )
+                                                               {
+                                                               default:                // Options are not used for date at this time
+                                                                       $qs .= " AND ".$f[0]." BETWEEN '".$GLOBALS[$f[3].'_FROM']."' AND '".$GLOBALS[$f[3].'_TO']."'";
+                                                                       break;
+                                                               }
+                                                 else  // Otherwise check if there's only one date submitted
+                                                       if( !empty($GLOBALS[$f[3].'_FROM']) || !empty($GLOBALS[$f[3].'_TO']) )
+                                                               $filter_out .= '<BR>(<FONT COLOR="red">Note:</FONT> both From and To required to specify date range)';
+                                               }
+                                       break;
+
+                               case "order":
+                               case "int":
+                               case "float":
+                               case "fixed":
+                                       $filter_out .= '<INPUT TYPE="text" NAME="'.$f[0].'" VALUE="'.$filter_value.'">
+                                            ';
+                                       if( !empty($filter_value) )     // Note: No filter options on type "int"
+                                               $qs .= " AND ".$f[0]." = ".$filter_value."";
+                                       break;
+
+                               case "checkbox":
+                                       if( empty($filter_value) )
+                                               $x = 1;
+                                         else
+                                               $x = $filter_value;
+                                       $filter_out .= '
+                                                       <SELECT NAME="'.$f[0].'">
+                                                               <OPTION VALUE="1" '.($x==1?"SELECTED":"").'>Don\'t care
+                                                               <OPTION VALUE="2" '.($x==2?"SELECTED":"").'>Yes
+                                                               <OPTION VALUE="3" '.($x==3?"SELECTED":"").'>No
+                                                       </SELECT>
+                                                       ';
+                                       switch( $x )
+                                               {
+                                               case "2":
+                                                       $qs .= " AND ".$f[0]." = 't'";
+                                                       break;
+                                               case "3":
+                                               $qs .= " AND ".$f[0]." = 'f'";
+                                               break;
+                                           case "1":
+                                           default:
+                                               break;
+                                               }
+                                       break;
+
+                               case "list" :
+
+                                               // If picklist options
+                                       $opts_table = array ();
+                                       $opts = explode_trim("~", $x[1]); // Separate list options
+                                       foreach ($opts as $opt)
+                                               {
+                                               $z = explode_trim("^", $opt); // Separate value from displayed text
+                                               $opts_table[$z[0]] = $z[1];
+                                               }
+                                       $opts_def = $GLOBALS[$f[3]] == '' ? '-1' : $GLOBALS[$f[3]];
+                                       $filter_out .= build_a_picklist($f[0], $opts_table, $opts_def, 'standard', $x[3].($x[3]!=''?'~':'')."blank");
+
+                                               // If there's any list options selected
+                                       if( is_array($GLOBALS[$f[3]]) )
+                                               {
+                                               $qss .= ' AND ( ';
+                                               $sep = '';
+                                               foreach( $GLOBALS[$f[3]] as $v )                // For each option specified
+                                                       {
+                                                       if( trim($v) != '' )                            // If the option is something other than ''
+                                                               {
+                                                               $qss .= $sep.$f[0]." = ".$v."";
+                                                               $sep = ' OR ';
+                                                               }
+                                                       }
+                                               if( $sep != '' )                                                // If there were options selected other than ''
+                                                       $qs .= $qss.' )';                                       // add to the query
+                                               }
+                                         else
+                                               {
+                                               if( $GLOBALS[$f[3]] != '' )
+                                                       $qs .= ' AND '.$f[3].' = '.$GLOBALS[$f[3]];
+                                               }
+
+                                       break;
+
+
+                               case "category":
+
+                                               // If picklist is selected - use that for selection
+
+                                       if( strstr($x[3],'picklist') )
+                                               {
+                                               if( ($nodes = cat_get_nodes($x[1])) )
+                                                       {
+                                                       $filter_out .= '<SELECT NAME="'.$f[0].'"><OPTION VALUE="">';
+
+                                                       reset($nodes);
+                                                       while( list($key, $val) = each($nodes) )
+                                                               {
+                                                               $filter_out .= '<OPTION VALUE="'.$val['id'].'">';
+                                                               if( strstr($x[3],'fullpath') )
+                                                                       $filter_out .= $val['cat_fullpath'];
+                                                                 else
+                                                                       {
+                                                                       for( $i=0 ; $i<$val['cat_level'] ; $i++ )
+                                                                               $filter_out .= "&nbsp;&nbsp;&nbsp;&nbsp;";
+                                                                       $filter_out .= $val['name'];
+                                                                       }
+                                                               }
+                                                       $filter_out .= '</SELECT>';
+                                                       }
+                                                 else
+                                                       $filter_out .= 'No categories listed.';
+                                               }
+                                         else  // Otherwise use pop-up
+                                               {
+
+                                               // Check if a value for this field is supplied
+                                               if( !empty($filter_value) )
+                                                       {
+                                                       if( ($cval = cat_get_node( $x[1], "id = ".$filter_value ) ) )
+                                                               {
+                                                               $cat_id = $filter_value;
+                                                               if( strstr($x[3],'fullpath') )
+                                                                       $cat_name = $cval['cat_fullpath'];
+                                                                 else
+                                                                       $cat_name = $cval['cat_name'];
+                                                               }
+                                                       }
+                                                 else
+                                                       {
+                                                       $cat_id = 0;
+                                                       $cat_name = "&nbsp;&nbsp;&nbsp;";
+                                                       }
+
+                                               $pop_width = !empty($x[4]) ? $x[4] : 200 ;
+                                               $pop_height = !empty($x[5]) ? $x[5] : 300 ;
+                                               $edit_width = !empty($x[6]) ? $x[6] : 400 ;
+                                               $edit_height = !empty($x[7]) ? $x[7] : 500 ;
+
+                                               $filter_out .= "
+                                                         <script language=\"JavaScript1.2\">
+                                                               <!--
+                                                                       function category_select_popup_".$f[0]."( target )
+                                                                               {
+                                                                                       // Pass values to the calendar
+
+                                                                               tempX = 400;
+                                                                               tempY = 300;
+
+                                                                               node_id = this.document.getElementById( target ).value;
+                                                                               var theUrl='".SI_BASE_URL."/glm_apps/category_select_popup.phtml?id=' + node_id + '&field_name=".$f[0]."&table=".$x[1]."&options=".urlencode($x[3])."&edit_width=".$edit_width."&edit_height=".$edit_height."&pop_width=".$pop_width."&pop_height=".$pop_height."';
+
+                                                                               tempX = tempX - 90;
+                                                                               //tempY = tempY - 170;
+
+                                                                       if (navigator.appName == 'Netscape')
+                                                                                       {
+                                                                               CategoryWind = window.open( theUrl, 'Calendar','scrollbars=yes,toolbar=no,resizable=yes,width=".$pop_width.",height=".$pop_height.",screenx=' + tempX + ',screeny=' + tempY,1 );
+                                                                       }
+                                                                                 else
+                                                                                       {
+                                                                       CategoryWind = window.open( theUrl, 'Calendar','scrollbars=no,toolbar=no,resizable=no,width=".$pop_width.",height=".$pop_height.", top=' + tempY + ', left=' + tempX,1 );
+                                                                       }
+
+                                                                               CategoryWind.focus();
+                                                                               }
+                                                               -->
+                                                         </script>
+                                                       ";
+
+                                               $filter_out .= '<INPUT TYPE="text" NAME="'.$f[0].'_NAME" ID="'.$f[0].'_NAME" VALUE="'.$cat_name.'" SIZE="'.$x[2].'" READONLY="readonly" STYLE="background-color: #eeeeee;">
+                                                                                                        <INPUT TYPE="hidden" NAME="'.$f[0].'" ID="'.$f[0].'" VALUE="'.$cat_id.'">
+                                                                                                        <A HREF="javascript:category_select_popup_'.$f[0].'(\''.$f[0].'\')">[Change]</A>
+                                                                                                       ';
+                                               }
+
+                                       if( $filter_value != '' )
+                                               $qs .= ' AND '.$f[0]." = '".$filter_value."'";
+
+                                       break;
+
+                               case "pointer":
+
+                                               // Get values from other table
+
+                                       $w = !empty($x[4]) ? " WHERE ".$x[4] : "" ;
+                                       $d = db_auto_get_data( "SELECT * FROM  ".$x[1].$w." ORDER BY ".$x[2].";", $conn_str, FALSE, 500 );
+
+                                       $p_id_field = !empty($x[3]) ? $x[3] : 'id';             // If no id field supplied, assume "id"
+
+                                               // Build picklist data
+
+                                       unset( $da );
+                                       if( !empty($d) )
+                                               {
+                                               while( list($key, $val) = each($d) )
+                                                       $da[$val[$p_id_field]] = $val[$x[2]];
+                                               $filter_out .= build_a_picklist( $f[0], $da, $filter_value, "standard", "blank" );
+                                               }
+                                         else
+                                               $filter_out .= '<FONT COLOR="red">No records from which to build picklist.</FONT>';
+
+                                               // If value supplied, add to query WHERE clause
+
+                                       if( !empty($filter_value) )
+                                               switch( $option )
+                                                       {
+                                                       case "like":
+                                                       case "begin":
+                                                       case "any":
+                                                               $filter_out .= '<FONT COLOR="red">Filter option for type "pointer" not valid. Must use "exact" for type pointer.</FONT>';
+                                                               break;
+                                                       case "exact":
+                                                       default:
+                                                               $qs .= " AND ".$f[0]." = '".$filter_value."'";
+                                                               break;
+                                                       }
+                                       break;
+
+                               default:
+                                       $filter_out .= '<FONT COLOR="red">UNKNOWN FILTER FIELD TYPE</FONT>';
+                                       break;
+
+                               }
+                       $filter_out .= '</TR>
+                            ';
+                       }
+               $filter_out .= '</TABLE>
+                               <INPUT TYPE="hidden" NAME="Action" VALUE="'.$action.'">
+                               <INPUT TYPE="submit" VALUE="Show Selected Results">
+                               '.$form_params.'
+                       </FORM>
+                    ';
+               }
+
+               // If "new" option selected display link
+
+       if( $option_new )
+               $new_out = '<A HREF="'.$url.'?Action='.urlencode($action).$link_params.'&Option=Add">[Add New Entry]</A><BR>
+                    ';
+            else
+               $new_out = "";
+
+
+               // Add in any ORDER BY clause (ignore anything after ".", which are nav options)
+
+       if( !empty($sortclicked) )                                      // Check if user clicked a column title
+               {
+               $qs .= ' ORDER BY '.$sortclicked;
+               if( $list_sort_direction == 'Backward' )
+                       $qs .= " DESC";
+               }
+         else
+               if( !empty($order) )
+                       {
+                       $qs .= " ORDER BY ";
+                       $ob_comma = "";
+                       $order_array = explode_trim( ",", $order );     // Break out multiple order by field names
+                       foreach( $order_array as $of )
+                               {
+                               $x = explode_trim( ".", $of );          // Break out field name from options
+                               $qs .= $ob_comma.$x[0];                 // Add field name to ORDER BY
+                               if( preg_match("/order_descending/", $of) )     // If order_descending use DESC order in ORDER BY for this field
+                                       $qs .= " DESC";
+                               $ob_comma = ", ";                       // Next order by field will have a comma in front of it
+                               }
+                       }
+
+               // Get the data
+
+       $what_fields = "*";
+       if( $id_field != "" )
+               $what_fields = "*, ".$id_field." AS id";
+
+       $query_string = "SELECT ".$what_fields." FROM ".$table." ".$qs.";";
+
+       if( SI_DEBUG >= 1 ) $ret .=  "<PRE>admin_list_records()[".__LINE__."]: Query String = $query_string</PRE><BR>";
+
+       $data = db_auto_get_data( $query_string, $conn_str, $fail_mode, $rows, $start );
+
+       if( $data )
+               {
+
+                       // Determine how much data we got back
+
+               reset( $data );
+               $return_counts = explode( "|", key($data) );
+               $num = $return_counts[1];
+
+                       // Calculate last entry on page
+
+               $end_list = $num>($start+$rows) ? $start+$rows : $num;
+
+
+                       // Display page navigation
+
+               $nav_out = "";
+               if( $num > 0 && $option_nopaging == FALSE )
+                       {
+                       if( $start > 0 )
+                               $nav_out .= '<A HREF="'.$url.'?Action='.urlencode($action).$link_params.$filter_link.'&start='.($start-$rows).'">previous</A>
+                                    ';
+                           else
+                               $nav_out .= "<I>previous</I> \n";
+
+                       $nav_out .= ' <- <B>Results '.($start+1).' to '.($end_list).' of '.$num.'</B> ->
+                            ';
+
+                       if( $num > $end_list )
+                               $nav_out .= '<A HREF="'.$url.'?Action='.urlencode($action).$link_params.$filter_link.'&start='.$end_list.'">next</A>
+                                    ';
+                           else
+                               $nav_out .= " <I>next</I>\n";
+                       }
+
+
+                       // Build field titles
+
+               $fieldcount = 0;
+               foreach( $field_table as $field )
+                       {
+                       $f2 = explode_trim( "~", $field[2] );   // Only use name, don't include QuickTip text.
+                       $f2_name = $f2[0];
+                       switch( $field[1] )
+                               {
+                               default:
+                                       if( $option_sortlinks )
+                                               {
+                                               $scd = '';
+
+                                                       // Check if a column title has been clicked to cause a sort
+                                               if( $sortclicked == $field[0] )
+                                                       {
+                                                               // Indicate sort direction
+
+                                                       if( $list_sort_direction == 'Forward' )
+                                                               $scd = "v";
+                                                         else
+                                                               $scd = "^";
+                                                       }
+                                               $outnames[$fieldcount++] = $scd.' <A HREF="'.$url.'?Action='.urlencode($action).'&Option=List'.$link_params.$filter_link.'&sortclicked_new='.$field[0].'">'
+                                                               .$f2_name.'</A> '.$scd;
+                                               }
+                                         else
+                                               $outnames[$fieldcount++] = $f2_name;
+                                       break;
+                               }
+                       }
+
+               if( $operation_column )
+                       $outnames[$fieldcount++] = 'Operation';
+
+
+                       // For each result we're going to display
+
+               $reccount = 0;
+               foreach( $data as $key => $r )
+                       {
+
+                               // For each field in the result
+
+                       $fieldcount = 0;
+                       foreach( $field_table as $field )
+                               {
+                               $w = explode_trim( "`", $field[1] );            // Separate out any format spec
+                               $f = explode_trim( ".", $w[0] );                        // break out the field type specs
+
+                                       // If there's any field format spec, save that in our $outvals array
+
+                               if( isset($w[1]) && trim($w[1]) != '' )
+                                       {
+                                               // Replace each {field_name} tag with {#} as needed to reference the correct $outvals[$reccount][#] entry
+
+                                       for( $i=0 ; $i<count($field_table) ; $i++ )
+                                               $w[1] = str_replace( '{'.$field_table[$i][0].'}', '{'.$i.'}', $w[1] );
+
+                                               // Save the new format spec
+                                       $outvals[$reccount][$fieldcount]['format'] = $w[1];
+                                       }
+
+                               switch( $f[0] )
+                                       {
+
+                                       case "lat":
+                                               $fw = 2;
+                                               if( $f[1] > 0 )
+                                                       $fw = $f[1];
+                                               $ns = 'N';
+                                               if( $r[$field[0]] < 0 )
+                                                       {
+                                                       $ns = 'S';
+                                                       $r[$field[0]] = -1 * $r[$field[0]];
+                                                       }
+                                               $dv = (int) $r[$field[0]];
+                                               $mv = ( $r[$field[0]] - $dv ) * 60;
+                                               $outvals[$reccount][$fieldcount]['data'] = sprintf( "<NOBR>%s %d&deg; %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+                                               break;
+
+                                       case "lon":
+                                               $fw = 2;
+                                               if( $f[1] > 0 )
+                                                       $fw = $f[1];
+                                               $ns = 'E';
+                                               if( $r[$field[0]] < 0 )
+                                                       {
+                                                       $ns = 'W';
+                                                       $r[$field[0]] = -1 * $r[$field[0]];
+                                                       }
+                                               $dv = (int) $r[$field[0]];
+                                               $mv = ( $r[$field[0]] - $dv ) * 60;
+                                               $outvals[$reccount][$fieldcount]['data'] = sprintf( "<NOBR>%s %d&deg; %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+                                               break;
+
+                                       case "order":
+                                       case "int":
+                                       case "float":
+                                               $outvals[$reccount][$fieldcount]['data'] = $r[$field[0]];
+                                               break;
+
+                                       case "money":
+                                               $outvals[$reccount][$fieldcount]['data'] = "$".sprintf( "%01.2f", $r[$field[0]] );
+                                               break;
+
+                                       case "fixed":
+                                               $outvals[$reccount][$fieldcount]['data'] = sprintf( "%01.".$f[1]."f", $r[$field[0]] );
+                                               break;
+
+                                       case "date":
+                                       case "text":
+                                       case "textbox":
+                                       case "richtext":
+                                       case "inet":
+                                               $outvals[$reccount][$fieldcount]['data'] = $r[$field[0]];
+                                               break;
+
+                                       case "state":
+                                               $outvals[$reccount][$fieldcount]['data'] = $GLOBALS['si_states_array'][$r[$field[0]]];
+                                               break;
+
+                                       case "country":
+                                               $outvals[$reccount][$fieldcount]['data'] = $GLOBALS['si_countries_array'][$r[$field[0]]];
+                                               break;
+
+                                       case "url":
+                                               $outvals[$reccount][$fieldcount]['data'] = '<A HREF="'.$r[$field[0]].'">'.$r[$field[0]].'</A>';
+                                               break;
+
+                                       case "category":
+                                                       // Get the category name for this field is supplied
+                                               if( !empty($r[$field[0]]) )
+                                                       {
+                                                       if( $cval = db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE id = ".$r[$field[0]].";", 0, $conn_str, FALSE ) )
+                                                               $outvals[$reccount][$fieldcount]['data'] = $cval['name'];
+                                                         else
+                                                               $outvals[$reccount][$fieldcount]['data'] = '<FONT COLOR="red">Unknown Category</FONT>';
+                                                       }
+                                                 else
+                                                       {
+                                                       $outvals[$reccount][$fieldcount]['data'] = "&nbsp;";
+                                                       }
+                                               break;
+
+                                       case "pointer":
+                                                       // If {value_field} supplied use that, otherwise use id of record as value to match
+                                               $value_field = !empty($f[3]) ? $f[3] : "id" ;
+
+                                                       // If {where} supplied use that, otherwise match {value_field} or "id" field
+                                               $w = '';
+                                               if( !empty($f[4]) )
+                                                       $w = " WHERE ".$f[4];
+                                                 elseif( trim($r[$field[0]]) != '' )
+                                                       $w = " WHERE ".$value_field." = ".$r[$field[0]];
+
+                                               if( $w != '' )
+                                                       {
+                                                       $pval = db_auto_get_row( "SELECT * FROM ".$f[1].$w.";", 0, $conn_str, $fail_mode );
+                                                       $outvals[$reccount][$fieldcount]['data'] = $pval[$f[2]];
+                                                       }
+                                                 else
+                                                       $outvals[$reccount][$fieldcount]['data'] = '';
+                                               break;
+
+                                       case "checkbox":
+                                               $outvals[$reccount][$fieldcount]['data'] = $r[$field[0]] == "t" ? "Yes" : "No" ;
+                                               break;
+
+                                       case "image":
+                                               if( !empty($r[$field[0]]) )
+                                                       {
+                                                       switch( $f[1] )
+                                                               {
+                                                               case "o":       $img_url = SI_IMG_ORIGINAL_URL; break;
+                                                               case "r":       $img_url = SI_IMG_RESIZED_URL;  break;
+                                                               case "m":       $img_url = SI_IMG_MIDSIZED_URL; break;
+                                                               case "t":       $img_url = SI_IMG_THUMB_URL;    break;
+                                                               default:        $img_url = "none";              break;
+                                                               }
+                                                       if( $img_url != "none" )
+                                                               $outvals[$reccount][$fieldcount]['data'] = '<IMG SRC="'.$img_url."/".$r[$field[0]].'">';
+                                                           else
+                                                               $outvals[$reccount][$fieldcount]['data'] = '<FONT COLOR="RED">Invalid Image Size</FONT>';
+                                                       }
+                                                   else
+                                                       $outvals[$reccount][$fieldcount]['data'] = '(no image)';
+                                               break;
+
+                                       case "file":
+                                               if( !empty($r[$field[0]]) )
+                                                       $outvals[$reccount][$fieldcount]['data'] = '<A HREF="'.SI_BASE_FILE_URL.'/'.$r[$field[0]].'">'.$r[$field[0]].'</A>';
+                                                   else
+                                                       $outvals[$reccount][$fieldcount]['data'] = '(no file)';
+                                               break;
+
+                                       case "list":
+                                               $opts_table = array ();
+                                               $opts = explode_trim( "~", $f[1] );     // Separate list options
+                                               foreach( $opts as $opt )
+                                                       {
+                                                       $z = explode_trim("^", $opt); // Separate value from displayed text
+                                                       $opts_table[$z[0]] = $z[1];
+                                                       }
+
+                                                       // In case there's multiple selected options, display results of all selected options with comma separators
+
+                                               $x = explode( '~', $r[$field[0]] );
+                                               $outvals[$reccount][$fieldcount]['data'] = $sep = '';
+                                               if( is_array($x) )
+                                                       foreach( $x as $y )
+                                                               {
+                                                               $outvals[$reccount][$fieldcount]['data'] .= $sep.$opts_table[$y];
+                                                               $sep = ', ';
+                                                               }
+
+                                               break;
+
+                                       default:
+                                               $outvals[$reccount][$fieldcount]['data'] = '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$f[0].' for '.$field[0].'</FONT>';
+                                               break;
+
+                                       } // switch( field )
+                               $fieldcount++;
+                               } // foreach( field )
+
+                       if( $operation_column )
+                               {
+                               $outvals[$reccount][$fieldcount]['data'] = "";
+                               if( $option_view )
+                                       $outvals[$reccount][$fieldcount]['data'] .= '<A HREF="'.$url.'?Action='.urlencode($action).'&Option=View'.$link_params.'&id='.$r["id"].'">[view] </A>';
+                               if( $option_edit )
+                                       $outvals[$reccount][$fieldcount]['data'] .= '<A HREF="'.$url.'?Action='.urlencode($action).'&Option=Edit'.$link_params.'&id='.$r["id"].'">[edit] </A>';
+                               if( $option_delete )
+                                       $outvals[$reccount][$fieldcount]['data'] .= '<A HREF="'.$url.'?Action='.urlencode($action).'&Option=Delete'.$link_params.'&id='.$r["id"].'">[delete] </A>';
+                               if( $option_duplicate )
+                                       $outvals[$reccount][$fieldcount]['data'] .= '<A HREF="'.$url.'?Action='.urlencode($action).'&Option=Duplicate'.$link_params.'&id='.$r["id"].'">[duplicate] </A>';
+                               $fieldcount++;
+                               }
+
+                       $reccount++;
+                       } // foreach( record )
+
+                       // Replace parameters in Title - {n} represents the field names in the page title
+
+               } // if( $data )
+
+       for( $i=0 ; $i<$fieldcount ; $i++ )
+               {
+               $a_title = ereg_replace( "\\{".$i."\\}", $outnames[$i], $a_title );
+               $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($outnames[$i]), $a_title );
+               }
+       $a_title = ereg_replace( "\\{filter\}", $filter_out, $a_title );
+       $a_title = ereg_replace( "\\{link_params\}", $link_params, $a_title );
+       $a_title = ereg_replace( "\\{form_params\}", $form_params, $a_title );
+       $a_title = ereg_replace( "\\{new\}", $new_out, $a_title );
+       $a_title = ereg_replace( "\\{nav\}", $nav_out, $a_title );
+
+       $ret .=  "<CENTER>\n";
+
+       if( empty($view) )      // If $view is not supplied
+               {
+
+               if( trim($quick_tip) != '' )
+                       $a_title = quick_tip( $a_title, $quick_tip );
+
+                       // Display title, filter, and optional "new" link
+
+               $ret .=  $a_title.'
+                       '.$filter_out.'
+                       '.$new_out;
+
+                       // If there were results listed, display the results
+
+               if( $data && ($fields != "") )
+                       {
+                       $ret .=  $nav_out.'<BR>'.$nav_initials.'
+                               <TABLE BORDER="'.($option_noborder==FALSE?'1':'0').'">
+                                       <TR>
+                            ';
+
+                            // Display the titles for all columns
+
+                       for( $i=0 ; $i<$fieldcount ; $i++ )
+                               {
+                               if( !$hidden[$i] )
+                                       $ret .=  "<TH>".$outnames[$i]."&nbsp;</TH>";
+                               }
+
+                               // Display the data for each result
+
+                       for( $i=0 ; $i<$reccount ; $i++ )
+                               {
+                               $ret .=  "<TR>";
+
+                               for( $j=0 ; $j<$fieldcount ; $j++ )
+                                       {
+                                               // If the field is supposed to be seen
+
+                                       if( !$hidden[$j] )
+                                               {
+                                                       // If there's a format spec, use that
+                                               if( $outvals[$i][$j]['format'] != '' )
+                                                       {
+                                                       $out = $outvals[$i][$j]['format'];
+                                                       for( $k=0 ; $k<$fieldcount ; $k++ )
+                                                               $out = str_replace( '{'.$k.'}', $outvals[$i][$k]['data'] , $out );
+                                                       $ret .=  "<td>$out</td>";
+                                                       }
+                                                 else  // Otherwise just output the value
+                                                       $ret .=  "<TD>".$outvals[$i][$j]['data']."&nbsp;</TD>";
+                                               }
+                                       }
+                               $ret .=  "</TR>\n";
+
+                               }
+                       $ret .=  '      </TABLE>
+                               '.$nav_out;
+                       }
+                   else
+                       $ret .=  '      <CENTER>(No results found)</CENTER>
+                            ';
+
+               }
+           else                // IF$view is supplied
+               {
+
+                       // Replace any reference to {filter}, {new}, and {nav} in $view
+
+               $view = ereg_replace( "\\{filter\\}", $filter_out, $view );
+               $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+               $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+               $view = ereg_replace( "\\{new\\}", $new_out, $view );
+               $view = ereg_replace( "\\{nav\\}", $nav_out, $view );
+
+                       // Separate the header, body, and footer
+
+               $head = $body = $foot = "";
+               $x = explode( "{body}", $view );
+               if( count($x) == 2 )    // if {body} found then we have the head and the rest
+                       {
+                       $head = $x[0];
+                       $view = $x[1];
+                       }
+               $x = explode( "{/body}", $view );
+               if( count($x) == 2 )    // If {/body} found then we have the body and the foot
+                       {
+                       $body = $x[0];
+                       $foot = $x[1];
+                       }
+                   else
+                       $body = $view;
+
+                       // Replace the values $head & $foot - {n} in Header and footer get names of fields
+
+               for( $i=0 ; $i<$fieldcount ; $i++ )
+                       {
+                       $head = ereg_replace( "\\{".$i."\\}", $outnames[$i], $head );
+                       $foot = ereg_replace( "\\{".$i."\\}", $outnames[$i], $foot );
+                       $head = ereg_replace( "\\{encode:".$i."\\}", urlencode($outnames[$i]), $head );
+                       $foot = ereg_replace( "\\{encode:".$i."\\}", urlencode($outnames[$i]), $foot );
+                       }
+
+               $ret .=  $a_title.$head;        // Output title & head sections
+
+               if( $data )
+                       {
+                               // Break up body into sections
+
+                       $body_parts = explode( "{section}", $body );    // Did I really write it that way???
+
+                               // For each body_part
+
+                       $bp = 0;
+
+                       for( $i=0 ; $i<$reccount ; $i++ )               // For each Record
+                               {
+                               $b = $body_parts[$bp++];                // Get body section and point to next
+                               if( $bp == count($body_parts) )         // if last available body section, start back at first
+                                       $bp = 0;
+
+                               for( $j=0 ; $j<$fieldcount ; $j++ )             // For each field
+                                       {
+                                       $b = ereg_replace( "\\{".$j."\\}", $outvals[$i][$j]['data'], $b );      // Replace value for that field
+                                       $b = ereg_replace( "\\{encode:".$j."\\}", urlencode($outvals[$i][$j]['data']), $b );    // Replace value for that field
+                                       }
+
+                               $ret .=  $b;    // Output this body section
+                               }
+                       }
+                   else
+                       $ret .=  "(No results found)\n";
+
+                       // Output foot
+
+               $ret .=  $foot;
+
+               }
+
+       $ret .=  "</CENTER>\n";
+
+       return( array( 'text' => $ret, 'status' => true ) );
+
+}
+
+function admin_list_records( $table, $where, $order, $conn_str, $fields,
+                               $options, $fail_mode, $rows = 20, $start = 0,
+                               $url, $action, $params, $filters, $a_title, $view = "", $id_field = "", $quick_tip = "" )
+{
+       $r = admin_list_records_r( $table, $where, $order, $conn_str, $fields,
+                               $options, $fail_mode, $rows, $start,
+                               $url, $action, $params, $filters, $a_title, $view, $id_field, $quick_tip );
+
+       echo $r['text'];
+       return( $r['status'] );
+}
+
+
+
+
+       // Ask for a new record for a table
+
+function admin_new_record_r( $table, $conn_str, $fields, $url, $action, $params, $a_title,
+                                               $view = "", $options = "", $quick_tip = "" )
+{
+
+       $ret = '';
+
+       $form_name = "edit";
+       $richtext_used = FALSE;         // Indicates whether richtext field type has been specified
+       $category_used = FALSE;         // Indicates whether categroy field type has been specified
+
+               // Make all submitted parameters available
+
+//     extract($GLOBALS[HTTP_GET_VARS]);
+//     extract($GLOBALS[HTTP_POST_VARS]);
+
+               // Check for any options
+
+       $borders = strstr( $options, "borders" ) == FALSE ? 0 : 1;
+
+               // Break out configuration data
+
+       $field_table = explode_trim( "|", $fields );
+
+               // Don't be surprised if last field is blank
+
+       if( trim($field_table[count($field_table)-1]) == "" )
+               array_pop( $field_table );
+
+       foreach( $field_table as $key => $r )
+               $field_table[$key] = explode_trim( ",", $r );
+
+               // Check for additional parameters that are passed
+
+       if( !empty($params) )
+               {
+               $param = explode_trim( "|", $params );  // Separate parameters
+               $link_params = $form_params = "";
+               foreach( $param as $p )
+                       {
+                       $x = explode_trim( ".", $p );   // Separate Names from Values
+                       $link_params .= "&".$x[0]."=".urlencode($x[1]);
+                       $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+                       }
+               }
+
+
+               // For each field in the result
+
+       $outcount = 0;
+       foreach( $field_table as $field )
+               {
+
+               $f = explode_trim( ".", $field[1] );
+
+               $out[$outcount]["display"] = TRUE;
+               $out[$outcount]["field"] = $field[0];
+
+                       // Display title fields
+
+               $n = explode_trim( '~', $field[2] );                    // Separate QuickTip from title
+               $field_name_color = 'black';
+               switch( $field[3] )
+                       {
+                       case "TRUE":
+                       case "UNIQUE":
+                               $field_name_color = 'red';
+                       case "FALSE":
+                       case "SUPPLIED":
+                       case "DISPLAY":
+                       case "UNIQUE_NOT_REQ":
+                                       // setup tip display - requires show_QuickTip() and hide_QuickTip() functions from java_functions.js
+
+                               if( count($n) > 1 )
+                                       $out[$outcount]["name"] = quick_tip( '<font color="'.$field_name_color.'">'.$n[0].'</font>', $n[1] );
+                                 else
+                                       $out[$outcount]["name"] = '<FONT COLOR="'.$field_name_color.'">'.$field[2].'</FONT>';
+
+                               break;
+
+                       case "HIDDEN":
+                               $out[$outcount]["name"] = '';
+                               break;
+
+                       default:
+                               $out[$outcount]["name"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                               break;
+                       }
+
+                       // Display input fields
+
+               switch( $f[0] )
+                       {
+                       case "money":
+                       case "int":
+                       case "order":
+                       case "url":
+                       case "text":
+                       case "inet":
+                       case "float":
+                       case "fixed":
+                               $v = "";
+                               $prefix = "";
+                               $s = $f[1];             // Field Input Size
+
+                               if( $f[0] == "int" )    // If it's an integer, default to 0
+                                       $v = 0;
+
+                               if( $f[0] == "order" )  // If it's an "order" field, default to 9999 - last in list
+                                       $v = 9999;
+
+                               if( $f[0] == "money" )  // If it's money, default to 0.00
+                                       {
+                                       $prefix = "$";
+                                       $v = "0.00";
+                                       }
+
+                               if( $f[0] == "fixed" )  // If it's fixed, default to specified precision
+                                       {
+                                       $prefix = "";
+                                       $v = "0";
+                                       if( $f[1] > 0 )
+                                               {
+                                               $v .= '.';
+                                               for( $i=0 ; $i<$f[1] ; $i++ )
+                                                       $v .= '0';
+                                               $s = $f[1] + 4;
+                                               }
+                                       }
+
+                               switch( $field[3] )     // {required} setting
+                                       {
+                                       case "TRUE":
+                                       case "UNIQUE":
+                                       case "UNIQUE_NOT_REQ":
+                                       case "FALSE":
+                                               $out[$outcount]["value"] = $prefix.'<INPUT TYPE="text" NAME="'.$field[0].'" VALUE="'.$v.'" SIZE="'.$s.'">';
+                                               break;
+                                       case "SUPPLIED":
+                                               $out[$outcount]["value"] = $prefix.'<INPUT TYPE="text" NAME="'.$field[0].'" SIZE="'.$s.'" VALUE="'.$GLOBALS[$field[4]].'">';
+                                               break;
+                                       case "DISPLAY":
+                                               $out[$outcount]["value"] = $prefix.'<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'.$GLOBALS[$field[4]];
+                                               break;
+                                       case "HIDDEN":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+                                               break;
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+                                       }
+                               break;
+
+                       case "lat":
+
+                               $fw = 2;
+                               if( $f[1] > 0 )
+                                       $fw = $f[1];
+
+                               switch( $field[3] )     // {required} setting
+                                       {
+                                       case "TRUE":
+                                       case "UNIQUE":
+                                       case "UNIQUE_NOT_REQ":
+                                       case "FALSE":
+                                               $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="N" SELECTED>North<OPTION VALUE="S">South</SELECT>
+                                                               <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="0" SIZE="4" MAXLENGTH="2" ALIGN="right">&deg;
+                                                               <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", 0 ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+                                               break;
+                                       case "SUPPLIED":
+                                       case "DISPLAY":
+                                               $ns = 'N';
+                                               if( $GLOBALS[$field[4]] < 0 )
+                                                       {
+                                                       $ns = 'S';
+                                                       $GLOBALS[$field[4]] = -1 * $GLOBALS[$field[4]];
+                                                       }
+                                               $dv = (int) $GLOBALS[$field[4]];
+                                               $mv = ( $GLOBALS[$field[4]] - $dv ) * 60;
+                                               if( $field[3] == "SUPPLIED" )
+                                                       $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="N" '.($ns=='N'?'SELECTED':'').'>North<OPTION VALUE="S" '.($ns=='S'?'SELECTED':'').'>South</SELECT>
+                                                               <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="'.$dv.'" SIZE="4"  MAXLENGTH="2" ALIGN="right">&deg;
+                                                               <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", $mv ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+                                                 else
+                                                       $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'
+                                                                       .sprintf( "<NOBR>%s %d&deg; %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+                                               break;
+                                       case "HIDDEN":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+                                               break;
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+                                       }
+                               break;
+
+                       case "lon":
+
+                               $fw = 2;
+                               if( $f[1] > 0 )
+                                       $fw = $f[1];
+
+                               switch( $field[3] )     // {required} setting
+                                       {
+                                       case "TRUE":
+                                       case "UNIQUE":
+                                       case "UNIQUE_NOT_REQ":
+                                       case "FALSE":
+                                               $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="W" SELECTED>West<OPTION VALUE="E">East</SELECT>
+                                                               <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="0" SIZE="4"  MAXLENGTH="3" ALIGN="right">&deg;
+                                                               <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", 0 ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+                                               break;
+                                       case "SUPPLIED":
+                                       case "DISPLAY":
+                                               $ns = 'E';
+                                               if( $GLOBALS[$field[4]] < 0 )
+                                                       {
+                                                       $ns = 'W';
+                                                       $GLOBALS[$field[4]] = -1 * $GLOBALS[$field[4]];
+                                                       }
+                                               $dv = (int) $GLOBALS[$field[4]];
+                                               $mv = ( $GLOBALS[$field[4]] - $dv ) * 60;
+                                               if( $field[3] == "SUPPLIED" )
+                                                       $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="W" '.($ns=='W'?'SELECTED':'').'>West<OPTION VALUE="E" '.($ns=='E'?'SELECTED':'').'>East</SELECT>
+                                                               <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="'.$dv.'" SIZE="4"  MAXLENGTH="3" ALIGN="right">&deg;
+                                                               <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", $mv ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+                                                 else
+                                                       $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'
+                                                                       .sprintf( "<NOBR>%s %d&deg; %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+                                               break;
+                                       case "HIDDEN":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+                                               break;
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+                                       }
+                               break;
+
+                       case "date":
+
+                               $date_f = !empty( $f[1] ) ? time()-$f[1]*86400 : time() ;       // Set datestamp of first day to allow
+                               $date_t = !empty( $f[2] ) ? time()+$f[2]*86400 : time() ;       // Set datestamp of last day to allow
+
+                               switch( $field[3] )     // {required} setting
+                                       {
+                                       case "TRUE":
+                                       case "FALSE":
+                                               $out[$outcount]["value"] = calendar_date_select( "", time(), $date_f, $date_t, $form_name, $field[0], $f[3], $f[4] );
+                                               break;
+                                       case "SUPPLIED":
+                                               $out[$outcount]["value"] = calendar_date_select( $GLOBALS[$field[4]], time(), $date_f, $date_t, $form_name, $field[0], $f[3], $f[4] );
+                                               break;
+                                       case "DISPLAY":
+                                               $out[$outcount]["value"] = $prefix.'<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'.$GLOBALS[$field[4]];
+                                               break;
+                                       case "HIDDEN":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+                                               break;
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+                                       }
+                               break;
+
+                       case "textbox":
+                               switch( $field[3] )     // {required} setting
+                                       {
+                                       case "TRUE";
+                                       case "FALSE";
+                                               $out[$outcount]["value"] = '<TEXTAREA NAME="'.$field[0].'" COLS="'.$f[1].'" ROWS="'.$f[2].'"></TEXTAREA>';
+                                               break;
+                                       case "SUPPLIED":
+                                               $out[$outcount]["value"] = '<TEXTAREA NAME="'.$field[0].'" COLS="'.$f[1].'" ROWS="'.$f[2].'">'
+                                                       .$GLOBALS[$field[4]].'</TEXTAREA>';
+                                               break;
+                                       case "DISPLAY":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'.$GLOBALS[$field[4]];
+                                               break;
+                                       case "HIDDEN":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+                                               break;
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+                                       }
+                               break;
+
+                       case "richtext":
+                               $def_text = '';
+                               switch( $field[3] )     // {required} setting
+                                       {
+                                       case "SUPPLIED":
+                                               $def_text = $GLOBALS[$field[4]];
+                                               // no break, dropps through
+                                       case "TRUE";
+                                       case "FALSE";
+                                               if( SI_RICHTEXT_TYPE_ENABLED )
+                                                       {
+                                                       if( !$richtext_used  )
+                                                               {
+                                                               include_once( SI_BASE_PATH.'/glm_apps/HTMLArea/glm_functions_support.inc' );
+                                                               $richtext_used = TRUE;
+                                                               }
+                                                       $ew = ( trim($f[1]) != "" ? $f[1] : SI_DEFAULT_RICHTEXT_WIDTH );
+                                                       $eh = ( trim($f[2]) != "" ? $f[2] : SI_DEFAULT_RICHTEXT_HEIGHT );
+                                                       htmlarea_add_field( $field[0], $ew, $eh );
+                                                       $out[$outcount]["value"] = '<TABLE BORDER="1" WIDTH="'.$ew.'"><TR><TD><TEXTAREA ID="'.$field[0].'" NAME="'.$field[0].'" COLS="60" ROWS="5">'.$def_text.'</TEXTAREA></TD></TR></TABLE>';
+                                                       }
+                                                 else
+                                                 $out[$outcount]["value"] = '<TEXTAREA ID="'.$field[0].'" NAME="'.$field[0].'" COLS="60" ROWS="5">'.$def_text.'</TEXTAREA>';
+                                               break;
+                                       case "DISPLAY":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">'.$GLOBALS[$field[4]];
+                                               break;
+                                       case "HIDDEN":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+                                               break;
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+                                       }
+                               break;
+
+                       case "multifield":              // multitext.numb_fields.new_line_string
+
+                                       // THIS FIELD TYPE REQUIRES java_functions.js
+
+                               switch( $field[3] )
+                                       {
+                                       case "TRUE":
+                                       case "FALSE":
+                                               $out[$outcount]["value"] = '<input type="hidden" name="'.$field[0].'_text" id="'.$field[0].'_text" value="'.$f[2].'">
+                                                                                                       <span id="'.$field[0].'_fields">';
+
+                                                       // If there's data, then build existing input lines with data
+                                               if( ( $x = trim($data[$field[0]]) ) != '' )
+                                                       {
+                                                       $field_data = unserialize( $data[$field[0]] );
+
+                                                       if( $field_data != false && is_array( $field_data ) )
+                                                               {
+                                                                       // For each line of inputs
+                                                               for( $i=1 ; $i<=count($field_data) ; $i++ )
+                                                                       {
+                                                                       $f_line = str_replace( '{line_numb}', $i, $f[2] );              // Set line number in output text
+                                                                               // For each input field on the line
+                                                                       for( $j=1 ; $j<=$f[1] ; $j++ )
+                                                                               $f_line = str_replace( '{field_'.$j.'}', '<input type="text" name="'.$field[0].'_'.$i.'_'.$j.'" id="'.$field[0].'_'.$i.'_'.$j.'" value="'.$field_data[$i-1][$j-1].'" onKeyUp="multi_fields(\''.$field[0].'\',this,'.$f[1].');">', $f_line );
+
+                                                                       $out[$outcount]["value"] .= $f_line."\n";
+                                                                       }
+                                                               }
+
+                                                       }
+                                                 else
+                                                       $i = 1;         // If no data blank line is #1
+
+                                                       // Build 1 spare input line
+                                               $f_line = str_replace( '{line_numb}', $i, $f[2] );              // Set line number in output text
+                                               for( $j=1 ; $j<=$f[1] ; $j++ )
+                                                       $f_line = str_replace( '{field_'.$j.'}', '<input type="text" name="'.$field[0].'_'.$i.'_'.$j.'" id="'.$field[0].'_'.$i.'_'.$j.'" value="" onKeyUp="multi_fields(\''.$field[0].'\',this,'.$f[1].');">', $f_line );
+                                               $out[$outcount]["value"] .= $f_line."\n</span>";
+
+                                               break;
+
+                                       case "HIDDEN":
+                                       case "DISLPLAY":
+                                       case "SUPPLIED":
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+
+                                       }
+                               break;
+
+                       case "image":
+                               switch( $field[3] )     // {required} setting
+                                       {
+                                       case "TRUE":
+                                       case "FALSE":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="file" NAME="'.$field[0].'">';
+                                               break;
+                                       case "SUPPLIED":
+                                       case "DISPLAY":
+                                       case "HIDDEN":
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">SUPPLIED/DISPLAY/HIDDEN not allowed here for image</FONT>';
+                                               break;
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+                                       }
+                               break;
+
+                       case "images":
+
+                               switch( $field[3] )
+                                       {
+                                       case "TRUE":
+                                       case "FALSE":
+                                               $out[$outcount]["value"] = '';
+                                               $im_num = 0;
+
+                                               if( empty($f[1]) )
+                                                       $spare = 2;
+                                                 else
+                                                       $spare = $f[1];
+
+                                                       // Check for options
+
+                                               $im_des = strstr( $f[2], 'descr' );
+                                               $im_align = strstr( $f[2], 'align' );
+                                               $im_size = strstr( $f[2], 'size' );
+                                               if( !empty( $f[3] ) )
+                                                       $im_des_s = $f[3];
+                                                 else
+                                                       $im_des_s = 40;
+                                               if( !empty( $f[4] ) )
+                                                       $im_des_t = $f[4];
+                                                 else
+                                                       $im_des_t = "Text";
+
+                                               for( $i=0 ; $i<$spare ; $i++ )
+                                                       {
+                                                       $out[$outcount]["value"] .= '
+                                                               Image #'.($im_num+1).'<BR>
+                                                               <TABLE BORDER="1">
+                                                                       <TR>
+                                                                               <TD COLSPAN="2" VALIGN="middle"><INPUT TYPE="file" NAME="'.$field[0].'['.$im_num.']">
+                                                                                       '.( $im_align ? '
+                                                                                               Align image <SELECT NAME="'.$field[0].'_ALIGN['.$im_num.']">
+                                                                                                       <OPTION VALUE="Left"'.($im_data[$im_num]['align']=="Left"?" SELECTED":"").'>Left
+                                                                                                       <OPTION VALUE="Right"'.($im_data[$im_num]['align']=="Right"?" SELECTED":"").'>Right
+                                                                                                       <OPTION VALUE="Top"'.($im_data[$im_num]['align']=="Top"?" SELECTED":"").'>Top
+                                                                                                       <OPTION VALUE="Middle"'.($im_data[$im_num]['align']=="Middle"?" SELECTED":"").'>Middle
+                                                                                                       <OPTION VALUE="Bottom"'.($im_data[$im_num]['align']=="Bottom"?" SELECTED":"").'>Bottom
+                                                                                               </SELECT>
+                                                                                               ' : '<INPUT TYPE="hidden" NAME="align" VALUE="">' ).'
+                                                                                       '.( $im_size ? '
+                                                                                               Size
+                                                                                               <SELECT NAME="'.$field[0].'_SIZE['.$im_num.']">
+                                                                                                       <OPTION VALUE="Original"'.($im_data[$im_num]['size']=="Original"?" SELECTED":"").'>Original
+                                                                                                       <OPTION VALUE="Resized"'.($im_data[$im_num]['size']=="Resized"?" SELECTED":"").'>Resized (width='.SI_RESIZED_SIZE.')
+                                                                                                       <OPTION VALUE="Midsized"'.($im_data[$im_num]['size']=="Midsized"?" SELECTED":"").'>Midsized (width='.SI_MIDSIZED_SIZE.')
+                                                                                                       <OPTION VALUE="Thumb"'.($im_data[$im_num]['size']=="Thumb"?" SELECTED":"").'>Thumb (width='.SI_THUMB_SIZE.')
+                                                                                               </SELECT>
+                                                                                               ' : '<INPUT TYPE="hidden" NAME="size" VALUE="">' ).'
+                                                                                       </TD>
+                                                                       </TR>
+                                                                       '.( $im_des ? '<TR><TD COLSPAN="2">'.$im_des_t.' <INPUT TYPE="text" NAME="'.$field[0].'_DESCR['.$im_num.']" SIZE="'.$im_des_s.'"></TD>' : '' ).'
+                                                                </TABLE>
+                                                                <BR>';
+                                                       $im_num++;
+                                                       }
+                                               break;
+
+                                       case "HIDDEN":
+                                       case "DISLPLAY":
+                                       case "SUPPLIED":
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+
+                                       }
+                               break;
+
+
+                       case "file":
+                               switch( $field[3] )     // {required} setting
+                                       {
+                                       case "TRUE":
+                                       case "FALSE":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="file" NAME="'.$field[0].'">';
+                                               break;
+                                       case "SUPPLIED":
+                                       case "DISPLAY":
+                                       case "HIDDEN":
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">SUPPLIED/DISPLAY/HIDDEN not allowed here for file</FONT>';
+                                               break;
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+                                       }
+                               break;
+
+                       case "category":
+
+                                       // If picklist is selected - use that for selection
+
+                               if( strstr($f[3],'picklist') )
+                                       {
+                                       if( ($nodes = cat_get_nodes($f[1])) )
+                                               {
+                                               $out[$outcount]["value"] .= '<SELECT NAME="'.$field[0].'"><OPTION VALUE="">';
+
+                                               reset($nodes);
+                                               while( list($key, $val) = each($nodes) )
+                                                       {
+                                                       $out[$outcount]["value"] .= '<OPTION VALUE="'.$val['id'].'">';
+                                                       if( strstr($f[3],'fullpath') )
+                                                               $out[$outcount]["value"] .= $val['cat_fullpath'];
+                                                         else
+                                                               {
+                                                               for( $i=0 ; $i<$val['cat_level'] ; $i++ )
+                                                                       $out[$outcount]["value"] .= "&nbsp;&nbsp;&nbsp;&nbsp;";
+                                                               $out[$outcount]["value"] .= $val['name'];
+                                                               }
+                                                       }
+                                               $out[$outcount]["value"] .= '</SELECT>';
+                                               }
+                                         else
+                                               $out[$outcount]["value"] .= 'No categories listed.';
+                                       }
+                                 else  // Otherwise use pop-up
+                                       {
+
+                                               // Check if a value for this field is supplied
+                                       if( !empty($GLOBALS[$field[4]]) )
+                                               {
+                                               if( ($cval = cat_get_node( $f[1], "id = ".$GLOBALS[$field[4]] ) ) )
+                                                       {
+                                                       $cat_id = $GLOBALS[$field[4]];
+                                                       if( strstr($f[3],'fullpath') )
+                                                               $cat_name = $cval['cat_fullpath'];
+                                                         else
+                                                               $cat_name = $cval['cat_name'];
+                                                       }
+                                               }
+                                         else
+                                               {
+                                               $cat_id = 0;
+                                               $cat_name = "&nbsp;&nbsp;&nbsp;";
+                                               }
+
+                                       $pop_width = !empty($f[4]) ? $f[4] : 200 ;
+                                       $pop_height = !empty($f[5]) ? $f[5] : 300 ;
+                                       $edit_width = !empty($f[6]) ? $f[6] : 400 ;
+                                       $edit_height = !empty($f[7]) ? $f[7] : 500 ;
+
+                                       $out[$outcount]["value"] .= "
+                                                 <script language=\"JavaScript1.2\">
+                                                       <!--
+                                                               function category_select_popup_".$field[0]."( target )
+                                                                       {
+                                                                               // Pass values to the calendar
+
+                                                                       tempX = 400;
+                                                                       tempY = 300;
+
+                                                                       node_id = this.document.getElementById( target ).value;
+                                                                       var theUrl='".SI_BASE_URL."/glm_apps/category_select_popup.phtml?id=' + node_id + '&field_name=".$field[0]."&table=".$f[1]."&options=".urlencode($f[3])."&edit_width=".$edit_width."&edit_height=".$edit_height."&pop_width=".$pop_width."&pop_height=".$pop_height."';
+
+                                                                       tempX = tempX - 90;
+                                                                       tempY = tempY - 170;
+
+                                                               if (navigator.appName == 'Netscape')
+                                                                               {
+                                                                       CategoryWind = window.open( theUrl, 'Calendar','scrollbars=yes,toolbar=no,resizable=yes,width=".$pop_width.",height=".$pop_height.",screenx=' + tempX + ',screeny=' + tempY,1 );
+                                                               }
+                                                                         else
+                                                                               {
+                                                               CategoryWind = window.open( theUrl, 'Calendar','scrollbars=no,toolbar=no,resizable=yes,width=".$pop_width.",height=".$pop_height.", top=' + tempY + ', left=' + tempX,1 );
+                                                               }
+
+                                                                       CategoryWind.focus();
+                                                                       }
+                                                       -->
+                                                 </script>
+                                               ";
+
+                                       $out[$outcount]["value"] .= '<INPUT TYPE="text" NAME="'.$field[0].'_NAME" ID="'.$field[0].'_NAME" VALUE="'.$cat_name.'" SIZE="'.$f[2].'" READONLY="readonly" STYLE="background-color: #eeeeee;">
+                                                                                                <INPUT TYPE="hidden" NAME="'.$field[0].'" ID="'.$field[0].'" VALUE="'.$cat_id.'">
+                                                                                                <A HREF="javascript:category_select_popup_'.$field[0].'(\''.$field[0].'\')">[Change]</A>
+                                                                                               ';
+                                       }
+                               break;
+
+                       case "pointer":
+
+                                       // If {value_field} type option supplied use that, otherwise use id of record as VALUE
+                               $value_field = !empty($f[3]) ? $f[3] : "id" ;
+
+                                       // If {where} type option supplied use that, otherwise get all possibilities from other table
+                               $w = !empty($f[4]) ? " WHERE ".$f[4] : "" ;
+
+                                       // If picklist options
+                               $p = !empty($f[5]) ? $f[5] : "" ;
+
+                                       // Sort field for query
+                               $s = !empty($f[6]) ? $f[6] : "id" ;
+
+                                       // Pointer options
+
+                               $pointer_option_add_field = FALSE;
+                               if( ! empty($f[7]) )
+                                       {
+                                       $option_table = explode_trim( ",", $f[7] );
+                                       foreach( $option_table as $option )
+                                               {
+                                               switch( $option )
+                                                       {
+                                                       case "add_field":                                               // Option to display a field for entering a new target
+                                                               $pointer_option_add_field = TRUE;
+                                                               break;
+
+                                                       default:
+                                                               break;
+                                                       }
+                                               }
+                                       }
+
+
+                               $s = !empty($f[6]) ? $f[6] : "id" ;
+
+                                       // Check if a value for this field is supplied
+                               if( !empty($field[4]) )
+                                       $supplied = $GLOBALS[$field[4]];
+                                 else
+                                       $supplied = "";
+
+                               switch( $field[3] )
+                                       {
+                                               // These require us to build a pick list
+                                       case "TRUE":
+                                       case "FALSE":
+                                       case "SUPPLIED":
+
+                                               $d = db_auto_get_data( "SELECT * FROM  ".$f[1].$w." ORDER BY ".$s.";", $conn_str, FALSE, 500 );
+
+                                               if( !$d )
+                                                       {
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">No records from which to build picklist</FONT>';
+                                                       }
+                                                 else
+                                                       {
+                                                               // Create table of possibilities for pick list
+
+                                                       unset( $da );
+                                                       while( list($key, $val) = each($d) )
+                                                               {
+                                                               $da[$val[$value_field]] = $val[$f[2]];
+
+                                                                       // If {required} setting is "SUPPLIED"
+                                                               if( $field[3] == "SUPPLIED" &&  $val[$value_field] == $GLOBALS[$field[4]] )
+                                                                       $dkey = $val[$value_field];     // Get id of record we're refering to
+                                                               }
+
+                                                       $out[$outcount]["value"] = build_a_picklist( $field[0], $da, $dkey, "standard", $p );
+                                                       }
+
+                                                       // Provide an additional input field to permit adding a new target value
+
+                                               if( $pointer_option_add_field )
+                                                       $out[$outcount]["value"] .= '<NOBR> or add new value <INPUT TYPE="text" NAME="'.$field[0].'_add_field"></NOBR>';
+
+                                               break;
+
+                                               // These require us to just get the data for the specific index
+
+                                       case "DISPLAY":
+                                       case "HIDDEN":
+                                               if( empty($field[4]) )
+                                                       {
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Missing value for DISPLAY & HIDDEN</FONT>';
+                                                       break;
+                                                       }
+                                               $d = db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE ".$value_field." = ".$GLOBALS[$field[4]]." ORDER BY ".$s.";", 0, $conn_str, $fail_mode  );
+                                               if( !$d )
+                                                       {
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Specified value for DISPLAY/HIDDEN not found in table</FONT>';
+                                                       break;
+                                                       }
+                                                   else
+                                                       $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$d[$value_field].'">';
+
+                                               if( $field[3] == "DISPLAY" )    // If DISPLAY add the visible data after the hidden field
+                                                       {
+                                                       if( $f[5] == "checkbox" )
+                                                               $out[$outcount]["value"] .= ($d[$f[2]]=='t'?"Yes":"No");
+                                                           else
+                                                               $out[$outcount]["value"] .= $d[$f[2]];
+                                                       }
+
+                                               break;
+
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+                                       }
+                               break;
+
+                       case "list":
+                                       // If picklist options
+                               $p = !empty($f[3]) ? $f[3] : "" ;
+
+                               $option_table = "";
+                               $opts = explode_trim( "~", $f[1] );     // Separate list options
+                               $def_value = !empty($f[2]) ? $f[2] : "" ;
+                               foreach( $opts as $opt )
+                                       {
+                                       $os = explode_trim( "^", $opt );        // Separate value from displayed text
+                                       $option_table[$os[0]] = $os[1];
+                                       }
+                                       $out[$outcount]["value"] = build_a_picklist( $field[0], $option_table, $def_value, "standard", $p );
+                               if( $out[$outcount]["value"] == '' )
+                                       $out[$outcount]["value"] = '(no options listed)';
+                               break;
+
+                       case "state":           // Special case of list
+
+                               $out[$outcount]["value"] = build_a_picklist( $field[0], $GLOBALS['si_states_array'], $f[1], "standard", $f[2] );
+                               break;
+
+                       case "country":         // Special case of list
+
+                               $out[$outcount]["value"] = build_a_picklist( $field[0], $GLOBALS['si_countries_array'], $f[1], "standard", $f[2] );
+                               break;
+
+                       case "checkbox":
+                               switch( $field[3] )     // {required} setting
+                                       {
+                                       case "TRUE":
+                                       case "FALSE":
+                                               $out[$outcount]["value"] =  '<INPUT TYPE="checkbox" NAME="'.$field[0].'">';
+                                               break;
+
+                                       case "SUPPLIED":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="checkbox" NAME="'.$field[0].'" '.($GLOBALS[$field[4]]=="t"?"CHECKED":"").'>';
+                                               break;
+
+                                       case "HIDDEN":
+                                               $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$GLOBALS[$field[4]].'">';
+                                               break;
+
+                                       case "DISPLAY":
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">DISPLAY/HIDDEN not available for type checkbox at this time</FONT>';
+                                               break;
+
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+                                       }
+                               break;
+
+                       case "bitmap":
+
+                               $bmap = explode_trim( "~", $f[1] );
+                               $out[$outcount]["value"] = "";
+
+                               switch( $field[3] )     // {required} setting
+                                       {
+                                       case "TRUE":
+                                       case "FALSE":
+                                               for( $i=0 ; $i<count($bmap) ; $i++ )
+                                                       if( $bmap[$i] != '' )
+                                                               $out[$outcount]["value"] .= '<INPUT TYPE="checkbox" NAME="'.$field[0]."[$i]".'">'.$bmap[$i].'<BR>';
+                                               break;
+
+                                       case "SUPPLIED":
+                                       case "DISPLAY":
+                                       case "HIDDEN":
+                                               for( $i=0 ; $i<count($bmap) ; $i++ )
+                                                       if( $bmap[$i] != '' )
+                                                               {
+                                                               $x = $GLOBALS[$field[4]] & pow( 2, $i ) ? " CHECKED" : "";              // Check if this bit set in supplied value
+                                                               $out[$outcount]["value"] .= '<INPUT TYPE="checkbox" NAME="'.$field[0]."[$i]".'"'.$x.'>'.$bmap[$i].'<BR>';
+                                                               }
+                                               break;
+
+                                       default:
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                               break;
+                                       }
+                               if( $out[$outcount]["value"] == '' )
+                                       $out[$outcount]["value"] = '(no options listed)';
+                               break;
+
+                       case "break":
+                               if( !empty($f[1]) )     // if {t1} is supplied
+                                       $out[$outcount]["value"] = $f[1];
+                                   else
+                                       $out[$outcount]["value"] = '<FONT COLOR="red">No {text} supplied for type "break"</FONT>';
+                               break;
+
+                       default:
+                               $out[$outcount]["value"] = '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$f[0].' for '.$field[0].'</FONT>';
+                               break;
+
+                       } // switch( field )
+
+               $outcount++;
+               } // foreach( field )
+
+               // Build submit button and hidden action and put in {submit}
+
+       $submit = '
+                       <INPUT TYPE="hidden" NAME="Action" VALUE="'.$action.'">
+                       '.$form_params.'
+                       <INPUT TYPE="submit" NAME="Option" VALUE="Add New">
+            ';
+
+               // Replace parameters in Title
+
+       for( $i=0 ; $i<$outcount ; $i++ )
+               {
+               $a_title = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $a_title );
+               $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $a_title );
+               }
+
+       $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+       $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+
+               // Add QuickTip if provided
+
+       if( trim($quick_tip) != '' )
+               $a_title = quick_tip( $a_title, $quick_tip );
+
+               // Output results
+
+                       // Display top of page and open form
+
+       $ret .=  '<CENTER>
+               <FORM ENCTYPE="multipart/form-data" ACTION="'.$url.'" METHOD="post" ID="'.$form_name.'" NAME="'.$form_name.'">
+            ';
+
+       $hidden_data = '';
+       if( empty($view) )      // If there's no format spec in $view
+               {
+
+               $ret .=  $a_title.'
+                       <FONT COLOR="red">(Required fields in red)</FONT><BR>
+                       <TABLE BORDER="'.$borders.'" '.($borders>0?' CELLPADDING="5"':"").'>
+                    ';
+
+               for( $i=0 ; $i<$outcount ; $i++ )
+                       {
+                       if( $out[$i]["name"] != '' )
+                               $ret .=  '<TR><TH ALIGN="right" VALIGN="top">'.$out[$i]["name"]
+                                       .'&nbsp;</TH><TD ALIGN="left">'.$out[$i]["value"].'&nbsp;</TD></TR>
+                                    ';
+                         else
+                               $hidden_data .= $out[$i]["value"];
+                       }
+
+               $ret .=  '      <P>
+                       </TABLE>'.$hidden_data.$submit; // Output the Confirm field and submit button
+
+               }
+         else  // Otherwise use $view to output data
+               {
+               reset( $out );
+               while( list ($k, $v) = each($out) )
+                       {
+                       $a_title = ereg_replace( "\\{".$v['field']."\\}", $v["value"], $a_title );
+                       $view = ereg_replace( "\\{".$v['field']."\\}", $v["value"], $view );
+                       $a_title = ereg_replace( "\\{encode:".$v['field']."\\}", urlencode($v["value"]), $a_title );
+                       $view = ereg_replace( "\\{encode:".$v['field']."\\}", urlencode($v["value"]), $view );
+                       }
+
+               for( $i=0 ; $i<$outcount ; $i++ )
+                       {
+                       $view = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $view );
+                       $view = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $view );
+                       }
+               $view = ereg_replace( "\\{submit\\}", $submit, $view );
+               $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+               $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+               $ret .=  $a_title.$view;
+               }
+
+               // Display bottom of page and close form
+
+               // If HTMLArea is used, attach scripts to set that up to submit button tags
+
+       if( $richtext_used )
+               $ret .=  htmlarea_setup_script();
+
+       $ret .=  '      </FORM>
+               </CENTER>
+            ';
+
+       return( array( 'text' => $ret, 'status' => true ) );
+}
+
+function admin_new_record( $table, $conn_str, $fields, $url, $action, $params, $a_title, $view = "", $options = "", $quick_tip = "" )
+{
+       $r = admin_new_record_r( $table, $conn_str, $fields, $url, $action, $params, $a_title, $view, $options, $quick_tip );
+
+       echo $r['text'];
+       return( $r['status'] );
+
+}
+
+
+
+
+       // Add new record to a table
+
+function admin_add_new_record_r( $table, $conn_str, $fields, $url, $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+
+       $ret = '';
+
+               // Make all submitted parameters available
+
+//     extract($GLOBALS[HTTP_POST_VARS]);
+//     extract($GLOBALS[HTTP_GET_VARS]);
+//     extract($GLOBALS[HTTP_POST_FILES]);
+
+               // Break out configuration data
+
+       $field_table = explode_trim( "|", $fields );
+
+               // Don't be surprised if last field is blank
+
+       if( trim($field_table[count($field_table)-1]) == "" )
+               array_pop( $field_table );
+
+       foreach( $field_table as $key => $r )
+               $field_table[$key] = explode_trim( ",", $r );
+
+               // Check for additional parameters that are passed
+
+       if( !empty($params) )
+               {
+               $param = explode_trim( "|", $params );  // Separate parameters
+               $link_params = $form_params = "";
+               foreach( $param as $p )
+                       {
+                       $x = explode_trim( ".", $p );   // Separate Names from Values
+                       $link_params .= "&".$x[0]."=".urlencode($x[1]);
+                       $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+                       }
+               }
+
+       $names = $values = $not_supplied = $problem = "";
+
+               // For each field in the result
+
+       $comma = "";    // first parameter doesn't need a comma in front of it
+       $outcount = 0;
+       foreach( $field_table as $field )
+               {
+               $names .= $comma.$field[0];             // Add field name to $names for INSERT
+               $out[$outcount]["name"] = $field[0];    // Make name available to view
+               $f = explode_trim( ".", $field[1] );    // Break out optional parameters from field type
+               $fta = explode_trim( "~", $field[2] );
+               $field_title_only = $fta[0];
+
+               switch( $f[0] )
+                       {
+                       case "money":
+                       case "order":
+                       case "int":
+                       case "float":
+                       case "fixed":
+                       case "pointer":
+                       case "category":
+
+                                       // Handle special cases in this group of types
+
+                               switch( $f[0] )
+                                       {
+
+                                       case "money":
+
+                                                       // Get rid of "$" and "," from silly users
+
+                                               $GLOBALS[$field[4]] = ereg_replace( "[\$,]", "", $GLOBALS[$field[4]] );
+                                               break;
+
+                                       case "pointer":
+
+                                                       // Check for add_field values - Add new value to pointer target record
+
+                                               if( ($add_value = trim($GLOBALS[$field[4].'_add_field'])) != '' )
+                                                       {
+                                                               // If value already exists warn user.
+
+                                                       if( db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE ".$f[2]." = '".trim($GLOBALS[$field[4].'_add_field'])."';", 0, $conn_str, $fail_mode ) )
+                                                               $not_supplied .= $field_title_only.": Value already exists in pick list, don't try to add it again.<BR>";
+                                                         else
+                                                               {
+                                                                       // Otherwise, add new value and use pointer to that
+
+                                                               $add_result = db_auto_get_row( "INSERT INTO ".$f[1]." ( ".$f[2]." ) VALUES ( '".trim($GLOBALS[$field[4].'_add_field'])."' );
+                                                                                                                               SELECT currval( '".$f[1]."_id_seq' ) AS id;", 0, $conn_str, $fail_mode );
+                                                               $GLOBALS[$field[4]] = $add_result['id'];
+                                                               }
+                                                       }
+
+                                               break;
+
+                                       default:
+                                               break;
+                                       }
+
+
+                               $out[$outcount]["value"] = $GLOBALS[$field[4]];
+                               if( !empty($GLOBALS[$field[4]]) && !is_numeric($GLOBALS[$field[4]]) )
+                                       $not_supplied .= $field_title_only.': "'.$GLOBALS[$field[4]].'" Is not an Integer Number<BR>';
+
+                               switch( $field[3] )
+                                       {
+                                       case "SUPPLIED":
+                                               $values .= $comma.$GLOBALS[$field[4]];
+                                               break;
+
+                                       case "TRUE":
+                                               if( !is_numeric($GLOBALS[$field[4]]) )
+                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                 else
+                                                       $values .= $comma.$GLOBALS[$field[4]];
+                                               break;
+
+                                       case "FALSE":
+                                               if( is_numeric($GLOBALS[$field[4]]) )
+                                                       $values .= $comma.$GLOBALS[$field[4]];
+                                                 else
+                                                       $values .= $comma."0";  // Default to 0
+                                               break;
+
+                                       case "UNIQUE":
+                                               if( empty($GLOBALS[$field[4]]) && $GLOBALS[$field[4]] != 0 )
+                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                 else
+                                                       $values .= $comma.$GLOBALS[$field[4]];
+
+                                               if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = ".trim($GLOBALS[$field[4]]).";", 0, $conn_str, $fail_mode ) )
+                                                       $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                               break;
+
+                                       case "UNIQUE_NOT_REQ":
+                                               if( is_numeric($GLOBALS[$field[4]]) )
+                                                       $values .= $comma.$GLOBALS[$field[4]];
+                                                 else
+                                                       $values .= $comma."0";  // Default to 0
+
+                                               if( !empty($GLOBALS[$field[4]]) && $GLOBALS[$field[4]] != 0 && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = ".trim($GLOBALS[$field[4]]).";", 0, $conn_str, $fail_mode ) )
+                                                               $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+
+                                               break;
+
+                                       default:
+                                               $problem .=  '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+                                               break;
+                                       }
+                               break;
+
+
+                       case "lat":
+                                       // If we've been passed a decimal degree value
+                               if( !empty($GLOBALS[$field[4]]) )
+                                       $v = $GLOBALS[$field[4]];
+                                 else  // Otherwise compile from parts
+                                       {
+                                       if( $GLOBALS[$field[4].'_DEG'] > 90 || $GLOBALS[$field[4].'_DEG'] < 0 || $GLOBALS[$field[4].'_MIN'] >= 60 || $GLOBALS[$field[4].'_MIN'] < 0 )
+                                               {
+                                               $not_supplied .= $field_title_only.": Invalid entry. Degrees must be 0 to 90 and Minutes must be 0 to less than 60<BR>";
+                                               break;
+                                               }
+                                       $v = ( $GLOBALS[$field[4].'_NS'] == "N" ? 1 : -1 ) * ( $GLOBALS[$field[4].'_DEG'] + ( $GLOBALS[$field[4].'_MIN'] / 60 ) );
+                                       }
+                               $fw = 2;
+                                       // Rebuild value for display
+                               if( $f[1] > 0 )
+                                       $fw = $f[1];
+                               $ns = 'N';
+                               if( ($v2=$v) < 0 )
+                                       {
+                                       $ns = 'S';
+                                       $v2 = -1 * $v2;
+                                       }
+                               $dv = (int) $v2;
+                               $mv = ( $v2 - $dv ) * 60;
+                               $out[$outcount]["value"] = sprintf( "%s %d&deg; %01.".$fw."f'", $ns, $dv, $mv );
+                               switch( $field[3] )
+                                       {
+                                       case "SUPPLIED":
+                                               $values .= $comma.$v;
+                                               break;
+
+                                       case "TRUE":
+                                               if( empty($v) )
+                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                 else
+                                               $values .= $comma.$v;
+                                               break;
+
+                                       case "FALSE":
+                                               $values .= $comma.$v;
+                                               break;
+
+                                       case "UNIQUE":
+                                               if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+                                                       $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                               $values .= $comma.$v;
+                                               break;
+
+                                       case "UNIQUE_NOT_REQ":
+                                               if( !empty($GLOBALS[$field[4]]) && $GLOBALS[$field[4]] != 0 && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+                                                       $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                               $values .= $comma.$v;
+                                               break;
+
+                                       default:
+                                               $problem .=  '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                               break;
+                                       }
+                               break;
+
+                       case "lon":
+                                       // If we've been passed a decimal degree value
+                               if( !empty($GLOBALS[$field[4]]) )
+                                       $v = $GLOBALS[$field[4]];
+                                 else  // Otherwise compile from parts
+                                       {
+                                       if( $GLOBALS[$field[4].'_DEG'] > 180 || $GLOBALS[$field[4].'_DEG'] < 0 || $GLOBALS[$field[4].'_MIN'] >= 60 || $GLOBALS[$field[4].'_MIN'] < 0 )
+                                               {
+                                               $not_supplied .= $field_title_only.": Invalid entry. Degrees must be 0 to 180 and Minutes must be 0 to less than 60<BR>";
+                                               break;
+                                               }
+                                       $v = ( $GLOBALS[$field[4].'_NS'] == "E" ? 1 : -1 ) * ( $GLOBALS[$field[4].'_DEG'] + ( $GLOBALS[$field[4].'_MIN'] / 60 ) );
+                                       }
+                               $fw = 2;
+                                       // Rebuild value for display
+                               if( $f[1] > 0 )
+                                       $fw = $f[1];
+                               $ns = 'E';
+                               if( ($v2=$v) < 0 )
+                                       {
+                                       $ns = 'W';
+                                       $v2 = -1 * $v2;
+                                       }
+                               $dv = (int) $v2;
+                               $mv = ( $v2 - $dv ) * 60;
+                               $out[$outcount]["value"] = sprintf( "%s %d&deg; %01.".$fw."f'", $ns, $dv, $mv );
+                               switch( $field[3] )
+                                       {
+                                       case "SUPPLIED":
+                                               $values .= $comma.$v;
+                                               break;
+
+                                       case "TRUE":
+                                               if( empty($v) )
+                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                 else
+                                               $values .= $comma.$v;
+                                               break;
+
+                                       case "FALSE":
+                                               $values .= $comma.$v;
+                                               break;
+
+                                       case "UNIQUE":
+                                               if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+                                                       $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                               $values .= $comma.$v;
+                                               break;
+
+                                       case "UNIQUE_NOT_REQ":
+                                               if( !empty($GLOBALS[$field[4]]) && $GLOBALS[$field[4]] != 0 && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+                                                       $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                               $values .= $comma.$v;
+                                               break;
+
+                                       default:
+                                               $problem .=  '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                               break;
+                                       }
+
+                               break;
+
+
+                       case "list":
+                       case "text":
+                       case "inet":
+                       case "state":
+                       case "country":
+                       case "url":
+                       case "richtext":
+                       case "textbox":
+
+                                       // Check for special cases
+
+                               switch( $f[0] )
+                                       {
+                                       case "inet":
+                                               if( ($r = clean_input( $field[0], 'inet' )) != '' )
+                                                       $problem .= '<FONT COLOR="red">'.$field_title_only.': Not a valid IP address or netmask.</FONT><BR>';
+                                               break;
+
+                                       case "list":
+                                                       // If 'multi' is selected for picklist option, then compile results from array
+                                               if( strstr( $f[3], 'multi' ) )
+                                                       {
+                                                       $m_val = $sep = '';
+
+                                                               // Place results in '~' separated string for storage.
+
+                                                       if( is_array($GLOBALS[$field[4]]) )
+                                                               foreach( $GLOBALS[$field[4]] as $m )
+                                                                       {
+                                                                       $m_val .= $sep.$m;
+                                                                       $sep = '~';
+                                                                       }
+                                                       $GLOBALS[$field[4]] = $m_val;
+                                                       }
+
+                                               break;
+
+                                       default:
+                                               break;
+                                       }
+
+                               $v = str_replace( "%27", "\'", $GLOBALS[$field[4]] );
+                               if( trim(strip_tags($v)) == '' )
+                                       $v = '';
+                               $out[$outcount]["value"] = $v;
+                               switch( $field[3] )
+                                       {
+                                       case "SUPPLIED":
+                                               $values .= $comma."'".$v."'";
+                                               break;
+
+                                       case "TRUE":
+                                               if( empty($v) )
+                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                 else
+                                               $values .= $comma."'".$v."'";
+                                               break;
+
+                                       case "FALSE":
+                                               $values .= $comma."'".$v."'";
+                                               break;
+
+                                       case "UNIQUE":
+                                               if( empty($v) )
+                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                 else
+                                                       {
+                                                       if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($v)."';", 0, $conn_str, $fail_mode ) )
+                                                               $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                                       }
+                                               $values .= $comma."'".$v."'";
+                                               break;
+
+                                       case "UNIQUE_NOT_REQ":
+                                               if( !empty($v) )
+                                                       {
+                                                       if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($v)."';", 0, $conn_str, $fail_mode ) )
+                                                               $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                                       }
+                                               $values .= $comma."'".$v."'";
+                                               break;
+
+                                       default:
+                                               $problem .=  '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                               break;
+                                       }
+                               break;
+
+                       case "date":
+                               $out[$outcount]["value"] = $GLOBALS[$field[4]];
+
+                               if( trim($GLOBALS[$field[4]]) == "" )                           // Blank dates must be "NULL"
+                                       $dval = "NULL";
+                                 else
+                                       $dval = "'".$GLOBALS[$field[4]]."'";
+
+                               switch( $field[3] )
+                                       {
+                                       case "SUPPLIED":
+                                               $values .= $comma.$dval;
+                                               break;
+
+                                       case "TRUE":
+                                               if( empty($GLOBALS[$field[4]]) )
+                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                 else
+                                                       $values .= $comma.$dval;
+                                               break;
+
+                                       case "FALSE":
+                                               $values .= $comma.$dval;
+                                               break;
+
+                                       case "UNIQUE":
+                                               if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($GLOBALS[$field[4]])."';", 0, $conn_str, $fail_mode ) )
+                                                       $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                               $values .= $comma.$dval;
+                                               break;
+
+                                       case "UNIQUE_NOT_REQ":
+                                               if( !empty($GLOBALS[$field[4]]) && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($GLOBALS[$field[4]])."';", 0, $conn_str, $fail_mode ) )
+                                                       $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                               $values .= $comma.$dval;
+                                               break;
+
+                                       default:
+                                               $problem .=  '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                               break;
+                                       }
+                               break;
+
+                       case "multifield":
+
+                               $line = 0;
+                               $empty = TRUE;
+                               $m_data = array();
+
+                                       // Build array of data to store
+                               while( isset( $GLOBALS[$field[4].'_'.($line+1).'_1'] ) )
+                                       {
+                                       $line++;
+                                       if( trim($GLOBALS[$field[4].'_'.$line.'_1']) != '' )
+                                               {
+                                               $a = array();
+                                               for( $i=1 ; $i<=$f[1] ; $i++ )
+                                                       {
+                                                       $a[$i-1] = trim( str_replace("%27", "\'", $GLOBALS[$field[4].'_'.($line).'_'.$i] ) );
+                                                       if( $a[$i-1] != '' )
+                                                               $empty = FALSE;
+                                                       }
+                                               array_push( $m_data, $a );
+                                               }
+                                       }
+
+                               if( !$empty )
+                                       $v = serialize( $m_data );
+                                 else
+                                       $v = '';
+
+                               $out[$outcount]["value"] = $v;
+
+                               switch ($field[3])
+                                       {
+                                       case "TRUE" :
+                                               if( $empty )
+                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                               else
+                                                       $values .= $comma."'".$v."'";
+                                               break;
+
+                                       case "FALSE" :
+                                               $values .= $comma."'".$v."'";
+                                               break;
+
+                                       default :
+                                               $problem .=  '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                               break;
+                                       }
+
+                               break;
+
+                       case "image":
+
+                               $out[$outcount]["value"] = "IMAGES Not Available for View at this time";
+                               switch( $field[3] )
+                                       {
+                                       case "SUPPLIED":
+                                               $problem .=  '<FONT COLOR="red">ERROR: "SUPPLIED" not permitted as option for image input</FONT><BR>';
+                                               break;
+
+                                       case "TRUE":
+                                               if( $GLOBALS[$field[4]."_name"] == "" )
+                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                               // no break; here - falls through to FALSE
+
+                                       case "FALSE":
+                                               if( $GLOBALS[$field[4]."_name"] != "" )
+                                                       $values .= $comma."'".process_image( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"] )."'";
+                                                   else
+                                                       $values .= $comma."''";
+                                               break;
+
+                                       default:
+                                               $problem .=  '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                               break;
+                                       }
+                               break;
+
+                       case "images":
+
+                               // Note that the image field is only updated when required so field name is set below along with value
+
+                               $out[$outcount]["value"] = "IMAGES Not Available for View at this time";
+                               switch( $field[3] )
+                                       {
+                                       case "FALSE":
+                                               if( is_array( ($im_data = $GLOBALS[$field[4]]) ) )
+                                                       {
+                                                       $im_cur = unserialize( $data[$field[0]] );              // Convert existing data to an array
+                                                       $im_new = array();
+                                                       $im_new_num = 0;
+                                                       for( $im_num=0 ; $im_num<count($GLOBALS[$field[0]."_name"]) ; $im_num++ )
+                                                               {
+                                                                       // If new image is supplied, store it
+                                                               if( $GLOBALS[$field[0]."_name"][$im_num] != "" )
+                                                                       {
+//                                                                     if( $im_cur[$im_num]['filename'] )              // If there's already an image, delete it before storing the new one
+//                                                                             delete_image( $im_cur[$im_num]['filename'] );
+                                                                       $im_new[$im_new_num]['filename'] = process_image( $GLOBALS[$field[0]][$im_num], $GLOBALS[$field[0]."_name"][$im_num] );
+                                                                       $im_new[$im_new_num]['descr'] = $GLOBALS[$field[0].'_DESCR'][$im_num];
+                                                                       $im_new[$im_new_num]['align'] = $GLOBALS[$field[0].'_ALIGN'][$im_num];
+                                                                       $im_new[$im_new_num]['size'] = $GLOBALS[$field[0].'_SIZE'][$im_num];
+                                                                       $im_new_num++;
+                                                                       }
+
+
+//                                                                             // Else, if there's an image in the database and we're deleting
+//                                                               elseif( $im_cur[$im_num]['filename'] != "" && isset( $GLOBALS[$field[0]."_DELETE"][$im_num] )  )
+//                                                                     delete_image( $im_cur[$im_num]['filename'] );
+//                                                               elseif( $im_cur[$im_num]['filename'] != "" )
+//                                                                     {
+//                                                                     $im_new[$im_new_num]['filename'] = $im_cur[$im_num]['filename'];
+//                                                                     $im_new[$im_new_num]['descr'] = $GLOBALS[$field[0].'_DESCR'][$im_num];
+//                                                                     $im_new[$im_new_num]['align'] = $GLOBALS[$field[0].'_ALIGN'][$im_num];
+//                                                                     $im_new[$im_new_num]['size'] = $GLOBALS[$field[0].'_SIZE'][$im_num];
+//                                                                     $im_new_num++;
+//                                                                     }
+
+
+                                                               }
+                                                       $values .= $comma."'".serialize( $im_new )."'";
+                                                       }
+
+                                               break;
+
+                                       case "TRUE":
+                                       case "SUPPLIED":
+                                       default:
+                                               $problem .=  '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                               break;
+                                       }
+                               break;
+
+                       case "file":
+
+                               $out[$outcount]["value"] = "FILES Not Available for View at this time";
+                               switch( $field[3] )
+                                       {
+                                       case "SUPPLIED":
+                                               $problem .=  '<FONT COLOR="red">ERROR: "SUPPLIED" not permitted as option for file input</FONT><BR>';
+                                               break;
+
+                                       case "TRUE":
+                                               if( $GLOBALS[$field[4]."_name"] == "" )
+                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                               // no break; here - falls through to FALSE
+
+                                       case "FALSE":
+                                               if( $GLOBALS[$field[4]."_name"] != "" )
+                                                       {
+                                                       if( isset( $f[1] ) && $f[1] != "" && !eregi( ".".$f[1]."$",$GLOBALS[$field[4]."_name"]) )
+                                                               $not_supplied .= $field_title_only.': "'.$GLOBALS[$field[4]."_name"].'" is not correct file type. Must be:  '.$f[1]."<BR>";
+                                                           else
+                                                               $values .= $comma."'". file_upload( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"], SI_BASE_FILE_PATH )."'";
+                                                       }
+                                                   else
+                                                       $values .= $comma."''";
+                                               break;
+
+                                       default:
+                                               $problem .=  '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                               break;
+                                       }
+                               break;
+
+                       case "checkbox":
+                               if( $GLOBALS[$field[4]] == "on" )
+                                       {
+                                       $out[$outcount]["value"] = "Yes";
+                                       $values .= $comma."'t'";
+                                       }
+                                   else
+                                       {
+                                       $out[$outcount]["value"] = "No";
+                                       $values .= $comma."'f'";
+                                       }
+                               break;
+
+                       case "bitmap":
+                               $out[$outcount]["value"] = "Bitmaps not available for view at this time";
+                               $b = 0;         // Start with clear bitmap
+                               for( $i=0 ; $i<SI_INT_SIZE ; $i++ )             // Bitmaps are based on the size of an integer
+                                       {
+                                       if( isset($GLOBALS[$field[4]][$i]) && $GLOBALS[$field[4]][$i] == "on" ) // If checked
+                                               $b = $b + pow(2,$i);                    // Set bit
+                                       }
+
+                               $values .= $comma.$b;
+                               break;
+
+                       default:
+                               $ret .=  '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$field[1].' for '.$field[0].'</FONT><BR>';
+                               break;
+
+                       } // switch( field )
+
+               $comma = ", ";  // All subsequent names/values must have a preceeding comma
+
+               $outcount++;
+               } // foreach( field )
+
+               // Replace parameters in Title
+
+       for( $i=0 ; $i<$outcount ; $i++ )
+               {
+               $a_title = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $a_title );
+               $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $a_title );
+               }
+
+       $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+       $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+
+               // Add QuickTip if provided
+
+       if( trim($quick_tip) != '' )
+               $a_title = quick_tip( $a_title, $quick_tip );
+
+       $oid = 0;       // Assume we don't get anything
+
+       $ok_to_save = true;
+
+       if( !empty($not_supplied) )
+               {
+               $results .= '
+                       <H2>Required fields not supplied</H2><P>
+                       <FONT COLOR="red">'.$not_supplied.'</FONT><P>
+                       Use "BACK" button on browser, add missing data and resubmit.<P>
+                    ';
+               $ok_to_save = false;
+               }
+
+       if( !empty($problem) )
+               {
+               $results .= $problem.'<P>
+                       Use "BACK" button on browser, correct problem field, and resubmit.<P>
+                       ';
+               $ok_to_save = false;
+               }
+
+       if( $ok_to_save )
+               {
+               $results = '&nbsp<P><H2>New data saved.</H2><P>';
+               $qs = "INSERT INTO $table ($names) VALUES ($values);";
+               if( SI_DEBUG >= 1 ) $ret .=  "<PRE>admin_add_new_record()[".__LINE__."]: Query String = $qs</PRE><BR>";
+               $oid = db_auto_exec( $qs, $conn_str, FALSE );
+               }
+
+               // Display top of page
+
+       $ret .=  '<CENTER>
+               '.$a_title.'
+            ';
+
+       if( empty($view) )      // If there's no spec in $view
+               $ret .=  $results;
+           else
+               {
+               for( $i=0 ; $i<$outcount ; $i++ )
+                       {
+                       $view = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $view );
+                       $view = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $view );
+                       }
+               $view = ereg_replace( "\\{results\\}", $results, $view );
+               $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+               $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+               $ret .=  $view;
+               }
+
+       $ret .=  '
+               </CENTER>
+            ';
+
+       $d = db_auto_get_row( "SELECT id FROM $table WHERE oid = $oid;" );
+       $id = $d['id'];
+
+       return( array( 'text' => $ret, 'status' => $oid, 'id' => $id ) );
+}
+
+function admin_add_new_record( $table, $conn_str, $fields, $url, $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+       $r = admin_add_new_record_r( $table, $conn_str, $fields, $url, $action, $params, $a_title, $view, $quick_tip );
+       echo $r['text'];
+       return( $r['status'] );
+}
+
+
+
+
+       // Edit a record
+
+function admin_edit_record_r( $table, $conn_str, $id, $fields, $url, $action,
+                       $params, $a_title, $view = "", $options = "", $quick_tip = "" )
+{
+
+       $ret = '';
+
+       $form_name = "admin_new_form";
+       $richtext_used = FALSE;
+
+               // Check for any options
+
+       $borders = strstr( $options, "borders" ) == FALSE ? 0 : 1;
+
+               // Check for additional parameters that are passed
+
+       if( !empty($params) )
+               {
+               $param = explode_trim( "|", $params );  // Separate parameters
+               $link_params = $form_params = "";
+               foreach( $param as $p )
+                       {
+                       $x = explode_trim( ".", $p );   // Separate Names from Values
+                       $link_params .= "&".$x[0]."=".urlencode($x[1]);
+                       $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+                       }
+               }
+
+
+               // Get the data
+
+       $query_string = "SELECT * FROM ".$table." WHERE id = ".$id.";";
+       if( SI_DEBUG >= 1 ) $ret .=  "<PRE>admin_edit_record()[".__LINE__."]: Query String = $query_string</PRE><BR>";
+       $data = db_auto_get_row( $query_string, 0, $conn_str, $fail_mode );
+
+       if( $data )
+               {
+
+                       // Break out configuration data
+
+               $field_table = explode_trim( "|", $fields );
+
+                       // Don't be surprised if last field is blank
+
+               if( trim($field_table[count($field_table)-1]) == "" )
+                       array_pop( $field_table );
+
+               foreach( $field_table as $key => $r )
+                       $field_table[$key] = explode_trim( ",", $r );
+
+                       // For each field in the result
+
+               $outcount = 0;
+               foreach( $field_table as $field )
+                       {
+
+                               // Display title fields
+                       $out[$outcount]["hidden"] = FALSE;
+
+                               // Check for pop-up-tips
+
+                       $n = explode_trim( '~', $field[2] );
+
+                       $field_name_color = 'black';
+
+                       switch( $field[3] )
+                               {
+                               case "TRUE":
+                               case "UNIQUE":
+                                       $field_name_color = 'red';
+                               case "FALSE":
+                               case "DISPLAY":
+                               case "UNIQUE_NOT_REQ":
+
+                                               // setup tip display - requires show_QuickTip() and hide_QuickTip() functions from java_functions.js
+
+                                       if( count($n) > 1 )
+                                               $out[$outcount]["name"] = quick_tip( '<font color="'.$field_name_color.'">'.$n[0].'</font>', $n[1] );
+                                         else
+                                               $out[$outcount]["name"] = '<FONT COLOR="'.$field_name_color.'">'.$field[2].'</FONT>';
+
+                                       break;
+                               case "SUPPLIED":
+                                        $out[$outcount]["name"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$field[4].'">';
+                                       break;
+                               case "HIDDEN":
+                                       $out[$outcount]["name"] = '';
+                                       $out[$outcount]["hidden"] = TRUE;
+                                       break;
+                               default:
+                                       $out[$outcount]["name"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                       break;
+                               }
+
+                               // Display input fields
+                       $f = explode_trim( ".", $field[1] );
+                       switch( $f[0] )
+                               {
+                               case "money":
+                               case "int":
+                               case "text":
+                               case "inet":
+                               case "url":
+                               case "order":
+                               case "float":
+                               case "fixed":
+                                       $prefix = "";
+                                       $s = $f[1];
+                                       $v = $data[$field[0]];
+                                       $prefix = "";
+
+                                       if( $f[0] == "money" )  // If it's money, default to 0.00
+                                               {
+                                               $v = sprintf( "%01.2f", $data[$field[0]] );
+                                               $prefix = "$";
+                                               }
+
+                                       if( $f[0] == "fixed" )  // If it's fixed, set precision
+                                               {
+                                               $v = sprintf( "%01.".$f[1]."f", $data[$field[0]] );
+                                               $s = $f[1] + 4;
+                                               }
+
+                                       switch( $field[3] )
+                                               {
+                                               case "TRUE":
+                                               case "FALSE":
+                                               case "UNIQUE":
+                                               case "UNIQUE_NOT_REQ":
+                                                       $out[$outcount]["value"] = $prefix.'<INPUT TYPE="text" NAME="'.$field[0].'" SIZE="'.$s.'" VALUE="'.htmlentities($v).'">';
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISPLAY":
+                                                       $out[$outcount]["value"] = $prefix.$v;
+                                                       break;
+
+                                               case "SUPPLIED":
+                                                       $out[$outcount]["value"] = "";
+                                                       break;
+
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+
+                                               }
+                                       break;
+
+                               case "lat":
+                                       $fw = 2;
+                                       if( $f[1] > 0 )
+                                               $fw = $f[1];
+
+                                       switch( $field[3] )     // {required} setting
+                                               {
+                                               case "TRUE":
+                                               case "UNIQUE":
+                                               case "UNIQUE_NOT_REQ":
+                                               case "FALSE":
+                                               case "DISPLAY":
+                                                       $ns = 'N';
+                                                       if( $data[$field[0]] < 0 )
+                                                               {
+                                                               $ns = 'S';
+                                                               $data[$field[0]] = -1 * $data[$field[0]];
+                                                               }
+                                                       $dv = (int) $data[$field[0]];
+                                                       $mv = ( $data[$field[0]] - $dv ) * 60;
+                                                       if( $field[3] != "DISPLAY" )
+                                                               $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="N" '.($ns=='N'?'SELECTED':'').'>North<OPTION VALUE="S" '.($ns=='S'?'SELECTED':'').'>South</SELECT>
+                                                                       <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="'.$dv.'" SIZE="4" MAXLENGTH="2" ALIGN="right">&deg;
+                                                                       <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", $mv ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+                                                         else
+                                                               $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$data[$field[0]].'">'
+                                                                               .sprintf( "<NOBR>%s %d&deg; %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+                                                       break;
+
+                                               case "HIDDEN":
+                                                       $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$data[$field[0]].'">';
+                                                       break;
+
+                                               case "SUPPLIED":
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+                                               }
+                                       break;
+
+                               case "lon":
+                                       $fw = 2;
+                                       if( $f[1] > 0 )
+                                               $fw = $f[1];
+
+                                       switch( $field[3] )     // {required} setting
+                                               {
+                                               case "TRUE":
+                                               case "UNIQUE":
+                                               case "UNIQUE_NOT_REQ":
+                                               case "FALSE":
+                                               case "DISPLAY":
+                                                       $ns = 'E';
+                                                       if( $data[$field[0]] < 0 )
+                                                               {
+                                                               $ns = 'W';
+                                                               $data[$field[0]] = -1 * $data[$field[0]];
+                                                               }
+                                                       $dv = (int) $data[$field[0]];
+                                                       $mv = ( $data[$field[0]] - $dv ) * 60;
+                                                       if( $field[3] != "DISPLAY" )
+                                                               $out[$outcount]["value"] = '<SELECT NAME="'.$field[0].'_NS"><OPTION VALUE="W" '.($ns=='W'?'SELECTED':'').'>West<OPTION VALUE="E" '.($ns=='E'?'SELECTED':'').'>East</SELECT>
+                                                                       <INPUT TYPE="text" NAME="'.$field[0].'_DEG" VALUE="'.$dv.'" SIZE="4" MAXLENGTH="3" ALIGN="right">&deg;
+                                                                       <INPUT TYPE="text" NAME="'.$field[0].'_MIN" VALUE="'.sprintf( "%01.".$fw."f", $mv ).'" SIZE="'.(3+$fw).'" ALIGN="right">\'';
+                                                         else
+                                                               $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$data[$field[0]].'">'
+                                                                               .sprintf( "<NOBR>%s %d&deg; %01.".$fw."f'</NOBR>", $ns, $dv, $mv );
+                                                       break;
+
+                                               case "HIDDEN":
+                                                       $out[$outcount]["value"] = '<INPUT TYPE="hidden" NAME="'.$field[0].'" VALUE="'.$data[$field[0]].'">';
+                                                       break;
+
+                                               case "SUPPLIED":
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+                                               }
+                                       break;
+
+                               case "date":
+
+                                       $date_f = !empty( $f[1] ) ? time()-$f[1]*86400 : time() ;       // Set datestamp of first day to allow
+                                       $date_t = !empty( $f[2] ) ? time()+$f[2]*86400 : time() ;       // Set datestamp of last day to allow
+
+                                       switch( $field[3] )
+                                               {
+                                               case "TRUE":
+                                               case "FALSE":
+                                                       $out[$outcount]["value"] = calendar_date_select( $data[$field[0]], strtotime($data[$field[0]]), $date_f, $date_t, $form_name, $field[0], $f[3], $f[4] );
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISPLAY":
+                                                       $out[$outcount]["value"] = $data[$field[0]];
+                                                       break;
+
+                                               case "SUPPLIED":
+                                                       $out[$outcount]["value"] = "";
+                                                       break;
+
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+                                               }
+                                       break;
+
+                               case "richtext":
+                                       switch( $field[3] )
+                                               {
+                                               case "TRUE":
+                                               case "FALSE":
+                                                       if( SI_RICHTEXT_TYPE_ENABLED )
+                                                               {
+                                                               if( !$richtext_used  )
+                                                                       {
+                                                                       include_once( SI_BASE_PATH.'/glm_apps/HTMLArea/glm_functions_support.inc' );
+                                                                       $richtext_used = TRUE;
+                                                                       }
+                                                               $ew = ( trim($f[1]) != "" ? $f[1] : SI_DEFAULT_RICHTEXT_WIDTH );
+                                                               $eh = ( trim($f[2]) != "" ? $f[2] : SI_DEFAULT_RICHTEXT_HEIGHT );
+                                                               htmlarea_add_field( $field[0], $ew, $eh );
+                                                               $out[$outcount]["value"] = '<TABLE BORDER="1" WIDTH="'.$ew.'"><TR><TD><TEXTAREA ID="'.$field[0].'" NAME="'.$field[0].'" COLS="60" ROWS="5">'.rawurldecode( $data[$field[0]] ).'</TEXTAREA></TD></TR></TABLE>';
+                                                               }
+                                                         else
+                                                               $out[$outcount]["value"] = '<TEXTAREA ID="'.$field[0].'" NAME="'.$field[0].'" COLS="60" ROWS="5">'.rawurldecode( $data[$field[0]] ).'</TEXTAREA>';
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISPLAY":
+                                                       $out[$outcount]["value"] = $data[$field[0]];
+                                                       break;
+
+                                               case "SUPPLIED":
+                                                       $out[$outcount]["value"] = "";
+                                                       break;
+
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+                                               }
+                                       break;
+
+                               case "textbox":
+                                       switch( $field[3] )
+                                               {
+                                               case "TRUE":
+                                               case "FALSE":
+                                                       if( isset($f[1]) )
+                                                               {
+                                                               $cols = $f[1];
+                                                               $rows = $f[2];
+                                                               }
+                                                         else
+                                                               {
+                                                               $cols = SI_DEFAULT_TEXTBOX_COLS;
+                                                               $rows = SI_DEFAULT_TEXTBOX_ROWS;
+                                                               }
+                                                       $out[$outcount]["value"] = '<TEXTAREA NAME="'.$field[0].'" COLS="'.$cols.'" ROWS="'.$rows.'">'.$data[$field[0]].'</TEXTAREA>';
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISPLAY":
+                                                       $out[$outcount]["value"] = rawurldecode( $data[$field[0]] );
+                                                       break;
+
+                                               case "SUPPLIED":
+                                                       $out[$outcount]["value"] = "";
+                                                       break;
+
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+                                               }
+                                       break;
+
+                               case "multifield":              // NOT TESTED  multitext.numb_fields.new_line_string
+
+                                               // THIS FIELD TYPE REQUIRES java_functions.js
+
+                                       switch( $field[3] )
+                                               {
+                                               case "TRUE":
+                                               case "FALSE":
+                                                       $out[$outcount]["value"] = '<input type="hidden" name="'.$field[0].'_text" id="'.$field[0].'_text" value="'.$f[2].'">
+                                                                                                               <span id="'.$field[0].'_fields">';
+
+                                                               // If there's data, then build existing input lines with data
+                                                       if( ( $x = trim($data[$field[0]]) ) != '' )
+                                                               {
+                                                               $field_data = unserialize( $data[$field[0]] );
+
+                                                               if( $field_data != false && is_array( $field_data ) )
+                                                                       {
+                                                                               // For each line of inputs
+                                                                       for( $i=1 ; $i<=count($field_data) ; $i++ )
+                                                                               {
+                                                                               $f_line = str_replace( '{line_numb}', $i, $f[2] );              // Set line number in output text
+                                                                                       // For each input field on the line
+                                                                               for( $j=1 ; $j<=$f[1] ; $j++ )
+                                                                                       $f_line = str_replace( '{field_'.($j).'}', '<input type="text" name="'.$field[0].'_'.$i.'_'.$j.'" id="'.$field[0].'_'.$i.'_'.$j.'" value="'.$field_data[$i-1][$j-1].'" onKeyUp="multi_fields(\''.$field[0].'\',this,'.$f[1].');">', $f_line );
+
+                                                                               $out[$outcount]["value"] .= $f_line."\n";
+                                                                               }
+                                                                       }
+
+                                                               }
+                                                         else
+                                                               $i = 1;         // If no data blank line is #1
+
+                                                               // Build 1 spare input line
+                                                       $f_line = str_replace( '{line_numb}', $i, $f[2] );              // Set line number in output text
+                                                       for( $j=1 ; $j<=$f[1] ; $j++ )
+                                                               $f_line = str_replace( '{field_'.$j.'}', '<input type="text" name="'.$field[0].'_'.$i.'_'.$j.'" id="'.$field[0].'_'.$i.'_'.$j.'" value="" onKeyUp="multi_fields(\''.$field[0].'\',this,'.$f[1].');">', $f_line );
+                                                       $out[$outcount]["value"] .= $f_line."\n</span>";
+
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISLPLAY":
+                                               case "SUPPLIED":
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+
+                                               }
+                                       break;
+
+                               case "image":
+                                       switch( $field[3] )
+                                               {
+                                               case "TRUE":
+                                               case "FALSE":
+                                                       $out[$outcount]["value"] = '<TABLE BORDER="1">';
+
+                                                       if( $data[$field[0]] != "" )    // If an image already exists
+                                                               {
+                                                               $out[$outcount]["value"] .= '   <TR>
+                                                                               <TD VALIGN="middle"><IMG SRC="'.SI_IMG_THUMB_URL."/".$data[$field[0]].'"></TD>
+                                                                               <TD VALIGN="middle">';
+
+                                                               if( $field[3] == "TRUE" )       // If this field is required
+                                                                       $out[$outcount]["value"] .= 'This image may be replaced using the input field below.';
+                                                                   else
+                                                                       $out[$outcount]["value"] .= '<INPUT TYPE="checkbox" NAME="'.$field[0].'_DELETE"> Delete this image';
+
+                                                               $out[$outcount]["value"] .= '           </TD></TR>';
+                                                               }
+
+                                                       $out[$outcount]["value"] .= '           <TR>
+                                                                               <TD COLSPAN="2" VALIGN="middle"><INPUT TYPE="file" NAME="'.$field[0].'"></TD>
+                                                                       </TR>
+                                                               </TABLE>';
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISLPLAY":
+                                                       $out[$outcount]["value"] = '<IMG SRC="'.SI_IMG_THUMB_URL."/".$data[$field[0]].'">';
+                                                       break;
+
+                                               case "SUPPLIED":
+                                                       $out[$outcount]["value"] = "";
+                                                       break;
+
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+
+                                               }
+                                       break;
+
+                               case "multitext":               // NOT TESTED  multitext.{size}.{spares}
+
+                                       switch( $field[3] )
+                                               {
+                                               case "TRUE":
+                                               case "FALSE":
+                                                       $out[$outcount]["value"] = '';
+                                                       $txt_num = 0;
+
+                                                       if( ( $x = trim($data[$field[0]]) ) != '' )
+                                                               {
+                                                               $txt_data = unserialize( $data[$field[0]] );
+
+                                                                       // Do existing images
+
+                                                               foreach( $txt_data as $txt )
+                                                                       {
+                                                                       $out[$outcount]["value"] .= '#'.($txt_num+1).'&nbsp;<INPUT TYPE="text" NAME="'.$field[0].'_DESCR['.$im_num.']" SIZE="'.$f[1].'" VALUE="'.$txt_data[$txt_num].'"><BR>';
+                                                                       $im_num++;
+                                                                       }
+                                                               }
+
+                                                       if( empty($f[1]) )
+                                                               $spare = 2;
+                                                         else
+                                                               $spare = $f[2];
+                                                       for( $i=0 ; $i<$spare ; $i++ )
+                                                               {
+                                                               $out[$outcount]["value"] .= '#'.($txt_num+1).'&nbsp;<INPUT TYPE="text" NAME="'.$field[0].'_DESCR['.$im_num.']" SIZE="'.$f[1].'" VALUE="'.$txt_data[$txt_num].'"><BR>';
+                                                               $im_num++;
+                                                               }
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISLPLAY":
+                                               case "SUPPLIED":
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+
+                                               }
+                                       break;
+
+                               case "images":
+
+                                       switch( $field[3] )
+                                               {
+                                               case "TRUE":
+                                               case "FALSE":
+                                                       $out[$outcount]["value"] = '';
+                                                       $im_num = 0;
+
+                                                       if( ( $x = trim($data[$field[0]]) ) != '' )
+                                                               {
+                                                               $im_data = unserialize( $data[$field[0]] );
+                                                               $im_des = strstr( $f[2], 'descr' );
+                                                               $im_align = strstr( $f[2], 'align' );
+                                                               $im_size = strstr( $f[2], 'size' );
+                                                               if( !empty( $f[3] ) )
+                                                                       $im_des_s = $f[3];
+                                                                 else
+                                                                       $im_des_s = 40;
+                                                               if( !empty( $f[4] ) )
+                                                                       $im_des_t = $f[4];
+                                                                 else
+                                                                       $im_des_t = "Text";
+
+                                                                       // Do existing images
+
+                                                               foreach( $im_data as $im )
+                                                                       {
+                                                                       $out[$outcount]["value"] .= '
+                                                                               Image #'.($im_num+1).'<BR>
+                                                                               <TABLE BORDER="1">
+                                                                                       <TR>
+                                                                                               <TD VALIGN="middle"><IMG SRC="'.SI_IMG_THUMB_URL."/".$im_data[$im_num]['filename'].'"></TD>
+                                                                                               <TD VALIGN="middle">
+                                                                                                       This image may be replaced using the input field below.<BR>
+                                                                                                       Or you may <INPUT TYPE="checkbox" NAME="'.$field[0].'_DELETE['.$im_num.']"> Delete this image.
+                                                                                                       <P>
+                                                                                               '.( $im_align ? '
+                                                                                                       Align image
+                                                                                                       <SELECT NAME="'.$field[0].'_ALIGN['.$im_num.']">
+                                                                                                               <OPTION VALUE="Left"'.($im_data[$im_num]['align']=="Left"?" SELECTED":"").'>Left
+                                                                                                               <OPTION VALUE="Right"'.($im_data[$im_num]['align']=="Right"?" SELECTED":"").'>Right
+                                                                                                               <OPTION VALUE="Top"'.($im_data[$im_num]['align']=="Top"?" SELECTED":"").'>Top
+                                                                                                               <OPTION VALUE="Middle"'.($im_data[$im_num]['align']=="Middle"?" SELECTED":"").'>Middle
+                                                                                                               <OPTION VALUE="Bottom"'.($im_data[$im_num]['align']=="Bottom"?" SELECTED":"").'>Bottom
+                                                                                                       </SELECT>
+                                                                                                       ' : '<INPUT TYPE="hidden" NAME="align" VALUE="">' ).'
+                                                                                               '.( $im_size ? '
+                                                                                                       Size
+                                                                                                       <SELECT NAME="'.$field[0].'_SIZE['.$im_num.']">
+                                                                                                               <OPTION VALUE="Original"'.($im_data[$im_num]['size']=="Original"?" SELECTED":"").'>Original
+                                                                                                               <OPTION VALUE="Resized"'.($im_data[$im_num]['size']=="Resized"?" SELECTED":"").'>Resized (width='.SI_RESIZED_SIZE.')
+                                                                                                               <OPTION VALUE="Midsized"'.($im_data[$im_num]['size']=="Midsized"?" SELECTED":"").'>Midsized (width='.SI_MIDSIZED_SIZE.')
+                                                                                                               <OPTION VALUE="Thumb"'.($im_data[$im_num]['size']=="Thumb"?" SELECTED":"").'>Thumb (width='.SI_THUMB_SIZE.')
+                                                                                                       </SELECT>
+                                                                                                       ' : '<INPUT TYPE="hidden" NAME="size" VALUE="">' ).'
+                                                                                               </TD>
+                                                                                       </TR>
+                                                                                       <TR>
+                                                                                               <TD COLSPAN="2" VALIGN="middle">Select Image <INPUT TYPE="file" NAME="'.$field[0].'['.$im_num.']"></TD>
+                                                                                       </TR>
+                                                                                       '.( $im_des ? '<TR><TD COLSPAN="2">'.$im_des_t.' <INPUT TYPE="text" NAME="'.$field[0].'_DESCR['.$im_num.']" SIZE="'.$im_des_s.'" VALUE="'.$im_data[$im_num]['descr'].'"></TD>' : '' ).'
+                                                                                </TABLE>
+                                                                                <BR>';
+                                                                       $im_num++;
+                                                                       }
+                                                               }
+
+                                                       if( empty($f[1]) )
+                                                               $spare = 2;
+                                                         else
+                                                               $spare = $f[1];
+                                                       for( $i=0 ; $i<$spare ; $i++ )
+                                                               {
+                                                               $out[$outcount]["value"] .= '
+                                                                       Image #'.($im_num+1).'<BR>
+                                                                       <TABLE BORDER="1">
+                                                                               <TR>
+                                                                                       <TD COLSPAN="2" VALIGN="middle"><INPUT TYPE="file" NAME="'.$field[0].'['.$im_num.']">
+                                                                                               '.( $im_align ? '
+                                                                                                       Align image <SELECT NAME="'.$field[0].'_ALIGN['.$im_num.']">
+                                                                                                               <OPTION VALUE="Left"'.($im_data[$im_num]['align']=="Left"?" SELECTED":"").'>Left
+                                                                                                               <OPTION VALUE="Right"'.($im_data[$im_num]['align']=="Right"?" SELECTED":"").'>Right
+                                                                                                               <OPTION VALUE="Top"'.($im_data[$im_num]['align']=="Top"?" SELECTED":"").'>Top
+                                                                                                               <OPTION VALUE="Middle"'.($im_data[$im_num]['align']=="Middle"?" SELECTED":"").'>Middle
+                                                                                                               <OPTION VALUE="Bottom"'.($im_data[$im_num]['align']=="Bottom"?" SELECTED":"").'>Bottom
+                                                                                                       </SELECT>
+                                                                                                       ' : '<INPUT TYPE="hidden" NAME="align" VALUE="">' ).'
+                                                                                               '.( $im_align ? '
+                                                                                                       Size
+                                                                                                       <SELECT NAME="'.$field[0].'_SIZE['.$im_num.']">
+                                                                                                               <OPTION VALUE="Original"'.($im_data[$im_num]['size']=="Original"?" SELECTED":"").'>Original
+                                                                                                               <OPTION VALUE="Resized"'.($im_data[$im_num]['size']=="Resized"?" SELECTED":"").'>Resized (width='.SI_RESIZED_SIZE.')
+                                                                                                               <OPTION VALUE="Midsized"'.($im_data[$im_num]['size']=="Midsized"?" SELECTED":"").'>Midsized (width='.SI_MIDSIZED_SIZE.')
+                                                                                                               <OPTION VALUE="Thumb"'.($im_data[$im_num]['size']=="Thumb"?" SELECTED":"").'>Thumb (width='.SI_THUMB_SIZE.')
+                                                                                                       </SELECT>
+                                                                                                       ' : '<INPUT TYPE="hidden" NAME="size" VALUE="">' ).'
+                                                                                               </TD>
+                                                                               </TR>
+                                                                               '.( $im_des ? '<TR><TD COLSPAN="2">'.$im_des_t.' <INPUT TYPE="text" NAME="'.$field[0].'_DESCR['.$im_num.']" SIZE="'.$im_des_s.'"></TD>' : '' ).'
+                                                                        </TABLE>
+                                                                        <BR>';
+                                                               $im_num++;
+                                                               }
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISLPLAY":
+                                               case "SUPPLIED":
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+
+                                               }
+                                       break;
+
+                               case "file":
+                                       switch( $field[3] )
+                                               {
+                                               case "TRUE":
+                                               case "FALSE":
+                                                       $out[$outcount]["value"] = '<TABLE BORDER="1">';
+
+                                                       if( $data[$field[0]] != "" )    // If a file already exists
+                                                               {
+                                                               $out[$outcount]["value"] .= '   <TR>
+                                                                               <TD VALIGN="middle">
+                                                                               <A HREF="'.SI_BASE_FILE_URL.'/'.$data[$field[0]].'">'.$data[$field[0]].'</A>
+                                                                               </TD>
+                                                                               <TD VALIGN="middle">';
+
+                                                               if( $field[3] == "TRUE" )       // If this field is required
+                                                                       $out[$outcount]["value"] .= 'This file may be replaced using the input field below.';
+                                                                   else
+                                                                       $out[$outcount]["value"] .= '<INPUT TYPE="checkbox" NAME="'.$field[0].'_DELETE"> Delete this file';
+
+                                                               $out[$outcount]["value"] .= '           </TD></TR>';
+                                                               }
+
+                                                       $out[$outcount]["value"] .= '           <TR>
+                                                                               <TD COLSPAN="2" VALIGN="middle"><INPUT TYPE="file" NAME="'.$field[0].'"></TD>
+                                                                       </TR>
+                                                               </TABLE>';
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISLPLAY":
+                                                       $out[$outcount]["value"] = '<A HREF="'.SI_BASE_FILE_URL.'/'.$data[$field[0]].'">'.$data[$field[0]].'</A>';
+                                                       break;
+
+                                               case "SUPPLIED":
+                                                       $out[$outcount]["value"] = "";
+                                                       break;
+
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+
+                                               }
+                                       break;
+
+                               case "category":
+
+                                               // If picklist is selected - use that for selection
+
+                                       if( strstr($f[3],'picklist') )
+                                               {
+                                               if( ($nodes = cat_get_nodes($f[1])) )
+                                                       {
+                                                       $out[$outcount]["value"] .= '<SELECT NAME="'.$field[0].'"><OPTION VALUE="">';
+
+                                                       reset($nodes);
+                                                       while( list($key, $val) = each($nodes) )
+                                                               {
+                                                               $out[$outcount]["value"] .= '<OPTION VALUE="'.$val['id'].'"'.($data[$field[0]]==$val['id']?' SELECTED':'').'>';
+                                                               if( strstr($f[3],'fullpath') )
+                                                                       $out[$outcount]["value"] .= $val['cat_fullpath'];
+                                                                 else
+                                                                       {
+                                                                       for( $i=0 ; $i<$val['cat_level'] ; $i++ )
+                                                                               $out[$outcount]["value"] .= "&nbsp;&nbsp;&nbsp;&nbsp;";
+                                                                       $out[$outcount]["value"] .= $val['name'];
+                                                                       }
+                                                               }
+                                                       $out[$outcount]["value"] .= '</SELECT>';
+                                                       }
+                                                 else
+                                                       $out[$outcount]["value"] .= 'No categories listed.';
+                                               }
+                                         else  // Otherwise use pop-up
+                                               {
+
+                                                       // Get the category name for this field is supplied
+                                               if( !empty($data[$field[0]]) )
+                                                       {
+                                                       if( ($cval = cat_get_node( $f[1], "id = ".$data[$field[0]] ) ) )
+                                                               {
+                                                               $cat_id = $data[$field[0]];
+                                                               if( strstr($f[3],'fullpath') )
+                                                                       $cat_name = $cval['cat_fullpath'];
+                                                                 else
+                                                                       $cat_name = $cval['cat_name'];
+                                                               }
+                                                       }
+                                                 else
+                                                       {
+                                                       $cat_id = 0;
+                                                       $cat_name = "&nbsp;&nbsp;&nbsp;";
+                                                       }
+
+                                               $pop_width = !empty($f[4]) ? $f[4] : 200 ;
+                                               $pop_height = !empty($f[5]) ? $f[5] : 300 ;
+                                               $edit_width = !empty($f[6]) ? $f[6] : 400 ;
+                                               $edit_height = !empty($f[7]) ? $f[7] : 500 ;
+
+                                               $out[$outcount]["value"] .= "
+                                                         <script language=\"JavaScript1.2\">
+                                                               <!--
+                                                                       function category_select_popup_".$field[0]."( target )
+                                                                               {
+                                                                                       // Pass values to the calendar
+
+                                                                               tempX = 400;
+                                                                               tempY = 300;
+
+                                                                               node_id = this.document.getElementById( target ).value;
+                                                                               var theUrl='".SI_BASE_URL."/glm_apps/category_select_popup.phtml?id=' + node_id + '&field_name=".$field[0]."&table=".$f[1]."&options=".urlencode($f[3])."&edit_width=".$edit_width."&edit_height=".$edit_height."&pop_width=".$pop_width."&pop_height=".$pop_height."&ref_id=".$id."';
+
+                                                                               tempX = tempX - 90;
+                                                                               //tempY = tempY - 170;
+
+                                                                       if (navigator.appName == 'Netscape')
+                                                                                       {
+                                                                               CategoryWind = window.open( theUrl, 'Calendar','scrollbars=yes,toolbar=no,resizable=yes,width=".$pop_width.",height=".$pop_height.",screenx=' + tempX + ',screeny=' + tempY,1 );
+                                                                       }
+                                                                                 else
+                                                                                       {
+                                                                       CategoryWind = window.open( theUrl, 'Calendar','scrollbars=no,toolbar=no,resizable=no,width=".$pop_width.",height=".$pop_height.", top=' + tempY + ', left=' + tempX,1 );
+                                                                       }
+
+                                                                               CategoryWind.focus();
+                                                                               }
+                                                               -->
+                                                         </script>
+                                                       ";
+
+                                               $out[$outcount]["value"] .= '<INPUT TYPE="text" NAME="'.$field[0].'_NAME" ID="'.$field[0].'_NAME" VALUE="'.$cat_name.'" READONLY="readonly" SIZE="'.$f[2].'" STYLE="background-color: #eeeeee;">
+                                                                                                        <INPUT TYPE="hidden" NAME="'.$field[0].'" ID="'.$field[0].'" VALUE="'.$cat_id.'">
+                                                                                                        <A HREF="javascript:category_select_popup_'.$field[0].'(\''.$field[0].'\')">[Change]</A>
+                                                                                                       ';
+                                               }
+
+                                       break;
+
+
+                               case "pointer":
+
+                                               // If {value_field} supplied use that, otherwise use id of record as VALUE
+                                       $value_field = !empty($f[3]) ? $f[3] : "id" ;
+
+                                               // If {where} supplied use that, otherwise get all possibilities from other table
+                                       $w = !empty($f[4]) ? " WHERE ".$f[4] : "" ;
+
+                                               // If picklist options
+                                       $p = !empty($f[5]) ? $f[5] : "" ;
+
+                                               // Sort order
+
+                                       $s = !empty($f[6]) ? $f[6] : "id" ;
+
+                                               // Pointer options
+
+                                       $pointer_option_add_field = FALSE;
+                                       if( ! empty($f[7]) )
+                                               {
+                                               $option_table = explode_trim( ",", $f[7] );
+                                               foreach( $option_table as $option )
+                                                       {
+                                                       switch( $option )
+                                                               {
+                                                               case "add_field":                                               // Option to display a field for entering a new target
+                                                                       $pointer_option_add_field = TRUE;
+                                                                       break;
+
+                                                               default:
+                                                                       break;
+                                                               }
+                                                       }
+                                               }
+
+                                       switch( $field[3] )
+                                               {
+
+                                               case "TRUE":
+                                               case "FALSE":
+
+                                                       $d = db_auto_get_data( "SELECT * FROM  ".$f[1].$w." ORDER BY ".$s.";", $conn_str, FALSE, 500 );
+
+                                                       if( is_array( $d ) )
+                                                               {
+                                                               unset( $da );
+                                                               while( list($key, $val) = each($d) )
+                                                                       $da[$val[$value_field]] = $val[$f[2]];
+
+                                                                       // If there's a supplied value, use that to match for selected
+
+                                                               if( !empty($field[4]) )
+                                                                       $z = $GLOBALS[$field[4]];
+                                                                 else
+                                                                       $z = $data[$field[0]];
+
+                                                               $out[$outcount]["value"] = build_a_picklist( $field[0], $da, $data[$field[0]], "standard", $p );
+                                                               }
+                                                         else
+                                                               $out[$outcount]["value"] = '(no values available)';
+
+                                                               // Provide an additional input field to permit adding a new target value
+
+                                                       if( $pointer_option_add_field )
+                                                               $out[$outcount]["value"] .= '<NOBR> or add new value <INPUT TYPE="text" NAME="'.$field[0].'_add_field"></NOBR>';
+
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISPLAY":
+
+                                                               // Get specific data requested
+                                                       if( ($d = db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE id = ".$data[$field[0]]." ORDER BY ".$s.";", 0, $conn_str, $fail_mode  )) );
+
+                                                               $out[$outcount]["value"] = $d[$f[2]];
+
+                                                       break;
+
+                                               case "SUPPLIED":
+                                                       $out[$outcount]["value"] = "";
+                                                       break;
+
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+
+
+                                               }
+                                       break;
+
+                               case "checkbox":
+
+                                               // Check for null value
+
+                                       if( empty($data[$field[0]]) )
+                                               $data[$field[0]] = "f";
+
+                                       switch( $field[3] )     // {required} setting
+                                               {
+
+                                               case "TRUE":
+                                               case "FALSE":
+                                                       $x = $data[$field[0]] == "t" ? " CHECKED" : "";
+                                                       $out[$outcount]["value"] = '<INPUT TYPE="checkbox" NAME="'.$field[0].'"'.$x.'>';
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISPLAY":
+                                                       $x = $data[$field[0]] == "t" ? "Yes" : "No";
+                                                       $out[$outcount]["value"] = $x;
+                                                       break;
+
+                                               case "SUPPLIED":
+                                                       $out[$outcount]["value"] = "";
+                                                       break;
+
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+                                               }
+                                       break;
+
+                               case "bitmap":
+                                       $bmap = explode_trim( "~", $f[1] );
+                                       $out[$outcount]["value"] = "";
+                                       switch( $field[3] )     // {required} setting
+                                               {
+                                               case "TRUE":
+                                               case "FALSE":
+                                                       for( $i=0 ; $i<count($bmap) ; $i++ )
+                                                               if( $bmap[$i] != '' )
+                                                                       {
+                                                                       $x = $data[$field[0]] & pow( 2, $i ) ? " CHECKED" : "";         // Check if this bit set
+                                                                       $out[$outcount]["value"] .= '<INPUT TYPE="checkbox" NAME="'.$field[0]."[$i]".'"'.$x.'>'.$bmap[$i].'<BR>';
+                                                                       }
+                                                       break;
+
+                                               case "HIDDEN":
+                                               case "DISPLAY":
+                                                       for( $i=0 ; $i<count($bmap) ; $i++ )
+                                                               if( $bmap[$i] != ' ' )
+                                                                       {
+                                                                       $x = $data[$field[0]] & pow( 2, $i ) ? "Yes" : "No";            // Check if this bit set
+                                                                       $out[$outcount]["value"] .= $x.": ".$bmap[$i].'<BR>';
+                                                                       }
+                                                       break;
+
+                                               case "SUPPLIED":
+                                                       $out[$outcount]["value"] = "";
+                                                       break;
+
+                                               default:
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Invalid {required} field specification</FONT>';
+                                                       break;
+                                               }
+                                       if( $out[$outcount]["value"] == '' )
+                                               $out[$outcount]["value"] = '(no options listed)';
+                                       break;
+
+                               case "list":
+
+                                               // If picklist options
+                                       $p = !empty($f[3]) ? $f[3] : "" ;
+
+                                       $option_table = "";
+                                       $opts = explode_trim( "~", $f[1] );     // Separate list options
+                                       $def_value = !empty($f[2]) ? $f[2] : "" ;
+
+                                               // If there's no current value, use default for current picklist option
+
+                                       if( trim($data[$field[0]]) == "" )
+                                               $current_value = $f[2];
+                                         else
+                                               $current_value = $data[$field[0]];
+
+                                       foreach( $opts as $opt )
+                                               {
+                                               $os = explode_trim( "^", $opt );        // Separate value from displayed text
+                                               $option_table[$os[0]] = $os[1];
+                                               }
+
+                                       switch( $field[3] )     // {required} setting
+                                               {
+                                               case "DISPLAY":
+                                                       $out[$outcount]['value'] = $option_table[$data[$field[0]]];
+                                                       break;
+                                               default:
+                                                       if( strstr( 'multi', $f[3] ) )
+                                                               $data[$field[0]] = explode( '~', $data[$field[0]] );
+                                                       $out[$outcount]["value"] = build_a_picklist( $field[0], $option_table, $data[$field[0]], "standard", $p );
+                                                       break;
+                                               }
+                                       break;
+
+                               case "state":
+                                       switch( $field[3] )     // {required} setting
+                                               {
+                                               case "DISPLAY":
+                                                       $out[$outcount]['value'] = $GLOBALS['si_states_array'][$data[$field[0]]];
+                                                       break;
+                                               default:
+                                                       $out[$outcount]["value"] = build_a_picklist( $field[0], $GLOBALS['si_states_array'], $data[$field[0]], "standard", $f[2] );
+                                               }
+                                       break;
+
+                               case "country":
+                                       switch( $field[3] )     // {required} setting
+                                               {
+                                               case "DISPLAY":
+                                                       $out[$outcount]['value'] = $GLOBALS['si_states_array'][$data[$field[0]]];
+                                                       break;
+                                               default:
+                                                       $out[$outcount]["value"] = build_a_picklist( $field[0], $GLOBALS['si_countries_array'], $data[$field[0]], "standard", $f[2] );
+                                               }
+                                       break;
+
+                               case "break":
+                                       if( !empty($f[1]) )     // if {t1} is supplied
+                                               $out[$outcount]["value"] = $f[1];
+                                           else
+                                               $out[$outcount]["value"] = '<FONT COLOR="red">No {text} supplied for type "break"</FONT>';
+                                       break;
+
+                               default:
+                                       $out[$outcount]["value"] = '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$f[0].' for '.$field[0].'</FONT>';
+                                       break;
+
+                               } // switch( field )
+
+                       $outcount++;
+                       } // foreach( field )
+
+               }
+           else
+               {
+               $ret .=  '      <CENTER>(No results found)</CENTER>
+                       <P>
+                    ';
+               return;
+               }
+
+       $submit = '
+                       <INPUT TYPE="hidden" NAME="Action" VALUE="'.$action.'">
+                       <INPUT TYPE="submit" NAME="Option" VALUE="Update">
+                       ';
+
+               // Replace parameters in Title
+
+       for( $i=0 ; $i<$outcount ; $i++ )
+               {
+               $a_title = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $a_title );
+               $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $a_title );
+               }
+
+       $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+       $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+
+               // Add QuickTip if provided
+
+       if( trim($quick_tip) != '' )
+               $a_title = quick_tip( $a_title, $quick_tip );
+
+               // Output Results
+
+                       // Display top of page
+
+       $ret .=  '<CENTER>
+               <FORM ENCTYPE="multipart/form-data" ACTION="'.$url.'" METHOD="post" NAME="'.$form_name.'">
+                       <INPUT TYPE="hidden" NAME="id" VALUE="'.$id.'">
+            ';
+
+       if( empty($view) )      // If there's no format spec in $view
+               {
+               $ret .=  '<CENTER>'.$a_title.'
+                       <FONT COLOR="red">(Required fields in red)</FONT><BR>
+                       <TABLE BORDER="'.$borders.'"'.($borders>0?' CELLPADDING="5"':'').'>
+                    ';
+
+               for( $i=0 ; $i<$outcount ; $i++ )
+                       {
+                       if( !$out[$i]["hidden"] )
+                               $ret .=  '<TR><TH ALIGN="right" VALIGN="top">'.$out[$i]["name"]
+                               .'&nbsp;</TH><TD ALIGN="left">'.$out[$i]["value"].'&nbsp;</TD></TR>
+                                    ';
+                       }
+               $ret .=  '      <P>
+                       </TABLE>'.$form_params.$submit; // Output the Update submit button
+
+               }
+         else  // Otherwise use $view to output data
+               {
+               for( $i=0 ; $i<$outcount ; $i++ )
+                       {
+                       $view = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $view );
+                       $view = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $view );
+                       }
+               $view = ereg_replace( "\\{submit\\}", $submit, $view );
+               $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+               $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+               $ret .=  '<CENTER>'.$a_title.$view;
+               }
+
+               // If HTMLArea is used, attach scripts to set that up to submit button tags
+
+       if( $richtext_used )
+               $ret .=  htmlarea_setup_script();
+
+       $ret .=  '
+               </FORM>
+               </CENTER>
+            ';
+
+       return( array( 'text' => $ret, 'status' => true ) );
+
+}
+
+
+function admin_edit_record( $table, $conn_str, $id, $fields, $url, $action,
+                       $params, $a_title, $view = "", $options = "", $quick_tip = "" )
+{
+
+       $r = admin_edit_record_r( $table, $conn_str, $id, $fields, $url, $action,
+                       $params, $a_title, $view, $options, $quick_tip );
+       echo $r['text'];
+       return( $f['status'] );
+}
+
+
+
+
+       // Update an edited record
+
+function admin_update_record_r( $table, $conn_str, $id, $fields, $url, $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+
+       $ret = '';
+
+               // Make all submitted parameters available
+
+//     extract($GLOBALS[HTTP_POST_VARS]);
+//     extract($GLOBALS[HTTP_GET_VARS]);
+//     extract($GLOBALS[HTTP_POST_FILES]);
+
+               // Check for additional parameters that are passed
+
+       if( !empty($params) )
+               {
+               $param = explode_trim( "|", $params );  // Separate parameters
+               $link_params = $form_params = "";
+               foreach( $param as $p )
+                       {
+                       $x = explode_trim( ".", $p );   // Separate Names from Values
+                       $link_params .= "&".$x[0]."=".urlencode($x[1]);
+                       $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+                       }
+               }
+
+               // Get the current data for reference and to make sure it exists
+
+       $query_string = "SELECT * FROM ".$table." WHERE id = ".$id.";";
+       if( SI_DEBUG >= 1 ) $ret .= "<PRE>admin_update_record()[".__LINE__."]: Get old record = $query_string</PRE><BR>";
+       $data = db_auto_get_row( $query_string, 0, $conn_str, $fail_mode );
+
+       $update_record = true;  // Assume update is going to succeed.
+
+       if( $data )
+               {
+
+                       // Break out configuration data
+
+               $field_table = explode_trim( "|", $fields );
+
+                       // Don't be surprised if last field is blank
+
+               if( trim($field_table[count($field_table)-1]) == "" )
+                       array_pop( $field_table );
+
+               foreach( $field_table as $key => $r )
+                       $field_table[$key] = explode_trim( ",", $r );
+
+               $result = $problem = $not_supplied = "";
+               $qs = '';
+
+                       // For each field in the result
+
+               $comma = "";    // first parameter doesn't need a comma in front of it
+
+               $outcount = 0;
+               foreach( $field_table as $field )
+                       {
+                       $f = explode_trim( ".", $field[1] );
+                       $fta = explode_trim( "~", $field[2] );
+                       $field_title_only = $fta[0];
+
+                       if( $field[3] != 'DISPLAY' )            // Don't even try to process a DISPLAY only field. No point to it!
+                               switch( $f[0] )
+                                       {
+
+                                       case "order":
+                                       case "int":
+                                       case "float":
+                                       case "fixed":
+                                       case "money":
+                                       case "pointer":
+                                       case "category":
+
+                                                       // Handle special cases
+
+                                               switch( $f[0] )
+                                                       {
+                                                       case "money":
+                                                               $GLOBALS[$field[4]] = ereg_replace( "[\$,]", "", $GLOBALS[$field[4]] ); // Get rid of "$" and "," from silly users
+                                                               break;
+
+                                                       case "pointer":
+
+                                                                       // Check for add_field values - Add new value to pointer target record
+
+                                                               if( ($add_value = trim($GLOBALS[$field[4].'_add_field'])) != '' )
+                                                                       {
+                                                                               // If value already exists warn user.
+
+                                                                       if( db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE ".$f[2]." = '".trim($GLOBALS[$field[4].'_add_field'])."';", 0, $conn_str, $fail_mode ) )
+                                                                               $not_supplied .= $field_title_only.": Value already exists in pick list, don't try to add it again.<BR>";
+                                                                         else
+                                                                               {
+                                                                                       // Otherwise, add new value and use pointer to that
+
+                                                                               $add_result = db_auto_get_row( "INSERT INTO ".$f[1]." ( ".$f[2]." ) VALUES ( '".trim($GLOBALS[$field[4].'_add_field'])."' );
+                                                                                                                                               SELECT currval( '".$f[1]."_id_seq' ) AS id;", 0, $conn_str, $fail_mode );
+                                                                               $GLOBALS[$field[4]] = $add_result['id'];
+                                                                               }
+                                                                       }
+
+                                                               break;
+                                                       }
+
+                                               $qs .= $comma." ".$field[0]." = ";              // Add field name to update to query string
+                                               $comma = ",";
+                                               $out[$outcount]["value"] = $GLOBALS[$field[4]];
+                                               switch( $field[3] )
+                                                       {
+                                                       case "SUPPLIED":
+                                                               $qs .= $GLOBALS[$field[4]];
+                                                               break;
+
+                                                       case "TRUE":
+                                                               if( !is_numeric($GLOBALS[$field[4]]) )
+                                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                                 else
+                                                                       $qs .= $GLOBALS[$field[4]];
+                                                               break;
+
+                                                       case "FALSE":
+                                                               if( is_numeric($GLOBALS[$field[4]]) )
+                                                                       $qs .= $GLOBALS[$field[4]];
+                                                                 else
+                                                                       $qs .= "0";     // Default to 0
+                                                               break;
+
+                                                       default:
+                                                               $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field name "'.$field[3].'" in function call</FONT><BR>';
+                                                               break;
+                                                       }
+                                               break;
+
+                                       case "lat":
+                                               $qs .= $comma." ".$field[0]." = ";
+                                               $comma = ",";
+                                                       // If we've been passed a decimal degree value
+                                               if( !empty($GLOBALS[$field[4]]) )
+                                                       $v = $GLOBALS[$field[4]];
+                                                 else  // Otherwise compile from parts
+                                                       {
+                                                       if( $GLOBALS[$field[4].'_DEG'] > 90 || $GLOBALS[$field[4].'_DEG'] < 0 || $GLOBALS[$field[4].'_MIN'] >= 60 || $GLOBALS[$field[4].'_MIN'] < 0 )
+                                                               {
+                                                               $not_supplied .= $field_title_only.": Invalid entry. Degrees must be 0 to 90 and Minutes must be 0 to less than 60<BR>";
+                                                               break;
+                                                               }
+                                                       $v = ( $GLOBALS[$field[4].'_NS'] == "N" ? 1 : -1 ) * ( $GLOBALS[$field[4].'_DEG'] + ( $GLOBALS[$field[4].'_MIN'] / 60 ) );
+                                                       }
+                                               $fw = 2;
+                                                       // Rebuild value for display
+                                               if( $f[1] > 0 )
+                                                       $fw = $f[1];
+                                               $ns = 'N';
+                                               if( ($v2=$v) < 0 )
+                                                       {
+                                                       $ns = 'S';
+                                                       $v2 = -1 * $v2;
+                                                       }
+                                               $dv = (int) $v2;
+                                               $mv = ( $v2 - $dv ) * 60;
+                                               $out[$outcount]["value"] = sprintf( "%s %d&deg; %01.".$fw."f'", $ns, $dv, $mv );
+                                               switch( $field[3] )
+                                                       {
+                                                       case "SUPPLIED":
+                                                       case "FALSE":
+                                                               $qs .= $v;
+                                                               break;
+
+                                                       case "TRUE":
+                                                               if( empty($v) )
+                                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                                 else
+                                                               $qs .= $v;
+                                                               break;
+
+                                                       case "UNIQUE":
+                                                               if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+                                                                       $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                                               $qs .= $v;
+                                                               break;
+
+                                                       case "UNIQUE_NOT_REQ":
+                                                               if( !empty($v) && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+                                                                       $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                                               $qs .= $v;
+                                                               break;
+
+                                                       default:
+                                                               $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                                               break;
+                                                       }
+                                               break;
+
+                                       case "lon":
+                                               $qs .= $comma." ".$field[0]." = ";
+                                               $comma = ",";
+                                                       // If we've been passed a decimal degree value
+                                               if( !empty($GLOBALS[$field[4]]) )
+                                                       $v = $GLOBALS[$field[4]];
+                                                 else  // Otherwise compile from parts
+                                                       {
+                                                       if( $GLOBALS[$field[4].'_DEG'] > 180 || $GLOBALS[$field[4].'_DEG'] < 0 || $GLOBALS[$field[4].'_MIN'] >= 60 || $GLOBALS[$field[4].'_MIN'] < 0 )
+                                                               {
+                                                               $not_supplied .= $field_title_only.": Invalid entry. Degrees must be 0 to 180 and Minutes must be 0 to less than 60<BR>";
+                                                               break;
+                                                               }
+                                                       $v = ( $GLOBALS[$field[4].'_NS'] == "N" ? 1 : -1 ) * ( $GLOBALS[$field[4].'_DEG'] + ( $GLOBALS[$field[4].'_MIN'] / 60 ) );
+                                                       }
+                                               $fw = 2;
+                                                       // Rebuild value for display
+                                               if( $f[1] > 0 )
+                                                       $fw = $f[1];
+                                               $ns = 'E';
+                                               if( ($v2=$v) < 0 )
+                                                       {
+                                                       $ns = 'W';
+                                                       $v2 = -1 * $v2;
+                                                       }
+                                               $dv = (int) $v2;
+                                               $mv = ( $v2 - $dv ) * 60;
+                                               $out[$outcount]["value"] = sprintf( "%s %d&deg; %01.".$fw."f'", $ns, $dv, $mv );
+                                               switch( $field[3] )
+                                                       {
+                                                       case "SUPPLIED":
+                                                       case "FALSE":
+                                                               $qs .= $v;
+                                                               break;
+
+                                                       case "TRUE":
+                                                               if( empty($v) )
+                                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                                 else
+                                                               $qs .= $v;
+                                                               break;
+
+                                                       case "UNIQUE":
+                                                               if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+                                                                       $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                                               $qs .= $v;
+                                                               break;
+
+                                                       case "UNIQUE_NOT_REQ":
+                                                               if( !empty($v) && db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = $v;", 0, $conn_str, $fail_mode ) )
+                                                                       $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                                               $qs .= $v;
+                                                               break;
+
+                                                       default:
+                                                               $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                                               break;
+                                                       }
+
+                                               break;
+
+                                       case "text":
+                                       case "inet":
+                                       case "list":
+                                       case "state":
+                                       case "country":
+                                       case "url":
+                                       case "textbox":
+                                       case "richtext":
+
+                                                       // Check for special cases
+
+                                               switch( $f[0] )
+                                                       {
+                                                       case "inet":
+                                                               if( ($r = clean_input( $field[0], 'inet' )) != '' )
+                                                                       $problem .= '<FONT COLOR="red">'.$field_title_only.': Not a valid IP address or netmask.</FONT><BR>';
+                                                               break;
+
+                                                       case "list":
+                                                                       // If 'multi' is selected for picklist option, then compile results from array
+                                                               if( strstr( $f[3], 'multi' ) )
+                                                                       {
+                                                                       $m_val = $sep = '';
+
+                                                                               // Place results in '~' separated string for storage.
+
+                                                                       if( is_array($GLOBALS[$field[4]]) )
+                                                                               foreach( $GLOBALS[$field[4]] as $m )
+                                                                                       {
+                                                                                       $m_val .= $sep.$m;
+                                                                                       $sep = '~';
+                                                                                       }
+                                                                       $GLOBALS[$field[4]] = $m_val;
+                                                                       }
+
+                                                               break;
+
+                                                       default:
+                                                               break;
+                                                       }
+
+                                               $v = str_replace( "%27", "\'", $GLOBALS[$field[4]] );
+                                               if( trim(strip_tags($v)) == '' )
+                                                       $v = '';
+                                               $qs .= $comma." ".$field[0]." = ";              // Add field name to update to query string
+                                               $comma = ",";
+                                               $out[$outcount]["value"] = $v;
+
+                                               switch( $field[3] )
+                                                       {
+                                                       case "SUPPLIED":
+                                                               $qs .= "'".rawurldecode( $v )."'";
+                                                               break;
+
+                                                       case "TRUE":
+                                                               if( empty($v) )
+                                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                                 else
+                                                                       $qs .= "'".rawurldecode( $v )."'";
+                                                               break;
+
+
+                                                       case "UNIQUE":
+                                                               if( $f[0] != text )
+                                                                       {
+                                                                       $problem .= '<FONT COLOR="red">ERROR: UNIQUE only available for type "text"</FONT><BR>';
+                                                                       break;
+                                                                       }
+
+                                                               if( empty($GLOBALS[$field[4]]) )
+                                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                                   else
+                                                                       {
+                                                                       $qs .= "'".rawurldecode( $GLOBALS[$field[4]] )."'";
+
+                                                                                       // Check if value is used anywhere other than current record
+
+                                                                       if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".rawurldecode( trim($v) )."' AND id != ".$id.";", 0, $conn_str, $fail_mode ) )
+                                                                               $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                                                       }
+
+                                                               break;
+
+                                                       case "UNIQUE_NOT_REQ":
+                                                               if( $f[0] != text )
+                                                                       {
+                                                                       $problem .= '<FONT COLOR="red">ERROR: UNIQUE only available for type "text"</FONT><BR>';
+                                                                       break;
+                                                                       }
+
+                                                               if( !empty($GLOBALS[$field[4]]) )
+                                                               {
+                                                                       $qs .= "'".rawurldecode( $GLOBALS[$field[4]] )."'";
+
+                                                                                       // Check if value is used anywhere other than current record
+
+                                                                       if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".rawurldecode( trim($v) )."' AND id != ".$id.";", 0, $conn_str, $fail_mode ) )
+                                                                               $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                                                       }
+                                                                 else
+                                                                       $qs .= "''";
+
+                                                               break;
+
+
+                                                       case "FALSE":
+                                                               $qs .= "'".rawurldecode( $v )."'";
+                                                               break;
+
+                                                       default:
+                                                               $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                                               break;
+                                                       }
+
+                                               break;
+
+                                       case "date":
+                                               $qs .= $comma." ".$field[0]." = ";              // Add field name to update to query string
+                                               $comma = ",";
+                                               $out[$outcount]["value"] = $GLOBALS[$field[4]];
+
+                                               if( trim($GLOBALS[$field[4]]) == "" )                   // Empty dates must be "NULL"
+                                                       $dval = "NULL";
+                                                 else
+                                                       $dval = "'".$GLOBALS[$field[4]]."'";
+
+                                               switch( $field[3] )
+                                                       {
+                                                       case "SUPPLIED":
+                                                               $qs .= $dval;
+                                                               break;
+
+                                                       case "TRUE":
+                                                               if( empty($GLOBALS[$field[4]]) )
+                                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                                   else
+                                                                       $qs .= $dval;
+                                                               break;
+
+
+                                                       case "UNIQUE":
+                                                               if( $field[1] != text )
+                                                                       {
+                                                                       $problem .= '<FONT COLOR="red">ERROR: UNIQUE only available for type "text"</FONT><BR>';
+                                                                       break;
+                                                                       }
+
+                                                               if( empty($GLOBALS[$field[4]]) )
+                                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                                   else
+                                                                       {
+                                                                       $qs .= $dval;
+
+                                                                                       // Check if value is used anywhere other than current reccord
+
+                                                                       if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($GLOBALS[$field[4]])."' AND id <> ".$id.";", 0, $conn_str, $fail_mode ) )
+                                                                               $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                                                       }
+
+                                                               break;
+
+                                                       case "UNIQUE_NOT_REQ":
+                                                               if( $field[1] != text )
+                                                                       {
+                                                                       $problem .= '<FONT COLOR="red">ERROR: UNIQUE only available for type "text"</FONT><BR>';
+                                                                       break;
+                                                                       }
+
+                                                               if( !empty($GLOBALS[$field[4]]) )
+                                                                   {
+                                                                       $qs .= $dval;
+
+                                                                                       // Check if value is used anywhere other than current reccord
+
+                                                                       if( db_auto_get_row( "SELECT * FROM $table WHERE ".$field[0]." = '".trim($GLOBALS[$field[4]])."' AND id <> ".$id.";", 0, $conn_str, $fail_mode ) )
+                                                                               $not_supplied .= $field_title_only.": Already exists, must be unique<BR>";
+                                                                       }
+                                                                 else
+                                                                       $qs .= $dval;
+
+                                                               break;
+
+
+                                                       case "FALSE":
+                                                               $qs .= $dval;
+                                                               break;
+
+                                                       default:
+                                                               $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                                               break;
+                                                       }
+                                               break;
+
+                                       case "multifield":
+
+                                               $line = 0;
+                                               $empty = TRUE;
+                                               $m_data = array();
+
+                                                       // Build array of data to store
+                                               while( isset( $GLOBALS[$field[4].'_'.($line+1).'_1'] ) )
+                                                       {
+                                                       $line++;
+                                                       if( trim($GLOBALS[$field[4].'_'.$line.'_1']) != '' )
+                                                               {
+                                                               $a = array();
+                                                               for( $i=1 ; $i<=$f[1] ; $i++ )
+                                                                       {
+                                                                       $a[$i-1] = trim( str_replace("%27", "\'", $GLOBALS[$field[4].'_'.($line).'_'.$i] ) );
+                                                                       if( $a[$i-1] != '' )
+                                                                               $empty = FALSE;
+                                                                       }
+                                                               array_push( $m_data, $a );
+                                                               }
+                                                       }
+
+                                               if( !$empty )
+                                                       $v = serialize( $m_data );
+                                                 else
+                                                       $v = '';
+
+                                               $qs .= $comma." ".$field[0]." = "; // Add field name to update to query string
+                                               $comma = ",";
+                                               $out[$outcount]["value"] = $v;
+
+                                               switch ($field[3])
+                                               {
+                                                       case "TRUE" :
+                                                               if (empty ($v))
+                                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                               else
+                                                                       $qs .= "'".rawurldecode($v)."'";
+                                                               break;
+
+                                                       case "FALSE" :
+                                                               $qs .= "'".rawurldecode($v)."'";
+                                                               break;
+
+                                                       default :
+                                                               $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                                               break;
+                                               }
+
+                                               break;
+
+                                       case "image":
+                                               // Note that the image field is only updated when required so field name is set below along with value
+                                               $out[$outcount]["value"] = "IMAGES Not Available for View at this time";
+                                               switch( $field[3] )
+                                                       {
+                                                       case "SUPPLIED":
+                                                               $problem .= '<FONT COLOR="red">ERROR: "SUPPLIED" not permitted as option for image input</FONT>';
+                                                               break;
+
+                                                       case "TRUE":
+                                                                       // If no image is supplied and there's no image in the database
+                                                               if( $GLOBALS[$field[4]."_name"] == "" && $data[$field[0]] == "" )
+                                                                       {
+                                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                                       break;
+                                                                       }
+
+                                                                       // If new image is supplied, replace old one
+                                                               if( $GLOBALS[$field[4]."_name"] != "" )
+                                                                       {
+                                                                       if( $data[$field[0]] != "" )
+                                                                               delete_image( $data[$field[0]] );
+                                                                       $qs .= $comma." ".$field[0]." = '".process_image( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"] )."'";
+                                                                       $comma = ",";
+                                                                       }
+                                                               break;
+
+                                                       case "FALSE":
+                                                                       // If new image is supplied, store it
+                                                               if( $GLOBALS[$field[4]."_name"] != "" )
+                                                                       {
+                                                                       if( $data[$field[0]] )          // If there's already an image, delete it before storing the new one
+                                                                               delete_image( $data[$field[0]] );
+                                                                       $qs .= $comma." ".$field[0]." = '".process_image( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"] )."'";
+                                                                       $comma = ",";
+                                                                       }
+                                                                       // Else, if there's an image in the database and we're deleting
+                                                                 elseif( $data[$field[0]] != "" && isset($GLOBALS[$field[0]."_DELETE"])  )
+                                                                       {
+                                                                       delete_image( $data[$field[0]] );
+                                                                       $qs .= $comma." ".$field[0]." = ''";    // Clear image name in database
+                                                                       $comma = ",";
+                                                                       }
+
+                                                               break;
+
+                                                       default:
+                                                               $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                                               break;
+                                                       }
+                                               break;
+
+                                       case "images":
+
+                                               // Note that the image field is only updated when required so field name is set below along with value
+
+                                               $out[$outcount]["value"] = "IMAGES Not Available for View at this time";
+                                               switch( $field[3] )
+                                                       {
+                                                       case "FALSE":
+                                                               if( is_array( ($im_data = $GLOBALS[$field[4]]) ) )
+                                                                       {
+                                                                       $im_cur = unserialize( $data[$field[0]] );              // Convert existing data to an array
+                                                                       $im_new = array();
+                                                                       $im_new_num = 0;
+                                                                       for( $im_num=0 ; $im_num<count($GLOBALS[$field[0]."_name"]) ; $im_num++ )
+                                                                               {
+                                                                                       // If new image is supplied, store it
+                                                                               if( $GLOBALS[$field[0]."_name"][$im_num] != "" )
+                                                                                       {
+                                                                                       if( $im_cur[$im_num]['filename'] )              // If there's already an image, delete it before storing the new one
+                                                                                               delete_image( $im_cur[$im_num]['filename'] );
+                                                                                       $im_new[$im_new_num]['filename'] = process_image( $GLOBALS[$field[0]][$im_num], $GLOBALS[$field[0]."_name"][$im_num] );
+                                                                                       $im_new[$im_new_num]['descr'] = $GLOBALS[$field[0].'_DESCR'][$im_num];
+                                                                                       $im_new[$im_new_num]['align'] = $GLOBALS[$field[0].'_ALIGN'][$im_num];
+                                                                                       $im_new[$im_new_num]['size'] = $GLOBALS[$field[0].'_SIZE'][$im_num];
+                                                                                       $im_new_num++;
+                                                                                       }
+                                                                                               // Else, if there's an image in the database and we're deleting
+                                                                                 elseif( $im_cur[$im_num]['filename'] != "" && isset( $GLOBALS[$field[0]."_DELETE"][$im_num] )  )
+                                                                                       delete_image( $im_cur[$im_num]['filename'] );
+                                                                                 elseif( $im_cur[$im_num]['filename'] != "" )
+                                                                                       {
+                                                                                       $im_new[$im_new_num]['filename'] = $im_cur[$im_num]['filename'];
+                                                                                       $im_new[$im_new_num]['descr'] = $GLOBALS[$field[0].'_DESCR'][$im_num];
+                                                                                       $im_new[$im_new_num]['align'] = $GLOBALS[$field[0].'_ALIGN'][$im_num];
+                                                                                       $im_new[$im_new_num]['size'] = $GLOBALS[$field[0].'_SIZE'][$im_num];
+                                                                                       $im_new_num++;
+                                                                                       }
+                                                                               }
+                                                                       $qs .= $comma." ".$field[0]." = '".serialize( $im_new )."'";
+                                                                       $comma = ",";
+                                                                       }
+
+                                                               break;
+
+                                                       case "TRUE":
+                                                       case "SUPPLIED":
+                                                       default:
+                                                               $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                                               break;
+                                                       }
+                                               break;
+
+                                       case "file":
+
+                                                       // Note that the file field is only updated when required so field name is set below along with value
+
+                                               $out[$outcount]["value"] = "FILES Not Available for View at this time";
+
+                                                       // Check if file type is specified and if so does it match
+
+                                               if( isset( $f[1] ) && ($GLOBALS[$field[4]."_name"] != "") && !eregi( ".".$f[1]."$",$GLOBALS[$field[4]."_name"]) )
+                                                       {
+                                                       $not_supplied .= $field_title_only.': "'.$GLOBALS[$field[4]."_name"].'" is not correct file type. Must be:  '.$f[1]."<BR>";
+                                                       break;
+                                                       }
+
+                                               switch( $field[3] )
+                                                       {
+                                                       case "SUPPLIED":
+                                                               $problem .= '<FONT COLOR="red">ERROR: "SUPPLIED" not permitted as option for file input</FONT>';
+                                                               break;
+
+                                                       case "TRUE":
+
+                                                                       // If no file is supplied and there's no file in the database
+
+                                                               if( $GLOBALS[$field[4]."_name"] == "" && $data[$field[0]] == "" )
+                                                                       {
+                                                                       $not_supplied .= $field_title_only.": Not Supplied<BR>";
+                                                                       break;
+                                                                       }
+
+                                                                       // If new file is supplied, replace old one
+                                                               if( $GLOBALS[$field[4]."_name"] != "" )
+                                                                       {
+                                                                       if( $data[$field[0]] != "" )
+                                                                               file_delete( $data[$field[0]] );
+                                                                       $qs .= $comma." ".$field[0]." = '".file_upload( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"] )."'";
+                                                                       $comma = ",";
+                                                                       }
+                                                               break;
+
+                                                       case "FALSE":
+
+                                                                       // If new file is supplied, store it
+
+                                                               if( $GLOBALS[$field[4]."_name"] != "" )
+                                                                       {
+                                                                       if( $data[$field[0]] )          // If there's already a file, delete it before storing the new one
+                                                                               file_delete( $data[$field[0]] );
+                                                                       $qs .= $comma." ".$field[0]." = '".file_upload( $GLOBALS[$field[4]], $GLOBALS[$field[4]."_name"] )."'";
+                                                                       $comma = ",";
+                                                                       }
+                                                                       // Else, if there's a file in the database and we're deleting
+                                                                   elseif( $data[$field[0]] != "" && isset($GLOBALS[$field[0]."_DELETE"])  )
+                                                                       {
+                                                                       file_delete( $data[$field[0]] );
+                                                                       $qs .= $comma." ".$field[0]." = ''";    // Clear file name in database
+                                                                       $comma = ",";
+                                                                       }
+
+                                                               break;
+
+                                                       default:
+                                                               $problem .= '<FONT COLOR="red">ERROR: Invalid "Required" field  name "'.$field[3].'" in function call</FONT><BR>';
+                                                               break;
+                                                       }
+                                               break;
+
+
+                                       case "checkbox":
+                                                       // Doesn't matter whether it's required or not, or whatever
+                                               $qs .= $comma." ".$field[0]." = ";              // Add field name to update to query string
+                                               $comma = ",";
+                                               if( $GLOBALS[$field[4]] == "on" )
+                                                       {
+                                                       $out[$outcount]["value"] = "Yes";
+                                                       $qs .= "TRUE";
+                                                       }
+                                                   else
+                                                       {
+                                                       $out[$outcount]["value"] = "No";
+                                                       $qs .= "FALSE";
+                                                       }
+                                               break;
+
+
+                                       case "bitmap":
+                                               $out[$outcount]["value"] = "Bitmaps not available for view at this time";
+                                               $qs .= $comma." ".$field[0]." = ";              // Add field name to update to query string
+                                               $comma = ",";
+                                               $b = 0;         // Start with clear bitmap
+                                               for( $i=0 ; $i<SI_INT_SIZE ; $i++ )             // Bitmaps are based on the size of an integer
+                                                       {
+                                                       if( isset($GLOBALS[$field[4]][$i]) && $GLOBALS[$field[4]][$i] == "on" ) // If checked
+                                                               $b = $b + pow(2,$i);                    // Set bit
+                                                       }
+
+                                               $qs .= $b;
+                                               break;
+
+                                       default:
+                                               $problem .= '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$field[1].' for '.$field[0].'</FONT><BR>';
+                                               break;
+
+                                       } // switch( field )
+
+                       $outcount++;
+                       } // foreach( field )
+
+               }
+           else
+               {
+               $ret .= '       <CENTER>(Record not found)</CENTER>
+                       <P>
+                    ';
+               return( array( 'text' => $ret, 'status' => false ) );
+               }
+
+       if( !empty($not_supplied) )
+               {
+               $result .= '    <H2>Required fields not supplied</H2><P>
+                       <FONT COLOR="red">'.$not_supplied.'</FONT><P>
+                       Use "BACK" button on browser, add missing data and resubmit.<P>
+                    ';
+               $update_record = false;
+               }
+
+       if( !empty($problem) )
+               {
+               $result .= $problem.'<P>
+                       Use "BACK" button on browser, correct problem field, and resubmit.<P>
+                    ';
+               $update_record = false;
+               }
+
+       if( $update_record && $qs != '' )
+               {
+               $qs = "UPDATE $table SET $qs WHERE id = $id;";
+               if( SI_DEBUG >= 1 ) $ret .= "<PRE>admin_update_record()[".__LINE__."]: Update record = $qs</PRE><BR>";
+               db_auto_exec( $qs, $conn_str, FALSE );
+               $result .= '<P><H2>Data updated.</H2><P>';
+               }
+
+               // Replace parameters in Title
+
+       for( $i=0 ; $i<$outcount ; $i++ )
+               {
+               $a_title = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $a_title );
+               $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $a_title );
+               }
+
+       $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+       $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+       $a_title = ereg_replace( "\\{result\\}", $result, $a_title );
+
+               // Add QuickTip if provided
+
+       if( trim($quick_tip) != '' )
+               $a_title = quick_tip( $a_title, $quick_tip );
+
+               // Display top of page
+
+       $ret .= '<CENTER>
+               '.$a_title."\n";
+
+       if( empty($view) )      // If there's no spec in $view
+               $ret .= $result;
+         else
+               {
+               for( $i=0 ; $i<$outcount ; $i++ )
+                       {
+                       $view = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $view );
+                       $view = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $view );
+                       }
+               $view = ereg_replace( "\\{999\\}", $out[999]["value"], $view );
+               $view= ereg_replace( "\\{link_params\\}", $link_params, $view );
+               $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+               $view = ereg_replace( "\\{result\\}", $result, $view );
+               $ret .= $view;
+               }
+
+       $ret .= '
+               </CENTER>
+            ';
+
+       return( array( 'text' => $ret, 'status' => $update_record ) );
+
+}
+
+function admin_update_record( $table, $conn_str, $id, $fields, $url, $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+       $r = admin_update_record_r( $table, $conn_str, $id, $fields, $url, $action, $params, $a_title, $view, $quick_tip );
+       echo $r['text'];
+       return( $r['status'] );
+}
+
+
+
+
+       // Ask for the deletion of a record
+
+function admin_delete_record_r( $table, $conn_str, $id, $fields,
+                               $options, $url, $action, $params, $a_title, $view="", $quick_tip="" )
+{
+
+       $ret = '';
+
+               // Break out configuration data
+
+       $field_table = explode_trim( "|", $fields );
+
+               // Don't be surprised if last field is blank
+
+       if( trim($field_table[count($field_table)-1]) == "" )
+               array_pop( $field_table );
+
+       foreach( $field_table as $key => $r )
+               $field_table[$key] = explode_trim( ",", $r );
+
+               // Check for additional parameters that are passed
+
+       if( !empty($params) )
+               {
+               $param = explode_trim( "|", $params );  // Separate parameters
+               $link_params = $form_params = "";
+               foreach( $param as $p )
+                       {
+                       $x = explode_trim( ".", $p );   // Separate Names from Values
+                       $link_params .= "&".$x[0]."=".urlencode($x[1]);
+                       $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+                       }
+               }
+
+               // Scan options
+
+       $option_strong = FALSE;
+       if( !empty($options) )
+               {
+               $option_table = explode_trim( ",", $options );
+               foreach( $option_table as $option )
+                       switch( $option )
+                               {
+                               case "strong":
+                                       $option_strong = TRUE;
+                                       break;
+
+                               default:
+//                                     $ret .=  '<H2><FONT COLOR="red">ERROR: Illegal Option Specified</FONT></H2>';
+                                       break;
+                               }
+               }
+
+
+               // Get the data
+
+       $query_string = "SELECT * FROM ".$table." WHERE id = $id;";
+       if( SI_DEBUG >= 1 ) $ret .=  "<PRE>admin_delete_record()[".__LINE__."]: Record to delete = $query_string</PRE><BR>";
+       $data = db_auto_get_row( $query_string, 0, $conn_str, $fail_mode );
+       $problem = '';
+
+       if( $data )
+               {
+
+                       // For each field in the result
+
+               $outcount = 0;  // replaceable field data table pointer
+               foreach( $field_table as $field )
+                       {
+                       $f2 = explode_trim( "~", $field[2] );
+                       $out[$outcount]["name"] = $f2[0];
+                       $out[$outcount]["display"] = $field[3] != "HIDDEN" ? TRUE : FALSE;
+                       $f = explode_trim( ".", $field[1] );            // Extract type options
+                       switch( $f[0] )
+                               {
+                                       // Check other tables for references to this record
+
+                               case "check":
+                                       if( $f[1] == '' || $f[2] == '' )
+                                               {
+                                               $problem .= '<FONT COLOR="red">'.$field[0].': Table or Field name not supplied for reference check.</FONT><BR>';
+                                               break;
+                                               }
+                                       if( ($c = db_auto_get_row( "SELECT count(".$f[2].") FROM ".$f[1]." WHERE ".$f[2]." = $id;" )) && $c['count'] > 0 )
+                                               {
+                                               $problem .= '<FONT COLOR="red">This reccord is referenced '.$c['count'].' time(s) by "'.$f2[0].'". Delete References first.</FONT><BR>';
+                                               break;
+                                               }
+
+                                       break;
+
+                               case "money":
+                                       $out[$outcount]["value"] = "$".sprintf( "%01.2f", $data[$field[0]] );
+                                       break;
+
+                               case "order":
+                               case "int":
+                               case "float":
+                               case "fixed":
+                                       $out[$outcount]["value"] = $data[$field[0]];
+                                       break;
+
+                               case "checkbox":
+                                       $out[$outcount]["value"] = $data[$field[0]] == 't' ? 'Yes' : 'No';
+                                       break;
+
+                               case "text":
+                               case "inet":
+                               case "state":
+                               case "country":
+                               case "textbox":
+                               case "richtext":
+                               case "date":
+                                       $out[$outcount]["value"] = $data[$field[0]];
+                                       break;
+
+                               case "checkbox":
+                                       $out[$outcount]["value"] = $data[$field[0]] == "t" ? "Yes" : "No" ;
+                                       break;
+                               case "url":
+                                       $out[$outcount]["value"] = '<A HREF="'.$data[$field[0]].'">'.$data[$field[0]].'</A>';
+                                       break;
+
+                               case "category":
+                                               // Get the category name for this field if supplied
+                                       if( !empty($data[$field[0]]) )
+                                               {
+                                               if( $cval = db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE id = ".$data[$field[0]].";", 0, $conn_str, FALSE ) )
+                                                       $out[$outcount]["value"] = $cval['name'];
+                                                 else
+                                                       $out[$outcount]["value"] = '<FONT COLOR="red">Unknown Category</FONT>';
+                                               }
+                                         else
+                                               {
+                                               $out[$outcount]["value"] = "&nbsp;";
+                                               }
+                                       break;
+
+                               case "pointer":
+                                               // If {value_field} supplied use that, otherwise use id of record as value to match
+                                       $value_field = !empty($f[3]) ? $f[3] : "id" ;
+
+                                               // If {where} supplied use that, otherwise get all possibilities from other table
+                                       $w = !empty($f[4]) ? " WHERE ".$f[4] : " WHERE ".$value_field." = ".$data[$field[0]] ;
+
+                                       $pval = db_auto_get_row(
+                                               "SELECT * FROM ".$f[1].$w.";",
+                                               0, $conn_str, $fail_mode );
+                                       $out[$outcount]["value"] = $pval[$f[2]];
+                                       break;
+
+                               default:
+                                       $out[$outcount]["value"] = '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$f[0].' for '.$field[0].'</FONT>';
+                                       break;
+
+                               } // switch( field )
+                       $outcount++;
+                       } // foreach( field )
+
+                       // Confirm field and Submit button go into {submit}
+
+               if( $option_strong )
+                       $submit = '<BR>
+                               To confirm, type "Delete" below.<BR>
+                               <FORM ACTION="'.$url.'" METHOD="post">
+                                       <INPUT TYPE="hidden" NAME="id" VALUE="'.$id.'">
+                                       <INPUT TYPE="hidden" NAME="Action" VALUE="'.$action.'">
+                                       <INPUT TYPE="text" NAME="Confirm"><BR>
+                                       <INPUT TYPE="hidden" NAME="Option" VALUE="Confirm Delete">
+                                       <INPUT TYPE="submit" NAME="usingHiddenOption" VALUE="Confirm Delete">
+                                       '.$form_params.'
+                               </FORM>
+                            ';
+                   else
+                       $submit = '
+                               <FORM ACTION="'.$url.'" METHOD="post">
+                                       <INPUT TYPE="hidden" NAME="id" VALUE="'.$id.'">
+                                       <INPUT TYPE="hidden" NAME="Action" VALUE="'.$action.'">
+                                       <INPUT TYPE="hidden" NAME="Confirm" VALUE="Delete"><BR>
+                                       <INPUT TYPE="hidden" NAME="Option" VALUE="Confirm Delete">
+                                       <INPUT TYPE="submit" NAME="usingHiddenOption" VALUE="Confirm Delete">
+                                       '.$form_params.'
+                               </FORM>
+                            ';
+
+                       // Replace parameters in Title
+
+               for( $i=0 ; $i<$outcount ; $i++ )
+                       {
+                       $a_title = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $a_title );
+                       $a_title = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $a_title );
+                       }
+
+               $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+               $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+               $a_title = ereg_replace( "\\{submit\\}", $submit, $a_title );
+               $a_title = ereg_replace( "\\{result\\}", $result, $a_title );
+
+
+                       // Add QuickTip if provided
+
+               if( trim($quick_tip) != '' )
+                       $a_title = quick_tip( $a_title, $quick_tip );
+
+
+                       // Output results
+
+               if( empty($view) )      // If there's no format spec in $view
+                       {
+                       $ret .=  '<CENTER>'.$a_title.'
+                               <P>
+                               <H2>Are you sure you want to delete this information?</H2>
+                               <TABLE BORDER="1">
+                            ';
+                       for( $i=0 ; $i<$outcount ; $i++ )
+                               {
+                               if( $out[$i]["display"] )
+                                       $ret .=  '<TR><TH ALIGN="right" VALIGN="top">'.$out[$i]["name"]
+                                               .'&nbsp;</TH><TD ALIGN="left">'.$out[$i]["value"].'&nbsp;</TD></TR>
+                                            ';
+                               }
+                       $ret .=  '      <P>
+                               </TABLE>'.$submit;      // Output the Confirm field and submit button
+
+                       }
+                   else        // Otherwise use $view to output data
+                       {
+                       for( $i=0 ; $i<$i ; $i++ )
+                               {
+                               $view = ereg_replace( "\\{".$i."\\}", $out[$i]["value"], $view );
+                               $view = ereg_replace( "\\{encode:".$i."\\}", urlencode($out[$i]["value"]), $view );
+                               }
+                       $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+                       $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+                       $view = ereg_replace( "\\{submit\\}", $submit, $view );
+                       $view = ereg_replace( "\\{result\\}", $result, $view );
+                       $ret .=  '<CENTER>'.$a_title.$view;
+                       }
+
+               if( $problem != '' )
+                       {
+                       $ret = '<CENTER>'.$a_title.$problem.'</CENTER>';
+                       return( array( 'text' => $ret, 'status' => false ) );
+                       }
+
+               } // if( $data )
+           else
+               $ret .=  '      <CENTER>(No results found)</CENTER>
+                       <P>
+                    ';
+
+
+
+       $ret .=  '</CENTER>
+            ';
+
+       return( array( 'text' => $ret, 'status' => true ) );
+
+}
+
+function admin_delete_record( $table, $conn_str, $id, $fields,
+                               $options, $url, $action, $params, $a_title, $view="", $quick_tip="" )
+{
+       $r = admin_delete_record_r( $table, $conn_str, $id, $fields,
+                               $options, $url, $action, $params, $a_title, $view, $quick_tip );
+       echo $r['text'];
+       return( $r['status'] );
+}
+
+
+       // Delete a record if confirmed
+
+function admin_confirm_delete_record_r( $table, $conn_str, $id, $fields, $url,
+                       $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+
+       $ret = '';
+
+               // Make all submitted parameters available
+
+//     extract($GLOBALS[HTTP_POST_VARS]);
+//     extract($GLOBALS[HTTP_GET_VARS]);
+
+               // Check for additional parameters that are passed
+
+       if( !empty($params) )
+               {
+               $param = explode_trim( "|", $params );  // Separate parameters
+
+               $link_params = $form_params = "";
+               foreach( $param as $p )
+                       {
+                       $x = explode_trim( ".", $p );   // Separate Names from Values
+                       $link_params .= "&".$x[0]."=".urlencode($x[1]);
+                       $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+                       }
+               }
+
+               // Check "Confirm" field for correct text
+
+       $result = "";
+       $delete_record = TRUE;          // Assume that we're going to delete this record
+       if( $GLOBALS['Confirm'] == "Delete" )
+               {
+
+                       // Get the current data for reference and to make sure it exists
+
+               $query_string = "SELECT * FROM $table WHERE id = $id;";
+               if( SI_DEBUG >= 1 ) $ret .=  "<PRE>admin_confirm_delete_record()[".__LINE__."]: Record to delete = $query_string</PRE><BR>";
+               $data = db_auto_get_row( $query_string, 0, $conn_str, $fail_mode );
+
+                       // Separate field title from QuickTip in case we need it
+               $fta = explode_trim( "~", $field[2] );
+               $field_title_only = $fta[0];
+
+
+               if( $data )
+                       {
+
+                       $not_delete_message = "";
+
+                       if( trim($fields) != "" )       // If there's any check fields
+                               {
+                                       // Break out configuration data
+
+                               $field_table = explode_trim( "|", $fields );
+
+                                       // Don't be surprised if last field is blank
+
+                               if( trim($field_table[count($field_table)-1]) == "" )
+                                       array_pop( $field_table );
+
+                               foreach( $field_table as $key => $r )
+                                       $field_table[$key] = explode_trim( ",", $r );
+
+                                       // For each check field specified
+
+                               foreach( $field_table as $field )
+                                       {
+                                       $f = explode_trim( ".", $field[1] );
+                                       switch( $f[0] )
+                                               {
+                                               case "reference":       // Check to see if this record is referenced
+                                                       if( db_auto_get_row( "SELECT id FROM ".$f[1]." WHERE ".$f[2]." = $id;", 0, $conn_str, $fail_mode ) )
+                                                               {
+                                                               $result .= '<FONT COLOR="red">Can\'t delete this information. You must delete '.$field[2].' first.</FONT><BR>';
+                                                               $delete_record = FALSE;
+                                                               }
+                                                       break;
+
+                                               case "image":
+                                                       delete_image( $data[$field[0]] );
+                                                       break;
+
+                                               default:
+                                                       $result .= '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$f[0].' for '.$field[0].'</FONT><BR>';
+                                                       $delete_record = FALSE;
+                                                       break;
+
+                                               } // switch( field )
+
+                                       } // foreach( field )
+                               }
+                       } // if data
+                 else
+                       {
+                       $result .= '<H2><FONT COLOR="red">Record not found</FONT></H2><BR>';
+                       $delete_record = FALSE;
+                       }
+
+
+               } // if Confirm
+         else
+               {
+               $result .= '<H2>Delete <FONT COLOR="red">NOT</FONT> Confirmed.</H2>';
+               $delete_record = FALSE;
+               }
+
+
+       if( $delete_record )
+               {
+               $qs = "DELETE FROM ".$table." WHERE id = ".$id.";";
+               if( SI_DEBUG >= 1 ) $ret .=  "<PRE>admin_confirm_delete_record()[".__LINE__."]: Delete Record = $qs</PRE><BR>";
+               db_auto_exec( $qs, $conn_str, FALSE );
+               $result .= '<P><H2>Record Deleted.</H2>';
+               }
+           else
+               $result .= '<P><H2>Not deleting this record</H2><P>
+                       <FONT COLOR="red" SIZE="4">'.$not_delete_message.'</FONT><P>
+                    ';
+
+               // Make replacements in $a_title
+
+       $a_title = ereg_replace( "\\{result\\}", $result, $a_title );
+       $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+       $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+
+               // Add QuickTip if provided
+
+       if( trim($quick_tip) != '' )
+               $a_title = quick_tip( $a_title, $quick_tip );
+
+               // Display top of page
+
+       $ret .=  '<CENTER>
+               '.$a_title.'
+            ';
+
+       if( empty($view) )
+               $ret .=  $result;
+           else
+               {
+               $view = ereg_replace( "\\{result\\}", $result, $view );
+               $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+               $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+               $ret .=  $view;
+               }
+
+       $ret .=  '
+               </CENTER>
+            ';
+
+
+       return( array( 'text' => $ret, 'status' => $delete_record ) );
+
+
+}
+
+function admin_confirm_delete_record( $table, $conn_str, $id, $fields, $url,
+                       $action, $params, $a_title, $view = "", $quick_tip = "" )
+{
+       $r = admin_confirm_delete_record_r( $table, $conn_str, $id, $fields, $url,
+                       $action, $params, $a_title, $view, $quick_tip );
+       echo $r['text'];
+       return( $r['status'] );
+}
+
+
+
+
+       // View the data in a record
+
+function admin_view_record_r( $table, $conn_str, $id, $fields,
+                               $url, $action, $params, $a_title, $view="", $options = "", $quick_tip = "", $id_field = '' )
+{
+
+       $ret = '';
+
+       if( empty($id_field) )
+               $id_field = 'id';
+
+               // Check for any options
+
+       $borders = strstr( $options, "borders" ) ? 1 : 0;               // Show table borders
+       $nocenter = strstr( $options, "nocenter" ) ? 1 : 0;             // Don't output <center></center> tags around content
+
+               // Break out configuration data
+
+       $field_table = explode_trim( "|", $fields );
+
+               // Don't be surprised if last field is blank
+
+       if( trim($field_table[count($field_table)-1]) == "" )
+               array_pop( $field_table );
+
+               // Check for additional parameters that are passed
+
+       if( !empty($params) )
+               {
+               $param = explode_trim( "|", $params );  // Separate parameters
+               $link_params = $form_params = "";
+               foreach( $param as $p )
+                       {
+                       $x = explode_trim( ".", $p );   // Separate Names from Values
+                       $link_params .= "&".$x[0]."=".urlencode($x[1]);
+                       $form_params .= '<INPUT TYPE="hidden" NAME="'.$x[0].'" VALUE="'.$x[1].'">';
+                       }
+               }
+
+               // Get the data
+
+       $qs = "SELECT * FROM $table WHERE ".$id_field." = $id;";
+       if( SI_DEBUG >= 1 ) $ret .=  "<PRE>admin_view_record()[".__LINE__."]: View Record = $qs</PRE><BR>";
+       $data = db_auto_get_row( $qs, 0, $conn_str, $fail_mode );
+
+       if( $data )
+               {
+                       // For each field in the result
+
+               for( $res_field=0 ; $res_field<count($field_table) ; $res_field++ )
+                       {
+                       $field = explode_trim( ",", $field_table[$res_field] );
+                       $f = explode_trim( ".", $field[1] );
+                       $out[$res_field]["hidden"] = preg_match( "/hidden/", $field_table[$res_field] );        // Check for .hidden
+
+                               // Check for pop-up-tips
+
+                       $n = explode_trim( '~', $field[2] );
+                       if( count($n) > 1 )
+                               {
+                                       // setup tip display - requires show_QuickTip() and hide_QuickTip() functions from java_functions.js
+
+                               $out[$res_field]["name"]  = quick_tip( '<font color="'.$field_name_color.'">'.$n[0].'</font>', $n[1] );
+                               }
+                         else
+                               $out[$res_field]["name"] = $field[2];
+
+                       $out[$res_field]['field'] = $field[0];
+
+                       switch( $f[0] )
+                               {
+
+                               case "lat":
+                                       $fw = 2;
+                                       if( $f[1] > 0 )
+                                               $fw = $f[1];
+                                       $ns = 'N';
+                                       if( $data[$field[0]] < 0 )
+                                               {
+                                               $ns = 'S';
+                                               $data[$field[0]] = -1 * $data[$field[0]];
+                                               }
+                                       $dv = (int) $data[$field[0]];
+                                       $mv = ( $data[$field[0]] - $dv ) * 60;
+                                       $out[$res_field]["value"] = sprintf( "%s %d&deg; %01.".$fw."f'", $ns, $dv, $mv );
+                                       break;
+
+                               case "lon":
+                                       $fw = 2;
+                                       if( $f[1] > 0 )
+                                               $fw = $f[1];
+                                       $ns = 'E';
+                                       if( $data[$field[0]] < 0 )
+                                               {
+                                               $ns = 'W';
+                                               $data[$field[0]] = -1 * $data[$field[0]];
+                                               }
+                                       $dv = (int) $data[$field[0]];
+                                       $mv = ( $data[$field[0]] - $dv ) * 60;
+                                       $out[$res_field]["value"] = sprintf( "%s %d&deg; %01.".$fw."f'", $ns, $dv, $mv );
+                                       break;
+
+                               case "money":
+                                       $out[$res_field]["value"] = "$".sprintf( "%01.2f", $data[$field[0]] );
+                                       break;
+
+                               case "fixed":
+                                       $fw = 2;
+                                       if( $f[1] > 0 )
+                                               $fw = $f[1];
+                                       $out[$res_field]["value"] = sprintf( "%01.".$fw."f", $data[$field[0]] );
+                                       break;
+
+                               case "text":
+                               case "inet":
+                               case "textbox":
+                               case "richtext":
+                                       $out[$res_field]["value"] = nl2br( $data[$field[0]] );
+                                       break;
+
+                               case "rawtext":
+                                       $out[$res_field]["value"] = $data[$field[0]];
+                                       break;
+
+                               case "order":
+                               case "int":
+                               case "date":
+                               case "float":
+                                       $out[$res_field]["value"] = $data[$field[0]];
+                                       break;
+
+                               case "url":
+                                       $out[$res_field]["value"] = '<A HREF="'.$data[$field[0]].'">'.$data[$field[0]].'</A>';
+                                       break;
+
+                               case "category":
+                                               // Get the category name for this field is supplied
+                                       if( !empty($data[$field[0]]) )
+                                               {
+                                               if( $cval = db_auto_get_row( "SELECT * FROM ".$f[1]." WHERE id = ".$data[$field[0]].";", 0, $conn_str, FALSE ) )
+                                                       $out[$res_field]["value"] = $cval['name'];
+                                                 else
+                                                       $out[$res_field]["value"] = '<FONT COLOR="red">Unknown Category</FONT>';
+                                               }
+                                         else
+                                               {
+                                               $out[$res_field]["value"] = "&nbsp;";
+                                               }
+                                       break;
+
+                               case "pointer":
+
+                                       if( !empty($data[$field[0]]) )
+                                               {
+                                                       // If {where} supplied use that, otherwise match "id" field
+                                               $w = !empty($f[4]) ? " WHERE ".$f[4] : " WHERE id = ".$data[$field[0]] ;
+                                               $comma = '';
+                                               if( ($pvals = db_auto_get_data( "SELECT * FROM ".$f[1].$w.";", $conn_str, $fail_mode )) )
+                                                       {
+                                                       foreach( $pvals as $pval )
+                                                               {
+                                                               $out[$res_field]["value"] .= $comma.$pval[$f[2]];
+                                                               $comma = ', ';
+                                                               }
+                                                       }
+                                                 else
+                                                       $out[$res_field]["value"] = '';
+                                               }
+                                         else
+                                               $out[$res_field]["value"] = '';
+
+                                       break;
+
+                               case "multifield":              // NOT TESTED  multitext.numb_fields.new_line_string
+
+                                       if( trim($f[2]) == '' )
+                                               {
+                                               $out[$res_field]["value"] = '<FONT COLOR="RED">Missing multifield line specification</FONT>';
+                                               break;
+                                               }
+
+                                       $v = '';
+
+
+                                               // If there's data, then build existing input lines with data
+                                       if( ( $x = trim($data[$field[0]]) ) != '' )
+                                               {
+                                               $field_data = unserialize( $data[$field[0]] );
+
+                                               if( $field_data != false && is_array( $field_data ) )
+                                                       {
+
+                                                               // For each line of inputs
+                                                       for( $i=1 ; $i<=count($field_data) ; $i++ )
+                                                               {
+                                                               $f_line = str_replace( '{line_numb}', ($i), $f[2] );            // Set line number in output text
+                                                                       // For each input field on the line
+
+                                                               for( $j=1 ; $j<=$f[1] ; $j++ )
+                                                                       $f_line = str_replace( '{field_'.($j).'}', $field_data[$i-1][$j-1], $f_line );
+
+                                                               $v .= $f_line;
+
+                                                               }
+                                                       }
+                                               }
+
+                                       $out[$res_field]["value"] = $v;
+
+                                       break;
+
+
+                               case "image":
+                                       if( !empty($data[$field[0]]) )
+                                               {
+                                               switch( $f[1] )
+                                                       {
+                                                       case "o":       $img_url = SI_IMG_ORIGINAL_URL; break;
+                                                       case "r":       $img_url = SI_IMG_RESIZED_URL;  break;
+                                                       case "m":       $img_url = SI_IMG_MIDSIZED_URL; break;
+                                                       case "t":       $img_url = SI_IMG_THUMB_URL;    break;
+                                                       default:        $img_url = "none";              break;
+                                                       }
+                                               if( $img_url != "none" )
+                                                       $out[$res_field]["value"] = '<IMG SRC="'.$img_url."/".$data[$field[0]].'">';
+                                                   else
+                                                       $out[$res_field]["value"] = '<FONT COLOR="RED">Invalid Image Size</FONT>';
+                                               }
+                                         else
+                                               $out[$res_field]["value"] = '(no image)';
+                                       break;
+
+                               case "images":
+                                       if( !empty($data[$field[0]]) )
+                                               {
+                                               if( $img_url != "none" )
+                                                       {
+                                                       $images = unserialize( $data[$field[0]] );
+                                                       foreach( $images as $im )
+                                                               {
+                                                               switch( !empty($im['size']) ? $im['size'] : $f[1] )
+                                                                       {
+                                                                       case "o":       $img_url = SI_IMG_ORIGINAL_URL; break;
+                                                                       case "r":       $img_url = SI_IMG_RESIZED_URL;  break;
+                                                                       case "m":       $img_url = SI_IMG_MIDSIZED_URL; break;
+                                                                       case "t":       $img_url = SI_IMG_THUMB_URL;    break;
+                                                                       default:        $img_url = "none";              break;
+                                                                       }
+                                                               $out[$res_field]["value"] = '<IMG SRC="'.$img_url."/".$im['filename'].'"><BR>'.$im['descr'];
+                                                               }
+                                                       }
+                                                 else
+                                                       $out[$res_field]["value"] = '<FONT COLOR="RED">Invalid Image Size</FONT>';
+                                               }
+                                         else
+                                           $out[$res_field]["value"] = '(no image)';
+                                       break;
+
+                               case "file":
+                                       $out[$res_field]["value"] = '<A HREF="'.SI_BASE_FILE_URL.'/'.$data[$field[0]].'">'.$data[$field[0]].'</A>';
+                                       break;
+
+
+                               case "checkbox":
+                                       $x = $data[$field[0]] == "t" ? "Yes" : "No";
+                                       $out[$res_field]["value"] = $x;
+                                       break;
+
+                               case "bitmap":
+                                       $bmap = explode_trim( "~", $f[1] );
+                                       $out[$res_field]["value"] = '<TABLE BORDER="0">';
+                                       for( $j=0 ; $j<count($bmap) ; $j++ )
+                                               if( $bmap[$j] != ' ' )
+                                                       {
+                                                       $d = $data[$field[0]] & pow( 2, $j ) ? "Yes" : "No";            // Check if this bit set
+                                                       $out[$res_field]["value"] .= '<TR><TD>'.$bmap[$j].'</TD><TD>'.$d.'</TD></TR>';
+                                                       }
+                                       $out[$res_field]["value"] .= '</TABLE>';
+                                       break;
+
+                               case "list":
+                                       $option_table = "";
+                                       $opts = explode_trim( "~", $f[1] );     // Separate list options
+                                       $def_value = !empty($f[2]) ? $f[2] : "" ;
+                                       foreach( $opts as $opt )
+                                               {
+                                               $os = explode_trim( "^", $opt );        // Separate value from displayed text
+                                               $option_table[$os[0]] = $os[1];
+                                               }
+                                               // In case there's multiple options, display results of all selected options with comma separators
+                                       $x = explode( '~', $data[$field[0]] );
+                                       $out[$res_field]["value"] = $sep = '';
+                                       if( is_array($x) )
+                                               foreach( $x as $y )
+                                                       {
+                                                       $out[$res_field]["value"] .= $sep.$option_table[$y];
+                                                       $sep = ', ';
+                                                       }
+                                       break;
+
+                               case "state":
+                                       $out[$res_field]["value"] = $GLOBALS['si_states_array'][$data[$field[0]]];
+                                       break;
+
+                               case "country":
+                                       $out[$res_field]["value"] = $GLOBALS['si_countries_array'][$data[$field[0]]];
+                                       break;
+
+                               case "break":
+                                       if( !empty($f[1]) )     // if {t1} is supplied
+                                               $out[$res_field]["value"] = $f[1];
+                                         else
+                                               $out[$res_field]["value"] = '<FONT COLOR="red">No break name or {text} supplied for type "break"</FONT>';
+                                       break;
+
+                               default:
+                                       $out[$res_field]["value"] = '<FONT COLOR="red">UNKNOWN FIELD TYPE: '.$x[0].' for '.$f[0].'</FONT>';
+                                       break;
+
+                               } // switch( field type )
+                       } // foreach( field )
+
+               } // if( $data )
+         else
+               {
+               return( array( 'text' => 'No Data Found', 'status' => false ) );
+               }
+
+               // Replace parameters in title and view
+
+       reset( $out );
+       while( list ($k, $v) = each($out) )
+               {
+               $a_title = ereg_replace( "\\{".$v['field']."\\}", $v["value"], $a_title );
+               $view = ereg_replace( "\\{".$v['field']."\\}", $v["value"], $view );
+               $a_title = ereg_replace( "\\{encode:".$v['field']."\\}", urlencode($v["value"]), $a_title );
+               $view = ereg_replace( "\\{encode:".$v['field']."\\}", urlencode($v["value"]), $view );
+               }
+
+       $a_title = ereg_replace( "\\{link_params\\}", $link_params, $a_title );
+       $a_title = ereg_replace( "\\{form_params\\}", $form_params, $a_title );
+       $view = ereg_replace( "\\{link_params\\}", $link_params, $view );
+       $view = ereg_replace( "\\{form_params\\}", $form_params, $view );
+
+               // Add QuickTip if provided
+
+       if( trim($quick_tip) != '' )
+               $a_title = quick_tip( $a_title, $quick_tip );
+
+               // Display top of page
+
+       if( !$nocenter )
+               $ret .=  '<CENTER>';
+
+       $ret .=  "$a_title\n";
+
+       if( $data )
+               {
+                       // Output results
+
+               if( empty($view) )      // If there's no format spec in $view
+                       {
+                       $ret .=  '<TABLE BORDER="'.$borders.'"'.($borders>0?' CELLPADDING="5"':'').'>
+                            ';
+                       reset( $out );
+                       while( list( $k, $v ) = each($out) )
+                               if( !$v["hidden"] )
+                                       $ret .=  '<TR><TH ALIGN="right" VALIGN="top">'.$v["name"].'&nbsp;</TH><TD ALIGN="left">'.$v["value"].'</TD></TR>
+                                                                            ';
+
+                       $ret .=  '</TABLE>
+                            ';
+                       }
+                 else  // Otherwise use $view to output data
+                       $ret .=  $view;
+               }
+           else
+               $ret .=  '      <CENTER>(No results found)</CENTER>
+                       <P>
+                    ';
+
+       if( !$nocenter )
+               $ret .=  "</CENTER>\n";
+
+       return( array( 'text' => $ret, 'status' => true ) );
+
+}
+
+function admin_view_record( $table, $conn_str, $id, $fields,
+                               $url, $action, $params, $a_title, $view="", $options = "", $quick_tip = "", $id_field = '' )
+{
+
+       $r = admin_view_record_r( $table, $conn_str, $id, $fields,
+                               $url, $action, $params, $a_title, $view, $options, $quick_tip, $id_field );
+       echo $r['text'];
+       return( $r['status'] );
+}
+
+
+
+
+       // User login management
+
+function admin_user_login( $operation, $conn_str, $sess_code, $table, $id_field, $pw_field, $user_id = "", $password = "", $where = "" )
+{
+
+       $secret_code = "ApplesANDOranges";      // Secret code used to md5 encrypt everything
+
+       switch( $operation )
+               {
+
+               case "create":
+
+                               // Get user information and create a session
+
+                       $d = db_auto_get_row( "SELECT * FROM $table WHERE id = '$sess_code';", 0, $conn_str, FALSE );
+                       if( !$d )
+                               return( FALSE );
+
+                               // Build MD5 string from User ID, timestamp, "id" field value and secret
+
+                       $t = time();
+                       $md5_string = md5( $d[$id_field].$t.$d["id"].$secret_code );
+
+                               // Build output data
+
+                       $d["session_code"] = $md5_string."-".$t."-".$d["id"];           // Session Code
+                       $d["session_link"] = "&session_code=".$d["session_code"];       // Link format
+                       $d["session_form"] = '<INPUT TYPE="hidden" NAME="session_code" VALUE="'.$d["session_code"].'">';        // Form format
+
+                       return $d;
+
+
+                       break;
+
+               case "login":
+
+                               // Do sanity check
+
+                       if( empty($user_id) || empty($password) || preg_match("/[,*']/", $user_id) || preg_match("/[,*']/", $password) )
+                               return( FALSE );
+
+                               // Check ID and Password against specified table
+
+                       $d = db_auto_get_row( "SELECT * FROM $table WHERE $id_field = '$user_id' AND $pw_field = '$password'".($where!=''?' AND '.$where:'').";",
+                                               0, $conn_str, FALSE );
+                       if( !$d )
+                               return( FALSE );
+
+                               // Build MD5 string from User ID, timestamp, "id" field value and secret
+
+                       $t = time();
+                       $md5_string = md5( $d[$id_field].$t.$d["id"].$secret_code );
+
+                               // Build output data
+
+                       $d["session_code"] = $md5_string."-".$t."-".$d["id"];           // Session Code
+                       $d["session_link"] = "&session_code=".$d["session_code"];       // Link format
+                       $d["session_form"] = '<INPUT TYPE="hidden" NAME="session_code" VALUE="'.$d["session_code"].'">';        // Form format
+
+                       return $d;
+
+                       break;
+
+               case "verify":
+
+                               // Break apart session code - [0] = md5, [1] = timestamp, [2] = record id
+
+                       $ses = explode_trim( "-", $sess_code );
+                       if( count($ses) != 3 || !is_numeric($ses[2]) )                  // If there's not 3 parts, or the id isn't numeric, then it's not a valid code
+                               return( FALSE );
+
+                               // Retrieve data record
+
+                       $d = db_auto_get_row( "SELECT * FROM $table WHERE id = ".$ses[2].($where!=''?' AND '.$where:'').";", 0, $conn_str, FALSE );
+
+                       if( !$d )                               // If no results, then not a valid record id
+                               return( FALSE );
+
+                               // Check MD5 string for valid session
+
+                       if( md5($d[$id_field].$ses[1].$d["id"].$secret_code) != $ses[0] )
+                               return( FALSE );
+
+                               // Check to see if session has timed out
+
+                       if( $ses[1] + SI_SES_TIMEOUT < time() )
+                               return( FALSE );
+
+                               // Update Timestamp and MD5 string
+
+                       $t = time();
+                       $md5_string = md5( $d[$id_field].$t.$d["id"].$secret_code );
+
+                               // Build output data
+
+                       $d["session_code"] = $md5_string."-".$t."-".$d["id"];           // Session Code
+                       $d["session_link"] = "&session_code=".$d["session_code"];       // Link format
+                       $d["session_form"]  = '<INPUT TYPE="hidden" NAME="session_code" VALUE="'.$d["session_code"].'">';       // Form format
+
+                       return( $d );
+
+                       break;
+
+               default:
+                       echo '<FONT COLOR="red">UNKNOWN user login operation</FONT>';
+                       return( FALSE );
+                       break;
+               }
+
+}
+
+
+
+function authorize_net_aim
+               (
+               $login, $key, $test, $conf_email, $merch_email,
+               $amount, $card_num, $exp_date, $card_code, $currency = '',
+               $fname = '', $lname = '', $company = '', $address = '', $city = '', $state = '', $zip = '', $country = '', $phone = '', $fax = '', $id = '', $ip = '', $tax_id = '',
+               $email = '',
+               $invoice = '', $descr ='', $header = '', $footer = '',
+               $ship_fname = '', $ship_lname = '', $ship_company = '', $ship_address = '', $ship_city = '', $ship_state = '', $ship_zip = '', $ship_country = ''
+               )
+{
+
+       /*
+               Authorize.net processing
+
+               Test card #
+
+                 TEST CARD               CARD TYPE
+                 NUMBER
+                 370000000000002         American Express
+                 6011000000000012        Discover
+                 5424000000000015        MasterCard
+                 4007000000027           Visa
+
+       */
+
+               // Make sure test is exactly 'FALSE' before conducting an actual transaction
+
+       switch( $test )
+               {
+               case 'LOCAL_TEST':
+               case 'LOCAL_FAIL':
+               case 'TRUE':
+               case 'FALSE':
+                       break;
+
+               default:
+                       echo 'APPLICATION ERROR: Authorize.Net test mode not properly defined.';
+                       exit;
+                       break;
+               }
+
+               // Compile submitted data
+
+       $submit_data = array
+               (
+                       // Base required information                                    Required
+
+               'x_version'                             => '3.1',
+               'x_delim_data'                  => 'TRUE',                                      //      Yes
+               'x_delim_char'                  => '|',
+               'x_encap_char'                  => '',
+               'x_relay_response'              => 'FALSE',                                     //      Yes
+               'x_test_request'                => $test,
+
+                       // Merchant Account Information
+
+               'x_login'                               => $login,                                      //      Yes
+               'x_tran_key'                    => $key,                                        //      Yes
+
+                       // Transaction parameters
+
+               'x_currency_code'               => '',
+               'x_method'                              => 'CC',                                        //      Yes             Options: CC, ( ECHECK not implemented )
+               'x_type'                                => 'AUTH_CAPTURE',                      //      Yes             Options: AUTH_CAPTURE, AUTH_ONLY, CAPTURE_ONLY, CREDIT, VOID, PRIOR_AUTH_CAPTURE
+               'x_amount'                              => $amount,                                     //      Yes
+
+                       // If x_method = 'CC'
+
+               'x_card_num'                    => $card_num,                                   //      Yes
+               'x_exp_date'                    => $exp_date,                           //      Yes
+               'x_card_code'                   => $card_code,
+
+                       // Additional Customer information
+
+               'x_first_name'                  => $fname,
+               'x_last_name'                   => $lname,
+               'x_company'                             => $company,
+               'x_address'                             => $address,
+               'x_city'                                => $city,
+               'x_state'                               => $state,                                      //                      Verified if supplied
+               'x_zip'                                 => $zip,
+               'x_country'                             => $country,                            //                      Verified if supplied
+               'x_phone'                               => $phone,
+               'x_fax'                                 => $fax,
+               'x_cust_id'                             => $id,
+               'x_customer_ip'                 => $ip,
+               'x_customer_tax_id'             => $tax_id,
+
+                       // E-Mail info for confirmation
+
+               'x_email'                               => $email,                                      //                      Customer E-Mail
+               'x_email_customer'              => $conf_email,                         //                      IF TRUE customer will receive conf via E-Mail from Authorize.Net
+               'x_header_email_receipt'        => $header,                                     //                              Header to be included in conf E-Mail
+               'x_footer_email_receipt'        => $footer,                                     //                              Footer to be included in conf E-Mail
+               'x_merchant_email'              => $merch_email,                                //                      If supplied, merchant will receive conf via E-Mail
+
+                       // Invoice
+
+               'x_invoice_num'                 => $invoice,
+               'x_description'                 => $descr,
+
+                       // Shipping information
+
+               'x_ship_to_first_name'  => $ship_fname,
+               'x_ship_to_last_name'   => $ship_lname,
+               'x_ship_to_company'             => $ship_company,
+               'x_ship_to_address'             => $ship_address,
+               'x_ship_to_city'                => $ship_city,
+               'x_ship_to_state'               => $ship_state,
+               'x_ship_to_zip'                 => $ship_zip,
+               'x_ship_to_country'             => $ship_country,
+
+
+               );
+
+       if( SI_DEBUG > 2 )
+               {
+               echo "<P>DEBUG: Authorize.Net Submit Array<BR><PRE>\n";
+
+               echo "\n</PRE><P>";
+               }
+
+               // Assemble above data into a string for posting
+
+       if( SI_DEBUG > 0 )
+               echo "<P>DEBUG: Authorize.Net Submit Array<BR><PRE><table><tr><th align=\"left\">Parameter</th><th align=\"left\">Value</th></tr>\n";
+
+       $postdata = $sep = '';
+       foreach($submit_data AS $key => $val)
+               {
+               $postdata .= $sep.urlencode( $key ).'='.urlencode( $val );
+               $sep = '&';
+               if( SI_DEBUG > 0 )
+                       echo "<tr><td>$key</td><td>$val</td></tr>\n";
+               }
+
+       if( SI_DEBUG > 0 )
+               echo "</table></PRE><P>";
+
+       if( SI_DEBUG > 0 )
+               echo "<P>DEBUG: Authorize.Net Post String = $postdata<P>";
+
+               // If this is a local test, just return data, don't send to Authorize.Net
+
+       if( $test == 'LOCAL_TEST' || $card_num == '0011001100110011' )
+               {
+               return
+                       (
+                       array
+                               (
+                               0 => 1,                         // Success
+                               4 => 'Local Test',      // Approval Code
+                               )
+                       );
+               }
+
+       if( $test == 'LOCAL_FAIL' )
+               {
+               return
+                       (
+                       array
+                               (
+                               0 => 2,                         // Decline
+                               4 => 'Local Fail',      // Approval Code
+                               )
+                       );
+               }
+
+               // Submit Request
+
+       $headers = "POST $path HTTP/1.1\r\nHost: $host\r\nContent-type: application/x-www-form-urlencoded\r\nContent-length: ".strlen($poststring)."\r\n";
+
+       exec( AUTH_CURL.' -k -d '.escapeshellarg($postdata)." -P 443 --url ".escapeshellarg(AUTH_URL), $results, $return );
+
+               // Check for failures
+
+       if( $return == 1 )                              // Exec failed - Code 100
+               return( array(0=>100) );
+
+       if( trim($results[0]) == '' )   // No data returned - Code 101
+               return( array(0=>101) );
+
+               // Break results up into an array
+
+       $res = explode( "|", $results[0] );
+       if( SI_DEBUG > 0 )
+               {
+               echo "<P>DEBUG: Authorize.Net Response Array<BR><PRE><table><tr><th align=\"left\">Parameter</th><th align=\"left\">Value</th></tr>\n";
+               reset( $res );
+               foreach($res AS $key => $val)
+                       echo "<tr><td>$key</td><td>$val</td></tr>\n";
+               echo "</table></PRE><P>";
+               }
+
+       if( !is_array($res) )                   // No good data from Authorize.net - Code 102
+               {
+               return( array(0=>102) );
+               }
+
+               // If MD5 Hash secret is provided, authenticate response from Authorize.Net
+
+       if( SI_AUTH_SECRET != '' )
+               {
+               $hash = md5( SI_AUTH_SECRET.$login.$key.round($amount, 2) );
+               if( $res[37] != $hash )
+                       $res[0] = 103;                  // Indicate MD5 Hash verification failure
+               }
+
+               // Return results
+
+       return( $res );
+
+}
+
+
+function build_nav( $nav_table, $menu_title, $current_item = '', $sub_menu = '', $link_data = '' )
+{
+       $nl = "\n";
+
+       $out = '<div id="navcontainer">'.$nl;
+
+               // If a title has been supplied - Add that
+
+       if( $menu_title != '' )
+               $out .= '<div id="navtitle">'.$menu_title.'</div>'.$nl;
+
+       $out .= '<ul id="Level1">'.$nl;
+
+               // If additional link_data passed, include ? and get rid of first "&"
+
+       if( strlen($link_data) > 1 )
+               $link_data = "?".substr($link_data, 1);
+
+               // Build nav from supplied table
+
+       reset( $nav_table );
+       while( list($key, $val) = each( $nav_table ) )
+               {
+                       // If current item make it a non-link and include any supplied sub-menu
+
+               if( $current_item == $key )
+                       $out .= '<li ><a href="#" class="inactive" onclick="return false;">'.$val['title'].'</a>'.$nl.$sub_menu.'</li>'.$nl;
+                 else
+                       $out .= '<li><a href="'.$val['url'].$link_data.'">'.$val['title'].'</a></li>'.$nl;
+               }
+
+       $out .= '</ul> <!-- level1 -->'.$nl.'</div> <!-- navcontainer -->'.$nl;
+
+       return( $out );
+}
+
+
+?>
diff --git a/registrations/registrations.php b/registrations/registrations.php
new file mode 100644 (file)
index 0000000..f6b2dda
--- /dev/null
@@ -0,0 +1,1364 @@
+<?php
+extract( $_REQUEST );
+$gArray = array(
+    'registration',
+    'lname',
+    'fname',
+    'org',
+    'title',
+    'addr1',
+    'addr2',
+    'city',
+    'state',
+    'zip',
+    'country',
+    'phone',
+    'fax',
+    'ccname',
+    'ccnum',
+    'cccode',
+    'email',
+    'email_ok',
+    'pay_code',
+    'cctype',
+    'ccmonth',
+    'ccyear',
+    'conf',
+);
+foreach ( $gArray as $gArr ) {
+    $GLOBALS[$gArr] = ${$gArr};
+}
+/*****************************************************
+ *
+ *  Gaslight Media - Travel Industry Data System
+ *
+ *  Event Registrations User Interface
+ *
+ *  Copyright (c) 2002, 2004 - All rights reserved
+ *
+ ******************************************************/
+
+
+/*****************************************************
+ *
+ *  Support Functions
+ *
+ ******************************************************/
+
+// Function to clean up data when it's going to be used for output
+
+function cleanup( $varname )
+{
+    $GLOBALS[$varname] = stripslashes( trim($GLOBALS[$varname]) );
+}
+
+$link_data = '';
+
+function reg_link_data( $data_field_name )
+{
+    global $link_data;
+    $x = urlencode(trim(str_replace( array( '|', '~' ), '', stripslashes($GLOBALS[$data_field_name]))));
+    if( $x != '' )
+        $link_data .= '&'.$data_field_name.'='.$x;
+}
+
+$form_data = '';
+
+function reg_pass_data( $data_field_name, $value = '' )
+{
+    global $link_data, $form_data ;
+    //extract( $_REQUEST );
+    $x = stripslashes(trim(str_replace( array( '|', '~' ), '', $GLOBALS[$data_field_name])));
+    if( $value != '' )
+        $x = $value;
+    reg_link_data( $data_field_name );
+    $form_data .= '<INPUT TYPE="hidden" NAME="'.$data_field_name.'" VALUE="'.$x.'">
+        ';
+}
+
+/*****************************************************
+ *
+ *  Data we need to have
+ *
+ ******************************************************/
+
+// Build global tag data for view fields
+
+$view_tags = array ( "global"   => array() );
+$v = &$view_tags["global"];
+
+$v['category_id'] = REGISTRATION_ID;    // Set Category ID used for registration system.
+
+// Set default view and style locations
+
+$qs_view  = 'Default';
+$qs_style = 'style.css';
+$v['stylesheet'] = SI_BASE_URL.'/Views/'.$qs_view.'/'.$qs_style;
+$qs_viewpath = '/Views/'.$qs_view;
+
+
+// Check for entrance with a specified Event Code (preselected event)
+
+if( !empty($event) && ($r = db_auto_get_row( "SELECT id FROM reg WHERE event_code = '$event' AND active = 't';", 0, SI_CONN_STR, FALSE )) )
+{
+    $registration = $r['id'];
+    $Action = 'Step2';
+}
+
+
+if( $Action == 'Step1' )
+    $registration = '';
+
+// Determine default step # and check for valid registration data
+
+if( empty($Action) )
+{
+    $Action = "Step0";
+}
+else
+{
+    $rate = 0;
+    $cutoff = '';
+
+    if( isset($registration) && $registration > 0 )
+    {
+
+        $reg_data = db_auto_get_row( "SELECT * FROM reg WHERE id = $registration;", 0, SI_CONN_STR, FALSE );
+        $v['reg_name']          = $reg_data['name'];
+        $v['reg_image']         = $reg_data['image'];
+        $v['reg_descr']         = $reg_data['descr'];
+        $v['reg_term']          = $reg_data['reg_term'];
+        $v['reg_term_cap']      = ucfirst( $reg_data['reg_term'] );
+        $v['reg_term_past']     = $reg_data['reg_term_past'];
+        $v['reg_term_past_cap'] = ucfirst( $reg_data['reg_term_past'] );
+        $v['reg_term_act']      = $reg_data['reg_term_act'];
+        $v['reg_term_act_cap']  = ucfirst( $reg_data['reg_term_act'] );
+        $v['reg_term_plur']     = $reg_data['reg_term_plur'];
+        $v['reg_term_plur_cap'] = ucfirst( $reg_data['reg_term_plur'] );
+
+        $v['ask_attendees'] = $reg_data['need_attendees'] == 't' ? 'Yes' : 'No';
+
+
+        // Determine registration rate
+
+        $rate_data = '';
+        if( time() <= strtotime($reg_data['cutoff_date']) + 86500 )
+        {
+            $rate_data = unserialize( $reg_data['rates_1'] );
+            $rate_from_date = '';
+            $cutoff = $reg_data['cutoff_date'];
+        }
+        elseif( !empty($reg_data['cutoff_date2']) && time() <= strtotime($reg_data['cutoff_date2']) + 86500 )
+        {
+            $rate_data = unserialize( $reg_data['rates_2'] );
+            $rate_from_date = $reg_data['cutoff_date'];
+            $cutoff = $reg_data['cutoff_date2'];
+        }
+        elseif( !empty($reg_data['cutoff_date3']) && time() <= strtotime($reg_data['cutoff_date3']) + 86500 )
+        {
+            $rate_data = unserialize( $reg_data['rates_3'] );
+            $rate_from_date = $reg_data['cutoff_date2'];
+            $cutoff = $reg_data['cutoff_date3'];
+        }
+        elseif( !empty($reg_data['cutoff_date4']) && time() <= strtotime($reg_data['cutoff_date4']) + 86500 )
+        {
+            $rate_data = unserialize( $reg_data['rates_4'] );
+            $rate_from_date = $reg_data['cutoff_date3'];
+            $cutoff = $reg_data['cutoff_date4'];
+        }
+
+        if( is_array($rate_data) )
+        {
+            $rate_classes = 'TRUE';
+
+            if( count($rate_data) == 1 )                // If there's only one rate class
+            {
+                $rate_class = 0;
+                $rate_class_name = $rate_data[0][0];
+                $base_rate = (!empty($rate_data[0][1])?$rate_data[0][1]:0);
+                $rate = $rate_data[0][2];
+                $attendee_credit = (!empty($rate_data[0][3])?$rate_data[0][3]:0);
+            }
+            elseif( isset($rate_class) && $rate_class != '' )             // If a rate class has been selected
+            {
+                $rate_class_name = $rate_data[$rate_class][0];
+                $base_rate = (!empty($rate_data[$rate_class][1])?$rate_data[$rate_class][1]:0);
+                $rate = $rate_data[$rate_class][2];
+                $attendee_credit = (!empty($rate_data[$rate_class][3])?$rate_data[$rate_class][3]:0);
+            }
+            else                                      // Otherwise no rate class is selecetd
+            {
+                $rate_class_name = '';
+                $rate_class = -1;
+                $base_rate = 0;
+                $rate = 0;
+                $attendee_credit =0;
+            }
+        }
+        else                                          // If no rate data, then it must be free
+        {
+            $rate_class_name = '';
+            $rate_class = -1;
+            $rate_classes = '';
+            $rate = 0;
+        }
+
+    }
+    else
+        $Action = "Step1";
+}
+
+// Build list of Attendees
+
+if( $reg_data['need_attendees'] == 't' )
+{
+    $attendee_found = FALSE;
+    $attendees = $sep = '';
+    $numb_attendees = 0;
+    $i = 0;
+    while( isset( $GLOBALS['attendee_'.(++$i).'_1'] ) )
+        if( trim($GLOBALS['attendee_'.$i.'_1']) != '' )     // Note that extra _1 is a result of the java function used for this, deal with it.
+        {
+            $attendee_found = TRUE;
+            $attendees .= $sep.$GLOBALS['attendee_'.$i.'_1'];
+            $sep = ', ';
+            $numb_attendees++;
+        }
+}
+else
+    $numb_attendees = 1;        // Needed as multiplier for all form based charges.
+
+
+/****************************************************
+ *
+ *  Certain steps require data to be checked and the
+ *  user sent back to the previous step if something
+ *  is wrong or certain default values to be set.
+ *
+ *****************************************************/
+
+$reason = array();
+$GLOBALS['reason'] = $reason;
+function add_reason( $text )
+{
+    array_push( $GLOBALS['reason'], array( 'text' => $text ) );
+}
+
+if( isset($cc_reason) )
+    add_reason( $cc_reason);
+
+if( $Action == "Step3" )
+{
+
+    // Check if we have a registrant record yet. If not, create one.
+    if( !isset($registrant) || ($registrant = ($registrant-0)) == 0 )
+    {
+        // Need to create registrant record
+        $user_trace_info = $REMOTE_ADDR." - ".date("m/d/Y H:i:s");
+        $sql = "INSERT INTO reg_req
+            ( user_trace_info, date_entered, status )
+            VALUES
+            ( '$user_trace_info', '".date('m/d/Y')."', ".SI_REG_STATUS_NEW." );\n
+            SELECT currval( 'reg_req_id_seq' ) AS id;";
+        if( ($qr=db_auto_get_row( $sql, 0, SI_CONN_STR, FALSE )) == FALSE )
+        {
+            // If failure to store request
+            $v["problem"] = 'Due to technical problems your request could NOT be submitted.
+                Please contact the '.SI_CUSTOMER_NAME.' at '.SI_CUSTOMER_TOLL_FREE.' regarding registration.
+                ';
+            echo parse_view( $qs_viewpath."/registrations_summary.html", $view_tags );
+            exit;
+        }
+        $registrant = $qr['id'];       // Get ID of registration Request
+        $GLOBALS['registrant'] = $registrant;
+    }
+
+    if( $rate_classes == 'TRUE' && $rate_class == -1 )
+        add_reason( 'You must select a Rate Category' );
+
+    // $charges is array of fees. Each element is array( 'charge_title', 'charge', 'extend' ) to use for summaries and totals
+
+    $free_registration = true;                          // Assume that this registration is free unless we determine otherwise
+    $charges = $field_data = $field_values = array();
+    $total_charges = 0;
+
+    if( $numb_attendees < $attendee_credit )
+        $attendee_credit = $numb_attendees;
+
+    // If Step3 (checkout form) Process MagicForm Submission or if Step4 final checkout then reprocess for using supplied hidden fields
+
+    if( $Action == 'Step3' )
+    {
+        if( ($r = magic_form_submit( $registration )) )
+        {
+            $mf_reasons = explode( "\n", $r['problem'] );
+            foreach( $mf_reasons as $mf_r )
+            {
+                if( trim($mf_r) != '' )
+                    add_reason( substr( $mf_r, 4, -5 ) );
+            }
+            $fd = $r['data'];
+            foreach( $fd as $f )
+                reg_pass_data( $f['id'], $f['value'] );
+
+            // Store dynamic field data under ID of this registration request where form ID is same as registration ID
+            magic_form_store_data( $registration, $registrant, $fd );
+        }
+        else
+        {
+            add_reason( 'ERROR: Unable to process MagicForm at this time.' );
+            //break;
+        }
+    }
+    //    else  // Otherwise for Step4 (final checkout ) just unserialize the form data
+    //      $fd = unserialize( stripslashes($reg_mf_data) );
+
+    // If there are any charges
+
+    if( $base_rate >0 || $rate > 0 )
+    {
+        if( $rate_from_date == '' )         // Date related info
+            array_push( $charges, array( 'charge_title' => 'On-Line '.$v['reg_term'].' on or before '.$cutoff, 'charge' => '', 'extend' => '' ) );
+        else
+            array_push( $charges, array( 'charge_title' => 'On-Line '.$v['reg_term'].' between '.$rate_from_date.' and '.$cutoff, 'charge' => '', 'extend' => '' ) );
+        if( $base_rate > 0 )                // Base Charges
+        {
+            $total_charges += $base_rate;
+            array_push( $charges, array( 'charge_title' => 'Base '.$v['reg_term_cap'].' Fee ', 'charge' => '', 'extend' => money($base_rate) ) );
+        }
+        if( $reg_data['need_attendees'] == 't' )
+        {
+            $charge = $rate * $numb_attendees;
+            $total_charges += $charge;
+            if( $rate > 0 )                     // Attendee charges
+                array_push( $charges, array( 'charge_title' => $numb_attendees.' Attendees', 'charge' => money($rate), 'extend' => money($charge) ) );
+            if( $attendee_credit > 0 )          // Attendee Credits
+            {
+                array_push( $charges, array( 'charge_title' => $attendee_credit.' Attendee Credits ', 'charge' => money($rate*-1), 'extend' => money($rate*$attendee_credit*-1) ) );
+                $total_charges -= $rate * $attendee_credit;
+            }
+        }
+        $free_registration = false; // Yep, there's some kind of charges involved with this reg
+    }
+    else
+        array_push( $charges, array( 'charge_title' => '(no base or per/attendee charges)', 'charge' => '', 'extend' => '' ) );
+
+    // Re-process MagicForm data to see if there's any additional charges and to get reports
+
+    reset( $fd );
+    foreach( $fd as $m )
+        if( $m['numb_val'] != '' )
+        {
+            switch( $m['type'] )
+            {
+            case 1:                 // Checkbox - Use title
+                $t = $m['title'].': Yes';
+                break;
+            case 5:                 // Picklist - Use data
+            case 6:                 // Radio Button - Use data
+                $t = $m['value'];
+                break;
+            default:
+                $t = '';
+                break;
+            }
+            array_push( $charges, array( 'charge_title' => $t, 'charge' => money($m['numb_val']), 'extend' => money( $m['numb_val'] * $numb_attendees ) ) );
+            $total_charges += $m['numb_val'] * $numb_attendees;
+        }
+
+
+    $v['rate'] = money( $rate );
+    $v['rate_total'] = money( $charge );
+
+    // If this event needs attendees
+
+    if( $reg_data['need_attendees'] == 't' )
+    {
+
+        // Check for at least 1 Attendee name
+
+        if( !$attendee_found )
+            add_reason( "There must be at least one attendee" );
+
+        // Check if this exceeds the number of attendees for the event
+
+        if( $reg_data['attendee_limit'] == 't' && $numb_attendees > ( $reg_data['attendee_max'] - $reg_data['attendee_count']) )
+            add_reason( "You have more attendees than can be registered at this time. Only ".( $reg_data['attendee_max'] - $reg_data['attendee_count'])." more available." );
+
+    }
+
+    // If there's any problems change step back to 2 - Checkout Form
+
+    if( count($reason) > 0 )
+        $Action = "Step2";
+    else
+    {
+        // Serialze the MagicForm data and pass it in a hidden field
+
+        $d = array();
+        foreach( $fd as $key=>$val )        // Build array that's a subset of the submitted data, just what's required for re-displaying form
+        {
+            $d[$key] = array( 'id' => $val['id'], 'opt_num' => $val['opt_num'], 'value' => $val['value'] );
+        }
+        $hs = array( '"' => '&quot;' );
+
+        //      $form_data .= '<INPUT TYPE="hidden" NAME="reg_mf_data" VALUE="'. strtr(serialize($d),$hs).'">';
+    }
+
+    $v['free_reg'] = $free_registration ? 'Yes' : 'No';
+
+}
+
+if( $Action == "Step4" )
+{
+
+    if( $rate_classes == 'TRUE' && $rate_class == -1 )
+        add_reason( 'You must select a Rate Category' );
+
+    // $charges is array of fees. Each element is array( 'charge_title', 'charge', 'extend' ) to use for summaries and totals
+
+    $free_registration = true;                          // Assume that this registration is free unless we determine otherwise
+    $charges = $field_data = $field_values = array();
+    $total_charges = 0;
+
+    if( $numb_attendees < $attendee_credit )
+        $attendee_credit = $numb_attendees;
+
+    // If there are any charges
+
+    if( $base_rate >0 || $rate > 0 )
+    {
+        if( $rate_from_date == '' )         // Date related info
+            array_push( $charges, array( 'charge_title' => 'On-Line '.$v['reg_term'].' on or before '.$cutoff, 'charge' => '', 'extend' => '' ) );
+        else
+            array_push( $charges, array( 'charge_title' => 'On-Line '.$v['reg_term'].' between '.$rate_from_date.' and '.$cutoff, 'charge' => '', 'extend' => '' ) );
+        if( $base_rate > 0 )                // Base Charges
+        {
+            $total_charges += $base_rate;
+            array_push( $charges, array( 'charge_title' => 'Base '.$v['reg_term_cap'].' Fee ', 'charge' => '', 'extend' => money($base_rate) ) );
+        }
+        if( $reg_data['need_attendees'] == 't' )
+        {
+            $charge = $rate * $numb_attendees;
+            $total_charges += $charge;
+            if( $rate > 0 )                     // Attendee charges
+                array_push( $charges, array( 'charge_title' => $numb_attendees.' Attendees', 'charge' => money($rate), 'extend' => money($charge) ) );
+            if( $attendee_credit > 0 )          // Attendee Credits
+            {
+                array_push( $charges, array( 'charge_title' => $attendee_credit.' Attendee Credits ', 'charge' => money($rate*-1), 'extend' => money($rate*$attendee_credit*-1) ) );
+                $total_charges -= $rate * $attendee_credit;
+            }
+        }
+        $free_registration = false; // Yep, there's some kind of charges involved with this reg
+    }
+    else
+        array_push( $charges, array( 'charge_title' => '(no base or per/attendee charges)', 'charge' => '', 'extend' => '' ) );
+
+    $v['rate'] = money( $rate );
+    $v['rate_total'] = money( $charge );
+
+    $v['free_reg'] = $free_registration ? 'Yes' : 'No';
+
+    cleanup( 'fname' );
+    cleanup( 'lname' );
+    cleanup( 'org' );
+    cleanup( 'title' );
+    cleanup( 'addr1' );
+    cleanup( 'addr2' );
+    cleanup( 'city' );
+    cleanup( 'zip' );
+    cleanup( 'phone' );
+    cleanup( 'fax' );
+
+    if( empty($fname) ) add_reason( "First Name is required" );
+    if( empty($lname) ) add_reason( "Last Name is required" );
+    if( empty($addr1) ) add_reason( "Address is required" );
+    if( empty($city) ) add_reason( "City is required" );
+    if( empty($state) ) add_reason( "State is required" );
+    if( empty($zip) ) add_reason( "ZIP Code is required" );
+    if( empty($country) ) add_reason( "Country is required" );
+    if( empty($phone) ) add_reason( "Phone number is required" );
+    if( empty($email) ) add_reason( "E-Mail is required" );
+
+    if( !$free_registration )
+    {
+        cleanup( 'ccname' );
+        cleanup( 'ccnum' );
+        cleanup( 'cccode' );
+        cleanup( 'email' );
+        cleanup( 'pay_code' );
+
+
+        // Check for good payment code
+
+        $status = SI_REG_STATUS_UNPAID;
+
+        if( !empty($pay_code) )
+        {
+            // Pay code supplied
+
+            $codes = unserialize($reg_data['pay_codes']);
+            $pay_code_match = FALSE;
+
+            // Try to match with paycodes for this registration setup
+
+            if( is_array($codes) )
+                foreach( $codes as $code )
+                    if( trim($pay_code) == trim($code[0]) )
+                    {
+                        // Code found.
+                        $pay_code_match = TRUE;
+                        $status = SI_REG_STATUS_COMP;
+                    }
+
+            if( !$pay_code_match )
+                add_reason( "Payment code is not valid" );
+            else
+            {
+                // make all charges 0
+
+                for( $i=0 ; $i<count($charges) ; $i++ )
+                    $charges[$i]['charge'] = $charges[$i]['extend'] = '$0.00';
+
+                for( $i=0 ; $i<count($field_data) ; $i++ )
+                    $field_data[$i]['charge'] = 0;
+
+                for( $i=0 ; $i<count($field_values) ; $i++ )
+                    $field_values[$i]['field_charge'] = '$0.00';
+
+                $total_charges = 0;
+            }
+
+        }
+        else
+        {
+            // No pay code, try CC processing
+
+            if( empty($ccnum) )
+                add_reason( "Credit Card number is required" );
+            else
+            {
+                if( ($cct = credit_card_check($ccnum)) == FALSE )
+                    add_reason( "Your Credit Card number does not appear to be correct." );
+                elseif( $cct != $cctype && $cct != "Test" )
+                    add_reason( "Your card does not appear to be a $cctype." );
+            }
+
+            if( strtotime( "$ccmonth/1/$ccyear" ) < strtotime(date('m/1/Y')) )
+                add_reason( "Credit Card has expired." );
+            if( empty($ccname) )
+                add_reason( "Name on Card is required" );
+
+            $status = SI_REG_STATUS_CC_PEND;                        // It's OK to set this here since we're not going to process anything unless there's no failure "$reason".
+
+        }
+
+    }
+    else
+    {
+        $status = SI_REG_STATUS_COMP;
+    }
+
+    // If there's any problems change step back to 2 - Checkout Form
+
+    if( isset($cc_reason) && $cc_reason != '' )
+        add_reason( $cc_reason );
+
+    if( count($reason) > 0 )
+        $Action = "Step3";
+}
+
+/*****************************************************
+ *
+ * Build data to pass on for links and forms
+ *
+ ******************************************************/
+
+// Other fields we may have to pass around to preserve ouput form entries (only happens if user fails on checkout)
+
+if( empty($email_ok) )
+    $email_ok = 't';
+
+if( empty($conf) )
+    $conf = 2;
+
+if( isset($registrant) and $registrant != '' )
+    reg_pass_data( 'registrant' );
+
+//$GLOBALS['registration'] = $registration;
+if( $Action != 'Step1' )
+    reg_pass_data( 'registration' );
+
+
+if( $Action != "Step2" )
+{
+    reg_pass_data( 'rate_class' );
+}
+
+// If we have a good registration id
+
+if( !empty($registration) )
+{
+    // If there is dynamic field data - Pass that along
+
+    if( is_array($rf_data) )
+    {
+        reset( $rf_data );
+        foreach( $rf_data as $rf )
+            if( $Action != 'Step2' )
+                reg_pass_data( 'dyn_'.$rf['id'] );
+            else
+                reg_link_data( 'dyn_'.$rf['id'] );
+    }
+
+    // Pass along attendee data
+
+    $i = 0;
+    while( isset( $GLOBALS['attendee_'.(++$i).'_1'] ) )
+        if( $Action != 'Step2' )
+            reg_pass_data( 'attendee_'.$i.'_1' );
+        else
+            reg_link_data( 'attendee_'.$i.'_1' );
+}
+
+if( $Action != 'Step3' )
+{
+    reg_pass_data( 'lname' );
+    reg_pass_data( 'fname' );
+    reg_pass_data( 'org' );
+    reg_pass_data( 'title' );
+    reg_pass_data( 'addr1' );
+    reg_pass_data( 'addr2' );
+    reg_pass_data( 'city' );
+    reg_pass_data( 'state' );
+    reg_pass_data( 'zip' );
+    reg_pass_data( 'country' );
+    reg_pass_data( 'phone' );
+    reg_pass_data( 'fax' );
+    reg_pass_data( 'ccname' );
+    reg_pass_data( 'ccnum' );
+    reg_pass_data( 'cccode' );
+    reg_pass_data( 'email' );
+    reg_pass_data( 'email_ok' );
+    reg_pass_data( 'pay_code' );
+    reg_pass_data( 'cctype' );
+    reg_pass_data( 'state' );
+    reg_pass_data( 'ccmonth' );
+    reg_pass_data( 'ccyear' );
+    reg_pass_data( 'conf' );
+}
+else
+{
+    reg_link_data( 'lname' );
+    reg_link_data( 'fname' );
+    reg_link_data( 'org' );
+    reg_link_data( 'title' );
+    reg_link_data( 'addr1' );
+    reg_link_data( 'addr2' );
+    reg_link_data( 'city' );
+    reg_link_data( 'state' );
+    reg_link_data( 'zip' );
+    reg_link_data( 'country' );
+    reg_link_data( 'phone' );
+    reg_link_data( 'fax' );
+    reg_link_data( 'ccname' );
+    reg_link_data( 'ccnum' );
+    reg_link_data( 'cccode' );
+    reg_link_data( 'email' );
+    reg_link_data( 'email_ok' );
+    reg_link_data( 'pay_code' );
+    reg_link_data( 'cctype' );
+    reg_link_data( 'state' );
+    reg_link_data( 'ccmonth' );
+    reg_link_data( 'ccyear' );
+    reg_link_data( 'conf' );
+}
+
+if( $Action >= 'Step3' )
+{
+    $v['fname'] = stripslashes( $fname );
+    $v['lname'] = stripslashes( $lname );
+    $v['org'] = stripslashes( $org );
+    $v['title'] = stripslashes( $c_title );
+    $v['addr1'] = stripslashes( $addr1 );
+    $v['addr2'] = stripslashes( $addr2 );
+    $v['city'] = stripslashes( $city );
+    $v['zip'] = stripslashes( $zip );
+    $v['phone'] = stripslashes( $phone );
+    $v['fax'] = stripslashes( $fax );
+    $v['email'] = stripslashes( $email );
+    $v['pay_code'] = stripslashes( $pay_code );
+    $v['ccname'] = stripslashes( $ccname );
+    $v['ccnum'] = stripslashes( $ccnum );
+    $v['cccode'] = stripslashes( $cccode );
+}
+
+/*****************************************************
+ *
+ * Registration step navigation
+ *
+ ******************************************************/
+
+$nav = "&nbsp;";
+if( isset($Action) && $Action > "Step1" && $Action < "Step4" )
+{
+    switch( $Action )
+    {
+    case "Step3":   $Step2 = TRUE;
+    case "Step2":   $Step1 = TRUE;
+    }
+
+    if( $Step1 ) $nav .= '<A HREF="'.SI_THIS_SCRIPT.'?Action=Step1'.$link_data.'">Select</A> > '; else $nav .= 'Select > ';
+    if( $Step2 ) $nav .= '<A HREF="'.SI_THIS_SCRIPT.'?Action=Step2'.$link_data.'">Registration Info</A> > '; else $nav .= 'Registration Info > ';
+    if( $Step3 ) $nav .= '<A HREF="'.SI_THIS_SCRIPT.'?Action=Step3'.$link_data.'">Payment</A> > '; else $nav .= 'Payment  ';
+}
+
+/*****************************************************
+ *
+ * More specific data we need for things that have been selected already
+ *
+ * Note that for each step further we get into the process, we need
+ * to process a bit more data. This code below ensures that we have
+ * processed everything we need for the current step.
+ *
+ ******************************************************/
+
+if( count($charges) > 0 )
+    $view_tags['charges'] = $charges;
+
+$date_array = getdate ();
+
+if( empty($Action) )
+    $Action = "Step0";
+
+$next_step = substr($Action,4) + 1;
+
+//$v["this_script"]     = BASE_SECURE_URL.SI_CALLED_FROM_DIR.'/'.$si_calling_script_name;
+$v["this_script"]           = SI_THIS_SCRIPT;
+$v["customer_name"]         = SI_CUSTOMER_NAME;
+$v["customer_long_name"]    = SI_CUSTOMER_LONG_NAME;
+$v['customer_address']      = SI_CUSTOMER_ADDRESS;
+$v['customer_city']         = SI_CUSTOMER_CITY;
+$v['customer_state']        = SI_CUSTOMER_STATE;
+$v['customer_zip']          = SI_CUSTOMER_ZIP;
+$v["customer_phone"]        = SI_CUSTOMER_PHONE;
+$v["customer_tollfree"]     = SI_CUSTOMER_TOLL_FREE;
+$v["meta_keywords"]         = SI_CUSTOMER_META_KEYWORDS;
+$v["meta_descr"]            = SI_CUSTOMER_META_DESCR;
+$v["registrations_title"]   = SI_CUSTOMER_REG_TITLE;
+$v["this_year"]             = $date_array["year"];
+$v["this_month"]            = $date_array["month"];
+$v["this_short_month"]      = substr( $date_array["month"], 0, 3 );
+$v["this_weekday"]          = $date_array["weekday"];
+$v["this_day_of_month"]     = $date_array["mday"];
+$v["navigation"]            = $nav;
+$v["form_data"]             = $GLOBALS['form_data'];
+$v["link_data"]             = $link_data;
+$view_tags["reason"]                = $reason;
+$v['have_reason']           = ( count($reason) > 0 ? 'YES' : 'NO' );
+$v["problem"]               = "";
+$v["price_debug"]           = "";
+$v["next_step"]             = "Step$next_step";
+$v['nav']                   = $nav;
+$v['attendees']             = $attendees;
+$v['numb_attendees']        = $numb_attendees;
+$v['total_charges']         = money($total_charges);
+$v['rate_classes']          = $rate_classes;
+$v['rate_name']             = $rate_class_name;
+$v['base_secure_url']       = BASE_SECURE_URL;
+$v['base_url']              = SI_BASE_URL;
+
+// Get bulletin and terms/conditions
+
+$misc = db_auto_get_row( "SELECT regterms, regbulletin FROM misc;",  0, SI_CONN_STR, FALSE );
+$v['regbulletin'] = nl2br($misc['regbulletin']);
+
+// ************* SPECIAL PROCESSING FOR SPECIFIC REGISTRATIONS *******************
+
+if( $regcode == 'NTA' )
+    $v['special_bulletin'] = '<center><a href="form.pdf">Click here to print off the Tour Operator Fam Tour Registration Form.</a><BR>
+    (Print only if you are NOT going to register on line)</center>';
+else
+    $v['special_bulletin'] = '';
+
+// *******************************************************************************
+
+$v['regterms'] = nl2br($misc['regterms']);
+$v['regterms_2'] = nl2br($reg_data['terms']);
+
+
+/*****************************************************
+ *
+ * Main Processing
+ *
+ * Where Action is:
+ *   Step0 = Intro Page (Optional)
+ *   Step1 = Event Selection
+ *   Step2 = Registration Information
+ *   Step3 = Checkout
+ *   Step4 = Confirmation
+ *
+ ******************************************************/
+
+switch( $Action )
+{
+
+    // Default entry is either Step0 (intro) or if that is not selected or available Step1
+
+default:
+
+    // Intro - If selected and available
+
+case "Step0":
+
+    if( SI_REG_INTRO )
+    {
+
+        // Parse and display intro page
+
+        echo parse_view( $qs_viewpath."/registrations_intro.html", $view_tags );
+
+        break;
+    }
+
+
+    // Step1 - Select a Event Registration
+
+case "Step1":
+
+    $v['RegSelect'] = SI_REG_SELECT;
+
+    // Get registration data
+
+    $view_tags["RegistrationList"] = $events = array();
+    $v['have_registrations'] = 'FALSE';
+
+    if( !empty($registration) )
+    {
+        $query = "SELECT * FROM reg WHERE active = 't' AND end_date >= 'today' AND id = $registration;";
+        $v["set_reg"] = 'TRUE';
+    }
+    else
+    {
+        $query = "SELECT * FROM reg WHERE active = 't' $regs_qs AND end_date >= 'today' ORDER BY sort;";
+        $v["set_reg"] = 'FALSE';
+    }
+
+    if( ($registrations = db_auto_get_data( $query, SI_CONN_STR, FALSE, 50, 0 )) &&
+        is_array($registrations) )
+    {
+        $v['have_registrations'] = 'TRUE';
+
+        $i = 0;
+        foreach( $registrations as $r )
+        {
+
+            $cutoff_date = '';
+
+            if( $r['active'] == 't' )
+            {
+                $view_tags["RegistrationList"][$i]["image"]                 = ( trim($r["image"]) != "" ? $r["image"] : "" );
+                $view_tags["RegistrationList"][$i]["name"]                  = $r["name"];
+                $view_tags["RegistrationList"][$i]["id"]                    = $r["id"];
+                $view_tags["RegistrationList"][$i]["descr"]                 = substr( $r["descr"], 0, 200 ).(strlen($r['descr'])>200?'...':'');
+                $view_tags["RegistrationList"][$i]["rates_descr"]           = $r["rates_descr"];
+                $view_tags["RegistrationList"][$i]["reg_term"]              = $r["reg_term"];
+                $view_tags["RegistrationList"][$i]["reg_term_cap"]          = ucfirst( $r["reg_term"] );
+                $view_tags["RegistrationList"][$i]["reg_term_past"]         = $r["reg_term_past"];
+                $view_tags["RegistrationList"][$i]["reg_term_past_cap"]     = ucfirst( $r["reg_term_past"] );
+                $view_tags["RegistrationList"][$i]["reg_term_act"]          = $r["reg_term_act"];
+                $view_tags["RegistrationList"][$i]["reg_term_act_cap"]      = ucfirst( $r["reg_term_act"] );
+                $view_tags["RegistrationList"][$i]["reg_term_plur"]         = $r["reg_term_plur"];
+                $view_tags["RegistrationList"][$i]["reg_term_plur_cap"]     = ucfirst( $r["reg_term_plur"] );
+
+                $rates = unserialize( $r['rates_1'] );
+                $rate_min = $rate_max = -1;
+                if( is_array($rates) )
+                    foreach( $rates as $rate )
+                    {
+                        if( $rate[2] < $rate_min || $rate_min == -1 )       $rate_min = $rate[2];
+                        if( $rate[2] > $rate_max || $rate_max == -1 )       $rate_max = $rate[2];
+                    }
+
+                $view_tags["RegistrationList"][$i]["reg_dates"]     = 'Register On-Line by '.$r["cutoff_date"].
+                    ' ('.($rate_min > 0 ? money($rate_min) : 'No Charge').($rate_max > $rate_min ? '-'.money($rate_max) : '').')';
+                $cutoff_date = $r['cutoff_date'];
+                if( !empty($r['cutoff_date2']) )
+                {
+                    $rates = unserialize( $r['rates_2'] );
+                    $rate_min = $rate_max = -1;
+                    if( is_array($rates) )
+                        foreach( $rates as $rate )
+                        {
+                            if( $rate[2] < $rate_min || $rate_min == -1 )       $rate_min = $rate[2];
+                            if( $rate[2] > $rate_max || $rate_max == -1 )       $rate_max = $rate[2];
+                        }
+                    $view_tags["RegistrationList"][$i]["reg_dates"] .= ', by '.$r["cutoff_date2"].
+                        ' ('.($rate_min > 0 ? money($rate_min) : 'No Charge').($rate_max > $rate_min ? '-'.money($rate_max) : '').')';
+                    $cutoff_date = $r['cutoff_date2'];
+                }
+                if( !empty($r['cutoff_date3']) )
+                {
+                    $rates = unserialize( $r['rates_3'] );
+                    $rate_min = $rate_max = -1;
+                    if( is_array($rates) )
+                        foreach( $rates as $rate )
+                        {
+                            if( $rate[2] < $rate_min || $rate_min == -1 )       $rate_min = $rate[2];
+                            if( $rate[2] > $rate_max || $rate_max == -1 )       $rate_max = $rate[2];
+                        }
+                    $view_tags["RegistrationList"][$i]["reg_dates"] .= ', by '.$r["cutoff_date3"].
+                        ' ('.($rate_min > 0 ? money($rate_min) : 'No Charge').($rate_max > $rate_min ? '-'.money($rate_max) : '').')';
+                    $cutoff_date = $r['cutoff_date3'];
+                }
+                if( !empty($r['cutoff_date4']) )
+                {
+                    $rates = unserialize( $r['rates_4'] );
+                    $rate_min = $rate_max = -1;
+                    if( is_array($rates) )
+                        foreach( $rates as $rate )
+                        {
+                            if( $rate[2] < $rate_min || $rate_min == -1 )       $rate_min = $rate[2];
+                            if( $rate[2] > $rate_max || $rate_max == -1 )       $rate_max = $rate[2];
+                        }
+                    $view_tags["RegistrationList"][$i]["reg_dates"] .= ', by '.$r["cutoff_date4"].
+                        ' ('.($rate_min > 0 ? money($rate_min) : 'No Charge').($rate_max > $rate_min ? '-'.money($rate_max) : '').')';
+                    $cutoff_date = $r['cutoff_date4'];
+                }
+                $view_tags["RegistrationList"][$i]["start_date"]    = $r["start_date"];
+                $view_tags["RegistrationList"][$i]["end_date"]      = $r["end_date"];
+
+                if( strtotime($cutoff_date) < time() )
+                    $view_tags["RegistrationList"][$i]['too_late'] = 'Yes';
+                else
+                    $view_tags["RegistrationList"][$i]['too_late'] = '';
+
+                // Determine if registration is full
+
+                if( $r['attendee_limit'] == 't' )
+                {
+                    $view_tags["RegistrationList"][$i]['limited'] = 'YES';
+                    if( $r['attendee_count'] >= $r['attendee_max'] )
+                        $view_tags["RegistrationList"][$i]['full'] = 'YES';
+                    else
+                        $view_tags["RegistrationList"][$i]['full'] = '';
+
+                    $view_tags["RegistrationList"][$i]['attendee_max'] = $r['attendee_max'];
+                    $view_tags["RegistrationList"][$i]['attendee_count'] = $r['attendee_count'];
+                    $view_tags["RegistrationList"][$i]['attendee_left'] = $r['attendee_max'] - $r['attendee_count'];
+                }
+                else
+                    $view_tags["RegistrationList"][$i]['limited'] = '';
+
+                $i++;
+            }
+
+            $events[$r['id']] = $r['name'];
+        }
+        $v['RegPicklist'] = build_picklist( 'registration', $events, '', 'standard' );
+    }
+
+    echo parse_view( $qs_viewpath."/registrations_step1.html", $view_tags );
+
+    break;
+
+
+    // Step2 - Collect information
+
+case "Step2":
+
+    $v['image'] = ( trim($reg_data["image"]) != "" ? $reg_data["image"] : "" );
+    $v['descr'] = $reg_data['descr'];
+    $v['rates_descr'] = $reg_data['rates_descr'];
+    $v['start_date'] = $reg_data['start_date'];
+    $v['end_date'] = $reg_data['end_date'];
+    $v['rate'] = money($rate);
+
+    // Build Rate Class Selection
+
+    $view_tags['rate_class_list'] = array();
+    if( $rate_classes == 'TRUE' )
+    {
+        for( $i=0 ; $i<count($rate_data) ; $i++ )
+        {
+            $ra = array( 'rate_class' => $i, 'rate_class_name' => $rate_data[$i][0], 'rate_class_base' => ($rate_data[$i][1]>0 ? money($rate_data[$i][1]) : ''),
+                'rate_class_rate' => ($rate_data[$i][2]>0 ? money($rate_data[$i][2]) : ''), 'rate_class_selected' => '', 'attendee_credits' => $rate_data[$i][3] );
+            if( $i == $rate_class )
+                $ra['rate_class_selected'] = 'CHECKED';
+            array_push( $view_tags['rate_class_list'], $ra );
+            $rate_classes = 'TRUE';
+        }
+    }
+    $v['rate_classes'] = $rate_classes;
+
+    // If this event requires attendee names
+
+    if( $reg_data['need_attendees'] == 't' )
+    {
+
+        // Build Attendee's list
+
+        $attendee_input_text = '<nobr>&nbsp;#[line_numb]: [field_1]</nobr>';
+        $v['attendees'] = '<input type="hidden" name="attendee_text" id="attendee_text" value="'.$attendee_input_text.'"><span id="attendee_fields">';
+
+        // If there's data, then build existing input lines with data
+
+        $i = 1;
+        if( $numb_attendees > 0 )
+        {
+            // For each line of inputs
+            for( $i=1 ; $i<=$numb_attendees ; $i++ )
+            {
+                $f_line = str_replace( '[line_numb]', $i, $attendee_input_text );       // Set line number in output text
+
+                // For each input field on the line
+
+                $f_line = str_replace( '[field_1]', '<input type="text" name="attendee_'.$i.'_1" id="attendee_'.$i.'_1" value="'.${'attendee_'.$i.'_1'}.'" size="40" onKeyUp="multi_fields_2(\'attendee\',this,1);">', $f_line );
+
+                $v['attendees'] .= $f_line."\n";
+            }
+        }
+        else
+            $i = 1;     // If no data blank line is #1
+
+        // Build 1 spare input line
+
+        $f_line = str_replace( '[line_numb]', $i, $attendee_input_text );       // Set line number in output text
+
+        $f_line = str_replace( '[field_1]', '<input type="text" name="attendee_'.$i.'_1" id="attendee_'.$i.'_1" value="" size="40" onKeyUp="multi_fields_2(\'attendee\',this,1);">', $f_line );
+
+        $v['attendees'] .= $f_line."\n</span>";
+
+    }   // if( $reg_data['need_attendees'] == 't' )
+
+    // MagicForm Display
+
+    //      if( $v['problem'] == '' )
+    //          $fd = unserialize( $form_data['rfq_data'] );
+
+    $mf = magic_form_display( $registration, $mf_styles, null, $fd );
+    if( $mf['success'] )
+    {
+        $v['magic_form'] = $mf['text'];
+        $v['required'] = ($mf['required']?'Yes':'No');
+    }
+    else
+    {
+        echo "OOPS! Some kind of problem with Magic Forms<P>";
+        exit;
+    }
+
+    echo parse_view( $qs_viewpath."/registrations_step2.html", $view_tags );
+
+    break;
+
+    // Step3 - Billing information
+
+case "Step3":
+
+    $v['state'] = build_picklist( "state", $si_states_array, (!empty($state)?$state:""), "standard", "blank" );
+    $v['country'] = build_picklist( "country", $si_countries_array, (!empty($country)?$country:""), "standard", "blank" );
+    $cc_array = array();
+    for( $i=0 ; $i<count($si_cc_array) ; $i++ )
+        if( SI_CC_ACCEPTS & pow( 2, $i )  )
+            array_push( $cc_array, $si_cc_array[$i] );
+    $v["cctype"]            = build_picklist( "cctype", $cc_array, $cctype, "simple" );
+
+    $v["ccmonth"] = build_numeric_picklist( "ccmonth", 1, 12, $ccmonth );
+    $v["ccyear"] = build_numeric_picklist( 'ccyear', date("Y"), date("Y")+10, $ccyear );
+    $v["conf"] = build_radio_buttons( "conf", $si_conf_methods, $conf );
+    $v["email_ok"] = $email_ok;
+
+    echo parse_view( $qs_viewpath."/registrations_step3.html", $view_tags );
+
+    break;
+
+
+    // Step4 - Confirmation
+
+case "Step4":
+
+    $user_trace_info = $REMOTE_ADDR." - ".date("m/d/Y H:i:s");
+
+    $v['state'] = $state;
+    $v['country'] = $country;
+
+    if( !$free_registration )
+    {
+        $v['cctype'] = $cctype;
+        $v['ccmonth'] = $ccmonth;
+        $v['ccyear'] = $ccyear;
+        $v['ccnum'] = "....... ".substr( $ccnum, -4 );
+    }
+    else
+    {
+        $v['cctype'] = '(no charges)';
+        $v['ccmonth'] = '';
+        $v['ccyear'] = '';
+        $v['ccnum'] = '';
+        $cc_conf = '(free registration)';
+    }
+
+
+    $v['request_numb'] = '';
+
+    // Check if submission is a duplicate
+
+    if( ( $rr = db_auto_get_row( "SELECT * FROM reg_req
+        WHERE fname = '$fname'
+        AND lname = '$lname'
+        AND addr1 = '$addr1'
+        AND addr2 = '$addr2'
+        AND city = '$city'
+        AND state = '$state'
+        AND zip = '$zip'
+        AND phone = '$phone'
+        AND email = '$email'
+        AND registration = $registration
+        AND attendees = '$attendees'
+        AND total = $total_charges
+        ;", 0, SI_CONN_STR, FALSE ) ) )
+    {
+        $v["duplicate"] = 'TRUE';
+        $v["request_numb"] = $rr["id"];
+        echo parse_view( $qs_viewpath."/registrations_summary.html", $view_tags );
+        exit;
+    }
+    else
+        $v['duplicate'] = '';
+
+    // Prepair transaction to save request and decriment inventory
+
+    $transaction = "BEGIN;\n";
+
+    // Save Event Registration request
+    $transaction .= "UPDATE reg_req
+        SET     fname           = '$fname',
+        lname           = '$lname',
+        org             = '$org',
+        title           = '$c_title',
+        addr1           = '$addr1',
+        addr2           = '$addr2',
+        city            = '$city',
+        state           = '$state',
+        zip             = '$zip',
+        country         = '$country',
+        phone           = '$phone',
+        fax             = '$fax',
+        email           = '$email',
+        email_ok        = '$email_ok',
+        numb_attending  = $numb_attendees,
+        attendees       = '$attendees',
+        date_entered    = '".date('m/d/Y')."',
+        registration    = $registration,
+        reg_start       = '".$reg_data['start_date']."',
+        reg_end         = '".$reg_data['end_date']."',
+        rate_class      = '".$rate_class_name."',
+        pay_code        = '$pay_code',
+        status          = $status,
+        total           = $total_charges,
+        cc_conf         = '$cc_conf',
+        notes           = '',
+        summary         = ''
+        WHERE id = $registrant;\n";
+
+    // Update attendee count - Used for limited registrations
+
+    if( $reg_data['attendee_limit'] == 't' )
+        $transaction .= "UPDATE reg SET attendee_count = attendee_count + $numb_attendees WHERE id = $registration;\n";
+
+    // Execute transaction
+
+    $transaction .= "COMMIT;";
+
+    if( db_auto_exec( $transaction, 0, SI_CONN_STR, FALSE ) == FALSE )  // Record transaction
+    {
+        // If failure to store request
+
+        $v["problem"] = 'Due to technical problems your request could NOT be submitted.
+            Please contact the '.SI_CUSTOMER_NAME.' at '.SI_CUSTOMER_TOLL_FREE.' regarding registration.
+            ';
+        echo parse_view( $qs_viewpath."/registrations_summary.html", $view_tags );
+        exit;
+    }
+
+    $v['request_numb'] = $reg_req_id = $registrant;     // Get ID of registration Request
+
+    // Enter into Contact table
+
+    if( ($ccheck = db_auto_get_data( "SELECT id FROM contact WHERE email = '".trim($email)."';", SI_CONN_STR, FALSE )) && is_array($ccheck) && count($ccheck) > 0 )
+    {
+        //          db_auto_exec( "UPDATE contact SET last_date = '".date('m/d/Y')."' WHERE email = '".trim($email)."';", SI_CONN_STR, FALSE );
+    }
+    else
+    {
+        db_auto_exec( "INSERT INTO contact
+            (
+                fname,              lname,              company,            address,            address2,
+                city,               state,              zip,                country,
+                phone,              fax,                email,              mail_ok,            create_date,
+                interest
+            )
+            VALUES
+            (
+                '$fname',           '$lname',           '$org',             '$addr1',           '$addr2',
+                '$city',            '$state',           '$zip',             '$country',
+                '$phone',           '$fax',             '$email',           '$email_ok',        '".date("m/d/Y")."',
+                'registration'
+            );", SI_CONN_STR, FALSE );
+    }
+
+    // If credit card transaction is pending, send it to Authorize.Net
+
+    $conf_header = '';      // Header for E-Mail from Authorize.Net
+    $conf_footer = '';      // Footer for E-Mail from Authorize.Net
+
+    if( $status == SI_REG_STATUS_CC_PEND )
+    {
+        switch( SI_REG_PROC_METHOD )
+        {
+
+        case SI_REG_PROC_METHOD_MERCHANT:
+            db_auto_exec( "UPDATE reg_req SET cc_name = '$ccname', cc_numb = '$ccnum', cc_exp = '$ccmonth/$ccyear', cc_cvv = '$cccode' where id = $reg_req_id;", SI_CONN_STR, FALSE );
+            $status = SI_REG_STATUS_CC_PEND;            // Card not yet run
+            $v['checkout_type'] = 'Request';            // This is a request only, not a confirmation
+            $v['auth_code'] = '(Pending)';              // No authorization code available yet
+            break;
+
+        case SI_REG_PROC_METHOD_AUTHORIZE:
+            $r = authorize_net_aim( SI_AUTH_LOGIN, SI_AUTH_TRAN_KEY, SI_AUTH_TEST, SI_AUTH_SEND_CONF, SI_AUTH_MERCHANT_EMAIL,
+                $total_charges, $ccnum, "$ccmonth/$ccyear", $cccode, '',
+                $fname, $lname, $org, $addr1, $city, $state, $zip, $country,
+                $phone, $fax, $reg_req_id, $REMOTE_ADDR, '',
+                $email,
+                $reg_req_id, 'Registration - '.$reg_data['name'], $conf_header, $conf_footer
+            );
+
+            $cc_reason = $failure_mode = $cc_conf = '';
+
+            switch( $r[0] )
+            {
+            case 1:     // Approved
+                $status = SI_REG_STATUS_CC_PAID;
+                $cc_conf = trim($r[4]);
+                break;
+            case 2:     // Declined
+                $status = SI_REG_STATUS_CC_DECL;
+                $cc_reason .= "Credit Card was declined. Please check the information below to make sure it is correct.";
+                $failure_mode = "*** Card Declined ***";
+                break;
+            case 3:     // Error
+            case 4:     // Held for review
+                $status = SI_REG_STATUS_FAILED;
+                $cc_reason .= "Credit Card was not approved".(trim($r[3])!=''?' - '.$r[3]:'');
+                $failure_mode = "*** Card Processing Failure (".$r[0].") ".$r[3]." ***";
+                break;
+            case 100:   // Exec call error
+            case 101:   // No data returned from exec call
+            case 102:   // No data returned from Authorize.Net
+            case 103:   // MD5 Hash verification failure - Did we talk to the correct server???
+            default:    // Unknown response code
+                $status = SI_REG_STATUS_FAILED;
+                $cc_reason .= "Processing Failure - Unable to store information. Please try later or call to register.";
+                $failure_mode = "*** Card Processing Failure (".$r[0].") ***";
+                break;
+            }
+
+            // If transaction failed for some reason
+
+            if( $cc_reason != '' )
+            {
+                // Mark request with failure mode and delete any dynamic field data from database
+
+                db_auto_exec( "UPDATE reg_req SET addr2 = '$failure_mode', status = $status WHERE id = $reg_req_id;", SI_CONN_STR, FALSE );
+
+                // Send user back to form with error
+
+                echo '
+                    <HTML>
+                    <HEAD>
+                    <META HTTP-EQUIV="Refresh" CONTENT="5;URL='.BASE_URL.'index.php?catid='.REGISTRATION_ID.'&Action=Step4&cc_reason='.urlencode($cc_reason).$link_data.'">
+                    </HEAD>
+                    <BODY>
+                    <H3>Processing.....</H3>
+                    If your browser does not forward to the next page in less than 10 seconds, click <A HREF="'.BASE_URL.'index.php?carid='.REGISTRATION_ID.'&Action=Step4&cc_reason='.urlencode($cc_reason).$link_data.'">HERE</A>;
+                </BODY>
+                    </HTML>
+                    ';
+                exit;
+            }
+
+            $v['checkout_type'] = 'Confirmation';
+            $v['auth_code'] = $r[4];
+
+            break;
+
+            default:
+                echo "OOPS! Payment Processing Method has not been set in siteinfo.inc.<P>";
+                exit;
+                break;
+        }
+
+    }
+    else
+        $v['checkout_type'] = 'Confirmation';
+
+    // Build and store HTML summary
+
+    $fd = db_auto_get_data( "SELECT * FROM mf_data WHERE fiid = $registrant ORDER BY field_id;", SI_CONN_STR, FALSE, 50, 0 );
+    $i = 0;
+    $fv = array();
+    foreach( $fd as $f )
+    {
+        array_push( $fv, array(
+            'field_title' => $f['title'],
+            'field_value' => ($f['type']==7&&$f['value']!=''?'<a href="'.SI_BASE_URL.'/files/'.$f['value'].'">'.$f['value'].'</a>':(!empty($f['txt_val'])?$f['txt_val']:$f['value'])),
+            'field_charge' => $f['numb_val']
+        ) );
+    }
+    $view_tags['field_values'] = $fv;
+
+    $html_store = parse_view( $qs_viewpath."/registrations_store.html", $view_tags );
+    db_auto_exec( "UPDATE reg_req SET summary = '".addslashes($html_store)."', status = $status, cc_conf = '$cc_conf', pay_code = '$pay_code' WHERE id = $reg_req_id;", SI_CONN_STR, FALSE );
+
+    // Send confirmation to Customer
+
+    $html_summary = parse_view( $qs_viewpath."/registrations_confirmation.html", $view_tags );
+    $email_content = "--ContentBoundry\n"
+        ."Content-Type: text/plain; charset=\"US-ASCII\"\n"
+        ."\n"
+        .( SI_CUST_EMAIL_MODE == 3 ?    $text_summary : "This message may only be read using an HTML enabled E-Mail client." )
+        ."\n"
+        ."--ContentBoundry\n"
+        ."Content-Type: text/html; charset=\"US-ASCII\"\n"
+        ."\n"
+        .$html_summary
+        ."\n"
+        ."--ContentBoundry--\n"
+        ."\n";
+    if( !empty($email) )
+        debug_mail( $email, SI_CUSTOMER_NAME." Registration Notification", "$email_content.", "From: ".SI_CUSTOMER_NAME." <".OWNER_EMAIL.">"
+        ."\nMime-Version: 1.0\nContent-Type: multipart/alternative; boundary=ContentBoundry\n");
+
+    // Mail to CVB
+
+    $notify_addresses = unserialize( $reg_data['notify_email'] );
+    $notify = '';
+    if( is_array($notify_addresses) && count($notify_addresses) > 0 )
+        foreach( $notify_addresses AS $n )
+            $notify .= ','.$n[0];
+
+    $email_content = "\n".SI_CUSTOMER_NAME." REGISTRATION #: $reg_req_id\n\n"
+        ."An ".SI_CUSTOMER_NAME." Registration has been submitted. Please see REGISTRATION\n"
+        ."REQUEST # $reg_req_id in the ".SI_CUSTOMER_NAME." adminstration area.\n\n";
+    debug_mail( SI_CUSTOMER_INTERNAL_EMAIL.$notify, SI_CUSTOMER_NAME." Registration", $email_content, "From: ".SI_CUSTOMER_NAME." <".OWNER_EMAIL.">\n" );
+
+    // Display output to Customer
+
+    echo parse_view( $qs_viewpath."/registrations_summary.html", $view_tags );
+
+    break;
+
+}
+
+?>
diff --git a/registrations/setup.php b/registrations/setup.php
new file mode 100644 (file)
index 0000000..51b140c
--- /dev/null
@@ -0,0 +1,3208 @@
+<?php
+//ini_set('session.bug_compat_warn','off');
+/** @header Gaslight Media Toolbox
+  Media Toolbox(R)
+  Setup.phtml file includes the functions that were in the functions.inc
+  and siteinfo.inc file into one file.
+  All set up stuff is on the top of the page.
+
+  $Id: setup.phtml,v 1.14 2009/02/02 20:31:01 matrix Exp $
+ */
+
+if( !isset($SITEINFO) )
+{
+
+    if(!isset($DEBUG))
+    {
+        $DEBUG = (isset($mysecretcode) && $mysecretcode == 1234);
+    }
+    // setup for pages
+    define("HOME_ID",1); // change this if home page is other than id = 1
+    define("REGISTRATION_ID", 24 );
+    $PAGES['default'] = 'index';
+    define( "MEMBERS_CATEGORY", 57 ); // set this to the members only category.
+    define( "MEMBERS_LIST_RAND", false ); // set this to the members only category.
+    $PAGES[1] = 'index';
+    //$DEBUG = TRUE;
+
+    /*
+     *  Customer Setup
+     */
+    define("SITENAME","cslewisfestival");   // used for outputing name of site in admin area
+    define("SITE_NAME",SITENAME);   // same as SITENAME
+    define("DB_TYPE", "postgres");  // DB library only knows postgres (FUTURE EXPANSION)
+    define("DB_ERROR_MSG", "an error has occured with the database!");  // default error message
+    define("MULTIPLE_CAT",0);       // weather or not to use many to many relations
+    define("CAT_LOCK",0);           // If set to 1 or true will lock the categories
+    define("ENTRIES_PER_PAGE",10);  // default per page number
+    define("HTML_HELP_CODE",1);     // this is being depreciated for general help guides
+    define("PRODUCTION_MODE","ON"); // used in the email out for contact DB
+    define("HTML_EMAIL","ON");  // turn ON for html emails
+    define("ACTIVE_FLAG",1);        // turn on if bus_category table has active bool field
+    define("DELUXE_TOOLBOX",1);     // used for the toolbox deluxe vrs.
+    define("SEO_URL",1);            // weather to use Search Engine Optimisezd url's requires .htaccess enabled
+    /* integration of different apps */
+    define("SITEMAP_GENERATOR",false);
+    define("PHOTO_GALLERY",0);
+    define("GOOGLE_SEARCH",0);
+    define("MEMBERS_DB",0);
+    /** htmlarea plugins */
+    define("HTMLAREA_TABLES",true); // weather to load the table plugin or not
+    define("HTMLAREA_CONTEXT_MENU",true);   // weather to load the context menu plugin or not
+    define("HTMLAREA_IMAGE_MANAGER",true);
+    define("HTMLAREA_CHARACTER_MAP",false);
+    define("HOME_PAGE_EVENTS",0);
+/**
+ * Login Id for StreamSend account
+ */
+define('STREAMSEND_LOGIN_ID', 'tjQOHTA3WC0n');
+/**
+ * key for StreamSend account
+ */
+define('STREAMSEND_KEY', '8pE7Er5QMghPBBrH');
+/**
+ * StreamSend Account Name
+ */
+define('STREAMSEND_ACCOUNT_NAME', 'CS Lewis Festival');
+/**
+ * StreamSend Audience Number
+ */
+define('STREAMSEND_AUDIENCE', '2');
+/**
+ * Site uses streamsend module?
+ */
+define('STREAMSEND_FORMS_API', true);
+/**
+ * Enable the form to send data to constant contact
+ */
+define('CONSTANT_CONTACT', false);
+/**
+ * Login for API (required)
+ */
+define('CONSTANT_CONTACT_LOGIN', false);
+/**
+ * Password for API (required)
+ */
+define('CONSTANT_CONTACT_PASSWORD', false);
+/**
+ * API Key (required)
+ */
+define('CONSTANT_CONTACT_APIKEY', false);
+/**
+ * API Path (Required)
+ */
+define('CONSTANT_CONTACT_APIPATH', false);
+define('CONSTANT_CONTACT_LIST', false);
+define('ICONTACT_APPLICATION', false);
+define('ICONTACT_API_ID', false);
+define('ICONTACT_API_PASSWORD', false);
+define('ICONTACT_API_USERNAME', false);
+    /*
+     *
+     *  DO NOT EDIT THIS SECTION
+     *
+     */
+
+        // Find where this file is located
+
+        $BASE_PATH      = dirname( __FILE__ );
+
+        $CALLED_FROM_DIR    = substr( dirname($_SERVER["SCRIPT_FILENAME"]), strlen($BASE_PATH) );
+        if( ($x = strlen($CALLED_FROM_DIR)) > 0 )
+            {
+            $base_url   = $_SERVER['HTTP_HOST'].substr( dirname($_SERVER['SCRIPT_NAME']), 0, -strlen($CALLED_FROM_DIR) );
+            }
+          else
+            {
+            $script_name_dir = dirname($_SERVER['SCRIPT_NAME']);
+            if( $script_name_dir == "/" )
+                $script_name_dir = "";
+            $base_url       = $_SERVER['HTTP_HOST'].$script_name_dir;
+            }
+
+        if( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == "on" )
+            $BASE_URL = "https://".$base_url;
+          else
+            $BASE_URL = "http://".$base_url;
+
+    $calling_script_name = basename($_SERVER['SCRIPT_NAME']);
+
+    /*
+     *
+     *  Dynamic Configuration - Parameters that DO change based on location
+     *
+     */
+    $si_base_url = get_permalink();
+    switch( $_ENV['GLM_HOST_ID'] )
+        {
+        case "DEVELOPMENT":
+            define("GLM_APP_BASE","/var/www/server/app.gaslightmedia.com/");
+            error_reporting(E_ALL ^ E_NOTICE);
+            ini_set("display_errors","1");
+            $BASE_SECURE_URL = $si_base_url;
+            define("BASE_SECURE_URL", $BASE_SECURE_URL);     // url used for the secur site
+            if ($_SERVER['HTTPS'] == "on") {
+                define("SECURE_URL", $BASE_SECURE_URL);  // url used for the secur site
+                $BASE_URL = "http://dev53.gaslightmedia.com/www.cslewisfestival.org";                    // This needs to be set to the real url ie. http://www.upnorth.net
+            } else {
+                define("SECURE_URL", $BASE_URL."/");     // url used for the secur site
+            }
+            define("CONN_STR","user=nobody host=devdb dbname=cslewisfestival");
+            define("OWNER_EMAIL", "ove@gaslightmedia.com");     // site owner's email address
+            define("FROM_NEWS_EMAIL", "ove@gaslightmedia.com");     // site owner's email address
+            define("REPLY_TO", "ove@gaslightmedia.com");            // the reply-to field for email's
+            define("SI_DEBUG_VIEW", false );
+            define( 'SI_AUTH_TEST',                 'TRUE' );// Must be "FALSE" for production! Otherwise "TRUE" or "LOCAL_TEST" (don't transmit)
+
+            define( "DEBUG",                                0 );    // Debug Level : 0=Off, 1, 2, 3, ... more debug info
+            define( "SI_DEBUG_MAIL",                        false );
+            define( 'SI_AUTH_TEST',                         'FALSE' );
+            define( 'SI_AUTH_SEND_CONF',            'FALSE' );
+            define( 'SI_AUTH_MERCHANT_EMAIL',       'FALSE' );
+            break;
+
+        case "PRODUCTION":
+            define("GLM_APP_BASE","/var/www/server/app.gaslightmedia.com/");
+            error_reporting(0);
+            ini_set("display_errors","0");
+            $BASE_SECURE_URL = "https://ws0.gaslightmedia.com/cslewis";
+                // for some sites it is necesary to change base_url when in secure mode
+            define("BASE_SECURE_URL", $BASE_SECURE_URL);     // url used for the secur site
+            if ($_SERVER['HTTPS'] == "on") {
+                define("SECURE_URL", $BASE_SECURE_URL."/");  // url used for the secur site
+                $BASE_URL = "http://www.cslewisfestival.org";                    // This needs to be set to the real url ie. http://www.upnorth.net
+            } else {
+                define("SECURE_URL", $BASE_URL."/");     // url used for the secur site
+            }
+            define("CONN_STR","user=nobody host=ds4 dbname=cslewisfestival");
+            define("OWNER_EMAIL", "info@cslewisfestival.org");       // site owner's email address
+            define("FROM_NEWS_EMAIL", "info@cslewisfestival.org");      // site owner's email address
+            define("REPLY_TO", "info@cslewisfestival.org");          // the reply-to field for email's
+            define("SI_DEBUG_VIEW", false );
+            define( 'SI_AUTH_TEST',                 'FALSE' );// Must be "FALSE" for production! Otherwise "TRUE" or "LOCAL_TEST" (don't transmit)
+
+            define( "DEBUG",                                0 );    // Debug Level : 0=Off, 1, 2, 3, ... more debug info
+            define( "SI_DEBUG_MAIL",                        false );
+            define( 'SI_AUTH_TEST',                         'FALSE' );
+            define( 'SI_AUTH_SEND_CONF',            'FALSE' );
+            define( 'SI_AUTH_MERCHANT_EMAIL',       'FALSE' );
+            break;
+
+        default:    // There should be no need for any settings here
+            die('Should not reach this');
+        break;
+
+    }
+    define("GLM_APP_BASE_URL","http://app.gaslightmedia.com/");
+    define("GLM_APP_SECURE_URL","https://app.gaslightmedia.com/");
+
+    define("BASE_URL", $BASE_URL.'/');                  // url used for the root of site
+    define("URL_BASE", $BASE_URL."/");                  // same as BASE_URL
+    define("BASE_PATH", $BASE_PATH."/");                // root directory path of site
+    define("BASE", $BASE_PATH."/");                     // same as BASE_PATH
+    define("GOOGLE",BASE.'google/');
+    define("HELP_BASE", "help/");                       // help guide base (depreciated)
+    define("UP_BASE", BASE."uploads/");                 // uploads directory path
+    define("IMG_BASE", URL_BASE."images/");             // the images url path
+    define("POSTCARD_URL",URL."postcard.phtml");        // postcard url (used for postcard app)
+    define("LOGO_IMG",URL_BASE."images/logoicon.gif");  // used in admin area as the path to image logo
+    define("HELP_IMG",URL_BASE."images/help.gif");      // help image url (depriated)
+    define("ORIGINAL_PATH", BASE."images/original/");   // path of original images
+    define("RESIZED_PATH", BASE."images/resized/");     // path of first resized image
+    define("MIDSIZED_PATH", BASE."images/midsized/");   // path of half sized of resized
+    define("THUMB_PATH", BASE."images/thumb/");         // path of thumbnail directory
+    if( $_SERVER['HTTPS'] == "on" )
+    {
+        define("ORIGINAL", $BASE_SECURE_URL."/images/original/");   // url of original images
+        define("RESIZED", $BASE_SECURE_URL."/images/resized/");     // url of resized
+        define("MIDSIZED", $BASE_SECURE_URL."/images/midsized/");   // url of midsized
+        define("THUMB", $BASE_SECURE_URL."/images/thumb/");         // url of thumbnail
+    }
+    else
+    {
+        define("ORIGINAL", URL_BASE."images/original/");    // url of original images
+        define("RESIZED", URL_BASE."images/resized/");      // url of resized
+        define("MIDSIZED", URL_BASE."images/midsized/");    // url of midsized
+        define("THUMB", URL_BASE."images/thumb/");          // url of thumbnail
+    }
+    $path = preg_split('(\/|:|\.)', get_include_path());
+    if (!in_array(GLM_APP_BASE.'glmPEAR', $path)) {
+        set_include_path(get_include_path() . PATH_SEPARATOR .
+            GLM_APP_BASE . 'glmPEAR');
+    }
+    try {
+        $dsn = 'pgsql:' . CONN_STR;
+        $driverOptions = array(
+            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
+        );
+        $dbh = new PDO($dsn, null, null, $driverOptions);
+        $dbh->setAttribute(PDO::ATTR_ERRMODE,
+            PDO::ERRMODE_EXCEPTION);
+    } catch (PDOException $e) {
+        echo '<pre>$e: ' . print_r( $e, true ) . '</pre>';
+        exit;
+    }
+    $flexyUrlRewrite = ($_SERVER['HTTPS'] == 'on') ? BASE_SECURE_URL : BASE_URL;
+    $flexyOptions    = array(
+        'templateDir' => BASE . 'templates',
+        'compileDir'  => BASE . 'templates/compiled',
+        'url_rewrite' => 'baseurl/::' . $flexyUrlRewrite,
+        'allowPHP'    => false,
+    );
+    function __autoload($className)
+    {
+        if ((preg_match('/Flexy.+/', $className) === 0) ||
+            $className == 'Toolkit_FlexyDataGridBuilder') {
+            switch ($className) {
+            case 'GLM_DB' :
+                require_once BASE . 'classes/class_db.inc';
+                break;
+
+            case 'GLM_TOOLBOX' :
+                require_once BASE . 'classes/class_toolbox.inc';
+                break;
+
+            case 'GLM_TEMPLATE' :
+                require_once BASE . 'classes/class_template.inc';
+                break;
+
+            case 'GLM_DB' :
+                require_once BASE . 'classes/class_db.inc';
+                break;
+
+            case 'BANNER_ADS' :
+                require_once BASE . 'classes/class_banners.inc';
+                break;
+
+            case 'GLM_EVENTS' :
+                require_once BASE . 'classes/class_events.inc';
+                break;
+
+            case 'GLM_COUPON' :
+                require_once BASE . 'classes/class_coupon.inc';
+                break;
+
+            case 'contact_form' :
+                require_once BASE . 'classes/class_contact_form.inc';
+                break;
+
+            case 'guide' :
+                require_once BASE . 'classes/class_visitor_guide_form.inc';
+                break;
+
+            case 'event_form' :
+                require_once BASE . 'classes/class_event_form.inc';
+                break;
+
+            case 'html_quickform_rule_phone' :
+            case 'html_quickform_rule_email' :
+            case 'html_quickform_rule_zip' :
+            case 'html_quickform_rule_state' :
+            case 'html_quickform_rule_banwords' :
+            case 'html_quickform_rule_date' :
+            case 'html_quickform_rule_image' :
+            case 'html_quickform_rule_image2' :
+            case 'html_quickform_rule_memberimage' :
+            case 'html_quickform_rule_memberpackage' :
+            case 'html_quickform_rule_memberlogo' :
+            case 'html_quickform_rule_memberfile' :
+            case 'html_quickform_rule_amenity' :
+            case 'html_quickform_rule_banner' :
+                $path = explode('_', $className);
+                $className = ucfirst(end($path));
+                require_once GLM_APP_BASE . "glmPEAR/HTML/QuickForm/Rule/$className.php";
+                break;
+
+            default :
+                //  Since our old naming conventions conflict w/ the pear
+                //  naming conventions.
+                //  Check to see what we're trying to call by checking if the
+                //  file/class exits in the PEAR sturcture.
+                $class = implode('/', explode('_', $className));
+                if (file_exists(GLM_APP_BASE . "glmPEAR/$class.php")) {
+                    require_once "$class.php";
+                } elseif (file_exists(GLM_APP_BASE . "$class.php")) {
+                    require_once GLM_APP_BASE . "$class.php";
+                } elseif (file_exists(BASE . "$class.php")) {
+                    require_once BASE . "$class.php";
+                } else {
+                    require_once BASE . "classes/$className.php";
+                }
+                break;
+            }
+        }
+    }
+
+    //require_once 'Text/CAPTCHA.php';
+    //require_once 'Text/CAPTCHA/Driver/Image.php';
+    session_start();
+
+    /** these are the image sizing defines USE THESE ONLY
+      only allowed string of 'WxH[<>]' [-quality Percentage]
+     */
+    define("ITEM_RESIZED", "'287>'");       // used in convert call to resize images
+    define("ITEM_MIDSIZED", "'210>'");
+    define("ITEM_THUMB","'120>'");
+
+    define("FOOTER_IMG", URL_BASE."images/logosmall.gif");
+    define("FOOTER_URL", URL_BASE);
+    define("STYLE","main.css");
+    define( "SI_COPYRIGHT_YEARS", "2002-".date("Y") );  // Years for copyright statement in footer
+
+    /**
+    * Now using new Image Server
+    * http://is0.gaslightmedia.com/admin
+    * setup new owner with owner_id and owner_pw
+    * MUST BE DONE BEFORE uploading any images
+    */
+   /**
+   * IS_OWNER_ID owner_id from image server config
+    */
+   define('IS_OWNER_ID', 'cslewis');
+   /**
+    * IS_OWNER_PW owner_pw from image server config
+    */
+   define('IS_OWNER_PW', 'cSl3w1s');
+   $fileServerUrl
+       = ($_SERVER['HTTPS'] == 'on')
+       ? 'https://is0.gaslightmedia.com/'
+       : 'http://is0.gaslightmedia.com/';
+   define('FILE_SERVER_URL', $fileServerUrl);
+   //  CKImage image rules
+   /**
+    * This is the rule used to create the Maximum Allowed Size image
+    * we allow for CKEditor Images, which is (700x500)
+    *
+    * If the user resizes (edits) the image, it can be smaller
+    */
+   define('TOOLBOX_ORIGINAL', FILE_SERVER_URL.IS_OWNER_ID."/original/");
+   define('CKIMAGE', FILE_SERVER_URL.IS_OWNER_ID."/CKImage/");
+   define('CKIMAGE_ORIGINAL', TOOLBOX_ORIGINAL);
+   define('CKIMAGE_RESIZED', TOOLBOX_RESIZED);
+   define('CKIMAGE_MIDSIZED', TOOLBOX_MIDSIZED);
+   define('CKIMAGE_THUMB', TOOLBOX_THUMB);
+
+   define('IMAGE_MANAGER', FILE_SERVER_URL.IS_OWNER_ID."/imgMgr/");
+
+   $secureUrl = $isSecurePage ? BASE_SECURE_URL : BASE_URL;
+
+$forceCompile = (DEVELOPMENT || $isSecurePage);
+
+$flexyOptions    = array(
+    'templateDir'  => BASE . 'templates',
+    'compileDir'   => BASE . 'templates/compiled',
+    'forceCompile' => 'true',
+    'url_rewrite'  => "baseurl/::".BASE_URL.",basesecureurl/::$secureUrl,glmappbaseurl/::" . GLM_APP_BASE_URL,
+    'allowPHP'     => true,
+);
+
+    /**
+      These are defines for the photo gallery images
+     */
+    define('PHOTO_LARGE_SIZE',"'700x450>'");
+    define('PHOTO_LARGE_DIR',BASE.'images/photo-large/');
+    define('PHOTO_LARGE_URL',BASE_URL.'images/photo-large/');
+
+    define('PHOTO_SMALL_SIZE',"'133x100>'");
+    define('PHOTO_SMALL_DIR',BASE.'images/photo-small/');
+    define('PHOTO_SMALL_URL',BASE_URL.'images/photo-small/');
+    // [status_US] array of states and their abbr.
+    $states_US[""] = "- Choose State -";
+    $states_US["AL"]= "Alabama";
+    $states_US["AK"]= "Alaska";
+    $states_US["AZ"]= "Arizona";
+    $states_US["AR"]= "Arkansas";
+    $states_US["CA"]= "California";
+    $states_US["CO"]= "Colorado";
+    $states_US["CT"]= "Connecticut";
+    $states_US["DE"]= "Delaware";
+    $states_US["DC"]= "District of Columbia";
+    $states_US["FL"]= "Florida";
+    $states_US["GA"]= "Georgia";
+    $states_US["HI"]= "Hawaii";
+    $states_US["ID"]= "Idaho";
+    $states_US["IL"]= "Illinois";
+    $states_US["IN"]= "Indiana";
+    $states_US["IA"]= "Iowa";
+    $states_US["KS"]= "Kansas";
+    $states_US["KY"]= "Kentucky";
+    $states_US["LA"]= "Louisiana";
+    $states_US["ME"]= "Maine";
+    $states_US["MD"]= "Maryland";
+    $states_US["MA"]= "Massachusetts";
+    $states_US["MI"]= "Michigan";
+    $states_US["MN"]= "Minnesota";
+    $states_US["MS"]= "Mississppi";
+    $states_US["MO"]= "Missouri";
+    $states_US["MT"]= "Montana";
+    $states_US["NE"]= "Nebraska";
+    $states_US["NV"]= "Nevada";
+    $states_US["NH"]= "New Hampshire";
+    $states_US["NJ"]= "New Jersey";
+    $states_US["NM"]= "New Mexico";
+    $states_US["NY"]= "New York";
+    $states_US["NC"]= "North Carolina";
+    $states_US["ND"]= "North Dakota";
+    $states_US["OH"]= "Ohio";
+    $states_US["OK"]= "Oklahoma";
+    $states_US["OR"]= "Oregon";
+    $states_US["PA"]= "Pennsylvania";
+    $states_US["RI"]= "Rhode Island";
+    $states_US["SC"]= "South Carolina";
+    $states_US["SD"]= "South Dakota";
+    $states_US["TN"]= "Tennessee";
+    $states_US["TX"]= "Texas";
+    $states_US["UT"]= "Utah";
+    $states_US["VT"]= "Vermont";
+    $states_US["VA"]= "Virginia";
+    $states_US["WA"]= "Washington";
+    $states_US["WV"]= "West Virginia";
+    $states_US["WI"]= "Wisconsin";
+    $states_US["WY"]= "Wyoming";
+
+    // [states] extended states array
+    $states["AL"]  = "Alabama";
+    $states["AK"] =  "Alaska";
+    $states["AB"] =  "Alberta";
+    $states["AS"] =  "American Samoa";
+    $states["AZ"] =  "Arizona";
+    $states["AR"] =  "Arkansas";
+    $states["BC"] =  "British Columbia";
+    $states["CA"] =  "California";
+    $states["CO"] =  "Colorado";
+    $states["CT"] =  "Connecticut";
+    $states["DE"] =  "Delaware";
+    $states["DC"] =  "District of Columbia";
+    $states["FM"] =  "Federated States of Micronesia";
+    $states["FL"] =  "Florida";
+    $states["GA"] =  "Georgia";
+    $states["GU"] =  "Guam";
+    $states["HI"] =  "Hawaii";
+    $states["ID"] =  "Idaho";
+    $states["IL"] =  "Illinois";
+    $states["IN"] =  "Indiana";
+    $states["IA"] =  "Iowa";
+    $states["KS"] =  "Kansas";
+    $states["KY"] =  "Kentucky";
+    $states["LA"] =  "Louisiana";
+    $states["ME"] =  "Maine";
+    $states["MB"] =  "Manitoba";
+    $states["MH"] =  "Marshall Islands";
+    $states["MD"] =  "Maryland";
+    $states["MA"] =  "Massachusetts";
+    $states["MI"] =  "Michigan";
+    $states["MN"] =  "Minnesota";
+    $states["MS"] =  "Mississppi";
+    $states["MO"] =  "Missouri";
+    $states["MT"] =  "Montana";
+    $states["NE"] =  "Nebraska";
+    $states["NV"] =  "Nevada";
+    $states["NB"] =  "New Brunswick";
+    $states["NF"] =  "Newfoundland";
+    $states["NH"] =  "New Hampshire";
+    $states["NJ"] =  "New Jersey";
+    $states["NM"] =  "New Mexico";
+    $states["NY"] =  "New York";
+    $states["NC"] =  "North Carolina";
+    $states["ND"] =  "North Dakota";
+    $states["MP"] =  "Northern Mariana Islands";
+    $states["NT"] =  "Northwest Territories";
+    $states["NS"] =  "Nova Scotia";
+    $states["OH"] =  "Ohio";
+    $states["OK"] =  "Oklahoma";
+    $states["ON"] =  "Ontario";
+    $states["OR"] =  "Oregon";
+    $states["PW"] =  "Palau";
+    $states["PA"] =  "Pennsylvania";
+    $states["PE"] =  "Prince Edward Island";
+    $states["PR"] =  "Puerto Rico";
+    $states["QC"] =  "Quebec";
+    $states["RI"] =  "Rhode Island";
+    $states["SK"] =  "Saskatchewan";
+    $states["SC"] =  "South Carolina";
+    $states["SD"] =  "South Dakota";
+    $states["TN"] =  "Tennessee";
+    $states["TX"] =  "Texas";
+    $states["UT"] =  "Utah";
+    $states["VT"] =  "Vermont";
+    $states["VI"] =  "Virgin Islands";
+    $states["VA"] =  "Virginia";
+    $states["WA"] =  "Washington";
+    $states["WV"] =  "West Virginia";
+    $states["WI"] =  "Wisconsin";
+    $states["WY"] =  "Wyoming";
+    $states["YT"] =  "Yukon";
+    $states["Asia"] =  "Asia";
+    $states["Australia"] =  "Australia";
+    $states["Bahamas"] =  "Bahamas";
+    $states["Caribbean"] =  "Caribbean";
+    $states["Costa Rica"] =  "Costa Rica";
+    $states["South America"] =  "South America";
+    $states["South Africa"] =  "South Africa";
+    $states["Europe"] =  "Europe";
+    $states["Mexico"] = "Mexico";
+    /* Libraries */
+    /* Replaced with the actual functions instead of includes (2001-12-14) */
+
+    $cp1252_map = array(
+            "\xc2\x80" => "\xe2\x82\xac", /* EURO SIGN */
+            "\xc2\x82" => "\xe2\x80\x9a", /* SINGLE LOW-9 QUOTATION MARK */
+            "\xc2\x83" => "\xc6\x92",    /* LATIN SMALL LETTER F WITH HOOK */
+            "\xc2\x84" => "\xe2\x80\x9e", /* DOUBLE LOW-9 QUOTATION MARK */
+            "\xc2\x85" => "\xe2\x80\xa6", /* HORIZONTAL ELLIPSIS */
+            "\xc2\x86" => "\xe2\x80\xa0", /* DAGGER */
+            "\xc2\x87" => "\xe2\x80\xa1", /* DOUBLE DAGGER */
+            "\xc2\x88" => "\xcb\x86",    /* MODIFIER LETTER CIRCUMFLEX ACCENT */
+            "\xc2\x89" => "\xe2\x80\xb0", /* PER MILLE SIGN */
+            "\xc2\x8a" => "\xc5\xa0",    /* LATIN CAPITAL LETTER S WITH CARON */
+            "\xc2\x8b" => "\xe2\x80\xb9", /* SINGLE LEFT-POINTING ANGLE QUOTATION */
+            "\xc2\x8c" => "\xc5\x92",    /* LATIN CAPITAL LIGATURE OE */
+            "\xc2\x8e" => "\xc5\xbd",    /* LATIN CAPITAL LETTER Z WITH CARON */
+            "\xc2\x91" => "\xe2\x80\x98", /* LEFT SINGLE QUOTATION MARK */
+            "\xc2\x92" => "\xe2\x80\x99", /* RIGHT SINGLE QUOTATION MARK */
+            "\xc2\x93" => "\xe2\x80\x9c", /* LEFT DOUBLE QUOTATION MARK */
+            "\xc2\x94" => "\xe2\x80\x9d", /* RIGHT DOUBLE QUOTATION MARK */
+            "\xc2\x95" => "\xe2\x80\xa2", /* BULLET */
+            "\xc2\x96" => "\xe2\x80\x93", /* EN DASH */
+            "\xc2\x97" => "\xe2\x80\x94", /* EM DASH */
+
+            "\xc2\x98" => "\xcb\x9c",    /* SMALL TILDE */
+            "\xc2\x99" => "\xe2\x84\xa2", /* TRADE MARK SIGN */
+            "\xc2\x9a" => "\xc5\xa1",    /* LATIN SMALL LETTER S WITH CARON */
+            "\xc2\x9b" => "\xe2\x80\xba", /* SINGLE RIGHT-POINTING ANGLE QUOTATION*/
+            "\xc2\x9c" => "\xc5\x93",    /* LATIN SMALL LIGATURE OE */
+            "\xc2\x9e" => "\xc5\xbe",    /* LATIN SMALL LETTER Z WITH CARON */
+            "\xc2\x9f" => "\xc5\xb8"      /* LATIN CAPITAL LETTER Y WITH DIAERESIS*/
+                );
+    /**
+     * is_utf8
+     *
+     * @param mixed $string
+     * @access public
+     * @return void
+     */
+    function is_utf8($string) {
+        return (preg_match('/^([\x00-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xec][\x80-\xbf]{2}|\xed[\x80-\x9f][\x80-\xbf]|[\xee-\xef][\x80-\xbf]{2}|f0[\x90-\xbf][\x80-\xbf]{2}|[\xf1-\xf3][\x80-\xbf]{3}|\xf4[\x80-\x8f][\x80-\xbf]{2})*$/', $string) === 1);
+    }
+    /**
+     * cp1252_to_utf8
+     *
+     * @param mixed $str
+     * @access public
+     * @return void
+     */
+    function cp1252_to_utf8($str) {
+        global $cp1252_map;
+        return  strtr(utf8_encode($str), $cp1252_map);
+    }
+    /**
+     * myEncode
+     *
+     * @param mixed $string
+     * @access public
+     * @return void
+     */
+    function myEncode( $string )
+    {
+        if( is_utf8( $string ) )
+        {
+            return( $string );
+        }
+        else
+        {
+            return( cp1252_to_utf8( $string ) );
+        }
+    }
+
+    /**
+     * CreditVal : CreditVal Checks for a valid credit card number doing Luhn check, if no
+     card type is given, attempts to guess. Then, if a list of
+     accepted types is given, determines whether or not we'll
+     accept it
+     * @param $Num: Credit Card Number
+     * @param $Name = '': Type of Card
+     * @param $Accepted='' : Accepted array
+     *
+     * @return bool
+     * @access
+     **/
+    function CreditVal($Num, $Name = '', $Accepted='')
+    {
+        $Name = strtolower( $Name );
+        $Accepted = strtolower( $Accepted );
+        $GoodCard = 1;
+        $Num = ereg_replace("/[^[:digit:]]/", "", $Num);
+        switch ($Name)
+        {
+
+            case "mastercard" :
+                $GoodCard = preg_match("/^5[1-5].{14}$/", $Num);
+            break;
+
+            case "visa" :
+                $GoodCard = preg_match("/^4.{15}$|^4.{12}$/", $Num);
+            break;
+
+            case "americanexpress" :
+                $GoodCard = preg_match("/^3[47].{13}$/", $Num);
+            break;
+
+            case "discover" :
+                $GoodCard = preg_match("/^6011.{12}$/", $Num);
+            break;
+
+            case "dinerscard" :
+                $GoodCard = preg_match("/^30[0-5].{11}$|^3[68].{12}$/", $Num);
+            break;
+
+            default:
+            if( preg_match("/^5[1-5].{14}$/", $Num) ) $Name = "mastercard";
+            if( preg_match("/^4.{15}$|^4.{12}$/", $Num) ) $Name = "visa";
+            if( preg_match("/^3[47].{13}$/", $Num) ) $Name = "americanexpress";
+            if( preg_match("/^6011.{12}$/", $Num) ) $Name = "discover";
+            if( preg_match("/^30[0-5].{11}$|^3[68].{12}$/", $Num) ) $Name="dinerscard";
+            break;
+        }
+
+        // If there's a limit on card types we accept, check for it here.
+        if( $Accepted )
+        {
+            $type_verified = FALSE;
+            $brands = explode_trim( ",", $Accepted );
+            foreach( $brands as $brand )
+                if( $Name == $brand )
+                    $type_verified = TRUE;
+
+            if( !$type_verified ) return(FALSE);
+        }
+
+        $Num = strrev($Num);
+
+        $Total = 0;
+
+        for ($x=0; $x<strlen($Num); $x++)
+        {
+            $digit = substr($Num,$x,1);
+            if ($x/2 != floor($x/2))
+            {
+                $digit *= 2;
+                if (strlen($digit) == 2)
+                    $digit = substr($digit,0,1) + substr($digit,1,1);
+            }
+            $Total += $digit;
+        }
+        if ($GoodCard && $Total % 10 == 0)
+        {
+            return(true);
+        }
+        else
+        {
+            return(false);
+        }
+    }
+    /* DataBase Library */
+    function show_multi_cats($table1, $table2, $table3, $link, $id, $dbd, $altcats, $catid)
+    {
+        echo "<tr><th colspan=2>Categories</th></tr>";
+        multiple_select();
+        if (isset($id) && !empty($id))
+        {
+            $qs = "
+             SELECT bc.id as catid, bcb.id as id, bc.category, bcb.pos
+               FROM $table1 bc,$table2 bcb,$table3 b
+              WHERE bcb.$link = $id
+                AND bcb.catid = bc.id
+                AND b.id      = bcb.$link
+              ORDER BY bc.category";
+
+            if (!$altres = db_exec($dbd, $qs))
+                html_error(DB_ERROR_MSG.$qs, 0);
+
+            for ($rel = 0; $rel < db_numrows($altres); $rel++)
+            {
+                $altrow = db_fetch_array($altres, $rel, PGSQL_ASSOC);
+                if (is_array($oldalt))
+                    $oldalt[$rel] = array_merge_recursive($altrow, $oldalt);
+            }
+        }
+        ?>
+        <tr><td class="navtd" align="right">Categories:</td>
+        <td>
+        <select name="catid[]" size="10" multiple>
+        <?php
+        $oldcatid = "";
+        if (is_array($altcats))
+        {
+            foreach ($altcats as $ck => $cv)
+            {
+                $threads[] = array( "ID"        => $cv['id'],
+                                    "content"   => $cv['category'],
+                                    "pos"       => $cv[$pos],
+                                    "parent"    => $cv[$parent],
+                                    "closed"    => false);
+            }
+        }
+        //echo $convertToThreads($threads,$threads[0]);
+
+        for ($i = 0; $i < db_numrows($altcats); $i++)
+        {
+            $altrow = db_fetch_array($altcats, $i, PGSQL_ASSOC);
+            if ($altrow['id'] != 7)
+            {
+                echo '<option style="font-weight: bold;" value="'.$altrow['id'].'"';
+                for ($a = 0; $a < count($oldalt); $a++)
+                {
+                    if (is_array($oldalt) && ($oldalt[$a]['catid'] == $altrow['id']))
+                    {
+                        echo " selected";
+                        $oldcatid .= ":".$altrow['id'];
+                    }
+                }
+                if ((!isset($id) || $id == "") && ($catid == $altrow['id']))
+                {
+                    echo " selected";
+                }
+                echo ">";
+                if (strlen($altrow['category']) > 40)
+                    echo substr($altrow['category'], 0, 40)."...";
+                else
+                    echo $altrow['category'];
+
+                $qs            = "
+                 SELECT id, category
+                   FROM bus_category
+                  WHERE parent = ".$altrow['id']."
+                  ORDER BY pos";
+                if (!$subLevel = db_exec($dbd,$qs))
+                    html_error(DB_ERROR_MSG.$qs,0);
+
+                for ($j = 0; $j < db_numrows($subLevel); $j++)
+                {
+                    $subLevelRow = db_fetch_array($subLevel, $j, PGSQL_ASSOC);
+                    echo '<option value="'.$subLevelRow['id'].'"';
+                    for ($k = 0; $k < count($oldalt); $k++)
+                    {
+                        if (is_array($oldalt) && ($oldalt[$k]['catid'] == $subLevelRow['id']))
+                        {
+                            echo " selected";
+                            $oldcatid .= ":".$subLevelRow['id'];
+                        }
+                    }
+                    if ((!isset($id) || $id == '') && ($catid == $subLevelRow['id']))
+                    {
+                        echo " selected";
+                    }
+                    echo ">";
+                    if (strlen($subLevelRow['category']) > 36)
+                        echo "&nbsp;&nbsp;&nbsp;".substr($subLevelRow['category'], 0, 36)."...";
+                    else
+                        echo "&nbsp;&nbsp;&nbsp;".$subLevelRow['category'];
+                }
+            }
+        }
+        ?>
+        </select>
+        <input type="hidden" name="oldcatid" value="<?php echo $oldcatid?>">
+        </td></tr>
+        <?php
+        echo "<tr><td colspan=2><hr noshade></td></tr>";
+    }
+
+    function multiple_select()
+    {
+        echo "<tr><td colspan=2 align=\"center\" class=\"accenttext\">
+            Hold down the Ctrl key to select or unselect more than one at a time.
+            Hold down the Shift key to select a range.
+            </td></tr>";
+    }
+    function update_banner_buscat($id,$catid,$oldcatid = ''){
+        $dbd = db_connect();
+        //echo $oldcatid.'<br>';
+
+        if(!is_array($catid)){
+            return(false);
+        }
+        if($oldcatid){
+            $oldcatid = ereg_replace("^:","",$oldcatid);
+            $oldcatid = split(":",$oldcatid);
+        }
+        else{
+            $oldcatid = array();
+        }
+        $test1 = count(array_diff($catid,$oldcatid));
+        $test2 = count(array_diff($oldcatid,$catid));
+        $list_drop = array_diff($oldcatid,$catid);
+        $list_add = array_diff($catid,$oldcatid);
+        if (($test1 + $test2) > 0)
+        {
+            foreach ($list_drop as $key => $value)
+            {
+                $qs = "
+                 SELECT id, pos
+                   FROM banner_buscat
+                  WHERE catid = $value
+                    AND bannerid = $id";
+                if (!$res = db_exec($dbd,$qs))
+                    html_error(DB_ERROR_MSG.$qs, 1);
+
+                $row = db_fetch_array($res, 0, PGSQL_ASSOC);
+
+                $qs = "
+                DELETE FROM banner_buscat
+                 WHERE id = ".$row['id'];
+
+                if(!db_exec($dbd,$qs))
+                    html_error(DB_ERROR_MSG.$qs, 1);
+                $qs =  "
+                 SELECT id
+                   FROM banner_buscat
+                  WHERE pos >= $row[pos]
+                    AND catid = $value
+                  ORDER BY pos";
+
+                if (!$res2 = db_exec($dbd, $qs))
+                    html_error(DB_ERROR_MSG.$qs, 1);
+
+                $counter = $row[pos];
+                for ($i = 0; $i < db_numrows($res2); $i++)
+                {
+                    $row2 = db_fetch_array($res2, $i, PGSQL_ASSOC);
+
+                    $qs = "
+                     UPDATE banner_buscat
+                        SET pos = $counter
+                      WHERE id = $row2[id]";
+
+                    if (!db_exec($dbd, $qs))
+                        html_error(DB_ERROR_MSG.$qs, 1);
+                    $counter++;
+                }
+            }
+            foreach ($list_add as $key => $value)
+            {
+                $qs = "
+                 SELECT count(*) as maxpos
+                   FROM banner_buscat
+                  WHERE catid = $value";
+                if(!$res = db_exec($dbd,$qs))
+                    html_error(DB_ERROR_MSG.$qs,1);
+                $row = db_fetch_array($res,0,PGSQL_ASSOC);
+                $pos = $row[maxpos];
+                $pos++;
+
+                $qs = "
+                 INSERT INTO banner_buscat (bannerid, catid, pos)
+                 VALUES ($id,$value,$pos)";
+                if(!db_exec($dbd,$qs))
+                    html_error(DB_ERROR_MSG.$qs,1);
+            }
+        }
+    }
+
+    /**
+     * db_connect :Creates a connection to database specified $conn_str
+     * @param $conn="" : connection string
+     *
+     * @return index or bool
+     * @access
+     **/
+    function db_connect($conn="")
+    {
+        switch (DB_TYPE)
+        {
+            case "postgres":
+                if($conn == "")
+                    $conn = CONN_STR;
+            $ret = pg_connect($conn);
+            break;
+            default:
+            return(0);
+        }
+
+        return($ret);
+    }
+
+    /**
+     * db_close :Closes the connection to database specified by the handle dbd
+     * @param $$dbd : database handle
+     *
+     * @return bool
+     * @access
+     **/
+
+    function db_close($dbd)
+    {
+
+        switch (DB_TYPE)
+        {
+            case "postgres":
+                $ret = pg_close($dbd);
+            break;
+            default:
+            return(0);
+        }
+
+        return($ret);
+    }
+
+    /**
+      NOTICE DON'T USE THIS
+     * db_pconnect :Creates a persistant connection to database specified in $conn_str
+     * @param $$conn="" : connection string
+     *
+     * @return
+     * @access
+     **/
+
+
+    function db_pconnect($conn="")
+    {
+        return( false );
+
+        switch (DB_TYPE)
+        {
+            case "postgres":
+                if($conn == "")
+                    $conn == CONN_STR;
+            $ret = pg_pconnect($conn);
+            break;
+            default:
+            return(0);
+        }
+
+        return($ret);
+    }
+    /**
+     * db_exec : Execute an SQL query
+     * @param $dbd: database handle
+     * @param $$qs : Query
+     *
+     * @return int Returns a valid result index on success 0 on failure
+     * @access
+     **/
+
+    function db_exec($dbd, $qs)
+    {
+
+        switch (DB_TYPE)
+        {
+            case "postgres":
+                $ret = pg_exec($dbd, $qs);
+            break;
+
+            default:
+            return(0);
+        }
+
+        return($ret);
+    }
+
+function db_fetch_row( $res, $i )
+{
+
+    if( SI_DEBUG >= 3 ) echo "<PRE>db_fetch()[".__LINE__."]: Row = ".$i."</PRE><BR>";
+
+    if( db_numrows($res) == 0 )
+        return( FALSE );
+
+    switch( SI_DB_TYPE )
+        {
+        case "postgres":
+            $row = pg_fetch_array( $res, $i, PGSQL_ASSOC );
+            break;
+
+        default:
+            return( FALSE );
+        }
+
+    return( $row );
+
+}
+
+
+    /**
+     * db_fetch_array :Stores the data in associative indices, using the field names as
+     * keys.
+     * @param $res: valid database result index
+     * @param $i: row number
+     * @param $$type : database type
+     *
+     * @return array Returns an associative array of key-value pairs
+     * @access
+     **/
+    function db_fetch_array($res, $i, $type)
+    {
+
+        switch (DB_TYPE)
+        {
+            case "postgres":
+                $row = pg_fetch_array($res, $i, $type);
+            break;
+
+            default:
+            return(0);
+        }
+
+        return($row);
+    }
+
+    /**
+     * db_freeresult :Free result memory.
+     * @param $$res : valid database result index
+     *
+     * @return bool - Returns 1 for success 0 for failure
+     * @access
+     **/
+    function db_freeresult($res)
+    {
+
+        switch (DB_TYPE)
+        {
+            case "postgres":
+                $ret = pg_freeresult($res);
+            break;
+
+            default:
+            return(0);
+        }
+
+        return($ret);
+    }
+
+    /**
+     * db_numrows :Determine number of rows in a result index
+     * @param $$res : valid database result index
+     *
+     * @return int - Returns number of rows
+     * @access
+     **/
+    function db_numrows($res)
+    {
+
+        switch (DB_TYPE)
+        {
+            case "postgres":
+                $ret = pg_numrows($res);
+            break;
+
+            default:
+            return(-1);
+        }
+
+        return($ret);
+    }
+
+    /************************************************************************
+     *                                                                      *
+     * BEGIN Auto functions                                                 *
+     *                                                                      *
+     ***********************************************************************/
+
+    /**
+     * db_auto_array :The auto function for retrieving an array based soley on a query
+     * string. This function makes the connection, does the exec, fetches
+     * the array, closes the connection, frees memory used by the result,
+     * and then returns the array
+     * @param $qs: SQL query string
+     * @param $i: row number
+     * @param $$type : PGSQL_ASSOC or PGSQL_BOTH or PSQL_NUM
+     *
+     * @return array - Returns an associative array of key-value pairs
+     * @access
+     **/
+    function db_auto_array($qs, $i, $type)
+    {
+
+        $dbd = db_connect();
+        if(!$dbd)
+        {
+            return(0);
+        }
+        $res = db_exec($dbd, $qs);
+        if(!$res)
+        {
+            return(0);
+        }
+
+        $row = db_fetch_array($res, $i, $type);
+
+        if(!db_freeresult($res))
+        {
+            return(0);
+        }
+
+        db_close($dbd);
+        return($row);
+    }
+
+    /**
+     * db_auto_exec :The auto function for executing a query.
+     * This function makes the connection, does the exec, fetches
+     * the array, closes the connection, frees memory used by the result,
+     * and then returns success (not a valid result index)
+     * @param $qs: SQL query string
+     * @param $$conn="" : Connect String
+     *
+     * @return int - Returns 1 (or oid, if available) for success 0 for failure
+     * @access
+     **/
+function db_auto_exec( $qs, $conn_str = SI_CONN_STR, $fail_mode = 'FALSE' )
+{
+
+    if( SI_DEBUG >= 2 ) echo "<PRE>db_auto_exec()[".__LINE__."]: \$qs = $qs, \$conn_str = $conn_str</PRE><BR>";
+
+    $dbd = db_connect( $conn_str, $fail_mode );
+    if( !$dbd )
+        return( 0 );
+
+    if( !( $result = db_exec($dbd, $qs)) )
+        {
+        db_close( $dbd );
+        return( 0 );
+        }
+      else
+        {
+        $oid = pg_getlastoid( $result );
+        db_close( $dbd );
+        if( empty($oid) || $oid == -1 )
+            return( 1 );
+          else
+            return( $oid );
+        }
+}
+/*
+    function db_auto_exec($qs, $conn="")
+    {
+
+        if($conn == "")
+            $conn = CONN_STR;
+        $dbd = db_connect($conn);
+        if(!$dbd)
+            return(0);
+        if(!db_exec($dbd, $qs))
+        {
+            db_close($dbd);
+            return(0);
+        }
+        else
+        {
+            db_close($dbd);
+            return(1);
+        }
+    }
+*/
+    /**
+     * db_auto_get_data :The auto function for retrieving an array based soley on a query
+     string. This function makes the connection, does the exec, fetches
+     the array, closes the connection, frees memory used by the result,
+     and then returns the array
+     * @param $qs:  SQL query string
+     * @param $CONN_STR: Connect String
+     * @param $$fail_mode=0 : Failure Mode
+     *
+     * @return array Returns an associative array of key-value pairs
+     * @access
+     **/
+
+function db_auto_get_data( $qs, $conn_str = SI_CONN_STR, $fail_mode = FALSE, $rows = 500, $start = 0 )
+{
+
+    if( SI_DEBUG >= 2 ) echo "<PRE>db_auto_get_data()[".__LINE__."]: \$qs = $qs, \$rows = $rows, \$start = $start</PRE><BR>";
+
+    if( !($dbd = db_connect( $conn_str, $fail_mode)) )
+        return( FALSE );
+
+    if( ($res = db_exec($dbd, SI_DB_SET_DATE_STYLE_STRING.$qs)) )
+        {
+        $totalrows = pg_NumRows( $res );
+        $stop = $start + $rows;
+        if( $stop > $totalrows )
+            $stop = $totalrows;
+
+        for( $i=$start ; $i<$stop ; $i++ )
+            {
+            $data["$i|$totalrows"] = db_fetch_row( $res, $i );
+            }
+        }
+    db_close( $dbd );
+
+    return( $data );
+}
+/*
+    function db_auto_get_data($qs,$conn = CONN_STR,$fail_mode=0)
+    {
+
+        if( !($dbd = db_connect($conn)) )
+        {
+            return( FALSE );
+        }
+
+        if( !($res = db_exec($dbd, $qs)) )
+        {
+            return( FALSE );
+        }
+
+        $totalrows = pg_NumRows($res);
+
+        for( $i = 0 ; $i < $totalrows ; $i++ )
+        {
+            $data[$i] = db_fetch_array($res, $i, PGSQL_ASSOC );
+        }
+
+        db_close( $dbd );
+        if(isset($data) && $data!="")
+        {
+            return( $data );
+        }
+        else
+        {
+            return(0);
+        }
+    }
+*/
+    /* HTML Libraries */
+
+    /**
+     * html_footer :Generates a footer table on the bottom of the page it's called on.
+     and closes out the body and html tags.
+     *
+     * @return void
+     * @access
+     **/
+    function html_footer()
+    {
+        $footer_table_width = "400";
+        $footer_table_align = "center";
+
+        ?>
+            <hr>
+            <table width="<?php echo $footer_table_width?>" align="<?php echo $footer_table_align?>" summary="Footer Information" class="footertable" cellspacing="0">
+            <tr>
+            <td align="left" class="footertd">
+            <a href="mailto:<?php echo MASTER_EMAIL?>"><?php echo MASTER?></a>
+            </td>
+            <td align="right" class="footertd">
+            <a href="<?php  echo FOOTER_URL?>" target="new">
+            <img src="<?php echo FOOTER_IMG?>" border=0 alt="FOOTER_IMG"></a>
+            </td>
+            </tr>
+            </table>
+            </body>
+            </html>
+            <?php:
+            exit(); /* we've got to terminate any more output */
+    }
+
+    /**
+     * html_error :Generates a footer table on the bottom of the page it's called on.
+     and closes out the body and html tags.
+     * @param $msg: string error message to be displayed
+     * @param $$bail : bool whether or not to exit() after $msg
+     *
+     * @return void
+     * @access
+     **/
+    function html_error($msg, $bail)
+    {
+        ?>
+            <table summary="Error Information" class="errortable" cellspacing="0">
+            <tr class="errortr">
+            <td class="errortd">
+            <div class="errormsg"><?php echo "<pre>$msg</pre>"?></div>
+            </td>
+            </tr>
+            </table>
+
+            <?php
+            if($bail)
+            {
+                html_footer();
+            }
+    }
+
+    /**
+     * html_nav_table :Generates a navigation table on the page it's called on.
+     * @param $nav: associative array with entries like:$nav[text][url]
+     * @param $$w : max width of table
+     *
+     * @return void
+     * @access
+     **/
+    function html_nav_table($nav, $w)
+    {
+        if( is_array( $nav ) )
+        {
+            $out = '<ul class="admin_nav">';
+            foreach( $nav as $link => $url )
+            {
+                if( is_array( $url ) )
+                {
+                    $out .= '<li><a href="'.$url[0].'" '.$url[1].'>'.$link.'</a></li>';
+                }
+                else
+                {
+                    $out .= '<li><a href="'.$url.'">'.$link.'</a></li>';
+                }
+            }
+            $out .= '</ul>';
+        }
+        echo $out;
+    }
+
+    /**
+     * html_header :Opens up the html tags, and includes the style sheet link
+     generates a header table on the top of the page it's called on.
+     * @param $title: Page Title
+     * @param $msg: message to display
+     * @param $$img : image to display
+     *
+     * @return void
+     * @access
+     **/
+    function html_header($title, $msg, $img)
+    {
+        $header_table_width = "400";
+        $header_table_align = "center";
+
+        ?>
+            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+            "http://www.w3.org/TR/html4/loose.dtd">
+            <html>
+            <head>
+            <title><?php echo $title?></title>
+            <link type="text/css" rel=stylesheet href="<?php echo STYLE?>">
+            </head>
+            <body>
+            <table width="<?php echo $header_table_width?>" align="<?php echo $header_table_align?>" summary="Header Information" class="headertable" cellspacing="0" cellpadding="3">
+            <tr class="headertr">
+            <td class="headertd">
+            <?php
+            if($img)
+            {
+                ?>
+                    <img src="<?php echo IMG_BASE.$img?>" alt="<?php echo HEAD?>" border="0">
+                    <?php
+            }
+        ?>
+            </td>
+            </tr>
+            <tr>
+            <td class="headertd2" align="center">
+            <div class="headerh2" align="center"><?php echo "$msg"?></div>
+            </td>
+            </tr>
+            </table>
+            <?php
+    }
+
+    /**
+     * form_header :Opens up the form tag, and includes the hidden assoc array as hidden
+     fields.
+     * @param $action: string form action string
+     * @param $method: string Method of form
+     * @param $$hidden = "" : assoc array with $hidden($name => $value)
+     *
+     * @return void
+     * @access
+     **/
+    function form_header($action, $method, $hidden = "")
+    {
+        echo "<form action=\"$action\" method=\"$method\"
+            enctype=\"multipart/form-data\">";
+        if($hidden != "" && is_array($hidden))
+        {
+            foreach($hidden as $key=>$value)
+            {
+                echo "<input type=\"hidden\" name=\"$key\" value=\"$value\">";
+            }
+        }
+    }
+
+    /**
+     * text_area :Creates textarea with good default values for rows cols and wrap.
+     * @param $name: string form action string
+     * @param $value: string Method of form
+     * @param $$rows = 15: int4 number of rows in textarea box
+     * @param $$cols = 50: int4 number of cols in textarea box
+     * @param $$wrap = "virtual"  : string the wrap value for the textarea box
+     *
+     * @return void
+     * @access
+     **/
+    function text_area($name, $value, $rows = 15, $cols = 50, $wrap = "virtual" )
+    {
+        echo "<td class=\"navtd2\"><textarea id=\"$name\" name=\"$name\" cols=\"$cols\"
+            rows=\"$rows\" wrap=\"$wrap\" maxlength=\"8104\">$value</textarea></td>";
+    }
+
+    /**
+     * text_box :Creates a input box for text with 35 as default size
+     * @param $name: string name of text box
+     * @param $value: string value of text box
+     * @param $$size = 35 : string size of text box
+     *
+     * @return void
+     * @access
+     **/
+    function text_box($name, $value, $size = 35)
+    {
+        echo "<td class=\"navtd2\"><input type=\"text\" name=\"$name\"
+            value=\"".htmlspecialchars($value)."\" size=\"$size\"></td>";
+    }
+
+    /**
+     * form_footer :Closes up the form tag, and includes the submit button
+     * @param $name: string form action string
+     * @param $$suppress = 0: string Method of form
+     * @param $$cs : int colspan for td
+     *
+     * @return void
+     * @access
+     **/
+    function form_footer($name, $suppress = 0, $cs)
+    {
+        echo "<tr><td colspan=\"$cs\" align=center>
+            <input type=\"SUBMIT\" name=\"Command\" value=\"$name\">";
+        if($suppress == 1)
+        {
+            echo "<input type=\"SUBMIT\" name=\"Command\" value=\"Delete\">";
+        }
+        /*      echo "<input type=\"SUBMIT\" name=\"Command\" value=\"Cancel\">";*/
+        echo "</td>";
+    }
+
+    /* Graphics Libraries */
+    /**
+     * process_image
+     * NOTES:
+     * This function does the following:
+     *
+     * 1) places image into original folder
+     *
+     * 2) makes three images from original size and places them
+     * into the RESIZED, MIDSIZED, and THUMB folders
+     *
+     * @param mixed $image
+     * @param mixed $image_name
+     * @access public
+     * @return string
+     */
+    function process_image( $image, $image_name )
+    {
+        if(!defined("ORIGINAL_PATH"))
+        {
+            html_error("this not defined original_path",1);
+        }
+        if(!defined("RESIZED_PATH"))
+        {
+            html_error("this not defined resized_path",1);
+        }
+        if(!defined("MIDSIZED_PATH"))
+        {
+            html_error("this not defined midsized_path",1);
+        }
+        if(!defined("THUMB_PATH"))
+        {
+            html_error("this not defined thumb_path",1);
+        }
+        $image_upload_array = img_upload($image,$image_name,ORIGINAL_PATH);
+        //img_resize($image_upload_array[1],ORIGINAL_PATH.$image_upload_array[0],ITEM_ORIGINAL);
+        img_resize(ORIGINAL_PATH.$image_upload_array[0],RESIZED_PATH.$image_upload_array[0],ITEM_RESIZED);
+        img_resize(RESIZED_PATH.$image_upload_array[0],MIDSIZED_PATH.$image_upload_array[0],ITEM_MIDSIZED);
+        img_resize(MIDSIZED_PATH.$image_upload_array[0],THUMB_PATH.$image_upload_array[0],ITEM_THUMB);
+        $image_name = $image_upload_array[0];
+        return($image_name);
+    }
+
+    /**
+     * img_resize
+     * resized based on imagick widthxheight given
+     * to scale by maxwidth of 280 use '280>'
+     * which will keep it from making image larger
+     *
+     * @param mixed $path2image
+     * @param mixed $path2thumb
+     * @param mixed $size
+     * @access public
+     * @return string
+     */
+    function img_resize( $path2image, $path2thumb, $size )
+    {
+        exec( "which convert", $output, $return );
+        if( $return == 0 )
+        {
+            $CONVERT = $output[0];
+        }
+        else
+        {
+            return( $error = array('convert path uknown') );
+        }
+        $imageName = basename($path2image);
+        $thumbName = basename($path2thumb);
+
+        exec("$CONVERT -quality 100 -scale $size $path2image $path2thumb");
+
+        $img_resize_array = array("$imageName","$path2image","$thumbName","$path2thumb");
+        return($img_resize_array);
+    }
+
+    /**
+     * img_upload
+     * simplified to use the file_upload function with restricted set to true
+     * which will return an array instead of string (as in files)
+     * and only allow png,gif,jpg images to be uploaded
+     *
+     * @param mixed $form_field
+     * @param mixed $img_name
+     * @param mixed $destination_path
+     * @access public
+     * @return string
+     */
+    function img_upload( $form_field, $img_name, $destination_path )
+    {
+        return( file_upload( $form_field, $img_name, $destination_path, true ) );
+    }
+
+    /**
+     * file_upload
+     * this will replace the older version and that of img_upload which calls this with extra
+     * restricted of true
+     *
+     * @param mixed $form_field
+     * @param mixed $file_name
+     * @param mixed $destination_path
+     * @access public
+     * @return string
+     */
+    function file_upload( $form_field, $file_name, $destination_path = SI_BASE_FILE_PATH, $restricted = false )
+    {
+        $file_name_in_use = false;
+        $file_name = ereg_replace( "[!@#$%^&()+={};:\'\"\/ ]", "-", $file_name );
+        if( $restricted )
+        {
+            $size = getImageSize( $form_field );
+            if( !in_array( $size[2], array( 1, 2, 3 ) ) )
+            {
+                echo '<p style="background-color:red;color:white;">'
+                .'The file you uploaded was of an incorect type, please only upload .gif,.png or .jpg files'
+                .'<BR CLEAR=ALL>'
+                .'</p>'
+                ."Hit your browser's back button to continue"
+                .'<P>';
+                $error[0] = "ERROR";
+                return($error);
+            }
+        }
+        if( file_exists( $destination_path.$file_name ) )
+        {
+            $file_name_in_use = true;
+        }
+        if( $file_name_in_use == true )
+        {
+            $new_file_name = mktime().$file_name;
+            $new_file_location = $destination_path.$new_file_name;
+            copy( $form_field, $new_file_location );
+            $file_upload = $new_file_name;
+            $file_upload_array = array( $new_file_name, $new_file_location );
+        }
+        else
+        {
+            $new_file_name = $file_name;
+            $new_file_location = $destination_path.$new_file_name;
+            copy( $form_field, $new_file_location );
+            $file_upload = $new_file_name;
+            $file_upload_array = array( $new_file_name, $new_file_location );
+        }
+        if( is_file( $new_file_location ) )
+        {
+            chmod( $new_file_location, 0666 );
+        }
+        if( $restricted )
+        {
+            return( $file_upload_array );
+        }
+        else
+        {
+            return( $file_upload );
+        }
+    }
+
+    /* Misc. Functions */
+
+    /**
+     * http_strip :Strips the http:// part from start of string
+     * @param $&$string : $string
+     *
+     * @return string $stirng minus http:// in front
+     * @access
+     **/
+    function http_strip(&$string)
+    {
+        $test_string = strtolower($string);
+        if(substr($test_string,0,7) == "http://")
+        {
+            $string = substr($string,7);
+        }
+    }
+
+    /**
+     * footer : used for admin page footer to close out the top function
+     *
+     * @return void
+     * @access
+     **/
+    function footer()
+    {
+        $out = '
+            </body>
+            </html>
+            ';
+        echo $out;
+    }
+
+    /**
+     * top :Output the starting html and admin table tags
+     * @param $message: The title
+     * @param $hp: The help file to use
+     * @param $$hp2 = NULL : The help file to use (links to gaslightmedia.com)
+     *
+     * @return void
+     * @access
+     **/
+    function top($message, $hp,$hp2 = NULL)
+    {
+        if($hp2 != "")
+        {
+            $help_guide = '<div id="glm-manual">';
+            /*
+               $help_guide = '<div id="glm-manual"><a id="manual-html"
+               href="http://www.gaslightmedia.com/manuals/html/'.$hp2.'.html"
+               target="_blank">Online Help Guide</a>&nbsp;';
+             */
+            $help_guide .= '<a id="manual-pdf"
+                href="http://www.gaslightmedia.com/manuals/pdf/'.$hp2.'.pdf"
+                target="_blank">Printable Help Guide</a></div>';
+        }
+        $out = '
+            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+            "http://www.w3.org/TR/html4/strict.dtd">
+            <html>
+            <head>
+            <title>Untitled</title>
+            <meta http-equiv="content-type" content="text/html;charset=utf-8">
+            <link rel="stylesheet" type="text/css" href="../main.css">
+            </head>
+            <body>
+            <h1>'.$message.'</h1>
+            '.$help_guide.'
+            ';
+        echo $out;
+    }
+
+    /**
+     * top2 : alias to top()
+     * @param $message: message title
+     * @param $hp: help file
+     * @param $$hp2 = NULL : gaslight help file
+     *
+     * @return
+     * @access
+     **/
+    function top2($message, $hp,$hp2 = NULL)
+    {
+        // make this an alias to top()
+        // by calling top instead of adding extra code
+        top($message,$hp,$hp2);
+
+    }
+
+    /********************************************************************************
+     *
+     *  DO NOT EDIT THIS SECTION
+     *
+     ********************************************************************************/
+
+    if( $DEBUG )
+    {
+        echo '<CENTER>
+            <TABLE BORDER=0 CELLPADDING=3 CELLSPACING=1 WIDTH=600 BGCOLOR="#000000" ALIGN="CENTER">
+            <TR VALIGN="middle" BGCOLOR="#9999CC">
+            <TD COLSPAN="2" ALIGN="center"><H1>Portable Site Data - setup.phtml </H1></TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>CVS Version Id:</B></TD>
+            <TD ALIGN="left">$Id: setup.phtml,v 1.14 2009/02/02 20:31:01 matrix Exp $</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>SITENAME</B></TD>
+            <TD ALIGN="left">'.SITENAME.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>BASE</B></TD>
+            <TD ALIGN="left">'.BASE.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>UP_BASE</B></TD>
+            <TD ALIGN="left">'.UP_BASE.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>HELP_BASE</B></TD>
+            <TD ALIGN="left">'.HELP_BASE.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>IMG_BASE</B></TD>
+            <TD ALIGN="left">'.IMG_BASE.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>URL_BASE</B></TD>
+            <TD ALIGN="left">'.URL_BASE.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>CONN_STR</B></TD>
+            <TD ALIGN="left">'.CONN_STR.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>STYLE</B></TD>
+            <TD ALIGN="left">'.STYLE.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>ORIGINAL_PATH</B></TD>
+            <TD ALIGN="left">'.ORIGINAL_PATH.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>RESIZED_PATH</B></TD>
+            <TD ALIGN="left">'.RESIZED_PATH.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>MIDSIZED_PATH</B></TD>
+            <TD ALIGN="left">'.MIDSIZED_PATH.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>THUMB_PATH</B></TD>
+            <TD ALIGN="left">'.THUMB_PATH.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>ORIGINAL</B></TD>
+            <TD ALIGN="left">'.ORIGINAL.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>RESIZED</B></TD>
+            <TD ALIGN="left">'.RESIZED.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>MIDSIZED</B></TD>
+            <TD ALIGN="left">'.MIDSIZED.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>THUMB</B></TD>
+            <TD ALIGN="left">'.THUMB.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>$CALLED_FROM_DIR</B></TD>
+            <TD ALIGN="left">'.$CALLED_FROM_DIR.'&nbsp;</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>$BASE_PATH</B></TD>
+            <TD ALIGN="left">'.$BASE_PATH.'</TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>$BASE_URL</B></TD>
+            <TD ALIGN="left"><A HREF="'.$BASE_URL.'">'.$BASE_URL.'</A></TD>
+            </TR>
+            <TR VALIGN="baseline" BGCOLOR="#CCCCCC">
+            <TD BGCOLOR="#CCCCFF" ><B>$BASE_SECURE_URL</B></TD>
+            <TD ALIGN="left">'.$BASE_SECURE_URL.'</TD>
+            </TR>
+            </TABLE>
+            &nbsp;
+        <P>
+            <HR WIDTH="600">
+            <P>
+            </CENTER>
+            ';
+
+    }
+    /**
+     * htmlcode: Output code to enable htmlarea for the page
+     * MUST BE CALLED AFTER TEXTAREAS ON PAGE
+     * @param $$w = 570: width of htmlarea in px
+     * @param $$h = 400: height of htmlarea in px
+     *
+     * @return void
+     * @access
+     **/
+    function htmlcode( $w = 570, $h = 400, $textarea = array('description') )
+    {
+        echo '
+            <style type="text/css">
+            /*<![CDATA[*/
+            <!--
+            .textarea { height: '.$h.'px; width: '.$w.'px; }
+        -->
+            /*]]>*/
+            </style>
+            <script type="text/javascript">
+            //<![CDATA[
+            _editor_url = "../htmlarea";
+        _editor_lang = "en";
+        //]]>
+        </script><!-- load the main HTMLArea file -->
+            <script type="text/javascript" src="../htmlarea/htmlarea.js">
+            </script>
+            ';
+        echo '
+            <script type="text/javascript">
+            //<![CDATA[
+
+            ';
+        if( HTMLAREA_CONTEXT_MENU == true )
+        {
+            echo '
+                HTMLArea.loadPlugin("ContextMenu");
+            ';
+        }
+        if( HTMLAREA_TABLES == true )
+        {
+            echo '
+                HTMLArea.loadPlugin("TableOperations");
+            ';
+        }
+        if( HTMLAREA_IMAGE_MANAGER == true )
+        {
+            echo '
+                HTMLArea.loadPlugin("ImageManager");
+            ';
+        }
+        if( HTMLAREA_CHARACTER_MAP == true )
+        {
+            echo '
+                HTMLArea.loadPlugin("CharacterMap");
+            ';
+        }
+        echo '
+            initdocument = function () {
+                var editor = new HTMLArea("description");
+
+                ';
+                foreach( $textarea as $htmlarea )
+                {
+                    echo '
+                        var editor_'.$htmlarea.' = new HTMLArea("'.$htmlarea.'");
+
+                    editor_'.$htmlarea.'.config.registerButton({
+                       id        : \'backtotop\',
+                       tooltip   : \'Back To Top\',
+                       image     : \'images/backtotop.gif\',
+                       textMode  : false,
+                       action    : function(editor, id) {
+                     editor.insertHTML(\'<p style="text-align: center;"><a href="#TOP">BACK TO TOP</a></p>\');
+                                                  }
+                        });
+                    ';
+                    echo '
+                        editor_'.$htmlarea.'.config.toolbar = [
+                        [ "fontname", "space",
+                        "fontsize", "space",
+                        "formatblock", "space",
+                        "bold", "italic", "underline", "separator","backtotop" ],
+
+                        [ "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
+
+                        "orderedlist", "unorderedlist", "outdent", "indent", "separator",
+                        "forecolor", "separator",
+                        "inserthorizontalrule", "createlink"';
+                    if( HTMLAREA_TABLES == true )
+                    {
+                        echo ', "inserttable"';
+                    }
+                    if( HTMLAREA_IMAGE_MANAGER == true )
+                    {
+                        echo ', "insertimage"';
+                    }
+                    echo ', "htmlmode", "separator",
+                         "copy", "cut", "paste", "space", "undo", "redo" ]
+                             ];
+                    ';
+                    if( HTMLAREA_CONTEXT_MENU == true )
+                    {
+                        echo '
+                            // add a contextual menu
+                            editor_'.$htmlarea.'.registerPlugin("ContextMenu");
+                        ';
+                    }
+                    if( HTMLAREA_TABLES == true )
+                    {
+                        echo '
+
+                            // register the TableOperations plugin
+                            editor_'.$htmlarea.'.registerPlugin(TableOperations);
+                        ';
+                    }
+                    if( HTMLAREA_CHARACTER_MAP == true )
+                    {
+                        echo '
+
+                            // register the CharacterMap plugin
+                            editor_'.$htmlarea.'.registerPlugin(CharacterMap);
+                        ';
+                    }
+                    echo '
+                        editor_'.$htmlarea.'.generate();
+                    ';
+                }
+
+                echo '
+            }
+        function addEvent(obj, evType, fn)
+        {
+            if (obj.addEventListener) { obj.addEventListener(evType, fn, true); return true; }
+            else if (obj.attachEvent) {  var r = obj.attachEvent("on"+evType, fn);  return r;  }
+            else {  return false; }
+        }
+        addEvent(window, \'load\', initdocument);
+        //]]>
+        </script>
+            ';
+    }
+
+    /**
+     * date_entry : Generate the select boxes for date entry
+     * month-day-year as drop down select
+     * @param $month:
+     * @param $day:
+     * @param $year:
+     * @param $month_name: name of select month
+     * @param $day_name: name of select day
+     * @param $$year_name : name of select year
+     *
+     * @return
+     * @access
+     **/
+    function date_entry($month,$day,$year,$month_name,$day_name,$year_name,$onChange = NULL)
+    {
+        $cur_date = getdate();
+
+        if($month == "")
+        {
+            $month = $cur_date['mon'];
+        }
+        if($day == "")
+        {
+            $day = $cur_date['mday'];
+        }
+        if($year == "")
+        {
+            $year = $cur_date['year'];
+        }
+        $date = '<SELECT id="'.$month_name.'" NAME="'.$month_name.'" '.$onChange.'>';
+        for($i=1;$i<13;$i++)
+        {
+            $date .= '<OPTION VALUE="';
+            if($i < 10)
+            {
+                $date .= "0";
+            }
+            $date .= $i.'"';
+            if($i == $month)
+            {
+                $date .= ' SELECTED';
+            }
+            $date .= '>'.$i;
+        }
+        $date .= '</SELECT>';
+        $date .= '<SELECT id="'.$day_name.'" NAME="'.$day_name.'" '.$onChange.'>';
+        for($i=1;$i<32;$i++)
+        {
+            $date .= '<OPTION VALUE="';
+            if($i < 10)
+            {
+                $date .= "0";
+            }
+            $date .= $i.'"';
+            if($i == $day)
+            {
+                $date .= ' SELECTED';
+            }
+            $date .= '>'.$i;
+        }
+        $date .= '</SELECT>';
+        $date .= '<SELECT id="'.$year_name.'" NAME="'.$year_name.'" '.$onChange.'>';
+        for($i=2000;$i<2023;$i++)
+        {
+            $date .= '<OPTION VALUE="'.$i.'"';
+            if($i == $year)
+            {
+                $date .= ' SELECTED';
+            }
+            $date .= '>'.$i;
+        }
+        $date .= '</SELECT>';
+        return $date;
+    }
+
+    /**
+     * contact_date_entry : build select boxes for date entry going backwords in years
+     * @param $month:
+     * @param $day:
+     * @param $year:
+     * @param $month_name: name of select month
+     * @param $day_name: name of select day
+     * @param $$year_name : name of select year
+     *
+     * @return void
+     * @access
+     **/
+    function contact_date_entry($month,$day,$year,$month_name,$day_name,$year_name)
+    {
+        $cur_date = getdate();
+
+        if($month == "")
+        {
+            $month = $cur_date['mon'];
+        }
+        if($day == "")
+        {
+            $day = $cur_date['mday'];
+        }
+        if($year == "")
+        {
+            $year = $cur_date['year'];
+        }
+        $date = '<SELECT NAME="'.$month_name.'">';
+        for($i=1;$i<13;$i++)
+        {
+            $date .= '<OPTION VALUE="';
+            if($i < 10)
+            {
+                $date .= "0";
+            }
+            $date .= $i.'"';
+            if($i == $month)
+            {
+                $date .= ' SELECTED';
+            }
+            $date .= '>'.$i;
+        }
+        $date .= '</SELECT>';
+        $date .= '<SELECT NAME="'.$day_name.'">';
+        for($i=1;$i<32;$i++)
+        {
+            $date .= '<OPTION VALUE="';
+            if($i < 10)
+            {
+                $date .= "0";
+            }
+            $date .= $i.'"';
+            if($i == $day)
+            {
+                $date .= ' SELECTED';
+            }
+            $date .= '>'.$i;
+        }
+        $date .= '</SELECT>';
+        $date .= '<SELECT NAME="'.$year_name.'">';
+        $ystart = $cur_date['year'] - 10;
+        for($i=$ystart;$i<=$year;$i++)
+        {
+            $date .= '<OPTION VALUE="'.$i.'"';
+            if($i == $year)
+            {
+                $date .= ' SELECTED';
+            }
+            $date .= '>'.$i;
+        }
+        $date .= '</SELECT>';
+        return $date;
+    }
+
+    /**
+     * time_entry : build select boxes for time entry
+     * @param $H:
+     * @param $m:
+     * @param $F:
+     * @param $H_name: name of select hour
+     * @param $m_name: name of select min
+     * @param $$F_name : name of select sec
+     *
+     * @return
+     * @access
+     **/
+    function time_entry($H,$m,$F,$H_name,$m_name,$F_name)
+    {
+        $cur_date = getdate();
+        if($H == "")
+        {
+            $H = $cur_date['hours'];
+        }
+        if($m == "")
+        {
+            $m = $cur_date['minutes'];
+        }
+        if($H>12)
+        {
+            $F = "PM";
+            $H = $H - 12;
+        }
+        $time = "Hr:<select name=\"$H_name\" size=\"1\">";
+        for($i=1;$i<=12;$i++)
+        {
+            $time .= "<option value=\"";
+            if($i < 10)
+            {
+                $time .= "0";
+            }
+            $time .= "$i\"";
+            if($i == $H)
+            {
+                $time .= " selected";
+            }
+            $time .= ">$i\n";
+        }
+        $time .= "</select>\n";
+        $time .= "Min:<select name=\"$m_name\" size=\"1\">";
+        for($i=0;$i<60;$i=$i+15)
+        {
+            $time .= "<Option value=\"";
+            if($i < 10)
+            {
+                $time .= "0";
+            }
+            $time .= "$i\"";
+            if($i == $m)
+            {
+                $time .= " selected";
+            }
+            $time .= ">";
+            if($i < 10)
+            {
+                $time .= "0";
+            }
+            $time .= "$i\n";
+        }
+        $time .= "</select>";
+        $time .= "<select name=\"$F_name\" size=\"1\">";
+        $time .= "<option value=\"AM\"";
+        if($F == "AM")
+        {
+            $time .= " selected";
+        }
+        $time .= ">AM\n";
+        $time .= "<option value=\"PM\"";
+        if($F == "PM")
+        {
+            $time .= " selected";
+        }
+        $time .= ">PM\n";
+        $time .= "</select>\n";
+        return $time;
+    }
+
+    /**
+     * get_parentid: get the (highest level) parent category for this id
+     * @param $id: id from bus_category table
+     *
+     * @return int parent
+     * @access
+     **/
+    function get_parentid( $id )
+    {
+        static $parentshow;
+        if( $id == 0 )
+        {
+            return( 0 );
+        }
+        if(!is_array($parentshow))
+        {
+            $qs = "select parent from bus_category where id = $id";
+            $parentrow = db_auto_get_data( $qs );
+        }
+        if($parentrow[0]['parent'] == 0)
+        {
+            return($id);
+        }
+        else
+        {
+            return( get_parentid($parentrow[0]['parent']) );
+        }
+    }
+
+    /**
+     * build_picklist:Builds a pick list from an array
+     * @param $fieldname: fieldname field name for select
+     * @param $data: data array of data
+     * @param $selected: selected witch element is selected
+     * @param $$type = "standard": type Standard,multi
+     * @param $$auto = 0: auto
+     * @param $$width = NULL : width width controlled by css
+     *
+     * @return void
+     * @access
+     **/
+    function build_picklist( $fieldname, $data, $selected, $type = "standard",$auto = 0,$width = NULL )
+    {
+        if(!is_array($selected))
+        {
+            $sel[0] = $selected;
+        }
+        else
+        {
+            $sel = $selected;
+        }
+        if($auto == 1)
+            $autosubmit = "onChange=\"form.submit()\"";
+        if($width)
+            $autosubmit .= "style=\"width:".$width."px;\"";
+        switch( $type )
+        {
+            case "multiple":
+                $str = "<SELECT NAME=\"".$fieldname."\" multiple size=\"10\" ".$autosubmit.">\n";
+            while( list($key, $val) = each($data) )
+            {
+                if( in_array($key,$sel) )
+                {
+                    $select = " SELECTED ";
+                }
+                else
+                    $select = "";
+                $str .= "   <OPTION VALUE=\"$key\"".$select.">$val\n";
+            }
+            break;
+            case "simple":
+                $str = "<SELECT NAME=\"$fieldname\" ".$autosubmit.">\n";
+            for( $i=0 ; $i<count($data) ; $i++ )
+            {
+                $select = (in_array($data[$i],$sel)) ? " SELECTED ":"";
+                $str .= "   <OPTION VALUE=\"".$data[$i]."\"".$select.">".$data[$i]."\n";
+            }
+            break;
+
+            case "standard":
+            default:
+                $str = "<SELECT NAME=\"$fieldname\" ".$autosubmit.">\n";
+                while( list($key, $val) = each($data) )
+                {
+                    $select = (in_array($key,$sel)) ? " SELECTED ":"";
+                    $str .= "   <OPTION VALUE=\"$key\"".$select.">$val\n";
+                }
+                break;
+        }
+        $str .= "</SELECT>\n";
+
+        return( $str );
+
+    }
+
+    /**
+     * create_page_links:Create prev and next links
+     * to page through the results.
+     * @param $totalnum: The total result of the query
+     * @param $num: The total result for the page
+     * @param $$start=0: The starting num defaults to 0
+     * @param $params: variables to add to the url
+     * @param $ENTRIES_PER_PAGE: number of items on page defaults to the ENTRIES_PER_PAGE
+     *
+     * @return string of links
+     * @access
+     **/
+    function create_page_links($totalnum,$num,$start=0,$params,$page_length=ENTRIES_PER_PAGE)
+    {
+        // find out which page we're on.
+        if($totalnum!=0)
+        {
+            $total_pages = floor($totalnum / $page_length);     // total pages = the total result divided by page length rounded down
+            $total_pages++;                                     // then add one
+            if($start == 0)                                     // if start is 0 then page is one
+            {
+                $page = 1;
+            }
+            else
+            {
+                $page = ($start / $page_length) + 1;
+            }
+        }
+
+        if($totalnum > $page_length && ( $page != $totalpages ) )
+        {
+            $end = $page_length + $start;
+        }
+        else
+        {
+            $end = $totalnum;
+        }
+        $last = $start - $page_length;
+        if(($start - $page_length) < 0)
+            $prev = "";
+        else
+            $prev = "<span class=\"accenttext\">[</span><a class=\"small\"
+                href=\"$GLOBALS[PHP_SELF]?start=".$last."&$params\">PREVIOUS PAGE</a><span
+                class=\"accenttext\"> ]</span>";
+        if($end < $totalnum)
+            $next = "<span class=\"accenttext\">[</span><a class=\"small\"
+                href=\"$GLOBALS[PHP_SELF]?start=".$end."&$params\">NEXT PAGE</a><span
+                class=\"accenttext\"> ]</span>";
+        else
+            $next = "";
+        $starting = $start + 1;
+        $last_c = $start + $num;
+        $links = '<center><span class="pagetitle">Listings Displayed: </span><span
+            class="accenttext">'.$starting.' to '.$last_c.'</span>
+            <span class="pagetitle"> of '.$totalnum.'<br></span> '.$prev. ' &nbsp; <span
+            class="pagetitle"></span> '.$next.'<BR></span></center>';
+        return($links);
+    }
+}
+
+/*
+ * Stuff required to make all the registration and MagicForm stuff work in Steve's world
+ */
+
+define( 'SI_DB_TYPE',   DB_TYPE );
+define( 'SI_BASE_PATH', BASE_PATH );
+define( "SI_BASE_URL",                      $BASE_URL );                        // URL to root of Web site
+define( "SI_BASE_FILE_URL",                 SI_BASE_URL."/files" );
+define( "SI_BASE_FILE_PATH",                SI_BASE_PATH."files/" );
+
+define( "SI_THIS_SCRIPT",   BASE_URL.substr($CALLED_FROM_DIR,1)."/".$calling_script_name );         // The name of the calling script
+
+define( "SI_CONN_STR", CONN_STR );
+define( "SI_DB_DATE_STYLE",                 "SQL" );
+        // ISO      - use ISO 8601-style dates and times,                   "1997-12-17 07:37:16-08"
+        // SQL      - use Oracle/Ingres-style dates and times,              "12/17/1997 07:37:16.00 PST"
+        // Postgres     - use traditional Postgres format,                  "Wed Dec 17 07:37:16 1997 PST"
+        // European     - use dd/mm/yyyy for numeric date representations., "17/12/1997 15:37:16.00 MET"
+        // US       - use mm/dd/yyyy for numeric date representations.,     "12/17/1997 07:37:16.00 PST"
+        // German   - use dd.mm.yyyy for numeric date representations.,     "17.12.1997 07:37:16.00 PST"
+define( 'SI_DB_STATIC',                     TRUE );             // If true database functions don't automatically close a connection and will re-use if possible
+define( "SI_DB_SET_DATE_STYLE_STRING",      "SET DATESTYLE TO '".SI_DB_DATE_STYLE."';\n" );
+define("SI_BASE_URL", BASE_URL );
+    // Graphics support
+
+define( "SI_GRPH_CONVERT",                  "/usr/bin/convert" );
+define( "SI_GRPH_DJPEG",                    "/usr/bin/djpeg ");
+define( "SI_GRPH_CJPEG",                    "/usr/bin/cjpeg ");
+define( "SI_GRPH_PNMSCALE",                 "/usr/bin/pnmscale ");
+define( "SI_GRPH_GIFTOPNM",                 "/usr/bin/giftopnm ");
+define( "SI_GRPH_PPMTOGIF",                 "/usr/bin/ppmtogif ");
+define( "SI_GRPH_PPMQUANT",                 "/usr/bin/ppmquant ");
+
+define( "SI_IMAGE_DIR",                     "images" );
+define( "SI_BASE_IMAGE_URL",                BASE_URL.SI_IMAGE_DIR );
+define( "SI_BASE_IMAGE_PATH",               BASE_PATH.SI_IMAGE_DIR );
+
+define( "SI_IMG_ORIGINAL_URL",              SI_BASE_IMAGE_URL."/original" );
+define( "SI_IMG_RESIZED_URL",               SI_BASE_IMAGE_URL."/resized" );
+define( "SI_IMG_MIDSIZED_URL",              SI_BASE_IMAGE_URL."/midsized" );
+define( "SI_IMG_THUMB_URL",                 SI_BASE_IMAGE_URL."/thumb" );
+
+define( "SI_IMG_ORIGINAL_PATH",             SI_BASE_IMAGE_PATH."/original" );
+define( "SI_IMG_RESIZED_PATH",              SI_BASE_IMAGE_PATH."/resized" );
+define( "SI_IMG_MIDSIZED_PATH",             SI_BASE_IMAGE_PATH."/midsized" );
+define( "SI_IMG_THUMB_PATH",                SI_BASE_IMAGE_PATH."/thumb" );
+define( "SI_POSTCARD_URL",                  SI_BASE_URL."/index.phtml" );
+
+define( "SI_RESIZED_SIZE",              ITEM_RESIZED );
+define( "SI_MIDSIZED_SIZE",             ITEM_MIDSIZED );
+define( "SI_THUMB_SIZE",                ITEM_THUMB );
+
+    // Information about the customer
+
+define( 'SI_CUSTOMER_NAME',                 'C.S. Lewis Festival' );
+define( 'SI_CUSTOMER_LONG_NAME',            'C.S. Lewis Festival' );
+define( 'SI_CUSTOMER_PHONE',                '231-347-5550' );
+define( 'SI_CUSTOMER_FAX',                  '' );
+define( 'SI_CUSTOMER_TOLL_FREE',            '' );
+define( 'SI_CUSTOMER_ADDRESS',              'P.O. Box 2026' );
+define( 'SI_CUSTOMER_CITY',                 'Petoskey' );
+define( 'SI_CUSTOMER_STATE',                'MI' );
+define( 'SI_CUSTOMER_ZIP',                  '49770' );
+define( 'SI_CUSTOMER_FROM_EMAIL',           'registrations@cslewisfestival.org' );
+define( 'SI_CUSTOMER_INTERNAL_EMAIL',           'info@cslewisfestival.org' );
+define( 'SI_CUSTOMER_LETTER_CLOSING',       'Sincerely,' );
+
+    // Convention Registration specific parameters
+
+define( "SI_CUSTOMER_REG_TITLE",            "C.S. Lewis Festival - Event Registration" );
+
+define( "SI_REG_INTRO",                     FALSE );        // Conventions Intro page displayed
+define( "SI_REG_SELECT",                    "List" );       // Method of selecting Conventions, "Pick" - Picklist, "List" - Detailed list
+
+    // Payment Processing Methods
+
+define( "SI_REG_PROC_METHOD_MERCHANT",      1 );            // Cards processed and confirmed by merchant
+define( "SI_REG_PROC_METHOD_AUTHORIZE",     2 );            // Credit Cards processed by Authorize.Net
+
+define( "SI_REG_PROC_METHOD",               SI_REG_PROC_METHOD_AUTHORIZE );         // Selected payment method
+
+    // Status Codes
+
+define( "SI_REG_STATUS_UNPAID",             1 );            //      Unknown or unpaid
+define( "SI_REG_STATUS_CC_PEND",            2 );            //      Paying by Credit Card - Card not run yet
+define( "SI_REG_STATUS_CC_PAID",            3 );            //      Paid by Credit Card
+define( "SI_REG_STATUS_CC_DECL",            4 );            //      Credit Card Declined
+define( "SI_REG_STATUS_CHECK_PEND",         5 );            //      Pending Check
+define( "SI_REG_STATUS_CHECK_PAID",         6 );            //      Paid by Check
+define( "SI_REG_STATUS_COMP",               7 );            //      Comp or no payment
+define( "SI_REG_STATUS_NEW",                    20 );           //      New registration with no data or incomplete data
+define( "SI_REG_STATUS_FAILED",             98 );           //      Failed to store all of registration data or failed trying to process CC, process not completed
+define( "SI_REG_STATUS_CANCELED",           99 );           //      Canceled
+
+
+$si_reg_status_types = array
+    (
+    SI_REG_STATUS_UNPAID            => 'Not Paid',
+    SI_REG_STATUS_CC_PEND           => 'Credit Card Pending',
+    SI_REG_STATUS_CC_PAID           => 'Paid by Credit Card',
+    SI_REG_STATUS_CC_DECL           => 'Credit Card Declined',
+    SI_REG_STATUS_CHECK_PEND        => 'Check Pending',
+    SI_REG_STATUS_CHECK_PAID        => 'Paid by Check',
+    SI_REG_STATUS_COMP              => 'Complimentary',
+    SI_REG_STATUS_NEW                   => 'New registration in progress',
+    SI_REG_STATUS_FAILED            => 'Submission Failed',
+    SI_REG_STATUS_CANCELED          => 'Canceled',
+    );
+$si_reg_status_list = $s = "";
+while( list($k, $v) = each($si_reg_status_types) )
+    {
+    $si_reg_status_list .= "$s$k^$v";
+    $s = "~";
+    }
+
+$si_reg_field_types = array
+    (
+    1   => 'Checkbox',
+    2   => 'Number',
+    3   => 'Text',
+    4   => 'Text Box',
+    5   => 'Picklist',
+    6   => 'Radio Buttons',
+    20  => 'Section Title',
+    21  => 'Misc. Text'
+    );
+
+
+$si_cc_verify = array               // Values are regex test strings for card type
+    ( // *** Don't forget to correct the commas ***
+    "Visa"              => "^4.{15}$|^4.{12}$",
+    "MasterCard"        => "^5[1-5].{14}$",
+    "American Express"  => "^3[47].{13}$",
+    "Discover"          => "^6011.{12}$",
+    "Diner's Club"      => "^30[0-5].{11}$|^3[68].{12}$"
+    );
+
+$si_cc_verify = $si_cc_verify;  // Backward compatibility
+
+define( "SI_CC_ACCEPTS",                    3 );        // Cards the CVB accepts - Carefull with this one - It's a bitmap of the cars above
+
+    // $si_credit_cards string and $si_cc_array array are built from above
+    // Select and deselect cards used from above array.
+
+$si_credit_cards = $s = "";
+$si_cc_array = array();
+$i = 0;
+while( list($k, $v) = each($si_cc_verify) )
+    {
+    $si_credit_cards .= "$s$k";
+    array_push( $si_cc_array, $k );
+    $s = "~";
+    }
+
+$si_pay_by_types =
+    "
+    1^Credit Card~
+    2^Check~
+    3^Direct to DMCVB
+    ";
+
+$si_conf_methods =
+    "
+    1^US Mail~
+    2^E-Mail
+    ";
+
+
+//  -------------------------------
+//  Setup for HTMLArea input forms
+//  -------------------------------
+
+define( "SI_RICHTEXT_TYPE_ENABLED",     TRUE );
+define( "SI_RICHTEXT_START_DELAY",      500 );      // Delay before starting to setup HTMLArea - 1/2 Sec
+define( "SI_RICHTEXT_SETUP_DELAY",      1000 );     // Delay after starting setup on each HTMLArea - 1 Sec
+
+    // Plugins for HTMLarea capabilities of richtext type
+    // Note that some plugins use toolbar buttons - See list of buttons below
+
+define( "SI_HTMLAREA_PLUGS",            '
+        editor.registerPlugin(CharacterMap);
+        editor.registerPlugin(ContextMenu);
+//      editor.registerPlugin(CSS, css_plugin_args);
+//      editor.registerPlugin(DynamicCSS);
+//      editor.registerPlugin(EnterParagraphs);         // Enter key creates new paragraph rather than just line break
+//      editor.registerPlugin(FullPage);                // Permits setting properties for entire page
+//      editor.registerPlugin(HtmlTidy);                // Requires HTML Tidy installed on server
+        editor.registerPlugin(ListType);
+//      editor.registerPlugin(SpellChecker);
+        editor.registerPlugin(TableOperations);
+    ' );
+
+    // Toolbar configuration
+
+define( "SI_HTMLAREA_TOOLBAR",          '
+        config.toolbar =
+            [
+                [
+                "fontname",
+                "fontsize",
+                "formatblock",
+                "space",
+                "bold",
+                "italic",
+                "underline",
+                "strikethrough",
+                "separator",
+                "subscript",
+                "superscript",
+                "separator",
+                "copy",
+                "cut",
+                "paste",
+                "space",
+                "undo",
+                "redo"
+                ],
+                [
+                "justifyleft",
+                "justifycenter",
+                "justifyright",
+                "justifyfull",
+                "separator",
+                "lefttoright",
+                "righttoleft",
+                "separator",
+                "ListType",                     // List Type Plugin
+                "insertorderedlist",
+                "insertunorderedlist",
+                "separator",
+                "outdent",
+                "indent",
+                "separator",
+                "forecolor",
+                "hilitecolor",
+                "separator",
+                "inserthorizontalrule",
+                "createlink",
+//              "insertimage",
+                "inserttable",
+                "htmlmode",
+                "separator",
+                "popupeditor"
+//              "separator",
+//              "showhelp",
+//              "about"
+                ]
+            ];
+    ' );
+
+    // Other toolbar buttons not in use
+
+/*
+                "insertcharacter"   // CharacterMap - Not required - inserted automatically
+                "FP-docprop"        // FullPage
+                "HT-html-tidy"      // HtmlTidy
+                "HT-auto-tidy"      // HtmlTidy
+                "unorderedlist"     // ListType - Couldn't get this to work correctly
+*/
+
+define( "SI_DEFAULT_RICHTEXT_WIDTH",    "540" );            // Default width
+define( "SI_DEFAULT_RICHTEXT_HEIGHT",   "100" );            // Default height
+
+
+//  -----------------------------------------
+//  Authorize.Net Configuration
+//  -----------------------------------------
+
+define( 'AUTH_CURL',            '/usr/bin/curl' );                      // Curl executable
+//define( 'AUTH_URL',           'https://secure.authorize.net/gateway/transact.dll' );      // Authorization URL
+define( 'AUTH_URL',         'http://ws6.gaslightmedia.com/AuthorizeNetRelay/glmAuthNetRelay/AuthNetRelayProduction.php' );      // Authorization URL
+// define( 'SI_AUTH_TEST',      'LOCAL_TEST' );                         // Must be "FALSE" for production! Otherwise "TRUE" or "LOCAL_TEST" (don't transmit)
+define( 'SI_AUTH_LOGIN',                '3uaA59As' );                                                   // Authorize.Net Customer Login                     -- UNIQE FOR EACH CUSTOMER --
+define( 'SI_AUTH_TRAN_KEY',             '2Mq3Sh38S63ys8R2' );                                           // Authorize.Net Customer Transaction Key       -- UNIQE FOR EACH CUSTOMER --
+define( 'SI_AUTH_SEND_CONF',        'TRUE' );                           // TRUE to have customer's receive E-Mail confirmation
+define( 'SI_AUTH_MERCHANT_EMAIL',   'FALSE' );                          // TRUE to have merchant receive E-Mail convirmation of customer charges
+define( 'SI_AUTH_SECRET',       '' );                               // MD5 Hash secret used by Authorize.Net to generate MD5 response verification data
+                                                        //  If empty - don't check MD5 response
+
+//  ----------
+//  MagicForms
+//  ----------
+
+/*  field types
+        1   Checkbox
+        2   Number
+        3   Text
+        4   Text Box
+        5   Picklist
+        6   Radio Buttons
+        7   File Upload
+        20  Section Title
+        21  Misc. Text
+        22  Horizontal Line
+        23  Blank Line
+        24  Display Image
+        25  Download File
+        31  Calculated Field
+ */
+
+define( 'MF_TABLE',                     'magicform' );      // Table name for MagicForm fields
+define( 'MF_DATA_TABLE',                'mf_data' );            // Table name for MagicForm fields
+define( 'MF_SUBFORMS',                  true );             // Enable/disable Sub-Forms
+
+    // Field Format Definitions
+    // Note that {chars} gets replaced with # of characters or # of digits to the left of the decimal point and {prec} gets replaced with # of digits to the right of decimal point
+
+$mf_formats = array
+    (
+    'Default Format'        =>  array
+        (
+        'short_name'    => 'Default Format',                // Short name for this validation type
+        'types'         => ' 2 3 ',                 // Field types this validation type applies to
+        'format'        => '%s',                        // Output format for this field - printf() style format string
+        'regex'         => '',                      // Regular expression to validate this field
+        'sample'        => ''
+        ),
+    'Integer Number'    => array
+        (
+        'short_name'    => 'Integer',
+        'types'         => ' 2 ',
+        'format'        => '%{chars}d',
+        'regex'         => '[0-9]*',
+        'sample'        => '123'
+        ),
+    'Floating Point Number' => array
+        (
+        'short_name'    => 'Float',
+        'types'         => ' 2 ',
+        'format'        => '%{chars}.{prec}f',
+        'regex'         => '[0-9]*\.[0-9]*',
+        'sample'        => '123.4'
+        ),
+    'Money'     => array
+        (
+        'short_name'    => 'Money',
+        'types'         => ' 2 ',
+        'format'        => '%{chars}.{prec}f',
+        'regex'         => '[0-9]*\.[0-9]*',
+        'sample'        => '$123.45'
+        ),
+    'E-Mail Address'        => array
+        (
+        'short_name'    => 'E-Mail',
+        'types'         => ' 3 ',
+        'format'        => '%s',
+        'regex'         => '[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,4}',
+        'sample'        => 'userid@domain.dom'
+        ),
+    'Phone Number'      => array
+        (
+        'short_name'    => 'Phone',
+        'types'         => ' 3 ',
+        'format'        => '%s',
+        'regex'         => '\d{3}[-.]{1}\d{3}[-.]{1}\d{4}[^\d]*\d*',
+        'sample'        => '123-456-7890 X123'
+        )
+    );
+
+    // Style definitions
+
+$mf_styles = array
+    (
+
+    'Default' =>    array
+                (
+                'types'     => ' 1 2 3 4 5 6 7 20 21 23 24 25 30 31 ',                                                                              // Field types - MUST HAVE SPACE EACH SIDE OF VALUES
+                'short_name' => 'Default',                                                                                                          // A short name used in form edit
+                'cols'      => 1,                                                                                                                   // Number of columns per row
+                'start'     => '',                                                                                                                  // Text when starting this style
+                'row_start' => '',                                                                                                                  // Text when starting a row
+                'body'      => '<ul>
+                                    <!--{if:required}--><span style="color: red;">{title}</span><!--{else:required}<b>{title}</b>{/if:required}--><br>
+                                    <!--{if:descr}-->{descr}<br><!--{/if:descr}-->
+                                    <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                    <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                    {input}
+                                    <!--{if:sub_forms}--><br><ol>{sub_forms}</ol><!--{/if:sub_forms}-->
+                                </ul>',                                                                                                             // Text for each column
+                'col_empty' => '',                                                                                                                  // Text for empty columns
+                'row_end'   => '',                                                                                                                  // Text for end of each row
+                'end'       => '',                                                                                                                  // Text when switching to different style
+                'sub_form'  => '<ul>{sub_form}</ul>'                                                                                                    // Text for each sub-form (yes, there could be multiples)
+                ),
+
+    'Prompt and Input on single line without following break' =>    array
+                (
+                'types'     => ' 1 2 3 4 5 6 7',
+                'short_name' => 'Single Line',
+                'cols'      => 1,
+                'start'     => '',
+                'row_start' => '',
+                'body'      => '<!--{if:required}--><span style="color: red;">{title}</span><!--{else:required}<b>{title}</b>{/if:required}-->
+                                    <!--{if:image}-->{image}<!--{/if:image}-->
+                                    <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                    {input}
+                                    <!--{if:sub_forms}--><br><ol>{sub_forms}</ol><!--{/if:sub_forms}-->
+                                ',
+                'col_empty' => '',
+                'row_end'   => '',
+                'end'       => '',
+                'sub_form'  => '<ul>{sub_form}</ul>'
+                ),
+
+    'Prompt and Input on single line with following break' =>   array
+                (
+                'types'     => ' 1 2 3 4 5 6 7',
+                'short_name' => 'Single Line w/break',
+                'cols'      => 1,
+                'start'     => '',
+                'row_start' => '',
+                'body'      => '<!--{if:required}--><span style="color: red;">{title}</span><!--{else:required}<b>{title}</b>{/if:required}-->
+                                    <!--{if:image}-->{image}<!--{/if:image}-->
+                                    <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                    {input}
+                                    <!--{if:sub_forms}--><br><ol>{sub_forms}</ol><!--{/if:sub_forms}--><br>
+                                ',
+                'col_empty' => '',
+                'row_end'   => '',
+                'end'       => '',
+                'sub_form'  => '<ul>{sub_form}</ul>'
+                ),
+
+    'Prompt and Input Aligned' =>   array
+                (
+                'types'     => ' 1 2 3 4 5 6 20 21 24 25 ',
+                'short_name' => 'Prompt Aligned',
+                'cols'      => 1,
+                'start'     => '<table border="0" cellspacing="0" cellpadding="2">',
+                'row_start' => '',
+                'body'      => '<tr>
+                                    <td align="right" valign="top">
+                                        <b><!--{if:required}--><span style="color: red;">{title}</span><!--{else:required}{title}{/if:required}--></b><br>
+                                        <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                        <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                    </td><td align="left">{input}<!--{if:sub_forms}--><p>{sub_forms}<!--{/if:sub_forms}--></td>
+                                </tr>
+                                <!--{if:descr}--><tr><td>&nbsp;</td><td align="left">{descr}</td></tr><!--{/if:descr}-->
+                                <!--{if:sub_forms}--><p><tr><td>&nbsp;</td><td align="left">{sub_forms}</td></tr><!--{/if:sub_forms}-->
+                                ',
+                'col_empty' => '',
+                'row_end'   => '',
+                'end'       => '</table><p>',
+                'sub_form'  => '{sub_form}<br>'
+                ),
+
+    '2 Column Table' => array
+                (
+                'types'     => ' 1 2 3 4 5 6 20 21 24 25 ',
+                'short_name' => '2 Column',
+                'cols'      => 2,
+                'start'     => '<table border="0" cellspacing="0" cellpadding="2" width="90%">',
+                'row_start' => '<tr>',
+                'body'      => '<td align="left" valign="top" width="50%">
+                                    <b><!--{if:required}--><span style="color: red;">{title}</span><!--{else:required}{title}{/if:required}--></b><br>
+                                    <!--{if:descr}-->{descr}<!--{/if:descr}--><br>
+                                    <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                    <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                    {input}
+                                    <!--{if:sub_forms}--><p>{sub_forms}<!--{/if:sub_forms}-->
+                                ',
+                'col_empty' => '<td>&nbsp;</td>',
+                'row_end'   => '</tr>',
+                'end'       => '</table><p>',
+                'sub_form'  => '{sub_form}<br>'
+                ),
+
+    '3 Column Table' => array
+                (
+                'types'     => ' 1 2 3 4 5 6 20 21 24 25 ',
+                'short_name' => '3 Column',
+                'cols'      => 3,
+                'start'     => '<table border="0" cellspacing="0" cellpadding="2" width="90%">',
+                'row_start' => '<tr>',
+                'body'      => '<td align="left" valign="top" width="33%">
+                                    <b><!--{if:required}--><span style="color: red;">{title}</span><!--{else:required}{title}{/if:required}--></b><br>
+                                    <!--{if:descr}-->{descr}<!--{/if:descr}--><br>
+                                    <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                    <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                    {input}
+                                    <!--{if:sub_forms}--><p>{sub_forms}<!--{/if:sub_forms}-->
+                                ',
+                'col_empty' => '<td>&nbsp;</td>',
+                'row_end'   => '</tr>',
+                'end'       => '</table><p>',
+                'sub_form'  => '{sub_form}<br>'
+                ),
+
+    '4 Column Table' => array
+                (
+                'types'     => ' 1 2 3 4 5 6 7 20 21 24 25 ',
+                'short_name' => '4 Column',
+                'cols'      => 4,
+                'start'     => '<table border="0" cellspacing="0" cellpadding="2" width="90%">',
+                'row_start' => '<tr>',
+                'body'      => '<td align="left" valign="top" width="25%">
+                                    <b><!--{if:required}--><span style="color: red;">{title}</span><!--{else:required}{title}{/if:required}--></b><br>
+                                    <!--{if:descr}-->{descr}<!--{/if:descr}--><br>
+                                    <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                    <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                    {input}
+                                    <!--{if:sub_forms}--><p>{sub_forms}<!--{/if:sub_forms}-->
+                                ',
+                'col_empty' => '<td>&nbsp;</td>',
+                'row_end'   => '</tr>',
+                'end'       => '</table><p>',
+                'sub_form'  => '{sub_form}<br>'
+                ),
+
+    '5 Column Table' => array
+                (
+                'types'     => ' 1 2 3 4 5 6 7 20 21 24 25',
+                'short_name' => '5 Column',
+                'cols'      => 5,
+                'start'     => '<table border="0" cellspacing="0" cellpadding="2" width="90%">',
+                'row_start' => '<tr>',
+                'body'      => '<td align="left" valign="top" width="20%">
+                                    <b><!--{if:required}--><span style="color: red;">{title}</span><!--{else:required}{title}{/if:required}--></b><br>
+                                    <!--{if:descr}-->{descr}<!--{/if:descr}--><br>
+                                    <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                    <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                    {input}
+                                    <!--{if:sub_forms}--><p>{sub_forms}<!--{/if:sub_forms}-->
+                                ',
+                'col_empty' => '<td>&nbsp;</td>',
+                'row_end'   => '</tr>',
+                'end'       => '</table><p>',
+                'sub_form'  => '{sub_form}<br>'
+                ),
+
+    'Big Title' =>  array
+                (
+                'types'     => ' 20 ',
+                'short_name' => 'Big Title',
+                'cols'      => 1,
+                'start'     => '',
+                'row_start' => '',
+                'body'      => '<font size="5">{title}</font><br><hr>',
+                'col_empty' =>'',
+                'row_end'   => '',
+                'end'       => '',
+                'sub_form'  => ''
+                ),
+
+    'Sub Title' =>  array
+                (
+                'types'     => ' 20 ',
+                'short_name' => 'Sub-Title',
+                'cols'      => 1,
+                'start'     => '',
+                'row_start' => '',
+                'body'      => '<p><font size="4">{title}</font><br>',
+                'col_empty' =>'',
+                'row_end'   => '',
+                'end'       => '',
+                'sub_form'  => ''
+                ),
+
+    'Full Width Rule' =>    array
+                (
+                'types'     => ' 22 ',
+                'short_name' => 'Wide Rule',
+                'cols'      => 1,
+                'start'     => '',
+                'row_start' => '',
+                'body'      => '<br><hr width="100%"><br>',
+                'col_empty' =>'',
+                'row_end'   => '',
+                'end'       => '',
+                'sub_form'  => ''
+                ),
+
+    'Half Width Rule' =>    array
+                (
+                'types'     => ' 22 ',
+                'short_name' => 'Short Rule',
+                'cols'      => 1,
+                'start'     => '',
+                'row_start' => '',
+                'body'      => '<br><hr width="50%"><br>',
+                'col_empty' =>'',
+                'row_end'   => '',
+                'end'       => '',
+                'sub_form'  => ''
+                )
+    );
+
+$si_states_array = $states_US;
+
+$si_countries_array = array
+    (
+        // Out of sequence for convenience
+    'US' => 'United States',
+    'CA' => 'Canada',
+
+    "AF" => "Afghanistan",
+    "AX" => "Land Islands",
+    "AL" => "Albania",
+    "DZ" => "Algeria",
+    "AS" => "American Samoa",
+    "AD" => "Andorra",
+    "AO" => "Angola",
+    "AI" => "Anguilla",
+    "AQ" => "Antarctica",
+    "AG" => "Antigua and Barbuda",
+    "AR" => "Argentina",
+    "AM" => "Armenia",
+    "AW" => "Aruba",
+    "AU" => "Australia",
+    "AT" => "Austria",
+    "AZ" => "Azerbaijan",
+    "BS" => "Bahamas",
+    "BH" => "Bahrain",
+    "BD" => "Bangladesh",
+    "BB" => "Barbados",
+    "BY" => "Belarus",
+    "BE" => "Belgium",
+    "BZ" => "Belize",
+    "BJ" => "Benin",
+    "BM" => "Bermuda",
+    "BT" => "Bhutan",
+    "BO" => "Bolivia",
+    "BA" => "Bosnia and Herzegovina",
+    "BW" => "Botswana",
+    "BV" => "Bouvet Island",
+    "BR" => "Brazil",
+    "IO" => "British Indian Ocean Territory",
+    "BN" => "Brunei Darussalam",
+    "BG" => "Bulgaria",
+    "BF" => "Burkina Faso",
+    "BI" => "Burundi",
+    "KH" => "Cambodia",
+    "CM" => "Cameroon",
+    "CA" => "Canada",
+    "CV" => "Cape Verde",
+    "KY" => "Cayman Islands",
+    "CF" => "Central African Republic",
+    "TD" => "Chad",
+    "CL" => "Chile",
+    "CN" => "China",
+    "CX" => "Christmas Island",
+    "CC" => "Cocos (Keeling) Islands",
+    "CO" => "Colombia",
+    "KM" => "Comoros",
+    "CG" => "Congo",
+    "CD" => "Congo&#44; the Democratic Rep&#46; of",
+    "CK" => "Cook Islands",
+    "CR" => "Costa Rica",
+    "CI" => "Cote D'Ivoire",
+    "HR" => "Croatia",
+    "CU" => "Cuba",
+    "CY" => "Cyprus",
+    "CZ" => "Czech Republic",
+    "DK" => "Denmark",
+    "DJ" => "Djibouti",
+    "DM" => "Dominica",
+    "DO" => "Dominican Republic",
+    "EC" => "Ecuador",
+    "EG" => "Egypt",
+    "SV" => "El Salvador",
+    "GQ" => "Equatorial Guinea",
+    "ER" => "Eritrea",
+    "EE" => "Estonia",
+    "ET" => "Ethiopia",
+    "FK" => "Falkland Islands (Malvinas)",
+    "FO" => "Faroe Islands",
+    "FJ" => "Fiji",
+    "FI" => "Finland",
+    "FR" => "France",
+    "GF" => "French Guiana",
+    "PF" => "French Polynesia",
+    "TF" => "French Southern Territories",
+    "GA" => "Gabon",
+    "GM" => "Gambia",
+    "GE" => "Georgia",
+    "DE" => "Germany",
+    "GH" => "Ghana",
+    "GI" => "Gibraltar",
+    "GR" => "Greece",
+    "GL" => "Greenland",
+    "GD" => "Grenada",
+    "GP" => "Guadeloupe",
+    "GU" => "Guam",
+    "GT" => "Guatemala",
+    "GN" => "Guinea",
+    "GW" => "Guinea-Bissau",
+    "GY" => "Guyana",
+    "HT" => "Haiti",
+    "HM" => "Heard Island&#44; McDonald Islands",
+    "VA" => "Holy see (Vatican City State)",
+    "HN" => "Honduras",
+    "HK" => "Hong Kong",
+    "HU" => "Hungary",
+    "IS" => "Iceland",
+    "IN" => "India",
+    "ID" => "Indonesia",
+    "IR" => "Iran&#44; Islamic Republic of",
+    "IQ" => "Iraq",
+    "IE" => "Ireland",
+    "IL" => "Israel",
+    "IT" => "Italy",
+    "JM" => "Jamaica",
+    "JP" => "Japan",
+    "JO" => "Jordan",
+    "KZ" => "Kazakhstan",
+    "KE" => "Kenya",
+    "KI" => "Kiribati",
+    "KP" => "Korea&#44; Democratic People's Rep&#46; of",
+    "KR" => "Korea&#44; Republic of",
+    "KW" => "Kuwait",
+    "KG" => "Kyrgyzstan",
+    "LA" => "Lao People's Democratic Republic",
+    "LV" => "Latvia",
+    "LB" => "Lebanon",
+    "LS" => "Lesotho",
+    "LR" => "Liberia",
+    "LY" => "Libyan Arab Jamahiriya",
+    "LI" => "Liechtenstein",
+    "LT" => "Lithuania",
+    "LU" => "Luxembourg",
+    "MO" => "Macao",
+    "MK" => "Macedonia&#44; the Former Yugoslav Rep&#46;",
+    "MG" => "Madagascar",
+    "MW" => "Malawi",
+    "MY" => "Malaysia",
+    "MV" => "Maldives",
+    "ML" => "Mali",
+    "MT" => "Malta",
+    "MH" => "Marshall Islands",
+    "MQ" => "Martinique",
+    "MR" => "Mauritania",
+    "MU" => "Mauritius",
+    "YT" => "Mayotte",
+    "MX" => "Mexico",
+    "FM" => "Micronesia&#44; Federated States of",
+    "MD" => "Moldova&#44; Republic of",
+    "MC" => "Monaco",
+    "MN" => "Mongolia",
+    "MS" => "Montserrat",
+    "MA" => "Morocco",
+    "MZ" => "Mozambique",
+    "MM" => "Myanmar",
+    "NA" => "Namibia",
+    "NR" => "Nauru",
+    "NP" => "Nepal",
+    "NL" => "Netherlands",
+    "AN" => "Netherlands Antilles",
+    "NC" => "New Caledonia",
+    "NZ" => "New Zealand",
+    "NI" => "Nicaragua",
+    "NE" => "Niger",
+    "NG" => "Nigeria",
+    "NU" => "Niue",
+    "NF" => "Norfolk Island",
+    "MP" => "Northern Mariana Islands",
+    "NO" => "Norway",
+    "OM" => "Oman",
+    "PK" => "Pakistan",
+    "PW" => "Palau",
+    "PS" => "Palestinian Territory&#44; Occupied",
+    "PA" => "Panama",
+    "PG" => "Papua New Guinea",
+    "PY" => "Paraguay",
+    "PE" => "Peru",
+    "PH" => "Philippines",
+    "PN" => "Pitcairn",
+    "PL" => "Poland",
+    "PT" => "Portugal",
+    "PR" => "Puerto Rico",
+    "QA" => "Qatar",
+    "RE" => "Reunion",
+    "RO" => "Romania",
+    "RU" => "Russian Federation",
+    "RW" => "Rwanda",
+    "SH" => "Saint Helena",
+    "KN" => "Saint Kitts and Nevis",
+    "LC" => "Saint Lucia",
+    "PM" => "Saint Pierre and Miquelon",
+    "VC" => "Saint Vincent and the Grenadines",
+    "WS" => "Samoa",
+    "SM" => "San Marino",
+    "ST" => "Sao Tome and Principe",
+    "SA" => "Saudi Arabia",
+    "SN" => "Senegal",
+    "CS" => "Serbia and Montenegro",
+    "SC" => "Seychelles",
+    "SL" => "Sierra Leone",
+    "SG" => "Singapore",
+    "SK" => "Slovakia",
+    "SI" => "Slovenia",
+    "SB" => "Solomon Islands",
+    "SO" => "Somalia",
+    "ZA" => "South Africa",
+    "GS" => "South Georgia&#44; South Sandwich Islands",
+    "ES" => "Spain",
+    "LK" => "Sri Lanka",
+    "SD" => "Sudan",
+    "SR" => "Suriname",
+    "SJ" => "Svalbard and Jan Mayen",
+    "SZ" => "Swaziland",
+    "SE" => "Sweden",
+    "CH" => "Switzerland",
+    "SY" => "Syrian Arab Republic",
+    "TW" => "Taiwan&#44; Province of China",
+    "TJ" => "Tajikistan",
+    "TZ" => "Tanzania&#44; United Republic of",
+    "TH" => "Thailand",
+    "TL" => "Timor-Leste",
+    "TG" => "Togo",
+    "TK" => "Tokelau",
+    "TO" => "Tonga",
+    "TT" => "Trinidad and Tobago",
+    "TN" => "Tunisia",
+    "TR" => "Turkey",
+    "TM" => "Turkmenistan",
+    "TC" => "Turks and Caicos Islands",
+    "TV" => "Tuvalu",
+    "UG" => "Uganda",
+    "UA" => "Ukraine",
+    "AE" => "United Arab Emirates",
+    "GB" => "United Kingdom",
+    "US" => "United States",
+    "UM" => "United States minor outlying islands",
+    "UY" => "Uruguay",
+    "UZ" => "Uzbekistan",
+    "VU" => "Vanuatu",
+    "VE" => "Venezuela",
+    "VN" => "Viet Nam",
+    "VG" => "Virgin Islands&#44; British",
+    "VI" => "Virgin Islands&#44; U&#46;S&#46;",
+    "WF" => "Wallis and Futuna",
+    "EH" => "Western Sahara",
+    "YE" => "Yemen",
+    "ZM" => "Zambia",
+    "ZW" => "Zimbabwe"
+    );
+
+
+$si_month_array = array
+    (
+    1   => "January",
+    2   => "February",
+    3   => "March",
+    4   => "April",
+    5   => "May",
+    6   => "June",
+    7   => "July",
+    8   => "August",
+    9   => "September",
+    10  => "October",
+    11  => "November",
+    12  => "December"
+    );
+?>
diff --git a/registrations/siteinfo.php b/registrations/siteinfo.php
new file mode 100644 (file)
index 0000000..53b9e51
--- /dev/null
@@ -0,0 +1,1537 @@
+<?php
+
+/********************************************************************************
+ *
+ *     FILE: siteinfo.inc - Portable site information
+ *
+ *     Copyright (C) 2002 - Gaslight Media - All Rights Reserved
+ *
+ ********************************************************************************/
+
+if( !defined("SITEINFO") )
+{
+
+define( "SITEINFO",                    TRUE );                 // Indicate that this file has been referenced
+
+/* These are now defined in the Dynamic section below
+define( "SI_DEBUG",                    0 );                    // Debug Level : 0=Off, 1, 2, 3, ... more debug info
+define( "SI_DEBUG_VIEW",       TRUE );                 // Display pop-up summary of data passed to parse_view()
+define( "GLMPDF_DEBUG",        FALSE );                // Overlays output forms with calibration grid
+*/
+
+/********************************************************************************
+ *
+ *     DO NOT EDIT THIS SECTION
+ *
+ ********************************************************************************/
+
+       // Find where this file is located
+//error_reporting(E_ALL);
+$si_base_path                          = dirname( __FILE__ );                  // Get Path where siteinfo resides
+$si_calling_script_name                = basename( $SCRIPT_NAME );             // Get name of calling script
+
+$si_called_from_dir            = substr( dirname($_SERVER["SCRIPT_FILENAME"]), strlen($si_base_path) );
+
+if( ($x = strlen($si_called_from_dir)) > 0 )
+       $si_base_url    = $HTTP_HOST.substr( dirname($SCRIPT_NAME), 0, -strlen($si_called_from_dir) );
+    else
+       {
+        $si_script_name_dir = dirname($SCRIPT_NAME);
+        if( $si_script_name_dir == "/" )
+                $si_script_name_dir = "";
+        $si_base_url       = $HTTP_HOST.$si_script_name_dir;
+       }
+
+
+$si_base_secure_url = "https://".$si_base_url;
+$si_base_insecure_url = "http://".$si_base_url;
+
+
+
+
+if( $HTTPS == "on" )
+       $si_base_url = "https://".$si_base_url;
+    else
+       $si_base_url = "http://".$si_base_url;
+//echo "si_base_url = $si_base_url<br>";
+
+$si_base_url = get_permalink();
+
+/********************************************************************************
+ *
+ *     Dynamic Configuration - Parameters that DO change based on location
+ *
+ ********************************************************************************/
+
+switch ($_ENV['GLM_HOST_ID']) {
+
+case "DEVELOPMENT":
+    $si_base_secure_url                                        = $si_base_url;
+    define( "SI_DB_HOST",                                      "devsys.gaslightmedia.com" );
+    define( "SI_DB_HOST2",                                     "ds1.gaslightmedia.com" );
+    define( "SI_DB_NAME",                                      "mtgf" );
+    define( "SI_DB_NAME2",                             "zip" );
+    define( "SI_CUSTOMER_EMAIL",                       "ove@gaslightmedia.com" );
+    define( "SI_CUSTOMER_INTERNAL_EMAIL",      "jodie@gaslightmedia.com" );
+    define( "SI_DEBUG",                                                1 );
+    define( "SI_DEBUG_VIEW",                           FALSE );
+    define( "SI_DEBUG_MAIL",                           FALSE );
+    define( 'SI_PATH_TO_GRAPHICS_TOOLS',       '/usr/bin' );
+    $BASE_SECURE_URL = $si_base_url;
+    define("CONN_STR","host=devsys dbname=mtgf");
+    define("OWNER_EMAIL", "steve@gaslightmedia.com");          // site owner's email address
+    define("REPLY_TO", "info@gaslightmedia.com");                 // the reply-to field for email's
+    define( 'SI_AUTH_TEST',                                    'TRUE' );// Must be "FALSE" for production! Otherwise "TRUE" or "LOCAL_TEST" (don't transmit)
+    break;
+
+case "PRODUCTION":
+    $si_base_secure_url                                        = $si_base_url;
+    define( "SI_DB_HOST",                                      "ds1.gaslightmedia.com" );
+    define( "SI_DB_NAME",                                      "mtgf" );
+    define( "SI_CUSTOMER_EMAIL",                       "mtfturf@comcast.net, jodie@gaslightmedia.com" );
+    define( "SI_CUSTOMER_INTERNAL_EMAIL",      "mtfturf@comcast.net, jodie@gaslightmedia.com" );
+    define( "SI_DEBUG",                                                0 );
+    define( "SI_DEBUG_VIEW",                           FALSE );
+    define( "SI_DEBUG_MAIL",                           false );
+    define( 'SI_PATH_TO_GRAPHICS_TOOLS',       '/usr/X11R6/bin' );
+    $BASE_SECURE_URL = $si_base_url;
+    define("CONN_STR","host=ds1 dbname=mtgf");
+    define("OWNER_EMAIL", "mtfturf@comcast.net, jodie@gaslightmedia.com");              // site owner's email address
+    define("REPLY_TO", "info@gaslightmedia.com");                 // the reply-to field for email's
+    define( 'SI_AUTH_TEST',                                    'FALSE' );// Must be "FALSE" for production! Otherwise "TRUE" or "LOCAL_TEST" (don't transmit)
+    break;
+
+default:       // There should be no need for any settings here
+    die('Should not reach this');
+    break;
+}
+
+/********************************************************************************
+ *
+ *     DO NOT EDIT THIS SECTION
+ *
+ ********************************************************************************/
+
+define( "SI_SERVER",                                           $HTTP_HOST );                                           // Host name of server
+define( "SI_BASE_PATH",                                                $si_base_path );                                        // Path to root of site
+define( "SI_CALLED_FROM_DIR",                          $si_called_from_dir );                          // Directory where current executing file exists
+define( "SI_BASE_URL",                                         $si_base_url );                                         // URL to root of Web site
+define( "SI_BASE_SECURE_URL",                          $si_base_secure_url );                          // URL to root of Secure Web site
+define( "SI_BASE_INSECURE_URL",                                $si_base_insecure_url );                        // URL to root of Insecure Web site
+define( "SI_GLM_APPS",                                         $si_base_url."/glm_apps" );                     // GLM misc application modules URL
+define( "SI_GLM_SECURE_APPS",                          $si_base_secure_url."/glm_apps" );      // GLM misc application modules URL - Secure
+define( "SI_THIS_SCRIPT",                                      SI_BASE_URL.SI_CALLED_FROM_DIR.'/'.$si_calling_script_name );                   // The name of the calling script
+
+define( "SI_DB_USER",                                          "nobody" );
+define( "SI_DB_TYPE",                                          "postgres" );
+define( "SI_CONN_STR",                                                 "host='".SI_DB_HOST."' dbname='".SI_DB_NAME."' user='".SI_DB_USER."'" );
+define( "SI_CONN_STR2",                                        "host='".SI_DB_HOST2."' dbname='".SI_DB_NAME2."' user='".SI_DB_USER."'" );
+define( "SI_DB_DATE_STYLE",                                    "SQL" );
+               // ISO          - use ISO 8601-style dates and times,                                   "1997-12-17 07:37:16-08"
+               // SQL          - use Oracle/Ingres-style dates and times,                              "12/17/1997 07:37:16.00 PST"
+               // Postgres     - use traditional Postgres format,                                      "Wed Dec 17 07:37:16 1997 PST"
+               // European     - use dd/mm/yyyy for numeric date representations., "17/12/1997 15:37:16.00 MET"
+               // US           - use mm/dd/yyyy for numeric date representations.,     "12/17/1997 07:37:16.00 PST"
+               // German       - use dd.mm.yyyy for numeric date representations.,     "17.12.1997 07:37:16.00 PST"
+define( 'SI_DB_STATIC',                                                TRUE );                         // If true database functions don't automatically close a connection and will re-use if possible
+define( "SI_DB_SET_DATE_STYLE_STRING",         "SET DATESTYLE TO '".SI_DB_DATE_STYLE."';\n" );
+
+//define( 'SI_PATH_TO_GRAPHICS_TOOLS',         '/usr/bin' );
+define( "SI_IMAGE_DIR",                                                "images" );
+define( "SI_BASE_IMAGE_URL",                           SI_BASE_URL."/".SI_IMAGE_DIR );
+define( "SI_BASE_IMAGE_PATH",                          SI_BASE_PATH."/".SI_IMAGE_DIR );
+
+define( "SI_IMG_ORIGINAL_URL",                                 SI_BASE_IMAGE_URL."/original" );
+define( "SI_IMG_RESIZED_URL",                          SI_BASE_IMAGE_URL."/resized" );
+define( "SI_IMG_MIDSIZED_URL",                                 SI_BASE_IMAGE_URL."/midsized" );
+define( "SI_IMG_THUMB_URL",                            SI_BASE_IMAGE_URL."/thumb" );
+
+define( "SI_IMG_ORIGINAL_PATH",                        SI_BASE_IMAGE_PATH."/original" );
+define( "SI_IMG_RESIZED_PATH",                                 SI_BASE_IMAGE_PATH."/resized" );
+define( "SI_IMG_MIDSIZED_PATH",                        SI_BASE_IMAGE_PATH."/midsized" );
+define( "SI_IMG_THUMB_PATH",                           SI_BASE_IMAGE_PATH."/thumb" );
+define( "SI_POSTCARD_URL",                                     SI_BASE_URL."/index.phtml" );
+
+define( "SI_BASE_FILE_URL",                                    SI_BASE_URL."/files" );
+define( "SI_BASE_FILE_PATH",                           SI_BASE_PATH."/files" );
+
+define( "SI_VIEW_BASE_PATH",                           "/Views" );
+
+
+$si_today = date( 'n/d/Y' );                           // Today's date
+$si_timestamp = time();                                                // Current Timestamp
+
+define( "SI_COPYRIGHT_YEARS",                          "2002-".date("Y") );                            // Years for copyright statement in footer
+
+/********************************************************************************
+ *
+ *     Static Configuration - Parameters that DON'T change based on location
+ *
+ ********************************************************************************/
+
+//     ------------------------------
+//     General Customer Configuration
+//     ------------------------------
+
+       // Information about the customer
+
+define( 'SI_CUSTOMER_NAME',                            'Michigan Turfgrass Foundation' );
+define( 'SI_CUSTOMER_LONG_NAME',                       'Michigan Turfgrass Foundation' );
+define( 'SI_CUSTOMER_PHONE',                           '517-321-1660' );
+define( 'SI_CUSTOMER_FAX',                                     '' );
+define( 'SI_CUSTOMER_TOLL_FREE',                       '' );
+define( 'SI_CUSTOMER_ADDRESS',                         'PO Box 80071' );
+define( 'SI_CUSTOMER_CITY',                                    'Lansing' );
+define( 'SI_CUSTOMER_STATE',                           'MI' );
+define( 'SI_CUSTOMER_ZIP',                                     '48908' );
+define( 'SI_CUSTOMER_FROM_EMAIL',                      'mtfturf@msn.com' );
+define( 'SI_CUSTOMER_LETTER_CLOSING',          'Sincerely,' );
+
+       // Strings for TITLE tags
+
+define( "SI_CUSTOMER_META_KEYWORDS",                   // Meta Keywords for search engines
+"Product Quotes" );
+
+define( "SI_CUSTOMER_META_DESCR",                              // Meta description for search engines
+"Spectrus, Inc. Product quote system." );
+
+define( "SI_CUSTOMER_ASSETS",                          SI_BASE_URL."/assets" );
+
+define( "SI_CUST_LOGO",                                                "assets/logo.gif" );
+define( "SI_CUST_LOGO_MEDIUM",                         "assets/logo_medium.gif" );
+define( "SI_CUST_LOGO_SMALL",                          "assets/logo_small.gif" );
+
+define( "SI_CUST_LOGO_URL",                                    $si_base_url."/".SI_CUST_LOGO );
+define( "SI_CUST_LOGO_MEDIUM_URL",                     $si_base_url."/".SI_CUST_LOGO_MEDIUM );
+define( "SI_CUST_LOGO_SMALL_URL",                      $si_base_url."/".SI_CUST_LOGO_SMALL );
+
+//  -----------------------------------
+//  Configurations Specific for Toolbox
+//  -----------------------------------
+$PAGES['default'] = 'index';
+$PAGES[1] = 'index';
+define("SITENAME","Michigan Turfgrass Foundation");    // used for outputing name of site in admin area
+define("SITE_NAME",SITENAME);  // same as SITENAME
+define("DB_TYPE", "postgres");         // DB library only knows postgres (FUTURE EXPANSION)
+define("DB_ERROR_MSG", "an error has occured with the database!");     // default error message
+define("MULTIPLE_CAT",0);              // weather or not to use many to many relations
+define("CAT_LOCK",0);                  // If set to 1 or true will lock the categories
+define("ENTRIES_PER_PAGE",10); // default per page number
+define("HTML_HELP_CODE",1);    // this is being depreciated for general help guides
+define("PRODUCTION_MODE","ON"); // used in the email out for contact DB
+define("HTML_EMAIL","ON");     // turn ON for html emails
+define("ACTIVE_FLAG",1);               // turn on if bus_category table has active bool field
+define("DELUXE_TOOLBOX",1);            // used for the toolbox deluxe vrs.
+define("SEO_URL",1);                   // weather to use Search Engine Optimisezd url's requires .htaccess enabled
+define("HTMLAREA_TABLES",1);   // weather to load the table plugin or not
+define("HTMLAREA_CONTEXT_MENU",1);     // weather to load the context menu plugin or not
+define("HTMLAREA_CHARACTER_MAP",0);    // weather to load the context menu plugin or not
+define("HOME_PAGE_EVENTS",0);
+switch( $GLM_SERVER_ID )
+{
+
+       case "devsys.gaslightmedia.com":
+               ini_set("display_errors","1");
+               // Use the $BASE_URL for secure URL on Devsys
+               $BASE_SECURE_URL = $BASE_URL;
+               define("CONN_STR","host=devsys dbname=mtgf");
+               define("OWNER_EMAIL", "info@gaslightmedia.com");                // site owner's email address
+               define("REPLY_TO", "info@gaslightmedia.com");                   // the reply-to field for email's
+       break;
+
+       case "ws1.gaslightmedia.com":
+               ini_set("display_errors","0");
+               $BASE_SECURE_URL = "https://".$base_url;
+               define("CONN_STR","host=ds1 dbname=mtgf");
+               define("OWNER_EMAIL", "info@gaslightmedia.com");                 // site owner's email address
+               define("REPLY_TO", "info@gaslightmedia.com");                    // the reply-to field for email's
+       break;
+
+       default:        // There should be no need for any settings here
+                       $BASE_SECURE_URL = $BASE_URL;
+                       define("CONN_STR","dbname=mtgf user=postgres");
+                       define("OWNER_EMAIL", "info@gaslightmedia.com");                // site owner's email address
+                       define("REPLY_TO", "info@gaslightmedia.com");                   // the reply-to field for email's
+       break;
+
+}
+if( $_SERVER['HTTPS'] == "on" )
+{
+       define("BASE_URL", "http://www.michiganturfgrass.org/");                                        // url used for the root of site
+}
+else
+{
+       define("BASE_URL", $si_base_url."/");                                   // url used for the root of site
+}
+define("URL_BASE", BASE_URL."/");                                      // same as BASE_URL
+define("BASE_PATH", $si_base_url."/");                         // root directory path of site
+define("BASE", $si_base_path."/");                                             // same as BASE_PATH
+define("SI_INCLUDE",BASE.'includes/');
+define("RANDOM_IMAGE_DIR",BASE.'assets/rotating');
+if( $_SERVER['HTTPS'] == "on" )
+{
+       define("RANDOM_IMAGE_URL",'http://www.michiganturfgrass.org/assets/rotating');
+}
+else
+{
+       define("RANDOM_IMAGE_URL",URL_BASE.'assets/rotating');
+}
+define("GOOGLE",BASE.'google/');
+define("HELP_BASE", "help/");                                          // help guide base (depreciated)
+define("UP_BASE", BASE."uploads/");                                    // uploads directory path
+define("IMG_BASE", URL_BASE."images/");                                // the images url path
+define("POSTCARD_URL",URL."postcard.phtml");           // postcard url (used for postcard app)
+define("LOGO_IMG",URL_BASE."images/logoicon.gif");     // used in admin area as the path to image logo
+define("HELP_IMG",URL_BASE."images/help.gif");         // help image url (depriated)
+define("ORIGINAL_PATH", BASE."images/original/");      // path of original images
+define("RESIZED_PATH", BASE."images/resized/");                // path of first resized image
+define("MIDSIZED_PATH", BASE."images/midsized/");      // path of half sized of resized
+define("THUMB_PATH", BASE."images/thumb/");                    // path of thumbnail directory
+//include_once(BASE."classes/class_toolbox.inc");
+if( $_SERVER['HTTPS'] == "on" )
+{
+       define("ORIGINAL", $BASE_SECURE_URL."/images/original/");       // url of original images
+       define("RESIZED", $BASE_SECURE_URL."/images/resized/");         // url of resized
+       define("MIDSIZED", $BASE_SECURE_URL."/images/midsized/");       // url of midsized
+       define("THUMB", $BASE_SECURE_URL."/images/thumb/");                     // url of thumbnail
+}
+else
+{
+       define("ORIGINAL", URL_BASE."images/original/");        // uecho "INP = <PRE>$inp</PRE><P>";rl of original images
+       define("RESIZED", URL_BASE."images/resized/");          // url of resized
+       define("MIDSIZED", URL_BASE."images/midsized/");        // url of midsized
+       define("THUMB", URL_BASE."images/thumb/");                      // url of thumbnail
+}
+
+/** these are the image sizing defines USE THESE ONLY
+  only allowed string of 'WxH[<>]' [-quality Percentage]
+ */
+define("ITEM_RESIZED", "'287>'");              // used in convert call to resize images
+define("ITEM_MIDSIZED", "'220>'");
+define("ITEM_THUMB","'120>'");
+
+define("FOOTER_IMG", URL_BASE."images/logosmall.gif");
+define("FOOTER_URL", URL_BASE);
+define("STYLE","main.css");
+
+//     -----------------------------------
+//     Application Specific Configurations
+//     -----------------------------------
+
+       // Convention Registration specific parameters
+
+define( "SI_CUSTOMER_REG_TITLE",                       "Michigan Turfgrass Foundation - Event Registration" );
+
+define( "SI_REG_INTRO",                                                FALSE );                // Conventions Intro page displayed
+define( "SI_REG_SELECT",                                       "List" );               // Method of selecting Conventions, "Pick" - Picklist, "List" - Detailed list
+
+       // Payment Processing Methods
+
+define( "SI_REG_PROC_METHOD_MERCHANT",         1 );                    // Cards processed and confirmed by merchant
+define( "SI_REG_PROC_METHOD_AUTHORIZE",                2 );                    // Credit Cards processed by Authorize.Net
+
+define( "SI_REG_PROC_METHOD",                          SI_REG_PROC_METHOD_AUTHORIZE );                 // Selected payment method
+
+       // Status Codes
+
+define( "SI_REG_STATUS_UNPAID",                                1 );                    //              Unknown or unpaid
+define( "SI_REG_STATUS_CC_PEND",                       2 );                    //              Paying by Credit Card - Card not run yet
+define( "SI_REG_STATUS_CC_PAID",                       3 );                    //              Paid by Credit Card
+define( "SI_REG_STATUS_CC_DECL",                       4 );                    //              Credit Card Declined
+define( "SI_REG_STATUS_CHECK_PEND",                    5 );                    //              Pending Check
+define( "SI_REG_STATUS_CHECK_PAID",                    6 );                    //              Paid by Check
+define( "SI_REG_STATUS_COMP",                          7 );                    //              Comp or no payment
+define( "SI_REG_STATUS_FAILED",                                98 );                   //              Failed to store all of registration data or failed trying to process CC, process not completed
+define( "SI_REG_STATUS_CANCELED",                      99 );                   //              Canceled
+
+
+$si_reg_status_types = array
+       (
+       SI_REG_STATUS_UNPAID                    => 'Not Paid',
+       SI_REG_STATUS_CC_PEND                   => 'Credit Card Pending',
+       SI_REG_STATUS_CC_PAID                   => 'Paid by Credit Card',
+       SI_REG_STATUS_CC_DECL                   => 'Credit Card Declined',
+       SI_REG_STATUS_CHECK_PEND                => 'Check Pending',
+       SI_REG_STATUS_CHECK_PAID                => 'Paid by Check',
+       SI_REG_STATUS_COMP                              => 'Complimentary',
+       SI_REG_STATUS_FAILED                    => 'Submission Failed',
+       SI_REG_STATUS_CANCELED                  => 'Canceled',
+       );
+$si_reg_status_list = $s = "";
+while( list($k, $v) = each($si_reg_status_types) )
+       {
+       $si_reg_status_list .= "$s$k^$v";
+       $s = "~";
+       }
+
+$si_reg_field_types = array
+       (
+       1       => 'Checkbox',
+       2       => 'Number',
+       3       => 'Text',
+       4       => 'Text Box',
+       5       => 'Picklist',
+       6       => 'Radio Buttons',
+       20      => 'Section Title',
+       21      => 'Misc. Text'
+       );
+
+
+$si_cc_verify = array                          // Values are regex test strings for card type
+       ( // *** Don't forget to correct the commas ***
+       "Visa"                          => "^4.{15}$|^4.{12}$",
+       "MasterCard"            => "^5[1-5].{14}$",
+       "American Express"      => "^3[47].{13}$",
+       "Discover"                      => "^6011.{12}$",
+       "Diner's Club"          => "^30[0-5].{11}$|^3[68].{12}$"
+       );
+
+$si_cc_verify = $si_cc_verify; // Backward compatibility
+
+define( "SI_CC_ACCEPTS",                                       7 );            // Cards the CVB accepts - Carefull with this one - It's a bitmap of the cars above
+
+       // $si_credit_cards string and $si_cc_array array are built from above
+       // Select and deselect cards used from above array.
+
+$si_credit_cards = $s = "";
+$si_cc_array = array();
+$i = 0;
+while( list($k, $v) = each($si_cc_verify) )
+       {
+       $si_credit_cards .= "$s$k";
+       array_push( $si_cc_array, $k );
+       $s = "~";
+       }
+
+$si_pay_by_types =
+       "
+       1^Credit Card~
+       2^Check~
+       3^Direct to DMCVB
+       ";
+
+$si_conf_methods =
+       "
+       1^US Mail~
+       2^E-Mail
+       ";
+
+
+//  -----------------------------------------
+//     Authorize.Net Configuration
+//     -----------------------------------------
+
+define( 'AUTH_CURL',                           '/usr/bin/curl' );                                                                                      // Curl executable
+define( 'AUTH_URL',                                    'https://secure.authorize.net/gateway/transact.dll' );          // Authorization URL
+//define( 'AUTH_URL',                          'http://ws6.gaslightmedia.com/AuthorizeNetRelay/glmAuthNetRelay/AuthNetRelayProduction.php' );          // Authorization URL
+// define( 'SI_AUTH_TEST',                             'LOCAL_TEST' );                                                                                 // Must be "FALSE" for production! Otherwise "TRUE" or "LOCAL_TEST" (don't transmit)
+define( 'SI_AUTH_LOGIN',                       'mtfresearch1' );                                                                                               // Authorize.Net Customer Login                     -- UNIQE FOR EACH CUSTOMER --
+define( 'SI_AUTH_TRAN_KEY',                    'X5EA4C6kN9X9P434' );                                                                                           // Authorize.Net Customer Transaction Key       -- UNIQE FOR EACH CUSTOMER --
+define( 'SI_AUTH_SEND_CONF',           'TRUE' );                                                                                                       // TRUE to have customer's receive E-Mail confirmation
+define( 'SI_AUTH_MERCHANT_EMAIL',      'FALSE' );                                                                                                      // TRUE to have merchant receive E-Mail convirmation of customer charges
+define( 'SI_AUTH_SECRET',                      '' );                                                                                                           // MD5 Hash secret used by Authorize.Net to generate MD5 response verification data
+                                                                                                                                                                                               //  If empty - don't check MD5 response
+
+//     -------------------------------------------
+//     Contact Database & Newsletter Configuration
+//     -------------------------------------------
+define( "CDB_DEFAULT_REPORT_FIELDS",   "lname, fname, city, state, email" );   // Default output fields for queries
+define( "CDB_LIST_ROWS",                               20 );                                                                   // Default number of query results to show per page
+define( "CDB_MAX_MAILOUT_COUNT",               9999999 );                                                              // Maximum number of E-Mail destinations we can send to
+define( "CDB_EMAIL_FIELD",                             'email' );                                                              // Name of field that contains contact's E-Mail address
+define( "CDB_EMAIL_OK_FIELD",                  'email_ok' );                                                   // Name of boolian E-Mail OK field - used to filter for mailout
+define( "CDB_HTML_EMAIL",                              TRUE );                                                                 // Send Newsletter as HTML E-Mail
+define( "CDB_NOTIFY_EMAIL",                            SI_CUSTOMER_INTERNAL_EMAIL );                   // Address that receives notification of distribution
+define( "CDB_FROM_EMAIL",                              "mtfturf@comcast.net" );                        // E-Mail Address that newsletters appear to come from
+define( "CDB_REPLY_EMAIL",                             "mtfturf@comcast.net" );                                // Reply address for newsletters
+define( "CDB_PRODUCTION_MODE",                 TRUE );                                                                 // SPAMerizer Production Mode (TRUE to actually send)
+define( "CDB_TOP_IMAGE_1",                             SI_CUSTOMER_ASSETS."/news_masthead.gif" );                              // Image displayed at top of newsletter
+define( "CDB_TOP_IMAGE_2",                             SI_CUSTOMER_ASSETS."/newsletter_header2.jpg" );                         // Image displayed at top of newsletter
+define( "CDB_TOP_IMAGE_3",                             SI_CUSTOMER_ASSETS."/newsletter_header3.jpg" );                         // Image displayed at top of newsletter
+//$cdb_c_type = parse_ini_file( BASE.'cdb-c-type.ini' );
+$cdb_c_type_string_array[] = '^~';
+//foreach( $cdb_c_type as $cdb_c_type_key => $cdb_c_type_val )
+//{
+//     $cdb_c_type_string_array[] = strtoupper($cdb_c_type_key).'^'.htmlspecialchars($cdb_c_type_val);
+//}
+$cdb_c_type_string = implode( "~",$cdb_c_type_string_array );
+$cdb_fields = array
+       (
+       'fname'                 => 'fname,                      text.40,                        First Name,                     TRUE,           fname,                  naeudvlqr',
+       'lname'                 => 'lname,                      text.40,                        Last Name,                      TRUE,           lname,                  naeudvlqr',
+       'company'               => 'company,            text.40,                        Company Name,           FALSE,          company,                naeudvlqr',
+       'password'              => 'password,           text.40,                        Password,                       FALSE,          password,               naeudvqr',
+       'addr1'                 => 'addr1,                      text.40,                        Address Line 1,         FALSE,          addr1,                  naeuvqr',
+       'addr2'                 => 'addr2,                      text.40,                        Address Line 2,         FALSE,          addr2,                  naeuvqr',
+       'city'                  => 'city,                       text.40,                        City,                           FALSE,          city,                   naeudvlqr',
+       'state'                 => 'state,                      state..blank,           State,                          FALSE,          state,                  naeudvlqr',
+       'country'               => 'country,            country..blank,         Country,                        FALSE,          country,                naeuvqr',
+       'zip'                   => 'zip,                        text.15,                        ZIP,                            FALSE,          zip,                    naeuvlqr',
+       'phone'                 => 'phone,                      text.15,                        Home Phone,                     FALSE,          phone,                  naeuvqr',
+       'work_phone'    => 'work_phone,         text.15,                        Work Phone,                     FALSE,          work_phone,             naeviqr',
+       'fax'                   => 'fax,                        text.15,                        FAX,                            FALSE,          fax,                    naeuvqr',
+       'email'                 => 'email,                      text.40,                        E-Mail Address (username for forum),TRUE,email, naeuvqr',
+       //'email'                       => 'email,                      text.40,                        E-Mail Address (username for forum),TRUE,email, na',
+       'email_ok'              => 'email_ok,           checkbox,                       E-Mail OK,                      FALSE,          email_ok,               naeuvlqr',
+       'member'                => 'member,                     checkbox,                       Member?,                        FALSE,          member,                 naeuvlqr',
+       'active'                => 'active,                     checkbox,                       Active?,                        FALSE,          active,                 naeuvlqr',
+       'tag_group'             => 'tag_group,          list.^~C^Voting~A^Affiliates~Y^Student, Member Type,FALSE,tag_group,naeuvlqr',
+       'c_type'                => 'c_type,                     list.^~'.$cdb_c_type_string.'..multi, Company Type,FALSE,c_type,naeuvlqr',
+       'create_date'   => 'create_date,        date.365.365,           Creation Date,          FALSE,          create_date,    aeuvqr',
+       'create_date_n' => 'create_date,        date.365.365,           Creation Date,          SUPPLIED,       si_today,               n',
+       'lname_f'               => 'lname,                      text.any,                       Last Name,                      ,                       lname,                  f',
+       'fname_f'               => 'fname,                      text.any,                       First Name,                     ,                       fname,                  f',
+       'company_f'             => 'company,            text.any,                       Company Name,           ,                       company,                f',
+       'city_f'                => 'city,                       text.any,                       City,                           ,                       city,                   f',
+       'state_f'               => 'state,                      state,                          State,                          ,                       state,                  f',
+       'email_f'               => 'email,                      text.any,                       E-Mail Address,         ,                       email,                  f',
+       'email_ok_f'    => 'email_ok,           checkbox,                       OK to Send E-Mail,      ,                       email_ok,               f',
+       'member_f'              => 'member,                     checkbox,                       Member?,                        ,                       member,                 f',
+       'active_f'              => 'active,                     checkbox,                       Active?,                        ,                       active,                 f',
+       'tag_group_f'   => 'tag_group,          list.C^Voting~A^Affiliates~Y^Student,   Member Type,,tag_group,         f',
+       'c_type_f'      => 'c_type,             list.'.$cdb_c_type_string.',    Company Type,,c_type,           f',
+       'create_date_f' => 'create_date,        daterange,                      Creation Date,          ,                       create_date,    f'
+       );
+
+$cdb_source_codes =
+       "
+       Imported~
+       Entered~
+       Reservation~
+       Package~
+       Convention~
+       Contest
+       ";
+
+$cdb_and_or = array
+       (
+       0       => 'AND',
+       1       => 'OR'
+       );
+
+$tag_list = array(
+               'C' => 'Voting',
+               'A' => 'Affiliate',
+               'Y' => 'Student'
+               );
+
+$cdb_where_types = array
+       (
+       0       => 'is Equal To',
+       1       => 'is Less Than',
+       2       => 'is Greater Than',
+       3       => 'is Not Equal To',
+       4       => 'Starts With',
+       5       => 'Contains'
+       );
+
+$cdb_where_operators = array
+       (
+       0       => '=',
+       1       => '<',
+       2       => '>',
+       3       => '!=',
+       4       => 'LIKE',
+       5       => 'LIKE'
+       );
+
+       // Report output types
+
+define( "CDB_OUTPUT_TYPE_HTML",                0 );
+define( "CDB_OUTPUT_TYPE_CSV",         1 );
+define( "CDB_OUTPUT_TYPE_FIXED",       2 );
+define( "CDB_OUTPUT_TYPE_TABS",                3 );
+define( "CDB_OUTPUT_TYPE_COMMAS",      4 );
+define( "CDB_OUTPUT_TYPE_PIPES",       5 );
+define( "CDB_OUTPUT_TYPE_CUSTOM",      99 );
+
+$cdb_standard_types =
+       "
+       0^HTML~
+       1^CSV~
+       2^Fixed Length Records~
+       3^Tab Delimited Records~
+       4^Comma Delimited Records~
+       5^Pipe Delimited Records~
+       99^Custom
+       ";
+
+$cdb_field_types =
+       "
+       0^Normal~
+       1^Double Quoted~
+       2^Single Quoted~
+       99^Enclosed in Specified Chars
+       ";
+
+$cdb_field_delim =
+       "
+       0^No delimiter~
+       1^New Line~
+       2^Tab~
+       3^Comma~
+       4^Vertical Bar~
+       99^Specified Chars
+       ";
+
+$cdb_record_types =
+       "
+       0^New Line~
+       1^Vertical Bar~
+       2^Fixed Length Records~
+       99^Specified  Chars
+       ";
+
+$cdb_file_types =
+       "
+       0^PC Compatible~
+       1^Unix Standard~
+       3^Mac Standard
+       ";
+
+$cdb_destinations =
+       "
+       0^Screen~
+       1^File~
+       2^E-Mail
+       ";
+
+
+//     ----------
+//     MagicForms
+//     ----------
+
+/*     field types
+               1       Checkbox
+               2       Number
+               3       Text
+               4       Text Box
+               5       Picklist
+               6       Radio Buttons
+               7       File Upload
+               20      Section Title
+               21      Misc. Text
+               22      Horizontal Line
+               23      Blank Line
+               24      Display Image
+               25      Download File
+               31      Calculated Field
+ */
+
+define( 'MF_TABLE',                                            'magicform' );          // Table name for MagicForm fields
+define( 'MF_DATA_TABLE',                               'mf_data' );                    // Table name for MagicForm fields
+define( 'MF_SUBFORMS',                                 true );                         // Enable/disable Sub-Forms
+
+       // Field Format Definitions
+       // Note that {chars} gets replaced with # of characters or # of digits to the left of the decimal point and {prec} gets replaced with # of digits to the right of decimal point
+
+$mf_formats = array
+       (
+       'Default Format'                =>      array
+               (
+               'short_name'    => 'Default Format',                            // Short name for this validation type
+               'types'                 => ' 2 3 ',                                     // Field types this validation type applies to
+               'format'                => '%s',                                                // Output format for this field - printf() style format string
+               'regex'                 => '',                                          // Regular expression to validate this field
+               'sample'                => ''
+               ),
+       'Integer Number'        => array
+               (
+               'short_name'    => 'Integer',
+               'types'                 => ' 2 ',
+               'format'                => '%{chars}d',
+               'regex'                 => '[0-9]*',
+               'sample'                => '123'
+               ),
+       'Floating Point Number' => array
+               (
+               'short_name'    => 'Float',
+               'types'                 => ' 2 ',
+               'format'                => '%{chars}.{prec}f',
+               'regex'                 => '[0-9]*\.[0-9]*',
+               'sample'                => '123.4'
+               ),
+       'Money'         => array
+               (
+               'short_name'    => 'Money',
+               'types'                 => ' 2 ',
+               'format'                => '%{chars}.{prec}f',
+               'regex'                 => '[0-9]*\.[0-9]*',
+               'sample'                => '$123.45'
+               ),
+       'E-Mail Address'                => array
+               (
+               'short_name'    => 'E-Mail',
+               'types'                 => ' 3 ',
+               'format'                => '%s',
+               'regex'                 => '[A-Za-z0-9._%-]+@[A-Za-z0-9._%-]+\.[A-Za-z]{2,4}',
+               'sample'                => 'userid@domain.dom'
+               ),
+       'Phone Number'          => array
+               (
+               'short_name'    => 'Phone',
+               'types'                 => ' 3 ',
+               'format'                => '%s',
+               'regex'                 => '\d{3}[-.]{1}\d{3}[-.]{1}\d{4}[^\d]*\d*',
+               'sample'                => '123-456-7890 X123'
+               )
+       );
+
+       // Style definitions
+
+$mf_styles = array
+       (
+
+       'Default' =>    array
+                               (
+                               'types'         => ' 1 2 3 4 5 6 7 20 21 23 24 25 30 31 ',                                                                                                                                                              // Field types - MUST HAVE SPACE EACH SIDE OF VALUES
+                               'short_name' => 'Default',                                                                                                                                                                                                                      // A short name used in form edit
+                               'cols'          => 1,                                                                                                                                                                                                                                   // Number of columns per row
+                               'start'         => '',                                                                                                                                                                                                                                  // Text when starting this style
+                               'row_start'     => '',                                                                                                                                                                                                                                  // Text when starting a row
+                               'body'          => '<ul>
+                                                                       <!--{if:required}--><span style="{color: red;}">{title}</span><!--{else:required}<b>{title}</b>{/if:required}--><br>
+                                                                       <!--{if:descr}-->{descr}<br><!--{/if:descr}-->
+                                                                       <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                                                       <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                                                       {input}
+                                                                       <!--{if:sub_forms}--><br><ol>{sub_forms}</ol><!--{/if:sub_forms}-->
+                                                               </ul>',                                                                                                                                                                                                                         // Text for each column
+                               'col_empty'     => '',                                                                                                                                                                                                                                  // Text for empty columns
+                               'row_end'       => '',                                                                                                                                                                                                                                  // Text for end of each row
+                               'end'           => '',                                                                                                                                                                                                                                  // Text when switching to different style
+                               'sub_form'      => '<ul>{sub_form}</ul>'                                                                                                                                                                                                        // Text for each sub-form (yes, there could be multiples)
+                               ),
+
+       'Prompt and Input on single line without following break' =>    array
+                               (
+                               'types'         => ' 1 2 3 4 5 6 7',
+                               'short_name' => 'Single Line',
+                               'cols'          => 1,
+                               'start'         => '',
+                               'row_start'     => '',
+                               'body'          => '<!--{if:required}--><span style="{color: red;}">{title}</span><!--{else:required}<b>{title}</b>{/if:required}-->
+                                                                       <!--{if:image}-->{image}<!--{/if:image}-->
+                                                                       <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                                                       {input}
+                                                                       <!--{if:sub_forms}--><br><ol>{sub_forms}</ol><!--{/if:sub_forms}-->
+                                                               ',
+                               'col_empty'     => '',
+                               'row_end'       => '',
+                               'end'           => '',
+                               'sub_form'      => '<ul>{sub_form}</ul>'
+                               ),
+
+       'Prompt and Input on single line with following break' =>       array
+                               (
+                               'types'         => ' 1 2 3 4 5 6 7',
+                               'short_name' => 'Single Line w/break',
+                               'cols'          => 1,
+                               'start'         => '',
+                               'row_start'     => '',
+                               'body'          => '<!--{if:required}--><span style="{color: red;}">{title}</span><!--{else:required}<b>{title}</b>{/if:required}-->
+                                                                       <!--{if:image}-->{image}<!--{/if:image}-->
+                                                                       <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                                                       {input}
+                                                                       <!--{if:sub_forms}--><br><ol>{sub_forms}</ol><!--{/if:sub_forms}--><br>
+                                                               ',
+                               'col_empty'     => '',
+                               'row_end'       => '',
+                               'end'           => '',
+                               'sub_form'      => '<ul>{sub_form}</ul>'
+                               ),
+
+       'Prompt and Input Aligned' =>   array
+                               (
+                               'types'         => ' 1 2 3 4 5 6 20 21 24 25 ',
+                               'short_name' => 'Prompt Aligned',
+                               'cols'          => 1,
+                               'start'         => '<table border="0" cellspacing="0" cellpadding="2">',
+                               'row_start'     => '',
+                               'body'          => '<tr>
+                                                                       <td align="right" valign="top">
+                                                                               <b><!--{if:required}--><span style="{color: red;}">{title}</span><!--{else:required}{title}{/if:required}--></b><br>
+                                                                               <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                                                               <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                                                       </td><td align="left">{input}<!--{if:sub_forms}--><p>{sub_forms}<!--{/if:sub_forms}--></td>
+                                                               </tr>
+                                                               <!--{if:descr}--><tr><td>&nbsp;</td><td align="left">{descr}</td></tr><!--{/if:descr}-->
+                                                               <!--{if:sub_forms}--><p><tr><td>&nbsp;</td><td align="left">{sub_forms}</td></tr><!--{/if:sub_forms}-->
+                                                               ',
+                               'col_empty'     => '',
+                               'row_end'       => '',
+                               'end'           => '</table><p>',
+                               'sub_form'      => '{sub_form}<br>'
+                               ),
+
+       '2 Column Table' =>     array
+                               (
+                               'types'         => ' 1 2 3 4 5 6 20 21 24 25 ',
+                               'short_name' => '2 Column',
+                               'cols'          => 2,
+                               'start'         => '<table border="0" cellspacing="0" cellpadding="2" width="90%">',
+                               'row_start'     => '<tr>',
+                               'body'          => '<td align="left" valign="top" width="50%">
+                                                                       <b><!--{if:required}--><span style="{color: red;}">{title}</span><!--{else:required}{title}{/if:required}--></b><br>
+                                                                       <!--{if:descr}-->{descr}<!--{/if:descr}--><br>
+                                                                       <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                                                       <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                                                       {input}
+                                                                       <!--{if:sub_forms}--><p>{sub_forms}<!--{/if:sub_forms}-->
+                                                               ',
+                               'col_empty'     => '<td>&nbsp;</td>',
+                               'row_end'       => '</tr>',
+                               'end'           => '</table><p>',
+                               'sub_form'      => '{sub_form}<br>'
+                               ),
+
+       '3 Column Table' =>     array
+                               (
+                               'types'         => ' 1 2 3 4 5 6 20 21 24 25 ',
+                               'short_name' => '3 Column',
+                               'cols'          => 3,
+                               'start'         => '<table border="0" cellspacing="0" cellpadding="2" width="90%">',
+                               'row_start'     => '<tr>',
+                               'body'          => '<td align="left" valign="top" width="33%">
+                                                                       <b><!--{if:required}--><span style="{color: red;}">{title}</span><!--{else:required}{title}{/if:required}--></b><br>
+                                                                       <!--{if:descr}-->{descr}<!--{/if:descr}--><br>
+                                                                       <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                                                       <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                                                       {input}
+                                                                       <!--{if:sub_forms}--><p>{sub_forms}<!--{/if:sub_forms}-->
+                                                               ',
+                               'col_empty'     => '<td>&nbsp;</td>',
+                               'row_end'       => '</tr>',
+                               'end'           => '</table><p>',
+                               'sub_form'      => '{sub_form}<br>'
+                               ),
+
+       '4 Column Table' =>     array
+                               (
+                               'types'         => ' 1 2 3 4 5 6 7 20 21 24 25 ',
+                               'short_name' => '4 Column',
+                               'cols'          => 4,
+                               'start'         => '<table border="0" cellspacing="0" cellpadding="2" width="90%">',
+                               'row_start'     => '<tr>',
+                               'body'          => '<td align="left" valign="top" width="25%">
+                                                                       <b><!--{if:required}--><span style="{color: red;}">{title}</span><!--{else:required}{title}{/if:required}--></b><br>
+                                                                       <!--{if:descr}-->{descr}<!--{/if:descr}--><br>
+                                                                       <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                                                       <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                                                       {input}
+                                                                       <!--{if:sub_forms}--><p>{sub_forms}<!--{/if:sub_forms}-->
+                                                               ',
+                               'col_empty'     => '<td>&nbsp;</td>',
+                               'row_end'       => '</tr>',
+                               'end'           => '</table><p>',
+                               'sub_form'      => '{sub_form}<br>'
+                               ),
+
+       '5 Column Table' =>     array
+                               (
+                               'types'         => ' 1 2 3 4 5 6 7 20 21 24 25',
+                               'short_name' => '5 Column',
+                               'cols'          => 5,
+                               'start'         => '<table border="0" cellspacing="0" cellpadding="2" width="90%">',
+                               'row_start'     => '<tr>',
+                               'body'          => '<td align="left" valign="top" width="20%">
+                                                                       <b><!--{if:required}--><span style="{color: red;}">{title}</span><!--{else:required}{title}{/if:required}--></b><br>
+                                                                       <!--{if:descr}-->{descr}<!--{/if:descr}--><br>
+                                                                       <!--{if:image}-->{image}<br><!--{/if:image}-->
+                                                                       <!--{if:file}-->{file}<br><!--{/if:file}-->
+                                                                       {input}
+                                                                       <!--{if:sub_forms}--><p>{sub_forms}<!--{/if:sub_forms}-->
+                                                               ',
+                               'col_empty'     => '<td>&nbsp;</td>',
+                               'row_end'       => '</tr>',
+                               'end'           => '</table><p>',
+                               'sub_form'      => '{sub_form}<br>'
+                               ),
+
+       'Big Title' =>  array
+                               (
+                               'types'         => ' 20 ',
+                               'short_name' => 'Big Title',
+                               'cols'          => 1,
+                               'start'         => '',
+                               'row_start'     => '',
+                               'body'          => '<font size="5">{title}</font><br><hr>',
+                               'col_empty'     =>'',
+                               'row_end'       => '',
+                               'end'           => '',
+                               'sub_form'      => ''
+                               ),
+
+       'Sub Title' =>  array
+                               (
+                               'types'         => ' 20 ',
+                               'short_name' => 'Sub-Title',
+                               'cols'          => 1,
+                               'start'         => '',
+                               'row_start'     => '',
+                               'body'          => '<p><font size="4">{title}</font><br>',
+                               'col_empty'     =>'',
+                               'row_end'       => '',
+                               'end'           => '',
+                               'sub_form'      => ''
+                               ),
+
+       'Full Width Rule' =>    array
+                               (
+                               'types'         => ' 22 ',
+                               'short_name' => 'Wide Rule',
+                               'cols'          => 1,
+                               'start'         => '',
+                               'row_start'     => '',
+                               'body'          => '<br><hr width="100%"><br>',
+                               'col_empty'     =>'',
+                               'row_end'       => '',
+                               'end'           => '',
+                               'sub_form'      => ''
+                               ),
+
+       'Half Width Rule' =>    array
+                               (
+                               'types'         => ' 22 ',
+                               'short_name' => 'Short Rule',
+                               'cols'          => 1,
+                               'start'         => '',
+                               'row_start'     => '',
+                               'body'          => '<br><hr width="50%"><br>',
+                               'col_empty'     =>'',
+                               'row_end'       => '',
+                               'end'           => '',
+                               'sub_form'      => ''
+                               )
+       );
+
+
+//     -------------------------------
+//     Other misc. configuration items
+//     -------------------------------
+
+       // Image related configuration
+
+define( "SI_THEIGHT",                                  "60" );
+define( "SI_RESIZED_SIZE",                             "287" );
+define( "SI_MIDSIZED_SIZE",                    "178" );
+define( "SI_THUMB_SIZE",                               "80" );
+
+       // Calender applet configuration
+
+define( "SI_CAL_BKND",                                 "#EFEFEF");             // Window Background color
+define( "SI_CAL_TABLE",                                        "#FFFFFF");             // Table background color
+define( "SI_CAL_HEAD",                                 "#FFFFFF");                     // Table Header Color (days)
+define( "SI_CAL_DATE",                                 "#FFFFFF");                     // Background color of days
+define( "SI_CAL_TODAY",                                        "yellow");                      // Background color of todays date
+define( "SI_CAL_NODATE",                               "#E0E0E0");                     // Background color of non-dates
+
+define( "SI_SES_TIMEOUT",                              "86400" );                      // Session timeout - 1 Hour
+
+       // Defaults for things in functions.inc
+
+define( "SI_DEFAULT_TEXTBOX_COLS",             60 );
+define( "SI_DEFAULT_TEXTBOX_ROWS",             6 );
+
+
+//     -------------------------------
+//     Setup for HTMLArea input forms
+//     -------------------------------
+
+define( "SI_RICHTEXT_TYPE_ENABLED",            TRUE );
+define( "SI_RICHTEXT_START_DELAY",             500     );              // Delay before starting to setup HTMLArea - 1/2 Sec
+define( "SI_RICHTEXT_SETUP_DELAY",             1000 );         // Delay after starting setup on each HTMLArea - 1 Sec
+
+       // Plugins for HTMLarea capabilities of richtext type
+       // Note that some plugins use toolbar buttons - See list of buttons below
+
+define( "SI_HTMLAREA_PLUGS",                   '
+               editor.registerPlugin(CharacterMap);
+               editor.registerPlugin(ContextMenu);
+//             editor.registerPlugin(CSS, css_plugin_args);
+//             editor.registerPlugin(DynamicCSS);
+//             editor.registerPlugin(EnterParagraphs);                 // Enter key creates new paragraph rather than just line break
+//             editor.registerPlugin(FullPage);                                // Permits setting properties for entire page
+//             editor.registerPlugin(HtmlTidy);                                // Requires HTML Tidy installed on server
+               editor.registerPlugin(ListType);
+//             editor.registerPlugin(SpellChecker);
+               editor.registerPlugin(TableOperations);
+       ' );
+
+       // Toolbar configuration
+
+define( "SI_HTMLAREA_TOOLBAR",                 '
+               config.toolbar =
+                       [
+                               [
+                               "fontname",
+                               "fontsize",
+                               "formatblock",
+                               "space",
+                               "bold",
+                               "italic",
+                               "underline",
+                               "strikethrough",
+                               "separator",
+                               "subscript",
+                               "superscript",
+                               "separator",
+                               "copy",
+                               "cut",
+                               "paste",
+                               "space",
+                               "undo",
+                               "redo"
+                               ],
+                               [
+                               "justifyleft",
+                               "justifycenter",
+                               "justifyright",
+                               "justifyfull",
+                               "separator",
+                               "lefttoright",
+                               "righttoleft",
+                               "separator",
+                               "ListType",                                             // List Type Plugin
+                               "insertorderedlist",
+                               "insertunorderedlist",
+                               "separator",
+                               "outdent",
+                               "indent",
+                               "separator",
+                               "forecolor",
+                               "hilitecolor",
+                               "separator",
+                               "inserthorizontalrule",
+                               "createlink",
+//                             "insertimage",
+                               "inserttable",
+                               "htmlmode",
+                               "separator",
+                               "popupeditor"
+//                             "separator",
+//                             "showhelp",
+//                             "about"
+                               ]
+                       ];
+       ' );
+
+       // Other toolbar buttons not in use
+
+/*
+                               "insertcharacter"       // CharacterMap - Not required - inserted automatically
+                               "FP-docprop"            // FullPage
+                               "HT-html-tidy"          // HtmlTidy
+                               "HT-auto-tidy"          // HtmlTidy
+                               "unorderedlist"         // ListType - Couldn't get this to work correctly
+*/
+
+define( "SI_DEFAULT_RICHTEXT_WIDTH",   "540" );                        // Default width
+define( "SI_DEFAULT_RICHTEXT_HEIGHT",  "100" );                        // Default height
+
+//     ----------------------------------------------
+//     Other misc. things you don't need to mess with
+//     ----------------------------------------------
+
+$si_month_array = array
+       (
+       1       => "January",
+       2       => "February",
+       3       => "March",
+       4       => "April",
+       5       => "May",
+       6       => "June",
+       7       => "July",
+       8       => "August",
+       9       => "September",
+       10      => "October",
+       11      => "November",
+       12      => "December"
+       );
+
+       // Countries list
+       // For the "out of sequence" countries there is no need to remove them from the full list
+       // For update see....http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/index.html
+
+$si_countries_array = array
+       (
+               // Out of sequence for convenience
+       'US' => 'United States',
+       'CA' => 'Canada',
+
+       "AF" => "Afghanistan",
+       "AX" => "Land Islands",
+       "AL" => "Albania",
+       "DZ" => "Algeria",
+       "AS" => "American Samoa",
+       "AD" => "Andorra",
+       "AO" => "Angola",
+       "AI" => "Anguilla",
+       "AQ" => "Antarctica",
+       "AG" => "Antigua and Barbuda",
+       "AR" => "Argentina",
+       "AM" => "Armenia",
+       "AW" => "Aruba",
+       "AU" => "Australia",
+       "AT" => "Austria",
+       "AZ" => "Azerbaijan",
+       "BS" => "Bahamas",
+       "BH" => "Bahrain",
+       "BD" => "Bangladesh",
+       "BB" => "Barbados",
+       "BY" => "Belarus",
+       "BE" => "Belgium",
+       "BZ" => "Belize",
+       "BJ" => "Benin",
+       "BM" => "Bermuda",
+       "BT" => "Bhutan",
+       "BO" => "Bolivia",
+       "BA" => "Bosnia and Herzegovina",
+       "BW" => "Botswana",
+       "BV" => "Bouvet Island",
+       "BR" => "Brazil",
+       "IO" => "British Indian Ocean Territory",
+       "BN" => "Brunei Darussalam",
+       "BG" => "Bulgaria",
+       "BF" => "Burkina Faso",
+       "BI" => "Burundi",
+       "KH" => "Cambodia",
+       "CM" => "Cameroon",
+       "CA" => "Canada",
+       "CV" => "Cape Verde",
+       "KY" => "Cayman Islands",
+       "CF" => "Central African Republic",
+       "TD" => "Chad",
+       "CL" => "Chile",
+       "CN" => "China",
+       "CX" => "Christmas Island",
+       "CC" => "Cocos (Keeling) Islands",
+       "CO" => "Colombia",
+       "KM" => "Comoros",
+       "CG" => "Congo",
+       "CD" => "Congo&#44; the Democratic Rep&#46; of",
+       "CK" => "Cook Islands",
+       "CR" => "Costa Rica",
+       "CI" => "Cote D'Ivoire",
+       "HR" => "Croatia",
+       "CU" => "Cuba",
+       "CY" => "Cyprus",
+       "CZ" => "Czech Republic",
+       "DK" => "Denmark",
+       "DJ" => "Djibouti",
+       "DM" => "Dominica",
+       "DO" => "Dominican Republic",
+       "EC" => "Ecuador",
+       "EG" => "Egypt",
+       "SV" => "El Salvador",
+       "GQ" => "Equatorial Guinea",
+       "ER" => "Eritrea",
+       "EE" => "Estonia",
+       "ET" => "Ethiopia",
+       "FK" => "Falkland Islands (Malvinas)",
+       "FO" => "Faroe Islands",
+       "FJ" => "Fiji",
+       "FI" => "Finland",
+       "FR" => "France",
+       "GF" => "French Guiana",
+       "PF" => "French Polynesia",
+       "TF" => "French Southern Territories",
+       "GA" => "Gabon",
+       "GM" => "Gambia",
+       "GE" => "Georgia",
+       "DE" => "Germany",
+       "GH" => "Ghana",
+       "GI" => "Gibraltar",
+       "GR" => "Greece",
+       "GL" => "Greenland",
+       "GD" => "Grenada",
+       "GP" => "Guadeloupe",
+       "GU" => "Guam",
+       "GT" => "Guatemala",
+       "GN" => "Guinea",
+       "GW" => "Guinea-Bissau",
+       "GY" => "Guyana",
+       "HT" => "Haiti",
+       "HM" => "Heard Island&#44; McDonald Islands",
+       "VA" => "Holy see (Vatican City State)",
+       "HN" => "Honduras",
+       "HK" => "Hong Kong",
+       "HU" => "Hungary",
+       "IS" => "Iceland",
+       "IN" => "India",
+       "ID" => "Indonesia",
+       "IR" => "Iran&#44; Islamic Republic of",
+       "IQ" => "Iraq",
+       "IE" => "Ireland",
+       "IL" => "Israel",
+       "IT" => "Italy",
+       "JM" => "Jamaica",
+       "JP" => "Japan",
+       "JO" => "Jordan",
+       "KZ" => "Kazakhstan",
+       "KE" => "Kenya",
+       "KI" => "Kiribati",
+       "KP" => "Korea&#44; Democratic People's Rep&#46; of",
+       "KR" => "Korea&#44; Republic of",
+       "KW" => "Kuwait",
+       "KG" => "Kyrgyzstan",
+       "LA" => "Lao People's Democratic Republic",
+       "LV" => "Latvia",
+       "LB" => "Lebanon",
+       "LS" => "Lesotho",
+       "LR" => "Liberia",
+       "LY" => "Libyan Arab Jamahiriya",
+       "LI" => "Liechtenstein",
+       "LT" => "Lithuania",
+       "LU" => "Luxembourg",
+       "MO" => "Macao",
+       "MK" => "Macedonia&#44; the Former Yugoslav Rep&#46;",
+       "MG" => "Madagascar",
+       "MW" => "Malawi",
+       "MY" => "Malaysia",
+       "MV" => "Maldives",
+       "ML" => "Mali",
+       "MT" => "Malta",
+       "MH" => "Marshall Islands",
+       "MQ" => "Martinique",
+       "MR" => "Mauritania",
+       "MU" => "Mauritius",
+       "YT" => "Mayotte",
+       "MX" => "Mexico",
+       "FM" => "Micronesia&#44; Federated States of",
+       "MD" => "Moldova&#44; Republic of",
+       "MC" => "Monaco",
+       "MN" => "Mongolia",
+       "MS" => "Montserrat",
+       "MA" => "Morocco",
+       "MZ" => "Mozambique",
+       "MM" => "Myanmar",
+       "NA" => "Namibia",
+       "NR" => "Nauru",
+       "NP" => "Nepal",
+       "NL" => "Netherlands",
+       "AN" => "Netherlands Antilles",
+       "NC" => "New Caledonia",
+       "NZ" => "New Zealand",
+       "NI" => "Nicaragua",
+       "NE" => "Niger",
+       "NG" => "Nigeria",
+       "NU" => "Niue",
+       "NF" => "Norfolk Island",
+       "MP" => "Northern Mariana Islands",
+       "NO" => "Norway",
+       "OM" => "Oman",
+       "PK" => "Pakistan",
+       "PW" => "Palau",
+       "PS" => "Palestinian Territory&#44; Occupied",
+       "PA" => "Panama",
+       "PG" => "Papua New Guinea",
+       "PY" => "Paraguay",
+       "PE" => "Peru",
+       "PH" => "Philippines",
+       "PN" => "Pitcairn",
+       "PL" => "Poland",
+       "PT" => "Portugal",
+       "PR" => "Puerto Rico",
+       "QA" => "Qatar",
+       "RE" => "Reunion",
+       "RO" => "Romania",
+       "RU" => "Russian Federation",
+       "RW" => "Rwanda",
+       "SH" => "Saint Helena",
+       "KN" => "Saint Kitts and Nevis",
+       "LC" => "Saint Lucia",
+       "PM" => "Saint Pierre and Miquelon",
+       "VC" => "Saint Vincent and the Grenadines",
+       "WS" => "Samoa",
+       "SM" => "San Marino",
+       "ST" => "Sao Tome and Principe",
+       "SA" => "Saudi Arabia",
+       "SN" => "Senegal",
+       "CS" => "Serbia and Montenegro",
+       "SC" => "Seychelles",
+       "SL" => "Sierra Leone",
+       "SG" => "Singapore",
+       "SK" => "Slovakia",
+       "SI" => "Slovenia",
+       "SB" => "Solomon Islands",
+       "SO" => "Somalia",
+       "ZA" => "South Africa",
+       "GS" => "South Georgia&#44; South Sandwich Islands",
+       "ES" => "Spain",
+       "LK" => "Sri Lanka",
+       "SD" => "Sudan",
+       "SR" => "Suriname",
+       "SJ" => "Svalbard and Jan Mayen",
+       "SZ" => "Swaziland",
+       "SE" => "Sweden",
+       "CH" => "Switzerland",
+       "SY" => "Syrian Arab Republic",
+       "TW" => "Taiwan&#44; Province of China",
+       "TJ" => "Tajikistan",
+       "TZ" => "Tanzania&#44; United Republic of",
+       "TH" => "Thailand",
+       "TL" => "Timor-Leste",
+       "TG" => "Togo",
+       "TK" => "Tokelau",
+       "TO" => "Tonga",
+       "TT" => "Trinidad and Tobago",
+       "TN" => "Tunisia",
+       "TR" => "Turkey",
+       "TM" => "Turkmenistan",
+       "TC" => "Turks and Caicos Islands",
+       "TV" => "Tuvalu",
+       "UG" => "Uganda",
+       "UA" => "Ukraine",
+       "AE" => "United Arab Emirates",
+       "GB" => "United Kingdom",
+       "US" => "United States",
+       "UM" => "United States minor outlying islands",
+       "UY" => "Uruguay",
+       "UZ" => "Uzbekistan",
+       "VU" => "Vanuatu",
+       "VE" => "Venezuela",
+       "VN" => "Viet Nam",
+       "VG" => "Virgin Islands&#44; British",
+       "VI" => "Virgin Islands&#44; U&#46;S&#46;",
+       "WF" => "Wallis and Futuna",
+       "EH" => "Western Sahara",
+       "YE" => "Yemen",
+       "ZM" => "Zambia",
+       "ZW" => "Zimbabwe"
+       );
+
+$si_countries_list = $s = "";
+while( list($k, $v) = each($si_countries_array) )
+       {
+       $si_countries_list .= "$s$k^$v";
+       $s = "~";
+       }
+
+$si_states_array = array
+       (
+       "AL" => "Alabama",
+       "AK" => "Alaska",
+       "AB" => "Alberta",
+       "AZ" => "Arizona",
+       "AR" => "Arkansas",
+       "BC" => "British Columbia",
+       "CA" => "California",
+       "CO" => "Colorado",
+       "CT" => "Connecticut",
+       "DE" => "Delaware",
+       "DC" => "District of Columbia",
+       "FL" => "Florida",
+       "GA" => "Georgia",
+       "GU" => "Guam",
+       "HI" => "Hawaii",
+       "ID" => "Idaho",
+       "IL" => "Illinois",
+       "IN" => "Indiana",
+       "IA" => "Iowa",
+       "KS" => "Kansas",
+       "KY" => "Kentucky",
+       "LA" => "Louisiana",
+       "ME" => "Maine",
+       "MB" => "Manitoba",
+       "MD" => "Maryland",
+       "MA" => "Massachusetts",
+       "MI" => "Michigan",
+       "MN" => "Minnesota",
+       "MS" => "Mississppi",
+       "MO" => "Missouri",
+       "MT" => "Montana",
+       "NE" => "Nebraska",
+       "NV" => "Nevada",
+       "NB" => "New Brunswick",
+       "NF" => "Newfoundland",
+       "NH" => "New Hampshire",
+       "NJ" => "New Jersey",
+       "NM" => "New Mexico",
+       "NY" => "New York",
+       "NC" => "North Carolina",
+       "ND" => "North Dakota",
+       "NT" => "Northwest Territories",
+       "NS" => "Nova Scotia",
+       "OH" => "Ohio",
+       "OK" => "Oklahoma",
+       "ON" => "Ontario",
+       "OR" => "Oregon",
+       "PA" => "Pennsylvania",
+       "PE" => "Prince Edward Island",
+       "PR" => "Puerto Rico",
+       "QC" => "Quebec",
+       "RI" => "Rhode Island",
+       "SK" => "Saskatchewan",
+       "SC" => "South Carolina",
+       "SD" => "South Dakota",
+       "TN" => "Tennessee",
+       "TX" => "Texas",
+       "UT" => "Utah",
+       "VT" => "Vermont",
+       "VI" => "Virgin Islands",
+       "VA" => "Virginia",
+       "WA" => "Washington",
+       "WV" => "West Virginia",
+       "WI" => "Wisconsin",
+       "WY" => "Wyoming",
+       "YT" => "Yukon"
+       );
+
+$si_states_list = $s = "";
+while( list($k, $v) = each($si_states_array) )
+       {
+       $si_states_list .= "$s$k^$v";
+       $s = "~";
+       }
+
+       // Websafe colors - Not including Black and White
+
+$si_websafe_colors = array
+       (
+       "Beige"                 => "#F6D89F",
+       "Light Purple"  => "#8F9ABF",
+       "Gold"                  => "#EDBC49",
+       "Light Blus"    => "#4FC9F5",
+       "Pink"                  => "#F8C1D9",
+       "Tan"                   => "#C5B49A",
+       "Mint"                  => "#7DF2CA",
+       "Light Orange"  => "#FFCC99",
+       "Dark Blue"             => "#0099CC",
+       "Antique White" => "#FAEBD7",
+       "Lavendar"              => "#E6E6FA",
+       "Tomato"                => "#FF6347",
+       "Light Salmon"  => "#FFA07A"
+       );
+
+       // Build Websafe color list for use in standard function calls
+
+$si_websafe_color_list = $s = "";
+while( list($k, $v) = each($si_websafe_colors) )
+       {
+       $si_websafe_color_list .= "$s$v^$k";
+       $s = "~";
+       }
+
+       // Other useable colors
+
+$si_std_colors = array
+       (
+       "#006400",
+       "#00CED1",
+       "#00FA9A",
+       "#191970",
+       "#20B2AA",
+       "#228B22",
+       "#2F4F4F",
+       "#32CD32",
+       "#388E8E",
+       "#3CB371",
+       "#40E0D0",
+       "#4169E1",
+       "#4682B4",
+       "#483D8B",
+       "#48D1CC",
+       "#4B0082",
+       "#555555",
+       "#556B2F",
+       "#5F9EA0",
+       "#6495ED",
+       "#6A5ACD",
+       "#6B8E23",
+       "#708090",
+       "#7171C6",
+       "#71C671",
+       "#778899",
+       "#7B68EE",
+       "#7CFC00",
+       "#7D9EC0",
+       "#8470FF",
+       "#87CEEB",
+       "#87CEFA",
+       "#8A2BE2",
+       "#8E388E",
+       "#8E8E38",
+       "#8FBC8F",
+       "#9370DB",
+       "#9400D3",
+//     "#98FB98",
+       "#9932CC",
+       "#A020F0",
+       "#A0522D",
+       "#A52A2A",
+       "#A9A9A9",
+       "#AAAAAA",
+//     "#ADD8E6",
+       "#ADFF2F",
+       "#B03060",
+       "#B0C4DE",
+//     "#B0E0E6",
+       "#B22222",
+       "#B8860B",
+       "#BA55D3",
+       "#BC8F8F",
+       "#BDB76B",
+       "#BEBEBE",
+       "#C5C1AA",
+       "#C67171",
+       "#C71585",
+       "#CD5C5C",
+       "#D02090",
+       "#D2691E",
+       "#D2B48C",
+//     "#D3D3D3",
+       "#D8BFD8",
+       "#DA70D6",
+       "#DAA520",
+       "#DB7093",
+       "#DC143C",
+//     "#DCDCDC",
+       "#DDA0DD",
+       "#DEB887",
+//     "#E6E6FA",
+       "#E9967A",
+       "#EE82EE",
+//     "#EEE8AA",
+       "#F08080",
+//     "#F0E68C",
+//     "#F0F8FF",
+       "#F4A460",
+//     "#F5DEB3",
+//     "#F5F5DC",
+//     "#F5FFFA",
+//     "#F8F8FF",
+       "#FA8072",
+//     "#FAEBD7",
+//     "#FAF0E6",
+//     "#FAFAD2",
+//     "#FDF5E6",
+       "#FF69B4",
+       "#FF7F50",
+       "#FF8C00",
+       "#FFB6C1",
+       "#FFC0CB",
+       "#FFD700"
+//     "#FFE4B5",
+//     "#FFEBCD",
+//     "#FFEFD5",
+//     "#FFFAF0"
+       );
+
+       // Determine number of bits in an integer useable for a bitmap - PHP doesn't have sizeof()
+
+settype( $test_int, "integer" );
+$test_int = 1;
+for( $i=1 ; $i<100 ; $i++ )
+       {
+       $t = $test_int * 2;
+       $test_int = $test_int << 1;
+       if( $test_int != $t )
+               break;
+       }
+define( 'SI_INT_SIZE', $i );
+
+
+} // if( !isset($siteinfo) )
+
+?>