var loadedobjects=""
var rootdomain="http://"+window.location.hostname

function ajaxpage(url, containerid){

var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
//		alert("page_request	1 - "+page_request);
//	alert("containerid 	1 - "+containerid);

loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
//	alert("page_request 2 - "+page_request);
//	alert("containerid 2 - "+containerid);
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}


function chamar(Explorer,Netscape)
{
	if ( navigator.appName == "Microsoft Internet Explorer" )
	{
		location = Explorer;
	}
	else
	{
		location = Explorer;
//		location = Netscape;
	}
}

function ConfirmarDelecao()
{
	document.ReturnValue=confirm('O(s) Item(s) marcados(s) será(ão) excluido(s). Confirma?');
}

function ConfirmarLogout()
{
	document.ReturnValue=confirm('Deseja desconectar?');
}

function MM_openBrWindow(theURL,winName,features)
{ //v2.0
	
	window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_jumpMenuGaleria(targ,selObj,restore){ //v3.0
  //eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (selObj.options[selObj.selectedIndex].value!="")
  {
	  window.open(selObj.options[selObj.selectedIndex].value,"FOTOS",'width=750,height=490,scrollbars=yes');
	  if (restore) selObj.selectedIndex=0;
  }
}


function MM_validateForm(){
        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]);
			   val = args[i];

               // if (val)
                //{
                        file://nm=val.name;
                        nm = args[i+1];
                        //val = val.trim();
				        if (val!="")
                        {
                                if (test.indexOf('isEmail')!=-1)
                                {
                                        p=val.indexOf('@');
                                        if (p<1 || p==(val.length-1))
                                                errors+='- '+nm+' deve conter um endereço de e-mail.\n';
                                }
                                else if (test!='R')
                                {
                                     	num = parseFloat(val);
                                        if (val!=''+num)
                                                errors+='- '+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 (num<min || max<num)
                                                        errors+='- '+nm+' deve conter un número entre '+min+' e '+max+'.\n';
                                        }
                                }
                        }
                        else if (test.charAt(0) == 'R')
                                errors += '- '+nm+' é requerido.\n';
               // }
        }
        if (errors){
                alert('Aviso: \n'+errors);
				return false;
		}
        document.MM_returnValue = (errors == '');
		return true;
}

function FormataData(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form[Campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.form[Campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 );
	}
}

function FormataHora(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;
	
	if ( tecla != 9 && tecla != 8 )
	{
		if ( tam > 2 && tam < 6 )
		{
			document.form[Campo].value = vr.substr( 0, tam - 3  ) + ':' + vr.substr( tam - 3, tam );
		}
	}
}

function FF_DataValida(vr,vrform) {

	// Data de entrada
	
	//vr = document.form.Data.value;

	tam = vr.length;
	var erro='';
	
	if (tam > 0)
	{
	   if (tam < 10)
	   {
  		  erro += 'Utilize o formato dd/mm/aaaa.';
	   }
	   else
	   {
			// Obtem dia, mes, ano da Data de Entrada
			var iDia  = vr.substr( 0, 2);
			var iMes  = vr.substr( 3, 2);
			var iAno  = vr.substr( 6, 4);

			// Obtem data atual
			var hoje = new Date();
			var datahj  = hoje.getDate();
			var anohj   = hoje.getYear();
			var anoBi;

			// Ano Hoje eh bisexto
			if (((anohj / 4   == 0) &&
				 (anohj / 100 != 0)   ) ||
				( anohj / 400 == 0    )   )
				anoBi =  ( true );
			else
				anoBi = ( false );

			// Dias no mes
			var diasMes = 0;
			switch ( iMes ) {
				case '01':
				case '03':
				case '05':
				case '07':
				case '08':
				case '10':
				case '12': diasMes = 31;
							      break;

				case '04':
				case '06':
				case '09':
				case '11': diasMes = 30;
								 break;

				case '02':{
						 if ( anoBi )
							diasMes = 29;
						 else
							diasMes = 28;
						}
			}//sw

			// Ano
			var ua = window.navigator.userAgent
			var msie = ua.indexOf ( "MSIE " )
			if ( msie < 0 ){
				anohj += 1900;
			}

			if (! ( (iAno >= (anohj - 100)) && (iAno <= (anohj + 10)) ) )
				erro += '   Ano ('+iAno+')\n';


			// Mes
			if (! (iMes > 0 && iMes < 13) )
				erro += '   Mês ('+iMes+')\n';

			// Dia
			if (! ( iDia > 0 && iDia <= diasMes ) && (diasMes != 0)) {
				erro += '   Dia ('+iDia+')\n';
			}

		}//if tam<10
	}
	else
	{
		erro = "Data não digitada";
	}

	if (erro) {
        alert('Data Inválida !\n\n'+erro);
		vrform.select();
		vrform.focus();
		return false;
	}

    return true;

}

