function checkBrowser() {
	var b = navigator.appName
	if (b == 'Netscape') this.b = 'ns'
	else if (b == 'Microsoft Internet Explorer') this.b = 'ie'
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b == 'ns' && this.v >= 4)
	this.ns4 = (this.b == 'ns' && this.v == 4)
	this.ns5 = (this.b == 'ns' && this.v == 5)
	this.ns6 = (this.b == 'ns' && this.v == 5)
	this.ie = (this.b == 'ie' && this.v >= 4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4') > 0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5.0') > 0)
	this.ie55 = (navigator.userAgent.indexOf('MSIE 5.5') > 0)
	this.ie6 = (navigator.userAgent.indexOf('MSIE 6.0') > 0)
	this.win = (navigator.userAgent.indexOf('Win') > 0)
	this.mac = (navigator.userAgent.indexOf('Mac') > 0)
	if (this.ie5) this.v = 5
	if (this.ie55) this.v = 5.5
	if (this.ie6) this.v = 6
	this.min = (this.ns || this.ie)
	this.dom = (this.v >= 5)
}
is = new checkBrowser()

// Checa de um objeto está definido
function isDef(S){return(eval('typeof('+S+')')!='undefined'&&eval('typeof('+S+')')!='unknown')}

// CSS Function
function css(id,left,top,width,height,color,vis,z,other) {
	if (id=="START") return '<STYLE TYPE="text/css">\n'
	else if (id=="END") return '</STYLE>'
	var str = (left!=null && top!=null)? '#'+id+' {position:absolute; left:'+left+'px; top:'+top+'px;' : '#'+id+' {position:relative;'
	if (arguments.length>=4 && width!=null) str += ' width:'+width+'px;'
	if (arguments.length>=5 && height!=null) {
		str += ' height:'+height+'px;'
		if (height!=null && width!=null && (arguments.length<9 || other.indexOf('clip')==-1)) str += ' clip:rect(0px '+width+'px '+height+'px 0px);'
	}
	if (arguments.length>=6 && color!=null) str += (is.ns)? ' layer-background-color:'+color+';' : ' background-color:'+color+';'
	if (arguments.length>=7 && vis!=null) str += ' visibility:'+vis+';'
	if (arguments.length>=8 && z!=null) str += ' z-index:'+z+';'
	if (arguments.length==9 && other!=null) str += ' '+other
	str += '}\n'
	return str
}
function writeCSS(str,showAlert) {
	str = css('START')+str+css('END')
	document.write(str)
	if (showAlert) alert(str)
}

// Escreve um estilo no caso de iE
if (is.ie) {
  str  = '.input-borda1 {background-color: #ffffff; border: 1px solid #FF9900;}'
  str += '.input-borda2 {background-color: #ffffff; border: 2px solid #999999;}'
  str += '.select-cadastro {font-family: verdana, arial, helvetica; font-size: 10px; background-color: #FFFFFF}'
  writeCSS(str,false)
}

// Abre um popup com telas de configurações de softwares
function PopConfig(software,numero,tamW,tamH) {
str = "pop_configs.asp?software="+software+"&numero="+numero+"&w="+tamW+"&h="+tamH
opc = "width="+tamW+" height="+tamH
  window.open(str,'popup',opc);
}

// Abre janela popup
function clickPop(url,nome,opcoes) {
  window.open(url,nome,opcoes);
}

// Manipulação de SELECTs
function mOption(strId, strText, className) {
  this.id = strId;
  this.text = strText;
	this.className = className;
}
function fSetOptions(vOptions, fSelect, strSelected) {
  fSelect.length = vOptions.length;
    for (i=0; i<vOptions.length; i++) {
      fSelect.options[i].value = vOptions[i].id; 
      fSelect.options[i].text = vOptions[i].text;
			if(vOptions[i].className)fSelect.options[i].className = vOptions[i].className;
      if (vOptions[i].id==strSelected)
        fSelect.options[i].selected=true;
      }
}

