$(document).ready(function() {
    if ($.browser.msie && ($.browser.version <= 7)) { $("body").addClass("ie"); } // Adiciona uma classe para o IE6.
    $("#formLogin").validate({ errorLabelContainer: $(".msgError") });
    $('#paises').change(function() {
        $url = $(this).find('option:selected').attr('value');
        if ($url != "") {
            window.open("http://" + $url, "_blank");
        }
    });

    //Envio de e-mail com link para o mapa do consultório da rede credenciada
    $("#enviarMapa").validate({ errorLabelContainer: $(".msgError"),
        submitHandler: function() {
            $.ajax({
                data: $("#enviarMapa").serialize(),
                dataType: "json",
                url: "/Consultorio/EnviarEmailMapa.ashx",
                success: function(json) {
                    if (json.msg == "OK") {
                        //Falta mostrar sucesso
                        parent.tb_remove();
                    } else {
                        //Falta tratar erro
                        parent.tb_remove();
                    }
                }
            });
        }
    });

    //Cadastro de pessoa física - passo 01 - avançar
    $("#formPessoaFisica01").validate({ errorContainer: $(".msgVerifique"), errorLabelContainer: $(".msgError"),
        submitHandler: function() {
            $.ajax({
                data: $("#formPessoaFisica01").serialize(),
                dataType: "json",
                url: "/PessoaFisica/SalvarCadastroPasso01.ashx",
                success: function(json) {
                    if (json.msg == "OK") {
                        //Falta mostrar sucesso
                        window.location = "/paraCorretores/sejaCorretorMetLife/cadastroPessoaFisicaPasso02.aspx"
                    } else {
                        //Falta tratar erro
                    }
                }
            });
        }
    });

    //Cadastro de pessoa física - passo 02 - retornar
    $("#retornarPessoaFisica02").click(function() {
        $.ajax({
            data: $("#formPessoaFisica02").serialize(),
            dataType: "json",
            url: "/PessoaFisica/SalvarCadastroPasso02.ashx",
            success: function(json) {
                if (json.msg == "OK") {
                    //Falta mostrar sucesso
                    window.location = "/paraCorretores/sejaCorretorMetLife/cadastroPessoaFisica.aspx"
                } else {
                    //Falta tratar erro
                }
            }
        });
    });

    //$("a[@href='/paraVoce/previdenciaComplementar/simuladorPrevidencia.aspx']").click(function() { // desabilita todos os links para o simulador de previdencia
    //	return false;
    //});

    //Cadastro de pessoa física - passo 02 - enviar
    $("#formPessoaFisica02").validate({ errorContainer: $(".msgVerifique"), errorLabelContainer: $(".msgError"),
        submitHandler: function() {
            $.ajax({
                data: $("#formPessoaFisica02").serialize(),
                dataType: "json",
                url: "/PessoaFisica/EnviarEmail.ashx",
                success: function(json) {
                    if (json.msg == "OK") {
                        //Falta mostrar sucesso
                        tb_show('', '/tb/tb_sucesso.html?keepThis=true&TB_iframe=true&width=332&height=86&modal=true', false);
                        //alert("Cadastro enviado com sucesso");
                    } else {
                        //Falta tratar erro
                    }
                }
            });
        }
    });

    //Cadastro de pessoa jurídica - passo 01 - avançar
    $("#formPessoaJuridica01").validate({ errorContainer: $(".msgVerifique"), errorLabelContainer: $(".msgError"),
        submitHandler: function() {
            $.ajax({
                data: $("#formPessoaJuridica01").serialize(),
                dataType: "json",
                url: "/PessoaJuridica/SalvarCadastroPasso01.ashx",
                success: function(json) {
                    if (json.msg == "OK") {
                        //Falta mostrar sucesso
                        window.location = "/paraCorretores/sejaCorretorMetLife/cadastroPessoaJuridicaPasso02.aspx"
                    } else {
                        //Falta tratar erro
                    }
                }
            });
        }
    });

    //Cadastro de pessoa jurídica - passo 02 - retornar
    $("#retornarPessoaJuridica02").click(function() {
        $.ajax({
            data: $("#formPessoaJuridica02").serialize(),
            dataType: "json",
            url: "/PessoaJuridica/SalvarCadastroPasso02.ashx",
            success: function(json) {
                if (json.msg == "OK") {
                    //Falta mostrar sucesso
                    window.location = "/paraCorretores/sejaCorretorMetLife/cadastroPessoaJuridica.aspx"
                } else {
                    //Falta tratar erro
                }
            }
        });
    });

    //Cadastro de pessoa jurídica - passo 02 - enviar
    $("#formPessoaJuridica02").validate({ errorContainer: $(".msgVerifique"), errorLabelContainer: $(".msgError"),
        submitHandler: function() {
            $.ajax({
                data: $("#formPessoaJuridica02").serialize(),
                dataType: "json",
                url: "/PessoaJuridica/EnviarEmail.ashx",
                success: function(json) {
                    if (json.msg == "OK") {
                        //Falta mostrar sucesso
                        tb_show('', '/tb/tb_sucesso.html?keepThis=true&TB_iframe=true&width=332&height=86&modal=true', false);
                        //alert("Cadastro enviado com sucesso");
                    } else {
                        //Falta tratar erro
                    }
                }
            });
        }
    });

    $("div#accordion, div.accordion").accordion({ autoheight: false, active: true, alwaysOpen: false, active: '.selected', header: 'h3', navigation: true, animated: 'easeslide' });
    $("ul#listTabs").idTabs();
    $("table.dados tr:even td").addClass('even');
    $("table.dados tr:odd td").addClass('odd');
    
	/*
	$randomnumber = Math.floor(Math.random()*2);	
	if ($randomnumber == 0){
		$("#flashParaVoce").flash({ src: '/swf/destaqueParaVoce.swf', width: 892, height: 290, wmode: 'transparent', scale: 'noscale', salign: 'tl', 
			flashvars: {
		        url1: ['/paraVoce/seguroVida/metLifeIndividual.aspx'].join(' '),
		        url2: ['/paraVoce/planosOdontologicos/planosCoberturas.aspx'].join(' '),
		        url3: ['/quemSomos/metLifeBrasil/Default.aspx'].join(' '),
		        url4: ['/paraVoce/planosOdontologicos/saudeBucal.aspx'].join(' ')
			}
	    }, { version: 8 });
	}
	else{	
		$("#flashParaVoce").flash({ src: '/swf/destaqueParaVoce20091202.swf', width: 892, height: 290, wmode: 'transparent', scale: 'noscale', salign: 'tl'
	    }, { version: 8 });
	}
	*/
	$("#flashParaVoce").flash({ src: '/swf/banner_Charlie_Brown.swf', width: 892, height: 290, wmode: 'transparent', scale: 'noscale', salign: 'tl'}, { version: 8 });
    $("#flashParaEmpresas").flash({ src: '/swf/destaqueParaEmpresas.swf', width: 892, height: 290, wmode: 'transparent', scale: 'noscale', salign: 'tl', 
		flashvars: {
	        url1: ['/paraEmpresas/planosOdontologicos/planosCoberturas.aspx'].join(' '),
	        url2: ['/paraEmpresas/previdenciaComplementar/multiPrev.aspx'].join(' '),
	        url3: ['/paraEmpresas/seguroVida/metLifeEmpresas.aspx'].join(' '),
	        url4: ['/paraEmpresas/seguroVida/metLifeBuyAndSell.aspx'].join(' ')
		}
    }, { version: 8 });
    $("#flashParaCorretores").flash({ src: '/swf/destaqueParaCorretores.swf', width: 893, height: 290, wmode: 'transparent', flashvars: { url: ['http://www.uol.com.br'].join(' ')} }, { version: 8 });
    $("input[@name='pesquisar'] + label").click(function() {
        $(".pesquisar").hide();
        $valor = $(this).prev().val();
        $("#tipoBusca").val($valor);
        if ($valor == 'Regiao') {
            $("#regiao").fadeIn();
        } else if ($valor == 'CEP') {
            $("#CEP").fadeIn();
        } else if ($valor == 'Nome') {
            $("#nome").fadeIn();
        }
    });

    $(".botaoAdd").click(function() {
        $bloco = $(this).prev().html();
        $(this).prev().append($bloco);
        return false;
    });

    $("#boxPais a").click(function() {
        $item = $(this).attr("href").split("#")[1];
        $("#descrPaises .item").hide();
        $("." + $item).fadeIn();
        return false;
    });

    $("#formSimulacao").validate({ errorLabelContainer: $(".msgError") });

    //Envio de e-mail para o ombudsman em atendimento
    $("#formOmbudsman").validate({ errorLabelContainer: $(".msgError"),
        submitHandler: function() {
            $.ajax({
                data: $("#formOmbudsman").serialize(),
                dataType: "json",
                url: "/Ombudsman/EnviarEmail.ashx",
                success: function(json) {
                    if (json.msg == "OK") {
                        tb_show('', '/tb/tb_sucessoEmail.html?keepThis=true&TB_iframe=true&width=332&height=86&modal=true', false);
                        //alert("Mensagem enviada com sucesso!");
                    } else {
                        alert("Erro ao enviar mensagem.")
                    }
                }
            });
        }
    });

    //Envio de e-mail de atendimento
    $("#formEmail").validate({ errorLabelContainer: $(".msgError"),
        submitHandler: function() {
            $.ajax({
                data: $("#formEmail").serialize(),
                dataType: "json",
                url: "/Atendimento/EnviarEmail.ashx",
                success: function(json) {
                    if (json.msg == "OK") {
                        tb_show('', '/tb/tb_sucessoEmail.html?keepThis=true&TB_iframe=true&width=332&height=86&modal=true', false);
                        //alert("Mensagem enviada com sucesso!");
                    } else {
                        alert("Erro ao enviar mensagem.")
                    }
                }
            });
        }
       });

       //Envio de e-mail de cadastro de corretor
       $("#formCadastroCorretor").validate({ errorLabelContainer: $(".msgError"),
       	submitHandler: function() {
       		$.ajax({
       		data: $("#formCadastroCorretor").serialize(),
       			dataType: "json",
       			url: "/CadastroCorretor/EnviarEmail.ashx",
       			success: function(json) {
       				if (json.msg == "OK") {
       					tb_show('', '/tb/tb_sucessoEmail.html?keepThis=true&TB_iframe=true&width=332&height=86&modal=true', false);
       					//alert("Mensagem enviada com sucesso!");
       				} else {
       					alert("Erro ao enviar mensagem.")
       				}
       			}
       		});
       	}
       });

    $("#chatPrevidencia").click(function() {
        openWindow('http://200.225.91.178/metlife201/chat4/cliente/frm_login.asp?IDArea=1&sel=HomePage', 'remote')
        return false;
    });

    $("#chatPlanosOdonto").click(function() {
        //openWindow('http://201.90.107.66:8082/orbium_prd/chat/default.aspx?chat=1&group=Origem&url=http://201.90.107.66:8082/orbium_prd/chat/test.aspx', 'remote')
		openWindow('http://chatonline.metlife.com.br:8082/orbium_prd/chat/default.aspx?chat=1&group=Origem&url=http://chatonline.metlife.com.br:8082/orbium_prd/chat/test.aspx ', 'remote')
        return false;
    });

    $("select#plano").change(function() {
        $plano = $(this).val();
        if ($plano == 1) {
            $("#rentabilidade").val("6.00%");
        } else if ($plano == 2) {
            $("#rentabilidade").val("8.00%");
        }
    });

    $("#comboUfs").change(function() {
        $id = $(this).val();
        if ($id > 0) {
            $("#comboMunicipios").load("/Consultorio/CarregarMunicipios.ashx", { uf: $id }).removeAttr("disabled");
        } else {
            $("#comboMunicipios").html("");
            $("#comboMunicipios").attr("disabled", "disabled");
        }
        $("#comboBairros").html("").attr("disabled", "disabled");
    });

    $("#comboMunicipios").change(function() {
        $id = $(this).val();
        if ($id > 0) {
            $("#comboBairros").load("/Consultorio/CarregarBairros.ashx", { municipio: $id }).removeAttr("disabled");
        } else {
            $("#comboBairros").html("").attr("disabled", "disabled");
        }
    });

    //Busca na rede credenciada
    $("form.redeCredenciada").each(function() {
        $(this).validate({ errorLabelContainer: $(".msgError"),
            submitHandler: function() {
                $("input[@name='submit']").attr("disabled", "disabled");
                $("#searching").fadeIn();
                $.ajax({
                    data: $(this.currentForm).serialize(),
                    url: '/Consultorio/Consultar.ashx',
                    success: function(html) {
                        $("#resultadoBusca").hide().html(html).fadeIn();
                        $("input[@name='submit']").removeAttr("disabled");
                        $("#searching").fadeOut();
                        window.location = '#box634';
                    }
                });
            }
        });
    });

    //Envio de newsletter
    $("form.newsletter").each(function() {
        $(this).validate({ errorLabelContainer: $(".msgError"),
            submitHandler: function() {
                $.ajax({
                    data: $(this.currentForm).serialize(),
                    dataType: "json",
                    url: '/Newsletter/EnviarEmail.ashx',
                    success: function(json) {
                        if (json.msg == "OK") {
                            //alert("Mensagem enviada com sucesso!");
                            tb_show('', '/tb/tb_sucesso.html?keepThis=true&TB_iframe=true&width=332&height=86&modal=true', false);
                        } else {
                            alert("Erro ao enviar mensagem.")
                        }
                    }
                });
            }
        });
    });



    //Cadastro Conar
    $("form.cadastroConar").each(function() {
        $(this).validate({ errorLabelContainer: $(".msgError"),
            submitHandler: function() {
                $.ajax({
                    data: $(this.currentForm).serialize(),
                    dataType: "json",
                    url: '/NewsletterConarRh/EnviarEmail.ashx',
                    success: function(json) {
                        if (json.msg == "OK") {
                            //alert("Mensagem enviada com sucesso!");
                            tb_show('', '/tb/tb_sucesso.html?keepThis=true&TB_iframe=true&width=332&height=86&modal=true', false);
                        } else {
                            alert("Erro ao enviar mensagem.")
                        }
                    }
                });
            }
        });
    });

    //Envio de newsletter multiprev
    $("#formNewsletterMultiprev").validate({ errorLabelContainer: $(".msgError"),
        submitHandler: function() {
            $.ajax({
                data: $("#formNewsletterMultiprev").serialize(),
                dataType: "json",
                url: "/NewsletterMultiprev/EnviarEmail.ashx",
                success: function(json) {
                    if (json.msg == "OK") {
                        //Falta mostrar sucesso
                        tb_show('', '/tb/tb_sucesso.html?keepThis=true&TB_iframe=true&width=332&height=86&modal=true', false);
                        //alert("Mensagem enviada com sucesso");
                    } else {
                        //Falta tratar erro
                    }
                }
            });
        }
    });

    //Credenciamento de dentistas
    $("form.credenciamentoDentista").each(function() {
        $(this).validate({ errorLabelContainer: $(".msgError"),
            submitHandler: function() {
                $.ajax({
                    data: $(this.currentForm).serialize(),
                    dataType: "json",
                    url: '/CredenciamentoDentista/EnviarEmail.ashx',
                    success: function(json) {
                        if (json.msg == "OK") {
                            tb_show('', '/tb/tb_sucesso.html?keepThis=true&TB_iframe=true&width=332&height=86&modal=true', false);
                            //alert("Mensagem enviada com sucesso!");
                        } else {
                            alert("Erro ao enviar mensagem.")
                        }
                    }
                });
            }
        });
    });

    //Busca no site
    $("div#busca input[@type='image']").click(function() {
        $filtro = $("div#busca input[@type='text']").val();
        $.ajax({
            data: $(this.currentForm).serialize(),
            dataType: "json",
            url: '/Busca/ValidarFiltro.ashx?filtro=' + $filtro,
            success: function(json) {
                if (json.msg == "OK") {
                    window.location = "/ResultadoBusca.aspx?filtro=" + $filtro;
                } else {
                    alert("Filtro inválido na busca!")
                }
            }
        });
    });

    $("input[@type='radio'] + label, input[@type='checkbox'] + label").click(function() {
        if ($(this).prev().is(":checked")) {
            $(this).prev().attr("checked", "");
        } else {
            $(this).prev().attr("checked", "checked");
        }
    });

    $(".checkbox").cssCheckbox();
    $(".radio").cssRadio();
    if ($(".boxAdvise").size() >= 1) {
        $nBox = $(".boxAdvise").size() - 1;
        $dBox = (Math.round((Math.random() * $nBox) + 1));
        $(".dest" + $dBox).fadeIn();
    }

    $("input[@type=radio][@checked]").next().next().fadeIn();

    $(".navAdvice a").click(function() {
        $(".boxAdvise").hide();
        $dest = $(this).attr("href").split("#")[1];
        $("." + $dest).fadeIn();
        return false;
    });

    $("input.dia").mask("99");
    $("input.mes").mask("99");
    $("input.ano").mask("9999");
    $("input.ddd").mask("99");
    $("input.date").mask("99/99/9999");
    $("input.tel").mask("99999999");
    $("input.telefone").mask("99-99999999");
    $("input.cep").mask("99999-999");
    $("input.cpf").mask("999.999.999-99");
    $("input.cnpj").mask("99.999.999/9999-99");
    $(".real").maskMoney({ symbol: "", decimal: ",", thousands: "." });
    $(":input").autotab_magic();

    /* INICIO - Cookie de navegacao */
    if ($("div").hasClass("prehome")) {
        $urlRedirect = $.cookie('metlife');
        if ($urlRedirect != null) {
            window.location = $urlRedirect;
        } else {
            window.location = 'paraVoce/Default.aspx';
        }
    } else if ($("body").hasClass("login")) {
    } else {
        $url = window.location.pathname.split("/")[1];
        switch ($url) {
            case 'paraVoce':
            case 'paraEmpresas':
            case 'paraCorretores':
            case 'paraDentistas':
                $redirect = $url;
                break;
            default:
                $redirect = 'paraVoce';
                break;
        }
        $.cookie('metlife', '/' + $redirect + '/Default.aspx', { path: '/', expires: 100 });
    }
    /* FINAL - Cookie de navegacao */

});

