// JavaScript Document

function ajustuTrem() {

var postop = (getInsideWindowHeight() - 520) / 2;
var posleft = (getInsideWindowWidth() - 980) / 2;
if (postop < 0) { postop = 0; } 
if (posleft < 0) { posleft = 0; } 

setObjTop('conteudo',postop);
setObjLeft('conteudo',posleft);
setObjTop('resultado',postop+10);
setObjLeft('resultado',posleft);
setObjTop('resultado1',postop+10);
setObjLeft('resultado1',posleft);
setObjTop('resultado2',postop+10);
setObjLeft('resultado2',posleft);
setObjTop('resultado3',postop+10);
setObjLeft('resultado3',posleft);
setObjTop('resultado4',postop+10);
setObjLeft('resultado4',posleft);
setObjTop('resultado5',postop+10);
setObjLeft('resultado5',posleft);

show('conteudo')
//show('resultado')

}

//---------------------------

a1=new Image(187,28)
a1.src="imagens/menu1.png"
a2=new Image(187,28)
a2.src="imagens/menu1b.png"
a3=new Image(142,28)
a3.src="imagens/menu2.png"
a4=new Image(142,28)
a4.src="imagens/menu2b.png"
a5=new Image(156,28)
a5.src="imagens/menu3.png"
a6=new Image(156,28)
a6.src="imagens/menu3b.png"
a7=new Image(146,28)
a7.src="imagens/menu4.png"
a8=new Image(146,28)
a8.src="imagens/menu4b.png"
a9=new Image(68,21)
a9.src="imagens/rodape2g.png"
a10=new Image(68,21)
a10.src="imagens/rodape2gb.png"

function filter(img,objectsrc){
if (document.images)
document.images[img].src=eval(objectsrc+".src")
}

//---------------------------

function openNewWindow(local) {
  popupWin = window.open(local, 
    'open_window',
    'menubar,toolbar,location,directories,status,scrollbars,resizable,dependent,width=1020,height=580,left=0,top=0')
}

//---------------------------

var req;
 
function buscaRegs(modulo,submod) {
	if(window.XMLHttpRequest) {
	   req = new XMLHttpRequest();
	}
	else if(window.ActiveXObject) {
	   req = new ActiveXObject("Microsoft.XMLHTTP");
	}

	var url = "info.php?modulo="+modulo+"&submod="+submod;
	 
	req.open("Get", url, true); 
	req.onreadystatechange = function() {
		if(req.readyState == 4 && req.status == 200) {
			var resposta = req.responseText;
			switch (modulo) {
				case 1:
					switch (submod) {
						case 0:
						case 2:
						case 4:
						case 6:
						case 8:
							document.getElementById('resultado').innerHTML = resposta;
							break;
						case 1:
						case 3:
						case 5:
						case 7:
						case 9:
							document.getElementById('resultado1').innerHTML = resposta;
					}
					break;
				case 2:
					document.getElementById('resultado2').innerHTML = resposta;
					break;
				case 3:
					document.getElementById('resultado3').innerHTML = resposta;
					break;
				case 4:
					document.getElementById('resultado4').innerHTML = resposta;
					break;
				case 5:
					document.getElementById('resultado5').innerHTML = resposta;
			}
		}
	}
	req.send(null);
}

//----------------------------

function moveElementos() {
	new Effect.Move('logo', { x: 591, y: -204, mode: 'absolute' })
	new Effect.Move('img1', { x: 140, y: 0, mode: 'absolute' })
	new Effect.Move('img3', { x: 140, y: 0, mode: 'absolute' })
	new Effect.Move('img5', { x: 140, y: 0, mode: 'absolute' })
	new Effect.Move('img7', { x: 140, y: 0, mode: 'absolute' })
	new Effect.Move('img9', { x: 0, y: -135, mode: 'absolute' })
	new Effect.Move('riofloripa', { x: 802, y: 0, mode: 'absolute' })
}

function retornaElementos() {
	new Effect.Move('logo', { x: 0, y: 0, mode: 'absolute' })
	new Effect.Move('img1', { x: 0, y: 0, mode: 'absolute' })
	new Effect.Move('img3', { x: 0, y: 0, mode: 'absolute' })
	new Effect.Move('img5', { x: 0, y: 0, mode: 'absolute' })
	new Effect.Move('img7', { x: 0, y: 0, mode: 'absolute' })
	new Effect.Move('img9', { x: 0, y: 0, mode: 'absolute' })
	new Effect.Move('riofloripa', { x: 0, y: 0, mode: 'absolute' })
}

function altTamanho() {
	resizeImg(document.getElementById('logo'), 70)
	resizeImg(document.getElementById('img9'), 100)
}

//----------------------------

var resizeDelay = 10;
var resizeIncrement = 1;
var imgCache = new Object();

function getCacheTag (imgElement) {
	return imgElement.src + "~" + imgElement.offsetLeft + "~" + imgElement.offsetTop;
}

function cachedImg (imgElement, increment) {
	this.img = imgElement;
	this.cacheTag = getCacheTag(imgElement);
	this.originalSrc = imgElement.src;
	
	var h = imgElement.height;
	var w = imgElement.width;
	this.originalHeight = h;
	this.originalWidth = w;
	
	increment = (!increment) ? resizeIncrement : increment;
	this.heightIncrement = Math.ceil(Math.min(1, (h / w)) * increment);
	this.widthIncrement = Math.ceil(Math.min(1, (w / h)) * increment);
}

