//if(confirm("You must be a goat to enter this site")) {
// Something
//}
//else {
// Something Else
//}

var is = new Is();

var leftX = 0;
var rightX = 0;
var leftY = 0;
var rightY = 0;

var lastMenu = "";
var fHide = "";
var fShow = "";

var anchopan=screen.availWidth;
var altopan=screen.availHeight;

var status;

if (is.ie||is.ns6)
{
	document.body.onclick=hideAll;
	document.body.onscroll=hideAll;
	document.body.onmousemove=updateIt;
	fHide = "hidden";
}
if (is.ns4)
{
	window.captureEvents(Event.MOUSEMOVE);
	window.captureEvents(Event.CLICK);
	window.onmousemove=updateIt;
	window.onclick=hideAll;
	fHide = "hidden";
}

reloj();

function Cooken() {
  if (is.ie||is.ns6)
	var cookieEnabled=(navigator.cookieEnabled)? true : false
  else if (typeof navigator.cookieEnabled=="undefined"){ 
	document.cookie="testcookie"
	cookieEnabled=(document.cookie=="testcookie")? true : false
	document.cookie="" //erase dummy value
  }
}

function Is() {
  var agent = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
  this.ns2 = (this.ns && (this.major == 3));
  this.ns3 = (this.ns && (this.major == 3));
  this.ns4b = (this.ns && (this.minor < 4.04));
  this.ns4 = (this.ns && (this.major >= 4 && this.major < 5));
  this.ns6 = (this.ns && (this.major >= 5));
  this.ie = (agent.indexOf("msie") != -1);
  this.ie3 = (this.ie && (this.major == 2));
  this.ie4 = (this.ie && (this.major >= 4));
  this.op3 = (agent.indexOf("opera") != -1);
  this.kq = (agent.indexOf("konqueror") != -1);
  this.win = (agent.indexOf("win")!=-1);
  this.mac = (agent.indexOf("mac")!=-1);
  this.unix = (agent.indexOf("x11")!=-1);
}

function cambiar(pag) {
location.href=pag;
}

function cambiar2(op,tipo,numero) {
location.href="ficha"+op+".asp?tipo="+tipo+"&numero="+numero;
}

function abrirven(pagina,anchoven,altoven) {
if (anchopan > anchoven)
  izq1 = (anchopan-anchoven)/2;
else
  {
  anchoven = anchopan; 
  izq1 = 0;
  }
if (altopan > altoven)
  top1 = (altopan-altoven)/2;
else
  {
  altoven = altopan; 
  top1 = 0;
  }

caract="width="+anchoven+",height="+altoven+",top="+top1+",left="+izq1+",toolbar=no,directories=no,status=no,scrollbars=yes,resize=no,menubar=no,titlebar=no"

msg=window.open(pagina,"OpenWindow",caract);
self.blur;
if (msg.focus!=null) msg.focus();
//document.getElementById("fecha1").innerHTML = caract;
return}

function nada() {}

function NombreMes(Mes){
	if (Mes == 1) return('Janeiro');
	if (Mes == 2) return('Fevereiro');
	if (Mes == 3) return('Mar&ccedil;o');
	if (Mes == 4) return('Abril');
	if (Mes == 5) return('Maio');
	if (Mes == 6) return('Junho');
	if (Mes == 7) return('Julho');
	if (Mes == 8) return('Agosto');
	if (Mes == 9) return('Setembro');
	if (Mes == 10) return('Outubro');
	if (Mes == 11) return('Novembro');
	if (Mes == 12) return('Dezembro');
}

function reloj(){
	var Digital = new Date();
	var dia = Digital.getDate();
        var dia1 = Digital.getDay();
	var mes = Digital.getMonth()+1;
	var ano = Digital.getYear();
        if (is.ns4||is.ns6) {ano+=1900};
	var horas = Digital.getHours();
	var minutos = Digital.getMinutes();
	var segundos = Digital.getSeconds();
        setTimeout("reloj()",1000);
        if (mes <= 9) { mes = "0"+mes; }
        if (horas <= 9) { horas = "0"+horas; }
        if (minutos <= 9) { minutos = "0"+minutos; }
	if (segundos <= 9) { segundos = "0"+segundos; }
	elreloj = '<span>'
        if (dia1 == 1) elreloj += "Segunda-feira";
        if (dia1 == 2) elreloj += "Ter&ccedil;a-feira";
        if (dia1 == 3) elreloj += "Quarta-feira";
        if (dia1 == 4) elreloj += "Quinta-feira";
        if (dia1 == 5) elreloj += "Sexta-feira";
        if (dia1 == 6) elreloj += "S&aacute;bado";
        if (dia1 == 0) elreloj += "Domingo";
      elreloj += ", " + dia + ' de ' + NombreMes(mes) + ' de ' + ano + '   ' + horas + ':' + minutos + ':' + segundos + '</span>';
	if (is.ns4) {
             liveclock = document.LiveClock;
             liveclock.document.write(elreloj);
		liveclock.document.close();
	} else if (is.ns6){
		document.getElementById("LiveClock").innerHTML = elreloj;
	} else if (is.ie) {
		LiveClock.innerHTML = elreloj;
                }            
        return;
}

