/* Strip whitespace from the beginning and end of a string */
if (typeof String.prototype.trim == "undefined") {
    String.prototype.trim = function () {
        var s = this.replace(/^\s*/, "");
        return s.replace(/\s*$/, "");
    }
}

function findObj(n, d) { 
  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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function Registar(){
  var formRF1=findObj('RegistarForm');
  if (formRF1) {	
   return true;
  } else {
	  return false;
  }
}

function Guardar(){
  var formRG=findObj('GuadarForm');
  if (formRFG) {	
   return true;
  } else {
	  return false;
  }
}

function recuperar(){
  var formRF2=findObj('RecuperarForm');
  if (formRF2) {	
   return true;
  } else {
	  return false;
  }
}


function login(){
	var form=findObj('Login');
	form.submit();
}

function logout(){
	var form=findObj('Logout');
	form.submit();
}

function pesquisar(){
  	
	var palavras=findObj('procurar');
	if (palavras) {
		var texto=palavras.value.trim();		
		if (texto.length>0) {
			  	var obj=findObj('search');
					obj.value=1;					
				var form=findObj('Pesquisa');
				    if (form) {				    	
				    	form.submit();
				    }
				    else alert('Erro na pesquisa!');
             
		} else { alert('Escreva uma ou mais palavras para pesquisar'); return false;}
	}
}



//FLASH INSERCAO

function flash(url,w,h){
 document.writeln('<!--[if IE]>');
 document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'">');
 document.writeln('<param name="movie" value="'+url+'">');
 document.writeln('<param name="quality" value="high">');
 document.writeln('<param name="menu" value="false">');
 document.writeln('<param name="wmode" value="transparent">');
 document.writeln('<\/object>');
 document.writeln('<![endif]-->');
 document.writeln('<!--[if !IE]> <!-->');
 document.writeln('<object type="application/x-shockwave-flash" data="'+url+'" width="'+w+'" height="'+h+'">');
 document.writeln('<param name="quality" value="high">');
 document.writeln('<param name="controller" value="false">');
 document.writeln('<param name="autoplay" value="true">');
 document.writeln('<param name="menu" value="false">');
 document.writeln('<param name="wmode" value="transparent">');
 document.writeln('alt : <a href="'+url+'">'+url+'<\/a>');
 document.writeln('<\/object>');
 document.writeln('<!--<![endif]-->');      
}

//FAVORITOS

function AjoutFavo() {
    if ((navigator.appName.indexOf("Microsoft",0)>=0) && (parseInt(navigator.appVersion)>=4)) {
        window.external.AddFavorite("http://paveiro.linux.dev","Aveiro" );
    } else {
        alert("Optimizado para Internet Explorer 5 ou superior")
    }
}

//----------------------------------

//MENU DROP DOWN

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



//**********************************





days = new Array(
"Domingo","Segunda","Ter�a","Quarta","Quinta","Sexta","Sabado"
);
months = new Array(
"Janeiro","Fevereiro","Mar�o","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"
);

function renderDate(){
	var mydate = new Date();
	var year = mydate.getYear();
	if (year < 2000) {
		if (document.all)
			year = "19" + year;
		else
			year += 1900;
	}
	var day = mydate.getDay();
	var month = mydate.getMonth();
	var daym = mydate.getDate();
	if (daym < 10)
		daym = "0" + daym;
	var hours = mydate.getHours();
	var minutes = mydate.getMinutes();
	var dn = "AM";
	if (hours >= 12) {
		dn = "PM";
		hours = hours - 12;
	}
	if (hours == 0)
		hours = 12;
	if (minutes <= 9)
		minutes = "0" + minutes;
	document.writeln(
	days[day]," de ",daym," de ",months[month]," de ",year);
}

function elmLoop(){
var resultado = "";
var theForm = document.forms[0]

   for(i=0; i<theForm.elements.length; i++){
   var alertText = ""
   //alertText += "Element Type: " + theForm.elements[i].type + "\n"
	alertText += theForm.elements[i].name+"(Element Type: " + theForm.elements[i].type + ")" + ":"

      if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "button"){
      alertText += "Element Value: " + theForm.elements[i].value + "\n"
      }
      else if(theForm.elements[i].type == "checkbox"){
      alertText += "Element Checked? " + theForm.elements[i].checked + "\n"
      }
      else if(theForm.elements[i].type == "radio"){
      	
      	alertText += "Element Checked? " + theForm.elements[i].checked + "\n" 
      }
      else if(theForm.elements[i].type == "select-one"){
      alertText += "Selected Option's Text: " + theForm.elements[i].options[theForm.elements[i].selectedIndex].text + "\n"
      }
   		resultado +=alertText;
   }
	alert(resultado);
}


