// JavaScript Document

// Geral para todas as páginas

function MM_findObj2(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers_2() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers_2.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj2(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v='hide')?'none':v; }
    obj.display=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



<!--
function openwindow(){
	window.open("http://www.vale.com/cvrd/hotsites/si/tutorial/","tutorial","menubar=0,resizable=0,width=778,height=697");
}
//-->

// Funções Login e Multimidia DIVs

var objToExecOnLogin = null;

function verificarLogin(itemId, strTipo, objEvent){
	
		return true
		var posX = mouseX(objEvent);
		var posY = mouseY(objEvent);
		
		var options = {
		   url:            	"../login/login.asp",
		   data:           	"tipo="+strTipo+"&item="+itemId+"&checkLogin=OK&posX="+posX+"&posY="+posY+"&sid="+Math.random(),
		   cache:          	false,
		   success:        	handleVerificacao,
		   complete:		function(XHR, responseStatus){
		   						if (responseStatus == "error"){
									
								}
							}
		};
		$.ajax(options);		
	}
	
	function handleVerificacao(responseText, responseStatus){
		var retornoLogin = eval("(" + responseText + ")");
		if (retornoLogin.status == 'LOGADO'){
			abrirDivMultimidia("#div"+retornoLogin.tipo+retornoLogin.item, retornoLogin.posX, retornoLogin.posY);
		}
		else{
			objToExecOnLogin = retornoLogin;
			abrirDivMultimidia("#divLogin", retornoLogin.posX, retornoLogin.posY);
		}
	}
	
	function executarLogin(){
		if ($("#strEmailLogin").val() == ""){
			$("#divMsgErroLogin").html("Please, fill your E-mail.");
			$("#strEmailLogin").focus();
			return;
		}
		if ($("#strPasswordLogin").val() == ""){
			$("#divMsgErroLogin").html("Please, fill your password.");
			$("#strPasswordLogin").focus();
			return;
		}
		var options = {
		   url:            	"../login/login.asp",
		   data:           	"loggingHome=OK&email="+$("#strEmailLogin").val()+"&senha="+$("#strPasswordLogin").val()+"&sid="+Math.random(),
		   cache:          	false,
		   success:        	handleLogin,
		   complete:		function(XHR, responseStatus){
		   						if (responseStatus == "error"){
									
								}
							}
		};
		$.ajax(options);
	}
	
	function handleLogin(responseText, responseStatus){
		if (responseStatus == "success"){
			var retornoLogin = eval("(" + responseText + ")");
			if (retornoLogin.status == 'LOGADO'){
				fecharDivMultimidia('#divLogin');
				//objToExecOnLogin  usado para saber qual janela deveria abrir antes de aparecer a janela de login.
				abrirDivMultimidia("#div"+objToExecOnLogin.tipo+objToExecOnLogin.item, objToExecOnLogin.posX, objToExecOnLogin.posY);
			}
			else{
				$("#divMsgErroLogin").html(retornoLogin.msg);
			}
		}
	}
	
	function abrirDivMultimidia(divItem, posX, posY){
		/*$(divItem).css("left", posX - 240);*/
		$(divItem).css("left", 400);
		$(divItem).css("top", posY - 230);
		$(divItem).css("z-index", 1000);
		$(divItem).show();
	}
	
	function fecharDivMultimidia(divItem){
		$(divItem).css("z-index", 0);
		$(divItem).hide();
	}
	
	function mouseX(evt) {
		if (evt.pageX) return evt.pageX;
		else if (evt.clientX) return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		else return null;
	}
	
	function mouseY(evt) {
		if (evt.pageY) return evt.pageY;
		else if (evt.clientY) return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
		else return null;
}

// Fim das Funções Login e Multimidia DIVs

//Validação do Formulario

function ValidateForm(objForm){
		if(TestField(objForm.nome)) alert("Nome é obrigatorio.");
		else if(TestField(objForm.email) || TestEmail(objForm.email.value)) alert("Email é obrigatorio");
		else if(TestSelect(objForm.area)) alert("Área é obrigatorio.");
		else if(TestField(objForm.veiculo)) alert("Veículo é obrigatorio.");
		else if(TestField(objForm.telefone)) alert("Telefone é obrigatorio.");
		else if(TestField(objForm.assunto)) alert("Assunto é obrigatorio.");
		else if(TestField(objForm.mensagem)) alert("Mensagem é obrigatorio.");
		else return true;
		
		return false;
}

