
function scJQGeneralAdd() {
  scLoadScInput('input:text.sc-js-input');
  scLoadScInput('input:password.sc-js-input');
  scLoadScInput('input:checkbox.sc-js-input');
  scLoadScInput('input:radio.sc-js-input');
  scLoadScInput('select.sc-js-input');
  scLoadScInput('textarea.sc-js-input');

} // scJQGeneralAdd

function scFocusField(sField) {
  var $oField = $('#id_sc_field_' + sField);

  if (0 == $oField.length) {
    $oField = $('input[name=' + sField + ']');
  }

  if (0 == $oField.length && document.F1.elements[sField]) {
    $oField = $(document.F1.elements[sField]);
  }

  if ($("#id_ac_" + sField).length > 0) {
    if ($oField.hasClass("select2-hidden-accessible")) {
      if (false == scSetFocusOnField($oField)) {
        setTimeout(function() { scSetFocusOnField($oField); }, 500);
      }
    }
    else {
      if (false == scSetFocusOnField($oField)) {
        if (false == scSetFocusOnField($("#id_ac_" + sField))) {
          setTimeout(function() { scSetFocusOnField($("#id_ac_" + sField)); }, 500);
        }
      }
      else {
        setTimeout(function() { scSetFocusOnField($oField); }, 500);
      }
    }
  }
  else {
    setTimeout(function() { scSetFocusOnField($oField); }, 500);
  }
} // scFocusField

function scSetFocusOnField($oField) {
  if ($oField.length > 0 && $oField[0].offsetHeight > 0 && $oField[0].offsetWidth > 0 && !$oField[0].disabled) {
    $oField[0].focus();
    return true;
  }
  return false;
} // scSetFocusOnField

