function indicarPortal() {
	var msg = "";
	$('#indique_nome2').removeAttr("disabled");
	$('#indique_email2').removeAttr("disabled");
	
	// Campos obrigatorios
	if($("#indique_nome").val()==null || $("#indique_nome").val()=="" || $("#indique_nome").val()=="seu nome") 
		msg+="Informe seu nome.\n";	
	if($("#indique_email").val()==null || $("#indique_email").val()=="" || $("#indique_email").val()=="seu e-mail") 
		msg+="Informe seu e-mail.\n"
	else if($("#indique_email").val().indexOf("@")==-1 || $("#indique_email").val().lastIndexOf(".")==-1 || $("#indique_email").val().indexOf("@")+1 > $("#indique_email").val().lastIndexOf("."))
		msg+='Campo "seu e-mail" tem formato inválido.\n'
	
	// Indique amigo 1
	if($("#indique_nome1").val()==null || $("#indique_nome1").val()=="" || $("#indique_nome1").val()=="nome amigo 01") 
		msg+="Informe o nome do primeiro indicado.\n"	
	if($("#indique_email1").val()==null || $("#indique_email1").val()=="" || $("#indique_email1").val()=="e-mail amigo 01") 
		msg+='Informe o e-mail do primeiro indicado.\n';
	else if($("#indique_email1").val().indexOf("@")==-1 || $("#indique_email1").val().lastIndexOf(".")==-1 || $("#indique_email1").val().indexOf("@")+1 > $("#indique_email1").val().lastIndexOf("."))
		msg+='Campo e-mail do primeiro indicado tem formato inválido.\n';
		
	// Indique amigo 2, opcional
	if($("#indique_nome2").val()==null || $("#indique_nome2").val()=="" || $("#indique_nome2").val()=="nome amigo 02") 
		$("#indique_nome2").attr("disabled", true);
	if($("#indique_email2").val()==null || $("#indique_email2").val()=="" || $("#indique_email2").val()=="e-mail amigo 02") 
		$("#indique_email2").attr("disabled", true);
	else if($("#indique_email2").val().indexOf("@")==-1 || $("#indique_email2").val().lastIndexOf(".")==-1 || $("#indique_email2").val().indexOf("@")+1 > $("#indique_email2").val().lastIndexOf(".")){
		$('#indique_nome2').removeAttr("disabled");
		if($("#indique_nome2").val()==null || $("#indique_nome2").val()=="" || $("#indique_nome2").val()=="nome amigo 02") 
			msg+="Informe o nome do segundo indicado.\n"
		msg+='Campo e-mail do segundo indicado tem formato inválido.\n';
	}

	if(msg.length>1){
		$('#indique_nome2').removeAttr("disabled");
		$('#indique_email2').removeAttr("disabled");
		alert(msg)
		return false
	}
	window.open(null, "indicacao", "height=200,width=455");
	$("#indique_form").submit();
}

$(document).ready( function(){
	
 	$("#pop_indique_nome1").each(function(i){		
  		this.onfocus=function(){if(this.value=="seu nome") this.value=""};
  		this.onblur=function(){if(this.value=="") this.value="seu nome" };
 	});
 	$("#pop_indique_email1").each(function(i){		
  		this.onfocus=function(){if(this.value=="seu e-mail") this.value=""};
  		this.onblur=function(){if(this.value=="") this.value="seu e-mail" };
 	});
 	$("[name=pop_indique_nome]").each(function(i){		
  		this.onfocus=function(){if(this.value=="nome amigo (a)") this.value=""};
  		this.onblur=function(){if(this.value=="") this.value="nome amigo (a)" };
		
 	});
 	$("[name=pop_indique_email]").each(function(i){
  		this.onfocus=function(){ if(this.value=="e-mail amigo (a)")	this.value="" };
  		this.onblur=function(){	if(this.value=="") this.value="e-mail amigo (a)" };
 	});
 	$("[name=to]").each(function(i){
  		this.onfocus=function(){ if(this.value=="e-mail amigo (a)")	this.value="" };
  		this.onblur=function(){	if(this.value=="") this.value="e-mail amigo (a)" };
 	});
});

