﻿function startMR() {
    $(document).ready(function() {
        $('a').click(function(event) {
        if (!$(this).is('.glow') && !$(this).is('.ContactEmailLink') && (($(this).attr('target') !== undefined) && $(this).attr('target') !== '_blank')) {
                event.preventDefault();

                var url = $(this).attr('href');

                animateOut(url);

            }
        });
    });

    $(window).load(function() {
        $(".contentPlaceHolder-inner").hide();
        $("#lineTop").animate({
            height: "0px"
        }, 450, function() {
            $("#header").animate({
                paddingTop: "0px"
            }, 450, function() {
                $(".contentPlaceHolder-inner").fadeIn()
            }
	            );
        }
	    )
	    ;

        $("#lineBottom").animate({
            height: "1px"
        }, 450, function() {
            $("#footer").animate({
                marginTop: "0px"
            }, 450);
        }
        );

        $(".contentPlaceHolder").animate({
            height: "490px"
        }, 450);
        $('.hoverVertical').css('display', 'block');
    });
}

function animateOut(url) {
    $(".contentPlaceHolder-inner").fadeOut("slow", function() {

        //alert('lol');
        $(".contentPlaceHolder-inner").hide();

        $("#header").animate({
            paddingTop: "55px"
        }, 450, function() {
            $("#lineTop").animate({
                height: "235px"
            }, 450, function() {
                document.location.href = url;
                return false;
            });
        });

        $("#footer").animate({
            marginTop: "-55px"
        }, 450, function() {
            $("#lineBottom").animate({
            //height: "230px"
        }, 450);
        $(".contentPlaceHolder").animate({
            height: "10px"
        }, 450);
    });
});
}

function flashLink(url) {
    //if(!url.toString().startsWith('http://')) {
    url = url.toString().replace(/'/g, "");
    //}
    animateOut(url);
}

function reloadAfterResize() {
$(document).ready(function() {
    var tempCounter = 0;
    var windowResizeTimeout;

    window.onresize = function() {
        window.clearTimeout(windowResizeTimeout);
        windowResizeTimeout = window.setTimeout(DelayedResize, 100);
    };
    function DelayedResize() {
        window.status = ++tempCounter;
        window.clearTimeout(windowResizeTimeout);
        // Add your original window.onresize implementation here
        animateOut("");
        location.reload(true);
    }

    });
}

function setModuleWidth(moduleDivId, width) {
    //alert(text);
    var el = document.getElementById(moduleDivId);
    el.style.width = width + "px";
    el.style.marginLeft = "20px";
    el.style.marginRight = "20px";
    //el.style = "margin:0px !important; width: 100% !important;";
    var el2 = document.getElementById('contentPlaceHolder-inner');
    if (width > $(window).width()) {
        el2.style.marginLeft = "0px";
        el2.style.marginRight = "0px";
    }
    else {
        el.style.marginLeft = "auto";
        el.style.marginRight = "auto";
        el2.style.marginLeft = "auto";
        el2.style.marginRight = "auto";
        el2.style.width = "100%";
    }
    //alert(el2.style.marginLeft);
}

function setHoverScroll(moduleId){
    $(document).ready(function() {
    var el = document.getElementById(moduleId);
        //alert(el.style.width.replace('px','') + ' ' + $(window).width());
        if (el.style.width.replace('px', '') > $(window).width()) {
            $('#' + moduleId + '').hoverscroll({
                vertical: false,
                width: $(window).width(),
                height: 490,
                arrows: true,
                arrowsOpacity: 0.1
            });
        }
    });
}

function S4() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); }

function guidforFlash() {
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4()).toUpperCase()

}

