    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));
		if (console != null) {
			console.error(_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();
			AdjustReflection();
			AdjustMask();
 		}
        catch(ex)
        {
            ShowException('Portal.js','AdjustLayout();',ex.message);
        }
    }
	function AdjustMask() 
	{
        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');
			});
 		}
        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
        {
			$('.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);
        }
    }
	
	var ShowCart_IntervalId = 0;
    function ShowCart()
    {
        try
        {
			document.location = '/Ecommerce/Step1/Cart/32/pgaInscricoes.aspx';
			return false;
		}
        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 title="Simular Frete"><label for="txtMyCep">Seu CEP: </label><input id="txtMyCep" name="txtMyCep" maxlength="8" size="8" type="text" /><br /><br /><label for="txtTotalCep">Frete: </label><input id="txtTotalCep" name="txtTotalCep" maxlength="10" size="4" type="text" readonly="readonly" /></div>').dialog({
				width: 300,
				height: 350,
				resizable: false,
				draggable: true,
				modal: true,
				dialogClass: 'ui-dialog-frete',
				buttons:{
					'Fechar pedido':function(){
						$(this).dialog('close');
						document.location = '/Ecommerce/Step2/Cart/33/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', 'SimulaFrete();', ex.message);
        }
    }
	
    function ApiBminds_Atria_LogoutUser()
    {
        $.getScript('/Services/User/Logout.aspx');
    }	