function janela_galeria(id_portfolio,imageWidth,imageHeight){
	posTop = (screen.availHeight/2-imageHeight/2);
	posLeft = (screen.availWidth/2-imageWidth/2);
	port_detalhado = window.open('portfolio/detalhe.php?id_portfolio='+id_portfolio+'','port_detalhado','width='+imageWidth+',height='+imageHeight+',top='+posTop+',left='+posLeft+'')
	port_detalhado.focus();
}

function SetCookie (name, value)    {
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path = "/";
   var domain = (argc > 4) ? argv[4] : null;
   var secure = (argc > 5) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
}


function getCookieVal (offset)    {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)    {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen)       {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break; 
      }
   return "";
}

function verificar_cep(cep,verif_cep,formulario){
	largura = 600;
	altura  = 400;
	url_janela = 'busca/cep.php?cep='+cep+''+verif_cep+'&formulario='+formulario;
	msg = window.open(url_janela,'janela_detalhe','scrollbars=yes,width='+largura+',height='+altura+',top='+(screen.availHeight/2-altura/2)+',left='+(screen.availWidth/2-largura/2));
	msg.focus();
}

function valida_cep(form,campo1,campo2){
	formulario = eval('document.'+form);
	cep = formulario[campo1].value;
	verif_cep = formulario[campo2].value;
	if((cep.length<5)||(verif_cep.length<3)){
		return false;
	}
	return true;
}

function SaltaCampo (form,campo,prox,tammax,teclapres){ //onKeyUP="SaltaCampo('form1','textfield6','textfield7','5',event);"
	formulario = eval('document.'+form);
	var tecla = teclapres.keyCode;
	vr = formulario[campo].value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		formulario[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ",", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	tam = vr.length;	


		
	 	if (tecla != 0 && tecla != 9 && tecla != 16 )
			if ( tam == tammax )	
				formulario[prox].focus() ;	}
}

function visualiza_imagem(imageName,imageWidth,imageHeight,alt) {
	posTop = (screen.availHeight/2-imageHeight/2);
	posLeft = (screen.availWidth/2-imageWidth/2);
	
	imagemJanela = window.open("","imagemJanela","width="+imageWidth+",height="+imageHeight+",left="+posLeft+",top="+posTop);
	imagemJanela.document.open();
	imagemJanela.document.write('<html><title>'+alt+'</title><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">');
	imagemJanela.document.write('<img src="'+imageName+'" width="'+imageWidth+'" height="'+imageHeight+'" alt="'+alt+'">');
	imagemJanela.document.write('</body></html>');
	imagemJanela.document.close();
	imagemJanela.focus();
}

function FormataValor(form,campo,tammax,teclapres) { //onKeyPress="FormataValor('form1','textfield5','10',event)"
	formulario = eval('document.'+form);
	var tecla = teclapres.keyCode;
	vr = formulario[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		formulario[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		formulario[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		formulario[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		formulario[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		formulario[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		formulario[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}		
	
}

function FormataData(form, Campo, teclapres) {//onKeyDown="FormataData('formulario', 'textfield',event)"
	formulario = eval('document.'+form);
	var tecla = teclapres.keyCode;
	vr = formulario[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			formulario[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			formulario[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
}

function selecionar(form) {
	 formulario = eval('document.'+form);
	 for (var i=0; i<formulario.elements.length; i++) {
	 	 if (formulario.elements[i].type=="checkbox") { 
		 	formulario.elements[i].checked=true;
		 }
	 }
} 

function desselecionar(form) {
	 formulario = eval('document.'+form);
	 for (var i=0; i<formulario.elements.length; i++) {
	 	if (formulario.elements[i].type=="checkbox") {
			formulario.elements[i].checked=false;
		}
	 }
} 

function inverter(form) {
	formulario = eval('document.'+form);
	for (var i=0; i<formulario.elements.length; i++) {
		if (formulario.elements[i].type=="checkbox") {
			formulario.elements[i].checked=!formulario.elements[i].checked;
		}
	}
} 


function func_janela(nome,url_destino,largura,altura){
	nome = window.open(url_destino,''+nome+'','scrollbars=yes,width='+largura+',height='+altura+',top='+(screen.availHeight/2-altura/2)+',left='+(screen.availWidth/2-largura/2));
	nome.focus();
}

function valida_pesquisa_home (campo,prox,tammax,teclapres){ //valida_pesquisa_home="SaltaCampo('textfield6','textfield7','5',event);"
	var tecla = teclapres.keyCode;	
	vr = document.form_pesquisa[campo].value;
		tam = vr.length;	
	if (tam<=tammax){
		if (tecla != 32){
			if ( tam>=tammax ){
				document.form_pesquisa[prox].disabled=false;
			}
		}else{
			document.form_pesquisa[campo].value=vr.substr(0,vr.length-1);
			document.form_pesquisa[prox].disabled=true;
		}
	}else{
		if ( tam>=tammax ){
			document.form_pesquisa[prox].disabled=false;
		}else{
			document.form_pesquisa[prox].disabled=true;				
		}
	}
	if ((tecla == 8) && (tam<tammax)){
		document.form_pesquisa[prox].disabled=true;				
	}
}

function favoritos(url,title){
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
		window.external.AddFavorite (url,title);
	} else {
	var msg = "Adicione nosso site ao seus Favoritos ";
	if ((navigator.appName == "Netscape") || (navigator.appName == "Microsoft Internet Explorer")) msg += "  (Pressione CTRL + D)";
		alert(msg); 
	}
}
