// JavaScript Document
// Autor André Cavallari
// cavallari@live.com
// SHORTCUTS 1.1
/* <script type="text/javascript" src="js/shortcuts.js"></script> */

function checkBrowser(browser){
	if(navigator.userAgent.indexOf(browser)>0){
		return true;
	}
	else{ return false; }
}
function addload(funcao){
	var velholoader = window.onload;
	if (typeof window.onload != 'function'){
		window.onload=funcao;
	}
	else{
		window.onload=function(){
			velholoader();
			funcao();
		}
	}
}
function addscroll(funcao){
	var velholoader = window.onscroll;
	if (typeof window.onscroll != 'function'){
		window.onscroll=funcao;
	}
	else{
		window.onscroll=function(){
			velholoader();
			funcao();
		}
	}
}

function $id(id){
	return document.getElementById(id);
}
function $tag(tagName){
	return document.getElementsByTagName(tagName);
}
function $value(id){
	return document.getElementById(id).value;
}
function $body(){
	return document.getElementsByTagName('body')[0];
}
function setvalue(id,value){
	document.getElementById(id).value=value;
}
function maxlength(id,maximo){
	obj=document.getElementById(id);
	total=obj.value.length;
	if(total>maximo){
		value=obj.value;
		obj.value=value.substr(0,maximo);
	}
}
function checkmail(id){
	obj=document.getElementById(id);
	value=obj.value;
	total=value.length;
	arroba=value.indexOf('@');
	ponto=value.indexOf('.');
	if((arroba>0) && (ponto>0)){
		aft=value.split('@');
		aft=aft[1];
		restante=aft.split('.');
		inicio=restante[0];
		resto=restante[1];
		if((resto.length<=1) || (inicio.length<=1)){
			return false;
		}
	}
	
	if((arroba>=1) && (ponto>=4) && (total>=7)){
		return true;
	}
	else{
		return false;
	}
}
//----------------------------------SCROLL FUNCTIONS-----------------------------------------
function scrollx(){
	xscroll=0;
	if(document.body.scrollLeft){ xscroll=document.body.scrollLeft };
	if(document.documentElement.scrollLeft){ xscroll=document.documentElement.scrollLeft; }
	if(self.pageXOffset){ xscroll=self.pageXOffset; }
	return xscroll;
}
function scrolly(){
	yscroll=0;
	if(document.body.scrollTop){ yscroll=document.body.scrollTop };
	if(document.documentElement.scrollTop){ yscroll=document.documentElement.scrollTop; }
	if(self.pageYOffset){ yscroll=self.pageYOffset; }
	return yscroll;
}
//-------------------------------------- MOUSE FUNCTIONS -------------------------------------
function mousex(e){
	if(!e){ e=event; }
	return e.clientX+scrollx();
}
function mousey(e){
	if(!e){ e=event; }
	return e.clientY+scrolly();
}
//------------------------------------ END MOUSE FUNCTIONS --------------------------------------
//------------------------------------ FROM LIGHTBOX - THANKS -------------------------------------
function pagex(){
	var xScroll;
	if (window.innerWidth && window.scrollMaxX) { xScroll = window.innerWidth + window.scrollMaxX;	} 
	else if (document.body.scrollWidth > document.body.offsetWidth){ xScroll = document.body.scrollWidth; } 
	else {	xScroll = document.body.offsetWidth; }
	var windowWidth;
	
	if (self.innerWidth) {
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		
	} 
	else if (document.documentElement && document.documentElement.clientWidth) { windowWidth = document.documentElement.clientWidth;	} 
	else if (document.body) { windowWidth = document.body.clientWidth; }	

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	return pageWidth;
}
function pagey(){
	var yScroll;
	var windowHeight;
	
	if (window.innerHeight && window.scrollMaxY) {	yScroll = window.innerHeight + window.scrollMaxY; } 
	else if (document.body.scrollHeight > document.body.offsetHeight){ 	yScroll = document.body.scrollHeight; }
	else { yScroll = document.body.offsetHeight; }
	
	if (self.innerHeight) {	windowHeight = self.innerHeight; }
	else if (document.documentElement && document.documentElement.clientHeight) { windowHeight = document.documentElement.clientHeight; }
	else if (document.body) { windowHeight = document.body.clientHeight; }
	
	if(yScroll < windowHeight){ pageHeight = windowHeight;	} 
	else { pageHeight = yScroll; }
	
	return pageHeight;
}
function pagew(){
	if (self.innerWidth) { 
		if(document.documentElement.clientWidth){ windowWidth = document.documentElement.clientWidth; } else { windowWidth = self.innerWidth; }		
	} 
	else if (document.documentElement && document.documentElement.clientWidth) { windowWidth = document.documentElement.clientWidth;	} 
	else if (document.body) { windowWidth = document.body.clientWidth; }
	return windowWidth;
}
function pageh(){
	if (self.innerHeight) {	windowHeight = self.innerHeight; }
	else if (document.documentElement && document.documentElement.clientHeight) { windowHeight = document.documentElement.clientHeight; }
	else if (document.body) { windowHeight = document.body.clientHeight; }
	return windowHeight;
}

//----------------------------------------------- END OF LIGHTBOX FUNCTIONS-------------- -------------------