function InsertImageFromFileManager(url, EditorClientId, text) {
    //alert();
    
    //alert(text);
    var el = document.getElementById(EditorClientId);
    //alert(el.parentElement.id)
    var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
    if (ie7) {
        var editor = $find(el.parentElement.id);
    }
    else {
        var editor = $find(el.parentNode.id);
    }
    try {
        // For 'Undo'
        editor._editPanel._modePanels[0]._saveContent();
        //value="avi;bmp;doc;docx;flv;gif;jpg;mp3;pdf;png;ppt;pptx;rar;swf;txt;xls;xlsx;zip" />
        // What to do - insert image at current selection if it is an image file if not insert href
        //---------------------------------------------------
        //alert(url.lastIndexOf(".jpg"));
        if (url.lastIndexOf(".swf") > -1) {
            var unicString = guidforFlash();
            var filename = url.substring(url.lastIndexOf('/') + 1);
            filename = filename.replace(".swf", "");
            var flashstring = "[Flash here]<!--[FlashStart]<div id=\"" + unicString + "\">Flash here</div><script src=\"/scripts/swfobject.js\" type=\"text/javascript\"></script><script type=\"text/javascript\"> var fo = new SWFObject('" + url + "', '" + filename + "', '720', '405', '9.0.28', '#000000'); fo.addParam('scale', 'noscale'); fo.addParam('wmode', 'transparent'); fo.addParam('quality', 'best'); fo.write('" + unicString + "'); </script>[FlashEnd]-->"
            editor._editPanel._modePanels[0].insertHTML(flashstring);
        }
        else 
        {
            if (url.lastIndexOf(".jpg") > -1 || url.lastIndexOf(".bmp") > -1 || url.lastIndexOf(".gif") > -1 || url.lastIndexOf(".png") > -1) {
                editor._editPanel._modePanels[0].insertHTML("<img src=\"" + url + "\" />");
            }
            else {
                var htmlToEditor = "&nbsp;&nbsp;<a href=\"" + url + "\">" + text + "</a>";
                editor._editPanel._modePanels[0].insertHTML(htmlToEditor);


            }
        }
        //---------------------------------------------------

        // Notify Editor about content changed and update toolbars linked to the edit panel
        //setTimeout(function() { editor._editPanel._modePanels[0].onContentChanged(); editor._editPanel._modePanels[0].updateToolbar(); }, 0);
        // Ensure focus in design panel
        editor._editPanel._modePanels[0].focusEditor();
        $find('ModalFileMnager_ModalPopupExtender').hide();
        return true;
    } catch (e) { alert(e.message) }

}

function InsertLinkFromCmsPageHierarchy(url, EditorClientId, text) {
    //alert(EditorClientId);
    var el = document.getElementById(EditorClientId);
    //alert(el.parentElement.id)
    //alert(EditorClientId);
    var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
    if (ie7) {
        var editor = $find(el.parentElement.id);
    }
    else {
        var editor = $find(el.parentNode.id);
    }
    
    try {
        // For 'Undo'
        editor._editPanel._modePanels[0]._saveContent();
        //alert(url);
        //alert(text);
        var htmlToEditor = "&nbsp;&nbsp;<a href=\"" + url + "\">" + text + "</a>";
        var htmlToEditorTemp = "<p>url=" + url + "text" + text + "</p>";
        //alert(htmlToEditorTemp);
        // What to do - insert image at current selection
        //---------------------------------------------------

        //editor._editPanel._modePanels[0].insertHTML(htmlToEditorTemp);

        editor._editPanel._modePanels[0]._setToEnd();
        editor._editPanel._modePanels[0].focusEditor();
        //editor._editPanel._modePanels[0]._saveContent();
        editor._editPanel._modePanels[0].insertHTML(htmlToEditor);
        //editor._execCommand("createLink", false, this._emptySrc);
        //---------------------------------------------------

        // Notify Editor about content changed and update toolbars linked to the edit panel
        //setTimeout(function() { editor._editPanel._modePanels[0].onContentChanged(); editor._editPanel._modePanels[0].updateToolbar(); }, 0);
        // Ensure focus in design panel
        editor._editPanel._modePanels[0].focusEditor();
        $find('ModalPagePicker_ModalPopupExtender').hide();
        return true;
    } catch (e) { alert(e.message) }

}

//Online Help
function OpenOnlineHelpWindow(url, role, languageId, windowTitle) {
    var onlineHelpUrl = url + "?role=" + role + "&languageId=" + languageId;
    var title = "";
    var features = "width=1000,height=680,resizable=no,scrollbars=yes";
    window.open(onlineHelpUrl,title,features);
}

//DefaultButton
function WebFormFireDefaultButton(event, target)
{
    var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
    if (ie7)
    {
        document.getElementById(target).focus();
        //alert(document.getElementById(target));
        document.all[target].click();
        event.returnValue=false;
        return;
    }
    else
    {
        //alert("alo");
        var pos=document.getElementById(target).href.indexOf("javascript:");
        var evt = document.createEvent('MouseEvents');
        evt.initMouseEvent('click', true, true, window, 0, 0, 
                               0, 0, 0, false, false, false, false, 0, null);
                                if (pos>=0)
                                {
                                    eval(unescape(document.getElementById(target).href));
                                }
                               
       document.getElementById(target).dispatchEvent(evt);
    } 

}
//Tooltip
function showToolTip(DivID)
{
    document.getElementById(DivID).style.display = "block";
}

