// InterDyn
// Copyright 2002-2007 JP7
// http://jp7.com.br
// Versão 1.32 - 2007/08/15 by JP


d=document
onresizeArr=new Array()

onresize=function(){
	for(var i=0;i<onresizeArr.length;i++){
		eval(onresizeArr[i])
	}
}


// Basics

String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g,'')}

// Array.indexOf( value, begin, strict ) - Return index of the first element that matches value
function array_indexOf(array, v, b, s ) {
 for( var i = +b || 0, l = array.length; i < l; i++ ) {
  if( array[i]===v || s && array[i]==v ) { return i; }
 }
 return -1;
};

function isDef(S){return(eval('typeof('+S+')')!='undefined'&&eval('typeof('+S+')')!='unknown')}

function getElm(id){return (is.ie4)?d.all[id]:d.getElementById(id)}

function getElmPos(elm){
	getElmPos.l=elm.offsetLeft
	getElmPos.t=elm.offsetTop
	while(elm=elm.offsetParent){
		getElmPos.l+=elm.offsetLeft
		getElmPos.t+=elm.offsetTop
	}
	/*
	while(elm.offsetParent){
		getElmPos.l+=elm.offsetLeft
		getElmPos.t+=elm.offsetTop
		elm=elm.offsetParent
	}
	*/
	return getElmPos
}

function toId(S){
	S=S.replace(/[áàãâäÁÀÃÂÄª]/g,'a')
	S=S.replace(/[éèêëÉÈÊË&]/g,'e')
	S=S.replace(/[íìîïÍÌÎÏ]/g,'i')
	S=S.replace(/[óòõôöÓÒÕÔÖº]/g,'o')
	S=S.replace(/[úùûüÚÙÛÜ]/g,'u')
	S=S.replace(/[çÇ]/g,'c')
	S=S.replace(/[ñ]/g,'n')
	S=S.replace(/[^\d\w]/g,'')
	S=S.toLowerCase()
	/*
	var S=S.toLowerCase()
	S=S.replace(/[áàãâä]/g,'a')
	S=S.replace(/[éèêë&]/g,'e')
	S=S.replace(/[íìîï]/g,'i')
	S=S.replace(/[óòõôö]/g,'o')
	S=S.replace(/[úùûü]/g,'u')
	S=S.replace(/[ç]/g,'c')
	for(var i=0;i<S.length;i++){if(' _0123456789abcdefghijklmnopqrstuvwxyz'.indexOf(S.charAt(i))==-1)S=S.replace(S.charAt(i),' ')}
	S=S.replace(/[ ]/g,'')
	S=S.replace(/[.]/g,'')
	*/
	return S
}

