function mostramenu(elemento,linko)
{
  if (document.getElementById(elemento).style.display=='block')
  {
    document.getElementById(elemento).style.display='none';
    /*document.getElementById(linko).style.background='url(img/mais.png) no-repeat 0 0';*/
  }
  else
  {
    document.getElementById(elemento).style.display='block';
    /*document.getElementById(linko).style.background='url(img/mais.png) no-repeat 0 -13px';*/
  }
}
function confirma(frase)
      {
          if (confirm(frase))
          {
              return true;
          }
          else
          {
              return false;
          }
      }

function Dados(valor) {
      //verifica se o browser tem suporte a ajax
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
	  //se tiver suporte ajax
	  if(ajax) {
	     //deixa apenas o elemento 1 no option, os outros são excluídos
		 document.forms[0].listSubCategs.options.length = 1;

		 idOpcao  = document.getElementById("opcoes");

	     ajax.open("POST", "sub.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

		 ajax.onreadystatechange = function() {
            //enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
			   idOpcao.innerHTML = "Carregando...!";
	        }
			//após ser processado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML);
			   }
			   else {
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   idOpcao.innerHTML = "SELECIONE";
			   }
            }
         }
		 //passa o código do estado escolhido
	     var params = "idcategoria="+valor;
         ajax.send(params);
      }
   }

   function processXML(obj){
      //pega a tag cidade
      var dataArray   = obj.getElementsByTagName("subcateg");

	  //total de elementos contidos na tag cidade
	  if(dataArray.length > 0) {
	     //percorre o arquivo XML paara extrair os dados
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//contéudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("idsubcateg")[0].firstChild.nodeValue;
			var descricao =  item.getElementsByTagName("nomesub")[0].firstChild.nodeValue;

	        idOpcao.innerHTML = "--Selecione--";

			//cria um novo option dinamicamente
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoes");
				//atribui um valor
			    novo.value = codigo;
				//atribui um texto
			    novo.text  = descricao;
				//finalmente adiciona o novo elemento
				document.forms[0].listSubCategs.options.add(novo);
		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "SELECIONE";
	  }
   }

var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos)    {
    if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
    if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
    else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
}

function criaElemento() {
try {
    var ipt = document.createElement("<input name='foto[]' type='file' style='margin: 3px 0px 3px 10px' />");
} catch (e)   {
    var ipt = document.createElement('input');
    ipt.setAttribute('type', 'file');
    ipt.setAttribute('name', 'foto[]');
    ipt.setAttribute('style', 'margin: 3px 0px 3px 10px');
}
var texto = document.createTextNode('imagem:');   
document.getElementById('formi').appendChild(ipt);
document.getElementById('formi').appendChild(document.createElement("br"));

}

function sonumeros(event)
  {
    var tecla = (event.which) ? event.which : event.keyCode

    if ((tecla >= 48 && tecla <= 57) || (tecla == 8) || (tecla == 46) || (tecla == 9))
    {
    return true;
    }
    else
    {
    return false;
    }
  }

function criaElemento2() {
  try {
      var ipt = document.createElement("<input name='entrada_empresa[]' type='text' class='horario' style='width: 178px;'/>");
      var iptL = document.createElement("<input name='saida_empresa[]' type='text' class='horario' style='width: 178px;'/>");
      var br = document.createElement("<br />");
      var br2 = document.createElement("<br />");
      var br3 = document.createElement("<br />");
  } catch (e)   {
      var ipt = document.createElement('input');
      ipt.setAttribute('type', 'text');
      ipt.setAttribute('name', 'entrada_empresa[]');
      ipt.style.cssText = 'width: 178px;';
      ipt.setAttribute('class', 'horario');
      var br = document.createElement('br');
      var iptL = document.createElement('input');
      iptL.setAttribute('type', 'text');
      iptL.setAttribute('name', 'saida_empresa[]');
      iptL.setAttribute('class', 'horario');      
      iptL.style.cssText = 'width: 178px;';
      var br2 = document.createElement('br');
      var br3 = document.createElement('br');
  }



  var a1 = document.getElementById("ajudar_criar_elemento");
  if (a1.value == 1)
  {
  var texto = document.createTextNode('Entrada 2: ');
  var textoL = document.createTextNode('Saída 2: ');
  a1.value = 2;
  } else
  {
  var texto = document.createTextNode('Entrada 3: ');
  var textoL = document.createTextNode('Saída 3: ');
  document.getElementById('desaparece_em_3').style.display = 'none';
  }



  document.getElementById('formi').appendChild(texto);
  document.getElementById('formi').appendChild(ipt);
  document.getElementById('formi').appendChild(br);
  document.getElementById('formi').appendChild(textoL);
  document.getElementById('formi').appendChild(iptL);
  document.getElementById('formi').appendChild(document.createElement("br"));
  document.getElementById('formi').appendChild(br2);
  document.getElementById('formi').appendChild(br3);
}

    $(document).ready(function() {

        $(".horario").mask("99:99",{placeholder:" "});

    });

function permitir_marcar(check)
{
    if(check.checked == true)
    {
     $('#tamanho_1').attr('disabled','false');
    }

}


