// JavaScript Document
// Autor André Cavallari
// cavallari@live.com
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 mousex(e){
	if(document.all){ e=event; }
	return e.clientX;
}
function mousey(e){
	if(document.all){ e=event; }
	return e.clientY;
}
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;
	}
}
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;
}

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(visibilidadeNum){
	if(visibilidadeNum){ document.getElmentById(this).style.visibility='visible'; }
	else{ document.getElementById(this).style.visible='hidden'; }
}
String.prototype.centerObject=function(obx,oby){
	object=document.getElementById(this);
	if(obx){
		sx=((object.style.width.replace('px','')/2)*-1)+'px';
		object.style.left='50%';
		object.style.marginLeft=sx;
	}
	if(oby){
		sy=((object.style.height.replace('px','')/2)*-1)+'px';
		object.style.top='50%';
		object.style.marginTop=sy;
	}
}


//------------------------------------- EDITING -------------------------------------
function pagex(){
	
	var xScroll;
	var windowWidth;
	
	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; }

	if (self.innerWidth) {	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 = windowWidth;	} 
	else { pageWidth = xScroll; }
	
	 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;
}