function hideToolTip(DivID)
{
    document.getElementById(DivID).style.display = "none";
}

function changeDisplay(DivID)
{
    if (document.getElementById(DivID).style.display == "none")
    {
        document.getElementById(DivID).style.display = "block";
    }
    else
    {
        document.getElementById(DivID).style.display = "none";
    }
}
//Form
function FormFieldClear(txtName) {
    document.getElementById(txtName).value = "";
}

//Translation
function TranslationCopy(destination, sourceText)
{
    //document.forms[0].elements[destination].value = sourceText;
    document.getElementById(destination).value = sourceText;
}
function TranslationClear(txtName)
{
    //document.forms[0].elements[txtName].value = "";
    document.getElementById(txtName).value = "";	
}

function TranslationCopyHtmlEditor(destination, sourceText)
{
    var editor = $find(destination);
    //editor._editPanel._modePanels[0]._copyCut('x', true);
    editor._editPanel._modePanels[0].insertHTML(sourceText);
    //$find(destination).SetText(sourceText);
}
function TranslationClearHtmlEditor(txtName)
{
    var editor = $find(txtName);
    //editor._editPanel._modePanels[0]._copyCut('x', true);
    editor._editPanel._modePanels[0]._editPanel.set_content("");
}
function CalculateInsurancePriceAbroad(destination, source, insuranceRate, minimumInsuranceCost)
{
    var price = parseFloat(convertNumberCulture(document.getElementById(source).value));
    var insuranceRateConverted = parseFloat(convertNumberCulture(insuranceRate));
    var minimumInsuranceCostConverted = parseFloat(convertNumberCulture(minimumInsuranceCost));
    var insurance = price * insuranceRateConverted / 100;
    if (insurance < minimumInsuranceCostConverted)
    {
        insurance = minimumInsuranceCostConverted;
    }
    insurance = Math.round(insurance*100)/100;
    document.getElementById(destination).value = insurance.toString().replace(".", ",");
}
function CalculateTax(message, source, taxRate, errorMessage, currency)
{
    if(document.getElementById(source).value == "" || document.getElementById(source).value == undefined)
    {
        alert(errorMessage);
    }
    else
    {
        var price = parseFloat(convertNumberCulture(document.getElementById(source).value));
        var taxRateConverted = parseFloat(convertNumberCulture(taxRate));
        var priceTax = price * (100 + taxRateConverted) / 100;
        priceTax = Math.round(priceTax*100)/100;
        alert(message + " " + priceTax.toString().replace(".", ",") + " " + currency + ".");
    }
}
function convertNumberCulture(number)
{
    var convertedNumber = number.toString().replace(",", ".");
    return convertedNumber;
}
// SelectArtist
function toggleArtistCategoryDDLDiv(DivID)
{
    if(document.getElementById(DivID).style.display == "none")
    {
        document.getElementById('ArtistsDiv').style.display = "none";
        document.getElementById('CategoriesDiv').style.display = "none";
        document.getElementById(DivID).style.display = "block";
    }
    else
    {
        document.getElementById(DivID).style.display = "none";
    }
}