function ValidateFormLogin(objForm){


		if(TestField(objForm.email) || TestEmail(objForm.email.value)) alert("Email é obrigatorio");
		else if(TestField(objForm.senha)) alert("Senha é obrigatorio.");
		else return true;
		
		return false;
}

//Formulario de Cadastro

function ValidateFormCadastro(objForm){	

		objForm.local.disabled = false;
		conta=0;
		for(var i =0;i <objForm.elements.length; i++) {
        if (objForm.elements[i].type=="checkbox"){
           if (objForm.elements[i].name=="categorias_newletter"){		   
		      if (objForm.elements[i].checked==true){
			    conta=conta+1			  
			  }
		   
		   }
        } 
       }
       if (conta>3){	   
	   alert("Lembre-se: você pode selecionar apenas três opções de categorias.")	   
	   return false
	   }
		if(TestField(objForm.nome_1)) alert("Nome é obrigatorio.");
		else if(TestField(objForm.nome_2)) alert("Sobrenome é obrigatorio.");
		else if(TestRadio(objForm.sexo)) alert("Sexo é obrigatorio.");
//		else if(TestField(objForm.email) || TestEmail(objForm.email.value)) alert("E-mail é obrigatorio");
		else if(TestField(objForm.email) || TestEmail(objForm.email, objForm.email.value)) alert("E-mail é obrigatorio");
		else if(TestField(objForm.senha)) alert("Senha é obrigatorio.");
		else if(TestField(objForm.senhaconf) || (objForm.senha.value != objForm.senhaconf.value)) alert("Confirmação de Senha é obrigatorio.");
		else if(TestField(objForm.veiculo)) alert("Veículo é obrigatorio.");
		else if(TestSelect(objForm.pais)) alert("País é obrigatorio.");
		else if(TestSelect(objForm.local)) alert("Estado é obrigatorio.");
		else if(TestField(objForm.cidade)) alert("Cidade é obrigatorio.");
		else if(TestSelect(objForm.cargo)) alert("Cargo é obrigatorio.");
		else if(TestSelect(objForm.editoria)) alert("Editoria é obrigatorio.");
		else if(TestField(objForm.telefone)) alert("Telefone é obrigatorio.");
		else if(TestField(objForm.DDD)) alert("DDD é obrigatorio.");
		else if(TestSelect(objForm.idioma)) alert("Idioma é obrigatorio.");
		else if(objForm.concordo.checked == false) alert("É preciso concordar com o termo de compromisso.");
		else {objForm.nome.value = (objForm.nome_1.value + ' ' + objForm.nome_2.value); 
		return true;}		
		return false;
}

//Formulario Alteracao de Cadastro

function ValidateFormAltCadastro(objForm){		

		objForm.local.disabled = false;
		conta=0;
		for(var i =0;i <objForm.elements.length; i++) {

        if (objForm.elements[i].type=="checkbox"){
           if (objForm.elements[i].name=="categorias_newletter"){		   
		      if (objForm.elements[i].checked==true){
			    conta=conta+1			  
			  } 		   
		   }
        } 
       }


       if (conta>3){
	   
	   alert("Você pode marcar apenas 3 opções de categorias de newsletter.")
	   
	   return false

	   }

		if(TestField(objForm.nome_1)) alert("Nome é obrigatorio.");
		else if(TestField(objForm.nome_1)) alert("Nome é obrigatorio.");
		else if(TestRadio(objForm.sexo)) alert("Sexo é obrigatorio.");
//		else if(TestField(objForm.email) || TestEmail(objForm.email.value)) alert("E-mail é obrigatorio");
		else if(TestField(objForm.email) || TestEmail(objForm.email, objForm.email.value)) alert("E-mail é obrigatorio");
		else if(TestField(objForm.senha)) alert("Senha é obrigatorio.");
		else if(TestField(objForm.senhaconf) || (objForm.senha.value != objForm.senhaconf.value)) alert("Confirmação de Senha é obrigatorio.");
		else if(TestField(objForm.veiculo)) alert("Veículo é obrigatorio.");
		else if(TestSelect(objForm.pais)) alert("País é obrigatorio.");
		else if(TestSelect(objForm.local)) alert("Estado é obrigatorio.");
		else if(TestField(objForm.cidade)) alert("Cidade é obrigatorio.");
		else if(TestSelect(objForm.cargo)) alert("Cargo é obrigatorio.");
		else if(TestSelect(objForm.editoria)) alert("Editoria é obrigatorio.");
		else if(TestField(objForm.telefone)) alert("Telefone é obrigatorio.");
		else if(TestField(objForm.DDD)) alert("DDD é obrigatorio.");
		else if(TestSelect(objForm.idioma)) alert("Idioma é obrigatorio.");
		else {
		return true;}
		
		return false;
}

