var URLSite = window.location.href;
var TituloSite = document.title;
function addfav(){
//if (document.all) window.external.AddFavorite(URLSite,TituloSite);
	if (window.sidebar)
        {
          window.sidebar.addPanel(TituloSite, URLSite,"");
        }
    else if( window.external ) { window.external.AddFavorite( URLSite, TituloSite); }
    else if(window.opera && window.print) { return true; }
    else { alert('Não foi possível adicionar esta página aos favoritos automaticamente.\n'+'Por favor, pressione CTRL + D para adicionar manualmente.'); }
}

function novaimg(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function mudaimg(a,b){
document[a].src=b;			
}

function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {
    xmlhttp = false;
    }
    }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
    xmlhttp = new XMLHttpRequest();
    } catch (e) {
    xmlhttp = false;
    }
    }
    return xmlhttp;
}
var http = getHTTPObject();
var foto_sel;
var timeoutID;
function verfoto(gal,foto) {
  clearTimeout(timeoutID);
  //document.getElementById("intro").style.display="none";
  http.open("GET", "foto.php?gal="+gal+"&foto="+foto, true);
  http.onreadystatechange = function(){
	if (http.readyState==4){
	  document.getElementById('big').innerHTML = http.responseText;
	  //alert(foto_sel);
	  if(foto_sel)
        {
			if(document.getElementById('foto_'+foto_sel))
				{
          	  	document.getElementById('foto_'+foto_sel).style.border='1px solid #D7E6F9';
				}
        }
	  if(document.getElementById('foto_'+foto))
		{
		document.getElementById('foto_'+foto).style.border='1px solid #0C2F69';
		}
	  if(mostraslide==1)
		{
			for(i=0;i<postodasimagens.length;i++)
                {
					//alert(foto+"-"+posimagens[i])
					if(foto==postodasimagens[i])
						{
							//alert("i="+i+" max="+(postodasimagens.length-1));
							if(i==postodasimagens.length-1)
								{
								foto2=postodasimagens[0];
								}
							else{
								foto2=postodasimagens[i+1];
						      }
    					document.getElementById("legendas_minis").innerHTML="&nbspImagem "+(i+1)+" de "+postodasimagens.length;
						i=postodasimagens.length;
						
				        }

				}
	  //foto_sel=foto;
		  //clearTimeout(timeoutID);
		//timeoutID = setTimeout("verfoto("+gal+","+foto2+")", 5000);
		timeoutID = setTimeout("carregada("+gal+","+foto+","+foto2+")", 100);
		//document.images["img_"+foto].onload=setTimeout("verfoto("+gal+","+foto2+")", 5000);
		}

	  foto_sel=foto;
	  
	}
	else{
	  document.getElementById('big').innerHTML = "<table cellpadding='0' cellspacing='0'><tr><td class='carregar'>A carregar</td></tr></table>";
	}
  }
  http.send(null);
}

function carregada(gal,foto,foto2)
    {
      
      if (document.images)
        {//alert(document.images["img_"+foto].complete);
              if(document.images["img_"+foto].complete)
                    {
                      timeoutID = setTimeout("verfoto("+gal+","+foto2+")", 5000);
                    }
              else{
                      timeoutID = setTimeout("carregada("+gal+","+foto+","+foto2+")", 100);
                }
        }
      else{
        timeoutID = setTimeout("carregada("+gal+","+foto+","+foto2+")", 100);
      }
    }
function digito(evt)
	{
         var charCode = (evt.which) ? evt.which : event.keyCode
        // alert(charCode);
         if ((charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=46) && (charCode > 106 || charCode < 95))
            return false;

         return true;
	}
function inteiro(campo)
	{
		valor=parseInt(campo.value);
		if (isNaN(valor)){valor=0};
		campo.value=parseInt(valor);
	}

/*
function setAndExecute(divId, innerHTML)
    {
      var div = document.getElementById(divId);
      div.innerHTML = innerHTML;
      var x = div.getElementsByTagName("script");
      for(var i=0;i<x.length;i++)
        {
          eval(x[i].text);
        }
//

    }
*/

