
//função redimensiona

function getPageScroll()
{

	var yScroll;
	
	if (self.pageYOffset) 
	{
		yScroll = self.pageYOffset;
	} 
	else if(document.documentElement && document.documentElement.scrollTop)
	{ // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} 
	else if (document.body) 
	{// all other Explorers
		yScroll = document.body.scrollTop;
	}
	
	arrayPageScroll = new Array('',yScroll)
	
	return arrayPageScroll;
}
	
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 - 18;
	} 
	else 
	{
		pageWidth = xScroll;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}


var Window =
{
	
	'_open': function(div,divW,divH) 
	{	
		
		//if (document.all)
		//var pos = evt.clientY;
		//else
		// var pos = window.pageYOffset;
		$.blockUI(); 
		 
		var pageSize = getPageSize();
		
		var objScroll = getPageScroll();
		
	
		var winW = pageSize[0];
		var winY = pageSize[1];
		

		//menos a altura da div
		if (divH > $(document).height())
			var y = 20;
		else 
			var y = (winY - divH) / 2;
			
		
		//menos a largura da div
		var w = (winW - divW) / 2;
		 
		
		
		//alert(w);
		//alert(y);
		
		document.getElementById(div).style.left = w + 'px';
		//document.getElementById(div).style.top = y + 'px';
		document.getElementById(div).style.top = (objScroll[1] + 90)  + 'px';
		
		
		$('#'+div).show('slow');
		
		$('#'+div).focus();
	
	},
	
	'_open2': function(div,divW,divH) 
	{	
		
		//if (document.all)
		//var pos = evt.clientY;
		//else
		// var pos = window.pageYOffset;
		$.blockUI(); 
		 
		var pageSize = getPageSize();
		
		var objScroll = getPageScroll();
		
	
		var winW = pageSize[0];
		var winY = pageSize[1];
		

		//menos a altura da div
		if (divH > $(document).height())
			var y = 20;
		else 
			var y = (winY - divH) / 2;
			
		
		//menos a largura da div
		var w = (winW - divW) / 2;
		 
		
		
		//alert(w);
		//alert(y);
		
		document.getElementById(div).style.left = w + 'px';
		//document.getElementById(div).style.top = y + 'px';
		document.getElementById(div).style.top = y  + 'px';
		
		
		$('#'+div).show('slow');
		
		$('#'+div).focus();
	
	},
	
	'_close':function(div)
	{
		$("#"+div).hide('slow');
		$("#"+div).empty();
		$.unblockUI();
	},
	
	'_close2':function(div)
	{
		$("#"+div).hide('slow');
		$.unblockUI();
	}
}


//CENTRALIZADA serve para previem de noticia, artigo, etc...
function openWin(url, name, w, h, s) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+s+',resizable=no';
//	winprop = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes';
	
	win = window.open(url, name, winprops)
	if(parseInt(navigator.appVersion) >= 4) {
		win.window.focus(); 
	}
}


//---------------------------------------------------------------------------------//
// COMMONS
//---------------------------------------------------------------------------------//

var Common = {
	
	'loadCidade': function(uf)
	{
		//alert(uf);
		$('#divCidade').load('load-cidade.php?uf=' + uf);	
	},
	
	'loadBairro': function(id_cidade) 
	{
		//alert(id_cidade);
		$('#divBairro').load('load-bairro.php?id_cidade=' + id_cidade);	
	},
	
	
	'loadTecnica': function(id_atividade) 
	{
		$('#id_tecnica').load('load-tecnica.php?id_atividade=' + id_atividade);	
	},
	
	'loadRegiao': function(id_tecnica) 
	{
		var id_atividade = $('#id_atividade').val();
		$('#id_regiao').load('load-regiao.php?id_atividade=' + id_atividade+'id_tecnica=' + id_tecnica);	
	},
	
	// ID = id do que se quer escluir
	// URL = pagina que sera feita a exclusao
	//MSG = se quiser definir mensagem especial para exclusao
	'Deleta': function(URL,MSG)
	{
		if (MSG == "" || MSG == null)
			MSG = "Tem certeza que deseja excluir ?";
			
	   if(confirm(MSG))
	   document.location = URL;
	},
	
	//Função para formatar moeda R$
	'formataMoeda': function(campo,event)
	{
		//Pega o código da tecla
		function getKey(e)
		{
		if (e == null) 
		{ // ie
			keycode = event.keyCode;
		} 
		else 
		{ // mozilla
			keycode = e.which;
		}
		//key = fromCharCode(keycode).toLowerCase();
		
		return keycode;
		}
		
		//Bloqueia caracteres que não sejam números
		function teclas(campo,event)
		{
			if(((event.keyCode < 96) || (event.keyCode > 105)) && ((event.keyCode < 48) || (event.keyCode > 57)) )
			{
			   campo.value = campo.value.replace(String.fromCharCode(event.keyCode).toLowerCase(),"");
			}
		}

	   //para evitar caracteres alfas.
	   teclas(campo,event);
	   str = campo.value;
	
	   while(str.search(",") != -1)
		   str = str.replace(",","");
	   i = 0;
	
	   while(i< str.length){
		   if(str.substr(i,1) == ".")
			  str = str.replace(".","");
			  i++;
	   }
	
	   part1 = str.substr(0,str.length - 2);
	   while(part1.search(" ") != -1)
		   part1 = part1.replace(" ","");
	
		   part2 = str.substr(str.length - 2,2);
		   res = "";
		   i = part1.length;
		   sob = i % 3;
		   if((sob != 0) && (i > 2))
			  res = part1.substr(0,sob) + ".";
		   else
			  res = part1.substr(0,sob);
		   j = 1;
		   part1 = part1.substr(sob);
		   i = 0;
		   while(i < part1.length){
			  if(j == 3){
				 if(i + 1 == part1.length)
					res = res + part1.substr(i-2,3);
				 else res = res + part1.substr(i-2,3) + ".";
			  }
			  i++;
			  j = j<3?j+1:1;
		   }
		   campo.value = res + "," + part2;
	}

}
//----------------------------------------------------------------------------------//
//Links
//----------------------------------------------------------------------------------//
var Links = {
	
    'Valida': function()
    {
        if ($('#id_atividade').val() == 0)
        {
            alert('Selecione um tipo de atividade!');
            $('#id_atividade').focus();
            return false;
        }		
		
		if ($('#id_tecnica').val() == 0)
        {
            alert('Selecione uma técnica!');
            $('#id_tecnica').focus();
            return false;
        }
		
		if ($('#id_regiao').val() == 0)
        {
            alert('Selecione um local!');
            $('#id_regiao').focus();
            return false;
        }
		
		return true;
    }
}


//----------------------------------------------------------------------------------//
// Contato
//-----------------------------------------------------------------------------------//

//usado nna troca de senha
var Contato = {
	
	'Valida': function()
	{		
		if ( $('#nome').val() == "")
		{
			alert('Você precisa digitar o nome! ');
			$('#nome').focus();
			return false;
		}
		
		if($('#email').val() == "")
		{
			alert('Você precisa digitar o e-mail! ')
			$('#email').focus();
			return false;
		}
		
		if($('#telefone').val() == "")
		{
			alert('Você precisa digitar o telefone! ')
			$('#telefone').focus();
			return false;
		}
		
		if($('#mensagem').val() == "")
		{
			alert('Você precisa digitar a mensagem! ')
			$('#mensagem').focus();
			return false;
		}
		
	}
}