function displaySubMenu(idMainMenu)
{
	var menu;
	var submenu;
	if (lastMenu != null && lastMenu != submenu) hideAll();
	if (idMainMenu != null){ 
	   if (is.ns4){
		submenu = document.layers[idMainMenu+"submenu"];
		submenu.left = document.layers[idMainMenu].pageX;
		submenu.top  = document.layers[idMainMenu].pageY + 140;
		submenu.visibility = fShow;

		leftX  = document.layers[idMainMenu+"submenu"].left;
		rightX = leftX + document.layers[idMainMenu+"submenu"].clip.width;
		leftY  = document.layers[idMainMenu+"submenu"].top+
			document.layers[idMainMenu+"submenu"].clip.height;
		rightY = leftY;
	   } else if (is.ie) {
		menu = eval(idMainMenu);
		submenu = eval(idMainMenu+"submenu.style");
		submenu.left = calculateSumOffset(menu, 'offsetLeft');
		submenu.top  = menu.style.top+140;
		submenu.visibility = fShow;
		leftX  = document.all[idMainMenu+"submenu"].style.posLeft
		rightX = leftX + document.all[idMainMenu+"submenu"].offsetWidth 
		leftY  = document.all[idMainMenu+"submenu"].style.posTop+document.all[idMainMenu+"submenu"].offsetHeight
		rightY = leftY;
	   } else if (is.ns6) {
		menu = document.getElementById(idMainMenu);
		submenu = document.getElementById(idMainMenu+"submenu").style;
		submenu.left = calculateSumOffset(menu, 'offsetLeft');
		submenu.top  = menu.style.top+140;
		submenu.visibility = fShow;
		leftX  = parseInt(document.getElementById(idMainMenu+"submenu").style.left);
		rightX = leftX+parseInt(document.getElementById(idMainMenu+"submenu").offsetWidth);

		leftY  = parseInt(document.getElementById(idMainMenu+"submenu").style.top) + parseInt(document.getElementById(idMainMenu+"submenu").offsetHeight);
		rightY = leftY;
	   }
	   lastMenu = submenu;
	}
}

function hideAll()
{
	if (lastMenu != null) {
		lastMenu.visibility = fHide;
		lastMenu.left = 0;}
}

function calculateSumOffset(idItem, offsetName)
{
	var totalOffset = 0;
	var item = eval('idItem');
	do
	{
		totalOffset += eval('item.'+offsetName);
		item = eval('item.offsetParent');
	} while (item != null);
	return totalOffset;
}

function updateIt(e)
{
	if (is.ie&&!is.opr6)
	{
		var x = window.event.clientX;
		var y = window.event.clientY;

		if (x > rightX || x < leftX) hideAll();
		else if (y > rightY) hideAll();
	}
	if (is.ns4||is.ns6)
	{
		var x = e.pageX;
		var y = e.pageY;

		if (x > rightX || x < leftX) hideAll();
		else if (y > rightY) hideAll();
	}
}

function operahide(){
        if (is.opr6){
        if (!MainTable.contains(event.toElement))
        hideAll()
}
}

function chequeoValor(fld)
{ // disallow a blank field
  if(fld.disabled) return true;
  if(!fld.value.length)
  { status= 'El campo '+fld.name+' no puede estar en blanco.'; return false; }
  return true;
}

function fijofecha(fld)
{ // tenacious date correction 
  if(!fld.value.length||fld.disabled) return true; // chequear campos vacios por chequeoValor
  var val= fld.value;
  val.replace(/\D/g,'/')
  ja = val.split("/")
  if(ja.length<3)
  { // La fecha es Incorrecta
    status= 'El campo '+fld.name+' tiene una fecha inválida.';
    return false;
  }
  var dt= new Date(ja[2], (ja[1]-1), ja[0]);
  if(!dt.valueOf())
  { // La fecha es Incorrecta 
    status= 'El campo '+fld.name+' tiene una fecha inválida.';
    return false;
  }
  fld.value= dt.getDate()+'/'+(dt.getMonth()+1)+'/'+dt.getFullYear();
  return true;
}