function selectpais(objpais){
	obj_pp=String(objpais).toLowerCase()
	for (i=0;i<document.frmCadastro.pais.options.length;i++){
		document.frmCadastro.pais.selectedIndex=i;
			if (document.frmCadastro.pais.options[document.frmCadastro.pais.selectedIndex].value.toLowerCase()==obj_pp){
				break;
				}
}
	return true;
}



function selectlocal(objpais){
	obj_pp=String(objpais).toLowerCase()
	for (i=0;i<document.frmCadastro.local.options.length;i++){
		document.frmCadastro.local.selectedIndex=i;
		if (document.frmCadastro.local.options[document.frmCadastro.local.selectedIndex].value.toLowerCase()==obj_pp){
			break;
			}
		}
	return true;
}

function selectcargo(objpais){
	obj_pp=String(objpais).toLowerCase()
	for (i=0;i<document.frmCadastro.cargo.options.length;i++){
		document.frmCadastro.cargo.selectedIndex=i;
			if (document.frmCadastro.cargo.options[document.frmCadastro.cargo.selectedIndex].value.toLowerCase()==obj_pp){
				break;
				}
			}
	return true;
}


function selecteditoria(objpais){
	obj_pp=String(objpais).toLowerCase()
	for (i=0;i<document.frmCadastro.editoria.options.length;i++){
		document.frmCadastro.editoria.selectedIndex=i;
		if (document.frmCadastro.editoria.options[document.frmCadastro.editoria.selectedIndex].value.toLowerCase()==obj_pp){
			break;
			}
		}
	return true;
}


function selectconexao(objpais){
	obj_pp=String(objpais).toLowerCase()
	for (i=0;i<document.frmCadastro.conexao.options.length;i++){
		document.frmCadastro.conexao.selectedIndex=i;
		if (document.frmCadastro.conexao.options[document.frmCadastro.conexao.selectedIndex].value.toLowerCase()==obj_pp){
			break;
			}
	}
	return true;
}


//Fim da Validação do Formulario

// Busca na home e Mais acessados

function ativarbarra () {
	$("#barralateralfechado").hide();
	$("#barralateralaberto").show();
	$("#categoriasbusca").hide();
}

function fecharbarra () {
	$("#barralateralfechado").show();
	$("#barralateralaberto").hide();
	$("#categoriasbusca").show();
}

// Fim da Busca na home e Mais acessados

// Noticias e Releases

function OpenPopParam(sLink,sWidth,sHeight){
	window.open(sLink,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,top=auto,left=auto,resizable=no,width=' + sWidth + ',height=' + sHeight);
}


function HasImage(){
		/**/
	}
	function SetTD(objTD){
		objTD.height = 41;
	}
	
	function StartImgDownload(intImages, intImageID){
		for (var i = 1; i <= intImages; i++){
			LoadImg('../../_newsimagens/news_' + intImageID + '_' + i + '_thumb.jpg?<%=Hour(now)&Minute(now)&Second(now)%>', 'spnThumb_' + i + '', '\'\'');
		}
}


// Fim de javascript para Noticias e Releases