function loadHtml(Url, div) {
	$.ajax({
		url: Url,
		data: {	'div' : div },
		type: "GET",
		cache: false,
		async: true,
		beforeSend: function(xmlhttprequest){
			$('#loading').show();
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
		  
		},
		complete: function(xmlhttprequest){
			$('#loading').hide();
		},
		success: function(html){
			$(div).html(html);
		}
	});
}


function submitForm( form, div, dados) {
	var data = $(form).serialize()+dados;
	$.ajax({
		url: $(form).attr("action"),
		data: data,
		type: $(form).attr("method"),
		cache: false,
		async: true,
		beforeSend: function(xmlhttprequest){
			$('#loading').show();
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
		  
		},
		complete: function(xmlhttprequest){
			$('#loading').hide();
		},
		success: function(html){
			$(div).html( html );
		}
	});
}


/**
 * Função para Abrir uma nova Janela ( popup )
 * @author Dreamweaver
 */
function popup ( url, nome, propriedades ){
	window.open( url, nome, propriedades );
}


function debug( objeto ){
	for( var key in objeto ){
		console.log( 'key: ' + key + ' objeto[key]: ' + objeto[key] );
	}
}

function imprimir(){
	if (!window.print){
		alert("O seu navegador não permite usar este botão para solicitar impressão!")
		return;
	}
	window.print();
}



/**
 * Função para montar as abas 
 * @author Samuel
 */
function Abas(){
	
	this.abas;
	this.nome;
	
	this.iniciar_abas = function( nome, array, aba ){

/*
		console.log( "#############################################" );
		console.log( "this.iniciar_abas" );
		console.log( "array: " + array );
		console.log( "aba: " + aba );
		console.log( "#############################################" );
*/

		this.abas = array;
		this.nome = nome;
		
		if( aba ){
			this.exibir_aba( aba );
		}
		else{
			
			for( var n_key in this.abas ){
				if( (!aba) || ( aba == "undefined" ) ){
					aba = n_key;
				}
			}
			this.exibir_aba( aba );
			//this.esconder_divs( aba  );
		}
	}

	this.exibir_aba = function( aba ){

/*
		console.log( "#############################################" );
		console.log( "this.exibir_aba" );
		console.log( "aba: " + aba );		
		console.log( "#############################################" );
*/

		if( aba ){
			document.getElementById( this.abas[aba]['div'] ).style.display = "";
			aba_exibir = document.getElementById( aba );
			aba_exibir.className = "ativo";
			aba_exibir.innerHTML = this.abas[aba]['titulo'];
			
			if( ( this.abas[aba]['acao'] ) && ( this.abas[aba]['acao'] != 'undefined' ) ){
				eval( this.abas[aba]['acao'] );
			}
		}
		this.esconder_divs( aba );
	}

	this.esconder_divs = function( aba ){

/*		
		console.log( "#############################################" );
		console.log( "this.esconder_divs" );
		console.log( "aba: " + aba );		
		console.log( "#############################################" );
*/		

		for ( var n_key in this.abas ){
			if( ( aba ) && ( aba != "undefined" ) ){					
				if( n_key != aba ){
					document.getElementById( this.abas[n_key]['div'] ).style.display = 'none';
					document.getElementById( n_key ).className = '';
					document.getElementById( n_key ).innerHTML = "<a href=\"#\" onclick=\""+this.nome+".exibir_aba('"+n_key+"');\" title=\""+this.abas[n_key]['titulo']+"\">"+this.abas[n_key]['titulo']+"</a>";
				}
			}
			else{
				
				aba = n_key;
				if( n_key != aba ){
					document.getElementById( this.abas[n_key]['div'] ).style.display = 'none';
					document.getElementById( n_key ).className = '';
					document.getElementById( n_key ).innerHTML = "<a href=\"#\" onclick=\""+this.nome+".exibir_aba('"+n_key+"');\" title=\""+this.abas[n_key]['titulo']+"\">"+this.abas[n_key]['titulo']+"</a>";
				}				
			}
		}

	}
}




function format(value,format)
{
	value = value.replace(/\D/g,"");
	var result="";
	
	if(format.length < value.length)
		return value;
	
	for(i=0,j=0;(i<format.length)&&(j<value.length);i++)
	{
		var ch = format.charAt(i) ;
		if(ch == '#')
		{
			result += value.charAt(j++);
			continue;
		}
		result += ch;
	}
	return result;
}

//onKeyUp="this.value = format(this.value,'##/##/####');"


function formataMoeda(objTextBox, SeparadorDecimal, SeparadorMilesimo, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;    
    // 13=enter, 8=backspace as demais retornam 0(zero)
    // whichCode==0 faz com que seja possivel usar todas as teclas como delete, setas, etc    
    if ((whichCode == 13) || (whichCode == 0) || (whichCode == 8))
    	return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
 
 
    if (strCheck.indexOf(key) == -1) 
    	return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) 
        	break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) 
        	aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) 
    	objTextBox.value = '';
    if (len == 1) 
    	objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) 
    	objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        	objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

//onKeyPress=”return(formataMoeda(this,’.',’,',event))”;