function openWindow(url, name){ 
	var winWidth = 488;
	var winHeight = 450;
	var winTop = parseInt((screen.availHeight - winHeight) / 2);
	var winLeft = parseInt((screen.availWidth - winWidth) / 2);
	popupWin = window.open(url,name,"width=" + winWidth + ",height=" + winHeight + ",top=" + winTop + ",left=" + winLeft + ",resizable=no,scrollbars=no,statusbar=no");
	if (popupWin.opener == null) {
		popupWin.opener = self;
	}
} 

function Paginate(page){
	$("#searching").fadeIn();
	$("#resultadoBusca").animate({ height: 'toggle' }, 2000);
	// $form = $("input[@name='pesquisar'] + label").val();
	$form = $("#tipoBusca").val();
	$.ajax({
	    data: $("#form" + $form).serialize() + '&page=' + page, 
		type: 'GET',
		dataType: "html",
		url: '/Consultorio/Consultar.ashx',
		success: function(html) {
			$("#resultadoBusca").html(html).fadeIn();
			$("#searching").fadeOut();
		}  
	}); 
}

/**
 * Autotab - jQuery plugin 1.1b
 * http://www.lousyllama.com/sandbox/jquery-autotab
 * 
 * Copyright (c) 2008 Matthew Miller
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 * 
 * Revised: 2008-09-10 16:55:08
 */

