﻿function hideSpiners() {
    $(".catName:contains('Spiners')").parents('.howdoi').css("display", "none");
}

function hideBlades() {
    $(".catName:contains('Blades')").parents('.howdoi').css("display", "none");
}

function hideHubs() {
    $(".catName:contains('Hubs')").parents('.howdoi').css("display", "none");
}

function hideControllers() {
    $(".catName:contains('Controllers')").parents('.howdoi').css("display", "none");
}

function hideExtensions() {
    $(".catName:contains('Extensions')").parents('.howdoi').css("display", "none");
}

function hideHardware() {
    $(".catName:contains('Hardware')").parents('.howdoi').css("display", "none");
}

function hideGeneral() {
    $(".catName:contains('General')").parents('.howdoi').css("display", "none");
}

function hideEuropa() {
    $(".catName:contains('Europa')").parents('.howdoi').css("display", "none");
}

function hidePelican() {
    $(".catName:contains('Pelican')").parents('.howdoi').css("display", "none");
}

function hideL42() {
    $(".catName:contains('L-42')").parents('.howdoi').css("display", "none");
}

function hideXimango() {
    $(".catName:contains('Ximango')").parents('.howdoi').css("display", "none");
}

function hideRans() {
    $(".catName:contains('Rans')").parents('.howdoi').css("display", "none");
}

function hideICP() {
    $(".catName:contains('ICP')").parents('.howdoi').css("display", "none");
}

function ChangeProductLinks()
{
    $('.ProductChangeLink').each(function (index) {
        var type = $('.TypeContainer').text();
        var href = $(this).attr('href');
        href = href.replace('Products/tabid/61/agentType/View/', 'Products/ProductDescription/tabid/97/agentType/View/PropertyTypeId/' + type + '/');
        $(this).attr('href', href);
    });
}


function CheckProductAndHide() {
    var hu = String(window.location);
    var propIndex = hu.indexOf('PropertyTypeID');

    if (propIndex > 0) {
        var prodId = hu.substring(propIndex + 15, propIndex + 17);
        if (prodId[1] == "/")
            prodId = prodId[0];
        //alert(prodId);
        //hide articles
        //spinners
        if (prodId == 13) {
            hideBlades();
            hideHubs();
            hideControllers();
            hideExtensions();
            hideHardware();
            hideGeneral();
        }
        //blades
        else if (prodId == 13) {
            hideSpiners()
            hideHubs();
            hideControllers();
            hideExtensions();
            hideHardware();
            hideGeneral();
        }
        //controllers
        else if (prodId == 15) {
            hideBlades();
            hideHubs();
            hideSpiners();
            hideExtensions();
            hideHardware();
            hideGeneral();
        }
        //hubs
        else if (prodId == 5) {
            hideBlades();
            hideSpiners();
            hideControllers();
            hideExtensions();
            hideHardware();
            hideGeneral();
        }
        //extensions
        else if (prodId == 17) {
            hideBlades();
            hideHubs();
            hideControllers();
            hideSpiners();
            hideHardware();
            hideGeneral();
        }
        //hardware
        else if (prodId == 19) {
            hideBlades();
            hideHubs();
            hideControllers();
            hideExtensions();
            hideSpiners();
            hideGeneral();
        }
    }
    else {
        //hideBlades();
        //hideHubs();
        //hideControllers();
        //hideExtensions();
        //hideSpiners();
        //hideSpiners();
    }

}


