/*---------------------------
	PEGA OS ARGUMENTOS E EXECUTA A REJEIÇÃO DA TECLA
---------------------------*/

function rejeitaTecla()
{
    var tecla 	  = 0;
    var args_eval = "e, ";
	
    for(var i=0; tecla=arguments[i]; i++)
    {
		args_eval += tecla + ", ";
	}
	
    args_eval += "0";
    eval("document.onkeypress=function(e){verificaTecla("+args_eval+");}\n"+"document.onkeydown=function(e){verificaTecla("+args_eval+");}");
}


/*---------------------------
	RETORNA TRUE/FALSE PARA TECLA REJEITADA
---------------------------*/

function verificaTecla()
{    
    var oEvent = arguments[0];
    var oEvent = oEvent ? oEvent : window.event;
    var tecla  = (oEvent.keyCode) ? oEvent.keyCode : oEvent.which;
    
    if(oEvent.type=="keydown" && navigator.appName.indexOf('Internet Explorer')<0 )
	{
        //se for keydown e não for o IE, vazarei pois o keypress já foi executado
        return false;
    }
    
    for(var i=1; cod_tecla=arguments[i]; i++)
	{
        if (tecla == cod_tecla)
		{
            if (typeof(oEvent.preventDefault)=='function')
			{
                oEvent.preventDefault();
            } 
			else 
			{
                oEvent.returnValue = false;
                oEvent.keyCode = 0;
            }
        }
    	return false;
	}
}


/*---------------------------
	RETORNA A POSICAO DO SCROLL DO BROWSER
---------------------------*/

function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}



/*---------------------------
	RETORNA O TAMANHO DA JANELA
---------------------------*/

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		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
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			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;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

/*---------------------------
	ENCONTRA OBJETOS E
	ELEMENTOS
---------------------------*/

function localizaObj(objNome, objDocumento) 
{
	var intContador, p, x;
	if (!objDocumento)
	{
		objDocumento = document;
	}
	if ((p = objNome.indexOf("?")) > 0 && parent.frames.length)
	{
		objDocumento = parent.frames[objNome.substring(p + 1)].document;
		objNome = objNome.substring(0, p);
	}
	if (!(x = objDocumento[objNome]) && objDocumento.all)
	{
		x = objDocumento.all[objNome];
	}
	for (intContador = 0; !x && intContador < objDocumento.forms.length; intContador++) x = objDocumento.forms[intContador][objNome];
	for (intContador = 0; !x && objDocumento.layers && intContador < objDocumento.layers.length; intContador++) x = localizaObj(objNome,objDocumento.layers[intContador].document);
	if (!x && objDocumento.getElementById)
	{
		x = objDocumento.getElementById(objNome);
	}
	return x;
}


/*---------------------------
	MOSTRA/ESCONDE CAMADAS
---------------------------*/

function manipulaDiv()
{
	var intContador, strDisplay, objNome, arrArgs = manipulaDiv.arguments;
	for (intContador = 0; intContador < (arrArgs.length - 1); intContador += 2)
	{
		if ((objNome = localizaObj(arrArgs[intContador])) != null)
		{
			strDisplay = arrArgs[intContador + 1];
			if (objNome.style)
			{
				objNome = objNome.style;
				strDisplay = (strDisplay == 'show')?'block':(strDisplay == 'hide')?'none':strDisplay;
			}
			objNome.display = strDisplay;
		}
	}
}



/*---------------------------
	ALTERA CSS DE UM OBJ
---------------------------*/

function setEstilo()
{
	var intContador, strClasse, objNome, arrArgs = setEstilo.arguments;
	for (intContador = 0; intContador < (arrArgs.length - 1); intContador += 2)
	{
		if ((objNome = localizaObj(arrArgs[intContador])) != null)
		{
			strClasse = arrArgs[intContador + 1];
			objNome.className = strClasse;
		}
	}
}

/*---------------------------
	RESIZE IFRAME
---------------------------*/

function resizeIframe() 
{
	var arrayPageSize = getPageSize();
	var largura = arrayPageSize[0];
	var altura  = arrayPageSize[1];
	
	try {
	
	 frame = document.getElementById('conteudo');
	 innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
	
	 objToResize = (frame.style) ? frame.style : frame;
	
	if(innerDoc=="[object]")
	{
		tamanho = innerDoc.body.scrollHeight; //IE
		auxilio = 20;
	}
	else
	{
		tamanho = innerDoc.body.offsetHeight; //Mozilla
		auxilio = 50;
	}
		objToResize.height = Number(tamanho+auxilio);
		document.getElementById('topo').focus();
	}
	
	catch (e) 
	{
		window.status = '';
	}
}

/*---------------------------
	REDIRECT IFRAME
---------------------------*/