function indicarPortalPopup(){
	var input= "";
	var msg = "";
	if($("#pop_indique_nome1").val()==null || $("#pop_indique_nome1").val()=="" || $("#pop_indique_nome1").val()=="seu nome") 
		msg+="Informe seu nome.\n";	
	if($("#pop_indique_email1").val()==null || $("#pop_indique_email1").val()=="" || $("#pop_indique_email1").val()=="seu e-mail") 
		msg+="Informe seu e-mail.\n"
	else if($("#pop_indique_email1").val().indexOf("@")==-1 || $("#pop_indique_email1").val().lastIndexOf(".")==-1 || $("#pop_indique_email1").val().indexOf("@")+1 > $("#pop_indique_email1").val().lastIndexOf("."))
		msg+='Campo "seu e-mail" tem formato inválido.\n'

	$("[name=pop_indique_email]").each(function(i){
		$(this).removeAttr("disabled");
		if($(this).val()==null || $(this).val()=="" || $(this).val()=="e-mail amigo (a)") {
			$(this).attr("disabled", true);
			return;
		}		
		else if($(this).val().indexOf("@")==-1 || $(this).val().lastIndexOf(".")==-1 || $(this).val().indexOf("@")+1 > $(this).val().lastIndexOf(".")){
			msg+= "O " + $(this).attr("tabindex") +'º campo "e-mail amigo (a)" tem formato inválido.\n';
			return;
		}
		input += $(this).val()+",";
	})
	$("[name=to]").each(function(i){
		$(this).removeAttr("disabled");
		if($(this).val()==null || $(this).val()=="" || $(this).val()=="e-mail amigo (a)") {
			$(this).attr("disabled", true);
			return;
		}		
		else if($(this).val().indexOf("@")==-1 || $(this).val().lastIndexOf(".")==-1 || $(this).val().indexOf("@")+1 > $(this).val().lastIndexOf(".")){
			msg+= "O " + $(this).attr("tabindex") +'º campo "e-mail amigo (a)" tem formato inválido.\n';
			return;
		}
		input += $(this).val()+",";
	})
	if(msg.length>1){
		$("[name=pop_indique_email]").each(function(i){
			$(this).removeAttr("disabled");
		})	
		alert(msg);
		return false;
	}
	if(msg.length>1){
		$("[name=to]").each(function(i){
			$(this).removeAttr("disabled");
		})	
		alert(msg);
		return false;
	}
	if(input.length>1){
		$("#pop_indique_cc").val(input);
		return true;
	} else {		
		$("[name=pop_indique_email]").each(function(i){
			$(this).removeAttr("disabled");
		})
		$("[name=to]").each(function(i){
			$(this).removeAttr("disabled");
		})
		alert("Informe o e-mail de ao menos um amigo (a).");
		return false;
	}
	
	
}
function openToCommentWindow(contentId) {
	window.open("/comments/homepage.mmp?contentId=" + contentId, "", "height=600, width=455, status=no, scrollbars=no, menubar=no, toolbar=no, titlebar=no, location=no, fullscreen=no, directories=no");
}

function openCommentsWindow(alias) {
	window.open("/content/" + alias  + ".mmp?template=comments", "", "height=572, width=455, status=no, scrollbars=no, menubar=no, toolbar=no, titlebar=no, location=no, fullscreen=no, directories=no");
}

function openMapWindow(alias) {
	window.open("/content/" + alias  + ".mmp", "", "height=500, width=455, status=no, scrollbars=no, menubar=no, toolbar=no, titlebar=no, location=no, fullscreen=no, directories=no");
}

function openPrivacidadeWindow(alias) {
	window.open("/content/" + alias  + ".mmp", "", "height=600, width=475, status=no, scrollbars=yes, menubar=no, toolbar=no, titlebar=no, location=no, fullscreen=no, directories=no");
}

function openFaleConoscoWindow() {
	var str = "";
	if(document.getElementById("nome_sessao").value!="" && document.getElementById("email_sessao").value!="")
		str = "?pars=" + document.getElementById("nome_sessao").value + "|" + document.getElementById("email_sessao").value;
	window.open('/includes/htms/fale-conosco.htm' + str, '_blank', 'height=700, width=455, status=no, scrollbars=no, menubar=no, toolbar=no, titlebar=no, location=no, fullscreen=no, directories=no');
}

function openIndiqueMaisWindow() {
	window.open('/includes/htms/indique.htm?pars=' + document.getElementById("indique_nome").value + "|" + document.getElementById("indique_email").value, '_blank', 'height=590, width=455, status=no, scrollbars=no, menubar=no, toolbar=no, titlebar=no, location=no, fullscreen=no, directories=no');
}

function openIndiquePaginaWindow(link) {
	window.open('/includes/htms/indique_pagina.htm?pars=' + document.getElementById("indique_nome").value + "|" + document.getElementById("indique_email").value + "|" + link, '_blank', 'height=590, width=455, status=no, scrollbars=no, menubar=no, toolbar=no, titlebar=no, location=no, fullscreen=no, directories=no');
}

