    var _ErrorMessage = "JavascriptError: \n\tFile:\n\t\t{0} \n\tFunction:\n\t\t{1} \n\tError Message:\n\t\t {2}";

    /// <summary>
    /// Throw the exception formated for the user
    /// </summary>
    function ShowException(file,fcn,msg)
    {
        alert(_ErrorMessage.toString().replace('{0}',file).replace('{1}',fcn).replace('{2}',msg));
    }
    
    /// <summary>
    /// Adjust the page layout, called every request
    /// </summary>
    function AdjustLayout()
    {
        try
        {
			AdjustGalleryLightBox();
			AdjustCycle();
			AdjustToolTip();
			AdjustConfirmButton();
			AdjustjCarousel();
			AdjustPng();
			AdjustReflection();
			AdjustLoginForm();
 		}
        catch(ex)
        {
            ShowException('Portal.js','AdjustLayout();',ex.message);
        }
    }
	
	function AdjustDivPosition()
	{
		obj_1 = document.getElementById('conteudo_esquerda'); //Div que vai ter a nova altura
		obj_2 = document.getElementById('conteudo_categorias'); //Div que vai ter a nova altura
		obj_3 = document.getElementById('conteudo_direita'); //Div que vai ter a nova altura
    	obj_4 = document.getElementById('conteudo_meio'); //Div com a altura que queremos
   		altura_pri = parseInt(obj_4.offsetHeight) - 0 + 'px';
		obj_1.style.height = obj_2.style.height = obj_3.style.height = altura_pri;
	}
    function AdjustReflection()
    {
        try
        {
			$('input:text').setMask();
			$('.Atria_SelectPaymentType_Products_PaymentTypes_PaymentType_Buy>a').addClass('ui-iconbuttontext ui-state-default');
			$('.ui-state-default').hover(function(){
				$(this).addClass('ui-state-hover');
			}, function(){
				$(this).removeClass('ui-state-hover');
			});
			$('.Atria_MailSender_Buttons_BtnSend>input',$('.confirmapedido').parent().parent()).attr('style','background-color:white !IMPORTANT;background-image:url(/Content/Artifacts/fckeditor/image/Buttons/btn_confirmarPedido.jpg) !IMPORTANT;background-repeat:no-repeat !IMPORTANT;border: 0px !IMPORTANT;color:transparent !IMPORTANT;height:24px !IMPORTANT;width:127px !IMPORTANT;');
		}
		catch(ex)
		{
            ShowException('Portal.js','AdjustReflection();',ex.message);
		}
	}

    function AdjustPng()
    {
        try
        {
			if ($.browser.msie) {
				$(document).pngFix(); 
			}
		}
		catch(ex)
		{
            ShowException('Portal.js','AdjustPng();',ex.message);
		}
	}

    /// <summary>
    /// Adjust the gallery lightbox plugin
    /// </summary>
    function AdjustGalleryLightBox()
    {
        try
        {
			if (!($.browser.msie && $.browser.version == '6.0')) {
				//$('. > a > img').lightbox();
			}
		}
		catch(ex)
		{
            ShowException('Portal.js','AdjustGalleryLightBox();',ex.message);
		}
	}
	
	/// <summary>
    /// Adjust the jCarousel plugin
    /// </summary>
    function AdjustjCarousel()
    {
        try
        {
		}
		catch(ex)
		{
            ShowException('Portal.js','AdjustjCarousel();',ex.message);
		}
	}
	
    /// <summary>
    /// Adjust the cycle plugin
    /// </summary>
    function AdjustCycle()
    {
        try
        {
		}
		catch(ex)
		{
            ShowException('Portal.js','AdjustCycle();',ex.message);
		}
	}
	
	/// <summary>
    /// Display a confirm message in all delete buttons
    /// </summary>
    function AdjustConfirmButton()
    {
        try
        {
            //bind the click function with the oldhref attr value
            $('.ConfirmButton').bind('click', function(){
            
                var button = $(this);
                var text = button.attr('ConfirmText') == undefined ? 'Confirm delete?' : button.attr('ConfirmText');
                var ok = button.attr('ConfirmTextOk') == undefined ? 'Yes' : button.attr('ConfirmTextOk');
                var cancel = button.attr('ConfirmTextCancel') == undefined ? 'No' : button.attr('ConfirmTextCancel');
               
                $.prompt(
                    text,
                    { 
                        buttons: { Ok: ok, Cancel: cancel }, 
                        zIndex: 99999999,
                        focus: 1, 
                            prefix:'Atria_Global_Warning',   
                        callback : function(v,m) { 
                            if (v == ok) { 
                                eval(button.attr('oldhref').substring(11)); 
                            } 
                        }
                    }
                );
            });
            
            //remove href and puts in the oldhref
            $('.ConfirmButton').each(function(){
                    $(this).attr('oldhref',$(this).attr('href'));
            });
                
            //clear href
            $('.ConfirmButton').attr('href','#');

            //make confirm required
        }
        catch(ex)
        {
            ShowException('Portal.js', 'AdjustConfirmButton();', ex.message);
        }
    }

    /// <summary>
    /// Adjust the tool tip plugin
    /// </summary>
    function AdjustToolTip()
    {
        try
        {
			$('[title]').tooltip({
				fade: false,
				showURL: false,
				track: true
			});
			if (!$.browser.msie) {
				$.jcorners('#tooltip',{radius:5});
			}
        }
        catch(ex)
        {
            ShowException('Portal.js', 'AdjustToolTip();', ex.message);
        }
    }
	function AdjustLoginForm()
	{
		try
		{
			$(".UserLogin_CellInput>input").keypress(function (e) {
				if (e.which == 13){
					$('#conteudo_meio .UserLogin_CellButton input').click(); 
					return false;
				}
			});
		}
        catch(ex)
        {
            ShowException('Portal.js', 'AdjustLoginForm();', ex.message);
        }

	}
	var ShowCart_IntervalId = 0;
    function ShowCart()
    {
        try
        {
			$('<div title="Meu Carrinho"></div>').dialog({
				width:520,
				height:300,
				resizable: false,
				draggable: false,
				dialogClass: 'dialog_fixed',
				modal:true,
				buttons:{
					'Finalizar pedido':function(){
						$(this).dialog('close');
						document.location = '/Ecommerce/Step1/Cart/42/pgaFecharCarrinho.aspx';
					},
					'Continuar comprando':function(){
						$(this).dialog('close');
					}
				},
				open: function(event, ui) {
					var $this = $(this);
					if ($('.ProductCart_Hidden').eq(0).html() != '') {
						$this.append($($('.ProductCart_Hidden').eq(0).html()));
					}
					ShowCart_IntervalId = setInterval(function(){
						$this.html('');
						if ($('.ProductCart_Hidden').eq(0).html() != '') {
							$this.append($($('.ProductCart_Hidden').eq(0).html()));
						}
					},1000);
				},
				close: function(event, ui) {
					 clearInterval(ShowCart_IntervalId);
				}
			});
		}
        catch(ex)
        {
            ShowException('Portal.js', 'ShowCart();', ex.message);
        }
    }

	function SimulaFrete()
    {
        try
        {
			var weight = 0;
			$('.ProductCart_Item_Full_Weight').each(function(){weight += parseInt($(this).html()) * parseInt($('.ProductCart_Item_Full_Count_Fixed',$(this).parent()).html());});
			$('<div class="SimularFrete" title="Simular Frete"><label for="txtMyCep">Seu CEP: </label><input id="txtMyCep" name="txtMyCep" maxlength="8" size="8" type="text" /><br /><label for="txtTotalCep">Frete (R$): </label><input id="txtTotalCep" name="txtTotalCep" maxlength="10" size="4" type="text" readonly="readonly" /></div>').dialog({
				width: 300,
				height: 150,
				resizable: false,
				draggable: true,
				modal: true,
				dialogClass: 'ui-dialog-frete',
				buttons:{
					'Fechar pedido':function(){
						$(this).dialog('close');
						document.location = '/Ecommerce/Step2/Cart/43/pgaSelecionaEndereco.aspx';
					},
					'Calcular frete':function(){
						$.ajax({
							type: "POST",
							url: "/Services/Sedex/CalculateFreight.asmx/GetFreight",
							data: "{currentSedexType: '40010', zipCodeSender: '90640002', zipCodeReceiver: '" + $('#txtMyCep').val() + "', weight: '" + weight + "'}",
							contentType: "application/json; charset=utf-8",
							dataType: "json",
							error: function(xml) {
								$('input[name=txtTotalCep]').val('30,00');
							},
							success: function(freight) {
								$('input[name=txtTotalCep]').val(freight.Value.toString().replace('.',','));
							}
						});
					}
				},
				open: function(event, ui) {
					$('#txtMyCep', $(this)).focus(); 
				}
			});		
		}
        catch(ex)
        {
            ShowException('Portal.js', 'ShowCart();', ex.message);
        }
    }
	function showCartMessage(ProductId)
	{
		try
		{
			$.Atria_Ecommerce_AddToCart(ProductId, function() {
			$.prompt('<div class="mensagem_box_titulo">Mensagem</div><br/><div class="mensagem_box">Produto adicionado ao carrinho!</div><br/>',
			{
				prefix:'Atria_Global_Alert', 
				buttons: { Ok: true }, 
				callback: function(){window.location = '/Page/27/pgaProdutosCarrinho.aspx';}
				});
			});
		}
		catch(ex)
        {
            ShowException('Portal.js', ' showCartMessage();', ex.message);
        }
	}
    function ApiBminds_Atria_LogoutUser()
    {
        $.getScript('/Services/User/Logout.aspx');
    }	