// JScript File
String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g,"");}

function VerificaEmail(pcampo)
{
	pcampo.value = pcampo.value.toLowerCase();					
	parametro = pcampo.value;								
	teste_parametro = "false"; 
	tamanho_parametro = parametro.length;
	aposicao = 0; //posicao @
	pposicao = 0; //poiscao ponto
	narrobas = 0; // numero de @
	for (i = 0; i < tamanho_parametro; i++) { /*verifica se existe espaco em branco */
		if (parametro.charAt(i) == "@"){
			narrobas = narrobas + 1
			aposicao = i;
		}
		if (parametro.charAt(i) == "."){
			pposicao = i;
		}
	}
	if (aposicao > 0 && aposicao+1 < pposicao && narrobas<2){
		teste_parametro = "true"; 
	}

	for (i = 0; i < tamanho_parametro; i++) { /*verifica se existe espaco em branco ..*/
		if (parametro.charAt(i) == " "){
			teste_parametro = "false"; 
		}
	}
	
	if (tamanho_parametro < 5){
		teste_parametro = "false"; /*tamanho minimo*/
	}
		
	if (parametro.charAt(0) == " " || parametro.charAt(1) == " ") { /*Primeiros chars em branco */
		teste_parametro = "false"; 
	}
	
	if (teste_parametro == "false" && tamanho_parametro != 0 ) { /*Existe algum problema no preenchiento do nome */
		MsgBox.Show("Dados Inválidos", "Verifique seu e-mail.", "alerta");
		pcampo.value = "";
		pcampo.focus();
		return false;
	}
	else
		return true;
}

