
//////////////////////////////////////////////////////////////////////////////////////
function fundo_cor(obj,cor,txt,fonte){
obj.style.backgroundColor = cor;
txt.style.color = fonte;
}
//////////////////////////////////////////////////////////////////////////////////////
function background(obj,cor){
obj.style.backgroundColor = cor;
}
//////////////////////////////////////////////////////////////////////////////////////
function log_in(){
	if(document.logon.usuario.value == ""){
	alert('Você deve preencher o campo com seu usuário');
	document.logon.usuario.focus();
	}else{
	if(document.logon.senha.value == ""){
	alert('Você deve preencher o campo com sua senha');
	document.logon.senha.focus();
	}else{
	document.logon.submit();
	}
	}
}
//////////////////////////////////////////////////////////////////////////////////////
/*** 
* Descrição.: formata um campo do formulário de 
* acordo com a máscara informada... 
* Parâmetros: - objForm (o Objeto Form) 
* - strField (string contendo o nome do textbox) 
* - sMask (mascara que define o formato que o dado será apresentado, 
* 		usando o algarismo "9" para definir números e o símbolo "!" para 
* 		qualquer caracter... 
* - evtKeyPress (evento) 
* Uso.......: <input type="textbox" name="xxx"..... 
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);"> 
* Observação: As máscaras podem ser representadas como os exemplos abaixo: 
* CEP -> 99.999-999 
* CPF -> 999.999.999-99 
* CNPJ -> 99.999.999/9999-99
* Data -> 99/99/9999 
* Tel Resid -> (99) 999-9999 
* Tel Cel -> (99) 9999-9999 
* Processo -> 99.999999999/999-99 
* C/C -> 999999-! 
***/
function mask(objForm, strField, sMask, evtKeyPress)
{
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	
	if(document.all) // Internet Explorer
		nTecla = evtKeyPress.keyCode;
	else if(document.layers) // Nestcape
		nTecla = evtKeyPress.which;
	
	sValue = objForm[strField].value;
	
	// Limpa todos os caracteres de formatação que
	// já estiverem no campo.
	while (sValue.indexOf('-')>=0)
		sValue = sValue.toString().replace( "-", "" );
	while (sValue.indexOf('.')>=0)
		sValue = sValue.toString().replace( ".", "" );
	while (sValue.indexOf('/')>=0)
		sValue = sValue.toString().replace( "/", "" );
	while (sValue.indexOf('(')>=0)
		sValue = sValue.toString().replace( "(", "" );
	while (sValue.indexOf(')')>=0)
		sValue = sValue.toString().replace( ")", "" );
	while (sValue.indexOf(' ')>=0)
		sValue = sValue.toString().replace( " ", "" );
	while (sValue.indexOf(':')>=0)
		sValue = sValue.toString().replace( ":", "" );		
	fldLen = sValue.length;
	mskLen = sMask.length;
	
	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;
	
	while (i <= mskLen)
	{
		bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " ") || (sMask.charAt(i) == ":"))
	
		if (bolMask)
		{
			sCod += sMask.charAt(i);
			mskLen++;
		}
		else
		{
			sCod += sValue.charAt(nCount);
			nCount++;
		}
		i++;
	}
	
	objForm[strField].value = sCod;
	
	if (nTecla != 8) // backspace
		if (sMask.charAt(i-1) == "9") // apenas números...
			return ((nTecla > 47) && (nTecla < 58));// números de 0 a 9
	return true;
}
/// usa-se assim -> onKeyPress="return mask(document.toInsert, 'cpf_field', '999.999.999-99', event)"
//////////////////////////////////////////////////////////////////////////////////////
function SemPrevilegios(nome){
	alert("DESCULPE "+nome+",\nMas você não tem previlégios para acessar esta seção da Extranet.");
	history.go(-1);	
}
//////////////////////////////////////////////////////////////////////////////////////
function ajaxInit(){
   var xmlhttp;
   try{
       xmlhttp = new XMLHttpRequest();
   }catch(ee){
      try{
         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      }catch(e){
	     try{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(E){
	xmlhttp = false;
		}
		}
		}
	return xmlhttp;
}
//////////////////////////////////////////////////////////////////////////////////////
function getCidades() {
    sEstado = document.getElementById("estado").value;
    ajax = ajaxInit();
    if(ajax){
       ajax.open("GET","ajax_cidades.php?estado=" + sEstado, true);
       ajax.onreadystatechange = function (){
          if(ajax.readyState == 4){
             if(ajax.status == 200){
                cidades.innerHTML = ajax.responseText;
             } else {
                alert(ajax.statusText);
             }
          }
       }
       ajax.send(null);
    }
}
//////////////////////////////////////////////////////////////////////////////////////
function campo_cor(obj,cor,fonte,borda){
obj.style.backgroundColor = cor;
obj.style.color = fonte;
obj.style.borderColor = borda;
}
function ccolor(obj,cor,borda){
obj.style.backgroundColor = cor;
obj.style.borderColor = borda;
}
//////////////////////////////////////////////////////////////////////////////////////
function executivo_select(){
executivo = document.getElementById("executivo").value;	
window.open('http://extranet.movitel.com.br/comercial/agendamento/executivos.php?executivo='+executivo+'&tipo=select','executivo','width=400,height=400,scrollbars=yes');
}

//////////////////////////////////////////////////////////////////////////////////////
function form_cadastro() {
	if(document.cadastro.razao_social.value == ""){
	alert('Você deve preencher a RAZÃO SOCIAL da empresa.');
	document.cadastro.razao_social.focus();
	}else{
	if(document.cadastro.cnpj.value == ""){
	alert('Você deve preencher o CNPJ da empresa.');
	document.cadastro.cnpj.focus();
	}else{
	if(document.cadastro.endereco.value == ""){
	alert('Você deve preencher o ENDEREÇO da empresa.');
	document.cadastro.endereco.focus();
	}else{
	if(document.cadastro.cidade.value == ""){
	alert('Você deve selecionar a CIDADE da empresa.');
	document.cadastro.cidade.focus();
	}else{
	if(document.cadastro.telefone.value == ""){
	alert('Você deve preencher o TELEFONE da empresa.');
	document.cadastro.telefone.focus();
	}else{
	document.cadastro.submit();
	}
	}
	}
	}
	}
}



/////////////////////////////////////////////////////////////
function data_submit() {
	document.agendamento.submit();
}
//////////////////////////////////////////////////////////////////////////////////////
function busca_bairro() {
	window.open('http://extranet.movitel.com.br/includes/bairro.php','bairro','width=200,height=300');
}
//////////////////////////////////////////////////////////////////////////////////////
function cadastrar_bairro() {
	if(document.cadastrar.bairro_cad.value == ""){
	alert('Para cadastrar um BAIRRO você deve preencher o nome dele.');
	document.cadastrar.bairro_cad.focus();
	}else{
	document.cadastrar.submit();
	}
}
//////////////////////////////////////////////////////////////////////////////////////
function select_bairro(){
bairro = document.getElementById("bairro").value;
idbairro = bairro.substring(0,7);
nomebairro = bairro.substring(9,200);
self.opener.document.agendamento.bairro.value = nomebairro;
self.opener.document.agendamento.bairro_hidden.value = idbairro;
window.close();
}
//////////////////////////////////////////////////////////////////////////////////////
function consultar_carteira(){
	var cc = document.carteira;
	if(cc.executivo.options[0].selected == true && cc.cidade.options[0].selected == true && cc.letra.value == ""){
	alert('Você deve selecionar um valor em algum dos campos para Consultar.');
	cc.executivo.focus();
	}else{ 
	cc.submit();
	}
}
//////////////////////////////////////////////////////////////////////////////////////
function carteira(cliente,atual,executivo,cidade,pagina,comentario){
	window.open('trocar.php?cliente='+cliente+'&atual='+atual+'&executivo='+executivo+'&cidade='+cidade+'&pagina='+pagina+'&comentario='+comentario+'','trocar','width=320,height=165');	
}
//////////////////////////////////////////////////////////////////////////////////////
function ver_linhas(cliente){
	window.open('http://extranet.movitel.com.br/linhas.php?cliente='+cliente+'','linhas','width=600,height=450,scrollbars=yes,left=10,top=10');	
}
//////////////////////////////////////////////////////////////////////////////////////
function popup(pagina){
	window.open(pagina,"_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=600,height=500,left=10,top=10");	
}

//////////////////////////////////////////////////////////////////////////////////////
function popup_celular(pagina){
	window.open(pagina,"_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=200,height=300,left=10,top=10");	
}

//////////////////////////////////////////////////////////////////////////////////////
function carteira_executivo(){
	document.carteira.submit();
}
//////////////////////////////////////////////////////////////////////////////////////
function carteira_executivo2(){
	if(document.carteira.cnpj.value == ""){
	alert('Você deve preencher o CNPJ para buscar.');
	document.carteira.cnpj.focus();
	}else{	
	document.carteira.submit();
	}
}
//////////////////////////////////////////////////////////////////////////////////////
function senha(){
	if(document.info.email.value == ""){
	alert('Seu campo de e-mail não pode ser en branco.');
	document.info.email.focus();
	}else{
	if(document.info.atual.value == ""){
	alert('Você deve preencher o campo com sua senha atual.');
	document.info.atual.focus();
	}else{
	if(document.info.nova_a.value == ""){
	alert('Você deve preencher o campo com sua nova senha.');
	document.info.nova_a.focus();
	}else{
	if(document.info.nova_b.value == ""){
	alert('O campo para confirmação de sua nova senha não pode estar em branco.');
	document.info.nova_b.focus();
	}else{
	if(document.info.nova_a.value != document.info.nova_b.value){
	alert('O campo com a sua nova senha e o de confirmação não conferem,\n redigite sua nova senha nos dois campos.');
	document.info.nova_a.focus();
	}else{
	document.info.submit();
	}
	}
	}
	}
	}
}
//////////////////////////////////////////////////////////////////////////////////////
function marcar_executivo(){
	var	agenda = document.agendamento;
	if(agenda.hora.value == ""){
	alert('Para efetuar um agendamento você precisa digitar a Hora.');	
	agenda.hora.focus();
	}else{
	self.opener.document.agendamento.data.value = agenda.data.value;
	self.opener.document.agendamento.hora.value = agenda.hora.value;
	window.close();
	}
}


//////////////////////////////////////////////////////////////////////////////////////
function agenda_submit() {
	if(document.agendas.executivo.options[0].selected == true){
	alert('Você deve escolher um executivo primeiro.');	
	document.agendas.executivo.focus();
	}else{
	document.agendas.submit();
	}
}
//////////////////////////////////////////////////////////////////////////////////////
function agenda_submit2() {
	if(document.agendas.data.value == ""){
	alert('Você deve escolher uma data para ver sua agenda.');	
	document.agendas.data.focus();
	}else{
	document.agendas.submit();
	}
}
//////////////////////////////////////////////////////////////////////////////////////
function info_cliente(id,tipo,agenda){
	window.open('info_cliente.php?idc='+id+'&tipoc='+tipo+'&idagenda='+agenda+'','infoclt','width=440,height=450,scrollbars=yes');	
}
//////////////////////////////////////////////////////////////////////////////////////
function info_carteira(id){
	window.open('http://extranet.movitel.com.br/info_carteira.php?idc='+id+'','infocart','width=400,height=280,scrollbars=yes');	
}
//////////////////////////////////////////////////////////////////////////////////////
function info_carteira_telefonica(id){
	window.open('http://extranet.movitel.com.br/telefonica/info_carteira.php?idc='+id+'','infocart','width=400,height=280,scrollbars=yes');	
}
//////////////////////////////////////////////////////////////////////////////////////
function imprime_agenda(data){
	window.open('agenda_imprime.php?data='+data+'','agenda','width=700,height=450,scrollbars=yes');
}
//////////////////////////////////////////////////////////////////////////////////////
function imprime_completa(data){
	window.open('info_imprimir.php?data='+data+'','agenda','width=700,height=450,scrollbars=yes');
}
//////////////////////////////////////////////////////////////////////////////////////
function gestor(id){
	window.open('http://extranet.movitel.com.br/callcenter/gestor.php?idc='+id+'','gestor','width=400,height=300');
}
//////////////////////////////////////////////////////////////////////////////////////
function gestor_novo(){
	window.open('http://extranet.movitel.com.br/backoffice/gestor.php','gestor','width=400,height=300');
}
//////////////////////////////////////////////////////////////////////////////////////
function confirma_gestor(){
var mensagem = confirm('Lembre de não Cadastrar Gestor com todos os Dados em Branco.\nVocê tem certeza que deseja Cadastrar este Gestor ??');	

if(mensagem){
	return true;
}else{
	window.close();
	return false;
}
}
//////////////////////////////////////////////////////////////////////////////////////
function consultar_carteira2(){
	var cc = document.carteira;
	if(cc.executivo.options[0].selected == true && cc.cidade.options[0].selected == true){
	alert('Você deve selecionar um valor em algum dos campos para Consultar.');
	cc.executivo.focus();
	}else{ 
	cc.submit();
	}
}
///////////////////////////////////////////////////////////////////////////////////////

function retorno_visita(visita,cliente){
	window.open('retorno.php?visita='+visita+'&cliente='+cliente+'','retorno','width=300,height=200');	
}
///////////////////////////////////////////////////////////////////////////////////////
function comentarios(cliente){
	window.open('info_visitas.php?cliente='+cliente+'','info','width=380,height=390,scrollbars=yes');	
}
///////////////////////////////////////////////////////////////////////////////////////

function relatorio() {
	if(document.relatorio.data_inicial.value == ""){
	alert('Você deve selecionar o periodo.');
	document.relatorio.marca.focus();
	}else{
	if(document.relatorio.data_final.value == ""){
	alert('Você deve selecionar o periodo.');
	document.relatorio.marca.focus();
	}else{
	document.relatorio.submit();
	}
	}
}

//////////////////////////////////////////////////////////////////////////////////////
function pedidos(){
	if(document.pedido.smp.value == ""){
	alert('O campo de SMP não pode estar vazio.');
	document.pedido.smp.focus();
	}else{
	if(document.pedido.data.value == ""){
	alert('Você deve preencher o campo com a data do pedido.');
	document.pedido.data.focus();
	}else{
	if(document.pedido.area.value == ""){
	alert('Você deve preencher área de cobertura.');
	document.pedido.area.focus();
	}else{
	//if(document.pedido.quantidade_minutos.value == ""){
	//alert('Você deve selecionar a minutagem do plano. Peça para alguém do Backoffice cadastrar!');
	//document.quantidade_minutos.area.focus();
	//}else{
	document.pedido.submit();
	//}
	}
	}
	}
}

//////////////////////////////////////////////////////////////////////////////////////
function pedidos_tt(){
	if(document.pedido.smp.value == ""){
	alert('O campo de SMP não pode estar vazio.');
	document.pedido.smp.focus();
	}else{
	if(document.pedido.data.value == ""){
	alert('Você deve preencher o campo com a data do pedido.');
	document.pedido.data.focus();
	}else{
	if(document.pedido.area.value == ""){
	alert('Você deve preencher área de cobertura.');
	document.pedido.area.focus();
	}else{
	if(document.pedido.cpf_cessionario.value == ""){
	alert('Você deve preencher o campo CPF/CNPJ.');
	document.pedido.cpf_cessionario.focus();
	}else{
	document.pedido.submit();
	}
	}
	}
	}
}

//////////////////////////////////////////////////////////////////////////////////////
function mes(){
	var ano = document.getElementById("tempo_endereco").value;
	var mes = ano * 12;
	self.document.cadastro.tempo_endereco.value = mes;
}
//////////////////////////////////////////////////////////////////////////////////////

	
//////////////////////////////////////////////////////////////////////////////////////
///////////////////////// zoom em fotos e fundo escurecido ///////////////////////////
//////////////////////////////////////////////////////////////////////////////////////

function popup(lnk,pop,w,h,s) { 
	window.open(lnk,pop,'width='+w+',height='+h+',top=100,left=100,resizable=0,status=0,menubar=0,scrollbars='+s); 
}


// Largura do box descri??o do Zoom

function larguraBoxZoom(){
	if (document.getElementById('imgZoom') != null) {
		var largura = document.getElementById('imgZoom').width;	
	}	
	if (document.getElementById('fotoZoom')) document.getElementById('descricao').style.width=largura;
}
window.onload = larguraBoxZoom;

/* ----- zoom ---- */

	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){
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else {
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) {
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		if(yScroll < windowHeight) pageHeight = windowHeight;
		else pageHeight = yScroll;
		if(xScroll < windowWidth) pageWidth = windowWidth;
		else pageWidth = xScroll;
		arrayPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight}
		return arrayPageSize;
	}
	
	function getPageScroll(){
		var yScroll;
		if (self.pageYOffset) yScroll = self.pageYOffset;
		else if (document.documentElement && document.documentElement.scrollTop) yScroll = document.documentElement.scrollTop;
		else if (document.body) yScroll = document.body.scrollTop;
		arrayPageScroll = {yScroll:yScroll};
		return arrayPageScroll;
	}

 	function initZoom(div) {
		var container = document.getElementById(div);	
		var lnks = container.getElementsByTagName('a');
		for(var i=0,len=lnks.length;i<len;i++) {
			if(lnks[i].className.indexOf('linkZoom') > -1) {
				lnks[i].onclick = function() {
					openZoom(this);
					return false;
				}
			}
		}
	}
	
	function closeZoom(obj) {
		document.body.removeChild(document.getElementById('zoom'));
		document.body.removeChild(document.getElementById('sombra'));
		obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
	}
	
	function resizeZoom(obj) {
		var largura = obj.width;
		var altura = obj.height;
		var box = obj.parentNode.parentNode;
		var pageSize = getPageSize();
		var pageScroll = getPageScroll();
		var boxTop = pageScroll.yScroll + ((pageSize.windowHeight - altura - 26) / 2);
		var boxLeft = ((pageSize.pageWidth - largura - 40) / 2);
		box.style.top = (boxTop < 0) ? "0px" : boxTop + "px";
		box.style.left = (boxLeft < 0) ? "0px" : boxLeft + "px";
		box.style.visibility = 'visible';
		try {
			var divZoom = document.getElementById('zoom_'+obj.className);
			var divDescricao = document.getElementById('desc_'+obj.className);
			if(divZoom) divZoom.style.width = largura;
			if(divDescricao) divDescricao.style.width = largura;
		} catch(erro) {}
	}
	
	function openZoom(obj) {
		var pageSize = getPageSize();
		var fonte = '';
		var descricao = '';
		var classe = 'abc';
		var divs = obj.parentNode.getElementsByTagName('div');
		for(var i=0,len=divs.length;i<len;i++) {
			if(divs[i].className.indexOf('fonte') > -1) fonte = divs[i].innerHTML;
			if(divs[i].className.indexOf('descricao') > -1) descricao = divs[i].innerHTML;
		}
		var divContainer = document.createElement('div');
		divContainer.id = 'zoom';
		divContainer.className = 'zoom';
		divContainer.style.height = (pageSize.pageHeight + 'px');
		var divSombra = document.createElement('div');
		divSombra.id = 'sombra';
		divSombra.className = 'sombra';
		divSombra.style.height = (pageSize.pageHeight + 'px');
		document.body.appendChild(divSombra);
		var divZoom = document.createElement('div');
		divZoom.id = 'zoom_' +  classe;
		divZoom.className = 'fotoZoom';
		var spanFonte = document.createElement('span');
		spanFonte.className = 'fonte';
		spanFonte.innerHTML = fonte;
		var imgZoom = document.createElement('img');
		imgZoom.id = 'img_' +  classe;
		imgZoom.className = classe;
		imgZoom.src = obj.href;
		imgZoom.alt = 'Foto';
		var divDescricao = document.createElement('div');
		divDescricao.id = 'desc_' +  classe;
		divDescricao.className = 'descricao';
		var p = document.createElement('p');
		p.innerHTML = descricao;
		var divFechar = document.createElement('div');
		divFechar.className = 'fechar';
		var aFechar = document.createElement('a');
		aFechar.title = 'fechar';
		aFechar.innerHTML = 'fechar';
		aFechar.href = '#';
		aFechar.onclick = function() {
			closeZoom(this);
			return false;
		}
		divDescricao.appendChild(imgZoom);
		divFechar.appendChild(aFechar);
		divDescricao.appendChild(p);
		divZoom.appendChild(divFechar);
		divZoom.appendChild(spanFonte);
		divZoom.appendChild(divDescricao);
		divContainer.appendChild(divZoom);		
		document.body.appendChild(divContainer);
		if(imgZoom.width && imgZoom.width > 56) {
		 resizeZoom(imgZoom);
		}
		imgZoom.onload = function() {
		  resizeZoom(this);
		  return false;
		}	
	}
						
//////////////////////////////////////////////////////////////////////////////////////
