// ***********************************************************************************************************
//	"javascript:MM_openwin(\"http://www.google.com\",300,400);"
// ***********************************************************************************************************
function MM_openwin(MM_file,MM_height,MM_width)
{
   MM_config=""
   MM_config+="toolbar=no,";
   MM_config+="location=no,"
   MM_config+="directories=no,";
   MM_config+="status=yes,"
   MM_config+="menubar=no," //Not on Apple Mac for obvious reasons
   MM_config+="scrollbars=yes,"
   MM_config+="resizable=yes," //Mac windows are always resizable
   MM_config+="copyhistory=no,"
   MM_config+="width="+MM_width+","
   MM_config+="height="+MM_height
   var MM_win=open(MM_file,"",MM_config);
   MM_win.focus();
}

// ***********************************************************************************************************
function PopupPic(sPicURL) { 
	window.open("/showpic.htm?"+sPicURL, "", "resizable=1,HEIGHT=20,WIDTH=20");
}

// ***********************************************************************************************************

function hidepass(){
   //document.formlogin.ptext.style.display='none'; 
   document.formlogin.pwd.style.display='sa';
   document.formlogin.pwd.style='Password';
   document.formlogin.pwd.focus();
 }
// ***********************************************************************************************************
function showpass(){
   document.formlogin.pwd.style.display='none'; 
   document.formlogin.ptext.style.display='';
   document.formlogin.ptext.focus();
}
// ***********************************************************************************************************
function setEnd (el) {
 if (el.createTextRange) {
   var FieldRange = el.createTextRange();
   FieldRange.moveStart('character', el.value.length);
   FieldRange.collapse();
   FieldRange.select();
 }
}
// ***********************************************************************************************************

function bookmark(){
var title = 'Title of Bookmark';
var url = 'http://yourdomain.com';
   if (document.all)
     window.external.AddFavorite(url, title);
   else if (window.sidebar)
     window.sidebar.addPanel(title, url, "")
   else if (window.sidebar&&window.sidebar.addPanel)
     window.sidebar.addPanel(title,url,"");
}

// ***********************************************************************************************************
// ***********************************************************************************************************

function textSize(dir) {
    if (dir == 'up') {
        if (currentTextSize <= 17) {
            currentTextSize += 2;
        }
    } else if (dir == 'down') {
        if (currentTextSize >= 11) {
            currentTextSize -= 2;
        }
    }
    currentLineHeight = currentTextSize + 5;
    document.getElementById('bodyText').style.fontSize = currentTextSize + 'px';
    document.getElementById('bodyText').style.lineHeight = currentLineHeight + 'px';
    // write/rewrite cookie
    //createCookie("ihtfontsize",currentTextSize,1000);
}
// ***********************************************************************************************************
// ***********************************************************************************************************

function toggleDiv(divid){
	if(document.getElementById(divid).style.display == 'none')
	{
    	document.getElementById(divid).style.display = 'block';
    }
	else
	{
    	document.getElementById(divid).style.display = 'none';
    }
}
// ***********************************************************************************************************
function formLogin(f)
{
 	f.login.focus();
   	return (true);
}
// ***********************************************************************************************************
function escondeStatus()
{
	var statusMsg=""
	window.status=statusMsg
	return true
}
// ***********************************************************************************************************
function RedirectOpener(url)
{
	window.opener.location = url;
	window.close();
}
// ***********************************************************************************************************
function imprime() 
{
	var agt=navigator.userAgent.toLowerCase();	
	if (window.print) 
	{
		setTimeout('window.print();',200);
	}
	else if (agt.indexOf("mac") != -1) 
		{
			alert("Pressione 'Cmd+p' no seu teclado para imprimir este artigo.");
		}
		else 
		{
			alert("Pressione 'Ctrl+p' no seu teclado para imprimir este artigo.")
		}
}
// ***********************************************************************************************************
function openpopupsize(url,larg,alt,barrasscroll)
{
	var popurl = url
	var esq = screen.width/2-(larg/2)
	var topo = screen.height/2-(alt/2)-50
	var tam="width=" + larg + ",height=" + alt
	winpops=window.open(popurl,"JANELA", tam + ",screenX=" + esq + ",left=" + esq + ",screenY=" + topo + ",top=" + topo + ",scrollbars=" + barrasscroll)
}

