// JavaScript Document

window.onload = loadFunctions;

function loadFunctions(){
	pegaTamanhoDiv();
}


function gE(ID){
	return document.getElementById(ID);
}

function pegaTamanhoDiv(){
	var vDiv = gE('complementoDiv');
	var vDivConteudo = gE('conteudo_conteudo2');
	var vDivTopo = gE('topo');
	var sizesPage = getPageSize();
	if (arrayPageSize[0] > 800){
		vDiv.style.display = 'block';
		vDivConteudo.style.marginLeft = '45px';
		vDivTopo.style.background = 'url(img/fundo_continuacao_direita.jpg) left -15px no-repeat';
	}
}

// classe para validações
/*	
	Os parametros passados para a validação são o ID do input, onde o mesmo deverá estar entre '' (aspas simples).
	Ex. de uso:		
		<form action="acao.php" onsubmit="return Validacao.ValidaItens('campoNome', 'itAssunto', 'frMensagem', 'oEmail', n);" method="post">
		** n -> é possivel iserir quantos campos quiser
*/

var Validacao = {
	ValidaItens: function(){
		var args = Validacao.ValidaItens.arguments; // coloca os parametros em uma variavel no qual se tornará um Array
		if (args.length > 0){ // verifica se há parametros atribuidos a função
			for (var x = 0; x < args.length; x++){
				var vItem = gE(args[x]);
				if (vItem.value == "" || vItem.value == null){
					vItem.focus();
					vItem.style.border = 'solid 1px red';
					alert("Campo em branco");
					return(false);
				}else{
					vItem.style.border = '';
				}				
				//verifica se há algum campo de e-mail para chamar o validaEmail
				var vCampo = args[x].toLowerCase();		
				if (vCampo.indexOf('email') > 0){
					if (Validacao.ValidaEmail(vItem) == false)
						return(false);
				}				
			} // fim do for			
			return(true);
		}else{
			alert('Ocorreu um erro ao realizar operação');
			return(false);			
		}// else (args.length > 0){
	}, // fim do ValidaItens
	
	ValidaEmail: function(pCampo){
		var email = pCampo.value;
		var resp = email.search(/(\w[\w\.\+]+)@(.+)\.(\w+)$/)==0;
		
		if (resp == false){
			pCampo.focus();
			pCampo.style.border = 'solid 1px red';
			alert('E-mail inválido');
			return(false);
		}else{
			return(true);
		}
	}
};

/* Funções de terceiros */
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

}
