//Teste de browser

// Marca - tipo de browser
//
// Marca = -1 : Indefinido
// Marca = 0 : IE
// Marca = 1 : NC
//
//
// Versao = numero da versao : ex 4
// Versao = -1 : Indefinido
//
// Release - subdivisao da versao 
//
//	Para o IE 4 
//		Release = 0 : sem SP
//		Release = 1 : com SP 1 ou 2
//		Release = -1 : Indefinido

//	Para o NC 
//		E o release da versao
//		Release = -1 : Indefinido
//
// OS - Sistema Operacional
//
// OS = 0 : W95
// OS = 1 : NT 
// OS = 2 : W98 - falta
// OS = 3 : Mac - falta
// OS = 4 : OS/2 - falta
// OS = 5 : Unix - falta
// OS = -1 : Indefinido

// Cookie - verifica se o cookie esta habilitado
//
// Cookie = 0 : Habilitado - falta
// Cookie = 1 : Desabilitado - falta
// Cookie = -1 : Indefinido
// 
// Java - verifica se o java esta habilitado
//
// Java = 0 : Habilitado - falta
// Java = 1 : Desabilitado - falta
// Java = -1 : Indefinido


function clsBrowser()
{
	// Atributos
	this.Marca = -1;
	this.Versao = -1;
	this.Release = -1;
	this.OS = -1;
	this.Java = -1;
	this.Cookie =-1;
	this.Flash =-1;
	this.VersaoFlash =-1;

	// Metodos
	this.sbExecuta = sbExecuta; 
	this.fnstrPath = fnstrPath;
	this.fnintProtocolo = fnintProtocolo;
	this.fnstrServidor = fnstrServidor;
	this.fnstrPathSemProtServ = fnstrPathSemProtServ;
	this.fnstrRetornaVisibilidade = fnstrRetornaVisibilidade;
	this.fnvarRetornaObjeto = fnvarRetornaObjeto;

	return this;
}

function sbExecuta()
{
	var browserVersion = navigator.appVersion;
	var userAgent = navigator.userAgent;
	var browserVersionNum = parseInt(browserVersion);
	var numExplorer = userAgent.indexOf("MSIE",0);
	var numExplorerVersion = -1;
	var numNetscapeVersion = -1;
	var numOS = navigator.userAgent.indexOf("95",0);
	var numOSNT = navigator.userAgent.indexOf("NT",0);

	if(numOS != -1)
	{
		this.OS = 0;
	}
	else
	{
		if(numOSNT != -1)
		{
			this.OS = 1;
		}
	}
		
	if (numExplorer != -1)
	{
		this.Marca = 0;

	 	 for (i=5;i<10;i++)
		 {
		 		 if (userAgent.indexOf("MSIE "+i,0) != -1)
				 {
				 		numExplorerVersion = i;
				 }
		 		 if (userAgent.indexOf("MSIE"+i,0) != -1)
				 {
				 		numExplorerVersion = i;
				 }
		 }

		if (numExplorerVersion != -1)
		{
		 	 this.Versao = numExplorerVersion;
		}
		else
		{
			if (browserVersionNum==4)
			{
				this.Versao = 4;
			}
			else
			{
				this.Versao = 3;
			}
		}
		//release
		var MinorVersion = navigator.appMinorVersion;
		var numOcorrencia = MinorVersion.indexOf("SP",0);
		if (numOcorrencia!=-1)
		{
			this.Release = 1;
		}		
		else
		{
			this.Release = 0;
		}
	}
	else
	{
		if (navigator.appName == "Netscape")
		{

			this.Marca = 1;

			if (browserVersionNum==5)
			{
    	 	 for (i=5;i<15;i++)
    		 {
    		 		 if (userAgent.indexOf("Netscape "+i,0) != -1)
    				 {
    				 		numNetscapeVersion = i;
    				 }
    		 		 if (userAgent.indexOf("Netscape"+i,0) != -1)
    				 {
    				 		numNetscapeVersion = i;
    				 }
    		 		 if (userAgent.indexOf("Netscape/"+i,0) != -1)
    				 {
    				 		numNetscapeVersion = i;
    				 }
    		 		 if (userAgent.indexOf("Netscape\\"+i,0) != -1)
    				 {
    				 		numNetscapeVersion = i;
    				 }
    		 }
      		if (numNetscapeVersion != -1)
      		{
      		 	 this.Versao = numNetscapeVersion;
      		}
      		else
      		{
					 		this.Versao = 5
					}				 
			}
			else
			{
  			if (browserVersionNum==4)
  			{
  				this.Versao = 4;
  				var numRel = navigator.userAgent.indexOf("4.",0);
  				if (numRel!=-1)
  				{
  					this.Release = parseInt(navigator.userAgent.substr(numRel+2,2));
  				}
  			}
  			else
  			{
  				this.Versao = 3;
  			}
			}
			//grupo flash
      if (navigator.plugins && navigator.plugins.length)
      {
      	x = navigator.plugins["Shockwave Flash"];
      	if (x)
      	{
      		this.Flash = 2;
      		if (x.description)
      		{
      			y = x.description;
      			this.VersaoFlash = y.charAt(y.indexOf('.')-1);
      		}
      	}
      	else
      	{
      		this.Flash = 1;
      	}
      	if (navigator.plugins["Shockwave Flash 2.0"])
      	{
      		this.Flash = 2;
      		this.VersaoFlash = 2;
      	}
      }
      else if (navigator.mimeTypes && navigator.mimeTypes.length)
      {
      	x = navigator.mimeTypes['application/x-shockwave-flash'];
      	if (x && x.enabledPlugin)
      	{
      		this.Flash = 2;
      	}
      	else
      	{
      		this.Flash = 1;
      	}
      }
		}
	}
}