// ***********************************************************************************************************
// Janela Modal
// ***********************************************************************************************************
var winModalWindow
function IgnoreEvents(e)
{
	return false
}
function openModal(url,larg,alt)
{
	var centerLeft = (window.screen.width - larg) / 2;
	var centerTop = (window.screen.height - alt) / 2;
	if (window.showModalDialog)
  	{
    	window.showModalDialog(url,null,'dialogWidth:' + larg + 'px; dialogHeight:' + alt + 'px; edge:Sunken; center:Yes; resizable:No; status:No; ')
	}
  	else
  	{
    	window.top.captureEvents (Event.CLICK|Event.FOCUS)
	    window.top.onclick=IgnoreEvents
	    window.top.onfocus=HandleFocus 
	    winModalWindow = 
    	window.open ("ModalChild.htm","ModalChild","dependent=yes,width=200,height=100")
		winModalWindow.focus()
  	}
}
function HandleFocus()
{
	if (winModalWindow)
  	{
    	if (!winModalWindow.closed)
    	{
      		winModalWindow.focus()
    	}
    	else
    	{
      		window.top.releaseEvents (Event.CLICK|Event.FOCUS)
      		window.top.onclick = ""
    	}
  	}
  	return false
}



// ***********************************************************************************************************
// Valida se alguma das opções do inquerito foi seleccionada
// ***********************************************************************************************************
function validate_form_inq(f) 
{
	var radioGrp = f.inquerito;
	var ok = false;
	//alert("número de opções =" + radioGrp.length);
	for(i=0; i < radioGrp.length; i++)
	{
		if (radioGrp[i].checked)
			ok = true;
	}
	if (ok == false)
	{
		alert("Escolha uma resposta!");	
	}
	return ok;
}

// ***********************************************************************************************************
// Valida se colocou pwd
// ***********************************************************************************************************
function validate_form_pwd(f) 
{
	var ok = false
	if (f.pwd.value != "")
	{
		ok = true		
	}
	if (ok == false)
	{
		alert("Escreva uma Palavra-passe!")
		return ok
	}
	ok = false
	if (f.pwd.value.length >= 4)
	{
		ok = true
	}
	if (ok == false)
	{
		alert("A Palavra-passe tem que ter pelo menos 4 cracteres!")
	}
	return ok
}

// ***********************************************************************************************************
// Valida se colocou pwd igual
// ***********************************************************************************************************
function validate_alter_pwd(f) 
{
	var ok = false;
	
	if (f.pwd1.value == "" || f.pwd2.value == "")
	{
		alert("Tem que escrever uma palavra-passe!\nPor favor tente de novo.");
		return ok;
	}
	if (f.pwd1.value != f.pwd2.value)
	{
		alert("As palavras devem ser iguais nas duas caixas!\nPor favor tente de novo.");
	}
	else
	{
		ok = true;
	}
		
	return ok;
}


// ***********************************************************************************************************
// Função mostra relógio
// ***********************************************************************************************************
function Wryt(ID, S) {
	document.getElementById(ID).innerHTML = S 
}

// ***********************************************************************************************************
function TimeStr(D) { 
	return D.toString().match(/\d\d:\d\d:\d\d/) 
}


// ***********************************************************************************************************
function DataPT() { 
/*
	var mydate=new Date()
	var year=mydate.getYear()
	if (year < 1000)
		year+=1900
	var day=mydate.getDay()
	var month=mydate.getMonth()
	var daym=mydate.getDate()
	if (daym<10)
		daym="0"+daym

	var dayarray=new Array("Domingo","Segunda","Terça","Quarta","Quinta","Sexta","S&aacute;bado")
	var montharray = new Array("Janeiro","Fevereiro","Mar&ccedil;o", "Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro")
	//document.write(dayarray[day] + ", " + daym + "/" + montharray[month]+ "/" + year)
	//return (dayarray[day] + ", " + daym + " de " + montharray[month]+ " de " + year)
	return (daym + " de " + montharray[month]+ " de " + year)
*/
}

