//Funcoes para a Compet Net
//Funcao Validacao da Newsletter
function ValidaNews(form){
	if(form.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1){
		alert("Atenção!\nO campo SEU E-MAIL deve ser preenchido.");
		form.email.focus();
		return false;
	}
}

//funcao para busca de lojas
function Busca_Lojas(pValor)
{
	if(pValor != '')
	{			
		document.location.href = pValor;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Função de popup
function MM_openBrWindow(theURL,winName,features){
	var myWin =  window.open(theURL,winName,features);
	myWin.focus();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Produtos
function fnMudaOn(id) {
	document.getElementById(id).style.display = '' ;
}
	
function fnMudaOff(id) {
	document.getElementById(id).style.display = 'none' ;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Funcao Adiciona a Favoritos
function fnAdicionaFavoritos(){
	str_titulo = ":: Compet ::";
	str_url = "http://www.competnet.com.br/";
	if(window.sidebar){ window.sidebar.addPanel(str_titulo, str_url,""); }
	else if(window.external){ window.external.AddFavorite( str_url, str_titulo); }
	else if(window.opera && window.print){ return true; }
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Funcao Validacao do Indique Amigo
function ValidaForm_IndiqueAmigo(form,evento){
	if(form.nome.value == ''){
		alert('Atenção!\nO campo SEU NOME deve ser preenchido.');
		form.nome.focus();
		return false ;
	}
	if(form.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1){
		alert("Atenção!\nO campo SEU E-MAIL deve ser preenchido.");
		form.email.focus();
		return false;
	}
	if(form.emailamigo.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1){
		alert("Atenção!\nO campo E-MAIL DO AMIGO deve ser preenchido.");
		form.emailamigo.focus();
		return false;
	}
	if(form.mensagem.value == ''){
		alert('Atenção!\nO campo MENSAGEM deve ser preenchido.') ;
		form.mensagem.focus();
		return false ;
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//valida formulario Contato
function ValidaForm_Contato(form){
	if(form.nome.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	
	if(form.telefone.value.length<=1){
		alert("O campo Telefone deve estar preenchido corretamente.");
		form.telefone.focus();
		return false;
	}
	
	if(form.cidade.value.length<=1){
		alert("O campo Cidade deve estar preenchido corretamente.");
		form.cidade.focus();
		return false;
	}
	
	if(form.estado.value.length<=1){
		alert("O campo Estado deve estar selecionado corretamente.");
		form.estado.focus();
		return false;
	}
	
	if(FnValidaCampo("Deseja receber informações sobre promoções e publicações técnicas?",form.deseja,0,'R') == false) return false;
	
	if(form.mensagem.value.length<=1){
		alert("O campo Mensagem deve estar preenchido corretamente.");
		form.mensagem.focus();
		return false;
	}
	if(form.cod.value.length<=1){
		alert("O campo Código de Segurança deve estar preenchido corretamente.");
		form.cod.focus();
		return false;
	}
}

/////////////////////////////////////////////////////////////////////////////////////
/*Valida input radio*/
function FnValidaCampo(strLblCampo,strCampo,intTamanho,strTipo){
	//Funcao validacao da Enquete
	if(strTipo == "R"){
		var contador;
		var flag;
		flag = false;
		for(contador=0; contador<strCampo.length; contador ++){
			if(strCampo[contador].checked){ flag = true; }
		}
		if(flag == false){
			alert("Por favor, escolha uma das opções do campo "+strLblCampo+".");
			return false;
		}
	}
}


/////////////////////////////////////////////////////////////////////////////////////////////////
// Função de Máscara de Campos
function FormatMask(objForm, strField, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	if(window.event){ nTecla = evtKeyPress.keyCode; }
	else if(evtKeyPress.which){ nTecla = evtKeyPress.which; }
	sValue = objForm[strField].value;
	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;
	if(nTecla != 8){
		if(sMask.charAt(i-1) == "9"){ return ((nTecla > 47)&&(nTecla < 58)); }
		else{
			while(i <= mskLen){
				bolMask = ((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++;
			}
			objForm[strField].value = sCod;
			return true;
		}
	}
	else{ return true; }
}
//Funcao da Mascara
function fnMascara(objeto, evt, mask){ 
	var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
	var Letras  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';	
	var Numeros = '0123456789';
	var Fixos  = '().-:/ ';
	var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";
	evt = (evt) ? evt : (window.event) ? window.event : "";
	var value = objeto.value;
	if(evt){
		var ntecla = (evt.which) ? evt.which : evt.keyCode;
		tecla = Charset.substr(ntecla - 32, 1);
		if(ntecla < 32) return true;
		var tamanho = value.length;
		if(tamanho >= mask.length) return false;
		var pos = mask.substr(tamanho,1);
		while(Fixos.indexOf(pos) != -1){
 	 		value += pos;
 	 		tamanho = value.length;
 	 		if (tamanho >= mask.length) return false;
 	 		pos = mask.substr(tamanho,1);
		}
		switch(pos){
   			case '#' : if (Numeros.indexOf(tecla) == -1) return false; break;
   			case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
   			case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
   			case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
   			case '*' : objeto.value = value; return true; break;
   			default : return false; break;
 		}
	}
	objeto.value = value;
	return true;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Funcao para o flash
function fnFlash(str_url,int_largura,int_altura){
	document.writeln('<object type="application/x-shockwave-flash" data="'+str_url+'" width="'+int_largura+'" height="'+int_altura+'">');
	document.writeln('<param name="movie" value="'+str_url+'">');
	document.writeln('<param name="quality" value="high">');
	document.writeln('<param name="wmode" value="transparent">');
	document.writeln('</object>');
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
//função para o (mostrar e ocultar)
function onOff(id){
	esconder = (document.getElementById(id).style.display == 'block');
	/*if ( visivel == "" || visivel == "none" ) { document.getElementById(id).style.display = "block" }
	else{ document.getElementById(id).style.display = "none"; }*/
	divs = document.getElementsByTagName('DIV');
	for(d=0; d<divs.length; d++){
		_div = divs[d];
		if (_div.className == 'titulo'){
			id_link = 'titulo_'+(_div.id);
			_link = document.getElementById(id_link);
			if(_div.id != id){ _div.style.display = 'none'; }
			else{ _div.style.display = esconder ? 'none' : 'block'; }
		}
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////
//valida formulario Trabalhe Conosco
function ValidaForm_Trabalhe_Conosco(form){
		
	if(form.nome.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	
	/*if(form.data_nascimento.value.length<=1){
		alert("O campo Data de Nascimento para contato deve estar selecionado corretamente.");
		form.data_nascimento.focus();
		return false;
	}
	
	if(form.sexo.value.length<=1){
		alert("O campo Sexo para contato deve estar selecionado corretamente.");
		form.sexo.focus();
		return false;
	}
	
	if(form.estado_civil.value.length<=1){
		alert("O campo Estado Civil para contato deve estar selecionado corretamente.");
		form.estado_civil.focus();
		return false;
	}
	
	cpf_valido = document.getElementById('cpf_erro').style.display;
	if((form.cpf.value.length <= 1 )||(cpf_valido == '')){
		alert("O campo CPF deve estar preenchido corretamente.");
		form.cpf.focus();
		return false;
	}
	
	if(form.endereco.value.length<=1){
		alert("O campo Endereço para contato deve estar selecionado corretamente.");
		form.endereco.focus();
		return false;
	}
	
	if(form.bairro.value.length<=1){
		alert("O campo Bairro para contato deve estar selecionado corretamente.");
		form.bairro.focus();
		return false;
	}
	
	
	if(form.cep.value.length<=8){
		alert("O campo Celular deve estar preenchido corretamente.");
		form.cep.focus();
		return false;
	}
	
	if(form.cidade.value.length<=1){
		alert("O campo Cidade deve estar preenchido corretamente.");
		form.cidade.focus();
		return false;
	}
	
	if(form.estado.value.length<=1){
		alert("O campo Estado deve estar selecionado corretamente.");
		form.estado.focus();
		return false;
	}*/
	
	if(form.telefone.value.length<=1){
		alert("O campo Telefone deve estar preenchido corretamente.");
		form.telefone.focus();
		return false;
	}
		
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	
	/*if(form.funcao.value.length<=1){
		alert("O campo Escolha uma Função deve estar preenchido corretamente.");
		form.funcao.focus();
		return false;
	}
	
	if(form.grau_instrucao.value.length<=1){
		alert("O campo Grau de Instrução deve estar preenchido corretamente.");
		form.grau_instrucao.focus();
		return false;
	}
	
	if(form.curso.value.length<=1){
		alert("O campo Curso deve estar preenchido corretamente.");
		form.curso.focus();
		return false;
	}
	
	if(form.instituicao.value.length<=1){
		alert("O campo Instituição deve estar preenchido corretamente.");
		form.instituicao.focus();
		return false;
	}
	
	if(form.ano.value.length<=1){
		alert("O campo Ano de Conclusão deve estar preenchido corretamente.");
		form.ano.focus();
		return false;
	}
	
	if(form.qualificacoes.value.length<=1){
		alert("O campo Qualificações deve estar preenchido corretamente.");
		form.qualificacoes.focus();
		return false;
	}
*/
}
//valida formulario Cadastre-se
function ValidaForm_Cadastro(form){
	if(form.nome.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	var str_email = form.email.value;
    if((str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)||(str_email == 'Email:')){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	if(form.endereco.value.length<=1){
		alert("O campo Endereço deve ser preenchido corretamente.");
		form.endereco.focus();
		return false;
	}
	if(form.cep.value.length<=1){
		alert("O campo CEP deve ser preenchido corretamente.");
		form.cep.focus();
		return false;
	}
	if(form.cidade.value.length<=1){
		alert("O campo Cidade deve ser preenchido corretamente.");
		form.cidade.focus();
		return false;
	}
	if(form.estado.value.length<=1){
		alert("O campo Estado deve ser preenchido corretamente.");
		form.estado.focus();
		return false;
	}
	if(form.deseja.value.length<=1){
		alert("O campo Deseja receber informações deve ser preenchido corretamente.");
		form.deseja.focus();
		return false;
	}
}
