function buildGraphImage($pControl, $pRecord)
{
    $thesource = $pControl->source;
    $thename = $pControl->graph;
    $thedir = $_GET['dir'];
    $addSession = '&ses=' . $_GET['ses'];
    if ($pControl->format == 'image') {
        $t = nuRunQuery("SELECT * FROM zzsys_image WHERE sim_code = '{$pControl->graph}'");
        $r = db_fetch_object($t);
        return "<img src='" . getPHPurl() . "formimage.php?dir={$thedir}&iid={$r->zzsys_image_id}' width='{$pControl->width}' height='{$pControl->height}'/>";
    } else {
        foreach ($pRecord as $key => $value) {
            //-----replace any strings, with hashes around them, in the querystring that match
            //-----fieldnames in the table
            //-----with values from the table
            //-----e.g. id=#ID# could become id=007
            $thesource = str_replace("#{$key}#", $value, $thesource);
        }
        reset($pRecord);
        $t = nuRunQuery("SELECT * FROM zzsys_activity WHERE sat_all_code = '" . $_GET['r'] . "'");
        $r = db_fetch_object($t);
        return "<img src='graph_report.php?dir={$thedir}{$addSession}&activityID={$r->zzsys_activity_id}&graph_name={$thename}&{$thesource}' width='{$pControl->width}' height='{$pControl->height}' />";
    }
}
    private function defaultJSfunctions()
    {
        $C = $this->CRLF;
        if ($this->form->sfo_javascript != '') {
            $this->appendJSfunction("{$C}//---- start of custom javascript ----{$C}{$C}" . $this->form->sfo_javascript . "{$C}{$C}//---- end of custom javascript ----");
        }
        $this->checkBlanks();
        $s = "function nuRefresh(){//---refresh index page{$C}";
        $s = $s . "      window.onbeforeunload = null; {$C}";
        $s = $s . "      window.onunload = null; {$C}";
        $s = $s . "      history.go(); {$C}";
        $s = $s . "}{$C}";
        $this->appendJSfunction($s);
        $s = "function sfVisibile(pTabNo){//---show subforms{$C}";
        $s = $s . "      var subformCount = document.getElementById('theform').TheSubforms.value; {$C}";
        $s = $s . "      var subformName  = ''; {$C}";
        $s = $s . "      for(ii=0;ii<subformCount;ii++){ {$C}";
        $s = $s . "          if(document.getElementById('theform')['SubformNumber'+ii].accept == pTabNo){ {$C}";
        $s = $s . "              subformName = document.getElementById('theform')['SubformNumber'+ii].value{$C}";
        $s = $s . "              document.getElementById('sf_title'+subformName).style.visibility = 'visible';{$C}";
        $s = $s . "              document.getElementById(subformName).style.visibility = 'visible';{$C}";
        $s = $s . "          }{$C}";
        $s = $s . "      }{$C}";
        $s = $s . "}{$C}";
        $this->appendJSfunction($s);
        $s = "function SFrowColor(pthis, pSubform){ {$C}";
        $s = $s . "      var lRow    = document.getElementById('lastRow_'  + pSubform).value;{$C}";
        $s = $s . "      var rColor  = document.getElementById('rowColor_' + pSubform).value;{$C}";
        $s = $s . "      if(lRow    != ''){ {$C}";
        $s = $s . "         document.getElementById(lRow).style.backgroundColor  = document.getElementById('lastColor_'  + pSubform).value;{$C}";
        $s = $s . "      }{$C}";
        $s = $s . "      document.getElementById('lastColor_'  + pSubform).value = document.getElementById(pthis.id).style.backgroundColor;{$C}";
        $s = $s . "      document.getElementById(pthis.id).style.backgroundColor = rColor;{$C}";
        $s = $s . "      document.getElementById('lastRow_' + pSubform).value    = pthis.id;{$C}";
        $s = $s . "}    {$C}";
        $this->appendJSfunction($s);
        $s = "function sfInvisibile(pTabNo){//---show subforms{$C}";
        $s = $s . "      var subformCount = document.getElementById('theform').TheSubforms.value; {$C}";
        $s = $s . "      var subformName  = ''; {$C}";
        $s = $s . "      for(ii=0;ii<subformCount;ii++){ {$C}";
        $s = $s . "          if(document.getElementById('theform')['SubformNumber'+ii].accept == pTabNo){ {$C}";
        $s = $s . "              subformName = document.getElementById('theform')['SubformNumber'+ii].value{$C}";
        $s = $s . "              document.getElementById('sf_title'+subformName).style.visibility = 'hidden';{$C}";
        $s = $s . "              document.getElementById(subformName).style.visibility = 'hidden';{$C}";
        $s = $s . "          }{$C}";
        $s = $s . "      }{$C}";
        $s = $s . "}{$C}";
        $this->appendJSfunction($s);
        $s = "function getImage(pID){ {$C}";
        $s = $s . "   return 'formimage.php?dir='+customDirectory()+'&iid='+pID; {$C}";
        $s = $s . "}{$C}{$C}";
        $this->appendJSfunction($s);
        if ($this->form->sfo_access_without_login != '1') {
            $s = "self.setInterval('checknuC()', 1000); {$C}{$C}";
        }
        if ($this->form->zzsys_form_id == 'index') {
            $s = '';
        }
        $s = $s . "function checknuC(){ {$C}";
        $s = $s . "   if(nuReadCookie('nuC') == null){ {$C}";
        if ($this->form->zzsys_form_id == 'index') {
            $s = $s . "      pop = window.open('formlogin.php', '_parent');{$C}";
        } else {
            $s = $s . "      pop = window.open('', '_parent');{$C}";
            $s = $s . "      pop.close();{$C}";
        }
        $s = $s . "   }{$C}";
        $s = $s . "}{$C}";
        $this->appendJSfunction($s);
        $s = "function MIN(pthis){//---mouse over menu{$C}";
        $s = $s . "      document.getElementById(pthis.id).style.color='" . $this->setup->set_hover_color . "';{$C}";
        $s = $s . "}{$C}";
        $this->appendJSfunction($s);
        $s = "function MOUT(pthis){//---mouse out menu{$C}";
        $s = $s . "   document.getElementById(pthis.id).style.color='';{$C}";
        $s = $s . "}{$C}";
        $this->appendJSfunction($s);
        $s = "function getCal(theID){//---open calendar{$C}";
        $s = $s . "   calendarBuild(theID); ";
        $s = $s . "}{$C}";
        $this->appendJSfunction($s);
        $s = "function reformat(pthis){ {$C}";
        $s = $s . "   if(aType[txtFormat[pthis.id]]=='date'){;{$C}";
        $s = $s . "      reformat(pthis);{$C}";
        $s = $s . "   }{$C}";
        $s = $s . "}{$C}";
        $this->appendJSfunction($s);
        $s = "function getframe(){//---which hidden frame to use{$C}";
        $s = $s . "   var theframe = document.getElementById('framenumber').value*1;{$C}";
        $s = $s . "      if(theframe == 4){;{$C}";
        $s = $s . "         theframe = 0;{$C}";
        $s = $s . "      }else{ {$C}";
        $s = $s . "         theframe = theframe + 1;{$C}";
        $s = $s . "      }{$C}";
        $s = $s . "   document.getElementById('framenumber').value = theframe;{$C}";
        $s = $s . "   return 'hide' + theframe;{$C}";
        $s = $s . "}{$C}";
        $this->appendJSfunction($s);
        $s = "function getvaluesurl(pthis){//---url used to save list to database{$C}";
        $s = $s . "   var url      = 'getlist.php?x=1&type=list&id='+document.getElementById('formsessionID').value+'&name='+pthis.id;{$C}";
        $s = $s . "   var theframe = getframe();{$C}";
        $s = $s . "   parent.frames[theframe].document.location = url;{$C}";
        $s = $s . "}{$C}";
        $this->appendJSfunction($s);
        $s = "function SaveThis(pclose){//---save record{$C}";
        $s = $s . "   document.getElementById('theform').close_after_save.value = pclose;{$C}";
        $s = $s . "   var vMessage = '';{$C}";
        $s = $s . "   vMessage     = noblanks();{$C}";
        $s = $s . "   if(vMessage != ''){;{$C}";
        $s = $s . "      alert(vMessage);{$C}";
        $s = $s . "      return;{$C}";
        $s = $s . "   }{$C}";
        $s = $s . "   if(window.nuBeforeSave){;{$C}";
        $s = $s . "      if(!nuBeforeSave()){;{$C}";
        $s = $s . "         return;{$C}";
        $s = $s . "      };{$C}";
        $s = $s . "   };{$C}";
        $s = $s . "   var framenumber       = parent.frames[0].document.theform.framenumber.value *1 + 1;{$C}";
        $s = $s . "   if (framenumber > 9){ {$C}";
        $s = $s . "   \tparent.frames[0].document.theform.framenumber.value = 0;{$C}";
        $s = $s . "   }else{ {$C}";
        $s = $s . "   parent.frames[0].document.theform.framenumber.value = framenumber;{$C}";
        $s = $s . "   }{$C}";
        $dbg = '&debug=' . $_GET['debug'];
        //--debug parameter (passed manually)
        if ($this->cloning == '1') {
            $s = $s . "   parent.frames[framenumber].document.location = 'formduplicate.php?x=1&r=-1&dir={$this->customDirectory}&ses={$this->session}&f={$this->formID}&form_ses={$this->formsessionID}{$dbg}';{$C}";
        } else {
            $s = $s . "   parent.frames[framenumber].document.location = 'formduplicate.php?x=1&r={$this->recordID}&dir={$this->customDirectory}&ses={$this->session}&f={$this->formID}&form_ses={$this->formsessionID}{$dbg}';{$C}";
        }
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        $s = "function CloneThis(pthis){//---save record{$C}";
        $s = $s . "   if(window.nuBeforeClone){;{$C}";
        $s = $s . "      if(!nuBeforeClone()){;{$C}";
        $s = $s . "         return;{$C}";
        $s = $s . "      };{$C}";
        $s = $s . "   };{$C}";
        if ($this->cloning == '1') {
            $recordID = '-1';
        } else {
            $recordID = $this->recordID;
        }
        $dbg = '&debug=' . $_GET['debug'];
        $s = $s . "   parent.frames['main'].document.forms[0].action = 'form.php?x=1&c=1&r={$recordID}&dir={$this->customDirectory}&ses={$this->session}&f={$this->formID}{$dbg}';{$C}";
        $s = $s . "   parent.frames['main'].document.forms[0].submit();{$C}";
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        $s = "function CheckMenu(pItem){//---load form{$C}";
        $s = $s . "   if(window.nuClickMenu){;{$C}";
        $s = $s . "      if(!nuClickMenu(pItem)){;{$C}";
        $s = $s . "         return;{$C}";
        $s = $s . "      };{$C}";
        $s = $s . "   };{$C}";
        $s = $s . "   showTab(pItem);{$C}";
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        $s = "function LoadThis(){//---load form{$C}";
        $s = $s . "   showTab(0);{$C}";
        $s = $s . "   if(window.nuLoadThis){;{$C}";
        $s = $s . "      nuLoadThis();{$C}";
        $s = $s . "   };{$C}";
        //--start cursor
        $t = nuRunQuery("SELECT sob_all_name FROM zzsys_object WHERE sob_all_start_cursor = '1' AND sob_zzsys_form_id = '" . $this->form->zzsys_form_id . "'");
        $r = mysql_fetch_object($t);
        if ($r->sob_all_name != '') {
            $s = $s . "   document.forms[0]['{$r->sob_all_name}'].focus();{$C}";
        }
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        $s = "function DeleteThis(pthis){//---delete record{$C}";
        $s = $s . "   if(window.nuBeforeDelete){;{$C}";
        $s = $s . "      if(!nuBeforeDelete()){;{$C}";
        $s = $s . "         return;{$C}";
        $s = $s . "      };{$C}";
        $s = $s . "   };{$C}";
        if ($this->delete == '1') {
            $s = $s . "   parent.frames['main'].document.forms[0].action = 'formdelete.php?x=1&r={$recordID}&dir={$this->customDirectory}&ses={$this->session}&f={$this->formID}';{$C}";
        } else {
            $s = $s . "   parent.frames['main'].document.forms[0].action = 'form.php?x=1&delete=1&r={$recordID}&dir={$this->customDirectory}&ses={$this->session}&f={$this->formID}';{$C}";
        }
        $s = $s . "   parent.frames['main'].document.forms[0].submit();{$C}";
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        $s = "function hoverMenu(){ {$C}";
        $s = $s . "   return 'green';{$C}";
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        $s = "function selectedMenu(){ {$C}";
        $s = $s . "   return 'C0C0C0';{$C}";
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        //Added by SG
        $s = "function emailIt(pReportID,pTo,pFrom,pSubject,pMessage,pFilename,pResponse,pType){                         {$C}";
        // BEGIN - 2009/05/29 - Michael
        // If set_default_email_from does not exist in the zzsys_setup table
        // or is blank, pFrom will still be null when it's passed through to
        // emailFormBuild.
        $s = $s . "   if (pFrom == null || pFrom == '')                                                                       {$C}";
        $s = $s . "        pFrom = '{$this->setup->set_default_email_from}';\t\t\t\t\t\t\t{$C}";
        // END - 2009/05/29 - Michael
        $s = $s . "   nuEraseCookie('emailREPORT');                                                                           {$C}";
        $s = $s . "  \temailFormBuild(pReportID,pTo,pFrom,pSubject,pMessage,pFilename,pResponse,pType);  \t\t\t\t\t\t{$C}";
        //	$s   = $s . "   if (pTo == '')       { pTo = prompt('Email to..','');}                                                  $C";
        //	$s   = $s . "   if (pFrom == '')     { pFrom = prompt('Email from..','');}                                              $C";
        //	$s   = $s . "   if (pSubject == '')  { pSubject = prompt('Subject..','');}                                              $C";
        //	$s   = $s . "   if (pMessage == '')  { pMessage = prompt('Message..','');}                                              $C";
        //	$s   = $s . "   if (pFilename == '') { pFilename = prompt('Filename..','');}                                            $C";
        //	$s   = $s . "   if (pTo == null || pFrom == null || pSubject == null || pMessage == null || pFilename == null) {        $C";
        //	$s   = $s . "           alert('not enough information provided to send email, please try again');                       $C";
        //	$s   = $s . "   } else {                                                                                                $C";
        //	$s   = $s . "           if (pTo == '' || pTo == null) {                                                                 $C";
        //	$s   = $s . "                   alert('Please provide an email address');                                               $C";
        //	$s   = $s . "           } else {                                                                                        $C";
        //	$s   = $s . "   				emailFormBuild(pReportID,pTo,pFrom,pSubject,pMessage,pFilename,pResponse,pType);        $C";
        //	$s   = $s . "                   emailSendIt(pReportID,pTo,pFrom,pSubject,pMessage,pFilename,pResponse,pType);           $C";
        //	$s   = $s . "           }                                                                                               $C";
        //	$s   = $s . "   }                                                                                                       $C";
        $s = $s . "}                                                                                                          {$C}";
        $this->appendJSfunction($s);
        // BEGIN - 2009/05/29 - Michael
        $php_url = getPHPurl();
        $s = <<<EOJS
\t\t\tfunction emailSendIt(pReportID, pTo, pFrom, pSubject, pMessage, pFilename, pAlert, pType, pResponse)
\t\t\t{
\t\t\t\t\t// Make sure the error message is hidden.
\t\t\t\tdocument.getElementById("error_row").style.display = 'none';
\t\t\t\t\t// Erase the cookie and make sure these is an email address.
\t\t\t\tnuEraseCookie("emailREPORT");
\t\t\t\tif (pTo == '' || pTo == null)
\t\t\t\t\talert("Please provide an email address");
\t\t\t\telse
\t\t\t\t{
\t\t\t\t\t\t// Generate the URL to email the report.
\t\t\t\t\t\t// NOTE: The subject, message and filename need to be escaped
\t\t\t\t\t\t//       otherwise everything after the first '&' in those values
\t\t\t\t\t\t//       will be dropped due to the way GET variables are interpreted.
\t\t\t\t\tvar report_url\t= "{$php_url}";
\t\t\t\t\tvar url \t= report_url+"reportemail.php" +
\t\t\t\t\t\t\t\t\t"?x=1" +
\t\t\t\t\t\t\t\t\t"&dir={$this->customDirectory}" +
\t\t\t\t\t\t\t\t\t"&ses={$this->session}" +
\t\t\t\t\t\t\t\t\t"&form_ses={$this->formsessionID}" +
\t\t\t\t\t\t\t\t\t"&r=" + pReportID +
\t\t\t\t\t\t\t\t\t"&to=" + pTo +
\t\t\t\t\t\t\t\t\t"&from=" + pFrom +
\t\t\t\t\t\t\t\t\t"&subject=" + escape(pSubject) +
\t\t\t\t\t\t\t\t\t"&message=" + escape(pMessage) +
\t\t\t\t\t\t\t\t\t"&filename=" + escape(pFilename) +
\t\t\t\t\t\t\t\t\t"&report_url=" + report_url +
\t\t\t\t\t\t\t\t\t"&reporttype=" + pType +
\t\t\t\t\t\t\t\t\t"&receipt=" + pResponse;
\t\t\t\t\t\t// Run that URL.
\t\t\t\t\tnuMailJax(url);
\t\t\t\t\t\t// Check if we need to be alerted about whether the email was
\t\t\t\t\t\t// successfully sent out.
\t\t\t\t\tif (pAlert == true || pAlert == 'true')
\t\t\t\t\t\tstartEmailTimeOut();
\t\t\t\t} // else
\t\t\t} // func
EOJS;
        $this->appendJSfunction($s);
        // END - 2009/05/29 - Michael
        /*
                $s   =      "function emailSendIt(pReportID,pTo,pFrom,pSubject,pMessage,pFilename,pAlert,pType,pResponse){              $C";
                $s   = $s . "   nuEraseCookie('emailREPORT');                                                                           $C";
                $s   = $s . "   if (pTo == '' || pTo == null) {                                                                         $C";
                $s   = $s . "           alert('Please provide an email address');                                                       $C";
                $s   = $s . "   } else {                                                                                                $C";
                $s   = $s . "           var report_url='".getPHPurl()."';                                                               $C";
                $s   = $s . "           var url='".getPHPurl()."reportemail.php?x=1&dir=$this->customDirectory&ses=$this->session';     $C";
                $s   = $s . "           var url=url+'&form_ses=$this->formsessionID&r='+pReportID;                                      $C";
                $s   = $s . "           var url=url+'&to='+pTo+'&from='+pFrom+'&subject='+pSubject+'&message='+pMessage;                $C";
                $s   = $s . "           var url=url+'&filename='+pFilename+'&report_url='+report_url+'&reporttype='+pType;              $C";
                $s   = $s . "           nuMailJax(url);                                                                                     $C";
                $s   = $s . "           if (pAlert == true || pAlert == 'true'){                                                                         $C";
                $s   = $s . "                   startEmailTimeOut();                                                 $C";
        		$s   = $s . "                   return;                                                 								$C";
                $s   = $s . "           }                                                                                               $C";
                $s   = $s . "   }                                                                                                       $C";
                $s   = $s . "}                                                                                                          $C";
                $this->appendJSfunction($s);
        */
        // BEGIN - 2009/05/29 - Michael
        $s = <<<EOJS
\t\t\tfunction emailSendResponse()
\t\t\t{
\t\t\t\t\t// Get the cookie and delete it.
\t\t\t\tcookieValue = nuReadCookie("emailREPORT");
\t\t\t\tnuEraseCookie("emailREPORT");
\t\t\t\t\t// Check the cookie value.
\t\t\t\tswitch (cookieValue)
\t\t\t\t{
\t\t\t\t\t// The cookie has this value if everything was successful.
\t\t\t\tcase "{$this->formsessionID}":
\t\t\t\t\temailSuccess();
\t\t\t\t\treturn true;
\t\t\t\t\t// The report could not be generated...
\t\t\t\t\t// NOTE: This case won't run if there was an error in the report
\t\t\t\t\t//       itself, only if the report URL could not be read from or
\t\t\t\t\t//       the report document could not be saved to the filesystem.
\t\t\t\tcase "report_error":
\t\t\t\t\temailFailure("There was an error generating the report");
\t\t\t\t\treturn false;
\t\t\t\t\t// The email was not sent successfully...
\t\t\t\t\t// NOTE: This will mostly like only occur if the report could not
\t\t\t\t\t//       be attached or there is no SMTP server listening on port 25.
\t\t\t\t\t//       Postfix will just add the message to a queue before it trys
\t\t\t\t\t//       to send the message, so invalid hostnames and users will
\t\t\t\t\t//       not trigger this error.
\t\t\t\tcase "email_error":
\t\t\t\t\temailFailure("There was an error sending the email");
\t\t\t\t\treturn false;
\t\t\t\t\t// This case will run if for some reason reportemail.php died
\t\t\t\t\t// before sendResponse() was called. In other words, no cookie.
\t\t\t\tdefault:
\t\t\t\t\temailFailure("There was an error sending the email");
\t\t\t\t\treturn false;
\t\t\t\t} // switch
\t\t\t} // function
EOJS;
        $this->appendJSfunction($s);
        // END - 2009/05/29 - Michael
        /*
                $s   =      "function emailSendResponse(){                                                                              $C";
                $s   = $s . "   if (nuReadCookie('emailREPORT') == '$this->formsessionID') {                                            $C";
                $s   = $s . "           //alert('Your email was successfully sent');                                                      $C";
                $s   = $s . "           nuEraseCookie('emailREPORT');                                                                   $C";
                $s   = $s . "           emailSuccess();      				                                                            $C";
                $s   = $s . "           return true;                                                                                    $C";
                $s   = $s . "   } else {                                                                                                $C";
                $s   = $s . "           //alert('possible error, you can try resending the email, or contact nuSoftware');                                             $C";
                $s   = $s . "           nuEraseCookie('emailREPORT');                                                                   $C";
        // BEGIN - 2009/05/09 - Michael
        				if (There was an error sending the email
                $s   = $s . "           emailFailure(errorString);		                                                                    $C";
        // END - Michael
                $s   = $s . "           return false;                                                                                   $C";
                $s   = $s . "   }                                                                                                       $C";
                $s   = $s . "}                                                                                                          $C";
        */
        //end added by SG
        $s = "function pdfIt(pReportID){ {$C}";
        $s = $s . "   var url='" . $this->setup->set_php_url . "runpdf.php?x=1&dir={$this->customDirectory}&ses={$this->session}&form_ses={$this->formsessionID}&r='+pReportID; {$C}";
        $s = $s . "   window.open (url,'_blank','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes'); {$C}";
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        $s = "function printIt(pReportID){ {$C}";
        $s = $s . "   var url='" . $this->setup->set_php_url . "runreport.php?x=1&dir={$this->customDirectory}&ses={$this->session}&form_ses={$this->formsessionID}&r='+pReportID; {$C}";
        $s = $s . "   window.open (url,'_blank','toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes,resizable=yes'); {$C}";
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        $s = "function exportIt(pReportID){ {$C}";
        $s = $s . "   var url='" . $this->setup->set_php_url . "runexport.php?x=1&dir={$this->customDirectory}&ses={$this->session}&form_ses={$this->formsessionID}&r='+pReportID; {$C}";
        $s = $s . "   window.open (url,'_blank','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes'); {$C}";
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        $s = "function runIt(pReportID){ {$C}";
        $s = $s . "   var url='" . $this->setup->set_php_url . "runprocedure.php?x=1&dir={$this->customDirectory}&ses={$this->session}&form_ses={$this->formsessionID}&r='+pReportID; {$C}";
        $s = $s . "   window.open (url,'_blank','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes'); {$C}";
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        $s = "function CheckIfSaved(){ {$C}";
        if (!$this->runActivity) {
            if ($this->formID == 'index') {
                $s = $s . "   event.returnValue = 'Are you sure?';{$C}";
            } else {
                $s = $s . "   if(document.getElementById('beenedited').value=='1'){ {$C}";
                $s = $s . "       event.returnValue = 'This record has NOT been saved.. (Click CANCEL to save this record)';{$C}";
                $s = $s . "   };{$C}";
            }
        }
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
        $s = "function untick(pBox){ {$C}";
        $s = $s . "   try{document.getElementById('row'+pBox).checked = false;}catch(err){}\n";
        $s = $s . "};{$C}";
        $this->appendJSfunction($s);
    }
 public function buildObject($C)
 {
     $lineFormat = formatForPDFandHTML($C->text_string[0]);
     //-- get any formatting stuff from the beginning of the string eg. #BOLD#
     $can_grow = $C->can_grow == '1';
     $temp_name = $this->temp_filename . $this->imagecount;
     $this->imagecount = $this->imagecount + 1;
     $draw = 'DF';
     $BC = $C->border_color;
     if (lresize($C->border_width) == 0 or $BC == 'transparent' or strtolower($BC) == 'white' or strtolower($BC) == '#ffffff' or strtolower($BC) == 'ffffff') {
         $draw = str_replace('D', '', $draw);
     }
     $BC = $C->background_color;
     if ($BC == 'transparent' or strtolower($BC) == 'white' or strtolower($BC) == '#ffffff' or strtolower($BC) == 'ffffff') {
         $draw = str_replace('F', '', $draw);
     }
     if (count($lineFormat['bgcolor']) == 0) {
         //-- no specific bg color for this object
         $color = rgbcolor($C->background_color, $this->html);
     } else {
         $color = $lineFormat['bgcolor'];
         if (strpos($draw, 'F') === false) {
             $draw = $draw . 'F';
         }
     }
     $this->SetFillColor($color['r'], $color['g'], $color['b']);
     $color = rgbcolor($C->border_color, $this->html);
     $this->SetDrawColor($color['r'], $color['g'], $color['b']);
     if (count($lineFormat['color']) == 0) {
         //-- no specific color for this object
         $color = rgbcolor($C->color, $this->html);
     } else {
         $color = $lineFormat['color'];
     }
     $this->SetTextColor($color['r'], $color['g'], $color['b']);
     $field_width = hresize($C->width);
     $this->SetLineWidth(lresize($C->border_width));
     if ($C->type != 'Graph') {
         if ($draw != '') {
             $this->Rect(hresize($C->left), vresize($C->top) + $this->section_top + 2, $field_width, hresize($C->height) + hresize($C->extra_growth), $draw);
         }
     }
     if (strpos($lineFormat['style'], 'B') === false) {
         //-- no specific boldness for this object
         if ($C->font_weight == 'bold') {
             $weight = 'B';
         } else {
             $weight = '';
         }
     } else {
         $weight = 'B';
     }
     $this->SetFont($C->font_name, $weight, fresize($C->font_size));
     $offset_top = hresize($C->original_height) * 0.2;
     if ($C->type == 'Graph') {
         if ($C->format == 'image') {
             $PT = nuRunQuery("SELECT zzsys_image_id FROM zzsys_image WHERE sim_code = '{$C->graph}'");
             $PR = db_fetch_object($PT);
             $logo = fopen(getPHPurl() . "formimage.php?dir=" . $_GET['dir'] . "&iid={$PR->zzsys_image_id}", "r");
         } else {
             $chop_at = strrpos($C->text_string[0], " width='");
             //-- chops off the "width='523' height='246' />" bit of the image
             $url = substr($C->text_string[0], 10, $chop_at - 11);
             $url = str_replace(" ", "%20", $url);
             $logo = fopen(getPHPurl() . $url, "r");
         }
         file_put_contents($temp_name . '.png', $logo);
         if (filesize($temp_name . '.png') > 0) {
             $im = imagecreatefrompng($temp_name . '.png');
             imageinterlace($im, 0);
             imagepng($im, $temp_name . '.png');
             $this->Image($temp_name . '.png', hresize($C->left), vresize($C->top) + $this->section_top + 2, $field_width, hresize($C->height) + hresize($C->extra_growth));
             unlink($temp_name . '.png');
         }
     } else {
         $string_array = array();
         if ($can_grow) {
             //-- already an array
             $string_array = $C->text_string;
         } else {
             //-- create an array
             $swap_br = array(chr(13), '<br/>', '<Br />', '<Br/>', '<BR />', '<BR/>');
             $the_string = str_replace($swap_br, '<br />', $C->text_string[0]);
             $string_array = explode("<br />", $the_string);
         }
         for ($ts = 0; $ts < count($string_array); $ts++) {
             $data = '';
             if ($ts == 0) {
                 $data = $lineFormat['string'];
                 //-- string with formatting removed
             } else {
                 $data = $string_array[$ts];
             }
             $data = str_replace('#totalNumberOfPages#', $this->total_pages, $data);
             $data = str_replace('#thePageNumber#', $this->page_no, $data);
             $data = str_replace('&nbsp;', ' ', $data);
             $data = str_replace('&nbsp', ' ', $data);
             if (strtoupper($data) == '=NOW()' or strtoupper($data) == 'NOW()') {
                 $data = $this->timestamp;
             }
             $text_width = $this->GetStringWidth($data);
             $resized_length = fwresize($text_width);
             $offset_left = 0;
             if ($C->text_align == 'right') {
                 $offset_left = vresize($C->width - $resized_length);
             }
             if ($C->text_align == 'center') {
                 $offset_left = vresize(($C->width - $resized_length) / 2);
             }
             if (!$can_grow and count($string_array) > 1) {
                 //-- dont realign top
                 $text_top = vresize($C->top) + fresize($C->font_size) / 2 * (1 * (1 + $ts)) + $this->section_top + 2;
             } else {
                 $text_top = vresize($C->top) + hresize($C->original_height) * (1 * (1 + $ts)) + $this->section_top + 2;
             }
             $left = vresize($C->left);
             $this->Text(hresize($C->left) + $offset_left, $text_top - $offset_top, $data);
         }
     }
     if ($cHeight != 0) {
     }
 }