﻿if (typeof (console) == "undefined") {
    console = { log: function () { }, dir: function () { } };
}
$(function () {
    var industries = "";
    var categories = "";
    $('.advanced').click(function (e) {
        e.preventDefault();
        $('.search-modal').removeClass('hide');
        $('.overlay').height($('.page').height());
        //grab industries

        if (industries == "" && categories == "") {
            $.ajax({
                url: '/home/SearchDropDownAjax',
                type: 'POST',
                dataType: 'json',
                success: function (data) {
                    categories = data[0];
                    industries = data[1];
                    $('#selCategory').html('<option value="">Select Category</option>');
                    $('#selIndustry').html('<option value="">Select Industry</option>');
                    for (var i = 0; i < categories.length; i++) {

                        $('#selCategory').append('<option value="' + categories[i].Id + '">' + categories[i].Text + '</option>');
                    }
                    for (var i = 0; i < industries.length; i++) {

                        $('#selIndustry').append('<option value="' + industries[i].Id + '">' + industries[i].Text + '</option>');
                    }
                    //loop through each and populate drop downs.

                },
                error: function (jqXHR, textStatus, errorThrown) {

                    //console.log('error');
                }
            });
        }
    });
    $('.search-close').click(function () {
        $('.search-modal').addClass('hide');
    });

    $('input#keyword').click(function () {
        if ($(this).val() == 'Enter Product or Keyword') {
            $(this).val('');
        }
    }).blur(function () {
        toggleText($(this), "Enter Product or Keyword");
    });
    $('input#txtKeyword').click(function () {
        if ($(this).val() == 'Enter Product or Keyword') {
            $(this).val('');
        }
    })
    .blur(function () {
        toggleText($(this), "Enter Product or Keyword");
    });

    function toggleText(jqObj, text) {

        var currentVal = jqObj.val();
        if (currentVal == text) {
            jqObj.val('');
        }
        else if (currentVal == '') {
            jqObj.val(text);
        }
    }

    $('#frmAdvancedSearch').submit(function (e) {


        if ($('#selIndustry').val() == '' && $('#selCategory').val() == '') {
            $('.advanced-errors').fadeOut(10, function () { $('.advanced-errors').fadeIn(); });

            return false;
        }
        else {
            if ($('#txtKeyword').val() == 'Enter Product or Keyword') {
                $('#txtKeyword').val('');
            }
            return true;
        }
    });

    $('#productManualList li a').click(function () {

        var manualName = $(this).html();
        _gaq.push(['_trackEvent', 'Technical Information', 'Download', manualName]);

    });
     
     
     if ($.browser.msie && $.browser.version < 9) 
     {
    
    
    	$("select.wide")

        .mousedown(function(){
            $(this)
                .data("origWidth", $(this).css("width"))
                .css("width", "auto");
        })

        .blur(function(){
            $(this).css("width", $(this).data("origWidth"));
        });

    
    }
     
     
});