(function($) {
// Look for an element based on ID or name
var check_element = function(name) {
	var obj = null;
	var check_id = $('#' + name);
	var check_name = $('input[name=' + name + ']');

	if(check_id != undefined)
		obj = check_id;
	else if(check_name != undefined)
		obj = check_name;

	return obj;
};

$.fn.autotab_magic = function(focus) {
	for(var i = 0; i < this.length; i++)
	{
		var n = i + 1;
		var p = i - 1;

		if(i > 0 && n < this.length)
			$(this[i]).autotab({ target: $(this[n]), previous: $(this[p]) });
		else if(i > 0)
			$(this[i]).autotab({ previous: $(this[p]) });
		else
			$(this[i]).autotab({ target: $(this[n]) });

		// Set the focus on the specified element
		if(focus != null && (isNaN(focus) && focus == $(this[i]).attr('id')) || (!isNaN(focus) && focus == i))
			$(this[i]).focus();
	}
};

$.fn.autotab_filter = function(options) {
	var defaults = {
		format: 'all',
		uppercase: false,
		lowercase: false,
		nospace: false,
		pattern: null
	};

	if(typeof options == 'string' || typeof options == 'function')
		defaults.format = options;
	else
		$.extend(defaults, options);

	for(var i = 0; i < this.length; i++)
	{
		$(this[i]).bind('keyup', function(e) {
			var val = this.value;

			switch(defaults.format)
			{
				case 'text':
					var pattern = new RegExp('[0-9]+', 'g');
					val = val.replace(pattern, '');
					break;

				case 'alpha':
					var pattern = new RegExp('[^a-zA-Z]+', 'g');
					val = val.replace(pattern, '');
					break;

				case 'number':
				case 'numeric':
					var pattern = new RegExp('[^0-9]+', 'g');
					val = val.replace(pattern, '');
					break;

				case 'alphanumeric':
					var pattern = new RegExp('[^0-9a-zA-Z]+', 'g');
					val = val.replace(pattern, '');
					break;

				case 'custom':
					var pattern = new RegExp(defaults.pattern, 'g');
					var val = val.replace(pattern, '');
					break;

				case 'all':
				default:
					if(typeof defaults.format == 'function')
						var val = defaults.format(val);

					break;
			}

			if(defaults.nospace)
			{
				var pattern = new RegExp('[ ]+', 'g');
				val = val.replace(pattern, '');
			}

			if(defaults.uppercase)
				val = val.toUpperCase();

			if(defaults.lowercase)
				val = val.toLowerCase();

			if(val != this.value)
				this.value = val;
		});
	}
};

$.fn.autotab = function(options) {
	var defaults = {
		format: 'all',
		maxlength: 2147483647,
		uppercase: false,
		lowercase: false,
		nospace: false,
		target: null,
		previous: null,
		pattern: null
	};

	$.extend(defaults, options);

	// Sets targets to element based on the name or ID
	// passed if they are not currently objects
	if(typeof defaults.target == 'string')
		defaults.target = check_element(defaults.target);

	if(typeof defaults.previous == 'string')
		defaults.previous = check_element(defaults.previous);

	var maxlength = $(this).attr('maxlength');

	// defaults.maxlength has not changed and maxlength was specified
	if(defaults.maxlength == 2147483647 && maxlength != 2147483647)
		defaults.maxlength = maxlength;
	// defaults.maxlength overrides maxlength
	else if(defaults.maxlength > 0)
		$(this).attr('maxlength', defaults.maxlength)
	// defaults.maxlength and maxlength have not been specified
	// A target cannot be used since there is no defined maxlength
	else
		defaults.target = null;

	if(defaults.format != 'all')
		$(this).autotab_filter(defaults);

	// Go to the previous element when backspace
	// is pressed in an empty input field
	return $(this).bind('keydown', function(e) {
		if(e.which == 8 && this.value.length == 0 && defaults.previous)
			defaults.previous.focus().val(defaults.previous.val());
	}).bind('keyup', function(e) {
		var keys = [8, 9, 16, 17, 18, 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145];

		if(e.which != 8)
		{
			var val = $(this).val();

			if($.inArray(e.which, keys) == -1 && val.length == defaults.maxlength && defaults.target)
				defaults.target.focus();
		}
	});
};

})(jQuery);


