function blockNone(whichLayer,what)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = what;
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = what;
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = what;
	}
}

function moveLayer(layer,x,y)
{
	lay = findObj(layer);
	if (lay)
	{
		style = lay.style;
		if (style)
		{
			style.left=x;
			style.top=y;
		}
	}
}

//logout screen and pop-ups
 function hideShowSelectElements(what)
 {
	 // args should be 'hidden' or 'visible'
 	if(document.getElementsByTagName)
 	{
 		var arrElements=document.getElementsByTagName('select');
 		for(var i=0;i<arrElements.length;i++)
 			arrElements[i].style.visibility=what;
 	}
 }
 
function logout()
{
	hideShowSelectElements('hidden');
	blockNone("fullTransparentDIV","block");
	blockNone("questionDIV","block");
}
function writeFullTransparentDiv() {
	var doc = document;
	doc.writeln('<div id="fullTransparentDIV" style="background-color:#e5e5e5;opacity: .5; DISPLAY: none; Z-INDEX: 1000; FILTER: alpha(opacity=70); VISIBILITY: visible; POSITION: absolute; -moz-opacity: .6; width: 100%; height: 100%; left: 0px; top: 0px;"></div>');
	}

function writeQuestionDiv()
{
	var doc = document;
	doc.writeln('<div id="questionDIV" style="width:305px;height:100px;display: none; left: 351px; top: 228px; Z-INDEX: 1001; POSITION: absolute;background-color:#ffffff;">');
	doc.writeln('<table width=\'100%\' height=\'100%\' style=\'border-color:#ffffff;border-width:3px;border-style:solid;background-color:#ff6500\'>');
	doc.writeln('<tr><td colspan=2 align=center style=\'color:#ffffff;font-weight:bold;\'>Do you really want to logout<br>from MarinERA extranet?</td></tr>');
	doc.writeln('<tr><td align=center><a href="/logout"><img src=\'/images/nav/yes.png\' border=0 alt=\'Yes\'></a></td><td align=center><a href=\'javascript:blockNone("fullTransparentDIV","none");javascript:blockNone("questionDIV","none");hideShowSelectElements("visible");\'><img src=\'/images/nav/no.png\' border=0 alt=\'No\'></a></td></tr>');
	doc.writeln('</table>');
	doc.writeln('</div>');
}
//END logout screen and pop-ups*/

function toggleLayer(whichLayer)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		var style2 = document.getElementById(whichLayer).style;
		style2.display = style2.display && style2.display=="block"?"none":"block";
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		var style2 = document.all[whichLayer].style;
		style2.display = style2.display && style2.display=="block"?"none":"block";
//		style2.display = style2.display? "":"block";
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		var style2 = document.layers[whichLayer].style;
		style2.display = style2.display && style2.display=="block"?"none":"block";
	}
}



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=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 preload(iarray)
{ 
  document.imageArray = new Array(iarray.length);
  for(var i=0; i<iarray.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = iarray[i];
  }
}

// Example: obj = findObj("image1");
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 doglow(dvn,cur)
{
	var g_nsteps = 10.0;
	var g_time_ms = 30;

	if(glowing!=dvn)
		return;

	dv=findObj(dvn);
	curop = 100 / g_nsteps *cur;
	
	imga = dv.getElementsByTagName("img");
	for(i=0;i<imga.length;i++)
	{
	imga[i].style["-moz-opacity"]=""+(curop/100.0)+"";
	imga[i].style.filter="alpha(opacity="+curop+")";
	imga[i].style.opacity=""+(curop/100.0)+"";
	}

	if(cur<g_nsteps)
		setTimeout("doglow(\""+dvn+"\","+(cur+1)+")",g_time_ms);
	else
		glowing = "";
}

function changeImgFade(imgname, imgsrc, curStep,rnd)
{
	if(!curStep)
	{
		curStep=0;
		rnd = Math.random();
		findObj(imgname).runningFade = rnd;
	}
	else 
		if(rnd != findObj(imgname).runningFade )
		{
			return;
		}
	
	//10 passos por imagem,
	stepsbyi = 30.0;
	g_time_ms = 10;
	
	toOn = curStep / stepsbyi > .5;
	curOpa = toOn? stepsbyi-curStep : curStep;
	curOpa = curOpa/(stepsbyi/2);
	
	curOpa = 1.0-curOpa;
	

	im = findObj(imgname);
	
	if(toOn)
		im.src = imgsrc;
	//window.status = curStep+"->"+curOpa;
	im.style["-moz-opacity"]=""+(curOpa)+"";
	im.style.filter="alpha(opacity="+(curOpa*100.0)+")";
	im.style.opacity=""+(curOpa)+"";
	curStep++;
	if(curStep<=stepsbyi)
		setTimeout("changeImgFade(\'"+imgname+"\',\'"+imgsrc+"\',"+curStep+","+rnd+")",g_time_ms);
}

function findPosX(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 findPosY(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 Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  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;
  }
}

var browser = new Browser();