function FF_DataValidaReturn(vr,vrform) {

	// Data de entrada
	
	//vr = document.form.Data.value;

	tam = vr.length;
	var erro='';
	
	if (tam > 0)
	{
	   if (tam < 10)
	   {
  		  erro += '- Utilize o formato dd/mm/aaaa.';
	   }
	   else
	   {
			// Obtem dia, mes, ano da Data de Entrada
			var iDia  = vr.substr( 0, 2);
			var iMes  = vr.substr( 3, 2);
			var iAno  = vr.substr( 6, 4);

			// Obtem data atual
			var hoje = new Date();
			var datahj  = hoje.getDate();
			var anohj   = hoje.getYear();
			var anoBi;

			// Ano Hoje eh bisexto
			if (((anohj / 4   == 0) &&
				 (anohj / 100 != 0)   ) ||
				( anohj / 400 == 0    )   )
				anoBi =  ( true );
			else
				anoBi = ( false );

			// Dias no mes
			var diasMes = 0;
			switch ( iMes ) {
				case '01':
				case '03':
				case '05':
				case '07':
				case '08':
				case '10':
				case '12': diasMes = 31;
							      break;

				case '04':
				case '06':
				case '09':
				case '11': diasMes = 30;
								 break;

				case '02':{
						 if ( anoBi )
							diasMes = 29;
						 else
							diasMes = 28;
						}
			}//sw

			// Ano
			var ua = window.navigator.userAgent
			var msie = ua.indexOf ( "MSIE " )
			if ( msie < 0 ){
				anohj += 1900;
			}

			if (! ( (iAno >= (anohj - 100)) && (iAno <= (anohj + 10)) ) )
				erro += '   Ano ('+iAno+')\n';


			// Mes
			if (! (iMes > 0 && iMes < 13) )
				erro += '   Mês ('+iMes+')\n';

			// Dia
			if (! ( iDia > 0 && iDia <= diasMes ) && (diasMes != 0)) {
				erro += '   Dia ('+iDia+')\n';
			}

		}//if tam<10
	}
	else
	{
		erro = "- Data não digitada.";
	}

	if (erro) {
        //alert('Data Inválida !\n\n'+erro);
		vrform.select();
		vrform.focus();
		//return false;
		return erro;
	}

    return erro;

}

function FF_HoraValida(vr) {

	// Hora de entrada
	//vr = document.form.Hora.value;
	tam = vr.length;
	var erro='';
	if (tam > 0) {
	   if (tam < 5) {
  		  erro += 'Digite apenas numeros.\n';
	   } else {

			// Obtem hora, minuto da Hora de Entrada
			var iH  = vr.substr( 0, 2);
			var iM  = vr.substr( 3, 2);

			// Hora
			if (! ( (iH >= (0)) && (iH <= (24)) ) )
				erro += '   Hora ('+iH+')\n';

		    // Min
			if (! (iM >= 0 && iM <= 59) )
				erro += '   Minutos ('+iM+')\n';

		}//if tam<5
	}// if tam>0

	if (erro) {
        alert('Hora Inválida !\n\n'+erro);
		document.form.Hora.select();
		document.form.Hora.focus();
		return false;
	}

    return true;

}