/**
 * Cookie plugin
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function printPage() {
	if (window.print){
		window.print()
	}else{
		alert("O script não conseguiu envira o documento diretamente para impressão,\nPressione Ctrl+P ou selecione Imprimir no menu Arquivo para imprimir esta página.");
	}
}

function janela(endereco,pagina,largura,altura,menus,parametros) {
		var larg = window.screen.width;
		var altr = window.screen.height;
		var posicao_h = (larg-largura)/2;
		var posicao_v = (altr-altura)/2-menus;
		pagina = parent.open(endereco, pagina, "width="+largura+",height="+altura+",top="+posicao_v+",left="+posicao_h+","+parametros);
		pagina.blur();
		pagina.focus();
	}
	
function previdencia()
{
   window.open('/pop/previdenciaCorporate.html','Previdencia_Corporate','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=450,height=250');
}

function noticiasCorretor()
{
   window.open('/pop/noticiasCorretor.html','Previdencia_Corporate','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=610,height=460');
}

function noticiasCorretorEdicao1()
{
   window.open('/pop/noticiasCorretorEdicao1.html','Previdencia_Corporate','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=610,height=460');
}

function noticiasCorretorEdicao2()
{
   window.open('/pop/noticiasCorretorEdicao2.html','Previdencia_Corporate','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=610,height=460');
}

function maisSorriso()
{
   window.open('/pop/maisSorriso.html','Previdencia_Corporate','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=610,height=460');
}