function alteradin(param,id) {
  //document.getElementById("intro").style.display="none";
  http.open("GET", param, true);
  http.onreadystatechange = function(){
	if (http.readyState==4){
	  document.getElementById(id).innerHTML = http.responseText;
      //setAndExecute(id, http.responseText);

	}
	else{
	  document.getElementById(id).innerHTML = "<div class='texto'>A carregar</div>";
	}
  }
  http.send(null);
}


function alteraclt(id,frm) {
  http.open("GET", "mudacliente.php?param="+id.value, true);
  http.onreadystatechange = function(){
	if (http.readyState==4){
		param = http.responseText;
		/*alert(param);*/
		if(param!="")
			{
			param=param.split("_");
			document.forms[frm].nome.value = param[0];
			document.forms[frm].localidade.value = param[1];
			}
		else{
			alert("O número de Cliente não é válido.")
			document.forms[frm].nome.value = "";
			document.forms[frm].localidade.value = "";
			}
	}
  }
  http.send(null);
}

function carregaimgs() {
	if (document.images) {
		menu1_over = novaimg("images/menu/menu_02_2.gif");
		menu2_over = novaimg("images/menu/menu_04_2.gif");
		menu3_over = novaimg("images/menu/menu_05_2.gif");
		menu4_over = novaimg("images/menu/menu_06_2.gif");
		menu5_over = novaimg("images/menu/menu_07_2.gif");
	}
}

function envia(a)
    {
        document.location=a;
    }

function posiciona_menu()
    {
      if(document.getElementById('menueatendimento'))
        {
            document.getElementById('menueatendimento').style.left=(findPosX(document.getElementById('imgeatendimento'))-10)+"px";
            document.getElementById('menueatendimento').style.top=(findPosY(document.getElementById('imgeatendimento'))+20)+"px";
        }
    }
function mostra_submenu(a)
	{
        posiciona_menu();
		document.getElementById(a).style.display = 'block';
	}
function esconde_submenu(a)
	{
		document.getElementById(a).style.display = 'none';
	}
	
mostraslide=0;
function openbars(id1,id2,tipo)
	 {
	   if(tipo==1)
			{
                  document.getElementById("legendas_minis").style.display="none";
				  document.getElementById(id1).style.filter="revealTrans(duration=0.1, transition=5)";
				  document.getElementById(id1).filters.revealTrans.apply();
				  document.getElementById(id1).style.visibility="visible";
				  document.getElementById(id1).filters.revealTrans.play();
				  document.getElementById(id2).style.filter="revealTrans(duration=0.1, transition=5)";
				  document.getElementById(id2).filters.revealTrans.apply();
				  document.getElementById(id2).style.visibility="visible";
				  document.getElementById(id2).filters.revealTrans.play();
				  document.getElementById("paginas").style.visibility="visible";
				  mostraslide=0;
				  clearTimeout(timeoutID);
			}
		else if(tipo==2){
				  document.getElementById(id1).style.filter="revealTrans(duration=0.1, transition=4)";
				  document.getElementById(id1).filters.revealTrans.apply();
				  document.getElementById(id1).style.visibility="hidden";
				  document.getElementById(id1).filters.revealTrans.play();
				  document.getElementById(id2).style.filter="revealTrans(duration=0.1, transition=4)";
				  document.getElementById(id2).filters.revealTrans.apply();
				  document.getElementById(id2).style.visibility="hidden";
				  document.getElementById(id2).filters.revealTrans.play();
				  document.getElementById("paginas").style.visibility="hidden";
				  document.getElementById("legendas_minis").style.display="block";
				  for(i=0;i<postodasimagens.length;i++)
				     {
						 if(postodasimagens[i]==foto_sel)
						 	{
								mostraslide=1;
								timeoutID = setTimeout("slidestart("+i+")", 5000);
								//verfoto(gal,posimagens[i]);
								document.getElementById("legendas_minis").innerHTML="&nbspImagem "+(i+1)+" de "+postodasimagens.length;
								i=postodasimagens.length;
							}
					 }

				  
			}
			
	 }
	