function checkEmail(fld)
{ // simple email check
  if(fld.disabled) return true; // blank fields are the domain of requireValue 
  var emailfmt= /^\w+([.-]\w+)*@\w+([.-]\w+)*\.\w{2,8}$/;
  if(!emailfmt.test(fld.value))
  { status= 'El campo '+fld.name+' debe contener una dirección de E-Mail Válida.'; return false; }
  return true;
}

function chequeo_cadena (texto,tipo)
{
  var checkOk = "";
/*  if (tipo == 1)     var checkOK = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";*/
  if (tipo == 1) {var checkOK = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";}
//			checkOK += "ƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ";
  if (tipo == 2)     var checkOK = "0123456789-/";
  if (tipo == 3)     var checkOK = "0123456789";
  var checkStr = texto;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++){
      if (ch == checkOK.charAt(j)) break;
    }
    if (j == checkOK.length) return (false);
  }
  return (true);
}

function chequeo_Radio(radios)
{ // require at least one radio in this group to be checked
  if(!radios.length) return true; // invalid parameter
  var visible= false, enabled= false;
  for(var i= 0; i < radios.length; i++)
  {
    if(!enabled) enabled= !radios[i].disabled;
    if(radios[i].checked) return true;
    else if(radios[i].offsetWidth == undefined || radios[i].offsetWidth > 0) visible= true;
  }
  if(!visible||!enabled) return true; // no visible/enabled options in this group
  status= 'Debe seleccionar una de las opciones de '+radios[0].name;
  return false;
}

function chequeo_entero(fld,sep)
{ // integer check/complainer 
  var val= fld.value;
  if(typeof(sep)!='undefined') val= val.replace(new RegExp(sep,'g'),'');
  val= parseInt(val);
  if(isNaN(val))
  { // parse error 
    return false;
  }
  fld.value= val;
  return true;
}

function Chequeo_Flotante(fld,sep)
{ // decimal number check/complainer 
  var val= fld.value;
  if(typeof(sep)!='undefined') val= val.replace(new RegExp(sep,'g'),'');
  val= parseFloat(val);
  if(isNaN(val))
  { // parse error 
    status= 'El Campo '+fld.name+' debe contener un número.';
    return false;
  }
  fld.value= val;
  return true;
}

function Chequeo_Moneda(fld,sep)
{ // monetary field check
  if(!fld.value.length||fld.disabled) return true; // blank fields are the domain of requireValue 
  var val= fld.value;
  val.replace(',',sep)
  if(typeof(sep)!='undefined') val= val.replace(new RegExp(sep,'g'),'');
  if(val.indexOf('$') == 0)
    val= parseFloat(val.substring(1,40));
  else
    val= parseFloat(val);
  if(isNaN(val))
  { // parse error 
    return false;
  }
  var sign= ( val < 0 ? '-': '' );
  val= Number(Math.round(Math.abs(val)*100)).toString();
  while(val.length < 2) val= '0'+val;
  var len= val.length;
  val= sign + ( len == 2 ? '0' : val.substring(0,len-2) ) + '.' + val.substring(len-2,len+1);
  fld.value= val;
  return true;
}

function Ajusto_Decimales(fld,dec,sep)
{ // fixed decimal fields 
  var val= fld.value;
  if(typeof(sep)!='undefined') val= val.replace(new RegExp(sep,'g'),'');
  val= parseFloat(val);
  if(isNaN(val))  {
    return false;
  }
  var sign= ( val < 0 ? '-': '' );
  val= Number(Math.round(Math.abs(val)*Math.pow(10,dec))).toString();
  while(val.length < dec) val= '0'+val;
  var len= val.length;
  val= sign + ( len == dec ? '0' : val.substring(0,len-dec) ) + '.' + val.substring(len-dec,len+1);
  fld.value= val;
  return true;
}

function Ajusto_Decimales2(fld,dec,sep)
{ // fixed decimal fields 
  var j;	
  var val= fld.toString();
  val= val.replace(new RegExp(',','g'),'.');
  val= parseFloat(val);
  if(isNaN(val))  {
    return false;
  }
  var sign= ( val < 0 ? '-': '' );
  val= Number(Math.round(Math.abs(val)*Math.pow(10,dec))).toString();
  while(val.length < dec) val= '0'+val;
  var len= val.length;
  val= sign + ( len == dec ? '0' : val.substring(0,len-dec) ) + '.' + val.substring(len-dec,len+1);
  return val;
}