function writemovie(path, desc) {
	document.getElementById("movie_area").innerHTML = "";
	document.getElementById("movie_area").style.marginLeft = "-1px";
	var so = new SWFObject(path, "movie", "220", "183", "", "");
    so.addParam("wmode", "transparent");
    so.addParam("play", "false");
    so.addParam("base", "http://www.portaldamaquiagem.com.br/resources/repvideos/steelexternalplayseekmute.swf");
    
	so.write("movie_area");
	document.getElementById("video_desc").innerHTML = desc;
}

function writeImg(path, desc) {
	document.getElementById("img_area").src = path;
	document.getElementById("img_desc").innerHTML = desc;
}


function openGallery(alias, cont) {
	var url = "/content/" + alias + ".mmp?template=galeria/detalhe&pic=" + cont;
	document.getElementById('novo_layer_pos').innerHTML = '<iframe src="'+url+'" width="906" height="450" frameborder="0"></iframe>';
	document.getElementById('novo_layer').style.display = 'block';
	setTimeout("document.getElementById('estrutura').onclick = closeLayer;", 100);
	if (navigator.appName == 'Microsoft Internet Explorer') {
		document.body.onkeyup = function close(event) {
		if (window.event.keyCode == '27')
			closeLayer();
			return;
		}
	} else {
		document.body.onkeyup = function close(event) {
			if (event.keyCode == '27')
				closeLayer();
			return;
		}
	}
	return;
}
  
function closeLayer() {
	document.getElementById('estrutura').onclick = function() {};
	document.getElementById('novo_layer').style.display = 'none';
}

//para galeria de imagens
function showImage(index) {
	document.getElementById("exposicao_img_lado_a").style.display = "block";
	document.getElementById("exposicao_img_lado_a_img").style.display = "block";
	document.getElementById("exposicao_img_lado_b").style.display = "block";
	document.getElementById("exposicao_img_lado_b_img").style.display = "block";
	if(index==0) {
		document.getElementById("exposicao_img_lado_a").style.display = "none";
		document.getElementById("exposicao_img_lado_a_img").style.display = "none";
	}
	if(index==images.length-1) {
		document.getElementById("exposicao_img_lado_b").style.display = "none";
		document.getElementById("exposicao_img_lado_b_img").style.display = "none";
	}
	
	document.getElementById("exposicao_img").style.background = "url('" + images[index][0] + "') no-repeat";
	
	document.getElementById("exposicao_leg").innerHTML = "<b>" + images[index][1] + "</b> " + images[index][2];

	curImg = index;
	
//	for(var i=0; i<images.length; i++) {
//		document.getElementById("lista_maquiagem_" + i).style.display = "none";
//	}
//	document.getElementById("lista_maquiagem_" + index).style.display = "block";
	document.getElementById("maquiadorName").innerHTML = images[index][3];
	document.getElementById("maquiadorDesc").innerHTML = images[index][4];
	document.getElementById("maquiadorImg").src = images[index][5];
	document.getElementById("maquiadorImg").name = images[index][3];
}

function nextImage() {
	if(curImg<images.length-1)
		showImage(curImg+1);
}

function prevImage() {
	if(curImg>0)
		showImage(curImg-1);
}

function showPopupImg(url, name, width, height) {
	/*
	document.getElementById("popup_img_src").src = "";
	document.getElementById("popup_img").style.display = "block";
	document.getElementById("titulo_trab").style.display = "none";
	document.getElementById("popup_img_src").src = url;
	var div = document.createElement("div");
	div.id = "backpopup";
	document.body.appendChild(div);
	div.style.height=document.documentElement.clientHeight + "px";
	if($("#lado_b")) {
		$("#lado_b").css({"display":"none"});
	}
	* */
	var h = height + 80;
	var w = width + 50;
	window.open("/view_resources/homepage.mmp?url=" + url + "&name=" + name, "imagem", "height=" + h + ", width=" + w + ", status=no, scrollbars=no, menubar=no, toolbar=no, titlebar=no, location=no, fullscreen=no, directories=no");
}

function showPopupTrab(url, name, width, height) {
	/*
	document.getElementById("popup_img_src").src = "";
	document.getElementById("popup_img").style.display = "block";
	document.getElementById("titulo_trab").style.display = "block";
	
	document.getElementById("popup_img_src").src = url;
	var div = document.createElement("div");
	div.id = "backpopup";
	document.body.appendChild(div);
	div.style.height=document.documentElement.clientHeight + "px";
	if($("#lado_b")) {
		$("#lado_b").css({"display":"none"});
	}*/
	var h = height + 150;
	var w = width + 50;
	window.open("/view_resources/homepage.mmp?trab=true&url=" + url + "&name=" + name, "imagem", "height=" + h + ", width=" + w + ", status=no, scrollbars=no, menubar=no, toolbar=no, titlebar=no, location=no, fullscreen=no, directories=no");
}

