﻿String.prototype.endsWith = function(t, i) { if (i == false) { return (t == this.substring(this.length - t.length)); } else { return (t.toLowerCase() == this.substring(this.length - t.length).toLowerCase()); } }

function doSearch(searchQuery) {
    window.location = baseUrl + "slides-list.aspx?search=" + encodeURIComponent(searchQuery);
}   

function GetFCKContentPlainText(fckEditorID, plainTextFieldID, divPlainTextID)
{
	var editor = FCKeditorAPI.GetInstance(fckEditorID) ;
		
	$('#' + divPlainTextID).html(editor.GetXHTML(false));	
	$('#' + plainTextFieldID).val($('#' + divPlainTextID).text());	
	return true;
}

function EnableValidatorById(validatorId, enable) {
    var validator = $('#' + validatorId);

    validator.get(0).enabled = enable;

    var asterix = $('#' + validatorId + '_asterix');

    if (enable) { asterix.show(); }
    else { asterix.hide(); }
}

function ShowINAMap(url) {
	//resize accourding the window size
	var fancyBoxWidth = $(window).width() - 90;
	var fancyBoxHeight = $(window).height() - 90;
	
	if (fancyBoxWidth<700) { fancyBoxWidth = 700; }
	if (fancyBoxHeight<500) { fancyBoxHeight = 500; }
	
	if ($.browser.msie) {
                fancyBoxWidth += 30;
                fancyBoxHeight += 30;
            }
		
	$("#aShowINAMap").fancybox({                                
                                'frameWidth': fancyBoxWidth,
                                'frameHeight': fancyBoxHeight
                            });                                    
    	
	//load the xbap url and show the fancyBox
    $('#iframeINAMap').attr("src", url);
    //$('#iframeINAMap').width(fancyBoxWidth - 10);
    $('#iframeINAMap').height(fancyBoxHeight - 0);
	$("#aShowINAMap").click();
	
	//reposition the box because IE does not display it centered
	$.fn.fancybox.scrollBox();
}

function InitFlashPopup(url, width, height, descriptionHtml) {
    
    flashembed("divFlashMovie",
                        {
                            src: url,
                            width: width + 1 + 'px',
                            height: height + 'px',
                            wmode: 'opaque',
                            bgcolor: '#ffffff'
                        }
                    );
    
    $("#divFlashDescription").html(descriptionHtml);
    
    if ($.fn.fancybox.getOpts() && $.fn.fancybox.getOpts().frameWidth) {
        $.fn.fancybox.getOpts().frameWidth = width + 240;
        $.fn.fancybox.getOpts().frameHeight = height;
    } else {
        $.fn.fancybox.defaults.frameWidth = width + 240;
        $.fn.fancybox.defaults.frameHeight = height;
    }    
}

function ShowEmbedHtmlPopup(sender, embed_html, width, height, descriptionHtml) {
    $("#divEmbedHtml").html(embed_html);
    //$("#divEmbedHtmlDescription").html(descriptionHtml);

    if ($.fn.fancybox.getOpts() && $.fn.fancybox.getOpts().frameWidth) {        
        $.fn.fancybox.getOpts().frameWidth = width;
        $.fn.fancybox.getOpts().frameHeight = height;
    } else {
        $.fn.fancybox.defaults.frameWidth = width;
        $.fn.fancybox.defaults.frameHeight = height;
    }

    $("#banner").hide();
    $("#marquee").hide();
    
    try {
        var opts = $(sender).fancybox.getOpts();

        opts.callbackOnStart = function() {                        
        }
        
        opts.callbackOnClose = function() {
            $("#divEmbedHtml").html('');
            $("#fancy_div").html('');

            $("#banner").show();
            $("#marquee").show();
        }
        if (height > $(window).height() - 90) { opts.centerOnScroll = false; }  
    }
    catch (err) { }
    
    $.fn.fancybox.scrollBox();    
}

//This script is used to fix the problem with DefaultButtons (ASP.NET hack)
//todo: test is this bug still valid
function defaultButtonFix() {
    __defaultFired = false;
}


function addSidebarMenuBG() {

    var titleToSelect = null;
    var subItemsToSelect = null;

    $('#divHierarchyBrowse td.project:visible').closest('div').find('td.report:visible').closest('div').find('td.report-items:visible')
        .each(function(i) {

            //get divs
            var reportItemsDiv = $(this).closest('div');
            var reportTitleTable = $('#' + reportItemsDiv.attr('id')).prev('table');

            if (reportItemsDiv.length > 0 || reportTitleTable.length > 0) {
                
                titleToSelect = reportTitleTable;
                subItemsToSelect = reportItemsDiv;
            }                        
        });

     if (titleToSelect == null || subItemsToSelect == null) {
            $('#divHierarchyBrowse td.project:visible').closest('div').find('td.report:visible')
                .each(function(i) {

                    //get divs
                    var projectItemsDiv = $(this).closest('div');
                    var projectTitleTable = $('#' + projectItemsDiv.attr('id')).prev('table');

                    if (projectItemsDiv.length > 0 && projectTitleTable.length > 0) {
                    
                        titleToSelect = projectTitleTable;
                        subItemsToSelect = projectItemsDiv;
                    }                    
                });
     }


     if (titleToSelect != null && subItemsToSelect != null) {
            //select
            titleToSelect.wrap('<div style="background-color:#ffffff; padding-top:2px;"></div>');

            switch (businessActivityTheme) {
                case 'yellow': subItemsToSelect.css('background-color', '#FFF8DB'); break;
                case 'blue': subItemsToSelect.css('background-color', '#CFEFFC'); break;
                case 'green': subItemsToSelect.css('background-color', '#C4EBEA'); break;
            }
     }        
}
