var fo;
var divObj;
var divOver = false;
function initStatus() {
	fo = new flashMovie("Meteo");
	divObj = document.getElementById("topsearch");
	divObj.onmouseover = function() {
		divOver = true;
	}
	divObj.onmousemove = function() {
		divOver = true;
	}
	divObj.onmouseout = function() {
		divOver = false;
	}
	document.onmousemove = function() {
		if (!divOver) fo.set("mouseOutFlash","true");
	}
}
//
window.onload = function(){
	var topnavwrapper = findObj("topnavwrapper");
	var secondarynavwrapper1 = findObj("secondarynavwrapper1");
	var secondarynavwrapper2 = findObj("secondarynavwrapper2");
	var secondarynavwrapper3 = findObj("secondarynavwrapper3");
	var flashzone = findObj("flashzone");	
	if(flashzone!=null)flashzone.className = "jsenabled";

	if(String(document.all)!=="undefined"){
        if(topnavwrapper!=null)
            topnavwrapper.style.filter="alpha(opacity=60)";
        if(secondarynavwrapper1!=null)
            secondarynavwrapper1.style.filter="alpha(opacity=50)";
        if(secondarynavwrapper2!=null)   
            secondarynavwrapper2.style.filter="alpha(opacity=50)";
        if(secondarynavwrapper3!=null)   
            secondarynavwrapper3.style.filter="alpha(opacity=50)";
    } else {
        if(topnavwrapper!=null){
            topnavwrapper.style.opacity=0.6;
        }
        if(secondarynavwrapper1!=null){
            secondarynavwrapper1.style.opacity=0.5;
        }
        if(secondarynavwrapper2!=null){
            secondarynavwrapper2.style.opacity=0.5;
        }
        if(secondarynavwrapper3!=null){
            secondarynavwrapper3.style.opacity=0.5;
    }
  }
}

function preloadPage()
{
	if (document.getElementById) {  // DOM3 = IE5, NS6
		document.getElementById("preloader").style.visibility = "hidden";
	}
	else
	{
		if (document.layers) {  // Netscape 4
			document.preloader.visibility = "hidden";
		}
		else
		{  // IE 4
			document.all.preloader.style.visibility = "hidden";
		}
	}
}

var browser = new Browser();
var fader=null;

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.isFF    = false;  //firefox
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  
}

function getPageOffsetLeft(el) {
  var x;
  // Return the x coordinate of an element relative to the page.
  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);
  return x;
}

function getPageOffsetTop(el) {
  var y;
  // Return the x coordinate of an element relative to the page.
  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);
  return y;
}