function CustomMessageBox()
{
	this.caption = "";
	this.mensagem = "";
	this.tipoIcone = "";
	this.blnTabAtivo = true;
	this.SrcImgOk = "";
	this.SrcImgCancel = "";
	
	document.write ("<div id=\"divMsgBox\" ></div>");
	
	CustomMessageBox.prototype.Close = function()
	{
		$("#divInternoMsgBox").hide();
		$("#divMsgBox").hide().html();
		this.blnTabAtivo = true;
	}
	
	CustomMessageBox.prototype.PressClose = function()
	{
		this.Close();
	}
	
	CustomMessageBox.prototype.PressOk = function()
	{
		this.Close();
	}
	
	CustomMessageBox.prototype.PressCancel = function()
	{
		this.Close();
	}
	
	CustomMessageBox.prototype.Show = function(strCaption, strMensagem, idTipoIcone)
	{
		var htmlToInject;
		this.caption = strCaption;
		this.mensagem = strMensagem;
		this.tipoIcone = idTipoIcone;
		
		if (this.tipoIcone == "")
		{
			htmlToInject = "<div id=\"divInternoMsgBox\" class=\"interno_simple_msgbox\"><div class=\"topo_msgbox\">";
			htmlToInject = htmlToInject + "<a id=\"btnFecharMsgBox\" href=\"javascript:MsgBox.PressClose();\" title=\"fechar esta mensagem\">fechar esta mensagem</a></div>";
			htmlToInject = htmlToInject + "<div class=\"corpo_msgbox\"><div class=\"interno_corpo_msgbox\"><span class=\"caption_msgbox\">";
			htmlToInject = htmlToInject + this.caption;
			htmlToInject = htmlToInject + "</span><span class=\"mensagem_msgbox\">";
			htmlToInject = htmlToInject + this.mensagem;
			htmlToInject = htmlToInject + "</span></div></div><div class=\"rodape_msgbox\"></div></div>";
		}
		else
			if (this.tipoIcone == "alerta")
			{
				htmlToInject = "<div id=\"divInternoMsgBox\" class=\"interno_alert_msgbox\"><div class=\"topo_msgbox\">";
				htmlToInject = htmlToInject + "<a id=\"btnFecharMsgBox\" href=\"javascript:MsgBox.PressClose();\" title=\"fechar esta mensagem\">fechar esta mensagem</a></div>";
				htmlToInject = htmlToInject + "<div class=\"corpo_msgbox\"><div class=\"interno_corpo_msgbox\"><div class=\"bloco_icone\"><span class=\"icone_alerta\">icone_alerta</span></div>";
				htmlToInject = htmlToInject + "<div class=\"bloco_texto\"><span class=\"caption_msgbox\">";
				htmlToInject = htmlToInject + this.caption;
				htmlToInject = htmlToInject + "</span><span class=\"mensagem_msgbox\">";
				htmlToInject = htmlToInject + this.mensagem;
				htmlToInject = htmlToInject + "</span></div><br clear=\"all\"/></div></div><div class=\"rodape_msgbox\"></div></div>";
			}
			else
				if (this.tipoIcone == "pergunta")
				{
					htmlToInject = "<div id=\"divInternoMsgBox\" class=\"interno_question_msgbox\"><div class=\"topo_msgbox\"></div><div class=\"corpo_msgbox\">";
					htmlToInject = htmlToInject + "<div class=\"interno_corpo_msgbox\"><span class=\"mensagem_msgbox\">";
					htmlToInject = htmlToInject + this.mensagem;
					htmlToInject = htmlToInject + "</span>";
					htmlToInject = htmlToInject + "<a id=\"btnYesMsgBox\" href=\"javascript:MsgBox.PressOk();\">";
					htmlToInject = htmlToInject + "<img src=\""  + this.SrcImgOk + "\" />";
					htmlToInject = htmlToInject + "</a>&nbsp;&nbsp;";
					htmlToInject = htmlToInject + "<a id=\"btnNoMsgBox\" href=\"javascript:MsgBox.PressCancel();\">";
					htmlToInject = htmlToInject + "<img src=\""  + this.SrcImgCancel + "\" />";
					htmlToInject = htmlToInject + "</a>";
					htmlToInject = htmlToInject + "</div></div>";
					htmlToInject = htmlToInject + "<div class=\"rodape_msgbox\"></div></div>";
				}
		
		$("#divMsgBox").html(htmlToInject);
		$("#divMsgBox").show();
		$("#divInternoMsgBox").show();

		$("#btnFecharMsgBox").focus();
		
		if (($.browser.msie) && ( $.browser.version <=6 )) {
			$('#divInternoMsgBox').pngFix(); 


		}
		this.blnTabAtivo = false;
	}
	
    CustomMessageBox.prototype.ShowWithRedirect = function(strCaption, strMensagem, idTipoIcone, urlDestino)
	{
		var htmlToInject;
		this.caption = strCaption;
		this.mensagem = strMensagem;
		this.tipoIcone = idTipoIcone;
		
		if (this.tipoIcone == "")
		{
			htmlToInject = "<div id=\"divInternoMsgBox\" class=\"interno_simple_msgbox\"><div class=\"topo_msgbox\">";
			htmlToInject = htmlToInject + "<a id=\"btnFecharMsgBox\" href=\"javascript:MsgBox.PressClose(); window.location.href='" + urlDestino + "';\" title=\"fechar esta mensagem\">fechar esta mensagem</a></div>";
			htmlToInject = htmlToInject + "<div class=\"corpo_msgbox\"><div class=\"interno_corpo_msgbox\"><span class=\"caption_msgbox\">";
			htmlToInject = htmlToInject + this.caption;
			htmlToInject = htmlToInject + "</span><span class=\"mensagem_msgbox\">";
			htmlToInject = htmlToInject + this.mensagem;
			htmlToInject = htmlToInject + "</span></div></div><div class=\"rodape_msgbox\"></div></div>";
		}
		else
			if (this.tipoIcone == "alerta")
			{
				htmlToInject = "<div id=\"divInternoMsgBox\" class=\"interno_alert_msgbox\"><div class=\"topo_msgbox\">";
				htmlToInject = htmlToInject + "<a id=\"btnFecharMsgBox\" href=\"javascript:MsgBox.PressClose(); window.location.href='" + urlDestino + "';\" title=\"fechar esta mensagem\">fechar esta mensagem</a></div>";
				htmlToInject = htmlToInject + "<div class=\"corpo_msgbox\"><div class=\"interno_corpo_msgbox\"><div class=\"bloco_icone\"><span class=\"icone_alerta\">icone_alerta</span></div>";
				htmlToInject = htmlToInject + "<div class=\"bloco_texto\"><span class=\"caption_msgbox\">";
				htmlToInject = htmlToInject + this.caption;
				htmlToInject = htmlToInject + "</span><span class=\"mensagem_msgbox\">";
				htmlToInject = htmlToInject + this.mensagem;
				htmlToInject = htmlToInject + "</span></div><br clear=\"all\"/></div></div><div class=\"rodape_msgbox\"></div></div>";
			}
			else
				if (this.tipoIcone == "pergunta")
				{
					htmlToInject = "<div id=\"divInternoMsgBox\" class=\"interno_question_msgbox\"><div class=\"topo_msgbox\"></div><div class=\"corpo_msgbox\">";
					htmlToInject = htmlToInject + "<div class=\"interno_corpo_msgbox\"><span class=\"mensagem_msgbox\">";
					htmlToInject = htmlToInject + this.mensagem;
					htmlToInject = htmlToInject + "</span>";
					htmlToInject = htmlToInject + "<a id=\"btnYesMsgBox\" href=\"javascript:MsgBox.PressOk();\">";
					htmlToInject = htmlToInject + "<img src=\""  + this.SrcImgOk + "\" />";
					htmlToInject = htmlToInject + "</a>&nbsp;&nbsp;";
					htmlToInject = htmlToInject + "<a id=\"btnNoMsgBox\" href=\"javascript:MsgBox.PressCancel();\">";
					htmlToInject = htmlToInject + "<img src=\""  + this.SrcImgCancel + "\" />";
					htmlToInject = htmlToInject + "</a>";
					htmlToInject = htmlToInject + "</div></div>";
					htmlToInject = htmlToInject + "<div class=\"rodape_msgbox\"></div></div>";
				}
		
		$("#divMsgBox").html(htmlToInject);
		$("#divMsgBox").show();
		$("#divInternoMsgBox").show();

		$("#btnFecharMsgBox").focus();
		
		if (($.browser.msie) && ( $.browser.version <=6 )) {
			$('#divInternoMsgBox').pngFix(); 


		}
		this.blnTabAtivo = false;
	}	
}

