﻿function DeleteValidation() {
    location.reload(true);
//    var ValidationsAndAlerts = new Array("vdsEmail", "ctl00_ucEmail1_vdsEmail", "UCAlerta1_DivJanela", "ctl00_UCAlerta1_DivJanela", "ctl00_vdsEmail");

//    for (i = 0; i < ValidationsAndAlerts.length; i++) {
//        if (document.getElementById(ValidationsAndAlerts[i]) != null) {
//            document.getElementById(ValidationsAndAlerts[i]).style.display = "none";
//        }
//    }

}

$(document).ready(function() {

    $('a[name=modal]').click(function(e) {

        hideAnnoyingElements();

        e.preventDefault();

        var id = $(this).attr('href');

        var maskHeight = $(document).height();
        var maskWidth = $(document).width();

        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow", 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        var ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

        if (ie6) {
            $('#mask').css('width', maskWidth + 20);
            $(id).css('top', winH / 2 - $(id).height() / 2 + document.documentElement.scrollTop);
            $(id).css('position', 'absolute');
            document.body.style.height = 'auto';
            document.body.style.overflowY = 'auto';
            document.getElementsByTagName('html')[0].style.overflowX = 'hidden';
            document.getElementsByTagName('html')[0].style.overflowY = 'hidden';
        } else
            $(id).css('position', 'fixed');

        $(id).fadeIn(2000);


    });

    $('.window .close').click(function(e) {
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();
        DeleteValidation();
        showAnnoyingElements();

        var ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

        if (ie6) {
            document.body.style.height = '';
            document.body.style.overflowY = 'hidden';
            document.getElementsByTagName('html')[0].style.overflowX = 'auto';
            document.getElementsByTagName('html')[0].style.overflowY = 'auto';
            if (window.screen.width > 800)
                document.documentElement.style.overflowX = "hidden";
        }

        //Simulação de refresh na página para contornar bug no IE7, linha 47.
        simulateRefresh();
    });

    $('#mask').click(function() {
        $(this).hide();
        $('.window').hide();
        DeleteValidation();


        showAnnoyingElements();

        var ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

        if (ie6) {
            document.body.style.height = '';
            document.body.style.overflowY = 'hidden';
            document.getElementsByTagName('html')[0].style.overflowX = 'auto';
            document.getElementsByTagName('html')[0].style.overflowY = 'auto';
            if (window.screen.width > 800)
                document.documentElement.style.overflowX = "hidden";
        }

        //Simulação de refresh na página para contornar bug no IE7, linha 47.
        simulateRefresh();
    });

    $('area[id=modal]').click(function(e) {

        hideAnnoyingElements();

        e.preventDefault();

        var id = $(this).attr('href');

        var maskHeight = $(document).height();
        var maskWidth = $(document).width();

        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        $('#mask').fadeIn(1000);
        $('#mask').fadeTo("slow", 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);

        var ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

        if (ie6) {
            $('#mask').css('width', maskWidth + 20);
            $(id).css('top', winH / 2 - $(id).height() / 2 + document.documentElement.scrollTop);
            $(id).css('position', 'absolute');
            document.body.style.height = 'auto';
            document.body.style.overflowY = 'auto';
            document.getElementsByTagName('html')[0].style.overflowX = 'hidden';
            document.getElementsByTagName('html')[0].style.overflowY = 'hidden';
        } else
            $(id).css('position', 'fixed');

        $(id).fadeIn(2000);


    });

    $('.window .close').click(function(e) {
        e.preventDefault();

        $('#mask').hide();
        $('.window').hide();

        showAnnoyingElements();

        var ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

        if (ie6) {
            document.body.style.height = '';
            document.body.style.overflowY = 'hidden';
            document.getElementsByTagName('html')[0].style.overflowX = 'auto';
            document.getElementsByTagName('html')[0].style.overflowY = 'auto';
            if (window.screen.width > 800)
                document.documentElement.style.overflowX = "hidden";
        }

        //Simulação de refresh na página para contornar bug no IE7, linha 47.
        simulateRefresh();
    });

    $('#mask').click(function() {
        $(this).hide();
        $('.window').hide();

        showAnnoyingElements();

        var ie6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

        if (ie6) {
            document.body.style.height = '';
            document.body.style.overflowY = 'hidden';
            document.getElementsByTagName('html')[0].style.overflowX = 'auto';
            document.getElementsByTagName('html')[0].style.overflowY = 'auto';
            if (window.screen.width > 800)
                document.documentElement.style.overflowX = "hidden";
        }

        //Simulação de refresh na página para contornar bug no IE7, linha 47.
        simulateRefresh();
    });
});

function hideAnnoyingElements() {
    var objs = document.getElementsByTagName('select');
    for (i = 0; i < objs.length; i++) {
        objs[i].style.visibility = 'hidden';
    }

    objs = document.getElementsByTagName('object');
    for (i = 0; i < objs.length; i++) {
        objs[i].style.visibility = 'hidden';
    }

    objs = document.getElementsByTagName('embed');
    for (i = 0; i < objs.length; i++) {
        objs[i].style.visibility = 'hidden';
    }
};

function showAnnoyingElements() {
    var objs = document.getElementsByTagName('select');
    for (i = 0; i < objs.length; i++) {
        objs[i].style.visibility = 'visible';
    }

    objs = document.getElementsByTagName('object');
    for (i = 0; i < objs.length; i++) {
        objs[i].style.visibility = 'visible';
    }

    objs = document.getElementsByTagName('embed');
    for (i = 0; i < objs.length; i++) {
        objs[i].style.visibility = 'visible';
    }

};

function simulateRefresh() {
    $('#wrapper1').hide();
    $('#wrapper1').show();
}