
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 MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

function validateBRDate( oSrc, args ) {
	var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
	var retorno = true;
	strValue = args.Value;
	
	if(!objRegExp.test(strValue)){
		retorno = false; //doesn't match pattern, bad date
	}else{
		var arrayDate = strValue.split(RegExp.$1); //split date into month, day, year
		var intDay = parseInt(arrayDate[0],10); 
		var intYear = parseInt(arrayDate[2],10);
		var intMonth = parseInt(arrayDate[1],10);
		
		if(intMonth > 12 || intMonth < 1) {
			retorno = false;
		}
		if (retorno){
			var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
								'08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
		  
			if(arrayLookup[arrayDate[1]] != null) {
				if(intDay > arrayLookup[arrayDate[1]] || intDay == 0){
					retorno = false;
				}
			}
			if (retorno && intMonth == 2){
				//check for February
				var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
				if(((booLeapYear && intDay > 29) || (!booLeapYear && intDay >28)) || intDay ==0){
					retorno = false;
				}
			}
		}
	}
	args.IsValid = retorno; //any other values, bad date
}
			
function Download (docID){
	location.replace('download_doc.aspx?docID=' + docID);
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- O campo '+nm+' deve conter um endereço de e-mail.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- O campo '+nm+' deve conter um número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- O campo '+nm+' deve conter um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- O campo '+nm+' não pode ser vazio.\n'; }
  }
  if (errors!=""){
	  return true;
  }else{
  	  return false;
  }
}


function pegaVariaveis() {
	if (navigator.appName == "Netscape") {
		horz=".left";
		vert=".top";
		docStyle="document.";
		styleDoc="";
		innerW="window.innerWidth";
		innerH="window.innerHeight";
		offsetX="window.pageXOffset";
		offsetY="window.pageYOffset";
	}else{
		horz=".pixelLeft";
		vert=".pixelTop";
		docStyle="";
		styleDoc=".style";
		innerW="document.body.clientWidth";
		innerH="document.body.clientHeight";
		offsetX="document.body.scrollLeft";
		offsetY="document.body.scrollTop";
   }
}

function checkLocation() {
	objectXY="LMenuTop";
	var availableX=eval(innerW);
	var availableY=eval(innerH);
	var currentX=eval(offsetX);
	var currentY=eval(offsetY);
	x=parseInt((availableX)-(imgwidth));
	x=Math.max(630,x-15);
	y=parseInt((availableY/2)-(imgheight/2));
	evalMove();
	setTimeout("checkLocation()",10);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

var janela = null;
function AbreJanela(theURL,winName,width,height,features, centralizada) { //v2.0
  if (janela != null) {
  	janela.close();
  }
  if (centralizada){
		if (navigator.appName == "Netscape") {
			innerW=eval("window.innerWidth");
			innerH=eval("window.innerHeight");
		}else{
			innerW=eval("document.body.clientWidth");
			innerH=eval("document.body.clientHeight");
		}
		x=parseInt((innerW/2)-(width/2));
		y=parseInt((innerH/2)-(height/2));
		janela = window.open(theURL,winName,features+',width='+width+',height='+height+',top='+x+',left='+y);
  }else{
	  janela = window.open(theURL,winName,features+',width='+width+',height='+height);
  }
  janela.focus();
  return janela;
}

function FechaJanela() {
  if (janela != null) {
  	janela.close();
  }
}