function fnstrPath()
{
	var tempstrPath = "";
	var tempstrAuxPath = "";

	if ((this.Marca == 0)&&(this.Versao == 4)&&(this.Release == 0))
	{
	 	 //resolver bug do ie sem sp
		 //verificar se ocorre com sp 2
		 	tempstrPath = window.location.pathname + "";
			tempstrAuxPath = tempstrPath.substring(1,tempstrPath.length);
   		tempstrPath = window.location.protocol + "//" + window.location.hostname + tempstrAuxPath;
			tempstrAuxPath = tempstrPath.lastIndexOf("/");
			tempstrPath = tempstrPath.substring(0,tempstrAuxPath+1);
	}
	else
	{
   		tempstrPath = window.location.protocol + "//" + window.location.host + window.location.pathname;
			tempstrAuxPath = tempstrPath.lastIndexOf("/");
			tempstrPath = tempstrPath.substring(0,tempstrAuxPath+1);
	}
	
	return tempstrPath;
} 

function fnstrPathSemProtServ()
{
	var tempstrPath = "";
	var tempstrAuxPath = "";

  tempstrPath = window.location.pathname;
	tempstrAuxPath = tempstrPath.lastIndexOf("/");
	tempstrPath = tempstrPath.substring(0,tempstrAuxPath+1);
	return tempstrPath;
}

function fnstrServidor()
{
 return window.location.host;
}

function fnintProtocolo()
{
 var intRetorno = 5;
 var tempprotocolo = window.location.protocol + ""; 
 switch (tempprotocolo)
 {
 				case "http:":
						 //http
						 intRetorno = 1;
				break;		 
				case "https:":
						 //https
						 intRetorno = 2;
				break;		 
				case "mms:":
						 //mms
						 intRetorno = 3;
				break;		 
				case "ftp:":
						 //ftp
						 intRetorno = 4;
				break;		 
				case "file:":
						 //file		 		 		 
						 intRetorno = 5;
				break;		 
 }
 return intRetorno;
}

function fnstrRetornaVisibilidade(intVisibilidade)
{
 var strVisibilidade = "";
 	if ((this.Marca == 0)||(this.Marca == 1))
	{
	 	 if (this.Versao > 5)
		 {
		 		if (intVisibilidade == 1)
				{
				 	 strVisibilidade = "visible";
				}
				else
				{
				 	 strVisibilidade = "hidden";
				}
		 }
		 else
		 {
		 		if (this.Marca == 0)
				{
  		 		if (intVisibilidade == 1)
  				{
  				 	 strVisibilidade = "visible";
  				}
  				else
  				{
  				 	 strVisibilidade = "hidden";
  				}
				}
				else
				{
  		 		if (intVisibilidade == 1)
  				{
  				 	 strVisibilidade = "show";
  				}
  				else
  				{
  				 	 strVisibilidade = "hide";
  				}
				} 
		 }
	}
	return strVisibilidade;	 
}
//intTipoObjeto
/*
							 0 = objeto em si
							 1 = style do objeto
*/
function fnvarRetornaObjeto(objHTMLElement,strNomeObjeto,intTipoObjeto)
{
 var varObjeto = null;
 	if ((this.Marca == 0)||(this.Marca == 1))
	{
	 	 if (this.Versao > 5)
		 {
		 		varObjeto = objHTMLElement.document.getElementById(strNomeObjeto)
				if ((varObjeto != null)&&(intTipoObjeto == 1))
				{
 				 	 varObjeto = varObjeto.style;
				}
		 }
		 else
		 {
		 		if (this.Marca == 0)
				{
  		 		varObjeto = objHTMLElement.document.all[strNomeObjeto]
					if ((varObjeto != null)&&(intTipoObjeto == 1))
  				{
  				 	 varObjeto = varObjeto.style;
  				}
				}
				else
				{
  		 		varObjeto = objHTMLElement.document.layers[strNomeObjeto];
				} 
		 }
	}
	return varObjeto;	 
}

//-------------------------------------------------------------

function clsRequest()
{
	// Propriedades
	this.Url = "";
	this.Chr_Sep_Url = "?";
  this.Chr_Sep_Parm = "&";
  this.Str_Sep_Valor = "=";

	// Metodos

	this.fnstrQuerystring = fnstrQuerystring; 
	this.fnstrServerVariables = fnstrServerVariables;
	this.fnintInsertParam = fnintInsertParam;

	return this;
}

function fnstrQuerystring(Param)
{
	Valor = "";
	var a = this.Url+"";
	var b = a.substring(a.indexOf(this.Chr_Sep_Url)+1,a.length);
	var c = b.split(this.Chr_Sep_Parm);
	for (var i=0;i<c.length;i++)
		{
		var d = c[i];
		var e = d.indexOf(this.Str_Sep_Valor);
		if ((e>0) && (e<d.length))
			{
			f = d.substring(0,e);
			if (Param==f)
				{
				Valor = d.substring(e+1,d.length);
				}
			}
		}
	return Valor;
}

function fnstrServerVariables()
{
	var a = this.Url;
	var b = "";
	if (a.indexOf(this.Chr_Sep_Url)!= -1)
	{
	 	 b = a.substring(a.indexOf(this.Chr_Sep_Url)+1,this.Url.length);
	}
	return b;
}

function fnintInsertParam(parmParam,parmValor)
{
	if (this.Url.indexOf(this.Chr_Sep_Url)== -1)
	{
	 	 this.Url = this.Url + this.Chr_Sep_Url + parmParam + this.Str_Sep_Valor + parmValor;
	}
	else
	{
	 		this.Url = this.Url + this.Chr_Sep_Parm + parmParam + this.Str_Sep_Valor + parmValor;
  }

}