// 2007/08/15
function getStyle(el,styleProp){
	var x=document.getElementById(el);
	if(x.currentStyle){
		if(styleProp.indexOf('-')!=-1){
			styleProp=styleProp.split('-')
			styleProp=styleProp[0]+styleProp[1].charAt(0).toUpperCase()+styleProp[1].substring(1)
		}
		var y=x.currentStyle[styleProp];
	}else if(window.getComputedStyle)var y=document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

String.prototype.toXHTML=function(){
	var addAttrQt=/\s*=\s*['"]?([^ '">]+)['"]?/gi
	var fixSingletTag=/<(img|input|br|hr)([^>]*)>/gi
	var fixSingletAttr=/((checked)|(selected)|(disabled))/gi
	return this.replace(addAttrQt,'="$1"').replace(fixSingletAttr,'$1="$1"').replace(fixSingletTag,'<$1$2/>')
}

function openPopup(url,tit,w,h,other,c){
	url=url.replace(/[ ]/g,'%20')
	var l=(c)?(screen.availWidth-w)/2:18
	var t=(c)?(screen.availHeight-h)/2:18
	var popup=window.open(url,tit||'popup_'+toId(url),'left='+l+',top='+t+',width='+w+',height='+h+',scrollbars=1'+((other)?','+other:''))
	other=other||''
	if(is.ie&&other.indexOf('fullscreen')!=-1){popup.moveTo(0,0);popup.resizeTo(screen.width,screen.height)}
	var antipopup=true
	if(popup){
		if(!popup.closed){
			popup.focus()
			antipopup=false
		}
	}
	//if(antipopup)window.open(url)
	//return popup
}

function resizeWindow(obj){
	resizeTo(400,400)
	if(is.ie){
		var width=(screen.width<obj.offsetWidth)?screen.width:obj.offsetWidth
		width=400-d.body.clientWidth+width
		var height=(screen.height<obj.offsetHeight)?screen.height:obj.offsetHeight
		height=400-d.body.clientHeight+height
		resizeTo(width,height)
	}else{
		window.innerWidth=obj.offsetWidth
		window.innerHeight=obj.offsetHeight
	}
}

function openBlank(url){window.open(url)}

function checkBrowser(){
	T=this
	b=navigator.appName
	v=navigator.appVersion
	u=navigator.userAgent
	if(b=='Netscape')T.b='ns'
	else if(b=='Microsoft Internet Explorer')T.b='ie'
	else T.b=b
	T.v=parseInt(v)
	T.ns=(T.b=='ns'&&T.v>=4)
	T.ns5=(T.b=='ns'&&T.v==5)
	T.ns6=(T.b=='ns'&&T.v==5)
	T.ie=(T.b=='ie'&&T.v>=4)
	T.ie4=(u.indexOf('MSIE 4')>0)
	T.ie5=(u.indexOf('MSIE 5.0')>0)
	T.ie55=(u.indexOf('MSIE 5.5')>0)
	T.ie6=(u.indexOf('MSIE 6.0')>0)
	T.ie7=(u.indexOf('MSIE 7.0')>0)
	T.ie8=(u.indexOf('MSIE 8.0')>0)
	if(T.ie5)T.v=5
	if(T.ie55)T.v=5.5
	if(T.ie6)T.v=6
	if(T.ie7)T.v=7
	if(T.ie8)T.v=8
	T.mo=(u.indexOf('Mozilla/5.0')==0)
	T.sa=(u.indexOf('Safari')>0)
	T.min=(T.ns||T.ie||T.sa)
	T.dom=(T.v>=5)
	T.win=(u.indexOf('Win')>0)
	T.mac=(u.indexOf('Mac')>0)
	T.osx=(u.indexOf('Mac OS X')>0||u.indexOf('MSIE 5.2')>0)
}
is=new checkBrowser()


// Page Dimensions

function docW(){return(is.ie)?d.body.scrollWidth:d.documentElement.scrollWidth}
function docH(){return(is.ie)?d.body.scrollHeight:d.documentElement.scrollHeight}
function winW(){
	if(is.ie){
		var R=d.documentElement.clientWidth
		if(!R)R=d.body.clientWidth
		return R
	}else return window.innerWidth
}
function winH(){
	if(is.ie){
		var R=d.documentElement.clientHeight
		if(!R)R=d.body.clientHeight
		return R
	}else return window.innerHeight
}

/**
 * Verifica altura e largura da janela (incluindo bordas e barras) e a redimensiona para tamanho desejado. 
 *
 * @param int newW Se for fornecido, a janela será redimensionada para essa largura.
 * @param int newH Se for fornecido, a janela será redimensionada para essa altura.
 * @return Object Objeto com propriedades 'h' e 'w', para altura e largura, respectivamente.
 */
function winSize(newW, newH){
	if (is.ie) {
		wW = cW = document.body.offsetWidth;
		wH = cH = document.body.offsetHeight;
		resizeTo(cW, cH);
		cW = document.body.offsetWidth;
		cH = document.body.offsetHeight;
		obj = {h: 2 * wH - cH, w: 2 * wW - cW}
	} else obj = {h: window.outerHeight, w: window.outerWidth};
	if (is.ie || newW || newH) window.resizeTo((newW) ? newW : obj['w'], (newH) ? newH : obj['h']);
	return obj;
}

// Images

function pI(src){
	obj=src.substring(src.lastIndexOf('/')+1,src.lastIndexOf('.'))
	eval(obj+'=new Image()')
	eval(obj+'.src="'+src+'"')
}

function cI(id,obj,lyr){
	id='d.images[\''+id+'\']'
	if(isDef(id)&&isDef(obj))eval(id).src=eval(obj).src
}


// Flash

function flash_DoFSCommand(command,args){eval(command+'("'+args+'")')}


// Layers

// newLyr (2008/02/21)
function newLyr(id,l,t,w,h,ct,z,v,bg,n,makeDL,className){
	if(n){
		index=n.lastIndexOf(".")
		var nestlyr=(index!=-1)?n.substr(index+1):n
	}
	if(is.dom){
		lyr=d.createElement('DIV')
		lyrS=lyr.style
		lyrS.position='absolute'
		lyrS.left=l+'px'
		lyrS.top=t+'px'
		if(w)lyrS.width=w+'px'
		if(h)lyrS.height=h+'px'
		else if(is.ie&&is.mac)lyrS.height='none'
		if(z)lyrS.zIndex=z
		if(v)lyrS.visibility=v
		if(bg)lyrS.backgroundColor=bg
		if(ct)lyr.innerHTML=ct+((is.ie&&is.mac)?'<span></span>':'')
		lyr.id=id
		if(className)lyr.className=className
		if(n)d.getElementById(nestlyr).appendChild(lyr)
		else d.body.appendChild(lyr)
	}
	else{
		var S='\n<DIV id='+id+' style="position:absolute;left:'+l+';top:'+t
		if(w)S+=';width:'+w
		else S+=';width:1'
		if(h!=null)S+=';height:'+h
		if(z!=null)S+=';z-index:'+z
		if(v)S+=';visibility:'+v
		if(bg!=null)S+=';background:'+bg
		S+='">'+((ct)?ct:'')+'</DIV>'
		if(n)d.all[nestlyr].insertAdjacentHTML("BeforeEnd",S)
		else d.body.insertAdjacentHTML("BeforeEnd",S)
	}
	if(makeDL){eval(((id.lastIndexOf('Div'))?id.substring(0,id.lastIndexOf('Div')):id)+'DL=new DL(\''+id+'\''+((n)?',\''+n+'\'':'')+')')}
}


// Objects Constructor

var DOA=new Array()
function DO(parent){this.arguments=(DO.caller)?DO.caller.arguments:newDO.arguments;this.newDO=newDO;this.parent=parent;this.itens=new Array()}
function newDO(){return (this.itens)?this.itens[this.itens.length]=new DO(this):DOA[DOA.length]=new DO()}


// DynLayer
// Copyright 1999 Dan Steinman
// http://www.dansteinman.com/dynapi/

// DL (2006/06/13)
function DL(id,n1,n2){
	var T=this
	T.elm=T.event=(is.ie4)?d.all[id]:d.getElementById(id)
	T.css=T.elm.style
	T.doc=document
	T.l=T.elm.offsetLeft
	T.t=T.elm.offsetTop
	T.w=T.elm.offsetWidth
	T.h=T.elm.offsetHeight
	if(!T.w)T.w=T.css.pixelWidth
	if(!T.h)T.h=T.css.pixelHeight
	T.obj=((id.lastIndexOf('Div'))?id.substring(0,id.lastIndexOf('Div')):id)+'DL'
	T.sh=DLsh
	T.hd=DLhd
	T.mTo=DLmTo
	T.mBy=DLmBy
	T.rTo=DLrTo
	T.rBy=DLrBy
	T.write=DLwrite
}

function DLsh(){this.css.visibility='visible'}
function DLhd(){this.css.visibility='hidden'}

function DLmTo(l,t){
	if(l!=null){
		this.l=l
		if(!is.ie)this.css.left=this.l+'px'
		else this.css.pixelLeft=this.l
	}
	if(t!=null){
		this.t=t
		if(!is.ie)this.css.top=this.t+'px'
		else this.css.pixelTop=this.t
	}
}
function DLmBy(l,t){this.mTo(this.l+l,this.t+t)}

function DLrTo(w,h){
	if(w!=null){
		this.w=w
		this.css.width=this.w
	}
	if(h!=null){
		this.h=h
		this.css.height=this.h
	}
}
function DLrBy(w,h){this.rTo(this.w+w,this.h+h)}

function DLwrite(S){this.elm.innerHTML=S}


// Cookie Functions
// Copyright 1999 Dan Steinman
// http://www.dansteinman.com/dynapi/

function saveCookie(name,value,days) {
	if(days){
		var date=new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000))
		var expires='; expires='+date.toGMTString()
	}
	else expires=''
	d.cookie=name+'='+value+expires+'; path=/'
}

