﻿/// <reference path="Telerik.Web.UI.Common.Core.js" />

/* Lägg javascript som är generella för Portal här  */

Sys.Application.add_load(function() {
$('.field').each(function() {
        var titleEl = $('div[title]:first,:input:first', this.parentNode);
        var title = titleEl.attr('title');
        if (title) { // has tooltip
            var img = $('img.tooltip-icon:first', this.parentNode);
            if (img.length > 0) { // has tooltip icon
                var div = $('<div class="tooltip-text"></div>');
                img.click(function() {
                    var pt = $(this).offset(); // { top: y, left: x }
                    div.css({ 'top': pt.top + "px", 'left': (pt.left + $(this).outerWidth(true)) + "px" }).toggle();
                });
                div.html(title);
                div.appendTo(document.body);
                titleEl.removeAttr('title');
            }
        } else {
            /*If the help icon is used outside the ordinary input structure (though always wrapped with .field class)*/
            var img = $('img.tooltip-icon:first', this.parentNode);
            var title = img.attr('title');
            if (title) { // has tooltip
                if (img.length > 0) { // has tooltip icon
                    var div = $('<div class="tooltip-text"></div>');
                    img.click(function() {
                        var pt = $(this).offset(); // { top: y, left: x }
                        div.css({ 'top': pt.top + "px", 'left': (pt.left + $(this).outerWidth(true)) + "px", 'z-index': 1600 }).toggle();
                    });
                    div.html(title);
                    div.appendTo(document.body);
                    img.removeAttr('title');
                }
            }
        }
    });
});


//case insensitive contains-selector for jquery
if ($) {
    $.expr[':'].icontains = function(obj, index, meta, stack) {
        return (obj.textContent || obj.innerText || jQuery(obj).text() || '').toLowerCase().indexOf(meta[3].toLowerCase()) >= 0;
    };
}
