﻿$(document).ready(function() {
    var watermark = 'Quick Tower Find: Enter City, County, State, Zip';

    //-- modal controller --//
    $('#find-small,#find-modal1,#find-modal2,#find-modal3').click(function() {
        callFloodlight('04fin684');
        $('div.searchbar').npModal({
            enableOverlayClose: true,
            isModal: true,
            toTop: true,
            width: '600px',
            overlay: 70
        });

        $('input.searchbox').focus();
        return false;
    });
    /* no click action on the headline for now.
    $('.advance_earth').click(function() {
    if ($('#find-expanded').is(':not(:visible)')) {
    if ($.browser.msie) {
    $('#find-expanded').show(0);
    $('#earth-glow-ie').animate({ opacity: 1.0 }, 400).fadeIn(500).fadeOut(1500);
    }
    else {
    $('#find-expanded').fadeIn();
    $('#earth-glow').animate({ opacity: 1.0 }, 400).fadeIn(500).fadeOut(1500);
    }
    }
    });
    */
    //-- filter animation --//
    $('input.searchbox', 'div.searchbar').focus(function() {
        //        if (LoggedIn == "False") {
        //            $("div[id*='advance_earth']").hide();
        //            $("#LoggedOverlay").css("display", "block");
        //        }
        // alert("hey");
        if ($("h4.logout").length == 0) {
          //  $("div[id*='advance_earth']").hide();
            $("div[id*='advance_earth'] p").replaceWith('<p style="font-size:18px; margin:-10px 0 -10px 0; padding:0;">&nbsp;</span></p>');
            $("div[id*='advance_earth'] span.promosubblock").replaceWith(' <span class="promosubblock">&nbsp;<br/>&nbsp;</span>');
        }
        if ($('#find-expanded').is(':not(:visible)')) {

            if ($.browser.msie) {
                $('#find-expanded').show(0);
                $('#earth-glow-ie').animate({ opacity: 1.0 }, 400).fadeIn(500).fadeOut(1500);
            }
            else {
                $('#find-expanded').fadeIn();
                $('#earth-glow').animate({ opacity: 1.0 }, 400).fadeIn(500).fadeOut(1500);
            }

        }

        //-- tooltip --//
        //$('div.tooltip').show();
        $('#tooltip1-hide').click(function() {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                url: rootpath + 'TowerCoService.asmx/HideToolTipCookie',
                data: '{}'
            });
        }).add('div.tooltip a.close').click(function() {
            $(this).parent().parent().remove();
        });
    }).Watermark(watermark);
    //-- textbox watermark --//

    $('#find-expanded-close').click(function() {

        if ($.browser.msie)
            $('#find-expanded').hide();
        else
            $('#find-expanded').fadeOut();
    });

    //    $('#find-expanded-close2').click(function() {
    //        $("div[id*='advance_earth']").show();
    //        $("#LoggedOverlay").hide();
    //    });

    //-- expand filter section --//
    $('#find-expanded h4').click(function() {
        if ($(this).parents('li').hasClass('on')) {
            $(this).parents('li').removeClass('on');
            $(this).siblings('div.filterbox').fadeOut();
        } else {
            $('#find-expanded div.filterbox').fadeOut(0, function() {
                $(this).parents('li').removeClass('on');
            });
            $(this).parents('li').addClass('on');
            $(this).siblings('div.filterbox').fadeIn();
        }
        $('#earth-glow').fadeOut();
        $('#earth-glow-ie').fadeOut();
    });

    //-- int validator --//
    $('input.int', '#find-filters').keypress(function(e) {
        if (e.which != 8 && e.which != 0 && e.which != 44 && e.which != 45 && (e.which < 48 || e.which > 57))
            return false;
    });

    //-- double validator --//
    $('input.double', '#find-filters').keypress(function(e) {
        if (e.which != 8 && e.which != 0 && e.which != 46 && e.which != 44 && e.which != 45 && (e.which < 48 || e.which > 57))
            return false;
    });

    //-- filter: latlong - keyup event --//
    $('#find-filter-latlong input:text').keyup(function() {
        $(this).removeClass('error');
        $('#latlong-error').html('').hide();

        if ($(this).attr('rel') != '') {
            var con = $(this).attr('rel');
            if (con.indexOf('|') > 0) {
                var min = parseFloat(con.split('|')[0]);
                var max = parseFloat(con.split('|')[1]);
                var val = parseFloat($(this).val());

                if (val < min || val > max) {
                    $(this).val($(this).val().substr(0, $(this).val().length - 1));
                    //alert('error: invalid parameter. must be between ' + min + ' and ' + max);

                    $(this).addClass('error');
                    $('#latlong-error').html('error: invalid parameter. must be between ' + min + ' and ' + max).show();
                }
            }
        }
    }).blur(function() {
        $(this).removeClass('error');
        $('#latlong-error').html('').hide();
    });

    $('#find-latd, #find-latm, #find-lats, #find-longd, #find-longm, #find-longs').keyup(function() {
        var $this = $(this);
        checkIsValid($this);
        var text = '';

        if ($('#find-latd').val() != '' || $('#find-latm').val() != '' || $('#find-lats').val() != '' ||
      $('#find-longd').val() != '' || $('#find-longm').val() != '' || $('#find-longs').val() != '') {
            var lat = 0;
            var latd = isNaN(parseInt($('#find-latd').val(), 10)) ? 0 : parseInt($('#find-latd').val(), 10);
            var latm = isNaN(parseInt($('#find-latm').val(), 10)) ? 0 : parseInt($('#find-latm').val(), 10);
            var lats = isNaN(parseFloat($('#find-lats').val())) ? 0 : parseInt($('#find-lats').val(), 10);

            var lngd = isNaN(parseInt($('#find-longd').val(), 10)) ? 0 : parseInt($('#find-longd').val(), 10);
            var lngm = isNaN(parseInt($('#find-longm').val(), 10)) ? 0 : parseInt($('#find-longm').val(), 10);
            var lngs = isNaN(parseFloat($('#find-longs').val())) ? 0 : parseInt($('#find-longs').val(), 10);

            setDecimal(latd, latm, lats, lngd, lngm, lngs);

            var lat = parseFloat($('#find-lat').val());
            var lng = parseFloat($('#find-long').val());

            if (!isNaN(lat) && !isNaN(lng)) {
                text += 'coords:' + lat + ',' + lng + ' ';

                if ($('#find-rad').val() != '' && !isNaN($('#find-rad').val()))
                    text += 'rad:' + $('#find-rad').val();
            }
        }

        setSearchText(text, this);
    });

    $('#find-lat, #find-long').keyup(function() {
        var $this = $(this);
        checkIsValid($this);
        var text = '';

        var lat = isNaN(parseFloat($('#find-lat').val())) ? 0 : parseFloat($('#find-lat').val());
        var lng = isNaN(parseFloat($('#find-long').val())) ? 0 : parseFloat($('#find-long').val());

        setDegrees(lat, lng);

        if (!isNaN(lat) && !isNaN(lng)) {
            text += 'coords:' + lat + ',' + lng + ' ';

            if ($('#find-rad').val() != '' && !isNaN($('#find-rad').val()))
                text += 'rad:' + $('#find-rad').val();
        }

        setSearchText(text, this);
    });

    $('#find-rad').keyup(function() {
        var $this = $(this);
        checkIsValid($this);
        var text = '';
        //var $f = $('.searchbar .find-filters .geo');
        var lat = isNaN(parseFloat($('#find-lat').val())) ? 0 : parseFloat($('#find-lat').val());
        var lng = isNaN(parseFloat($('#find-long').val())) ? 0 : parseFloat($('#find-long').val());

        if (!isNaN(lat) && !isNaN(lng)) {
            text += 'coords:' + lat + ',' + lng + ' ';

            if ($('#find-rad').val() != '' && !isNaN($('#find-rad').val()))
                text += 'rad:' + $('#find-rad').val();
        }

        setSearchText(text, this);
    });

    function checkIsValid($this) {
        if ($this.attr('rel') != '') {
            var con = $this.attr('rel');
            if (con.indexOf('|') > 0) {
                var min = parseFloat(con.split('|')[0]);
                var max = parseFloat(con.split('|')[1]);
                var val = parseFloat($this.val());

                if (val < min || val > max) {
                    $this.val($this.val().substr(0, $this.val().length - 1));
                    //alert('error: invalid parameter. must be between ' + min + ' and ' + max);

                    $(this).addClass('error');
                    $('#latlong-error').html('error: invalid parameter. must be between ' + min + ' and ' + max).show();
                }
            }
        }
    }

    function setDegrees(lat, lng) {
        var latd, latm, lats, lngd, lngm, lngs;

        latd = lat > 0 ? Math.floor(lat) : Math.ceil(lat);
        latm = Math.floor((Math.abs(lat) - Math.abs(latd)) * 60);
        lats = (Math.floor((Math.abs(lat) - Math.abs(latd) - latm / 60) * 360000) / 100);

        lngd = lng > 0 ? Math.floor(lng) : Math.ceil(lng);
        lngm = Math.floor((Math.abs(lng) - Math.abs(lngd)) * 60);
        lngs = (Math.floor((Math.abs(lng) - Math.abs(lngd) - lngm / 60) * 360000) / 100);

        !isNaN(latd) ? $('#find-latd').val(latd) : $('#find-latd').val('');
        !isNaN(latm) ? $('#find-latm').val(latm) : $('#find-latm').val('');
        !isNaN(lats) ? $('#find-lats').val(lats) : $('#find-lats').val('');
        !isNaN(lngd) ? $('#find-longd').val(lngd) : $('#find-longd').val('');
        !isNaN(lngm) ? $('#find-longm').val(lngm) : $('#find-longm').val('');
        !isNaN(lngs) ? $('#find-longs').val(lngs) : $('#find-longs').val('');
    }

    function setDecimal(latd, latm, lats, lngd, lngm, lngs) {
        var lat = (Math.floor((Math.abs(latd) + (latm / 60.) + (lats / 3600.)) * 10000) / 10000.);
        if (lat != 0) lat = lat * (latd / Math.abs(latd));

        var lng = (Math.floor((Math.abs(lngd) + (lngm / 60.) + (lngs / 3600.)) * 10000) / 10000.);
        if (lngd != 0) lng = lng * (lngd / Math.abs(lngd));

        !isNaN(lat) ? $('#find-lat').val(lat) : $('#find-lat').val('');
        !isNaN(lng) ? $('#find-long').val(lng) : $('#find-long').val('');
    }

    //-- sort order: mtabta - names to numbers, vice versa --//
    $('#namesbtn,#numbersbtn').click(function() {
        var $this = $(this);
        $('#namesbtn,#numbersbtn').removeClass('inuse');
        $this.addClass('inuse');
        loadMTABTA();
    });

    function loadMTABTA() {
        var $this;
        if ($('#namesbtn').hasClass('inuse')) {
            $('#mtaselect option').each(function(i) {
                $this = $(this);
                if ($this.text() != '')
                    $this.text($this.attr('name') + ' - ' + $this.val());
            });
            $('#btaselect option').each(function(i) {
                $this = $(this);
                if ($this.text() != '')
                    $this.text($this.attr('name') + ' - ' + $this.val());
            });
            $('#mtaselect option').tsort({ attr: 'name' });
            $('#btaselect option').tsort({ attr: 'name' });
        }
        else {
            $('#mtaselect option').each(function(i) {
                $this = $(this);
                if ($this.text() != '')
                    $this.text($this.val() + ' - ' + $this.attr('name'));
            });
            $('#btaselect option').each(function(i) {
                $this = $(this);
                if ($this.text() != '')
                    $this.text($this.val() + ' - ' + $this.attr('name'));
            });
            $('#mtaselect option').tsort({ attr: 'value' });
            $('#btaselect option').tsort({ attr: 'value' });
        }
    }
    loadMTABTA();

    //-- filter: mtabta - mta change event --//
    $('#mtaselect').change(function() {
        var $this = $(this);
        var option = $this.find('option:selected');
        var index = $this.val();
        var options = btas[index];
        $('#btaselect').html('<option value="" name=""></option>' + options);
        loadMTABTA();

        var text = jQuery.trim(option.attr('name'));

        if (text != '')
            setSearchText('mta:' + text, this);
        else
            clearSearchText(this);
    });

    $('#btaselect').change(function() {
        var mta = jQuery.trim($('#mtaselect option:selected').attr('name'));
        var bta = jQuery.trim($(this).find('option:selected').attr('name'));

        var text = '';

        if (mta != '')
            text += 'mta:' + mta;

        if (bta != '')
            text += ' bta:' + bta;

        setSearchText(text, this);
    });

    //-- filter: location - keyup event --//
    $('input:text', '#find-filter-location').keyup(function() {
        var text = '';
        var $f = $('#find-filter-location');

        if ($f.find('#find-address').val() != '')
            text += 'address:' + $f.find('#find-address').val();

        if ($f.find('#find-city').val() != '')
            text += ' city:' + $f.find('#find-city').val();

        if ($f.find('select.state').val() != '') {
            text += ' state:' + $f.find('select.state').val();
            //$f.find('input.county').attr('filters', 'State=' + $f.find('select.state option:selected').val());
            //$f.find('input.county').flushCache();
        }

        if ($f.find('#find-county').val() != '')
            text += ' county:' + $f.find('#find-county').val();

        if ($f.find('#find-zipcode').val() != '')
            text += ' zip:' + $f.find('#find-zipcode').val();

        if ($f.find('#find-address-radius').val() != '')
            text += ' rad:' + $f.find('#find-address-radius').val();

        setSearchText(text, this);
    });

    //-- filter: location - change event on select tags --//
    $('#find-filter-location select').change(function() {
        var text = '';
        var $f = $('#find-filter-location');

        if ($f.find('#find-address').val() != '')
            text += 'address:' + $f.find('#find-address').val();

        if ($f.find('#find-city').val() != '')
            text += ' city:' + $f.find('#find-city').val();

        if ($f.find('select.state').val() != '') {
            text += ' state:' + $f.find('select.state').val();
            //f.find('input.county').attr('filters', 'StateId=' + $f.find('select.state option:selected').attr('stateid'));
            //$f.find('input.county').flushCache();
        }

        if ($f.find('#find-county').val() != '')
            text += ' county:' + $f.find('#find-county').val();

        if ($f.find('#find-zipcode').val() != '')
            text += ' zip:' + $f.find('#find-zipcode').val();

        if ($f.find('#find-address-radius').val() != '')
            text += ' rad:' + $f.find('#find-address-radius').val();

        setSearchText(text, this);
    });

    //-- filter: sitename - keyup event --//
    $('#find-sitename').keyup(function() {
        var text = '';

        if ($(this).val() != '')
            text = 'site:' + $(this).val();

        setSearchText(text, this);
    });

    //-- filter: site number - keyup event --//
    $('#find-sitenumber').keyup(function() {
        var text = '';

        if ($(this).val() != '')
            text = 'id:' + $(this).val();

        setSearchText(text, this);
    });

    //-- filter: fcc number - keyup event --//
    $('#find-fccnumber').keyup(function() {
        var text = '';

        if ($(this).val() != '')
            text = 'fcc:' + $(this).val();

        setSearchText(text, this);
    });

    function setSearchText(text, e) {
        if ($('input.searchbox').val() != watermark) {
            $('input.searchbox').val(text);
        } else {
            $('input.searchbox').css('color', '#000').val(text);
        }
    }

    function clearSearchText(e) {
        $('input.searchbox').val('')
			.focus()
			.blur();
        $(e).focus();
    }
    var TcoCount;
    //-- find click event --//
    $('input.find').click(function() {
        var text = jQuery.trim($('input.searchbox').val());

        if (text == '' || text == watermark) {
            $('#find-search-error').show();
            return false;
        }

        $('input.searchbox').attr('disabled', 'disabled');

        $.ajax({
            type: 'POST', dataType: 'json', contentType: 'application/json; charset=utf-8',
            url: rootpath + 'TowerCoService.asmx/GetResultCount',
            data: '{ SearchText:"' + $('input.searchbox').val() + '" }',
            success: function(msg, textStatus) {
                var data = (msg.d == undefined || msg.d == null) ? msg : msg.d;
                data = data.parseJSON();
                TcoCount = data.TowerCoCount;
                $('input.searchbox').removeAttr('disabled');
                if (data.Refine == 'True') {
                    if (parseInt(data.ResultCount, 10) <= parseInt(data.Continue, 10)) {
                        if (data.Queries.length == 0) {
                            $('p.simplify').hide();
                        }
                        $('#proceed').show();
                        $('#onlytco').show();
                        $('#noproceed').hide();
                        $('#noonlytco').hide();
                        if ($.browser.msie && parseInt(data.ResultCount, 10) > 750) {
                            $('#proceed').hide();
                            //   $('#noproceed').show();
                        }
                        if ($.browser.msie && TcoCount < 750) {
                            $('#onlytco').show();
                        } else {
                            //  $('#onlytco').hide();
                        }
                    } else if (data.Queries.length == 0) {
                        $('p.simplify').hide();
                        $('#proceed').hide();
                        $('#noproceed').hide();
                        // if returned towerco towers is less than the continue go, but if the browser is ie then check to make sure the query is not for ca then go
                        //  alert(parseInt(data.TowerCoCount));
                        if (TcoCount <= parseInt(data.Continue, 10)) {
                            if (!$.browser.msie) {
                                $('#onlytco').show(); // whenever the data needs to be refined just offer to show only TowerCo towers.
                            } else if (TcoCount > 750) {
                                $('#onlytco').hide();
                            }
                            if ($.browser.msie && TcoCount < 751) {
                                $('#onlytco').show(); // whenever the data needs to be refined just offer to show only TowerCo towers.
                            } else if (TcoCount > 750) {
                                $('#onlytco').hide();
                            }
                        }
                        $('#noonlytco').hide();
                    } else {
                        $('p.simplify').show();
                        $('#proceed').hide();
                        $('#noproceed').show();
                        $('#onlytco').hide();
                        $('#noonlytco').show();
                    }

                    $('#resultcountmodalparent').attr('threshold', data.Continue);

                    $('#preResultsCount').html(data.ResultCount + " (" + data.TowerCoCount + " TowerCo)");
                    $('#preSearched').html(data.Assumed + (data.Queries.length > 0 ? ' keywords:' + data.Query : ''));
                    $('input.searchbox').val($('#preSearched').html());
                    var $results = $('#preResults');
                    $results.html('');


                    var assumed = data.Assumed.length > 0 ? '<strong>' + data.Assumed + '</strong>' : '';
                    var str = '';
                    for (var j = 0; j < data.Queries.length; j++) {
                        // data.Queries.length is only populated when the user searches with our built in query labels.
                        str += '\n<div class="simplify-container">\n\t<div class="header">';
                        if (assumed.length > 0 || data.Queries[j].Remains.length > 0) {
                            str += 'With ' + assumed;
                            if (assumed.length > 0 && data.Queries[j].Remains.length > 0) str += ' and';
                            if (data.Queries[j].Remains.length > 0)
                                str += ' <strong>' + data.Queries[j].Remains + '</strong> as keyword(s)';
                            str += ', Let\'s simplify. Please select one option:';
                        } else {
                            str += 'Let\'s simplify. Please select one option:';
                        }
                        str += '</div>\n\t<ul>';

                        for (var i = 0; i < data.Queries[j].Columns.length; i++) {
                            var label = '';

                            switch (data.Queries[j].Columns[i].Column) {
                                case 'SiteName':
                                    label += 'site';
                                    break;
                                default:
                                    label += data.Queries[j].Columns[i].Column;
                                    break;
                            }

                            label += ':' + data.Queries[j].Query + ' ' + data.Assumed;
                            label += (data.Queries[j].Remains.length > 0 ? ' keywords:' + data.Queries[j].Remains + ' ' : '');

                            str += '\n\t\t<li>';
                            str += '<input type="checkbox" id="presearch' + j + '' + i + '" class="presearchcb" value="' + label + '" />';
                            str += '<label for="presearch' + j + '' + i + '">';
                            str += '<strong>' + data.Queries[j].Query + '</strong> as a ' + data.Queries[j].Columns[i].Column + ' (<span class="query-count">' + data.Queries[j].Columns[i].Count + '</span>)';
                            str += '</label>';
                            str += '</li>';
                        }
                        // keep these buttons deactivated by default when the checkboxes are displayed. should need this because it happens already
                        $('#proceed').hide();
                        $('#noproceed').show();
                        $('#onlytco').hide();
                        $('#noonlytco').show();
                        str += '\n\t</ul>\n</div>';
                    }
                    $results.html(str);

                    $('#resultcountmodal').show().parent().npModal({
                        closeClass: '.close',
                        isModal: true,
                        autoPosition: false,
                        sender: 'div.searchbar'
                    });
                } else {
                    var label = data.Assumed + (data.Queries.length > 0 ? ' keywords:' + data.Queries[0].Query : (data.Query.length > 0 ? ' keywords:' + data.Query : ''));
                    $('input.searchbox').val(label).removeAttr('disabled');

                    $('input.find').unbind('click')
						.trigger('click');
                }

            },
            error: function(xhr, msg) {
                alert('fail: ' + msg + '\n ' + xhr.responseText);
            }
        });

        return false;
    });

    //-- change event for revised options --//
    $('#resultcountmodalparent input.presearchcb').live('click', function() {
        var count = parseInt($(this).siblings('label').find('span.query-count').text(), 10);
        var threshold = parseInt($('#resultcountmodalparent').attr('threshold'), 10);
        // alert(TcoCount);

        if (this.checked) {
            $('input.searchbox').val($(this).val());

        } else {
            $('input.searchbox').val($('#preSearched').text());
         
        }
        if (count <= threshold && this.checked) {
            $('#proceed').show();
            $('#noproceed').hide();
            if ($.browser.msie && count >= 750) {
                $('#proceed').hide();
                $('#noproceed').show();
            }
        } else {
            $('#proceed').hide();
            $('#noproceed').show();
        }
        if ((TcoCount <= threshold && this.checked) || (count <= threshold && this.checked)) {
            $('#onlytco').show();
            $('#noonlytco').hide();
            if ($.browser.msie && TcoCount >= 750 && count >= TcoCount) {
                $('#onlytco').hide();
                $('#noonlytco').show();
            }
        } else {
            $('#onlytco').hide();
            $('#noonlytco').show();
        }

        var id = $(this).attr('id');
        $('#resultcountmodalparent input.presearchcb:not(#' + id + ')').removeAttr('checked');
    });

    // need to refine this to only show towerco. as the owner.
    $('#onlytco').live('click', function() {
        LogAction(window.location.href.toString(), null, null, "Only Towerco 750 Search");
    
        $('input.searchbox').removeAttr('disabled');
        var $search = $('input.searchbox').val();
        // alert($search);
        var $newsearch = $search + " keywords:TowerCo";
        $('input.searchbox').val($newsearch);
        $('input.find').unbind('click')
			.trigger('click');
    });

    $('#proceed').live('click', function() {
        $('input.searchbox').removeAttr('disabled');

        if ($('#resultcountmodalparent input.presearchcb:checked').length > 0) {
            $('input.searchbox').val($('#resultcountmodalparent input.presearchcb:checked').val());
        }

        $('input.find').unbind('click')
			.trigger('click');
    });

    $('#cancel').click(function() {
        $('#resultcountmodal').npModalDestroy();
        var $search = $('input.searchbox');
        if ($search.val().indexOf('keywords:') == -1)
            $search.val($search.val() + ' keywords:');

        $search.removeAttr('disabled').focus();
    });

    $('#preResults a.downloadonly').live('click', function() {
        $('input.searchbox').removeAttr('disabled')
			.val($(this).attr('value'));

        $('#resultcountmodal input.csv').click();
    });

    // Floodligh tag for appTracker detail page
    $('.viewdetails').click(function() {
        callFloodlight('32app631');
    });
    // Functions to call the correct spotlight when direct pdf links from the Colocation page are clicked
    $('.colop').click(function() {
        callFloodlight('27col640');
    });

    $('.reconfigp').click(function() {
        callFloodlight('28col035');
    });

    $('.fiberp').click(function() {
        callFloodlight('29col376');
    });

    // Funcions for main Find ASP Button and a few other server tags that just detects a click and does the call Floodlight function
    $('.bar .png').live("mousedown", function() {
        callFloodlight('02fin106');
    });

    // Site Details load
    $('.toweridlink').click(function() {
        callFloodlight('06sit675');
    });

    // Site Details downloads
    $('a#colocDL').live("mousedown", function() {
        callFloodlight('07sit546');
    });

    $('a#reconfigDL').live("mousedown", function() {
        callFloodlight('08sit159');
    });

    $('a#datasheetDL').live("mousedown", function() {
        callFloodlight('09sit668');
    });

    $('a#csvDL').live("mousedown", function() {
        callFloodlight('10sit050');
    });

    $('a#gearthDL').live("mousedown", function() {
        callFloodlight('11sit555');
    });

    //  top download selected files link form search results list
    $('.dcsv').live("mousedown", function() {
        callFloodlight('12sea913');
    });

    // Google Earth data download link on map search results
    $('.repeat .earth').live("mousedown", function() {
        callFloodlight('14sea479');
    });

    // csv download from find bar on any page
    $('.excel').live("mousedown", function() {
        callFloodlight('16tow202');
    });

    // Google Earth data download from find bar
    $('div.filterbox a.earth').live("mousedown", function() {
        callFloodlight('17tow953');
    });

    // Colocation page Downloads
    $('#colocoloDL').live("mousedown", function() {
        callFloodlight('21col458');
    });

    $('#coloreloDL').live("mousedown", function() {
        callFloodlight('22col650');
    });

    $('#colofiberDL').live("mousedown", function() {
        callFloodlight('23col186');
    });

    $('#colotestingDL').live("mousedown", function() {
        callFloodlight('24col676');
    });

    $('#colocsvDL').live("mousedown", function() {
        callFloodlight('25col175');
    });

    $('#cologearthDL').live("mousedown", function() {
        callFloodlight('26col171');
    });
});
// Example: callFloodlight('01tow474');
function callFloodlight(cat) {
    var axel = Math.random() + "";
    var a = axel * 10000000000000;
    var tag_url = "http://fls.doubleclick.net/activityi;src=2671532;type=tower510;cat=" + cat + ";ord=1;num=" + a + "?"
    if (document.getElementById("TCO_FLDiv")) {
        var flDiv = document.getElementById("TCO_FLDiv");
    }
    else {
        var flDiv = document.body.appendChild(document.createElement("div"));
        flDiv.id = "TCO_FLDiv";
        flDiv.style.display = "none";
    }
    var TCO_FLIframe = document.createElement("iframe");
    TCO_FLIframe.id = "TCO_FLIframe_" + Math.floor(Math.random() * 999999);
    TCO_FLIframe.src = tag_url;
    flDiv.appendChild(TCO_FLIframe);
}

