﻿var caminho_url = '/';

// ajax return functions 
var callbackResult = function(resultado){
 if (typeof resultado!= 'undefined' && resultado.SUCCESS) {
  $('#success').css({display:'block'});
  $("#success_msg").empty().html(resultado.MESSAGE);
 
 
  $(this).oneTime(500, "hide", function() {
	  top.location.href=caminho_url+$.query.copy();
    }); 
   
 } else {
  $('#warning').css({display:'block'});
  $('#warning_msg').html(resultado.MESSAGE);
 }
}

var errorHandler = function(statusCode,statusMsg) {
  $('#warning').css({display:'block'});
  $('#warning_msg').html(statusMsg);
}

$(document).ready(function() {

	$('form').submit(function(){  
		$(':submit', this).click(function() {  
			return false;  
		});  
	});
	
  fnc_controla_campos();
  
  if( window.fnc_centro && window.fnc_mostra_div ){ 
	 fnc_centro('carregando'); 
	 fnc_centro('login'); 	
	 fnc_mostra_div('carregando');
	 fnc_mostra_div('login');
	 
  }		
  // ocultar pré-loader e mostra formulario
  if ( window.fnc_referencia_div && fnc_referencia_div('carregando') && fnc_referencia_div('carregando').style.display != 'none' ) {
	fnc_oculta_div('carregando');
    fnc_mostra_div('nqform');
  }

 $('ul.items>li.active>ul').slideDown();
	$(function() {
			$('.items').click(clickFn);
 });
 function clickFn(e) {
	var $el = $(e.target);
	if (!$el.parent().children('ul').is(':visible')) {
		if ($el.parent().parent().is('ul.items')) {
			$('ul.items>li>ul:visible').slideUp();
			$el.parent().children("ul").slideDown();
		}
	} 
  }	
  function getEventTarget(e) {
	e = e || window.event;
	return e.target || e.srcElement;
  }

  $('.close').click(function() {
	$(this).parents(".alert").animate({ opacity: 'hide' }, "slow");
	 return false;
  });  
  
});

function encodeHTML(str){
 var aStr = str.split(''),
     i = aStr.length,
     aRet = [];

   while (--i) {
    var iC = aStr[i].charCodeAt();
    if (iC < 65 || iC > 127 || (iC>90 && iC<97)) {
      aRet.push('&#'+iC+';');
    } else {
      aRet.push(aStr[i]);
    }
  }
 return aRet.reverse().join('');
}