
/*=====================FUNÇAO LIGTHWINDOW BY GUILHERME HORVATICH======================*/

function $id() {
  var elements = new Array();
  var totArgs = arguments.length;
  for (var i = 0; i < totArgs; i++) {
    if (typeof arguments[i] == 'string') arguments[i] = document.getElementById(arguments[i]);
    if (arguments.length == 1) return arguments[i];
    elements.push(arguments[i]);
  }
  return elements;
}
function fsClass(){
    return function() {
      this.initialize.apply(this, arguments);
	}
}
var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}
function $tag(t){
	return document.getElementsByTagName(t);
}
// EVENT
function addEvent(object, eventType, doIt){
	if(object.addEventListener){ // ALL BROWSERS
		object.addEventListener(eventType, doIt, false); 
		return true;
	} else if (object.attachEvent){ // IE	
		var r = object.attachEvent('on'+eventType, doIt);
		return r;
	} else 	return false;
}
// ================
var $obj = {
	create: function(type, id, parentObj,formType){

		this.newObj = document.createElement(type);
		if(id) this.newObj.setAttribute('id',id);
		if(formType) this.newObj.type=formType;
		if(type=="form" || type=="iframe" || formType) if(id) this.newObj.setAttribute('name',id);
		
		parentObj.appendChild(this.newObj);
	},
	clone: function(orObj,cloneObj,cloneType){
		this.dimension = Array();
		this.position = Array();
		this.dimension = this.getDimension(orObj);
		this.position = this.getPos(orObj);
		$obj.create(cloneType,cloneObj,$tag("body").item(0));
		$id(cloneObj).style.position='absolute';
		$id(cloneObj).style.left=this.position[1]+"px";
		$id(cloneObj).style.top=this.position[0]+"px";
		$id(cloneObj).style.width=this.dimension[1]+"px";
		$id(cloneObj).style.height=this.dimension[0]+"px";
		$id(cloneObj).style.zIndex=999;
	},
	opacity: function(obj,value){
		var bsv = value/100; 
		$id(obj).style.opacity=bsv;
		$id(obj).style.MozOpacity=bsv;
		$id(obj).style.filter="alpha(opacity="+value+")";
	},
	getPos: function(obj){
		if($id(obj)){
			obj = $id(obj);
			var top=obj.offsetTop;
			objY=obj;
			while((objY=objY.offsetParent) != null) top+=objY.offsetTop;
			var left=obj.offsetLeft;
			objX=obj;
			while((objX=objX.offsetParent)!=null) left+=objX.offsetLeft;
			var position=Array(top,left);
			return position;
		} else return Array("ERROR:","Object '"+obj+"' not found");
	},
	getDimension: function(obj){
		if($id(obj)){
			obj = $id(obj);
			var height=obj.offsetHeight;
			var width=obj.offsetWidth;
			var dimension=Array(height,width);
			return dimension;
		} else return Array("ERROR:","Object '"+obj+"' not found");
	}
}

// BELLOW HERE WILL BE IN SEPARETED FILES IN FUTURE

// FORM VALIDATION
var validation = {
	Email: function(mail){
		var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
		if(typeof(mail) == "string"){
			if(er.test(mail)) return true;
		}else if(typeof(mail) == "object"){
			if(er.test(mail.value)){
				return true;
			}
		}else return false;
	}
}
// EFFECTS

var effects = {
	colorMask: function(color, obj, objOpacity){
		if(!$id("fsMask")) $obj.clone("imagem","fsMask","div");
		$id("fsMask").style.background=color;
		$obj.opacity("fsMask",objOpacity);		
	},
	fade: function(color, obj, from, to, func, nowOpacity){
		from = (!from)?0:from;
		to = (!to)?0:to;
		color = (!color)?null:color=="null"?null:color;
		
		nowOpacity = (!nowOpacity)?from:nowOpacity;
		
		if(!color) $obj.opacity(obj,nowOpacity);
		else this.colorMask(color,obj,nowOpacity);
		if(from>=to){			
			if(nowOpacity>to){
				nowOpacity-=10;
				setTimeout("effects.fade('"+color+"','"+obj+"',"+from+","+to+",'"+func+"','"+nowOpacity+"')",5);
			} else if(func) eval(func);
		} else {
			if(nowOpacity<to){
				nowOpacity+=10;
				setTimeout("effects.fade('"+color+"','"+obj+"',"+from+","+to+",'"+func+"',"+nowOpacity+")",10);
			}else if(func) eval(func);
		}
	}
}



// ==================================================
function fechaImp(){
	
	history.go(0);
	/*$id('janela_impressao').style.display="none"; 
	$id('fImp').style.display="none"; */
}
function janelaImpressao(){
	var objBody = $tag("body").item(0);

	//=============================================
	// CRIA DIV "fImp" - Fundo pra area de impressao ter destaque
	$obj.create("div","fImp",objBody);
	$id("fImp").style.display="none";
	
	//=============================================
	// CRIA DIV "janela_impressao" - Janela onde mostrara a area a ser impressa
	$obj.create("div","janela_impressao",objBody);
	$id("janela_impressao").style.display = "none";	
	
	//=============================================
	// CRIA DIV "topo_janela" - Topo da Janela
	
	$obj.create("div","topo_janela",$id("janela_impressao"));
	
	//=============================================	
	// CRIA FORM
	$obj.create("form","form_impressao",$id("topo_janela"));

	//=============================================	
	// CRIA H1 "TITULO" - TITULO DA JANELA

	//=============================================	
	// CRIA INPUT "fechaJanela"
	$obj.create("input","fechaJanela",$id("form_impressao"),"button");
	
	/*$id("fechaJanela").setAttribute('value','');*/
	$id("fechaJanela").setAttribute('type','button');
	$id("fechaJanela").setAttribute('className','button');
	
	/*
	$obj.create("input","fechaJanela",$id("form_impressao"),"image");
	$id("fechaJanela").setAttribute('src','http://www.assefaz.org.br/portal/img/btn_fechar_div.gif');
	$id("fechaJanela").setAttribute('type','image');
	$id("fechaJanela").setAttribute('className','button');
	*/
	
	if(/Internet Explorer/.test(navigator.appName)){ // IE sempre ele
		$id("fechaJanela").setAttribute('onclick',fechaImp);
		$id("fechaJanela").setAttribute('className','button');
	}else{ 
		$id("fechaJanela").setAttribute('onclick',"fechaImp()");
		$id("fechaJanela").setAttribute('class','button');
	}
	

}
function imprime(cont){
	
	

	
	// jogamos a tela pro topo
	scrollTo(0,0);
	
	telaH = document.body.offsetHeight;
	navH = document.documentElement.clientHeight;
	
	if(navH>telaH)
		telaH=navH;
	telaH+= "px";
	$id("fImp").style.height = telaH;
	
	$id("fImp").style.display='block';
	$id("janela_impressao").style.display='block';
	effects.fade(null,"janela_impressao", 999,999);
	

	//=============================================	
	// CRIA IFRAME "conteudo_impressao" - CONTEUDO
	$obj.create("iframe","conteudo_impressao",$id("janela_impressao"));
	$id("conteudo_impressao").setAttribute('src',cont);
 
	//=============================================	
}

addEvent(window,"load",janelaImpressao);

/*=========================FIM FUNÇÃO===========================*/