function resizeImg (imgElement, percentChange, newImageURL) {
	var pct = (percentChange) ? percentChange / 100 : 1;
	var cacheTag = imgElement.getAttribute("cacheTag");
	if (!cacheTag) {
		cacheTag = getCacheTag(imgElement);
		imgElement.setAttribute("cacheTag", cacheTag);
	}
	
	var cacheVal = imgCache[cacheTag];
	if (!cacheVal) {
		imgCache[cacheTag] = new Array(new cachedImg(imgElement), pct);
	} else {
		cacheVal[1] = pct;
	}
	
	if (newImageURL)
		imgElement.src = newImageURL;
	
	resizeImgLoop(cacheTag);
	return true;
}

function resizeImgLoop (cacheTag) {
	var cacheVal = imgCache[cacheTag];
	if (!cacheVal)
		return false;
	
	var cachedImageObj = cacheVal[0];
	var imgElement = cachedImageObj.img;
	var pct = cacheVal[1];
	var plusMinus = (pct > 1) ? 1 : -1;
	var hinc = plusMinus * cachedImageObj.heightIncrement;
	var vinc = plusMinus * cachedImageObj.widthIncrement;
	var startHeight = cachedImageObj.originalHeight;
	var startWidth = cachedImageObj.originalWidth;
	
	var currentHeight = imgElement.height;
	var currentWidth = imgElement.width;
	var endHeight = Math.round(startHeight * pct);
	var endWidth = Math.round(startWidth * pct);
	
	if ( (currentHeight == endHeight) || (currentWidth == endWidth) )
		return true;
	
	var newHeight = currentHeight + hinc;
	var newWidth = currentWidth + vinc;
	if (pct > 1) {
		if ((newHeight >= endHeight) || (newWidth >= endWidth)) {
			newHeight = endHeight;
			newWidth = endWidth;
		}
	} else {
		if ((newHeight <= endHeight) || (newWidth <= endWidth)) {
			newHeight = endHeight;
			newWidth = endWidth;
		}
	}
	
	imgElement.height = newHeight;
	imgElement.width = newWidth;
	
	if ((newHeight == cachedImageObj.originalHeight) || (newWidth == cachedImageObj.originalwidth)) {
		imgElement.src = cachedImageObj.originalSrc;
	}
	
	setTimeout("resizeImgLoop('" + cacheTag + "')", resizeDelay);
}

//------------------------------

/* Script by: www.jtricks.com 
* Version: 1.0 (20110615) 
* Latest version: 
* www.jtricks.com/javascript/blocks/ordering.html 
*/  
function getAbsoluteDivs() {  
  var arr = new Array();  
  var all_divs = document.body.getElementsByTagName("DIV");  
  var j = 0;  

  for (i = 0; i < all_divs.length; i++) {  
		if (all_divs.item(i).currentStyle)  
			 style = all_divs.item(i).currentStyle.position;  
		else  
			 style = window.getComputedStyle(  
			 all_divs.item(i), null).position;  

		if ('absolute' == style || 'relative' == style) {  
			 arr[j] = all_divs.item(i);  
			 j++;  
		}  
  }  
  return arr;  
}  

function bringToFront(id) {  
  if (!document.getElementById ||  
		!document.getElementsByTagName)  
		return;

  var obj = document.getElementById(id);  
  var divs = getAbsoluteDivs();  
  var max_index = 0;  
  var cur_index;  

  // Compute the maximal z-index of  
  // other absolute-positioned divs  
  for (i = 0; i < divs.length; i++) {  
		var item = divs[i];  
		if (item == obj ||  
			 item.style.zIndex == '')  
			 continue;  

		cur_index = parseInt(item.style.zIndex);  
		if (max_index < cur_index) {  
			 max_index = cur_index;  
		}  
  }  

  obj.style.zIndex = max_index + 1;  
}  

function sendToBack(id) {  
  if (!document.getElementById ||  
		!document.getElementsByTagName)  
		return;  

  var obj = document.getElementById(id);  
  var divs = getAbsoluteDivs();  
  var min_index = 999999;  
  var cur_index;  

  if (divs.length < 2)  
		return;  

  // Compute the minimal z-index of  
  // other absolute-positioned divs  
  for (i = 0; i < divs.length; i++) {  
		var item = divs[i];  
		if (item == obj)  
			 continue;  

		if (item.style.zIndex == '') {  
			 min_index = 0;  
			 break;  
		}

		cur_index = parseInt(item.style.zIndex);  
		if (min_index > cur_index) {  
			 min_index = cur_index;  
		}  

  }  

  if (min_index > parseInt(obj.style.zIndex)) {  
		return;
  }  

  obj.style.zIndex = 1;  

  if (min_index > 1)  
		return;  

  var add = min_index == 0 ? 2 : 1;  

  for (i = 0; i < divs.length; i++) {  
		var item = divs[i];  
		if (item == obj)  
			 continue;  

		item.style.zIndex += add;  
  }  
}

//----------------------------

function stringTrim(umaString) {
   stemp = umaString;
   while (stemp.charAt(0)==' ') {
      stemp = stemp.substring(1, stemp.length);
   }
   while (stemp.charAt(stemp.length-1)==' ') {
      stemp = stemp.substring(0, stemp.length-1);
   }
   return stemp;
}

function validaFormCad() {
 	valnome = stringTrim(document.formCad.nome.value);
 	valmsg = stringTrim(document.formCad.mensagem.value);
	document.formCad.nome.value = valnome;
	document.formCad.mensagem.value = valmsg;
	flagok = (valnome.length>0);
	flagok = (valmsg.length>0);
    return flagok;
}

function enviaFormCad() {
    if (validaFormCad()) {
	    document.formCad.submit();
		document.formCad.reset();
	} else {
	    alert('Erro de validação dos dados. Os campos com '*'  são de preenchimento obrigatório.');
		document.formCad.nome.focus();
	}
}
