﻿
/* edit profile - check for list of nickname words */
function badwords(txt){
    var bad_words_array = new Array("telerik", "admin", "administrator", "sitefinity");
    var alert_arr=new Array;
    var alert_count=0;
    var compare_text=txt;
                
    for(var i=0; i<bad_words_array.length; i++) {
        for(var j=0; j<(compare_text.length); j++) {                                    
                if(bad_words_array[i]==compare_text.substring(j,(j+bad_words_array[i].length)).toLowerCase()) {
                    alert_count++;
                }
        }
    }
    return alert_count;
   }

/* Escape Character */
function escapeCharacter(endOfIdToMatch) {
    $("[id$=" + endOfIdToMatch + "]").each(function () {
        this.value = this.value.replace(/</g, '&lt;').replace(/>/g, '&gt;');

    });
}
   
/* Web forms - check if Enter Key is pressed */
function keyPress(event, btn) { 
              
   if ((event.which && (event.which == 13)) || (event.keyCode && (event.keyCode == 13))) {     
       $("[id$=" + btn + "]").focus();  
       $("[id$=" + btn + "]").click(function(event){
            event.stopPropagation();
       });       
       return false;
   }
   else return true;

}

function searchProxy(text, productId, searchPageUrl) {
    $("#page-wrap").empty();
    var count = 0;
    $(document).ready(function () {
        $.ajax({
            type: "GET",
            url: searchPageUrl,
            data: "q=" + text + "&requiredfields=ProductId%3a" + productId,
            dataType: "xml",
            success: function (xml) {
                $(xml).find('RES').find('R').each(function () {
                    var title = $(this).find('T').text();
                    var url = $(this).find('U').text();
                    var content = $(this).find('S').text();
                    $('<div id="link_' + count + '"></div>')
                        .html('<a target="_blank" href="' + url + '">' + title + '</a><div>' + content + '</div>')
                        .appendTo('#page-wrap');
                    count++;
                });
                if (count != 0) {
                    $('#mailNoteTooltip').addClass('asTooltipBoxShow');
                }
            }
        });
    });
}
/* Returns url without parameters */
function getURLNoParams(url) {

    var start = url.indexOf('?');
    var query = url.toLowerCase();

    if (start > -1) {
        query = url.substring(0, start);
        
    }

    return query;
}
/* Return the params of a URL */
function getQuery(url) {

    var start = url.indexOf('?');
    var stop = url.indexOf('&');
    var query = "";

    if (start > -1) {
        if (stop > -1) {
            query = url.substring(start + 1, stop);
        }
        else {
            query = url.substring(start + 1);
        }
    }

    return query;
}

/* collapse expand function for controls */
function CollapseExpand(element, button, minElements) {

    button.toggleClass("less");

    if (button.hasClass('less')) {
        element.children('li').show();
        button.children().text(button.children().text().replace('all', 'less'));
    }
    else {
        element.children('li').hide();
        element.children('li:lt(' + minElements + ')').show();
        button.children().text(button.children().text().replace('less', 'all'));
    }
}

function EqualHeightBlocksInRows(objList) {
    var currentTallest = 0,
    currentRowStart = 0,
    rowDivs = new Array(),
    $el,
    topPosition = 0;

    objList.each(function (index) {
        $el = $(this);
        topPostion = $el.position().top;

        if (currentRowStart != topPostion) {

            // we just came to a new row.  Set all the heights on the completed row
            for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
                rowDivs[currentDiv].height(currentTallest);
            }

            // set the variables for the new row
            rowDivs.length = 0; // empty the array
            currentRowStart = topPostion;
            currentTallest = $el.height();
            rowDivs.push($el);

        } else {

            // another div on the current row.  Add it to the list and check if it's taller
            rowDivs.push($el);
            currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);

        }

        // do the last row
        for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
            rowDivs[currentDiv].height(currentTallest);
        }

    });

}

$(document).ready(function () {
    /* image mask */
    if ($('.image-mask')) {
        var wrapper = '<div class="img-mask-wrapper"></div>';
        var mask = '<span class="products-img-mask"></span>';
        $('.image-mask').wrap(wrapper).parent().append(mask);
    }

    if ($('.table')) {
        $('.table tr:nth-child(2n+1)').addClass('table-grey-bg');
    }
});