function scEventControl_init(iSeqRow) {
  scEventControl_data["prenom" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
  scEventControl_data["nom" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
  scEventControl_data["age" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
  scEventControl_data["sexe" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
  scEventControl_data["wilaya" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
  scEventControl_data["commune" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
  scEventControl_data["adresse" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
  scEventControl_data["lieu_travail" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
  scEventControl_data["symptomes" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
  scEventControl_data["antecedents" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
  scEventControl_data["hospitalisation" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
  scEventControl_data["evacuation" + iSeqRow] = {"blur": false, "change": false, "autocomp": false, "original": "", "calculated": ""};
}

function scEventControl_active(iSeqRow) {
  if (scEventControl_data["prenom" + iSeqRow] && scEventControl_data["prenom" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["prenom" + iSeqRow] && scEventControl_data["prenom" + iSeqRow]["change"]) {
    return true;
  }
  if (scEventControl_data["nom" + iSeqRow] && scEventControl_data["nom" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["nom" + iSeqRow] && scEventControl_data["nom" + iSeqRow]["change"]) {
    return true;
  }
  if (scEventControl_data["age" + iSeqRow] && scEventControl_data["age" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["age" + iSeqRow] && scEventControl_data["age" + iSeqRow]["change"]) {
    return true;
  }
  if (scEventControl_data["sexe" + iSeqRow] && scEventControl_data["sexe" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["sexe" + iSeqRow] && scEventControl_data["sexe" + iSeqRow]["change"]) {
    return true;
  }
  if (scEventControl_data["wilaya" + iSeqRow] && scEventControl_data["wilaya" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["wilaya" + iSeqRow] && scEventControl_data["wilaya" + iSeqRow]["change"]) {
    return true;
  }
  if (scEventControl_data["commune" + iSeqRow] && scEventControl_data["commune" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["commune" + iSeqRow] && scEventControl_data["commune" + iSeqRow]["change"]) {
    return true;
  }
  if (scEventControl_data["adresse" + iSeqRow] && scEventControl_data["adresse" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["adresse" + iSeqRow] && scEventControl_data["adresse" + iSeqRow]["change"]) {
    return true;
  }
  if (scEventControl_data["lieu_travail" + iSeqRow] && scEventControl_data["lieu_travail" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["lieu_travail" + iSeqRow] && scEventControl_data["lieu_travail" + iSeqRow]["change"]) {
    return true;
  }
  if (scEventControl_data["symptomes" + iSeqRow] && scEventControl_data["symptomes" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["symptomes" + iSeqRow] && scEventControl_data["symptomes" + iSeqRow]["change"]) {
    return true;
  }
  if (scEventControl_data["antecedents" + iSeqRow] && scEventControl_data["antecedents" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["antecedents" + iSeqRow] && scEventControl_data["antecedents" + iSeqRow]["change"]) {
    return true;
  }
  if (scEventControl_data["hospitalisation" + iSeqRow] && scEventControl_data["hospitalisation" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["hospitalisation" + iSeqRow] && scEventControl_data["hospitalisation" + iSeqRow]["change"]) {
    return true;
  }
  if (scEventControl_data["evacuation" + iSeqRow] && scEventControl_data["evacuation" + iSeqRow]["blur"]) {
    return true;
  }
  if (scEventControl_data["evacuation" + iSeqRow] && scEventControl_data["evacuation" + iSeqRow]["change"]) {
    return true;
  }
  return false;
} // scEventControl_active

function scEventControl_onFocus(oField, iSeq) {
  var fieldId, fieldName;
  fieldId = $(oField).attr("id");
  fieldName = fieldId.substr(12);
  scEventControl_data[fieldName]["blur"] = true;
  if ("wilaya" + iSeq == fieldName) {
    scEventControl_data[fieldName]["blur"] = false;
  }
  if ("commune" + iSeq == fieldName) {
    scEventControl_data[fieldName]["blur"] = false;
  }
  if ("symptomes" + iSeq == fieldName) {
    scEventControl_data[fieldName]["blur"] = false;
  }
  scEventControl_data[fieldName]["change"] = false;
} // scEventControl_onFocus

function scEventControl_onBlur(sFieldName) {
  scEventControl_data[sFieldName]["blur"] = false;
  if (scEventControl_data[sFieldName]["change"]) {
        if (scEventControl_data[sFieldName]["original"] == $("#id_sc_field_" + sFieldName).val() || scEventControl_data[sFieldName]["calculated"] == $("#id_sc_field_" + sFieldName).val()) {
          scEventControl_data[sFieldName]["change"] = false;
        }
  }
} // scEventControl_onBlur

function scEventControl_onChange(sFieldName) {
  scEventControl_data[sFieldName]["change"] = false;
} // scEventControl_onChange

function scEventControl_onAutocomp(sFieldName) {
  scEventControl_data[sFieldName]["autocomp"] = false;
} // scEventControl_onChange

var scEventControl_data = {};

function scJQEventsAdd(iSeqRow) {
  $('#id_sc_field_nom' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_nom_onblur(this, iSeqRow) })
                                 .bind('focus', function() { sc_fiche_pro_sante_nom_onfocus(this, iSeqRow) });
  $('#id_sc_field_prenom' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_prenom_onblur(this, iSeqRow) })
                                    .bind('focus', function() { sc_fiche_pro_sante_prenom_onfocus(this, iSeqRow) });
  $('#id_sc_field_age' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_age_onblur(this, iSeqRow) })
                                 .bind('focus', function() { sc_fiche_pro_sante_age_onfocus(this, iSeqRow) });
  $('#id_sc_field_sexe' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_sexe_onblur(this, iSeqRow) })
                                  .bind('focus', function() { sc_fiche_pro_sante_sexe_onfocus(this, iSeqRow) });
  $('#id_sc_field_wilaya' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_wilaya_onblur(this, iSeqRow) })
                                    .bind('change', function() { sc_fiche_pro_sante_wilaya_onchange(this, iSeqRow) })
                                    .bind('focus', function() { sc_fiche_pro_sante_wilaya_onfocus(this, iSeqRow) });
  $('#id_sc_field_commune' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_commune_onblur(this, iSeqRow) })
                                     .bind('focus', function() { sc_fiche_pro_sante_commune_onfocus(this, iSeqRow) });
  $('#id_sc_field_symptomes' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_symptomes_onblur(this, iSeqRow) })
                                       .bind('focus', function() { sc_fiche_pro_sante_symptomes_onfocus(this, iSeqRow) });
  $('#id_sc_field_antecedents' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_antecedents_onblur(this, iSeqRow) })
                                         .bind('focus', function() { sc_fiche_pro_sante_antecedents_onfocus(this, iSeqRow) });
  $('#id_sc_field_adresse' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_adresse_onblur(this, iSeqRow) })
                                     .bind('focus', function() { sc_fiche_pro_sante_adresse_onfocus(this, iSeqRow) });
  $('#id_sc_field_lieu_travail' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_lieu_travail_onblur(this, iSeqRow) })
                                          .bind('focus', function() { sc_fiche_pro_sante_lieu_travail_onfocus(this, iSeqRow) });
  $('#id_sc_field_hospitalisation' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_hospitalisation_onblur(this, iSeqRow) })
                                             .bind('focus', function() { sc_fiche_pro_sante_hospitalisation_onfocus(this, iSeqRow) });
  $('#id_sc_field_evacuation' + iSeqRow).bind('blur', function() { sc_fiche_pro_sante_evacuation_onblur(this, iSeqRow) })
                                        .bind('focus', function() { sc_fiche_pro_sante_evacuation_onfocus(this, iSeqRow) });
  $('.sc-ui-radio-sexe' + iSeqRow).on('click', function() { scMarkFormAsChanged(); });
  $('.sc-ui-radio-hospitalisation' + iSeqRow).on('click', function() { scMarkFormAsChanged(); });
  $('.sc-ui-radio-evacuation' + iSeqRow).on('click', function() { scMarkFormAsChanged(); });
} // scJQEventsAdd

function sc_fiche_pro_sante_nom_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_nom();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_nom_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function sc_fiche_pro_sante_prenom_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_prenom();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_prenom_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function sc_fiche_pro_sante_age_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_age();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_age_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function sc_fiche_pro_sante_sexe_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_sexe();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_sexe_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function sc_fiche_pro_sante_wilaya_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_wilaya();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_wilaya_onchange(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_refresh_wilaya();
}

function sc_fiche_pro_sante_wilaya_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function sc_fiche_pro_sante_commune_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_commune();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_commune_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function sc_fiche_pro_sante_symptomes_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_symptomes();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_symptomes_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function sc_fiche_pro_sante_antecedents_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_antecedents();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_antecedents_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function sc_fiche_pro_sante_adresse_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_adresse();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_adresse_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function sc_fiche_pro_sante_lieu_travail_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_lieu_travail();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_lieu_travail_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function sc_fiche_pro_sante_hospitalisation_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_hospitalisation();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_hospitalisation_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function sc_fiche_pro_sante_evacuation_onblur(oThis, iSeqRow) {
  do_ajax_fiche_pro_sante_mob_validate_evacuation();
  scCssBlur(oThis);
}

function sc_fiche_pro_sante_evacuation_onfocus(oThis, iSeqRow) {
  scEventControl_onFocus(oThis, iSeqRow);
  scCssFocus(oThis);
}

function displayChange_block(block, status) {
	if ("0" == block) {
		displayChange_block_0(status);
	}
	if ("1" == block) {
		displayChange_block_1(status);
	}
	if ("2" == block) {
		displayChange_block_2(status);
	}
	if ("3" == block) {
		displayChange_block_3(status);
	}
	if ("4" == block) {
		displayChange_block_4(status);
	}
	if ("5" == block) {
		displayChange_block_5(status);
	}
}

function displayChange_block_0(status) {
	displayChange_field("prenom", "", status);
	displayChange_field("nom", "", status);
	displayChange_field("age", "", status);
	displayChange_field("sexe", "", status);
}

function displayChange_block_1(status) {
	displayChange_field("wilaya", "", status);
	displayChange_field("commune", "", status);
}

function displayChange_block_2(status) {
	displayChange_field("adresse", "", status);
	displayChange_field("lieu_travail", "", status);
}

function displayChange_block_3(status) {
	displayChange_field("symptomes", "", status);
}

function displayChange_block_4(status) {
	displayChange_field("antecedents", "", status);
}

function displayChange_block_5(status) {
	displayChange_field("hospitalisation", "", status);
	displayChange_field("evacuation", "", status);
}

function displayChange_row(row, status) {
	displayChange_field_prenom(row, status);
	displayChange_field_nom(row, status);
	displayChange_field_age(row, status);
	displayChange_field_sexe(row, status);
	displayChange_field_wilaya(row, status);
	displayChange_field_commune(row, status);
	displayChange_field_adresse(row, status);
	displayChange_field_lieu_travail(row, status);
	displayChange_field_symptomes(row, status);
	displayChange_field_antecedents(row, status);
	displayChange_field_hospitalisation(row, status);
	displayChange_field_evacuation(row, status);
}

function displayChange_field(field, row, status) {
	if ("prenom" == field) {
		displayChange_field_prenom(row, status);
	}
	if ("nom" == field) {
		displayChange_field_nom(row, status);
	}
	if ("age" == field) {
		displayChange_field_age(row, status);
	}
	if ("sexe" == field) {
		displayChange_field_sexe(row, status);
	}
	if ("wilaya" == field) {
		displayChange_field_wilaya(row, status);
	}
	if ("commune" == field) {
		displayChange_field_commune(row, status);
	}
	if ("adresse" == field) {
		displayChange_field_adresse(row, status);
	}
	if ("lieu_travail" == field) {
		displayChange_field_lieu_travail(row, status);
	}
	if ("symptomes" == field) {
		displayChange_field_symptomes(row, status);
	}
	if ("antecedents" == field) {
		displayChange_field_antecedents(row, status);
	}
	if ("hospitalisation" == field) {
		displayChange_field_hospitalisation(row, status);
	}
	if ("evacuation" == field) {
		displayChange_field_evacuation(row, status);
	}
}

function displayChange_field_prenom(row, status) {
    var fieldId;
}

function displayChange_field_nom(row, status) {
    var fieldId;
}

function displayChange_field_age(row, status) {
    var fieldId;
}

function displayChange_field_sexe(row, status) {
    var fieldId;
}

function displayChange_field_wilaya(row, status) {
    var fieldId;
	if ("on" == status) {
		if ("all" == row) {
			var fieldList = $(".css_wilaya__obj");
			for (var i = 0; i < fieldList.length; i++) {
				$($(fieldList[i]).attr("id")).select2("destroy");
			}
		}
		else {
			$("#id_sc_field_wilaya" + row).select2("destroy");
		}
		scJQSelect2Add(row, "wilaya");
	}
}

function displayChange_field_commune(row, status) {
    var fieldId;
	if ("on" == status) {
		if ("all" == row) {
			var fieldList = $(".css_commune__obj");
			for (var i = 0; i < fieldList.length; i++) {
				$($(fieldList[i]).attr("id")).select2("destroy");
			}
		}
		else {
			$("#id_sc_field_commune" + row).select2("destroy");
		}
		scJQSelect2Add(row, "commune");
	}
}

function displayChange_field_adresse(row, status) {
    var fieldId;
}

function displayChange_field_lieu_travail(row, status) {
    var fieldId;
}

function displayChange_field_symptomes(row, status) {
    var fieldId;
	if ("on" == status) {
		if ("all" == row) {
			var fieldList = $(".css_symptomes__obj");
			for (var i = 0; i < fieldList.length; i++) {
				$($(fieldList[i]).attr("id")).select2("destroy");
			}
		}
		else {
			$("#id_sc_field_symptomes" + row).select2("destroy");
		}
		scJQSelect2Add(row, "symptomes");
	}
}

function displayChange_field_antecedents(row, status) {
    var fieldId;
}

function displayChange_field_hospitalisation(row, status) {
    var fieldId;
}

function displayChange_field_evacuation(row, status) {
    var fieldId;
}

function scRecreateSelect2() {
	displayChange_field_wilaya("all", "on");
	displayChange_field_commune("all", "on");
	displayChange_field_symptomes("all", "on");
}
function scResetPagesDisplay() {
	$(".sc-form-page").show();
}

function scHidePage(pageNo) {
	$("#id_fiche_pro_sante_mob_form" + pageNo).hide();
}

function scCheckNoPageSelected() {
	if (!$(".sc-form-page").filter(".scTabActive").filter(":visible").length) {
		var inactiveTabs = $(".sc-form-page").filter(".scTabInactive").filter(":visible");
		if (inactiveTabs.length) {
			var tabNo = $(inactiveTabs[0]).attr("id").substr(27);
		}
	}
}
function scJQSpinAdd(iSeqRow) {
  $("#id_sc_field_age" + iSeqRow).spinner({
    max: 120,
    min: 0,
    step: 1,
    page: 5,
    change: function(event, ui) {
      $(this).trigger("change");
    },
    stop: function(event, ui) {
      $(this).trigger("change");
    }
  });
} // scJQSpinAdd

function scJQUploadAdd(iSeqRow) {
} // scJQUploadAdd

var api_cache_requests = [];
function ajax_check_file(img_name, field  ,t, p, p_cache, iSeqRow, hasRun, img_before){
    setTimeout(function(){
        if(img_name == '') return;
        iSeqRow= iSeqRow !== undefined && iSeqRow !== null ? iSeqRow : '';
        var hasVar = p.indexOf('_@NM@_') > -1 || p_cache.indexOf('_@NM@_') > -1 ? true : false;

        p = p.split('_@NM@_');
        $.each(p, function(i,v){
            try{
                p[i] = $('[name='+v+iSeqRow+']').val();
            }
            catch(err){
                p[i] = v;
            }
        });
        p = p.join('');

        p_cache = p_cache.split('_@NM@_');
        $.each(p_cache, function(i,v){
            try{
                p_cache[i] = $('[name='+v+iSeqRow+']').val();
            }
            catch(err){
                p_cache[i] = v;
            }
        });
        p_cache = p_cache.join('');

        img_before = img_before !== undefined ? img_before : $(t).attr('src');
        var str_key_cache = '<?php echo $this->Ini->sc_page; ?>' + img_name+field+p+p_cache;
        if(api_cache_requests[ str_key_cache ] !== undefined && api_cache_requests[ str_key_cache ] !== null){
            if(api_cache_requests[ str_key_cache ] != false){
                do_ajax_check_file(api_cache_requests[ str_key_cache ], field  ,t, iSeqRow);
            }
            return;
        }
        //scAjaxProcOn();
        $(t).attr('src', '<?php echo $this->Ini->path_icones ?>/scriptcase__NM__ajax_load.gif');
        api_cache_requests[ str_key_cache ] = false;
        var rs =$.ajax({
                    type: "POST",
                    url: 'index.php?script_case_init=<?php echo $this->Ini->sc_page; ?>',
                    async: true,
                    data:'nmgp_opcao=ajax_check_file&AjaxCheckImg=' + encodeURI(img_name) +'&rsargs='+ field + '&p=' + p + '&p_cache=' + p_cache,
                    success: function (rs) {
                        if(rs.indexOf('</span>') != -1){
                            rs = rs.substr(rs.indexOf('</span>') + 7);
                        }
                        if(rs.indexOf('/') != -1 && rs.indexOf('/') != 0){
                            rs = rs.substr(rs.indexOf('/'));
                        }
                        rs = sc_trim(rs);

                        // if(rs == 0 && hasVar && hasRun === undefined){
                        //     delete window.api_cache_requests[ str_key_cache ];
                        //     ajax_check_file(img_name, field  ,t, p, p_cache, iSeqRow, 1, img_before);
                        //     return;
                        // }
                        window.api_cache_requests[ str_key_cache ] = rs;
                        do_ajax_check_file(rs, field  ,t, iSeqRow)
                        if(rs == 0){
                            delete window.api_cache_requests[ str_key_cache ];

                           // $(t).attr('src',img_before);
                            do_ajax_check_file(img_before+'_@@NM@@_' + img_before, field  ,t, iSeqRow)

                        }


                    }
        });
    },100);
}

function do_ajax_check_file(rs, field  ,t, iSeqRow){
    if (rs != 0) {
        rs_split = rs.split('_@@NM@@_');
        rs_orig = rs_split[0];
        rs2 = rs_split[1];
        try{
            if(!$(t).is('img')){

                if($('#id_read_on_'+field+iSeqRow).length > 0 ){
                                    var usa_read_only = false;

                switch(field){

                }
                     if(usa_read_only && $('a',$('#id_read_on_'+field+iSeqRow)).length == 0){
                         $(t).html("<a href=\"javascript:nm_mostra_doc('0', '"+rs2+"', 'fiche_pro_sante_mob')\">"+$('#id_read_on_'+field+iSeqRow).text()+"</a>");
                     }
                }
                if($('#id_ajax_doc_'+field+iSeqRow+' a').length > 0){
                    var target = $('#id_ajax_doc_'+field+iSeqRow+' a').attr('href').split(',');
                    target[1] = "'"+rs2+"'";
                    $('#id_ajax_doc_'+field+iSeqRow+' a').attr('href', target.join(','));
                }else{
                    var target = $(t).attr('href').split(',');
                     target[1] = "'"+rs2+"'";
                     $(t).attr('href', target.join(','));
                }
            }else{
                $(t).attr('src', rs2);
                $(t).css('display', '');
                if($('#id_ajax_doc_'+field+iSeqRow+' a').length > 0){
                    var target = $('#id_ajax_doc_'+field+iSeqRow+' a').attr('href').split(',');
                    target[1] = "'"+rs2+"'";
                    $(t).attr('href', target.join(','));
                }else{
                     var t_link = $(t).parent('a');
                     var target = $(t_link).attr('href').split(',');
                     target[0] = "javascript:nm_mostra_img('"+rs_orig+"'";
                     $(t_link).attr('href', target.join(','));
                }

            }
            eval("window.var_ajax_img_"+field+iSeqRow+" = '"+rs_orig+"';");

        } catch(err){
                        eval("window.var_ajax_img_"+field+iSeqRow+" = '"+rs_orig+"';");

        }
    }
   /* hasFalseCacheRequest = false;
    $.each(api_cache_requests, function(i,v){
        if(v == false){
            hasFalseCacheRequest = true;
        }
    });
    if(hasFalseCacheRequest == false){
        scAjaxProcOff();
    }*/
}

$(document).ready(function(){
});

function scJQPasswordToggleAdd(seqRow) {
  $(".sc-ui-pwd-toggle-icon" + seqRow).on("click", function() {
    var fieldName = $(this).attr("id").substr(17), fieldObj = $("#id_sc_field_" + fieldName), fieldFA = $("#id_pwd_fa_" + fieldName);
    if ("text" == fieldObj.attr("type")) {
      fieldObj.attr("type", "password");
      fieldFA.attr("class", "fa fa-eye sc-ui-pwd-eye");
    } else {
      fieldObj.attr("type", "text");
      fieldFA.attr("class", "fa fa-eye-slash sc-ui-pwd-eye");
    }
  });
} // scJQPasswordToggleAdd

function scJQSelect2Add(seqRow, specificField) {
  if (null == specificField || "wilaya" == specificField) {
    scJQSelect2Add_wilaya(seqRow);
  }
  if (null == specificField || "commune" == specificField) {
    scJQSelect2Add_commune(seqRow);
  }
  if (null == specificField || "symptomes" == specificField) {
    scJQSelect2Add_symptomes(seqRow);
  }
} // scJQSelect2Add

function scJQSelect2Add_wilaya(seqRow) {
  var elemSelector = "all" == seqRow ? ".css_wilaya_obj" : "#id_sc_field_wilaya" + seqRow;
  $(elemSelector).select2(
    {
      containerCssClass: 'css_wilaya_obj',
      dropdownCssClass: 'css_wilaya_obj',
      language: {
        noResults: function() {
          return "<?php echo $this->Ini->Nm_lang['lang_autocomp_notfound'] ?>";
        },
        searching: function() {
          return "<?php echo $this->Ini->Nm_lang['lang_autocomp_searching'] ?>";
        }
      }
    }
  );
} // scJQSelect2Add

function scJQSelect2Add_commune(seqRow) {
  var elemSelector = "all" == seqRow ? ".css_commune_obj" : "#id_sc_field_commune" + seqRow;
  $(elemSelector).select2(
    {
      containerCssClass: 'css_commune_obj',
      dropdownCssClass: 'css_commune_obj',
      language: {
        noResults: function() {
          return "<?php echo $this->Ini->Nm_lang['lang_autocomp_notfound'] ?>";
        },
        searching: function() {
          return "<?php echo $this->Ini->Nm_lang['lang_autocomp_searching'] ?>";
        }
      }
    }
  );
} // scJQSelect2Add

function scJQSelect2Add_symptomes(seqRow) {
  var elemSelector = "all" == seqRow ? ".css_symptomes_obj" : "#id_sc_field_symptomes" + seqRow;
  $(elemSelector).select2(
    {
      containerCssClass: 'css_symptomes_obj',
      dropdownCssClass: 'css_symptomes_obj',
      language: {
        noResults: function() {
          return "<?php echo $this->Ini->Nm_lang['lang_autocomp_notfound'] ?>";
        },
        searching: function() {
          return "<?php echo $this->Ini->Nm_lang['lang_autocomp_searching'] ?>";
        }
      }
    }
  );
} // scJQSelect2Add


function scJQElementsAdd(iLine) {
  scJQEventsAdd(iLine);
  scEventControl_init(iLine);
  scJQSpinAdd(iLine);
  scJQUploadAdd(iLine);
  scJQPasswordToggleAdd(iLine);
  scJQSelect2Add(iLine);
  setTimeout(function () { if ('function' == typeof displayChange_field_wilaya) { displayChange_field_wilaya(iLine, "on"); } }, 150);
  setTimeout(function () { if ('function' == typeof displayChange_field_commune) { displayChange_field_commune(iLine, "on"); } }, 150);
  setTimeout(function () { if ('function' == typeof displayChange_field_symptomes) { displayChange_field_symptomes(iLine, "on"); } }, 150);
} // scJQElementsAdd

function scGetFileExtension(fileName)
{
    fileNameParts = fileName.split(".");

    if (1 === fileNameParts.length || (2 === fileNameParts.length && "" == fileNameParts[0])) {
        return "";
    }

    return fileNameParts.pop().toLowerCase();
}

function scFormatExtensionSizeErrorMsg(errorMsg)
{
    var msgInfo = errorMsg.split("||"), returnMsg = "";

    if ("err_size" == msgInfo[0]) {
        returnMsg = "<?php echo $this->Ini->Nm_lang['lang_errm_file_size'] ?>. <?php echo $this->Ini->Nm_lang['lang_errm_file_size_extension'] ?>".replace("{SC_EXTENSION}", msgInfo[1]).replace("{SC_LIMIT}", msgInfo[2]);
    } else if ("err_extension" == msgInfo[0]) {
        returnMsg = "<?php echo $this->Ini->Nm_lang['lang_errm_file_invl'] ?>";
    }

    return returnMsg;
}