function redirectIframe(frame,pagina)
{
	this[frame].location = pagina;
}

/*---------------------------
	SETA O NOME DA COR
---------------------------*/

function setaCor(cor)
{
	document.getElementById("cor").value = cor;
}

/*---------------------------
	ALERT
---------------------------*/

function alertSobre(msg)
{
	alert(msg);
}

/*---------------------------
	TIPO DE AÇÃO
---------------------------*/

function tipoControleAcao()
{
	tipo = document.getElementById("tipo");
	
	if (tipo.value == "")
	{
		alert("Você deve selecionar o tipo de ação que deseja cadastrar e clicar em INSERIR novamente.");
		tipo.focus();
		return;
	} 
	else 
	{
		if (tipo.value == 1) { location.href = "inserir_telefone.php"; }
		if (tipo.value == 2) { location.href = "inserir_assistencia.php"; }
		if (tipo.value == 3) { location.href = "inserir_visita.php"; }
	}
}

/*---------------------------
	TIPO DE PROPOSTA
---------------------------*/

function tipoProposta()
{
	tipo = document.getElementById("tipo");
	
	if (tipo.value == "")
	{
		alert("Você deve selecionar o tipo de proposta que deseja cadastrar e clicar em INSERIR novamente.");
		tipo.focus();
		return;
	} 
	else 
	{
		if (tipo.value == 1) { location.href = "inserir_brasil.php"; }
		if (tipo.value == 2) { location.href = "inserir_exterior.php"; }
	}
}

/*---------------------------
	CATEGORIA DO CLIENTE
---------------------------*/

function setaCategoriaCliente()
{
	with(document.formulario)
	{
		if (cliente.value != "")
		{
			if (categoria.value != "")
			{
				if (confirm("Tem certeza que deseja alterar a categoria deste cliente para "+categoria.value+" ?"))
				{
				}
				else
				{
					categoria.options[0].selected = true;	
				}
			}
		}
		else
		{
			alert("Para alterar a categoria é necessário selecionar um cliente");
			categoria.options[0].selected = true;	
			cliente.focus();
			return;
		}
	}
}

/*---------------------------
	EXCLUIR
---------------------------*/

function execAct(acao,query)
{
	if (confirm("Tem certeza que deseja excluir este registro?")){
		location.href = 'acoes.php?acao='+acao+"&"+query;
	}
}

/*---------------------------
	MUDA PÁGINA
---------------------------*/

function mudaPagina(url)
{
	location.href = url;
}

/*---------------------------
	POPUP CENTRALIZADO
---------------------------*/

function abrePopup(pagina,largura,altura,rolagem)
{
	var posX;
	var posY;
	posX = (window.screen.width - largura) / 2;
	posY = (window.screen.height - altura) / 2;
	window.open(pagina,"_blank","width="+largura+",height="+altura+",top="+posY+",left="+posX+",scrollbars="+rolagem+",toolbar=no,location=no,directories=no,menubar=no,resizable=no,menubar=no");
}

/*---------------------------
	POPUP POSIÇÃO PADRÃO
---------------------------*/

function abrePopupMenor(pagina,largura,altura,rolagem)
{
	window.open(pagina,"_blank","width="+largura+",height="+altura+",top=80,left=80,scrollbars="+rolagem+",toolbar=no,location=no,directories=no,menubar=no");
}

/*---------------------------
	PONTUAÇÃO ATRAVÉS DO TELEFONE
---------------------------*/

function setaPontosTelefone()
{
	with(document.formulario)
	{
		if (dia.value == "" || mes.value == "" || ano.value == "")
		{
			alert("Selecione a data que foi feito o contato.");
			dia.focus();
			return;
		}
		
		if (assunto.value == "")
		{
			alert("Preencha o assunto do contato.");
			assunto.focus();
			return;
		}		
		
		if (tipo_realizado.value == "")
		{
			alert("Selecione o tipo de pessoa contatada.");
			tipo_realizado.focus();
			return;
		}
		
		if (para.value == "")
		{
			alert("Selecione com quem foi feito o contato.");
			para.focus();
			return;
		}
		
		if (observacoes.value == "")
		{
			alert("Preencha as observações sobre o contato.");
			observacoes.focus();
			return;
		}
		
		if (pagina_acao.value == "inserir")
		{		
			if (tipo_realizado.value == "Representante") { pontuacao.value = "1"; }
			else if (tipo_realizado.value == "Cliente") { pontuacao.value = "21"; }
			else if (para.value == "1000") { pontuacao.value = "17"; }
			else if (para.value != "1000" && para.value != "") { pontuacao.value = "19"; }
			else { pontuacao.value = ""; }
		}

		submit();
	}
}


