﻿//Ajax Code for PDF Access Counter - Start
//Master rollup account
var pageTracker;
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24291490-1']);
_gaq.push(['_trackPageview']);

(function () {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

$(document).ready(function () {
    $('a#PDFLink').click(function () {
        updateCounter();
        return true;
    });
});
function SummaryLoadedSuccessfully(event, httpRequest, ajaxOptions) {
    // alert("SUCCESS" + httpRequest.responseText);
}

function SummaryLoadingError(event, httpRequest, ajaxOptions, errorText) {
    // alert("Error" + httpRequest);
}

//ajax call settings
jQuery().ajaxSuccess(SummaryLoadedSuccessfully);
jQuery().ajaxError(SummaryLoadingError);

function updateCounter() {
    var parameters = {};
    parameters["PDFLinkClicked"] = "1";
    var updateUrl = "/PageTemplates/UpdatePDFAccessCounter.aspx"
    $.getJSON(updateUrl, parameters);
}
//Ajax Code for PDF Access Counter - End


// Customized GA code//
$(document).ready(function () {
    var url = window.location.href;
    if (url.match('#nogo')) {
        window.location.href = window.location.href.slice(0, -5);
    }
    
        var a = document.getElementById('ctl00_inGoogleAnalytics').value
        try {


            _gaq.push(['t2._setAccount', a]);
            _gaq.push(['t2._trackPageview']);
            pageTracker = _gat._getTracker(a);

            (function () {
                var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
            })();
        }
        catch (err) { alert(err.description); }

        if (document.getElementById('ctl00_inPortalCheck').value == 'true') {
            try {
                $('#KHE_NavSearchRow').hide();
                $('#KHE_BackPack').hide();
                $('#CTA_Buckets').hide();
            }
            catch (err) { }
        }
        else {
        }

    

    var url = window.location.href;

    if (url.match('Request_Information')) {
        _gaq.push(['_trackEvent', 'Request Information', 'Click']); _gaq.push(['t2._trackEvent', 'Request Information', 'Click']);
    }

    else if (url.match('Schedule_a_Tour')) {
      _gaq.push(['_trackEvent', 'Schedule A Tour', 'Click']); _gaq.push(['t2._trackEvent', 'Schedule A Tour', 'Click']);
    }

    else if (url.match('ReturnUrl=%2fsecure%2fstudent%2fstudent')) {
      _gaq.push(['_trackEvent', 'Student Login', 'Click']); _gaq.push(['t2._trackEvent', 'Student Login', 'Click']);
    }

    else if (url.match('KHE_Scholarship_Myths.pdf')) {
     _gaq.push(['_trackEvent', 'PDF', 'Scholarship Myths']); _gaq.push(['t2._trackEvent', 'PDF', 'Scholarship Myths']);
    }

    else if (url.match('KHE_Scholarship_Tips.pdf')) {
      _gaq.push(['_trackEvent', 'PDF', 'Scholarship Tips']); _gaq.push(['t2._trackEvent', 'PDF', 'Scholarship Tips']);

    }

    else if (url.match('KHE_Scholarship_Resume.pdf')) {
      _gaq.push(['_trackEvent', 'PDF', 'Scholarship Resume']); _gaq.push(['t2._trackEvent', 'PDF', 'Scholarship Resume']);
    }

    else if (url.match('KHE_Scholarship_Websites.pdf')) {
      _gaq.push(['_trackEvent', 'PDF', 'Scholarship Websites']); _gaq.push(['t2._trackEvent', 'PDF', 'Scholarship Websites']);
    }

  else if (url.match('Emergency_Response_Plan.pdf')) {
      _gaq.push(['_trackEvent', 'PDF', 'Emergency Response']); _gaq.push(['t2._trackEvent', 'PDF', 'Emergency Response']);
  }



    
    $('#FacebookFooter').click(function () {
        _gaq.push(['_trackEvent', 'Socialmedia', 'Click', 'KHEC Facebook']); _gaq.push(['t2._trackEvent', 'Socialmedia', 'Click', 'KHEC Facebook']);

    });

    $('#TwitterFooter').click(function () {
        _gaq.push(['_trackEvent', 'Socialmedia', 'Click', 'KHEC Twitter']); _gaq.push(['t2._trackEvent', 'Socialmedia', 'Click', 'KHEC Twitter']);
    });

    $('#YoutubeFooter').click(function () {
       _gaq.push(['_trackEvent', 'Socialmedia', 'Click', 'KHEC Youtube']); _gaq.push(['t2._trackEvent', 'Socialmedia', 'Click', 'KHEC Youtube']);
    });

    $('#LinkedinFooter').click(function () {
        _gaq.push(['_trackEvent', 'Socialmedia', 'Click', 'KHEC Linkedin']); _gaq.push(['t2._trackEvent', 'Socialmedia', 'Click', 'KHEC Linkedin']);
    });

    $('#Likeboxtrackevent').click(function () {
        _gaq.push(['_trackEvent', 'Socialmedia', 'Click', 'KHEC Likeboxpod']); _gaq.push(['t2._trackEvent', 'Socialmedia', 'Click', 'KHEC Likeboxpod']);
    });

    $('#Adbucketverticaltrackevent').click(function () {
        pageTracker._trackEvent('Marketing Ad Buckets', 'Click', 'KHEC Marketing Ad Buckets Vertical');
    });

    $('#Videoverticaltrackevent').click(function () {
       _gaq.push(['_trackEvent', 'Video', 'Click', 'KHEC Video']); _gaq.push(['t2._trackEvent', 'Video', 'Click', 'KHEC Video']);
    });

    $('#Adbuckethorizontaltrackevent').click(function () {
        pageTracker._trackEvent('Marketing Ad Buckets', 'Click', 'KHEC Marketing Ad Buckets horizontal');
    });

    $('#Videohorizontaltrackevent').click(function () {
        pageTracker._trackEvent('Video', 'Click', 'KHEC Video horizontal');        
    });

    $('#divLiveChat').click(function () {
        _gaq.push(['_trackEvent', 'Chat', 'Click', 'KHEC Live Chat']); _gaq.push(['t2._trackEvent', 'Chat', 'Click', 'KHEC Live Chat']);
    });


});



$(document).ready(function () {
    var len = $('ul.KHE_Doormat_Footer_txt').length; //.last().css('border-width','0');
    $('ul.KHE_Doormat_Footer_txt').each(function (index) {
        //remove right border of last footer column
        if (index == len - 1) {
            $(this).css('border-right-width', '0px');
        }
    });
});

function fnCheckSearchText(elementId) {
    var textElement = document.getElementById(elementId);
    if (null != textElement && fnTrim(textElement.value) != "") {
        return true;
    }
    else {
        alert('Please enter one or more search words.');
        return false;
    }
}

function fnTrim(value) {
    return value.replace(/^\s+|\s+$/g, "");
}