function closePopupImg() {
	document.getElementById('popup_img').style.display = 'none';
	if($("#lado_b")) {
		$("#lado_b").css({"display":"block"});
	}
	if(document.getElementById("backpopup")) {
		document.body.removeChild(document.getElementById("backpopup"));
	}
	
}

function getMakeUpPopup(field) {
	window.open(field.href, "privacidade", "height=600, width=465, status=no, scrollbars=yes, menubar=no, toolbar=no, titlebar=no, location=no, fullscreen=no, directories=no");
	/*
	$.ajax({
    	url: '/content/' +  alias +'.mmp?template=premio/ganhadores',
	    type: 'GET',
		    timeout: 1000,
		    dataType: "html",
		    error: function(){
        		alert('Erro ao requisitar pÃ¡gina...');
		    },
		    success: function(data){
		    	$("#profile_content").html(data);
		    	$("#popup_profile").css({"display":"block"});
				var div = document.createElement("div");
				div.id = "backpopup";
				document.body.appendChild(div);
				div.style.height=document.documentElement.clientHeight + "px";
				if($("#lado_b")) {
					$("#lado_b").css({"display":"none"});
				}
		    }
	});
	* */
}

function closePopupProfile() {
	document.getElementById('popup_profile').style.display = 'none';
	if($("#lado_b")) {
		$("#lado_b").css({"display":"block"});
	}
	if(document.getElementById("backpopup")) {
		document.body.removeChild(document.getElementById("backpopup"));
	}
	
}

function getMakeUpInterview(alias) {
	$.ajax({
    	url: '/content/' +  alias +'.mmp?template=premio/ganhadores/entrevista',
	    type: 'GET',
		    timeout: 1000,
		    dataType: "html",
		    error: function(){
        		alert('Erro ao requisitar pÃ¡gina...');
		    },
		    success: function(data){
		    	$("#profile_content").html(data);
		    	$("#popup_profile").css({"display":"block"});
				var div = document.createElement("div");
				div.id = "backpopup";
				document.body.appendChild(div);
				div.style.height=document.documentElement.clientHeight + "px";
				if($("#lado_b")) {
					$("#lado_b").css({"display":"none"});
				}
		    }
	});
}

function getLatestYears(alias) {
	$.ajax({
    	url: '/content/' +  alias +'.mmp?template=premio/anosanteriores',
	    type: 'GET',
		    timeout: 1000,
		    dataType: "html",
		    error: function(){
        		alert('Erro ao requisitar pÃ¡gina...');
		    },
		    success: function(data){
		    	$("#profile_content").html(data);
		    	$("#popup_profile").css({"display":"block"});
				var div = document.createElement("div");
				div.id = "backpopup";
				document.body.appendChild(div);
				div.style.height=document.documentElement.clientHeight + "px";
				if($("#lado_b")) {
					$("#lado_b").css({"display":"none"});
				}
		    }
	});
}

//para busca
function submitSearch() {
	if(document.getElementById("busca_q").value=="buscar" || document.getElementById("busca_q").value=="") {
		alert("Favor preencher o campo de busca");
		return false;
	}
	document.getElementById("busca-conteudo").submit();
}

function sendComment() {
	var msg = '';
	var state = document.getElementById('state');
	if(document.getElementById('nome').value == '' || document.getElementById('nome').value == 'seu nome')
		msg += '- Informe seu nome.'+"\n";
	if(document.getElementById('email').value == '' || document.getElementById('email').value == 'seu e-mail')
		msg += '- Informe seu e-mail.'+"\n";
	if(document.getElementById('comentario').value == '' || document.getElementById('comentario').value == 'coment&aacute;rio')
		msg += '- FaÃ§a um comentÃ¡rio.'+"\n";
	if(state.options[state.selectedIndex].value=="0") {
		msg += '- Informe seu estado.'+"\n";
	}
	if(document.getElementById('cidade').value == '' || document.getElementById('cidade').value == 'sua cidade')
		msg += '- Informe sua cidade.'+"\n";
	if (msg != '') {
		alert(msg+"\n"+'Clique em "Ok" para voltar ao formulário.');
		return false;
	} else {
		document.getElementById('comentario').value += " (" + document.getElementById('cidade').value + "/" + state.options[state.selectedIndex].value + ")";
		return true;
	}


}