/*---------------------------
	PONTUAÇÃO ATRAVÉS DE ASSISTÊNCIA
----------------------------*/

function setaPontosAssistencia()
{
	with(document.formulario)
	{
		if (dia.value == "" || mes.value == "" || ano.value == "")
		{
			alert("Selecione a data que foi feito o contato.");
			dia.focus();
			return;
		}
		
		if (cliente.value == "")
		{
			alert("Selecione o cliente a quem foi prestado a assistência.");
			cliente.focus();
			return;
		}		
		
		if (tipo_realizado.value == "")
		{
			alert("Selecione o tipo de asistência prestada.");
			tipo_realizado.focus();
			return;
		}
		
		if (grupo.value == "")
		{
			alert("Selecione o grupo de equipamento na qual foi prestada a assistência.");
			grupo.focus();
			return;
		}
		
		if (equipamento.value == "")
		{
			alert("Selecione o equipamento.");
			equipamento.focus();
			return;
		}
		
		if (equipamento.value == "1000")
		{
			if (outro_equipamento.value == "")
			{
				alert("Preencha a qual equipamento foi prestado a assistência.");
				outro_equipamento.focus();
				return;
			}
		}
		
		if (observacoes.value == "")
		{
			alert("Preencha as observações sobre a assistência.");
			observacoes.focus();
			return;
		}
		
		submit();
	}
}

/*---------------------------
	PONTUAÇÃO ATRAVÉS DE VISITAS
---------------------------*/

function setaPontosVisitas()
{
	with(document.formulario)
	{
		if (dia.value == "" || mes.value == "" || ano.value == "")
		{
			alert("Selecione a data que foi feito o contato.");
			dia.focus();
			return;
		}
		
		if (visita_feita_com.value == "")
		{
			alert("Selecione a categoria do usuário com quem você realizou a visita.");
			visita_feita_com.focus();
			return;
		}		
		
		if (acompanhante.value == "")
		{
			alert("Selecione o acompanhante durante a visita.");
			acompanhante.focus();
			return;
		}
		
		if (cliente.value == "")
		{
			alert("Selecione o cliente na qual foi feita a visita.");
			cliente.focus();
			return;
		}
		
		if (tipo_realizado.value == "")
		{
			alert("Selecione o tipo de visita realizada.");
			tipo_realizado.focus();
			return;
		}
		
		if (tipo_realizado.value == "")
		{
			alert("Selecione o tipo de visita realizada.");
			tipo_realizado.focus();
			return;
		}
		
		if (tipo_realizado.value == "Feira / Eventos")
		{
			if (feira.value == "")
			{
				alert("Selecione a feira na qual foi realizada a visita.");
				feira.focus();
				return;
			}
		}
		
		if (assunto.value == "")
		{
			alert("Preencha o assunto da visita.");
			assunto.focus();
			return;
		}		
		
		if (observacoes.value == "")
		{
			alert("Preencha as observações sobre a visita.");
			observacoes.focus();
			return;
		}		
		
		if (pagina_acao.value == "inserir")
		{
			if (visita_feita_com.value == "3"){ pontuacao.value = "18"; }
			else if (visita_feita_com.value == "4"){ pontuacao.value = "20"; }
			else if (tipo_realizado.value == "Atendido"){ pontuacao.value = "6"; }
			else if (tipo_realizado.value == "Não Atendido"){ pontuacao.value = "5"; }
			else if (tipo_realizado.value == "Brashoes"){ pontuacao.value = "7"; }
			else if (tipo_realizado.value == "Feira / Eventos"){ pontuacao.value = "8"; }
			else if (tipo_realizado.value == "Pedido"){ pontuacao.value = "11"; }
			else { pontuacao.value = ""; }
		}
		
		submit();
	}
}


/**************************************************
	AJUSTA JANELA
**************************************************/
function ajustaJanela()
{
	version = 0;
	
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		temp = navigator.appVersion.split("MSIE");
		version = parseFloat(temp[1]);
	}
	
	if (version == 7){
		num = 75;
	} else {
		num = 50;
	}
	
    var x = document.getElementById("imag").width+10;     
    var y = document.getElementById("marker").offsetTop+num;
 	window.resizeTo(x, y);
}


/**************************************************
	ABRE POPUP
**************************************************/
function img_grande(pagina,largura,altura,rolagem)
{
  window.open(pagina,"_blank","width="+largura+",height="+altura+",top=40,left=40,scrollbars=no,toolbar=no,location=no,directories=no,menubar=no");
}


/*---------------------------------------------------------------------------------
	VAI PARA PÁGINA
---------------------------------------------------------------------------------*/

function getPage(resto)
{
	with (document.formulario) 
	{
		location.href = "index.php?pagina=servicos&pg="+pagina.value+resto;	
	}
}


