/*
	Pwpp Soluções Digitais
		Validação de Email
		Data: 20/10/2005
*/
function acertaEstiloFundo(obj){
	if(obj == "800"){
		document.write('<style type="text/css">body {  background-image: url(../../imagens/fundo.gif); background-repeat: repeat-y; background-attachment: fixed; background-position: 0px}</style>');
	}else{
		document.write('<style type="text/css">body {  background-image: url(../../imagens/fundo.gif); background-repeat: repeat-y; background-attachment: fixed; background-position: '+larguraRestante+'px}</style>');
	}
}
function formatar(src, mask){
	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);
	}
}
function validaTeclaSenha(e){

	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	} else if(e.which) {
		// netscape
		key = e.which;
	}

	if((key > 47 && key < 58) || (key > 64 && key < 91) || (key > 96 && key < 123)){ // numeros de 0 - 9 letras de a - z
		return true;
	}else{
		if(key != 8){ // backspace
			return false;
		}else{
			return true;
		}
	}
}
function upG(number,imagemLink){
   		document.images[number].src=imagemLink;
}
function downG(number,imagemLink){
	document.images[number].src=imagemLink;
}
function bloquearNaoNumerico() { 
	if (event.keyCode==34 || event.keyCode==38 || event.keyCode==39){ 
		event.keyCode=0; 
	} 
	if ((event.keyCode < 48) ||(event.keyCode > 57)){
		if (event.keyCode==13){
			event.keyCode=13; 
		}else{
			event.keyCode=0; 
		}
	} 
}
function Ajax() {
  try {
    return new ActiveXObject("Microsoft.XMLHTTP");
  } catch(e) {
    try {
      return new ActiveXObject("Msxml2.XMLHTTP");
    } catch(ex) {
      try {
        return new XMLHttpRequest();
      } catch(exc) {
        return false;
      }
    }
  }
}

function Open(pag, div){
	var field  = document.getElementById(""+div+"");
	var ajax = Ajax();
	ajax.open("GET",""+pag,true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 1) {
			field.innerHTML = "Carregando...";
		}else if(ajax.readyState == 4) {
			if(ajax.status == 200) {
				var returnText = ajax.responseText.replace(/\+/g," ");
				field.innerHTML = unescape(returnText);
			} else {
				<!-- ajax.statusText; -->
			}
		}
	}
	ajax.send(null);
}


