// JavaScript Document
jQuery.noConflict();
 
jQuery(document).ready(function(){
	//modal();
	jQuery('.modal').nyroModal();
});

function ValidaFormBusca() {
	  if ((frmBusca.txtBusca.value.length)<6){
		erro_busca.innerHTML = 'Por favor, digite no mínimo 6 caracteres.';
		return false;
   }
	return true;
}


function abre(elem){
	estado = document.getElementById(elem);
	seta_div = 'setaDivSegmento' + elem.replace('divSegmento','');
	try{
		if (estado.style.display == '') {
			estado.style.display = 'none';
			document.getElementById(seta_div).className = 'listaSetaAzulFecha linkazul';
		}else{
			estado.style.display = '';
			document.getElementById(seta_div).className = 'listaSetaAzulAbre linkazul';
		}
		alert(document.style.display);
	}catch(e){
		erro = 'sim';
	}
}

// Topo Regionais
function sebraeRs(){
				var obj = document.getElementById('selecioneRegiao').value;
				var TxtAlert = document.getElementById('TxtAlert');
				if(obj != 'NULL')
					document.location.href = '../_default.asp?Secao=SebraeRS&IdRegistro='+obj;
				else
					TxtAlert.InnerHTML = 'OK';
			}
			
modal_zindex = 9999;

function modal() {
	jQuery(".modal").bind('click', function() {

		if (jQuery('#modal').length == 0) { // if the div doesn't exist yet
			// you know, it must be on the top
			jQuery(this).parent('div').css('z-index',modal_zindex++);
			jQuery(this).parent('li').css('z-index',modal_zindex++);

			// get the image path
			var src = jQuery(this).attr('href');
			var src = '../files/'+src.split('files')[1];
			
			var parent_class = jQuery(this).parent().attr('class'); // for aligment stuff
			
			// legend stuff
			var alt = jQuery(this).find('img').attr('alt')+"";
			var alt = alt.split('|')
			
			var legenda = (alt[0]=='undefined' || !alt[0]) ? '' : alt[0];
			var credito = (alt[1]=='undefined' || !alt[1]) ? '' : alt[1];

			// let's make its structure
			var code = '<div id="modal" class="'+parent_class+'">';
			code = code+'<img id="large" src="'+src+'" alt="Imagem ampliada" />';
			code = code+'<small>'+legenda+' <span>'+credito+'</span></small>';
			code = code+'<a id="close" href="javascript:modalClose()" title="Fechar">Fechar</a>';
			code = code+'</div>';
			
			// append and show it!
			jQuery(this).parent().append(code);
			jQuery("#modal").css("display",'none').fadeIn();

		} else {
			modalClose();
		}
		return false;
	});	
}


function modalClose() {
	jQuery("#modal").remove();
}



function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setIframeHeight(conteudoiframe) {
  var iframeWin = window.frames[conteudoiframe];
  var iframeEl = document.getElementById? document.getElementById(conteudoiframe): document.all? document.all[conteudoiframe]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
    var docHt = getDocHeight(iframeWin.document);
    // need to add to height to be sure it will all show
    if (docHt) iframeEl.style.height = docHt + 30 + "px";
  }
}

function loadIframe(conteudoiframe, url) {
  if ( window.frames[conteudoiframe] ) {
    window.frames[conteudoiframe].location = url;   
    return false;
  }
  else return true;
}

var fraObj;
var iframeids=["iframe_informativo"]

function startdyncode(){
dyniframesize()
}

function dyniframesize() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById){ //begin resizing iframe procedure
dyniframe[dyniframe.length] = document.getElementById(iframeids[i]);
if (dyniframe[i] && !window.opera){
dyniframe[i].style.display="block"
if (dyniframe[i].contentDocument && dyniframe[i].contentDocument.body.offsetHeight) //ns6 syntax
dyniframe[i].height = dyniframe[i].contentDocument.body.offsetHeight; 
else if (dyniframe[i].Document && dyniframe[i].Document.body.scrollHeight) //ie5+ syntax
dyniframe[i].height = dyniframe[i].Document.body.scrollHeight;
}
}
}
}


if (window.addEventListener) {
	window.addEventListener("load", startdyncode, false);
	window.addEventListener("resize", startdyncode, false); 
} else if (window.attachEvent) {
	window.attachEvent("onload", startdyncode);
	window.attachEvent("onResize", startdyncode); 
}
