$versions{'htmlcssjs_includes_builder.pl'} = '06.6.00.0000';

# Contains all sub routines (functions) for building and saving HTML metatags, CSS and
# Javascript files to include in HTML token/variable calls from templates --
# (dynamic inclusions via tokens that are replaced with variables created here)
#
# Previously in Main Settings, then Template Manager, but now abstracted so that
# multiple manager settings areas can properly save any updates or inclusions needed
# in the store headers or footers.  Add-ons can now save any thing they need to include
# if added onto existing/supported variables.
#
#######################################################################
#
# AgoraCart and all associated files, except where noted, are
# Copyright 2001 to Present jointly by K-Factor Technologies, Inc.
# and by C E Mayo (aka Mister Ed) at AgoraCart.com & K-Factor.net
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This copyright notice may not be removed or altered in any way.
#
#######################################################################

{
    local ($modname) = 'htmlcssjs_includes_builder';
    register_extension( $modname, 'HTML CSS JS Includes Builder', $versions{$modname} );
}

#######################################################################

sub write_html_css_js_includes {

    my $myset2 = q{};

    if ( $mgr_is_manifest_loaded ne 'yes' ) {
      require_supporting_libraries( __FILE__, __LINE__,
          "$sc_hedfut_templates_dir/$sc_headerTemplateRoot/$sc_hedfut_template_manifest" );
    }

    my $temp_template_dir_URL = $sc_hedfut_templates_dir;
    $temp_template_dir_URL =~ s/\.\///; # strip off relative path: ./

    # currently known buySafe call:
    my $buysafe_header_string = qq|
<script src="https://seal.buysafe.com/private/rollover/rollover.js" charset="utf-8"></script>
<script>
function buySAFEOnClick(WantsBond)
{
  document.cartForm.buySAFE.value = WantsBond;
  document.cartForm.submit();
}
</script>
|;

    if ( $sc_buySafe_is_enabled !~ /yes/i ) {
        $buysafe_header_string = q{};
    }


    # BEGIN  Header & CSS builder
    $myset2 .= qq[\$sc_header_charset = qq|$mgr_template_html_header_metatag_charset{$sc_headerTemplateRoot}|;\n];
    $myset2 .= qq[\$sc_standard_head_info = qq|$mgr_template_html_header_metatags{$sc_headerTemplateRoot}\n];
    $mgr_css_framework_and_font_files{$sc_headerTemplateRoot} =~ s/\[\[LocalFile\]\]/$sc_SSL_base_URL$temp_template_dir_URL\/$sc_headerTemplateRoot/g;
    $mgr_css_framework_and_font_files{$sc_headerTemplateRoot} =~ s/\[\[AssetFile\]\]/$sc_SSL_base_URL$sc_viewer_assets_dir_URL/g;
    $myset2 .= qq|$mgr_css_framework_and_font_files{$sc_headerTemplateRoot}\n|;
    $myset2 .= "\n<!-- Custom CSS for this template -->\n";
    if ( ( $sc_template_css_enabled eq 'yes' ) && ( $sc_template_css_file ) ) {
      $myset2 .= q|<link rel="stylesheet" href="| . $sc_SSL_base_URL . $sc_template_css_file . qq|">\n|;
    }

    if ( $sc_agoracolors_css_enabled eq 'yes' ) {
      $myset2 .= q|<link rel="stylesheet" href="| . $sc_SSL_base_URL . q|agoracolors.css">\n|;
    }

    $myset2 .= qq~$buysafe_header_string\n|;\n~;

    ######### END of $sc_standard_head_info && Header & CSS builder



    # Javascript list builder
    $mgr_template_js_file_group{$sc_headerTemplateRoot} =~ s/\[\[LocalFile\]\]/$sc_SSL_base_URL$temp_template_dir_URL\/$sc_headerTemplateRoot/g;
    $mgr_template_js_file_group{$sc_headerTemplateRoot} =~ s/\[\[AssetFile\]\]/$sc_SSL_base_URL$sc_viewer_assets_dir_URL/g;

    $myset2 .= qq[\$sc_template_javascript_includes = qq|];
    $myset2 .= qq|$mgr_template_js_file_group{$sc_headerTemplateRoot}\n|;
    if ( ( $sc_template_js_enabled eq 'yes' ) && ( $sc_template_js_file ) ) {
      $myset2 .= qq|<!-- Template JS -->\n<script src="$sc_SSL_base_URL$sc_template_js_file"></script>\n|;
    }
    $myset2 .= qq|$sc_header_or_footer_tags\n|;
    $myset2 .= qq~\n|;\n~; # end of $sc_template_javascript_includes



    update_store_settings( 'INCLUDESHTMLCSSJS', $myset2 );   # save the variable set in user settings
}

#######################################################################

1;