function findObj(theObj, theDoc)
{
 var p, i, foundObj;

 if(!theDoc) theDoc = document;
 if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
 {
   theDoc = parent.frames[theObj.substring(p+1)].document;
   theObj = theObj.substring(0,p);
 }

 if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
 for (i=0; !foundObj && i < theDoc.forms.length; i++)
   foundObj = theDoc.forms[i][theObj];
 for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
   foundObj = findObj(theObj,theDoc.layers[i].document);
 if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

 return foundObj;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
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;  	
	if(a.length==1){
		var ma=a[0];
		if(ma.indexOf(",")!=-1){
			a=ma.split(",");
		}
	};
	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 showMapAlert()
{
	var frmObj = document.getElementById("alert");
    frmObj.style.top = getPageY()+200+"px";    
    frmObj.style.left = (document.body.offsetWidth-300)/2+"px";
	frmObj.style.visibility = "visible";
	frmObj.style.display = "block";
    INTERVAL_MILLIS=40;
    fader = new Fadomatic(frmObj, 30, 0);
    fader.show();
}

function hideMapAlert()
{
	if(fader)
        fader.fadeOut();
    else{
        var frmObj = document.getElementById("alert");
	    frmObj.style.visibility = "hidden";
	    frmObj.style.display = "none";
    }    
    	
}

function showMapViewer()
{
	var frmObj = document.getElementById("mapviewer");
	frmObj.style.visibility = "visible";
	frmObj.style.display = "block";
}

function hideMapViewer()
{
	var frmObj = document.getElementById("mapviewer");
	frmObj.style.visibility = "hidden";
	frmObj.style.display = "none";
    //hideMapAlert();
    var frmObj = document.getElementById("alert");
	frmObj.style.visibility = "hidden";
	frmObj.style.display = "none";
	
}

function showSubContent(cont,title)
{

	var content = document.getElementById(cont);
	var subtitle=document.getElementById("divsubsectiontitle");
	if(subtitle!=null)subtitle.innerHTML=title;
	hideSubContent();
	content.style.visibility = "visible";
	content.style.display = "block";

}

function hideSubContent()
{
	var converter = document.getElementById("converter");
	var comingfrom = document.getElementById("comingfrom");
	var comingto = document.getElementById("comingto");

	converter.style.visibility = "hidden";
	converter.style.display = "none";
	comingfrom.style.visibility = "hidden";
	comingfrom.style.display = "none";
	comingto.style.visibility = "hidden";
	comingto.style.display = "none";
}

function showSubContent2(cont,title)
{
	var content = document.getElementById(cont);
	var subtitle=document.getElementById("divsubsectiontitle");
	if(subtitle!=null)subtitle.innerHTML=title;
	
	hideSubContent2();
	content.style.visibility = "visible";
	content.style.display = "block";
}

function hideSubContent2()
{
	var transportation = document.getElementById("transportation");
	var usefulnumbers = document.getElementById("usefulnumbers");
	var tips = document.getElementById("tips");

	transportation.style.visibility = "hidden";
	transportation.style.display = "none";
	usefulnumbers.style.visibility = "hidden";
	usefulnumbers.style.display = "none";
	tips.style.visibility = "hidden";
	tips.style.display = "none";
}


function resetHighlight()
{
	var labels = document.getElementsByTagName('label');
	var inputs = document.getElementsByTagName('input');
	var selects = document.getElementsByTagName('select');
	var textareas = document.getElementsByTagName('textarea');

	for (i = 0; i < labels.length; i++)
	{
		if (labels[i].id.indexOf("lbl") != -1)
			labels[i].className = "";
	}
	for (i = 0; i < inputs.length; i++)
	{
		if (inputs[i].id.indexOf("txt") != -1)
			inputs[i].style.backgroundColor = "";
	}
	for (i = 0; i < selects.length; i++)
	{
		if (selects[i].id.indexOf("opt") != -1)
			selects[i].style.backgroundColor = "";
	}
	for (i = 0; i < textareas.length; i++)
	{
		if (textareas[i].id.indexOf("txt") != -1)
			textareas[i].style.backgroundColor = "";
	}
}

// form validation functions

function trim(str)
{
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function isBlank(str)
{
	if (trim(str) == "" ) 
		return true;
	return false;
}

function isEmail(s)
{
	if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,4}$/) != -1)
		return true;
	return false;
}

function Controle()
{
	if (document.frmNewsletter.chkDeny.checked)
	{
		document.frmNewsletter.chkAgree.checked = true;
		return true;
	}
	return true;
}
function Controle2()
{
	if (!document.frmNewsletter.chkAgree.checked)
	{
		document.frmNewsletter.chkDeny.checked = false;
		return true;
	}
	return true;
}

/* show/hide error */

function showError(formobj,err_str,err_div,input) {
	var x = getPageOffsetLeft(input);
	var y = getPageOffsetTop(input);
	var objCon = MM_findObj(err_div+"Content");
	var divObj = MM_findObj(err_div);
	if (objCon != null) {
		objCon.innerHTML="<p>"+err_str+"</p>";
	}
	if (divObj != null) {
		divObj.style.left = (x+4)+"px";
		divObj.style.top = y+20+"px";
		divObj.style.visibility = "visible";
	}
	
	if (browser.isIE) {
		var iframeObj = MM_findObj(err_div+"Iframe");
		if (iframeObj != null && divObj!=null) {
			iframeObj.style.width = divObj.offsetWidth+"px";
			iframeObj.style.height = divObj.offsetHeight+"px";
			iframeObj.style.left = divObj.style.left;
			iframeObj.style.top = divObj.style.top;
			iframeObj.style.visibility = "visible";
		}
	}
	//input.style.backgroundColor="#ebebeb";
	input.focus();
	return false;
}