function findPosY(obj)
{
	if(obj)
		{
			var curtop = 0;
			if (obj.offsetParent)
			{
				while (obj.offsetParent)
				{
					curtop += obj.offsetTop
					obj = obj.offsetParent;
				}
			}
			else if (obj.y)
				curtop += obj.y;
			return curtop;
		}
}
function findPosX(obj)
{
	if(obj)
		{
			var curleft = 0;
			if (obj.offsetParent)
			{
				while (obj.offsetParent)
				{
					curleft += obj.offsetLeft
					obj = obj.offsetParent;
				}
			}
			else if (obj.x)
				curleft += obj.x;
			return curleft;
		}
}

function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
    try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {
    xmlhttp = false;
    }
    }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
    xmlhttp = new XMLHttpRequest();
    } catch (e) {
    xmlhttp = false;
    }
    }
    return xmlhttp;
}
var http = getHTTPObject();
function bigthumb(gal,foto) {
  var b="ie";
    if(navigator.appName != "Microsoft Internet Explorer")
    	{
    		b="ff";
    	}
  //document.getElementById("intro").style.display="none";
  http.open("GET", "bigthumb.php?gal="+gal+"&foto="+foto+"&b="+b, true);
  http.onreadystatechange = function(){
	if (http.readyState==4){
	  document.getElementById('big').innerHTML = "<table cellpadding='0' cellspacing='0'><tr><td class='carregar' width='310' valign='top'><div style='width:310px;'>"+http.responseText+"</div></td></tr></table>";
	}
	else{
	  document.getElementById('big').innerHTML = "<table cellpadding='0' cellspacing='0'><tr><td class='carregar' width='310'><div style='width:310px;margin-top:80px;'>A carregar...</div></td></tr></table>";
	}
  }
  http.send(null);
}

var http2 = getHTTPObject();
function dinpopup(s,w,h,l,id) {
  var b="ie";
    if(navigator.appName != "Microsoft Internet Explorer")
    	{
    		b="ff";
    	}
  var leg = l.split("£");
  if(leg.length==2)
    {
      l=leg[0]+"&ngal="+leg[1];
    }
  //document.getElementById("intro").style.display="none";
  http2.open("GET", "dinimg.php?s="+s+"&w="+w+"&h="+h+"&l="+l+"&b="+b+"&lfoto="+id, true);
  w2=w; if(w<450){w2=450;}
  http2.onreadystatechange = function(){
	if (http2.readyState==4){
	  document.getElementById('dinimg').innerHTML = "<table cellpadding='0' cellspacing='0' onclick=\"hm('box')\"><tr><td class='carregar' width='"+(w2+10)+"' valign='top' align='center'>"+http2.responseText+"</td></tr></table>";
	}
	else{
	  document.getElementById('dinimg').innerHTML = "<table cellpadding='0' cellspacing='0'><tr><td class='carregar' width='"+(w2+10)+"'><div style='width:"+(w2+10)+"px;margin-top:80px;'>A carregar...</div></td></tr></table>";
	}
  }
  http2.send(null);
}




function imagem(largura,altura,img,leg){
      if(document.getElementById("box"))
        {
              dinpopup(img,largura,altura,leg,"");
              if(leg!=""){altura+=20;}
              var sizesPage = getPageSize();

              var p="px";
              bodyOverlay();
              if(largura<450){largura=450;}
              if(altura<320){altura=320;}
              document.getElementById("box").style.top=posTop()+arrayPageSize[3]/2-altura/2+p;
              document.getElementById("box").style.left=posLeft()+arrayPageSize[2]/2-largura/2+p;
              document.getElementById("box").style.display="block";
              //alert(arrayPageSize[2]/2);
        }

    }