// ***********************************************************************************************************
function TimeNow() {
	var D = new Date()
	var S = TimeStr(D)
  	setTimeout("TimeNow()",1050-D.getTime()%1000)
	
  	Wryt('Timer', DataPT()+'&nbsp;&bull;&nbsp;'+S) 
	/*Wryt('Timer', '<span>' + S + '<\/span">') */
}
// ***********************************************************************************************************
function formdefaultfocus()
{
		var foo = typeof document.forms[0] != 'undefined';
		if (foo == true)
		{
			document.forms[0].elements[0].focus();
		}	
}

// ***********************************************************************************************************
function formDefaultFocus(f,e)
{
		//f = nº do form (inicio em 0)
		//e = elemento ou campo do form (inicio em 9)
		
		// cloca Focus no 1º campo do 1º Form
		var existe = typeof document.forms[f] != 'undefined';
		//alert('form 0 existe: ' + existe);
		
		if (existe == true)
		{
			try
   			{
				document.forms[f].elements[e].focus();
   			}
			catch(err)
   			{
   				//txt="There was an error on this page.\n\n"
   				//txt+="Error description: " + err.description + "\n\n"
   				//txt+="Click OK to continue.\n\n"
   				//alert(txt)
   			}
		}
}


// ***********************************************************************************************************
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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// ***********************************************************************************************************
function MM_validateForm() { //v4.0
  var contato = document.getElementById('contato');
  var i, check = false, interesse;
  for( i = 1; i <= 5; i++ ){
	interesse = document.getElementById('interesse'+i).checked;
	if( interesse == true ){
	  check = true;
	}
  }
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { 
      test=args[i+2]; 
	  val=MM_findObj(args[i]);
	  if(val.name == 'mensagem'){
		if( check == false ){
				errors += '- serviço de interesse é requerido.\n'; 
		} 
	  }
      if (val) { 
	    nm=val.name; 
		if ((val=val.value)!="") {
		  if (test.indexOf('isEmail')!=-1) { 		
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("email").value))){
			   errors+='- O '+nm+' não é valido.\n';
			}	
		  } else if (test!='R') { 
		    num = parseFloat(val);
			if (isNaN(val)) errors+='- O '+nm+'deve conter apenas números.\n';
			if (test.indexOf('inRange') != -1) { 
			    p=test.indexOf(':');
			    min=test.substring(8,p); max=test.substring(p+1);
			    if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
			} 
		  } 
		} else if (test.charAt(0) == 'R'){
			errors += '- '+nm+' é requerido.\n'; 
		}
	  }
	
  } 

  if (errors) alert('Ocorreram os seguintes erros:\n'+errors);
  document.MM_returnValue = (errors == '');
  if (errors == ''){ contato.submit(); }
}

// ***********************************************************************************************************
function createTable(){
	var altura = '';
	var largura = '';
	altura = document.body.scrollHeight;
	largura = document.body.scrollWidth;
	
	document.getElementById('transparente').style.height = altura;
	document.getElementById('transparente').style.width = largura;
	
	var redimenciona = '<img src="/images/transp.gif" width="30" height="'+altura+'">';	
	
	document.getElementById('transparente').innerHTML = redimenciona;	

}

// ***********************************************************************************************************
function swf(xml,id){
	var flash = '<a href="#item'+id+'" onClick="MM_showHideLayers(\'transparente\',\'\',\'hide\',\'exemplo\',\'\',\'hide\');"><img src="imagens/fecharfoto.gif" width="139" height="20" border="0" style="margin-bottom: 5px;"></a><br>';	
		flash += '<script type="text/javascript">AC_FL_RunContent( \'codebase\',\'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\',\'wmode\',\'transparent\',\'width\',\'410\',\'height\',\'340\',\'menu\',\'false\',\'src\',\'galeria_fotos?arquivo='+xml+'\',\'quality\',\'high\',\'pluginspage\',\'http://www.macromedia.com/go/getflashplayer\',\'movie\',\'galeria_fotos?arquivo='+xml+'\' );</script>';
      	flash += '<embed src="galeria_fotos.swf?arquivo='+xml+'" menu="false" width="410" height="340" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>';
	document.getElementById('site').innerHTML = flash;
}