function closeError(err_div) {
	var divObj=MM_findObj(err_div);
	if (divObj!=null) {
		divObj.style.visibility="hidden";
	}
	if (browser.isIE) {
		var iframeObj = MM_findObj(err_div+"Iframe");
		if (iframeObj!=null) {
			iframeObj.style.visibility="hidden";
		}
	}
}

function getElementsByBaseTagClass(base, tag, className) { 
    var classPat = new RegExp('\\b'+className+'\\b'); 
    var nodes = base.getElementsByTagName(tag); 
    var matching = []; 

    for (var i = 0; i < nodes.length; i++) { 
        if (classPat.test(nodes[i].className)) { 
            matching.push(nodes[i]); 
        } 
    } 
	return matching; 
}


function getPageY(){
	if(window.scrollY) return window.scrollY; // Mozilla
	if(window.pageYOffset) return window.pageYOffset; // Opera, NN4
	if(document.documentElement && document.documentElement.scrollTop){ // IE
		return document.documentElement.scrollTop;
	} else if(document.body && document.body.scrollTop){
		return document.body.scrollTop;
	}
	return 0;
}

function popUpload() {
	var maskObj = MM_findObj("containerMask");
	if (maskObj != null && maskObj.style) {
		maskObj.style.height = document.body.offsetHeight+"px";
		maskObj.style.visibility = "visible";
        maskObj.style.display = "block"; 
	}
}

function closePopup() {
	var maskObj = MM_findObj("containerMask");
	if (maskObj != null && maskObj.style) {
		maskObj.style.visibility = "hidden";
        maskObj.style.display = "none"; 
	}
}

function getPageOffsetTop(el) {
  var y;
  // Return the x coordinate of an element relative to the page.
  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);
  return y;
}
function initscroller() {
		//scrollablediv 1
		var scroller = new Bs_ScrollableDiv();         
		scroller.init('divContainer_1', 'divContent_1');
	  	var sliderObj = new Bs_Slider();
		sliderObj.width          = 11;
		sliderObj.height         = 400;		
		sliderObj.arrowMouseOver = false;
		sliderObj.direction      = 1;
		sliderObj.imgDir         = 'images/';
		sliderObj.setBackgroundImage('scroll_ln.gif', 'repeat');
		sliderObj.setSliderIcon('scroll_knob.gif', 11, 5);
		sliderObj.setArrowIconLeft("up_arrow.gif", 11, 10);//('scroll_up.gif', 11, 10);
		sliderObj.setArrowIconRight("down_arrow.gif",11, 10)//('scroll_dn.gif', 11, 10);
		
		scroller.setSliderObject(sliderObj, 'sliderDiv1');
        var speed=(browser.isNS)?6000:2000;
		scroller.setSlideSpeed(speed, 'pixel'); //50 pixel per second
		scroller.setWheelSpeed(10, 'pixel'); //10 pixel per tick
}

/*function getPageY(mY){	
	if(window.scrollY) window.scrollY=mY + "px"; // Mozilla
	if(window.pageYOffset) window.pageYOffset=mY + "px"; // Opera, NN4
	if(document.documentElement && document.documentElement.scrollTop){ // IE
		document.documentElement.scrollTop=mY + "px";
	} else if(document.body && document.body.scrollTop){
		document.body.scrollTop=mY + "px";
	}	
} */
function bodyOnload(){
	fomenufont.write("flashzone");
	fotopsearch.write("topsearch");	
	foMenuButton.write("menubutton");
	initStatus();
}