var MsgBox = new CustomMessageBox();

function mascara(e,src,mask) 
{
    if(window.event) 
    {
        _TXT = e.keyCode;
    } else
        if(e.which) 
        {
            _TXT = e.which;
        }
        if(_TXT > 47 && _TXT < 58) 
        {
            var i = src.value.length;
            var saida = mask.substring(0,1);
            var texto = mask.substring(i);
            if(texto.substring(0,1) != saida) 
            {
                src.value += texto.substring(0,1);
            }
            return true;
        } 
        else 
        {        
            navegador = /msie/i.test(navigator.userAgent);
            if (navegador)
            {
                var ctrl=event.ctrlKey;
            }
            else
            {
                var _TXT = e.which;
                var ctrl = e.ctrlKey;
            }
            if(ctrl && (_TXT == 118 || _TXT == 99))
            {
                return true
            }
            else
            {
                if(_TXT > 47 && _TXT < 58) // numeros de 0 a 9
                    return true;
                else
                {
                    if (_TXT != 8 && _TXT !=0) // backspace
                        return false;
                    else
                        return true;
                }
            }
        }
}

function isNumeric(e)
{
    var intKeyId;
	if(document.all){
	    intKeyId = event.keyCode; 
	}else {
	    intKeyId = window.event ? e.keyCode : e.which; }
    var retorno = false;
	switch(intKeyId)
	{
		case 48: // 0 (zero)
			retorno = true;
			break;
		case 49: // 1 (um)
			retorno = true;
			break;
		case 50: // 2 (dois)
			retorno = true;
			break;
		case 51: // 3 (três)
			retorno = true;
			break;
		case 52: // 4 (quatro)
			retorno = true;
			break;
		case 53: // 5 (cinco)
			retorno = true;
			break;
		case 54: // 6 (seis)
			retorno = true;
			break;
		case 55: // 7 (sete)
			retorno = true;
			break;
		case 56: // 8 (oito)
			retorno = true;
			break;
		case 57: // 9 (nove)
			retorno = true;
			break;
		default:
			retorno = false;
			break;
	}
	if(!window.event && (intKeyId == 0 || intKeyId == 8)){
	    retorno = true;}
	return retorno;
}
function $cmp(id)
{
    var cmp = document.getElementById(id);
    if(!cmp)
        cmp = document.getElementById('ctl00_ContentPlaceHolder1_'+id);
    return cmp;
}
function abrePopup(str)
{
    window.open(str);
}
function abreChat()
{
    window.open('http://atendimento.magazineluiza.com.br/orbium/chat/default.aspx?chat=2&group=Origem&url=',"janela", "width=355,height=450,resizable=no,toolbar=0,location=0,directories=0,status=no,menubar=0");
}


// Pula de uma Campo a Outro Automático
function JumpField(fields, e) {
    var intKeyId;
	if(document.all){
	    intKeyId = event.keyCode; 
	}else {
	    intKeyId = window.event ? e.keyCode : e.which; }
    
    if(intKeyId == 9 || intKeyId == 16)
        return;
    if (fields.value.length == fields.maxLength) {
        for (var i = 0; i < fields.form.length; i++) {
            if (fields.form[i] == fields && fields.form[(i + 1)] && fields.form[(i + 1)].type != "hidden") {
                fields.form[(i + 1)].focus();
                break;
            }
        }
    }
}