//Funcao para validar campo de busca das paginas
function ValidaBusca(){
	b = document.formbusca.txt_busca;
	if(b.value == ""){
		alert("Digite pelo menos uma palavra para busca!");
		b.focus();
		return false;
	}
	return true;
}

function doSel(obj) {
  var i = 0
  for (i = 0; i < obj.length; i++)
    if (obj[i].selected == true)
      if (i != 0) //ignore the first option
        eval(obj[i].value);
}

function ValidaLogin() {
	l = document.formlogin;
	if(!ValidaEmail(l)){
		return false;	
	}
	if(l.senha.value == ""){
		alert("Senha deve ser preenchido!");
		l.senha.focus();
		return false;
	}
	return true;
}

function explica(texto) {

}


function checanum(campo) {
	straux = campo.value + '#';
	i = 0;
	while (straux.charAt(i)!='#')	{
		if ( ( (straux.charAt(i)>='0') && (straux.charAt(i)<='9') ) || (straux.charAt(i)=='-') || (straux.charAt(i)=='.'))
			i++;
		else
		{
			campo.value = '';
//			campo.focus();
			return false;
		}
	}
	return true;
}

function CheckNome(campo) {
	valor = campo.value;
	for (var i=1; i < valor.length; i++) {
		if (valor.charAt(i)==" ") 
		  if ((valor.charAt(i + 1)!=" ") && (valor.charAt(i + 1)!=""))
			return true;
	}
	return false;
}


function ChecaEmail(campo) {
	size=campo.value.length;
	i=1;
	numA=0;
	numP=0;
	lugarA=true;
	while (i<=size)
	{
		if (campo.value.charAt(i)!=" ") {
			if (campo.value.charAt(i)=="@") {
				numA++;
				if (campo.value.charAt(i+1)=="")
					lugarA=false;
			}
			if (campo.value.charAt(i)==".") {
				numP++;
				if (campo.value.charAt(i+1)=="")
					lugarA=false;
				if ( (campo.value.charAt(i+1)=="@") || (campo.value.charAt(i-1)=="@") )
					lugarA=false;
		}
	}
	else lugarA=false;
		i++;
	}
	if ( (lugarA) && (numA==1) && (numP>0) ){
		return true;
	}
	return false;
}

function checaano(campo) {
	checanum(campo);
	if (campo.value=="")
	{
		return false;
	}
	data1=new Date();
	ano=data1.getYear();
	if (ano==99) {
		ano += 1900;
	} 
	else 
		ano += 2000;
	if (campo.value > 1800) {
		if( 1 > (ano - campo.value) )
			conf1=confirm(" Confirma o ano do seu nascimento ( " +  campo.value + " ) ?" );
		else
			return true;
	        if (conf1)
		  return true;
	}
	campo.value="";
	campo.focus();
	return false;
}


function checadia(campo) {
	checanum(campo);
	if (campo.value=="")
	{
		return false;
	}

	if(campo.value>31)
	{
		campo.value = '';
		campo.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function checames(campo) {
	checanum(campo);
	if (campo.value=="")
	{
		return false;
	}
	if(campo.value>12)
	{
		campo.value = '';
		campo.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function checaData(campo1, campo2, campo3) {
	dia = campo1.value;
	mes = campo2.value;
	ano = campo3.value;

	if(!checadia(campo1)){
	  return false;
	}
	if (!checames(campo2)){
	  return false;
	}
	if (!checaano(campo3)){
	  return false;
	}
	if ((mes == 2) && (dia > 28)){
	  return false;
	}
	if ((mes % 2) && (mes < 8) && (dia == 31)){
	  return false;
	}
	if ((!(mes % 2)) && (mes >= 8) && (dia == 31)){
	  return false;
	}
	
	return true;
}

function ValidaEmail(l) {
	if(l.email.value == "") {
		alert("E-mail deve ser preenchido!");
		l.email.focus();
		return false;
	}else{
		if(!ChecaEmail(l.email)) {
			alert("Digite um e-mail válido!");
			l.email.focus();
			return false;
		}
	}
	return true;
}