function formToMail(){
var resultado = "";
var theForm = document.forms[0]

   for(i=0; i<theForm.elements.length; i++){
   var alertText = ""
   //alertText += "Element Type: " + theForm.elements[i].type + "\n"
	alertText += theForm.elements[i].name + ":"

      if(theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" ){
      alertText += theForm.elements[i].value + "\n"
      }
      else if(theForm.elements[i].type == "checkbox"){
      	if(theForm.elements[i].checked==true){
      		alertText += theForm.elements[i].value + "\n"		
      	}
      	else
      		alertText =""
      }
      else if(theForm.elements[i].type == "radio"){
      	if(theForm.elements[i].checked==true){
      		alertText += theForm.elements[i].value + "\n"		
      	}
      	else
      		alertText =""
      }
      else if(theForm.elements[i].type == "select-one"){
      alertText += + theForm.elements[i].options[theForm.elements[i].selectedIndex].text + "\n"
      }
   		resultado +=alertText;
   }
	//alert(resultado);
   	var mmsg = document.createElement("<input name='mmsg' type='hidden'>");
	mmsg = resultado;
	theForm.appendChild(mmsg);
	theForm.submit();
}





function do_focus(obj,str){
	if(obj.value == str)
		obj.value='';
}

function do_blur(obj,str){
	if(obj.value==''){
		obj.value = str;
	}
}

function tab_pesquisa(n){
	for(var i=1;i<=2;i++){
		$('pesquisa_body_'+i).style.display = (i==n) ? 'block' : 'none';
		$('pesquisa_tab_'+i).className = (i==n) ? 'selected' : '';
	}
}



/*FAVORITOS funciona ie e firfox*/
function favoris() {
if ( navigator.appName != 'Microsoft Internet Explorer' )
{ window.sidebar.addPanel("APA","http://apa.teleformar.net",""); }
else { window.external.AddFavorite("http://apa.teleformar.net","APA"); } } 



// Modal Image Box
// copyright 21st May 2006 by Stephen Chapman
// http://javascript.about.com/
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
/**/

function pageWidth() {return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;}

function pageHeight() {return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;}

function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset:document.documentElement && document.documentElement.scrollLeft? document.documentElement.scrollLeft:document.body.scrollLeft? document.body.scrollLeft:0;}

function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset:document.documentElement && document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop?document.body.scrollTop:0;}

function scrollFix(){var obol=$('ol');obol.style.top=posTop()+'px';obol.style.left=posLeft()+'px'}

function sizeFix(){var obol=$('ol');obol.style.height=pageHeight()+'px';obol.style.width=pageWidth()+'px';}

function kp(e){ky=e?e.which:event.keyCode;if(ky==88||ky==120)hm();return false}

function inf(h){tag=document.getElementsByTagName('select');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;tag=document.getElementsByTagName('iframe');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;tag=document.getElementsByTagName('object');for(i=tag.length-1;i>=0;i--)tag[i].style.visibility=h;}

function sm(obl){var h='hidden';var b='block';var p='px';var obol=$('ol');obol.style.height=pageHeight()+p;obol.style.width=pageWidth()+p;obol.style.top=posTop()+p;obol.style.left=posLeft()+p;obol.style.display=b;im=new Image();im.onload=function(){$('mbi').src=obl.href;var tp=posTop()+((pageHeight()-im.height)/2)-12;var lt=posLeft()+((pageWidth()-im.width)/2)-12;var obbx=$('mbox');obbx.style.top=(tp<0?0:tp)+p;obbx.style.left=(lt<0?0:lt)+p;$('mbd').style.width=im.width+p;inf(h);obbx.style.display=b;document.onkeypress=kp;return false};im.src=obl.href}

function hm(){var v='visible';var n='none';$('ol').style.display=n;$('mbox').style.display=n;inf(v);document.onkeypress=''}

function initmb(){var ab='absolute';var n='none';if(!document.getElementsByTagName)return;var anchors=document.getElementsByTagName('a');for(var i=0;i<anchors.length;i++){var an=anchors[i];if(an.getAttribute('href')&&/gif|jpe?g|png$/.test(an.getAttribute('href'))){an.onclick=function(){sm(this);return false}}}var obody=document.getElementsByTagName('body')[0];var frag=document.createDocumentFragment();var obol=document.createElement('div');obol.setAttribute('id','ol');obol.style.display=n;obol.style.position=ab;obol.style.top=0;obol.style.left=0;obol.style.zIndex=998;obol.style.width='100%';frag.appendChild(obol);var obbx=document.createElement('div');obbx.setAttribute('id','mbox');obbx.onclick=function(){hm();return false};obbx.style.display=n;obbx.style.position=ab;obbx.style.zIndex=999;var obl=document.createElement('span');obbx.appendChild(obl);var obbxd=document.createElement('div');obbxd.setAttribute('id','mbd');obl.appendChild(obbxd);var obmbm=document.createElement('div');obmbm.setAttribute('id','mbm');obmbm.innerHTML='X';obbxd.appendChild(obmbm);var obim=document.createElement('img');obim.setAttribute('id','mbi');obl.appendChild(obim);frag.insertBefore(obbx,obol.nextSibling);obody.insertBefore(frag,obody.firstChild);
window.onscroll = scrollFix; window.onresize = sizeFix;}

window.onload = initmb;