function readCookie(name) {
	var nameEQ=name+'='
	var ca=d.cookie.split(';')
	for(var i=0;i<ca.length;i++){
		var c=ca[i];
		while(c.charAt(0)==' ')c=c.substring(1,c.length)
		if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length)
	}
	return null
}

function deleteCookie(name){saveCookie(name,'',-1)}


// Sites Functions

// 2008/01/30 by JP
function jp7_changeLang(newLang){
	// Check newLang
	if(!newLang)newLang=(lang=='pt-br')?'en':'pt-br';
	oldLang=lang.replace('pt-br','site');
	newLang=newLang.replace('pt-br','site');
	// Check and Parser Querystring
	var oldLocation=location.toString();
	var query_i=oldLocation.indexOf('?');
	if(query_i!=-1){
		oldLocation=oldLocation.substring(0,query_i+1);
		var queries=location.search;
		queries=queries.substr(1);
		queries=queries.split('&');
		var query_key_id=null;
		var query_attribute=null;
		for(var query_key in queries){
			query_attribute=queries[query_key].split('=');
			if(query_attribute[0]=='id')query_key_id=query_key;
		}
		// Check and Replace "id" with "id_tipo"
		if(query_key_id!==null)queries[query_key_id]='id_tipo='+tipos[tipos.length-1];
		queries=queries.join('&');
	}
	// Mount newLocation
	var newLocation=oldLocation.replace('/'+oldLang,'/'+newLang)
	if(newLocation==oldLocation)newLocation='http://'+location.host+'/'+path+newLang+'/'
	location.replace(newLocation+((queries)?queries:''))
}