function GetCookie (name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen) 
	{
		var j = i + alen;

		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);

		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0) 
			break; 
	}

	return null;
}

function SetCookie (name, value) 
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;

	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function getCookieVal (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);

	if (endstr == -1)
		endstr = document.cookie.length;

	return unescape(document.cookie.substring(offset, endstr));
}

function ValidaEmail(sEmail) 
{
  var regex=/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	if (regex.test(sEmail) == false)
	{
		alert('Não é um e-mail válido!');
	}
  return regex.test(sEmail);
}

function hide(divId) 
{ 
if (document.layers) 
{ document.layers[divId].visibility = 'hide'; } 

else if (document.all) 
{ document.all[divId].style.visibility = 'hidden'; } 

else if (document.getElementById) 
{ document.getElementById(divId).style.visibility = 'hidden'; } 
} 

//shows corresponding div 

function show(divId) 
{ 
if (document.layers) 
{ document.layers[divId].visibility = 'show'; } 

else if (document.all) 
{ document.all[divId].style.visibility = 'visible'; } 

else if (document.getElementById) 
{ document.getElementById(divId).style.visibility = 'visible'; } 
} 

function aspas(f){
  for(i=0;i<f.elements.length;i++){
    quote(f.elements[i]);
  }
}


function quote(field) {
	out = "'"; // replace this
	add = "''"; // with this
	aux = "" + field.value; // temporary holder
	temp ="";
	
	while (aux.indexOf(out)>-1) {
		pos= aux.indexOf(out);
		temp = temp + (aux.substring(0, pos)) + add;
		aux = aux.substring((pos + out.length), aux.length);
	}

	out = "\""; // replace this
	while (aux.indexOf(out)>-1) {
		pos= aux.indexOf(out);
		temp = temp + (aux.substring(0, pos)) + add;
		aux = aux.substring((pos + out.length), aux.length);
	}

	if(field.type != "file"){
		field.value = temp + aux;
	}
}


/* INICIO este script abaixo eh para o esquema de submenu vertical usado no site da aqx */

function DOMgetElementsByClassName($node,$className){
/* Description: retorna um array com todos os elementos dentro
     de $node que possuam a classe indicada em $className
    Versão: 1.0 - 30/08/2006
    Author: Micox - Náiron J.C.G - micoxjcg@yahoo.com.br
    Site:   http://elmicox.blogspot.com
    Não retire estas informações pra não infringir direitos autorais!
*/
  var $node, $atual, $className, $retorno = new Array(), $novos = new Array();
  $retorno = new Array();
  for (var $i=0;$i<$node.childNodes.length;$i++){
   $atual = $node.childNodes[$i];
   if($atual.nodeType==1){// 1 = XML_ELEMENT_NODE
      $classeAtual = $atual.className;                              
      if(new RegExp("\\b"+$className+"\\b").test($classeAtual)){
      $retorno[$retorno.length] = $atual;
      }
      if($atual.childNodes.length>0){
      $novos = DOMgetElementsByClassName($atual,$className);
      if($novos.length>0){
     $retorno = $retorno.concat($novos);
      }
      }
   }
  }
  return $retorno;
}
function addEvent(obj, evType, fn){
  //adiciona evento, versao crossbrowser
  //retirado de http://elcio.com.br/crossbrowser/#7
  if (obj.addEventListener){
   obj.addEventListener(evType, fn, true)}
  if (obj.attachEvent){
   obj.attachEvent("on"+evType, fn)}
}
function ativaHover(classe) {
  //ativa o hover para elementos n?o links, por causa de bug do IE
  //retirado de http://www.maujor.com/tutorial/ddownmenu-a.php
  var pais = DOMgetElementsByClassName(document.body,classe);
  for (var j=0; j<pais.length; j++) {
   var sfEls = pais[j].getElementsByTagName("LI");
   for (var i=0; i<sfEls.length; i++) {
      sfEls[i].onmouseover=function() {
       this.className+=" over";
      }
      sfEls[i].onmouseout=function() {
       this.className=this.className.replace(new RegExp(" over\\b"), "");
      }
   }
  }
}
  
