// Deteção de propriedades do navegador -------------------------------------------------------------------------------------------------------------
function BrowserDetect()
{
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetect();

// Exibe a dica do objeto ---------------------------------------------------------------------------------------------------------------------------
function MostraDica(objeto, strdica)
{
	var node;
	node = document.getElementById("dica");
	node.replaceChild(document.createTextNode(strdica), node.lastChild);
	document.getElementById("dica").innerText = strdica;
	objeto.title = strdica;
	self.status = strdica;
}

// Formata data no padrão dd/mm/aaaa ----------------------------------------------------------------------------------------------------------------

function txtBoxFormat(objeto, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

	if ( document.all ) { // Internet Explorer
		nTecla = evtKeyPress.keyCode;
	} //if
	else { // Nestcape
		nTecla = evtKeyPress.which;
	}

	sValue = objeto.value;

	// Limpa todos os caracteres de formatação que
	// já estiverem no campo.
	sValue = sValue.toString().replace( ":", "" );
	sValue = sValue.toString().replace( ":", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( " ", "" );
	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) == ".") || (sMask.charAt(i) == "/"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

		if ( bolMask ) {
			sCod += sMask.charAt(i);
			mskLen++;
		} //if
		else {
			sCod += sValue.charAt(nCount);
			nCount++;
		} //Fim do else
		i++;
	} //Fim do while

	objeto.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
		else { // qualquer caracter...
			return true;
		} //Fim do else
	} //if
	else {
		return true;
	} //Fim do else
}

// Cria popup ---------------------------------------------------------------------------------------------------------------------------------------
function Popup(CaminhoArquivo, NomeJanela, Largura, Altura, DistanciaEsquerda, DistanciaTopo, BarraStatus, ScrollBars, Resizable, Modal)
{
	var wscr = screen.availWidth; // largura da tela
	var hscr = screen.availHeight;  // altura da tela
	var m_DistanciaEsquerda = DistanciaEsquerda;
	var m_DistanciaTopo = DistanciaTopo;
	var m_Centralizado = "no";
	if((DistanciaEsquerda==-1)&&(DistanciaTopo==-1))
	{
		m_DistanciaEsquerda = parseInt(wscr / 2) - parseInt(Largura / 2);
		m_DistanciaTopo = parseInt(hscr / 2) - parseInt(Altura / 2);
		m_Centralizado = "yes";
	}
	if(Modal=="yes")
	{
		if(browser.isIE)
		{
			var sFeatures="dialogHeight: " + (Altura+35) + "px;";
			sFeatures +="dialogWidth: " + (Largura+5) + "px;";
			sFeatures +="dialogLeft: " + m_DistanciaEsquerda + "px;";
			sFeatures +="dialogTop: " + m_DistanciaTopo + "px;";
			sFeatures +="center: " + m_Centralizado + ";";
			sFeatures +="scroll: " + ScrollBars + ";";
			sFeatures +="status: " + BarraStatus + ";";
			window.showModalDialog(CaminhoArquivo, "", sFeatures);
		}
		else
		{
			window.open(CaminhoArquivo, NomeJanela, "width=" + Largura + ", height=" + Altura + ", top=" + m_DistanciaTopo + ", left=" + m_DistanciaEsquerda + ", statusbar=" + BarraStatus + ", status=" + BarraStatus + ", scrollbars=" + ScrollBars + ", resizable=" + Resizable + ", toolbar=no, menubar=no, directories=no, modal=yes");
		}
	}
	else
		window.open(CaminhoArquivo, NomeJanela, "width=" + Largura + ", height=" + Altura + ", top=" + m_DistanciaTopo + ", left=" + m_DistanciaEsquerda + ", statusbar=" + BarraStatus + ", status=" + BarraStatus + ", scrollbars=" + ScrollBars + ", resizable=" + Resizable + ", toolbar=no, menubar=no, directories=no");
	
}