String.prototype.setSize=function(Width,Height){
	if(Width){document.getElementById(this).style.width=Width+'px';}
	if(Height){document.getElementById(this).style.height=Height+'px';}
}
String.prototype.setPosition=function(posX,posY){
	if(posX || posY){ document.getElementById(this).style.position='absolute'; }
	if(posX){document.getElementById(this).style.left=posX+'px';}
	if(posY){document.getElementById(this).style.top=posY+'px';}
}
String.prototype.setVisible=function(vis){
	if(vis){ document.getElementById(this).style.display='block'; }
	else{ document.getElementById(this).style.display='none'; }
}
String.prototype.centerObject=function(obx,oby){
	object=document.getElementById(this);
	object.style.position='absolute';
	if(obx){
		tamx=parseInt(object.style.width)/2;
		pagx=parseInt(pagex())/2;
		posx=Math.floor(pagx-tamx);
		object.style.left=posx+'px';
	}
	if(oby){
		tamy=parseInt(object.style.height)/2;
		pagy=parseInt(pagey())/2;
		posy=Math.floor(pagy-tamy);
		object.style.top=posy+'px';
	}
}
String.prototype.centerScreen=function(obx,oby){
	obj=document.getElementById(this);
	obj.style.position='absolute';
	if(obx){
		tamx=parseInt(obj.style.width)/2;
		pagx=parseInt(pagew())/2;
		posx=Math.floor(pagx-tamx)+scrollx();
		obj.style.left=posx+'px';
	}
	if(oby){
		tamy=parseInt(obj.style.height)/2;
		pagy=parseInt(pageh())/2;
		posy=Math.floor(pagy-tamy)+scrolly();
		obj.style.top=posy+'px';
	}
}
String.prototype.setOpacity=function(opacity){
	var ie=false;
	if(navigator.userAgent.indexOf('MSIE')>0){
		ie=true;
	}
	if(opacity>0){ this.setVisible(true); }
	if(ie){
		document.getElementById(this).style.filter='alpha(opacity='+opacity+')';
	}
	else{
		opacity=opacity/100;
		document.getElementById(this).style.opacity=opacity;
	}
	if(opacity==0){ this.setVisible(false); }
}
//************************************** ELASTIC CLASS *******************************************************
function FX(ms,divisor){
	this.tmp=0;
	ins=this;
	this.ms=5;
	this.divisor=50;
	this.centerx=false;
	this.centery=false;
	if(arguments.length==1){ this.ms=ms; }
	if(arguments.length==2){ this.ms=ms; this.divisor=divisor; }
	this.center=function(centerx,centery){
			this.centerx=centerx;
			this.centery=centery;
	}
	this.easing=function(id,type,start,end){
		if(start==null){
			if(type=='x'){ start=parseInt($id(id).style.left); }
			if(type=='y'){ start=parseInt($id(id).style.top); }
			if(type=='w'){ start=parseInt($id(id).style.width); }
			if(type=='h'){ start=parseInt($id(id).style.height); }
			if(!start){ start=0; }
		}
		wait=0;
		if(arguments[4]) wait=this.tmp;
		el=start;
		i=0;
		while(el!=end){
			i++;
			el=el+((end-el)/this.divisor);
			if(el>start){
				el=Math.ceil(el);
			}
			else{
				el=Math.floor(el);
			}
			setTimeout("ins.work('"+id+"','"+type+"','"+el+"')",(wait+i)*this.ms);
			this.tmp=wait+i;
		}
	}
	this.move=function(id,type,start,end){
		if(start==null){
			if(type=='x'){ start=parseInt($id(id).style.left); }
			if(type=='y'){ start=parseInt($id(id).style.top); }
			if(type=='w'){ start=parseInt($id(id).style.width); }
			if(type=='h'){ start=parseInt($id(id).style.height); }
		}
		wait=0;
		if(arguments[4]) wait=this.tmp;
		o=0;
		if(start<end){
			end++;
			for(i=start;i<end;i++){
				o++;
				setTimeout("ins.work('"+id+"','"+type+"','"+i+"')",(wait+o)*this.ms);
				this.tmp=wait+o;
			}
		}
		else{
			end--;
			for(i=start;i>end;i--){
				o++;
				setTimeout("ins.work('"+id+"','"+type+"','"+i+"')",(wait+o)*this.ms);
				this.tmp=wait+o;			
			}
		}
	}
	this.work=function(id,type,el){
		if(type=='x'){ id.setPosition(el,false) ;}
		if(type=='y'){ id.setPosition(false,el) ;}
		if(type=='w'){ id.setSize(el,false); id.centerScreen(this.centerx,this.centery); }
		if(type=='h'){ id.setSize(false,el); id.centerScreen(this.centerx,this.centery); }
		if(type=='o'){ id.setOpacity(el) ;}
	}
}
//---------------------------- FROM INTERNET - UBKNOWN AUTHOR (THANKS) ----------------------------------------
function addEvent( obj, type, fn ){ 
   if (obj.addEventListener){ 
      obj.addEventListener( type, fn, false );
   }
   else if (obj.attachEvent){ 
      obj["e"+type+fn] = fn; 
      obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
      obj.attachEvent( "on"+type, obj[type+fn] ); 
   } 
}