// PopUp
function PopUp(theURL,winName, width, height, top, left, features) { //v2.0
		if(navigator.appName=="Microsoft Internet Explorer")
		{
	  		newwindow=window.open(theURL,winName ,'location=yes, width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + features);
	  		if (window.focus) {newwindow.focus()}
		}
		else
		{
			newwindow=window.open(theURL, winName, 'location=0,fullscreen=0,menubar=0,toolbar=0,status=0,screenX=' + left + ',screenY=' + top + ',resizable=1,width=' + width + ',height=' + height + features);
	  		if (window.focus) {newwindow.focus()}
		}
		//return false;
	}

// Ação: Abre HighSlide de acordo com as configurações de formato passadas como parâmetro
// Exemplo: onclick=" return AbreHs(this, player.video);"
var player = {"video" : 0, "ampliarimagem" : 1, "slideshow" : 2, "podcast" : 3, "detalheProduto" : 4, "servicomontagem" : 5, "indiqueproduto" : 6, "instalacaogratis" : 7};
function AbreHs(objCampo, formatoExibir)
{

     var retorno = false;
     var hrefOriginal = "";
     hs.creditsHref = 'javascript: void(0);';
     hs.marginLeft = 15;
     hs.allowSizeReduction = false;

     // Configura componente hs de acordo com o formato
     switch(formatoExibir)
     {
             case player.video:
             hs.height = 450;
             hs.minWidth = 450;
             hs.lang.creditsText = "Aprenda tudo e faça a melhor compra!";
             break;

             case player.endereco:
             hs.height = 700;
             hs.minWidth = 730;
             //hs.lang.creditsText = "Aprenda tudo e faça a melhor compra!";
             break;

             case player.podcast:
             hs.height = 195;
             hs.minWidth = 490;
             hs.lang.creditsText = "Fala Lu";
             break;
             case player.detalheProduto:
             hs.height = 1100;
             hs.minWidth = 500;
             hs.lang.creditsText = "";
             break;
             case player.ampliarimagem:
             hs.height = 548;
             hs.minWidth = 722;
             hs.lang.creditsText = "<h5 class=\"imagemAmpliadaTit\">Imagem Ampliada</h5>";
             hs.marginLeft = ($(document).width() - hs.minWidth) / 2;

             var parametros = $(objCampo).attr("href");
             hrefOriginal = parametros;
             parametros = parametros + "&strUrlImagemAtual=" + $("#imagemPrincipal").attr("src")
             $(objCampo).attr("href", parametros);
             break;

             case player.slideshow:
             hs.height = 368;
             hs.minWidth = 440;
             hs.lang.creditsText = "<h5 class=\"slideShowTit\">Slide Show</h5>";
             hs.marginLeft = ($(document).width() - hs.minWidth) / 2;
             break;

             case player.servicomontagem:
             hs.height = undefined;
             hs.minWidth = 515;
             hs.lang.creditsText = "<h5 class=\"montagem_gratis_moveis\">Montagem Grátis</h5>";
             break;

             case player.indiqueproduto:
             hs.height = undefined;
             hs.minWidth = 570;
             hs.lang.creditsText = "<h6 class=\"header_pop_indicacao\">Indique este produto</h6>";
             break;

             case player.instalacaogratis:
             hs.height = undefined;
             hs.minWidth = 515;
             hs.lang.creditsText = "<h5 class=\"instalacao_gratis\">Instalação Grátis</h5>";
             break;
     }

     retorno = hs.htmlExpand(objCampo, {objectType: 'iframe'});

     if (formatoExibir == player.ampliarimagem)
     $(objCampo).attr("href", hrefOriginal);

     return retorno;
}

// Ação: Abre HighSlide de acordo com as configurações de formato passadas como parâmetro
// Exemplo: onclick=" return AbreHsGenerico(this, 100, 100 'titulo');"
function AbreHsGenerico(objCampo, altura, largura, titulo)
{
 hs.creditsHref = 'javascript: void(0);';
 hs.allowSizeReduction = false;

 hs.height = altura;
 hs.minWidth = largura;
 if (titulo != null) { hs.lang.creditsText = titulo; } else {hs.lang.creditsText = ''; }


 return hs.htmlExpand(objCampo, {objectType: 'iframe'});
} 


/*******************
* Método: limpar/mostrar
* Finalidade: limpa o campo no foco e repõe mensagem se o texto não for digitado
*********************/
function limpar (objeto, msg) {
    if (objeto.value == msg)objeto.value = '';
}

function mostrar (objeto, msg) {
    if (objeto.value == '')objeto.value = msg;
}

function ButtonPostBackValidation(eventTarget, eventArgument, validationGroup, confirmMessage)
{
	if (confirmMessage != null && confirmMessage != '')
	{
		if (!confirm(confirmMessage))
		{
			return false;
		}
	}

	if (typeof(Page_ClientValidate) == 'function')
	{
		Page_ClientValidate(validationGroup);
		return Page_IsValid;
	}
	else
	{
		return true;
	}
}