/*FIM INICIO este script abaixo eh para o esquema de submenu vertical usado no site da aqx */
function TipoBrowser()
{
var browserName=navigator.appName; 
 if (browserName=="Microsoft Internet Explorer")
 {
  return("ie");
 }
 else
  {
  return("nie");
   }
}

function VerificaData(data, obrigatorio, dma){
 	var strdata = data;
 	if((obrigatorio == 1) || (obrigatorio == 0 && strdata != "")){
 		if(dma == 1)
 		{
 			dia = strdata.substr(0,2)
 			 		//Verifica o dia
	 		if (isNaN(dia) || dia > 31 || dia < 0){
	 			alert("Formato do dia não é válido.");
	 			return true;
	 		}
		}
		else if(dma == 2)
		{
			dia = strdata.substr(0,2)
 			 		//Verifica o dia
	 		if (isNaN(dia) || dia > 31 || dia < 0){
	 			alert("Formato do dia não é válido.");
	 			return true;
	 		}
 			mes = strdata.substr(3,2);
	 		if (mes == 4 || mes == 6 || mes == 9 || mes == 11){
	 			if (dia == "31"){
	 				alert("O mês informado não possui 31 dias.");
	 				return true;
	 			}
	 		}
	 		//Verifica o mês
	 		if (isNaN(mes) || mes > 12 || mes < 0){
	 			alert("Formato do mês não é válido.");
	 			return true;
	 		}			
		}
		else if(dma == 3)
		{
			dia = strdata.substr(0,2);
			mes = strdata.substr(3,2);
	 		ano = strdata.substr(6,10);
	 		if (mes == "02"){
	 			bissexto = ano % 4;
	 			if (bissexto == 0){
	 				if (dia > 29){
	 					alert("O mês informado possui somente 29 dias.");
	 					return true;
	 				}
	 			}else{
	 				if (dia > 28){
	 					alert("O mês informado possui somente 28 dias.");
	 					return true;
	 				}
	 			}
	 		}
	 		//Verifica o ano
	 		if (isNaN(ano)){
	 			alert("Formato do ano não é válido.");
	 			return true;
	 		} 
	 	}
 	}
}

function MascaraData(data, componente)
{
	var strdata = data;
	var erro = 0;
	//verifica tamanho data
	if(strdata.length < 3)
	{
		if(isNaN(strdata.substring(0,strdata.length)))
		{
			alert("Formato do dia não é válido.");
			componente.value = strdata.substring(0,strdata.length - 1);
			erro = 1;
		}
		else if(strdata.length == 2)
		{
			if(VerificaData(data, 1, 1))
			{
				erro = 1
				componente.value = '';
			}
		}
		if(erro == 0)
		{
			if(strdata.length == 2)
			{
				componente.value = componente.value + '/';
			}
		}
	}
	if(strdata.length > 2 && strdata.length < 6)
	{
		if(isNaN(strdata.substring(3,strdata.length)))
		{
			alert("Formato do mês não é válido.");
			componente.value = strdata.substring(0,strdata.length - 1);
			erro = 1;
		}
		else if(strdata.length == 5)
		{
			if(VerificaData(data, 1, 2))
			{
				erro = 1
				componente.value = '';
			}
		}
		if(erro == 0)
		{
			if(strdata.length == 5)
			{
				 componente.value = componente.value + '/';
			}
		}
	}
	if(strdata.length > 5 && strdata.length < 11)
	{
		if(isNaN(strdata.substring(6,strdata.length)))
		{
			alert("Formato do ano não é válido.");
			componente.value = strdata.substring(0,strdata.length - 1);
		}
		else if(strdata.length == 10)
		{
			if(VerificaData(data, 1, 3))
			{
				erro = 1
				componente.value = '';
			}
		}
	}
	if(strdata.length == 11)
	{
		alert("Formato do ano não é válido.");	
		componente.value = strdata.substring(0,strdata.length-1);
	}
}