function jp7_file_view(url){
	if(!jp7_file_download_click)openPopup(url,site+'_fileview_popup',640,480,'resizable=1')
}

var jp7_file_download_click=false
function jp7_file_download(url,file_name){
	jp7_file_download_click=true
	location='../_templates/download.php?url='+url+'&file_name='+file_name
	setTimeout('jp7_file_download_click=false',0)
}

function jp7_album(id,id_arquivo,parte,thumbs,w,h,id_tipo){
	if(!thumbs){
		w=100
		h=100
	}
	openPopup('../../site/_templates/album'+((thumbs)?'_frameset':'')+'.php?lang='+lang+'&id='+id+'&id_arquivo='+id_arquivo+((parte)?'&parte='+parte:'')+((thumbs)?'&thumbs=true':'')+((id_tipo)?'&id_tipo='+id_tipo:''),site+'_album',w,h,(thumbs)?' resizable=1':'')
}

function jp7_album_dhtml(id,id_arquivo,parte,thumbs,w,h,url){
	openPopup(((url)?url:'../_templates/album.php')+'?height='+h+'&id='+id+'&id_arquivo='+id_arquivo+((parte)?'&parte='+parte:'')+((thumbs)?'&thumbs=1':'&thumbs=0'),site+'_album',w,h,'resizable=0,status=1')
}

function jp7_popup_img(url){
	openPopup('http://'+location.host+'/'+path+((lang!='pt-br')?lang:'site')+'/_default/popup_img.php?url='+url,'popup_img',200,200)
}

function jp7_popup_video(url,w,h){
	openPopup('http://'+location.host+'/'+path+((lang!='pt-br')?lang:'site')+'/_default/popup_video.php?url='+url+'&width='+w+'&height='+h,'popup_img',w,h)
}

// 2007/08/15 by JP
function jp7_parseInt(S){
	S=parseInt(S,10)
	return (isNaN(S))?0:S
}

// 2007/08/15 by Thiago
function jp7_footer_repos(plus){
	if(getElm('footer')){
		if(plus){
			var masterPadding=jp7_parseInt(getStyle('master','padding-top'),10)+jp7_parseInt(getStyle('master','padding-bottom'),10)
			var footerMargin=jp7_parseInt(getStyle('footer','margin-top'),10)+jp7_parseInt(getStyle('footer','margin-bottom'),10)
			var footerHeight=getElm('footer').offsetHeight
			var repos=winH()-(masterPadding+footerMargin+footerHeight)
			if (repos>0) getElm('master').style[(is.ie&&is.v<7) ? 'height' : 'minHeight'] = repos + 'px';
		}else if(winH()>docH()){
			getElm('footer').style.top=winH()-docH()+'px'
		}
		getElm('footer').style.visibility='visible'
		if(array_indexOf(onresizeArr,'jp7_footer_repos('+plus+')')==-1)onresizeArr[onresizeArr.length]='jp7_footer_repos('+plus+')'
	}
}