// Função de apoio ao menu --------------------------------------------------------------------------------------------------------------------------
function fncOcultar(objTable, mnuStyle)
{
	if((objTable != 'tblOcultPainulo') && (objTable != 'tblOcultModnulo'))
		{
			if(document.getElementById(objTable))
			{
				if(document.getElementById(objTable).style.display=='block')
					document.getElementById(objTable).style.display='none';
				else
					document.getElementById(objTable).style.display='block';
			}
		}
}

//Função para carregar e limitar o tamanho do text área, e passar o tamanho do mesmo para um input text, caso haja. ---------------------------------
//No input adicione o comando: onkeyup='LimTextArea(this, valor maximo(ex.: 100), objeto que receberá o lenght do textarea)'
function LimTextArea(obj, Len, objLen){	
	
	if(obj.value.length > Len){
		obj.value = obj.value.substring(0, Len);
	}
	if(objLen!=undefined){ 
		objLen.value = obj.value.length;
	}
}


// Função de passagem de parametros de uma popup para a tela que a chamou -----------------------------------------------------------------------------
function EnviarDadosPopup(objTexto, objValor, texto, valor, fechaJanela)
{
	/*opener.document.getElementById(objTexto).value = texto;
	opener.document.getElementById(objValor).value = valor;
	if(fechaJanela == true)
		window.close();*/
}


// Função de passagem de parametros de uma popup para a tela que a chamou -----------------------------------------------------------------------------
// envia tres valores para a janela chamadora
function EnviarDadosPopup3(objTexto1, objTexto2, objValor, texto1, texto2, valor, fechaJanela)
{
	opener.document.getElementById(objTexto1).value = texto1;
	opener.document.getElementById(objTexto2).value = texto2;
	opener.document.getElementById(objValor).value = valor;
	if(fechaJanela == true)
		window.close();
}

// Troca de dados entre dois objetos SELECT
function AddList(Select1, Select2, optSelected, campo, acao) {
	//Select1 - Select que está passando.
	//Select2 - Select que está recebendo.
	//optSelected - Indica se está selecionando tudo ou não.
	//campo - Nome do campo que recerá o valor do array.
	//acao - Indica se a direção de movimentação dos registros.
	
	//Percorre todos os registros do select que está enviando.
	for (var Current=0;Current < Select1.options.length;Current++) {
		//Verifica se o registro foi selecionado para ser enviado.
		if (optSelected == true ||Select1.options[Current].selected) {
			//Instancia um novo objeto option com as caracteristicas do option corrente do Select1.
			var optionName = new Option(Select1.options[Current].text, Select1.options[Current].value, true, true)

			var length = Select2.length;

			//Atribui o objeto option que foi instanciado no Select2 
			Select2.options[length] = optionName;
			
			//Remove o option corrente do Select2. 
			Select1.remove(Current);
			Current --;
		}
	}
	//Verifica se foi passado um campo para receber o valor do array.
	if(campo != ''){
		if(acao == 1)
			goArray(Select2, campo);
		else
			goArray(Select1, campo);
	}
}
	
function goArray(Setor, campo){
	//Limpa o valor do campo para receber o novo valor do array.
	campo.value = '';

	//Percorre todos os registros do select que passará os valores para o banco..
	for (var Current=0;Current < Setor.options.length;Current++) {

		if(campo.value == '')
			campo.value = Setor.options[Current].value;
		else
			campo.value = campo.value + ',' + Setor.options[Current].value;
	}
}
			
function AdicionarFavoritos(){
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
		window.external.AddFavorite(document.location, 'Viacao Riodoce');
	}
	else {
		if(navigator.appName == "Netscape")
			alert ("Pressione Crtl+D para adicionar esta página em seus favoritos.");
	}
}		

// direciona para a pagina com os detalhes do tipo de onibus informado
function selecionarTipoOnibus(codigo) {
	
	document.forms[0].action = 'alu_inc.aspx?cd=' + codigo;
	document.forms[0].submit();
}