function CheckApplicationAndHide() {
    var hu = String(window.location);
    var propIndex = hu.indexOf('PropertyID');

    if (propIndex > 0) {
        var prodId = hu.substring(propIndex + 11, propIndex + 13);
        if (prodId[1] == "/")
            prodId = prodId[0];

        //alert(prodId);
        //hide articles
        //spinners
        if (prodId == 13) {
            //hideEuropa();
            hidePelican();
            hideL42();
            hideXimango();
            hideRans();
            hideICP();
        }
        //blades
        else if (prodId == 14) {
            hideEuropa();
            //hidePelican();
            hideL42();
            hideXimango();
            hideRans();
            hideICP();
        }
        //controllers
        else if (prodId == 15) {
            hideEuropa();
            hidePelican();
            //hideL42();
            hideXimango();
            hideRans();
            hideICP();
        }
        //hubs
        else if (prodId == 16) {
            hideEuropa();
            hidePelican();
            hideL42();
            //hideXimango();
            hideRans();
            hideICP();
        }
        //extensions
        else if (prodId == 17) {
            hideEuropa();
            hidePelican();
            hideL42();
            hideXimango();
            //hideRans();
            hideICP();
        }
        //hardware
        else if (prodId == 18) {
            hideEuropa();
            hidePelican();
            hideL42();
            hideXimango();
            hideRans();
            //hideICP();
        }
    }
    else {
        //hideBlades();
        //hideHubs();
        //hideControllers();
        //hideExtensions();
        //hideSpiners();
        //hideSpiners();
    }

}

function HideEmptyBorders() {

    $('div.ProductListWrapper table tr:first td').css('border-top', 'none');
    $('div.ProductListWrapper table tr:last td').css('border-bottom', 'none');
    $('div.ProductListWrapper table tr td:first-child').css('border-left', 'none');
    $('div.ProductListWrapper table tr td:last-child').css('border-right', 'none');


    $('div.ProductListWrapper table tr td').each(function (index) {

        var td = $(this);

        if ($(this).children('div').hasClass('product_22')) {
            td.html('');
        }

        if ($(this).html() == '') {
            $(this).addClass('NoBorder');
        }
    });

    $('div.ProductListWrapper table tr:last td').css('border-bottom', 'none');

    $('table#dnn_ctr432_Default_LandingPage_ctl01 tr:first td').css('border-top', 'none');
    
}



