PageRenderTime 172ms CodeModel.GetById 100ms app.highlight 13ms RepoModel.GetById 17ms app.codeStats 8ms

/administrator/components/com_breezingforms/libraries/crosstec/classes/BFQuickMode.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 1745 lines | 1589 code | 122 blank | 34 comment | 169 complexity | 374ca1b32a219a597dc81f8ec8df6fc5 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1<?php
  2/**
  3* BreezingForms - A Joomla Forms Application
  4* @version 1.8
  5* @package BreezingForms
  6* @copyright (C) 2008-2012 by Markus Bopp
  7* @license Released under the terms of the GNU General Public License
  8**/
  9defined('_JEXEC') or die('Direct Access to this location is not allowed.');
 10
 11require_once(JPATH_SITE.'/administrator/components/com_breezingforms/libraries/Zend/Json/Decoder.php');
 12require_once(JPATH_SITE.'/administrator/components/com_breezingforms/libraries/Zend/Json/Encoder.php');
 13
 14class BFQuickMode{
 15	
 16	/**
 17	 * @var HTML_facileFormsProcessor
 18	 */
 19	private $p = null;
 20	
 21	private $dataObject = array();
 22	
 23	private $rootMdata = array();
 24	
 25	private $fading = true;
 26	
 27	private $fadingClass = '';
 28	
 29	private $fadingCall = '';
 30	
 31	private $useErrorAlerts = false;
 32
 33        private $useDefaultErrors = false;
 34
 35        private $useBalloonErrors = false;
 36	
 37	private $rollover = false;
 38	
 39	private $rolloverColor = '';
 40	
 41	private $toggleFields = '';
 42	
 43	private $hasFlashUpload = false;
 44	
 45	private $flashUploadTicket = '';
 46	
 47	private $cancelImagePath = '';
 48	
 49	private $uploadImagePath = '';
 50        
 51        private $htmltextareas = array();
 52        
 53	function __construct( HTML_facileFormsProcessor $p ){
 54            
 55                // will make sure mootools loads first, important 4 jquery
 56                jimport('joomla.version');
 57                $version = new JVersion();
 58                if(version_compare($version->getShortVersion(), '3.0', '<')){
 59                    JHTML::_('behavior.mootools');
 60                }
 61                
 62                JFactory::getDocument()->addScriptDeclaration('<!--');
 63                
 64                $this->p = $p;
 65		$this->dataObject = Zend_Json::decode( base64_decode($this->p->formrow->template_code) );
 66		$this->rootMdata = $this->dataObject['properties'];
 67		$this->fading = $this->rootMdata['fadeIn'];
 68		$this->useErrorAlerts = $this->rootMdata['useErrorAlerts'];
 69                $this->useDefaultErrors = isset($this->rootMdata['useDefaultErrors']) ? $this->rootMdata['useDefaultErrors'] : false;
 70                $this->useBalloonErrors = isset($this->rootMdata['useBalloonErrors']) ? $this->rootMdata['useBalloonErrors'] : false;
 71		$this->rollover = $this->rootMdata['rollover'];
 72		$this->rolloverColor = $this->rootMdata['rolloverColor'];
 73		$this->toggleFields = $this->parseToggleFields( isset($this->rootMdata['toggleFields']) ? $this->rootMdata['toggleFields'] : '[]' );
 74		
 75		mt_srand();
 76		$this->flashUploadTicket = md5( strtotime('now') .  mt_rand( 0, mt_getrandmax() ) );
 77
 78                JFactory::getDocument()->addStyleDeclaration('
 79
 80.bfClearfix:after {
 81content: ".";
 82display: block;
 83height: 0;
 84clear: both;
 85visibility: hidden;
 86}
 87.bfInline{
 88float:left;
 89}
 90.bfFadingClass{
 91display:none;
 92}');
 93                $jQuery = '';
 94                if(isset($this->rootMdata['disableJQuery']) && $this->rootMdata['disableJQuery']){
 95                    $jQuery = 'var JQuery = jQuery;'."\n";
 96                } else {
 97                    JFactory::getDocument()->addScript(JURI::root(true) . '/components/com_breezingforms/libraries/jquery/jq.min.js');
 98                }
 99                
100                JFactory::getDocument()->addStyleSheet( JURI::root(true) . '/components/com_breezingforms/libraries/jquery/tooltip.css' );
101                JFactory::getDocument()->addScript(JURI::root(true) . '/components/com_breezingforms/libraries/jquery/tooltip.js');
102
103                if($this->useBalloonErrors){
104                    JFactory::getDocument()->addStyleSheet( JURI::root(true) . '/components/com_breezingforms/libraries/jquery/validationEngine.jquery.css' );
105                    JFactory::getDocument()->addScript(JURI::root(true) . '/components/com_breezingforms/libraries/jquery/jquery.validationEngine-en.js');
106                    JFactory::getDocument()->addScript(JURI::root(true) . '/components/com_breezingforms/libraries/jquery/jquery.validationEngine.js');
107                }
108
109		$toggleCode = '';
110		if($this->toggleFields != '[]'){
111			$toggleCode = '
112			var toggleFieldsArray = '.$this->toggleFields.';
113			String.prototype.beginsWith = function(t, i) { if (i==false) { return
114			(t == this.substring(0, t.length)); } else { return (t.toLowerCase()
115			== this.substring(0, t.length).toLowerCase()); } } 
116			function bfDeactivateSectionFields(){
117				for( var i = 0; i < bfDeactivateSection.length; i++ ){
118                                        bfSetFieldValue(bfDeactivateSection[i], "off");
119					JQuery("#"+bfDeactivateSection[i]+" .ff_elem").each(function(i){
120                                            if( JQuery(this).get(0).name && JQuery(this).get(0).name.beginsWith("ff_nm_", true) ){
121                                                bfDeactivateField[JQuery(this).get(0).name] = true;
122                                            }
123					});
124				}
125                                for( var i = 0; i < toggleFieldsArray.length; i++ ){
126                                    if(toggleFieldsArray[i].state == "turn"){
127                                        bfSetFieldValue(toggleFieldsArray[i].tName, "off");
128                                    }
129                                }
130			}
131			function bfToggleFields(state, tCat, tName, thisBfDeactivateField){
132                                // maybe a little to harsh, but currently no other workaround
133				// file uploads will be removed for the complete form if a rule is executed
134				// make sure you offer file uploads at the end of your form if you have visibility rules!
135				if(typeof bfFlashUploadInterval != "undefined"){
136					window.clearInterval( bfFlashUploadInterval );
137					for(qID in bfFlashUploadAll){
138						try{
139							JQuery(bfFlashUploadAll[qID]).uploadifyCancel(qID);
140						}catch(e){}
141					}
142					bfFlashUploadTooLarge = {};
143					bfFlashUploadAll = {};
144					JQuery("#bfFileQueue").html("")
145					JQuery(".bfFlashFileQueueClass").html("");
146				}
147				if(state == "on"){
148					if(tCat == "element"){
149                                                if( typeof JQuery("[name=\"ff_nm_"+tName+"[]\"]") != "undefined" && JQuery("[name=\"ff_nm_"+tName+"[]\"]").parent().attr("class").substr(0, 10) == "bfElemWrap" ){
150                                                    JQuery("[name=\"ff_nm_"+tName+"[]\"]").parent().css("display", "");
151                                                } else if(JQuery("[name=\"ff_nm_"+tName+"[]\"]").get(0).type == "checkbox" || JQuery("[name=\"ff_nm_"+tName+"[]\"]").get(0).type == "radio"){
152                                                    JQuery("[name=\"ff_nm_"+tName+"[]\"]").parent().parent().css("display", "");
153                                                }
154						thisBfDeactivateField["ff_nm_"+tName+"[]"] = false;
155                                                bfSetFieldValue(tName, "on");
156					} else {
157						JQuery("#"+tName).css("display", "");
158                                                bfSetFieldValue(tName, "on");
159						JQuery("#"+tName).find(".ff_elem").each(function(i){
160                                                    if( JQuery(this).get(0).name && JQuery(this).get(0).name.beginsWith("ff_nm_", true) ){
161                                                        thisBfDeactivateField[JQuery(this).get(0).name] = false;
162                                                    }
163						});
164					}
165				} else {
166					if(tCat == "element"){
167                                                if( typeof JQuery("[name=\"ff_nm_"+tName+"[]\"]") != "undefined" && JQuery("[name=\"ff_nm_"+tName+"[]\"]").parent().attr("class").substr(0, 10) == "bfElemWrap" ){
168                                                    JQuery("[name=\"ff_nm_"+tName+"[]\"]").parent().css("display", "none");
169                                                } else if(JQuery("[name=\"ff_nm_"+tName+"[]\"]").get(0).type == "checkbox" || JQuery("[name=\"ff_nm_"+tName+"[]\"]").get(0).type == "radio"){
170                                                    JQuery("[name=\"ff_nm_"+tName+"[]\"]").parent().parent().css("display", "none");
171                                                }
172						thisBfDeactivateField["ff_nm_"+tName+"[]"] = true;
173                                                bfSetFieldValue(tName, "off");
174					} else {
175						JQuery("#"+tName).css("display", "none");
176                                                bfSetFieldValue(tName, "off");
177						JQuery("#"+tName+" .ff_elem").each(function(i){
178                                                    if( JQuery(this).get(0).name && JQuery(this).get(0).name.beginsWith("ff_nm_", true) ){
179                                                        thisBfDeactivateField[JQuery(this).get(0).name] = true;
180                                                    }
181						});
182					}
183				}
184			}
185                        function bfSetFieldValue(name, condition){
186                            for( var i = 0; i < toggleFieldsArray.length; i++ ){
187                                if( toggleFieldsArray[i].action == "if" ) {
188                                    if(name == toggleFieldsArray[i].tCat && condition == toggleFieldsArray[i].statement){
189
190                                        var element = JQuery("[name=\"ff_nm_"+toggleFieldsArray[i].condition+"[]\"]");
191                                        
192                                        switch(element.get(0).type){
193                                            case "text":
194                                            case "textarea":
195                                                if(toggleFieldsArray[i].value == "!empty"){
196                                                    element.val("");
197                                                } else {
198                                                    element.val(toggleFieldsArray[i].value);
199                                                }
200                                            break;
201                                            case "select-multiple":
202                                            case "select-one":
203                                                if(toggleFieldsArray[i].value == "!empty"){
204                                                    for(var j = 0; j < element.get(0).options.length; j++){
205                                                        element.get(0).options[j].selected = false;
206                                                    }
207                                                }
208                                                for(var j = 0; j < element.get(0).options.length; j++){
209                                                    if(element.get(0).options[j].value == toggleFieldsArray[i].value){
210                                                        element.get(0).options[j].selected = true;
211                                                    }
212                                                }
213                                            break;
214                                            case "radio":
215                                            case "checkbox":
216                                                var radioLength = element.size();
217                                                if(toggleFieldsArray[i].value == "!empty"){
218                                                    for(var j = 0; j < radioLength; j++){
219                                                        element.get(j).checked = false;
220                                                    }
221                                                }
222						for(var j = 0; j < radioLength; j++){
223                                                    if( element.get(j).value == toggleFieldsArray[i].value ){
224                                                        element.get(j).checked = true;
225                                                    }
226                                                }
227                                            break;
228                                        }
229                                    }
230                                }
231                            }
232                        }
233			function bfRegisterToggleFields(){
234                        
235                                var offset = 0;
236                                var last_offset = 0;
237                                var limit  = 10;
238                                var limit_cnt = 0;
239                                
240                                if( arguments.length == 1 ){
241                                    offset = arguments[0];
242                                }
243
244                                var thisToggleFieldsArray = toggleFieldsArray;
245				var thisBfDeactivateField = bfDeactivateField;
246                                var thisBfToggleFields = bfToggleFields;
247                                
248				for( var i = offset; limit_cnt < limit && i < toggleFieldsArray.length; i++ ){
249                                //  for( var i = 0; i < toggleFieldsArray.length; i++ ){
250                                              if( toggleFieldsArray[i].action == "turn" && (toggleFieldsArray[i].tCat == "element" || toggleFieldsArray[i].tCat == "section") ){
251						var toggleField = toggleFieldsArray[i];
252						var element = JQuery("[name=\"ff_nm_"+toggleFieldsArray[i].sName+"[]\"]");
253						if(element.get(0)){
254							switch(element.get(0).type){
255								case "text":
256								case "textarea":
257                                                                        JQuery("[name=\"ff_nm_"+toggleField.sName+"[]\"]").unbind("blur");
258									JQuery("[name=\"ff_nm_"+toggleField.sName+"[]\"]").blur(
259										function(){
260											for( var k = 0; k < thisToggleFieldsArray.length; k++ ){
261												var regExp = "";
262												if(thisToggleFieldsArray[k].value.beginsWith("!", true) && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"){
263										 			regExp = thisToggleFieldsArray[k].value.substring(1, thisToggleFieldsArray[k].value.length);
264										 		}
265
266                                                                                                if(thisToggleFieldsArray[k].condition == "isnot"){
267                                                                                                    if(
268                                                                                                            ( ( regExp != "" && JQuery(this).val().test(regExp) <= 0 ) || JQuery(this).val() != thisToggleFieldsArray[k].value ) && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"
269                                                                                                    ){
270                                                                                                            var names = thisToggleFieldsArray[k].tName.split(",");
271                                                                                                            for(var n = 0; n < names.length; n++){
272                                                                                                                thisBfToggleFields(thisToggleFieldsArray[k].state, thisToggleFieldsArray[k].tCat, JQuery.trim(names[n]), thisBfDeactivateField);
273                                                                                                            }
274                                                                                                            //break;
275                                                                                                    }
276                                                                                                } else if(thisToggleFieldsArray[k].condition == "is"){
277                                                                                                    if(
278                                                                                                            ( ( regExp != "" && JQuery(this).val().test(regExp) > 0 ) || JQuery(this).val() == thisToggleFieldsArray[k].value ) && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"
279                                                                                                    ){
280                                                                                                            var names = thisToggleFieldsArray[k].tName.split(",");
281                                                                                                            for(var n = 0; n < names.length; n++){
282                                                                                                                thisBfToggleFields(thisToggleFieldsArray[k].state, thisToggleFieldsArray[k].tCat, JQuery.trim(names[n]), thisBfDeactivateField);
283                                                                                                            }
284                                                                                                            //break;
285                                                                                                    }
286                                                                                                }
287											}
288										}
289									);
290									break;
291								case "select-multiple":
292								case "select-one":
293                                                                        JQuery("[name=\"ff_nm_"+toggleField.sName+"[]\"]").unbind("change");
294									JQuery("[name=\"ff_nm_"+toggleField.sName+"[]\"]").change(
295										function(){
296											var res = JQuery.isArray( JQuery(this).val() ) == false ? [ JQuery(this).val() ] : JQuery(this).val();
297											for( var k = 0; k < thisToggleFieldsArray.length; k++ ){
298												
299												// The or-case in lists 
300												var found = false;
301												var chkGrpValues = new Array();
302										 		if(thisToggleFieldsArray[k].value.beginsWith("#", true) && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"){
303										 			chkGrpValues = thisToggleFieldsArray[k].value.substring(1, thisToggleFieldsArray[k].value.length).split("|");
304										 			for(var l = 0; l < chkGrpValues.length; l++){
305										 				if( JQuery.inArray(chkGrpValues[l], res) != -1 ){
306										 					found = true;
307										 					break;
308										 				}
309										 			}
310										 		}
311												// the and-case in lists
312												var foundCount = 0;
313												chkGrpValues2 = new Array();
314										 		if(thisToggleFieldsArray[k].value.beginsWith("#", true) && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"){
315										 			chkGrpValues2 = thisToggleFieldsArray[k].value.substring(1, thisToggleFieldsArray[k].value.length).split(";");
316										 			for(var l = 0; l < res.length; l++){
317										 				if( JQuery.inArray(res[l], chkGrpValues2) != -1 ){
318										 					foundCount++;
319										 				}
320										 			}
321										 		}
322                                                                                                
323                                                                                                if(thisToggleFieldsArray[k].condition == "isnot"){
324                                                                                                
325                                                                                                    if(
326                                                                                                            (
327                                                                                                                    !JQuery.isArray(res) && JQuery(this).val() != thisToggleFieldsArray[k].value && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"
328                                                                                                            )
329                                                                                                            ||
330                                                                                                            (
331                                                                                                                    JQuery.isArray(res) && ( JQuery.inArray(thisToggleFieldsArray[k].value, res) == -1 || !found || ( foundCount == 0 || foundCount != chkGrpValues2.length ) ) && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"
332                                                                                                            )
333                                                                                                     ){
334                                                                                                            var names = thisToggleFieldsArray[k].tName.split(",");
335                                                                                                            for(var n = 0; n < names.length; n++){
336                                                                                                                thisBfToggleFields(thisToggleFieldsArray[k].state, thisToggleFieldsArray[k].tCat, JQuery.trim(names[n]), thisBfDeactivateField);
337                                                                                                            }
338                                                                                                            //break;
339                                                                                                    }
340                                                                                                } else if(thisToggleFieldsArray[k].condition == "is"){
341                                                                                                    if(
342                                                                                                            (
343                                                                                                                    !JQuery.isArray(res) && JQuery(this).val() == thisToggleFieldsArray[k].value && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"
344                                                                                                            )
345                                                                                                            ||
346                                                                                                            (
347                                                                                                                    JQuery.isArray(res) && ( JQuery.inArray(thisToggleFieldsArray[k].value, res) != -1 || found || ( foundCount != 0 && foundCount == chkGrpValues2.length ) ) && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"
348                                                                                                            )
349                                                                                                     ){
350                                                                                                            var names = thisToggleFieldsArray[k].tName.split(",");
351                                                                                                            for(var n = 0; n < names.length; n++){
352                                                                                                                thisBfToggleFields(thisToggleFieldsArray[k].state, thisToggleFieldsArray[k].tCat, JQuery.trim(names[n]), thisBfDeactivateField);
353                                                                                                            }
354                                                                                                            //break;
355                                                                                                    }
356                                                                                                }
357											}
358										}
359									);
360									break;
361								case "radio":
362								case "checkbox":
363									var radioLength = JQuery("[name=\"ff_nm_"+toggleField.sName+"[]\"]").size();
364									for(var j = 0; j < radioLength; j++){
365                                                                                 JQuery("#" + JQuery("[name=\"ff_nm_"+toggleField.sName+"[]\"]").get(j).id ).unbind("click");
366										 JQuery("#" + JQuery("[name=\"ff_nm_"+toggleField.sName+"[]\"]").get(j).id ).click(										 	
367										 	function(){
368										 		// NOT O(n^2) since its ony executed on click event!
369										 		for( var k = 0; k < thisToggleFieldsArray.length; k++ ){
370										 			
371										 			// used for complex checkbox group case below
372										 			var chkGrpValues = new Array();
373										 			if(JQuery(this).get(0).checked && thisToggleFieldsArray[k].value.beginsWith("#", true) && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"){
374										 				chkGrpValues = thisToggleFieldsArray[k].value.substring(1, thisToggleFieldsArray[k].value.length).split("|");
375										 			}
376
377                                                                                                        if(thisToggleFieldsArray[k].condition == "isnot"){
378
379                                                                                                            if(
380                                                                                                                    // simple radio case for selected value
381                                                                                                                    ( JQuery(this).get(0).type == "radio" && JQuery(this).get(0).checked && JQuery(this).val() != thisToggleFieldsArray[k].value && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]" )
382                                                                                                                    ||
383                                                                                                                    // single checkbox case for checked/unchecked
384                                                                                                                    (
385                                                                                                                            JQuery(this).get(0).type == "checkbox" &&
386                                                                                                                            JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]" &&
387                                                                                                                            ( JQuery(this).get(0).checked && thisToggleFieldsArray[k].value != "!checked"
388                                                                                                                             ||
389                                                                                                                              JQuery(this).get(0).checked && thisToggleFieldsArray[k].value == "!unchecked"
390                                                                                                                            )
391                                                                                                                    )
392                                                                                                                    ||
393                                                                                                                    // complex checkbox/radio group case by multiple values
394                                                                                                                    (
395                                                                                                                            JQuery(this).get(0).checked && JQuery.inArray(JQuery(this).val(), chkGrpValues) == -1 && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"
396                                                                                                                    )
397                                                                                                                    ||
398                                                                                                                    // simple checkbox group case by single value
399                                                                                                                    (
400                                                                                                                            JQuery(this).get(0).type == "checkbox" && JQuery(this).get(0).checked && JQuery(this).val() != thisToggleFieldsArray[k].value && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"
401                                                                                                                    )
402                                                                                                            ){
403                                                                                                                    var names = thisToggleFieldsArray[k].tName.split(",");
404                                                                                                                    for(var n = 0; n < names.length; n++){
405                                                                                                                        thisBfToggleFields(thisToggleFieldsArray[k].state, thisToggleFieldsArray[k].tCat, JQuery.trim(names[n]), thisBfDeactivateField);
406                                                                                                                    }
407                                                                                                                    //break;
408                                                                                                            }
409                                                                                                        }
410                                                                                                        else
411                                                                                                        if(thisToggleFieldsArray[k].condition == "is"){
412                                                                                                            if(
413                                                                                                                    // simple radio case for selected value
414                                                                                                                    ( JQuery(this).get(0).type == "radio" && JQuery(this).get(0).checked && JQuery(this).val() == thisToggleFieldsArray[k].value && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]" )
415                                                                                                                    ||
416                                                                                                                    // single checkbox case for checked/unchecked
417                                                                                                                    (
418                                                                                                                            JQuery(this).get(0).type == "checkbox" &&
419                                                                                                                            JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]" &&
420                                                                                                                            ( JQuery(this).get(0).checked && thisToggleFieldsArray[k].value == "!checked"
421                                                                                                                             ||
422                                                                                                                              !JQuery(this).get(0).checked && thisToggleFieldsArray[k].value == "!unchecked"
423                                                                                                                            )
424                                                                                                                    )
425                                                                                                                    ||
426                                                                                                                    // complex checkbox/radio group case by multiple values
427                                                                                                                    (
428                                                                                                                            JQuery(this).get(0).checked && JQuery.inArray(JQuery(this).val(), chkGrpValues) != -1 && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"
429                                                                                                                    )
430                                                                                                                    ||
431                                                                                                                    // simple checkbox group case by single value
432                                                                                                                    (
433                                                                                                                            JQuery(this).get(0).type == "checkbox" && JQuery(this).get(0).checked && JQuery(this).val() == thisToggleFieldsArray[k].value && JQuery(this).get(0).name == "ff_nm_"+thisToggleFieldsArray[k].sName+"[]"
434                                                                                                                    )
435                                                                                                            ){
436                                                                                                                    var names = thisToggleFieldsArray[k].tName.split(",");
437                                                                                                                    for(var n = 0; n < names.length; n++){
438                                                                                                                        thisBfToggleFields(thisToggleFieldsArray[k].state, thisToggleFieldsArray[k].tCat, JQuery.trim(names[n]), thisBfDeactivateField);
439                                                                                                                    }
440                                                                                                                    //break;
441                                                                                                            }
442                                                                                                        }
443												}
444												
445											}
446										 );
447									}
448									break;
449							}
450						}
451					}
452                                        
453                                        limit_cnt++;
454                                        last_offset = i;
455                                }
456                                
457                                if( last_offset+1 < toggleFieldsArray.length ){ setTimeout("bfRegisterToggleFields( "+last_offset+" )", 350); }
458                        }';
459			
460		}
461		
462		JFactory::getDocument()->addScriptDeclaration(
463                        $jQuery.'
464			var inlineErrorElements = new Array();
465			var bfSummarizers = new Array();
466			var bfDeactivateField = new Array();
467			var bfDeactivateSection = new Array();
468			'.$toggleCode.'
469			function bfCheckMaxlength(id, maxlength, showMaxlength){
470				if( JQuery("#ff_elem"+id).val().length > maxlength ){
471					JQuery("#ff_elem"+id).val( JQuery("#ff_elem"+id).val().substring(0, maxlength) );
472				}
473				if(showMaxlength){
474					JQuery("#bfMaxLengthCounter"+id).text( "(" + (maxlength - JQuery("#ff_elem"+id).val().length) + " '.BFText::_('COM_BREEZINGFORMS_CHARS_LEFT').')" );
475				}
476			}
477			function bfRegisterSummarize(id, connectWith, type, emptyMessage, hideIfEmpty){
478				bfSummarizers.push( { id : id, connectWith : connectWith, type : type, emptyMessage : emptyMessage, hideIfEmpty : hideIfEmpty } );
479			}
480			function bfField(name){
481				var value = "";
482				switch(ff_getElementByName(name).type){
483					case "radio":
484						if(JQuery("[name="+ff_getElementByName(name).name+"]:checked").val() != "" && typeof JQuery("[name="+ff_getElementByName(name).name+"]:checked").val() != "undefined"){
485							value = JQuery("[name="+ff_getElementByName(name).name+"]:checked").val();
486							if(!isNaN(value)){
487								value = Number(value);
488							}
489						}
490						break;
491					case "checkbox":
492					case "select-one":
493					case "select-multiple":
494						var nodeList = document["'.$this->p->form_id.'"][""+ff_getElementByName(name).name+""];
495						if(ff_getElementByName(name).type == "checkbox" && typeof nodeList.length == "undefined"){
496							if(typeof JQuery("[name="+ff_getElementByName(name).name+"]:checked").val() != "undefined"){
497								value = JQuery("[name="+ff_getElementByName(name).name+"]:checked").val();
498								if(!isNaN(value)){
499									value = Number(value);
500								}
501							}
502						} else {
503							var val = "";
504							for(var j = 0; j < nodeList.length; j++){
505								if(nodeList[j].checked || nodeList[j].selected){
506									val += nodeList[j].value + ", ";
507								}
508							}
509							if(val != ""){
510								value = val.substr(0, val.length - 2);
511								if(!isNaN(value)){
512									value = Number(value);
513								}
514							}
515						}
516						break;
517					default:
518						if(!isNaN(ff_getElementByName(name).value)){
519							value = Number(ff_getElementByName(name).value);
520						} else {
521							value = ff_getElementByName(name).value;
522						}
523				}
524				return value;
525			}
526			function populateSummarizers(){
527				// cleaning first
528                                
529				for(var i = 0; i < bfSummarizers.length; i++){
530					JQuery("#"+bfSummarizers[i].id).parent().css("display", "");
531					JQuery("#"+bfSummarizers[i].id).html("<span class=\"bfNotAvailable\">"+bfSummarizers[i].emptyMessage+"</span>");
532				}
533				for(var i = 0; i < bfSummarizers.length; i++){
534					var summVal = "";
535					switch(bfSummarizers[i].type){
536						case "bfTextfield":
537						case "bfTextarea":
538						case "bfHidden":
539						case "bfCalendar":
540						case "bfFile":
541							if(JQuery("[name=\"ff_nm_"+bfSummarizers[i].connectWith+"[]\"]").val() != ""){
542								JQuery("#"+bfSummarizers[i].id).text( JQuery("[name=\"ff_nm_"+bfSummarizers[i].connectWith+"[]\"]").val() ).html();
543								var breakableText = JQuery("#"+bfSummarizers[i].id).html().replace(/\\r/g, "").replace(/\\n/g, "<br/>");
544								
545								if(breakableText != ""){
546									var calc = null;
547									eval( "calc = typeof bfFieldCalc"+bfSummarizers[i].id+" != \"undefined\" ? bfFieldCalc"+bfSummarizers[i].id+" : null" );
548									if(calc){
549										breakableText = calc(breakableText);
550									}
551								}
552								
553								JQuery("#"+bfSummarizers[i].id).html(breakableText);
554								summVal = breakableText;
555							}
556						break;
557						case "bfRadioGroup":
558						case "bfCheckbox":
559							if(JQuery("[name=\"ff_nm_"+bfSummarizers[i].connectWith+"[]\"]:checked").val() != "" && typeof JQuery("[name=\"ff_nm_"+bfSummarizers[i].connectWith+"[]\"]:checked").val() != "undefined"){
560								var theText = JQuery("[name=\"ff_nm_"+bfSummarizers[i].connectWith+"[]\"]:checked").val();
561								if(theText != ""){
562									var calc = null;
563									eval( "calc = typeof bfFieldCalc"+bfSummarizers[i].id+" != \"undefined\" ? bfFieldCalc"+bfSummarizers[i].id+" : null" );
564									if(calc){
565										theText = calc(theText);
566									}
567								}
568								JQuery("#"+bfSummarizers[i].id).text( theText );
569								summVal = theText;
570							}
571						break;
572						case "bfCheckboxGroup":
573						case "bfSelect":
574							var val = "";
575							var nodeList = document["'.$this->p->form_id.'"]["ff_nm_"+bfSummarizers[i].connectWith+"[]"];
576							
577							for(var j = 0; j < nodeList.length; j++){
578								if(nodeList[j].checked || nodeList[j].selected){
579									val += nodeList[j].value + ", ";
580								}
581							}
582							if(val != ""){
583								var theText = val.substr(0, val.length - 2);
584								if(theText != ""){
585									var calc = null;
586									eval( "calc = typeof bfFieldCalc"+bfSummarizers[i].id+" != \"undefined\" ? bfFieldCalc"+bfSummarizers[i].id+" : null" );
587									if(calc){
588										theText = calc(theText);
589									}
590								}
591								JQuery("#"+bfSummarizers[i].id).text( theText );
592								summVal = theText;
593							}
594						break;
595					}
596					
597					if( ( bfSummarizers[i].hideIfEmpty && summVal == "" ) || ( typeof bfDeactivateField != "undefined" && bfDeactivateField["ff_nm_"+bfSummarizers[i].connectWith+"[]"] ) ){
598                                            JQuery("#"+bfSummarizers[i].id).parent().css("display", "none");
599					}
600				}
601			}
602');
603		
604		if($this->fading || !$this->useErrorAlerts || $this->rollover){
605			if(!$this->useErrorAlerts){
606                                $defaultErrors = '';
607                                if($this->useDefaultErrors || (!$this->useDefaultErrors && !$this->useBalloonErrors)){
608                                    $defaultErrors = 'JQuery(".bfErrorMessage").html("");
609					JQuery(".bfErrorMessage").css("display","none");
610					JQuery(".bfErrorMessage").fadeIn(1500);
611					var allErrors = "";
612					var errors = error.split("\n");
613					for(var i = 0; i < errors.length; i++){
614						allErrors += "<div class=\"bfError\">" + errors[i] + "</div>";
615					}
616					JQuery(".bfErrorMessage").html(allErrors);
617					JQuery(".bfErrorMessage").css("display","");';
618                                }
619				JFactory::getDocument()->addScriptDeclaration('var bfUseErrorAlerts = false;'."\n");
620				JFactory::getDocument()->addScriptDeclaration('
621				function bfShowErrors(error){
622                                        '.$defaultErrors.'
623
624                                        if(JQuery.bfvalidationEngine)
625                                        {
626                                            JQuery("#'.$this->p->form_id.'").bfvalidationEngine({
627                                              promptPosition: "bottomLeft",
628                                              success :  false,
629                                              failure : function() {}
630                                            });
631
632                                            for(var i = 0; i < inlineErrorElements.length; i++)
633                                            {
634                                                if(inlineErrorElements[i][1] != "")
635                                                {
636                                                    var prompt = null;
637                                                    
638                                                    if(inlineErrorElements[i][0] == "bfCaptchaEntry"){
639                                                        prompt = JQuery.bfvalidationEngine.buildPrompt("#bfCaptchaEntry",inlineErrorElements[i][1],"error");
640                                                    }
641                                                    else if(inlineErrorElements[i][0] == "bfReCaptchaEntry"){
642                                                        // nothing here yet for recaptcha, alert is default
643                                                        alert(inlineErrorElements[i][1]);
644                                                    }
645                                                    else if(typeof JQuery("#flashUpload"+inlineErrorElements[i][0]).get(0) != "undefined")
646                                                    {
647                                                        prompt = JQuery.bfvalidationEngine.buildPrompt("#"+JQuery("#flashUpload"+inlineErrorElements[i][0]).val(),inlineErrorElements[i][1],"error");
648                                                    }
649                                                    else
650                                                    {
651                                                        if(ff_getElementByName(inlineErrorElements[i][0])){
652                                                            prompt = JQuery.bfvalidationEngine.buildPrompt("#"+ff_getElementByName(inlineErrorElements[i][0]).id,inlineErrorElements[i][1],"error");
653                                                        }else{
654                                                            alert(inlineErrorElements[i][1]);
655                                                        }
656                                                    }
657                                                    
658                                                    JQuery(prompt).mouseover(
659                                                        function(){
660                                                            var inlineError = JQuery(this).attr("class").split(" ");
661                                                            if(inlineError && inlineError.length && inlineError.length == 2){
662                                                                var result = inlineError[1].split("formError");
663                                                                if(result && result.length && result.length >= 1){
664                                                                    JQuery.bfvalidationEngine.closePrompt("#"+result[0]);
665                                                                }
666                                                            }
667                                                        }
668                                                    );
669                                                }
670                                                else
671                                                {
672                                                    if(typeof JQuery("#flashUpload"+inlineErrorElements[i][0]).get(0) != "undefined")
673                                                    {
674                                                        JQuery.bfvalidationEngine.closePrompt("#"+JQuery("#flashUpload"+inlineErrorElements[i][0]).val());
675                                                    }
676                                                    else
677                                                    {
678                                                        if(ff_getElementByName(inlineErrorElements[i][0])){
679                                                            JQuery.bfvalidationEngine.closePrompt("#"+ff_getElementByName(inlineErrorElements[i][0]).id);
680                                                        }
681                                                    }
682                                                }
683                                            }
684                                            inlineErrorElements = new Array();
685                                        }
686				}');
687			}
688			if($this->fading){
689				$this->fadingClass = ' bfFadingClass';
690				$this->fadingCall  = 'bfFade();';
691				JFactory::getDocument()->addScriptDeclaration('
692					function bfFade(){
693						JQuery(".bfPageIntro").fadeIn(1000);
694						var size = 0;
695						JQuery(".bfFadingClass").each(function(i,val){
696							var t = this;
697							setTimeout(function(){JQuery(t).fadeIn(1000)}, (i*100));
698							size = i;
699						});
700						setTimeout(\'JQuery(".bfSubmitButton").fadeIn(1000)\', size * 100);
701						setTimeout(\'JQuery(".bfPrevButton").fadeIn(1000)\', size * 100);
702						setTimeout(\'JQuery(".bfNextButton").fadeIn(1000)\', size * 100);
703						setTimeout(\'JQuery(".bfCancelButton").fadeIn(1000)\', size * 100);
704					}
705				');
706			}
707                        
708			if($this->rollover && trim($this->rolloverColor) != ''){
709				JFactory::getDocument()->addScriptDeclaration('
710					var bfElemWrapBg = "";
711					function bfSetElemWrapBg(){
712						bfElemWrapBg = JQuery(".bfElemWrap").css("background-color");
713					}
714					function bfRollover() {
715						JQuery(".ff_elem").focus(
716							function(){
717								var parent = JQuery(this).parent();
718								if(parent && parent.attr("class").substr(0, 10) == "bfElemWrap"){
719									parent.css("background","'.$this->rolloverColor.'");
720								} else {
721									parent = JQuery(this).parent().parent();
722									parent.css("background","'.$this->rolloverColor.'");
723								}
724                                                                parent.addClass("bfRolloverBg");
725							}
726						).blur(
727							function(){
728								var parent = JQuery(this).parent();
729								if(parent && parent.attr("class").substr(0, 10) == "bfElemWrap"){
730									parent.css("background",bfElemWrapBg);
731								} else {
732									parent = JQuery(this).parent().parent();
733									parent.css("background",bfElemWrapBg);
734								}
735                                                                parent.removeClass("bfRolloverBg");
736							}
737						);
738					}
739					function bfRollover2() {
740						JQuery(".bfElemWrap").mouseover(
741							function(){
742								JQuery(this).css("background","'.$this->rolloverColor.'");
743                                                                JQuery(this).addClass("bfRolloverBg");
744							}
745						);
746						JQuery(".bfElemWrap").mouseout(
747							function(){
748								JQuery(this).css("background",bfElemWrapBg);
749                                                                JQuery(this).removeClass("bfRolloverBg");
750							}
751						);
752					}
753				');
754			}
755		}
756		JFactory::getDocument()->addScriptDeclaration('
757			JQuery(document).ready(function() {
758				if(typeof bfFade != "undefined")bfFade();
759				if(typeof bfSetElemWrapBg != "undefined")bfSetElemWrapBg();
760				if(typeof bfRollover != "undefined")bfRollover();

Large files files are truncated, but you can click here to view the full file