﻿document.write("<script src='/ElakeFenniaInternet/js/AC_OETags.js' type='text/javascript' language='javascript'></script>");

function renderFlash(swfPath, swfWidth, swfHeight, swfMajorVersion, swfMinorVersion, swfRevision, swfFlashvars, isEditMode, flashInstance, swfBgColor) {

    var hasRequestedVersion = DetectFlashVer(swfMajorVersion, swfMinorVersion, swfRevision);

    if (hasRequestedVersion) {
        var runFlash = AC_FL_RunContent(
        "src", swfPath,
        "width", swfWidth,
        "height", swfHeight,
        "menu", "false",
        "align", "middle",
        "id", ("teaserFlash" + flashInstance++),
        "quality", "high",
        "bgcolor", swfBgColor,
        "name", ("teaserFlash" + flashInstance++),
        "allowScriptAccess", "always",
        "wmode", "opaque",
        "type", "application/x-shockwave-flash",
        'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
        "pluginspage", "http://www.adobe.com/go/getflashplayer",
        'FlashVars', swfFlashvars
        );

        var layer = jQuery('#imagecontent' + flashInstance);

        if (isEditMode == '1') {
            layer.show();
        } else {
            layer.hide();
        }
    }
    else {
        var layer = jQuery('#imagecontent' + flashInstance);
        layer.show();
    }
}

// get the item list through json request
function getNewsItems(pageId, itemsPerPage, filter, listType, filterTemplateName) {
    //alert(pageId + ' ' + itemsPerPage + ' ' + listType + ' ' + filterTemplateName);
    jQuery.ajax({
        type: "POST",
        url: "/ElakeFenniaInternet/layouts/ajax.aspx/getItemsByFilterAndTemplate",
        contentType: "application/json; charset=utf-8",
        data: "{pageGuid:'" + pageId + "', itemsPerPage:'" + itemsPerPage + "', filter:'" + filter + "', filterTemplateName:'" + filterTemplateName + "'}",
        dataType: "json",
        success: function (msg) {
            var items = (typeof msg.d) == 'string' ? eval('(' + msg.d + ')') : msg.d;

            jQuery('.itemList').html('<div class="itemList"></div>');
            var newHtml = getListHtml(items, listType);
            jQuery('.itemList').html(newHtml);

        },
        error: AjaxFailed
    });

}

function AjaxFailed(result) {
    alert('AJAX REQUEST FAILED: ' + result.status + ' ' + result.statusText + ' ' + result.d);
}

// Modify this function to set correct presentation to the item list
// <remarks>Some of the fields of item are exposed as their own properties,
// but you can access all the fields of the item by item.Fields['FieldName']</remarks>
function getListHtml(items, listType) {

    var newHtml = '';
    switch (listType) {
        case 'latest':
            for (var i = 0; i < items.length; i++) {
                newHtml += '<p class="news-item">' + items[i].PublicationDate + '<br/><a href="' + items[i].Url + '">' + items[i].Title + '</a></p>';
            }
            break;

        case 'news':
            newHtml += '<div class="news">';
            if (items != null) {
                for (var i = 0; i < items.length; i++) {
                    newHtml += '<ul>';
                    newHtml += '<li class="date">' + items[i].PublicationDate + '</li>';
                    newHtml += '<li><a href="' + items[i].Url + '">' + items[i].Title + '</a></li>';
                    newHtml += '</ul>';
                }
            }
            newHtml += '</div>';
            break;
    }

    return newHtml;
}