function sendTalkTo() {
	var msg = '';
	var state = document.getElementById('state');
	var subject = document.getElementById('subject_int');
	if(document.getElementById('nome').value == '' || document.getElementById('nome').value == 'seu nome')
		msg += '- Informe seu nome.'+"\n";
	if(document.getElementById('email').value == '' || document.getElementById('email').value == 'seu e-mail')
		msg += '- Informe seu e-mail.'+"\n";
	if(document.getElementById('mensagem').value == '' || document.getElementById('mensagem').value == 'mensagem')
		msg += '- Digite uma mensagem'+"\n";
	if(state.options[state.selectedIndex].value=="0")
		msg += '- Informe seu estado.'+"\n";
	if(document.getElementById('cidade').value == '' || document.getElementById('cidade').value == 'sua cidade')
		msg += '- Informe sua cidade.'+"\n";
	if(subject.options[subject.selectedIndex].value=="0")
		msg += '- Informe o assunto.'+"\n";
	if (msg != '') {
		alert(msg+"\n"+'Clique em "Ok" para voltar ao formulário.');
		return false;
	} else {
          
          var sub = subject.options[subject.selectedIndex].value;
			if(subject.selectedIndex==1)
				document.getElementById('mail_to').value = "maquiagem";
			else if(subject.selectedIndex==2 || subject.selectedIndex==3)
				document.getElementById('mail_to').value = "conexao";
			else if(subject.selectedIndex==4)
				document.getElementById('mail_to').value = "elogios";
			else {
				/*
				document.getElementById("comentario_add_form").innerHTML = '<center><div class="font_verdana size_13px bold cor_747474 mt_15 mb_10">' + 
				'Para  informa&ccedil;&otilde;es sobre a Avon e seus produtos acesse www.avon.com.br e clique em <em>Converse com a gente</em>. Voc&ecirc; tamb&eacute;m pode ligar para o Servi&ccedil;o de Atendimento ao Consumidor - 0800 708 2866'
				+ '</div></center><div style="height: 15px"><div class="bt_close"><a href="" onclick="window.close(this); return false;" title="Fechar esta janela"><img src="/images/bt_close.gif" class="bt_fechar" alt="Fechar esta janela" /></a></div></div>'
				document.getElementById("topic").style.display = "none";
				* */
				alert("Selecione outro assunto para enviar sua mensagem.");
				return false;
			}
			return true;
	}
}

function viewMsg(field) {
	var sub = field.options[field.selectedIndex].value;
	//if(sub=="Portal da Maquiagem Fale Com - Dúvidas sobre produtos Avon" || sub=="Portal da Maquiagem Fale Com - Dúvidas sobre a Avon") {
	if(field.selectedIndex==5 || field.selectedIndex==6) {
		alert("Para  informações sobre a Avon e seus produtos acesse www.avon.com.br e clique em Converse com a gente. Você também pode ligar para o Serviço de Atendimento ao Consumidor - 0800 708 2866");
	}
	
}

function sendUserCreation() {
	var msg = '';
	if (document.getElementById('nome').value == '' || document.getElementById('nome').value == 'seu nome')
		msg += '- Informe seu nome.'+"\n";
	if (document.getElementById('email').value == '' || document.getElementById('email').value == 'seu e-mail')
		msg += '- Informe seu e-mail.'+"\n";
	if (msg != '') {
		alert(msg+"\n"+'Clique em "Ok" para voltar ao formulário.');
		return false;
	} else
		return true;
}

// máscara para formulários
function txtBoxFormat(objeto, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;


	if(document.all) { // Internet Explorer
		nTecla = evtKeyPress.keyCode;
	} else if(document.layers) { // Nestcape
		nTecla = evtKeyPress.which;
	} else {
		nTecla = evtKeyPress.which;
		if (nTecla == 8 || nTecla == 0) {
			return true;
		}
	}
    sValue = objeto.value;

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( ":", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/") || (sMask.charAt(i) == ":"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    objeto.value = sCod;
    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); } 
      else { // qualquer caracter...
        return true;
      } 
    }
    else {
      return true;
    }
}

$("document").ready(function(){
	$(".desce_texto").mouseover(function(){
		var DefaultTop = $("#rolaTexto").scrollTop();
		
		interval = setInterval(function(){
			var top = $("#rolaTexto").scrollTop();
			$("div#rolaTexto").scrollTop(top+5)
		},50)
	}).mouseout(function(){
		clearInterval(interval)
	});
	
	$(".sobe_texto").mouseover(function(){
		var DefaultTop = $("#rolaTexto").scrollTop();
		
		interval = setInterval(function(){
			var top = $("#rolaTexto").scrollTop();
			$("div#rolaTexto").scrollTop(top-5)
		},50)
	}).mouseout(function(){
		clearInterval(interval)
	});
});