// 2008/01/29 by JP
function jp7_date_combo(name,date,year_start,year_end,text_month,simpleReturn,xtra){
	var partes=new Array('Dia','Mês','Ano','Hora','Min.')
	var partes_letra=new Array('d','m','Y','H','i')
	var partes_start=new Array(1,1,(year_start)?year_start:1900,0,0)
	var partes_end=new Array(31,12,(year_end)?year_end:2010,23,59)
	var meses=new Array('Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez')
	var S='<input type="hidden" name="'+name+'" value="'+date+'">'
	var ii=3
	if(date){
		if(date.indexOf(':')!=-1){
			date=date.split(' ')
			date[0]=date[0].split('-').reverse()
			date[1]=date[1].replace(/[:]/g,'-')
			date=date[0].join('-')+'-'+date[1]
			date=date.split('-')
			ii=5
		}else date=date.split('-').reverse()
	}
	for(var i=0;i<ii;i++){
		S+=''+
		'<select'+((!simpleReturn)?' name="'+name+'_'+partes_letra[i]+'"':'')+' id="'+name+'_'+partes_letra[i]+'" label="'+partes[i]+'" onchange="if(value)form[\''+name+'\'].value=form[\''+name+'_Y\'].value+\'-\'+form[\''+name+'_m\'].value+\'-\'+form[\''+name+'_d\'].value"'+((xtra)?' '+xtra:'')+'>'+
			'<option value="">'+partes[i]+'</option>'+
			'<option value="">---</option>'
			for(var j=partes_start[i];j<=partes_end[i];j++){
				text=(text_month&&partes[i]=='Mês')?meses[j-1]:((j<10)?'0':'')+j
				S+='<option value="'+((j<10)?'0'+j:j)+'"'+((date&&j==date[i])?' selected':'')+'>'+text+'</option>'
			}
		S+='</select>'
		if(i<2)S+='&nbsp;/&nbsp;'
		else if(ii==5){
			if(i==2)S+='&nbsp;-&nbsp;'
			else if(i<4)S+='&nbsp;:&nbsp;'
		}
		if(i==(ii-1))S+='<br />'
	}
	d.write(S)
}

function jp7_num_combo(start,end,selected,zero){
	var S=''
	for(var i=start;i<=end;i++){
		S+='<option value="'+i+'"'+((i==selected)?' selected':'')+'>'+((zero&&i<10)?'0':'')+i+'</option>'
	}
	d.write(S)
}

// 2006/10/02
function jp7_nextSibling(obj){
	return obj.nextSibling
}


// AJAX

// 2006/06/12 by JP
function ajax_xmlhttp(){
	var xmlhttp
	if(window.XMLHttpRequest){
		try{xmlhttp=new XMLHttpRequest()}
		catch(e){xmlhttp=false}
	}else if(window.ActiveXObject){
		try{xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")}
		catch(e){
			try{xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")}
			catch(e){xmlhttp=false}
		}
	}
	return xmlhttp
}

// 2007/06/22 by JP
function ajax_function(obj,xml,func){
	var ajax
	if(ajax=ajax_xmlhttp()){
		var myrequest=xml
		ajax.open('GET',myrequest,true)
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				func((getElm(obj))?getElm(obj):obj,ajax.responseXML,ajax.status==200&&ajax.responseText.indexOf('invalid')==-1)
			}
		}
		ajax.send(null)
		delete ajax
	}
}


// PNG Fix

function png_check(){
	// Check Browser
	if (!is.ie||is.v>=7)return
	var tagsArray=new Array('BODY','DIV','IMG','TABLE','TR','TD','INPUT')
	for(var i=0;i<tagsArray.length;i++){
		var tags=document.getElementsByTagName(tagsArray[i])
		for(var j=0;j<tags.length;j++){
			png_fix(tags[j])
		}
	}
}

function png_filter(obj,s,m){
	var f='DXImageTransform.Microsoft.AlphaImageLoader'
	if(obj.filters[f]){
		obj.filters[f].enabled=(s)?true:false
		if(s){
			with(obj.filters[f]){
				src=s
				sizingMethod=m
			}
		}
	}else if(s)obj.style.filter='progid:'+f+'(src="'+s+'",sizingMethod="'+m+'")'
	obj.currentPNG=s
}

function png_fix(obj){
	// Check Current PNG
	var bgImg=obj.currentStyle.backgroundImage
	if(bgImg.indexOf(obj.currentPNG)!=-1)return
	// DO
	var blankImg='/_default/img/px.gif'
	if(bgImg&&bgImg!='none'){
		if(bgImg.match(/^url[("']+(.*\.png)[)"']+$/i)){
			var s=RegExp.$1;
			if(obj.currentStyle.width=='auto'&&obj.currentStyle.height=='auto')obj.style.width=obj.offsetWidth+'px'
			obj.style.backgroundPosition='10000px 10000px'
			png_filter(obj,s,'crop');
			//png_filter(obj,s,'scale');
			// IE link fix.
			for(var n=0;n<obj.childNodes.length;n++){
				if(obj.childNodes[n].style)obj.childNodes[n].style.position='relative'
			}
  	}else png_filter(obj);
	}else if(obj.tagName=='IMG'){
		if((/\.png$/i).test(obj.src)){
			if(obj.currentStyle.width=='auto')obj.style.width=obj.offsetWidth+'px'
			if(obj.currentStyle.height=='auto')obj.style.height=obj.offsetHeight+'px'
			png_filter(obj,obj.src,'scale');
			obj.src=blankImg;
		}else if(obj.src.indexOf(blankImg)<0)png_filter(obj);
	}
}