function SearchCriteriaJs(itemId, type, HdnArtistCategoryStringToShow, HdnTypeId, HiddenArtClientId, HiddenCatClientId, lblSelectedArtClientId, lblSelectedCatClientId, DefaultValueForlblSelectedArt, DefaultValueForlblSelectedCat, SelectedItemNameToShow,PanelToUpdateId)
{
    document.getElementById('ArtistsDiv').style.display = "none";
    document.getElementById('CategoriesDiv').style.display = "none";
    
    //type variable artist or category
        //1 artsit
        //0 category
        //3 reset
    if (type == "1")
    {
        document.getElementById(HiddenArtClientId).value=itemId;
        document.getElementById(HiddenCatClientId).value="";
        document.getElementById(HdnTypeId).value=1;
        document.getElementById(HdnArtistCategoryStringToShow).value=SelectedItemNameToShow;
        
        document.getElementById(lblSelectedArtClientId).innerHTML=SelectedItemNameToShow;
        document.getElementById(lblSelectedCatClientId).innerHTML=DefaultValueForlblSelectedCat;
        LoadUpdatePanel(PanelToUpdateId);
    }
    if (type == "0")
    {
        document.getElementById(HiddenArtClientId).value="";
        document.getElementById(HiddenCatClientId).value=itemId;
        document.getElementById(HdnTypeId).value=0;
        document.getElementById(HdnArtistCategoryStringToShow).value=SelectedItemNameToShow
        
        document.getElementById(lblSelectedArtClientId).innerHTML=DefaultValueForlblSelectedArt;
        document.getElementById(lblSelectedCatClientId).innerHTML=SelectedItemNameToShow;
        LoadUpdatePanel(PanelToUpdateId);
    }
    if (type == "3")
    {
        document.getElementById(HiddenArtClientId).value="";
        document.getElementById(HiddenCatClientId).value="";
        document.getElementById(HdnTypeId).value=3;
        document.getElementById(HdnArtistCategoryStringToShow).value=SelectedItemNameToShow
        
        document.getElementById(lblSelectedArtClientId).innerHTML=DefaultValueForlblSelectedArt;
        document.getElementById(lblSelectedCatClientId).innerHTML=DefaultValueForlblSelectedCat;
        LoadUpdatePanel(PanelToUpdateId);
    }
}

//force UpOrderItemsCosts to update
    function LoadUpdatePanel(PanelId)
    {
        __doPostBack(PanelId, '');
    }

function allocateSidebarHeight(containerWidth, containerHeight) {
    //var contentDom = document.getElementById('PortfolioProjectDetailsDiv'); 
    var sidebarDom = document.getElementById('PortfolioProjectsSidebarList');
    //alert(sidebarDom.offsetHeight + " " + containerHeight);
    if (sidebarDom.offsetHeight > containerHeight) {
        $(document).ready(function() {
            //$('#PortfolioProjectsList').hoverscroll({
        $('#PortfolioProjectsList2').hoverscroll({
                vertical: true,
                width: containerWidth,
                //height: containerHeight - 50, // PortfolioCategoryHeader height in px
                height: containerHeight,
                arrows: true,
                arrowsOpacity: 0.1
            });
        });
    }
}

//function allocateSidebarHeight(containerWidth, containerHeight) {
//    var contentDom = document.getElementById('PortfolioProjectDetailsDiv');
//    var sidebarDom = document.getElementById('PortfolioProjectsSidebarList');
//    alert(sidebarDom.offsetHeight + " " + contentDom.offsetHeight);
//    if ((contentDom.offsetHeight - 800) > sidebarDom.offsetHeight) {
//        $(document).ready(function() {
//            $('#PortfolioProjectsList').hoverscroll({
//                vertical: true,
//                width: containerWidth,
//                height: containerHeight,
//                arrows: true,
//                arrowsOpacity: 0.1
//            });
//        });
//    }
//}

function loadImage(PortfolioProjectGallery1, counter, tableLenght) {
    //alert(PortfolioProjectGallery1.length);
    //alert(PortfolioProjectGallery1[counter][0]);
    
    if (PortfolioProjectGallery1 == "null") {
        PortfolioProjectGallery1 = PortfolioProjectGallery;
    }
    if (counter < tableLenght) {
        
        //alert("jestem");
            $(function() {
            var img = new Image();
            img.onload = function() {
                // always called
            //alert('image loaded kjhg');
            loadImage(PortfolioProjectGallery1, counter + 1, tableLenght);
            };

                // wrap our new image in jQuery, then:  
                $(img)
                // once the image has loaded, execute this code
    .load(function() {
        //            if (counter < tableLenght) {
        //                loadImage(PortfolioProjectGallery1, counter + 1, tableLenght);
        //            }
        // set the image hidden by default          
        $(this).hide();
        // with the holding div #loader, apply:
        $('#' + PortfolioProjectGallery1[counter][0] + '')
        // remove the loading class (so no background spinner),         
    .removeClass('loading')
        // then insert our image
    .append(this);
        
        
        // fade our image in to create a nice effect
        $(this).fadeIn();

    })

                // if there was an error loading the image, react accordingly
    .error(function() {
        //            if (counter < tableLenght) {
        //                loadImage(PortfolioProjectGallery1, counter + 1, tableLenght);
        //            }
        // notify the user that the image could not be loaded    
    })
                // *finally*, set the src attribute of the new image to our image
    .attr('src', PortfolioProjectGallery1[counter][1]);


            });



       
       
    }

    
}