//*********************************************************************************************************************************************************
// Valida CPF
function TESTA(CNUMB,CTYPE){
	if(Verify(CNUMB, CTYPE)){
		
	}else{
		str = CTYPE+" inválido!\n"
	}
	return;
}
function ClearStr(str, char){
	while((cx=str.indexOf(char))!=-1){		
		str = str.substring(0,cx)+str.substring(cx+1);
	}
	return(str);
}
function ParseNumb(c){
	c=ClearStr(c,"-");
	c=ClearStr(c,"/");
	c=ClearStr(c,",");
	c=ClearStr(c,".");
	c=ClearStr(c,"(");
	c=ClearStr(c,")");
	c=ClearStr(c," ");
	if((parseFloat(c) / c != 1)){
		if(parseFloat(c) * c == 0){
			return(c);
		}else{
			return(0);
		}
	}else{
		return(c);
	}
	return(c);
}
function Verify(CNUMB,CTYPE){
	CNUMB=ParseNumb(CNUMB)
	if(CNUMB == 0){
		return(false);
	}else{
		g=CNUMB.length-2;
		if(TestDigit(CNUMB,CTYPE,g)){
			g=CNUMB.length-1;
			if(TestDigit(CNUMB,CTYPE,g)){	
				return(true);
			}else{
				return(false);
			}
		}else{
			return(false);
		}
	}
}
function TestDigit(CNUMB,CTYPE,g){
	var dig=0;
	var ind=2;
	for(f=g;f>0;f--){
		dig+=parseInt(CNUMB.charAt(f-1))*ind;
		if (CTYPE=='CNPJ'){ 
			if(ind>8) {
				ind=2
			}else {
				ind++
			} 
		}else{
			ind++ 
		}
	}
	dig%=11;
	if(dig<2){
		dig=0;
	}else{
		dig=11-dig;
	}
	if(dig!=parseInt(CNUMB.charAt(g))){
		return(false);
	}else{
		return(true);
	}
}
//*********************************************************************************************************************************************************
// Genericos
function janela(url,janela,larg,alt,scroll){
	if (!scroll) {
		scroll='auto'
	}
	var posx = (screen.width - larg) / 2;
	var posy = (screen.height - alt) / 2;
	janelaNova = window.open(url,janela,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+scroll+",resizable=0,copyhistory=0,width="+larg+",height="+alt+",left="+posx+",top="+posy+"");
	janelaNova.focus();
}
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_swapImgRestore() {
	var i,x,a=document.MM_sr; 
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
		x.src=x.oSrc;
}
/* ------------------- COMBO PRODUTOS -------------------------------- */
function MM_jumpMenu(targ,selObj,restore){
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}
/* ------------------- GALERIA DE IMAGENS DE FESTAS E EVENTOS -------------------------------- */
function galeriaFesta(tituloGaleria, imagem, id) {
	_url = "../popups/galeria_festa.asp?imagem=" + imagem + "&tituloGaleria=" + tituloGaleria + "&id=" + id;
	zoom = open(_url, "galeriaImagens", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=350,height=10,left=0,top=0");
	window.zoom.focus();
}
/* ------------------- GALERIA DE IMAGENS GENÉRICAS -------------------------------- */
function Aumenta(secao, imagem, id) {
	_url = "../popups/galeria.asp?imagem=" + imagem + "&secao=" + secao + "&id=" + id;
	zoom = open(_url, "zoom", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=350,height=10,left=0,top=0");
	window.zoom.focus();
}
/* ------------------- POPUP PRODUTOS -------------------------------- */
function openProduct(titulo, conteudo, pasta, nomeFoto, embalagem, restricoes) {
	/*
		titulo -> nome do produto (ex.: Coca Cola Light PET)
		conteudo -> conteúdo (ex.: 500ml)
		pasta -> pasta onde se encontram as fotos da linha (ex.: coca_normal)
		nomeFoto -> nome da foto do produto com extenção (ex.: coca_normal_g.jpg)
		embalagem -> TRUE se for Retornável e FALSE se for Descartável (ex.: true)
		restricoes -> locais onde vendam, caso não exista restrições colocar null (ex.: Somente RS)
	*/
	//alert(titulo +'\n'+ conteudo +'\n'+ pasta +'\n'+ nomeFoto +'\n'+ embalagem +'\n'+restricoes);

	path = '';
	path += '../popups/produtos.asp?';
	path += "titulo=" + titulo + "";
	path += "&conteudo=" + conteudo + "";
	path += "&pasta=" + pasta + "";
	path += "&nomeFoto=" + nomeFoto + "";
	path += "&embalagem=" + embalagem + "";
	path += "&restricoes=" + restricoes +"";

	zoom = open(path, "zoom", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width=350,height=10,left=0,top=0");
	window.zoom.focus();
}
/* ------------------- POPUP PRODUTOS 360 -------------------------------- */
function viewImg360(fileName) {
	/*
		fileName -> nome do arquivo sem extensão
	*/
	larg = 320;
	alt = 560;
	url = "../popups/360.asp?file=" + fileName + "";
	var posx = (screen.width - larg) / 2;
	var posy = (screen.height - alt) / 2;
	
	img360 = window.open(url,"img360","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width="+larg+",height="+alt+",left="+posx+",top="+posy+"");
	window.img360.focus();
}
/* ------------------- ENQUETES -------------------------------- */
function votar(){
	var frm=document.enquete;
	var opcao = 0;
	for (var i = 0; i < frm.enquete.length; i++) {
		if (frm.enquete[i].checked) {
			opcao = frm.enquete[i].value;
		}
	}
	if (opcao == "0"){
		alert("Por favor, selecione uma opção.");
	} else {
		_url = "votar.asp?resposta=" + opcao + "&ID_conteudo=" + frm.ID_conteudo.value;
//		xxx = open(url, "Enquete", "directories=0,location=0,menubar=0,resizable=0,scrollbars=1,status=0,toolbar=0,width=350,height=300,left=0,top=0");
		janela(_url,'Enquete','350','300',0);
	}
}
/* ------------------- PWPP CURRICULOS -------------------------------- */
function validaLogin(){
	obj = document.login;
	str = '';
	if(obj.CPF.value == '' || obj.CPF.value == 'CPF'){
		str += 'Você deve informar seu CPF.';
	}else{
		TESTA(obj.CPF.value, 'CPF');
	}
	if(str != ''){
		alert(str);
	}else{
		document.login.submit();
	}
}
/* ------------------- PWPP CURRICULOS -------------------------------- */
function novoCPF(){
	obj = document.novo;
	str = '';
	if(obj.CPFNovo.value == ''){
		str += 'Você deve informar seu CPF.';
	}else{
		TESTA(obj.CPFNovo.value, 'CPF');
	}
	if(str != ''){
		alert(str);
	}else{
		if (str != 'CPF Inválido') {
			document.novo.submit();
		}
	}
}
/* ------------------- PWPP CURRICULOS -------------------------------- */
function Checar(){
	marcado = -1
	for (i=0;i<login.id_vaga.length;i++) {
		if (login.id_vaga[i].checked) {
			marcado = i
		}
	}
	if (marcado == -1) {
		alert("Selecione pelo menos uma das vagas.");
		}
   else {
		obj = document.login;
		str = '';
		if(obj.CPF.value == '' || obj.CPF.value == 'CPF'){
			str += 'Você deve informar seu CPF.';
		}else{
			TESTA(obj.CPF.value, 'CPF');
		}
		if(str != ''){
			alert(str);
		}else{
			document.login.submit();
		}
   }
}
/* ------------------- CAPTURA ENTER -------------------------------- */
function f1(e) {
	if( ((document.layers && e.which == 13) || (document.all && window.event.keyCode == 13)) && (!(document.activeElement.name=="mensagem")) && (!(document.activeElement.name=="descricao")) && (!(document.activeElement.name=="objetivos")) && (!(document.activeElement.name=="forma_aproveitamento"))  ) { 
		execEnter(); 
		return false; 
	} 
} 
if (document.layers) { 
	document.captureEvents(Event.KEYPRESS); 
} 
if (document.layers || document.all){
	document.onkeypress = f1;	
} 
/* ------------------- VALIDA EMAIL -------------------------------- */
function checkEmail(emailStr) {
	if (emailStr.length == 0) {
		return false;
	}
	var emailPat=/^(.+)@(.+)$/;
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
    var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
    var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
    var matchArray=emailStr.match(emailPat);
	if (matchArray == null) {
    	return false;
	}
    var user=matchArray[1];
	var domain=matchArray[2];
    if (user.match(userPat) == null) {
		return false;
	}
	var IPArray = domain.match(ipDomainPat);
    if (IPArray != null) {
    	for (var i = 1; i <= 4; i++) {
	    	if (IPArray[i] > 255) {
		    	return false;
			}
		}
		return true;
	}
	var domainArray=domain.match(domainPat);
	if (domainArray == null) {
		return false;
	}
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if ((domArr[domArr.length-1].length < 2) || (domArr[domArr.length-1].length > 3)) {
		return false;
	}
	if (len < 2) {
		return false;
	}
	return true;
}
/*
	-----------------------------------------------------------------------------------------------
	-------------------------------- DESABILITA BOTÃO DIREITO -------------------------------------
	-----------------------------------------------------------------------------------------------
*/

function md(e) 
{ 
  try { if (event.button==2||event.button==3) return false; }  
  catch (e) { if (e.which == 3) return false; } 
}
document.oncontextmenu = function() { return false; }
document.ondragstart   = function() { return false; }
document.onmousedown   = md;


/*

	-----------------------------------------------------------------------------------------------
	-------------------------------- DESABILITA BOTÃO DIREITO -------------------------------------
	-----------------------------------------------------------------------------------------------
*/
/* ------------------- REFRESH NA PAGINA AO ALTERAR DE TAMANHO DO IE -------------------------------- */
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) 
		with (navigator) {
			if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
				document.MM_pgW=innerWidth; 
				document.MM_pgH=innerHeight; 
				onresize=MM_reloadPage; 
			}
		}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
		location.reload();
}
MM_reloadPage(true);