// set elements to equal height
function EqualHeight(group) {
    var tallest = 0;
    group.each(function () {
        var thisHeight = jQuery(this).height();
        if (thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

// content blocks
function accordion(id, openText, closeText) {

        jQuery('#' + id + ' div.content').hide();
        jQuery("#" + id + " div.faqtitle").click(function () {

            if (!jQuery(this).next('div.content').is(':visible')) {
                jQuery('#' + id + ' div.content').slideUp(300);
                jQuery('#' + id).find('a#accordion').addClass('close').removeClass('open').text(openText);
            }
            jQuery(this).next('div.content').animate({ opacity: 'toggle', height: 'toggle' }, "fast");
            jQuery(this).find('a#accordion').text(jQuery(this).find('a#accordion').text() == openText ? closeText : openText);
            jQuery(this).find('a#accordion').is('.close') ? jQuery(this).find('a#accordion').addClass('open').removeClass('close') : jQuery(this).find('a#accordion').addClass('close').removeClass('open')
            return false;
        });
    }

function imageGallery(toggle, image) {

    maxWidht = jQuery('div.leftColumn').length > 0 ? "?mw=355" : "?mw=595";

    // hidden if there's no picture to show
    if (jQuery('.' + toggle).length == 0) jQuery('.' + image).hide();

    jQuery('.' + toggle).click(function () {

        if (!jQuery(this).parent().is('.selected')) {

            jQuery('.' + image).hide().load(function () {
                jQuery(this).fadeIn();
            }).attr('src', jQuery(this).attr('MediaSrc') + maxWidht);
        }

        jQuery('.' + toggle).parent('.selected').removeClass("selected");
        jQuery(this).parent().addClass("selected");
    }).filter(':first').click();

}

function tab(title, content) {

    jQuery('.' + content).hide(); //Hide all content
    jQuery('ul.' + title + ' li:first').addClass("selected").show(); //Activate first tab
    jQuery('.' + content + ':first').show(); //Show first tab content

    jQuery('ul.' + title + ' li').click(function () {
        jQuery('ul.' + title + ' li').removeClass("selected"); //Remove any "active" class
        jQuery(this).addClass("selected"); //Add "active" class to selected tab
        jQuery('.' + content).hide(); //Hide all tab content
        var activeTab = jQuery(this).find("a").attr("rel"); //Find the rel attribute value to identify the active tab + content
        jQuery('#' + activeTab).fadeIn(); //Fade in the active content
        return false;
    });
}


function FormValidatorHandler() {
    setTimeout('FormValidatorHandlerTimeOut()', 1);
}
function FormValidatorHandlerTimeOut() {
    jQuery('.error').html('<p class="summary"></p>').empty();
    var html = '';
    var comparedID;
    for (i = 0; i < Page_Validators.length; i++) {
        var inputControl = document.getElementById(Page_Validators[i].controltovalidate);
        
        if (inputControl != null) {
            var inputID = inputControl.id;
            var errorMessage = Page_Validators[i].errormessage;
            //alert(Page_Validators[i].isvalid + errorMessage);
            var errorControl = document.getElementById(Page_Validators[i].id);
            var validationType = jQuery(errorControl).attr('type');

            if (!Page_Validators[i].isvalid) {
                comparedID = inputID;

                if (Page_Validators[i].errormessage != undefined) {
                    html += '<li>' + errorMessage + '</li>';
                }

                switch (validationType) {
                    case 'table':
                        jQuery(inputControl).parent().prev().addClass('requiredNoImage');
                        break;
                    default:
                        jQuery(inputControl).parent().prev().addClass('required');
                        break;
                }

            }
            // Do not change styles if mentioned control is already flagged as invalid
            else if (inputID != comparedID) {

                switch (validationType) {
                    case 'table':
                        jQuery(inputControl).parent().prev().removeClass('requiredNoImage');
                        break;
                    default:
                        jQuery(inputControl).parent().prev().removeClass('required');
                        break;
                }
            }
        }
    }
    if (html.length > 0) {
        jQuery('.scfValidationSummary').show();
        jQuery('.summary').html('<ul>' + html + '</ul>');
    }
    else {
        jQuery('.scfValidationSummary').hide();
    }

}

function GeneralAjaxFormLoad() {
    Sys.Application.add_load(AjaxGeneralFormLoad);
    function AjaxGeneralFormLoad() {
        jQuery(document).ready(function () {

            // hide all validators in the form
            jQuery('.scfForm .validator').attr('display', 'none');

            // validators change
            jQuery('.scfForm :text').change(function () {
                FormValidatorHandler();
            });
            jQuery('.scfForm textarea').change(function () {
                FormValidatorHandler();
            });
            jQuery('.scfForm :checkbox').change(function () {
                FormValidatorHandler();
            });
            jQuery('.scfForm :radio').change(function () {
                FormValidatorHandler();
            });
            jQuery('.scfForm select').change(function () {
                FormValidatorHandler();
            });
        });
    }
}

// used in the calculation request form
function CalculationLoadHandler() {
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
    jQuery('#' + args.get_postBackElement().id).parent().next().next().show();
}
function EndRequestHandler(sender, args) {
    jQuery('.loader').hide();
}
}

jQuery(function () {

    // hide all validators in the form if ajax is not used
    jQuery('.scfForm .validator').attr('display', 'none');

    // run modifications to html on every page
    // adding <p>-element to <ol><li>-elements
    jQuery('ol li').each(function () {
        jQuery(this).replaceWith('<li><p>' + jQuery(this).text() + '</p></li>')

    });
});