$(document).ready(function () {



    $('.tab a').click(function () {
        $(this).parents('.topNav').children('.tab').removeClass('SelectedTab');
        $(this).parents('.tab').addClass('SelectedTab');
        $('.tabCont').css('display', 'none');
        var rel = $(this).attr('rel');
        var arr = rel.split('|');

        $('#' + arr[0]).css('display', 'block');

        $('.topNav').removeClass('topNav1').removeClass('topNav2').removeClass('topNav3').addClass(arr[1]);
    });

    //alert($(".HowDoIArticleLink").length);

    if ($('.HowDoIArticleLink').length > 0) {
        $('.HowDoIArticleLink').fancybox({
            'height': 330,
            'width': 800,
            'autoDimensions': true,
            'titlePosition': 'inside',
            'transitionIn': 'fade',
            'transitionOut': 'fade',
            'scrolling': 'auto',
            'showNavArrows': 'false'
        });
    }

    $('#HouseMenuNavCurrentLink').parent('li').parent('ul').parent('li').children('a:first-child').addClass('CurrentMenuItem');
    $('#HouseMenuNavCurrentLink').parent('li').parent('ul').parent('li').children('a:first-child').css('color', '#fff');

    if ($("#showFullmap").length > 0) {
        $("#showFullmap").fancybox({
            'titlePosition': 'inside',
            'transitionIn': 'none',
            'transitionOut': 'none',
            'showNavArrows': 'false'
        });
    }

    if ($('.PopUpImg').length > 0) {
        $(".PopUpImg").fancybox({
            'titlePosition': 'inside',
            'transitionIn': 'none',
            'transitionOut': 'none',
        });
    }

    $('.ChangeImg').click(function () {
        $('#MedumSizeImg').attr('src', $(this).attr('rel'));
        $('#MediumSizeImgLink').attr('href', $(this).attr('rel'));
    })

    //display print icon for articles
    var articlesNumber = $('div.itemText').length;
    if (articlesNumber > 0) {
        $('.itemText').each(function (index) {
            var id = $(this).attr('id');
            var title = $(this).parents('.howdoi').children('.HowDoIArticleLink').attr('title');
            title = title.replace(' ', '-').replace('/', '');

            var linkCategory = $(this).parents('.howdoi').children('.HowDoIArticleLink').attr('rel');
            var link = '';


            //2. testimonials 
            if (linkCategory.toLowerCase().indexOf('testimonials') > -1) {
                link = '/PrintContent/PrintContentTestimonials/tabid/85/articleType/ArticleView/articleId/' + id + '/' + title + '.aspx';
            }
            else if (linkCategory.toLowerCase().indexOf('resellers') > -1) {
                link = '/PrintContent/PrintContentResellers/tabid/89/articleType/ArticleView/articleId/' + id + '/' + title + '.aspx';
            }
            else /*if (linkCategory.toLowerCase().indexOf('howdoi') > -1) {*/
            {
                link = '/PrintContent/PrintContentLibrary/tabid/87/articleType/ArticleView/articleId/' + id + '/' + title + '.aspx';
            }

            //$(this).add('a').addClass('ArticlePrintLink').attr('href','/PrintContent/PrintContentTestimonials/tabid/85/articleType/ArticleView/articleId/' + id + '/' + title + '.aspx');
            $(this).append('<a class="ArticlePrintLink" href="' + link + '"></a>');
        });

    }


    //change links for products
    $('.ProductChangeLink').each(function (index) {
        var type = $(this).attr('rel');
        var href = $(this).attr('href');
        href = href.replace('Products/tabid/61/agentType/View/', 'Products/ProductDescription/tabid/97/agentType/View/PropertyTypeId/' + type + '/');
        $(this).attr('href', href);
    });

    $('#dnn_ctr432_Default_ViewProperty_ctl00').attr('cellspacing', '1');

    $('table#dnn_ctr432_Default_ViewProperty_ctl00 td').each(function (index) {
        if ($(this).children().length == 0) {
            $(this).css('border', 'none');
        }
    });




    if (('.sepaline').length > 0) {
        $('.sepaline:last').css('display', 'none');
    }

    $('ul.articlesList li:last-child div.separateline').css('display', 'none');

    //    $('.ProductSpecs tr:last-child td').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductSpecs tr td[rowspan^="2"]').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductSpecs tr td[rowspan^="3"]').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductSpecs tr td[rowspan^="4"]').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductSpecs tr td[rowspan^="5"]').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductSpecs tr td[rowspan^="6"]').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductSpecs tr td[rowspan^="7"]').addClass('noborder').css('border-bottom', 'none');

    //    $('.ProductFeatures tr:last-child td').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductFeatures tr td[rowspan^="2"]').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductFeatures tr td[rowspan^="3"]').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductFeatures tr td[rowspan^="4"]').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductFeatures tr td[rowspan^="5"]').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductFeatures tr td[rowspan^="6"]').addClass('noborder').css('border-bottom', 'none');
    //    $('.ProductFeatures tr td[rowspan^="7"]').addClass('noborder').css('border-bottom', 'none');




})


// refine search
$(function() {
  $('.ModSearchResultsC span[id$="lblNo"]').hide();
  $('.ModSearchResultsC span[id$="lblRelevance"]').hide();
  var exprs = [ '/Products/tabid/\\d+/agentType/View/PropertyID/\\d+/Default.aspx',
                '/PrintContent/.*Type/.*\\d{1,3}/',
                '/ApplicationDescription/tabid/\\d+/agentType/View/PropertyID/\\d+/Default.aspx' ]
  $('#dnn_ctr356_SearchResults_dgResults tr td:nth-child(2)').each(function() {
    for(var i in exprs) {
      var regex = new RegExp(exprs[i], 'gi');
      var result = regex.exec($(this).find('a.SubHead').attr('href'));
      
      if (result) {
        $(this).parent().hide();
        break;
      }
    }
  });
});
