function menuLeft(id)
{
	$('ul#nav-left li div').removeClass();
	
	if (id == 1)
	{
		$('#center-in').load('load-novidade.php');	
	}
	else
	{
		$('#center-in').load('load-grupo.php?ID='+id);
	}
	$('ul[@tipo=menu]').hide();
	$('#menuSubgrupo'+id).show();
	$('li#menuGrupo'+id+' div:eq(0)').attr('class','over');

}


//função overlay
function overlay(n)
{
	if (n == 1)
		$.blockUI();
	else
		$.unblockUI();
}

//limpa espacos em branco 
function Trim(str){return str.replace(/^\s+|\s+$/g,"");}


//função sleep
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}


//adicionar ao favorito
function addFav(){
    var url      = "http://www.jorev.com.br";
    var title    = "Jorev - Luterano";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}



//função menu
/* início do HACK PARA CORRIGIR O LI:HOVER NO IE6*/
/*
over = function() 
{
	var sfEls = $("#nav-left li");
	for (var i=0; i<sfEls.length; i++)
	{
		sfEls[i].onmouseover=function() 
		{
			this.className+=" over";
		}
		sfEls[i].onmouseout=function() 
		{
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
}
	if (window.attachEvent) window.attachEvent("onload", over);
/* final do HACK PARA CORRIGIR O LI:HOVER NO IE6*/


//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) 
	{
		
		overlay(1);
		//if (document.all)
		//var pos = evt.clientY;
		//else
		// var pos = window.pageYOffset;
		
		var pageSize = getPageSize();
		
		var objScroll = getPageScroll();
		//alert(objScroll[1]);
		
		var winW = pageSize[0];
		var winY = pageSize[1];
		
		//menos a largura da div
		var w = (winW - divW) / 2;
		 //menos a altura da div
		//var y = (winY - 500) / 2;
		
		var y = objScroll[1] + 20;
		//alert(w);
		//alert(y);
		
		document.getElementById(div).style.left = w + 'px';
		document.getElementById(div).style.top = y + 'px';
		document.getElementById(div).style.display = 'block';
	},
	
	'_close': function(div)
	{
		document.getElementById(div).style.display='none';
		overlay(0);
	},
	
	'openWin': function(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 = {
	
	'menuColor': function(obj,tipo)
	{			
		switch(tipo)
		{
			case 'over':$(obj).css({background:'#8C715C', color:'#FFFFFF'});
			break;
			case 'out':$(obj).css({background:'transparent', color:'#623F28'});	
			break;
		}			
	},
	
	'menuColor2': function(obj,tipo,img)
	{			
		switch(tipo)
		{
			case 'over':$(obj).attr('src',img);	
			break;
			case 'out':$(obj).attr('src',img);		
			break;
		}			
	},
	
	// 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;
	}

}




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

//valida contato
var Contato = {
	
	'Valida': function()
	{
		
		if ( $('#nome').val() == "")
		{
			alert('Você precisa digitar o seu nome ! ');
			$('#nome').focus();
			return false;
		}
		
		if($('email').val() == "" || document.getElementById('email').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) 
		{
			alert('Você precisa digitar um endereço de e-mail válido ! ')
			$('#email').focus();
			return false;
		}
		
		if ( $('#telefone').val() == "")
		{
			alert('Você precisa digitar o seu telefone ! ');
			$('#telefone').focus();
			return false;
		}
		
		if ( $('#assunto').val() == "")
		{
			alert('Você precisa digitar o assunto ! ');
			$('#assunto').focus();
			return false;
		}

		if ( $('#mensagem').val() == "")
		{
			alert('Você precisa digitar a sua mensagem ! ');
			$('#mensagem').focus();
			return false;
		}
	}
}


//----------------------------------------------------------------------------------//
// Cadastro
//-----------------------------------------------------------------------------------//

//valida Cadastro
var Cadastro = {
	
	'Valida': function()
	{
		
		if ( $('#nome').val() == "")
		{
			alert('Você precisa digitar o seu nome ! ');
			$('#nome').focus();
			return false;
		}
		
		if($('email').val() == "" || document.getElementById('email').value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) 
		{
			alert('Você precisa digitar um endereço de e-mail válido ! ')
			$('#email').focus();
			return false;
		}
		
		if ( $('#telefone').val() == "")
		{
			alert('Você precisa digitar o seu telefone ! ');
			$('#telefone').focus();
			return false;
		}
		
		if ( $('#data_nasc').val() == "")
		{
			alert('Você precisa digitar a sua data de nascimento ! ');
			$('#data_nasc').focus();
			return false;
		}

		if ( $('#uf').val() == "")
		{
			alert('Você precisa escolher um estado! ');
			$('#uf').focus();
			return false;
		}
		
		if ( $('#id_cidade').val() == 0)
		{
			alert('Você precisa escolher uma cidade! ');
			$('#id_cidade').focus();
			return false;
		}
		
		if ( $('#endereco').val() == "")
		{
			alert('Você precisa digitar seu endereço! ');
			$('#endereco').focus();
			return false;
		}
	}
}
