// JavaScript Document
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_popupMsg(msg) { //v1.0
  alert(msg);
}

//Nao avalia a versao dos navegadores pois eh do conhecimento
//do usuario os Navegadores e versoes que sao homologados.
function consisteNavegador() { //v1.0 - Alexandre Giordani
  var userAgent=navigator.userAgent;
  if (userAgent.indexOf('Netscape') != -1) {
	return "1"; //Netscape
  } else if (userAgent.indexOf('MSIE') != -1) {
	return "2"; //Internet Explorer
  } else{
  	//Se nao for nenhum dos dois, retorna como se fosse Netscape, pois ha mais probab. de funcionar.
  	return "1";
  }
}

function ValidarData(vData){
	
	if (vData==0) { 
		//alert("Favor informar a data."); 
		return false; 
	}
	var Parte=vData.split("/"); 
	Ano=Parte[2];
	Mes=Parte[1];
	Dia=Parte[0];
	if (Parte.join("").length < 6 || Parte.join("").length > 8 ) { 
		//alert("Digite a Data corretamente."); 
		return false; 
	}
	if ( isNaN(Parte.join("")) ) {
		//alert("Data deve ser numérica."); 
		return false;
	}
	if (Ano <= 1900) {
		//alert("Verifique o ano."); 
		return false;
	}
	Data1 = new Date(Ano,Mes-1,Dia);
	if (Mes < 1 || Mes > 12) {
		//alert("Mes incorreto, favor retificar."); 
		return false;
	}
	if (Dia < 1 || Dia > 31) {
		//alert("Dia incorreto, favor retificar."); 
		return false;
	}
	if (Dia > 30 || (Dia > 28 && Mes == 02 )){
		 D = Data1.getDate();
		 if (D < Dia){
		 	//alert("Dia maior que 30 em mes indevido ou\n fevereiro com dia 29 em ano não bissexto,\n favor retificar.");
		 	return false; 
		 }
	}
	/*Hoje = new Date();
	Ano2 = Hoje.getFullYear(); 
	Mes2 = Hoje.getMonth();  
	Dia2 = Hoje.getDate();
	Hoje = new Date(Ano2,Mes2,Dia2);
	
	Data1 = Data1.getTime();
	Hoje  = Hoje.getTime(); 
	if (Hoje > Data1) {
		//alert("Data não deve ser menor que a data atual."); 
		return false;
	}*/
	return true;
}

function FormatarData(campo,e) {
	var cod="";
	if(document.all) {
		cod=event.keyCode;
	} else {
		cod=e.which;
	}  
	if(cod == 08) return;
	if (cod < 48 || cod > 57)	{
		if (cod < 45 || cod > 57) alert("Digite somente Caracteres Numéricos!");
		cod=0;
		campo.focus(); return false;
	}
	tam=campo.value.length; 
	if(tam > 9) return false;
	var caract = String.fromCharCode(cod);
	if(tam == 2 || tam == 5) {
		campo.value+="/"+caract; 
		return false;
	}  
	campo.value+=caract; 
	return false;                
}

function ale_getWidth(pWidth){
	return (screen.width/2)-(pWidth/2+10);
}

function ale_getHeight(pHeight){
	return (screen.height/2)-(pHeight/2+20);
}

function mOvr(src,clrOver) {
	    src.style.cursor = 'hand';
		src.style.backgroundColor = clrOver;
 }
 function mOut(src,clrIn) {
	    src.style.cursor = 'default';
		src.style.backgroundColor = clrIn;
 }
 function mClk(src,cLink,iTarget) {
     window.parent.frames[iTarget].location = cLink;
}

function numerico(e)
{
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
				if (tecla != 8) // backspace
					event.keyCode = 0;
					//return false;
				else
					return true;
			}
}

function decimal(e){
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
	else if(document.layers) // Nestcape
		var tecla = e.which;
		
	if (tecla > 47 && tecla < 58) // numeros de 0 a 9
		return true;
	else{
		if (tecla != 8 && tecla != 44) // backspace e virgula
			event.keyCode = 0;
			//return false;
		else
			return true;
	}
}

function isValidMail(sMail){
	var retorno = true;
	if (sMail.indexOf("@",0) == -1) retorno = false;
	if (sMail.indexOf(".",0) == -1) retorno = false;
	if (sMail.indexOf("@.",0) != -1) retorno = false;			
	if (sMail.length < 5) retorno = false;
	
	return retorno;	
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function addOption(objSelect,text,value){
	obj = document.createElement("option");
	obj.text = text;
	obj.value = value;		
	if ( consisteNavegador() == "1" ){ //NN
		objSelect.add(obj,null);
	} else { //IE
		objSelect.add(obj);
	}
}

function custom_print() {
    if (document.all) {
        if (navigator.appVersion.indexOf("5.0") == -1) {
            var OLECMDID_PRINT = 6;
            var OLECMDEXECOPT_DONTPROMPTUSER = 2;
            var OLECMDEXECOPT_PROMPTUSER = 1;
            var WebBrowser = "<OBJECT ID=\"WebBrowser1\" WIDTH=0 HEIGHT=0 CLASSID=\"CLSID:8856F961-340A-11D0-A96B-00C04FD705A2\"></OBJECT>";
            document.body.insertAdjacentHTML("beforeEnd", WebBrowser);
            WebBrowser1.ExecWB(6, 2);
            WebBrowser1.outerHTML = "";
        } else {
            self.print();
        }
    } else {
        self.print();
    }
}

function showOrHide(elemento,f){
	if(f){
		visi="visible";
	} else { 
		visi="hidden";
	}
		
	if(document.layers){
		document.elemento.visibility = visi;
	}
	
	if(document.all){
		document.getElementById(elemento).style.visibility = visi;
	}
	
	if(document.getElementById){
		document.getElementById(elemento).style.visibility = visi;
	}
} 
