Can I delete this script (to save bandwidth)?

Discussion in 'JavaScript' started by mar08, Jun 16, 2006.

  1. #1
    I have a phpbb-Forum and one template I recently installed has this strange code:

    <script language="javascript" type="text/javascript">
    <!--

    var PreloadFlag = false;
    var expDays = 90;
    var exp = new Date();
    var tmp = '';
    var tmp_counter = 0;
    var tmp_open = 0;

    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

    function changeImages()
    {
    if (document.images)
    {
    for (var i=0; i<changeImages.arguments.length; i+=2)
    {
    document[changeImages.arguments].src = changeImages.arguments[i+1];
    }
    }
    }

    function newImage(arg)
    {
    if (document.images)
    {
    rslt = new Image();
    rslt.src = arg;
    return rslt;
    }
    }

    function PreloadImages()
    {
    if (document.images)
    {
    // preload all rollover images
    <!-- BEGIN switch_user_logged_out -->
    img0 = newImage('{T_TEMPLATE_PATH}/images/lang_{LANG}/btn_login_on.gif');
    img1 = newImage('{T_TEMPLATE_PATH}/images/lang_{LANG}/btn_register_on.gif');
    <!-- END switch_user_logged_out -->
    <!-- BEGIN switch_user_logged_in -->
    img2 = newImage('{T_TEMPLATE_PATH}/images/lang_{LANG}/btn_pm_on.gif');
    img3 = newImage('{T_TEMPLATE_PATH}/images/lang_{LANG}/btn_profile_on.gif');
    img4 = newImage('{T_TEMPLATE_PATH}/images/lang_{LANG}/btn_groups_on.gif');
    img5 = newImage('{T_TEMPLATE_PATH}/images/lang_{LANG}/btn_logout_on.gif');
    <!-- END switch_user_logged_in -->
    img6 = newImage('{T_TEMPLATE_PATH}/images/lang_{LANG}/btn_faq_on.gif');
    img7 = newImage('{T_TEMPLATE_PATH}/images/lang_{LANG}/btn_search_on.gif');
    img8 = newImage('{T_TEMPLATE_PATH}/images/lang_{LANG}/btn_users_on.gif');
    img9 = newImage('{T_TEMPLATE_PATH}/images/lang_{LANG}/btn_index_on.gif');
    PreloadFlag = true;
    }
    return true;
    }

    function SetCookie(name, value)
    {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2)? argv[2] : null;
    var path = (argc > 3)? argv[3] : null;
    var domain = (argc > 4)? argv[4] : null;
    var secure = (argc > 5)? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
    ((expires == null)? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null)? "" : ("; path=" + path)) +
    ((domain == null)? "" : ("; domain=" + domain)) +
    ((secure == true)? "; secure" : "");
    }

    function getCookieVal(offset)
    {
    var endstr = document.cookie.indexOf(";",offset);
    if (endstr == -1)
    {
    endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
    }

    function GetCookie(name)
    {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
    return getCookieVal(j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0)


    break;
    }
    return null;
    }

    //-->
    </script>


    Question: Can I delete it? I tried and if I remove it, there is no difference, must be sth for preloading images (which I don't use) and a cookie, but is it necessary? I tried to login and logout and everything worked very fine *without* that code.

    I would appreciate any comment (I habe obviously no idea about javascript)
     
    mar08, Jun 16, 2006 IP
  2. DXL

    DXL Peon

    Messages:
    380
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It indeed does some image preloading and cookie handling. Unless you utilize the cookie functions anywhere (I don't think so) you can safely delete it.
     
    DXL, Jun 16, 2006 IP
  3. mar08

    mar08 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you very much DXL! :)
     
    mar08, Jun 16, 2006 IP