

$(document).ready(function(){
						   
	//alert($(document).height());
	if ($(window).height() < 545 || $(window).width() < 1000)
	{
		document.documentElement.style.overflow = 'auto';		
	}
	else
	{
		document.documentElement.style.overflow = 'hidden';	
	}	
});

//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 = $("#menuProdutos ul 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*/





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

var Common = {
	
	'color': function(obj,tipo)
	{			
		switch(tipo)
		{
			case 'over':$(obj).css({background:'#91c3e8'});	
			break;
			case 'out':$(obj).css({background:'#e6f0f5'});	
			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;
	}

}




//----------------------------------------------------------------------------------//
// DISTRIBUIDOR
//-----------------------------------------------------------------------------------//

var distribuidorCadastro = {
	
	'Valida': function()
	{
		
		if ( $('#nome').val() == "")
		{
			alert('Você precisa digitar a razão social! ');
			$('#nome').focus();
			return false;
		}
		
		if ( $('#nome_fantasia').val() == "")
		{
			alert('Você precisa digitar o nome fantasia! ');
			$('#nome_fantasia').focus();
			return false;
		}
		
		if ( $('#responsavel').val() == "")
		{
			alert('Você precisa digitar o nome do responsável! ');
			$('#responsavel').focus();
			return false;
		}
		
		if ( $('#cpf').val() == "")
		{
			alert('Você precisa digitar o CPF! ');
			$('#cpf').focus();
			return false;
		}
		
		if ( $('#rg').val() == "")
		{
			alert('Você precisa digitar o rg! ');
			$('#rg').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 ( $('#nome_bairro').val() == "")
		{
			alert('Você precisa digitar seu bairro! ');
			$('#nome_bairro').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 ( $('#endereco').val() == "")
		{
			alert('Você precisa digitar seu endereço! ');
			$('#endereco').focus();
			return false;
		}
		
		if ($('#telefone1').val() == "" && $('#telefone2').val() == "")
		{
			alert('Você precisa digitar um telefone! ');
			$('#telefone1').focus();
			return false;
		}
						
	}
}


//----------------------------------------------------------------------------------//
// CONTATO
//-----------------------------------------------------------------------------------//

//usado nna troca de senha
var Contato = {
	
	'Valida': function()
	{
		
		if ( $('#assunto').val() == "")
		{
			alert('Você precisa escolher o assunto! ');
			$('#assunto').focus();
			return false;
		}
		
		
		if ( $('#setor').val() == "")
		{
			alert('Você precisa escolher o setor! ');
			$('#setor').focus();
			return false;
		}

		
		if ( $('#nome').val() == "")
		{
			alert('Você precisa digitar o nome! ');
			$('#nome').focus();
			return false;
		}
		
		if ( $('#documento').val() == "")
		{
			alert('Você precisa digitar o numero do seu documento! ');
			$('#documento').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 telefone! ');
			$('#telefone').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 ( $('#mensagem').val() == "")
		{
			alert('Você precisa digitar sua mensagem! ');
			$('#mensagem').focus();
			return false;
		}		
	},
	
	'Valida2': function()
	{
		
		if ( $('#assunto').val() == "")
		{
			alert('Você precisa escolher o assunto! ');
			$('#assunto').focus();
			return false;
		}
		
		
		if ( $('#setor').val() == 0)
		{
			alert('Você precisa escolher o setor! ');
			$('#setor').focus();
			return false;
		}
		
		if ( $('#tipo').val() == 0)
		{
			alert('Você precisa preencher o campo você é! ');
			$('#tipo').focus();
			return false;
		}
		
		if ( $('#nome').val() == "")
		{
			alert('Você precisa digitar o nome! ');
			$('#nome').focus();
			return false;
		}
		
		if ( $('#documento').val() == "")
		{
			alert('Você precisa digitar o numero do seu documento! ');
			$('#documento').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 telefone! ');
			$('#telefone').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 ( $('#mensagem').val() == "")
		{
			alert('Você precisa digitar sua mensagem! ');
			$('#mensagem').focus();
			return false;
		}		
	}
}



//----------------------------------------------------------------------------------//
// NEWSLETTER
//-----------------------------------------------------------------------------------//

//usado nna troca de senha
var Newsletter = {
	
	'Valida': function()
	{
		
		if ( $('#nome').val() == "")
		{
			alert('Você precisa digitar o 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 telefone! ');
			$('#telefone').focus();
			return false;
		}
		
		if ($("input:checked").length == 0)
		{
			alert('você precisa escolher uma das opções! ');
			$('#profissional').focus();
			return false;
		}
		
	}
}

var Fale = {
	'Escolhe': function(id)
	{
		var value = $('#'+id+' option:selected').attr('tipo');
		
		switch (parseInt(value)) {
			case 1:{
			   $('#txt').html("Qual(is)?");		  
			   }
			   break;
			case 2:{
			    $('#txt').html("Qual canal/ programa?");
				}
			   break;
			case 3:{
			    $('#txt').html("Qual(is) filme(s)? ");
				}
			   break;			
					   
		} 
		
	},
	
	'Escolhe_ing': function(id)
	{
		
		var value = $('#'+id+' option:selected').attr('tipo');
		
		switch (parseInt(value)) {
			case 1:{
			   $('#txt').text("Which one?");
			   }		  
			   break;
			case 2:{
			    $('#txt').text("Which channel/program?");
				}
			   break;
			case 3:{
			    $('#txt').text("Which movie? ");
				}
			   break;				   
		} 
		
	}
}

function somente_numero(campo){  
var digits="-0123456789/"  
var campo_temp   
} 
